Bug 1309109 part 4 - Add ServoDeclarationBlock class. r?heycam
MozReview-Commit-ID: 8I9sbt0oMhx
--- a/layout/style/DeclarationBlock.h
+++ b/layout/style/DeclarationBlock.h
@@ -8,35 +8,44 @@
* representation of a declaration block in a CSS stylesheet, or of
* a style attribute
*/
#ifndef mozilla_DeclarationBlock_h
#define mozilla_DeclarationBlock_h
#include "mozilla/StyleBackendType.h"
+#include "mozilla/ServoUtils.h"
class nsHTMLCSSStyleSheet;
namespace mozilla {
+class ServoDeclarationBlock;
+
namespace css {
+class Declaration;
class Rule;
} // namespace css
class DeclarationBlock
{
protected:
DeclarationBlock(StyleBackendType aType)
: mImmutable(false), mType(aType) { mContainer.mRaw = 0; }
DeclarationBlock(const DeclarationBlock& aCopy)
: DeclarationBlock(aCopy.mType) {}
public:
+ MOZ_DECL_STYLO_METHODS(css::Declaration, ServoDeclarationBlock)
+
+ inline MozExternalRefCountType AddRef();
+ inline MozExternalRefCountType Release();
+
/**
* Return whether |this| may be modified.
*/
bool IsMutable() const {
return !mImmutable;
}
/**
new file mode 100644
--- /dev/null
+++ b/layout/style/DeclarationBlockInlines.h
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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/. */
+
+#ifndef mozilla_DeclarationBlockInlines_h
+#define mozilla_DeclarationBlockInlines_h
+
+#include "mozilla/css/Declaration.h"
+#include "mozilla/ServoDeclarationBlock.h"
+
+namespace mozilla {
+
+MOZ_DEFINE_STYLO_METHODS(DeclarationBlock, css::Declaration, ServoDeclarationBlock)
+
+MozExternalRefCountType
+DeclarationBlock::AddRef()
+{
+ MOZ_STYLO_FORWARD(AddRef, ())
+}
+
+MozExternalRefCountType
+DeclarationBlock::Release()
+{
+ MOZ_STYLO_FORWARD(Release, ())
+}
+
+} // namespace mozilla
+
+#endif // mozilla_DeclarationBlockInlines_h
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoDeclarationBlock.cpp
@@ -0,0 +1,23 @@
+/* -*- 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"
+
+namespace mozilla {
+
+/* static */ already_AddRefed<ServoDeclarationBlock>
+ServoDeclarationBlock::FromStyleAttribute(const nsAString& aString)
+{
+ NS_ConvertUTF16toUTF8 value(aString);
+ RefPtr<RawServoDeclarationBlock> raw = Servo_ParseStyleAttribute(
+ reinterpret_cast<const uint8_t*>(value.get()),
+ value.Length(), nullptr).Consume();
+ RefPtr<ServoDeclarationBlock> decl = new ServoDeclarationBlock(raw.forget());
+ return decl.forget();
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoDeclarationBlock.h
@@ -0,0 +1,38 @@
+/* -*- 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/. */
+
+#ifndef mozilla_ServoDeclarationBlock_h
+#define mozilla_ServoDeclarationBlock_h
+
+#include "mozilla/ServoBindings.h"
+#include "mozilla/DeclarationBlock.h"
+
+namespace mozilla {
+
+class ServoDeclarationBlock final : public DeclarationBlock
+{
+public:
+ NS_INLINE_DECL_REFCOUNTING(ServoDeclarationBlock)
+
+ static already_AddRefed<ServoDeclarationBlock>
+ FromStyleAttribute(const nsAString& aString);
+
+ RawServoDeclarationBlock* const& Raw() const {
+ return *reinterpret_cast<RawServoDeclarationBlock* const*>(&mRaw);
+ }
+
+protected:
+ ServoDeclarationBlock(already_AddRefed<RawServoDeclarationBlock> aRaw)
+ : DeclarationBlock(StyleBackendType::Servo), mRaw(aRaw) {}
+
+private:
+ ~ServoDeclarationBlock() {}
+
+ RefPtr<RawServoDeclarationBlock> mRaw;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_ServoDeclarationBlock_h
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -82,24 +82,26 @@ EXPORTS += [
EXPORTS.mozilla += [
'AnimationCollection.h',
'CSSEnabledState.h',
'CSSStyleSheet.h',
'CSSVariableDeclarations.h',
'CSSVariableResolver.h',
'CSSVariableValues.h',
'DeclarationBlock.h',
+ 'DeclarationBlockInlines.h',
'HandleRefPtr.h',
'IncrementalClearCOMRuleArray.h',
'LayerAnimationInfo.h',
'RuleNodeCacheConditions.h',
'RuleProcessorCache.h',
'ServoBindingHelpers.h',
'ServoBindingList.h',
'ServoBindings.h',
+ 'ServoDeclarationBlock.h',
'ServoElementSnapshot.h',
'ServoStyleSet.h',
'ServoStyleSheet.h',
'ServoTypes.h',
'ServoUtils.h',
'SheetType.h',
'StyleAnimationValue.h',
'StyleBackendType.h',
@@ -189,16 +191,17 @@ UNIFIED_SOURCES += [
'nsStyleSet.cpp',
'nsStyleStruct.cpp',
'nsStyleTransformMatrix.cpp',
'nsStyleUtil.cpp',
'nsTransitionManager.cpp',
'RuleNodeCacheConditions.cpp',
'RuleProcessorCache.cpp',
'ServoBindings.cpp',
+ 'ServoDeclarationBlock.cpp',
'ServoElementSnapshot.cpp',
'ServoStyleSet.cpp',
'ServoStyleSheet.cpp',
'StyleAnimationValue.cpp',
'StyleRule.cpp',
'StyleSheet.cpp',
'SVGAttrAnimationRuleProcessor.cpp',
]