From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- layout/style/ServoDeclarationBlock.cpp | 110 +++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 layout/style/ServoDeclarationBlock.cpp (limited to 'layout/style/ServoDeclarationBlock.cpp') diff --git a/layout/style/ServoDeclarationBlock.cpp b/layout/style/ServoDeclarationBlock.cpp new file mode 100644 index 000000000..1dc691bfb --- /dev/null +++ b/layout/style/ServoDeclarationBlock.cpp @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "mozilla/ServoDeclarationBlock.h" + +#include "mozilla/ServoBindings.h" + +#include "nsCSSProps.h" + +namespace mozilla { + +/* static */ already_AddRefed +ServoDeclarationBlock::FromCssText(const nsAString& aCssText) +{ + NS_ConvertUTF16toUTF8 value(aCssText); + RefPtr + raw = Servo_ParseStyleAttribute(&value).Consume(); + RefPtr decl = new ServoDeclarationBlock(raw.forget()); + return decl.forget(); +} + +/** + * An RAII class holding an atom for the given property. + */ +class MOZ_STACK_CLASS PropertyAtomHolder +{ +public: + explicit PropertyAtomHolder(const nsAString& aProperty) + { + nsCSSPropertyID propID = + nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent); + if (propID == eCSSPropertyExtra_variable) { + mIsCustomProperty = true; + mAtom = NS_Atomize( + Substring(aProperty, CSS_CUSTOM_NAME_PREFIX_LENGTH)).take(); + } else { + mIsCustomProperty = false; + if (propID != eCSSProperty_UNKNOWN) { + mAtom = nsCSSProps::AtomForProperty(propID); + } else { + mAtom = nullptr; + } + } + } + + ~PropertyAtomHolder() + { + if (mIsCustomProperty) { + NS_RELEASE(mAtom); + } + } + + explicit operator bool() const { return !!mAtom; } + nsIAtom* Atom() const { MOZ_ASSERT(mAtom); return mAtom; } + bool IsCustomProperty() const { return mIsCustomProperty; } + +private: + nsIAtom* mAtom; + bool mIsCustomProperty; +}; + +void +ServoDeclarationBlock::GetPropertyValue(const nsAString& aProperty, + nsAString& aValue) const +{ + if (PropertyAtomHolder holder{aProperty}) { + Servo_DeclarationBlock_GetPropertyValue( + mRaw, holder.Atom(), holder.IsCustomProperty(), &aValue); + } +} + +void +ServoDeclarationBlock::GetPropertyValueByID(nsCSSPropertyID aPropID, + nsAString& aValue) const +{ + nsIAtom* atom = nsCSSProps::AtomForProperty(aPropID); + Servo_DeclarationBlock_GetPropertyValue(mRaw, atom, false, &aValue); +} + +bool +ServoDeclarationBlock::GetPropertyIsImportant(const nsAString& aProperty) const +{ + if (PropertyAtomHolder holder{aProperty}) { + return Servo_DeclarationBlock_GetPropertyIsImportant( + mRaw, holder.Atom(), holder.IsCustomProperty()); + } + return false; +} + +void +ServoDeclarationBlock::RemoveProperty(const nsAString& aProperty) +{ + AssertMutable(); + if (PropertyAtomHolder holder{aProperty}) { + Servo_DeclarationBlock_RemoveProperty(mRaw, holder.Atom(), + holder.IsCustomProperty()); + } +} + +void +ServoDeclarationBlock::RemovePropertyByID(nsCSSPropertyID aPropID) +{ + AssertMutable(); + nsIAtom* atom = nsCSSProps::AtomForProperty(aPropID); + Servo_DeclarationBlock_RemoveProperty(mRaw, atom, false); +} + +} // namespace mozilla -- cgit v1.2.3