From 77fad93235c241202a5a45ab470ad4cc2b8e58c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Tue, 5 Jun 2018 13:39:42 +0200 Subject: [PATCH] Bug 1451289 - Part 7: Merge ServoPageRule and CSSPageRule r=emilio MozReview-Commit-ID: 5kqMLZWXFN5 --HG-- extra : rebase_source : 1ef8e31634b1be81c0df3c36bb56d13f7be9a9a2 --- layout/style/CSSPageRule.cpp | 170 ++++++++++++++++++++++++++- layout/style/CSSPageRule.h | 90 ++++++++++++-- layout/style/ServoCSSRuleList.cpp | 4 +- layout/style/ServoPageRule.cpp | 188 ------------------------------ layout/style/ServoPageRule.h | 107 ----------------- layout/style/moz.build | 2 - layout/style/nsHTMLStyleSheet.cpp | 1 + 7 files changed, 251 insertions(+), 311 deletions(-) delete mode 100644 layout/style/ServoPageRule.cpp delete mode 100644 layout/style/ServoPageRule.h diff --git a/layout/style/CSSPageRule.cpp b/layout/style/CSSPageRule.cpp index d43745eae6cc..cb0a8fae5b63 100644 --- a/layout/style/CSSPageRule.cpp +++ b/layout/style/CSSPageRule.cpp @@ -5,12 +5,180 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/CSSPageRule.h" - #include "mozilla/dom/CSSPageRuleBinding.h" +#include "mozilla/DeclarationBlock.h" +#include "mozilla/ServoBindings.h" + namespace mozilla { namespace dom { +// -- CSSPageRuleDeclaration --------------------------------------- + +CSSPageRuleDeclaration::CSSPageRuleDeclaration( + already_AddRefed aDecls) + : mDecls(new DeclarationBlock(std::move(aDecls))) +{ +} + +CSSPageRuleDeclaration::~CSSPageRuleDeclaration() +{ + mDecls->SetOwningRule(nullptr); +} + +// QueryInterface implementation for CSSPageRuleDeclaration +NS_INTERFACE_MAP_BEGIN(CSSPageRuleDeclaration) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + // We forward the cycle collection interfaces to Rule(), which is + // never null (in fact, we're part of that object!) + if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) || + aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) { + return Rule()->QueryInterface(aIID, aInstancePtr); + } + else +NS_IMPL_QUERY_TAIL_INHERITING(nsDOMCSSDeclaration) + +NS_IMPL_ADDREF_USING_AGGREGATOR(CSSPageRuleDeclaration, Rule()) +NS_IMPL_RELEASE_USING_AGGREGATOR(CSSPageRuleDeclaration, Rule()) + +/* nsDOMCSSDeclaration implementation */ + +css::Rule* +CSSPageRuleDeclaration::GetParentRule() +{ + return Rule(); +} + +nsINode* +CSSPageRuleDeclaration::GetParentObject() +{ + return Rule()->GetParentObject(); +} + +DeclarationBlock* +CSSPageRuleDeclaration::GetCSSDeclaration(Operation aOperation) +{ + return mDecls; +} + +nsresult +CSSPageRuleDeclaration::SetCSSDeclaration(DeclarationBlock* aDecl) +{ + MOZ_ASSERT(aDecl, "must be non-null"); + CSSPageRule* rule = Rule(); + + if (aDecl != mDecls) { + mDecls->SetOwningRule(nullptr); + RefPtr decls = aDecl; + Servo_PageRule_SetStyle(rule->Raw(), decls->Raw()); + mDecls = decls.forget(); + mDecls->SetOwningRule(rule); + } + + return NS_OK; +} + +nsIDocument* +CSSPageRuleDeclaration::DocToUpdate() +{ + return nullptr; +} + +nsDOMCSSDeclaration::ParsingEnvironment +CSSPageRuleDeclaration::GetParsingEnvironment( + nsIPrincipal* aSubjectPrincipal) const +{ + return GetParsingEnvironmentForRule(Rule()); +} + +// -- CSSPageRule -------------------------------------------------- + +CSSPageRule::CSSPageRule(RefPtr aRawRule, + uint32_t aLine, uint32_t aColumn) + : Rule(aLine, aColumn) + , mRawRule(std::move(aRawRule)) + , mDecls(Servo_PageRule_GetStyle(mRawRule).Consume()) +{ +} + +NS_IMPL_ADDREF_INHERITED(CSSPageRule, css::Rule) +NS_IMPL_RELEASE_INHERITED(CSSPageRule, css::Rule) + +// QueryInterface implementation for PageRule +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSPageRule) +NS_INTERFACE_MAP_END_INHERITING(css::Rule) + +NS_IMPL_CYCLE_COLLECTION_CLASS(CSSPageRule) + +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(CSSPageRule, css::Rule) + // Keep this in sync with IsCCLeaf. + + // Trace the wrapper for our declaration. This just expands out + // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use + // directly because the wrapper is on the declaration, not on us. + tmp->mDecls.TraceWrapper(aCallbacks, aClosure); +NS_IMPL_CYCLE_COLLECTION_TRACE_END + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CSSPageRule, css::Rule) + // Keep this in sync with IsCCLeaf. + + // Unlink the wrapper for our declaraton. This just expands out + // NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use + // directly because the wrapper is on the declaration, not on us. + tmp->mDecls.ReleaseWrapper(static_cast(p)); + tmp->mDecls.mDecls->SetOwningRule(nullptr); +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSPageRule, css::Rule) + // Keep this in sync with IsCCLeaf. +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +bool +CSSPageRule::IsCCLeaf() const +{ + if (!Rule::IsCCLeaf()) { + return false; + } + + return !mDecls.PreservingWrapper(); +} + +size_t +CSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const +{ + // TODO Implement this! + return aMallocSizeOf(this); +} + +#ifdef DEBUG +void +CSSPageRule::List(FILE* out, int32_t aIndent) const +{ + nsAutoCString str; + for (int32_t i = 0; i < aIndent; i++) { + str.AppendLiteral(" "); + } + Servo_PageRule_Debug(mRawRule, &str); + fprintf_stderr(out, "%s\n", str.get()); +} +#endif + +/* CSSRule implementation */ + +void +CSSPageRule::GetCssText(nsAString& aCssText) const +{ + Servo_PageRule_GetCssText(mRawRule, &aCssText); +} + +/* CSSPageRule implementation */ + +nsICSSDeclaration* +CSSPageRule::Style() +{ + return &mDecls; +} + JSObject* CSSPageRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { diff --git a/layout/style/CSSPageRule.h b/layout/style/CSSPageRule.h index 9f9646d4d787..3e3f07cbde21 100644 --- a/layout/style/CSSPageRule.h +++ b/layout/style/CSSPageRule.h @@ -8,33 +8,101 @@ #define mozilla_dom_CSSPageRule_h #include "mozilla/css/Rule.h" +#include "mozilla/ServoBindingTypes.h" +#include "nsDOMCSSDeclaration.h" #include "nsICSSDeclaration.h" namespace mozilla { +class DeclarationBlock; + namespace dom { +class DocGroup; +class CSSPageRule; -class CSSPageRule : public css::Rule +class CSSPageRuleDeclaration final : public nsDOMCSSDeclaration { -protected: - using Rule::Rule; - virtual ~CSSPageRule() {}; - public: - virtual bool IsCCLeaf() const override = 0; + NS_DECL_ISUPPORTS_INHERITED + + css::Rule* GetParentRule() final; + nsINode* GetParentObject() final; + +protected: + DeclarationBlock* GetCSSDeclaration(Operation aOperation) final; + nsresult SetCSSDeclaration(DeclarationBlock* aDecl) final; + nsIDocument* DocToUpdate() final; + nsDOMCSSDeclaration::ParsingEnvironment + GetParsingEnvironment(nsIPrincipal* aSubjectPrincipal) const final; + +private: + // For accessing the constructor. + friend class CSSPageRule; + + explicit CSSPageRuleDeclaration( + already_AddRefed aDecls); + ~CSSPageRuleDeclaration(); + + inline CSSPageRule* Rule(); + inline const CSSPageRule* Rule() const; + + RefPtr mDecls; +}; + +class CSSPageRule final : public css::Rule +{ +public: + CSSPageRule(RefPtr aRawRule, + uint32_t aLine, uint32_t aColumn); + + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED( + CSSPageRule, css::Rule + ) + + bool IsCCLeaf() const final; + + RawServoPageRule* Raw() const { return mRawRule; } // WebIDL interfaces uint16_t Type() const final { return CSSRuleBinding::PAGE_RULE; } - virtual void GetCssText(nsAString& aCssText) const override = 0; - virtual nsICSSDeclaration* Style() = 0; + void GetCssText(nsAString& aCssText) const final; + nsICSSDeclaration* Style(); - virtual size_t - SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override = 0; + size_t + SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final; + +#ifdef DEBUG + void List(FILE* out = stdout, int32_t aIndent = 0) const final; +#endif JSObject* - WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + WrapObject(JSContext* aCx, JS::Handle aGivenProto) final; + +private: + ~CSSPageRule() = default; + + // For computing the offset of mDecls. + friend class CSSPageRuleDeclaration; + + RefPtr mRawRule; + CSSPageRuleDeclaration mDecls; }; +CSSPageRule* +CSSPageRuleDeclaration::Rule() +{ + return reinterpret_cast( + reinterpret_cast(this) - offsetof(CSSPageRule, mDecls)); +} + +const CSSPageRule* +CSSPageRuleDeclaration::Rule() const +{ + return reinterpret_cast( + reinterpret_cast(this) - offsetof(CSSPageRule, mDecls)); +} + } // namespace dom } // namespace mozilla diff --git a/layout/style/ServoCSSRuleList.cpp b/layout/style/ServoCSSRuleList.cpp index cc592e0a031f..d345830b25b5 100644 --- a/layout/style/ServoCSSRuleList.cpp +++ b/layout/style/ServoCSSRuleList.cpp @@ -13,13 +13,13 @@ #include "mozilla/dom/CSSKeyframesRule.h" #include "mozilla/dom/CSSMediaRule.h" #include "mozilla/dom/CSSNamespaceRule.h" +#include "mozilla/dom/CSSPageRule.h" #include "mozilla/dom/CSSStyleRule.h" #include "mozilla/IntegerRange.h" #include "mozilla/ServoBindings.h" #include "mozilla/ServoDocumentRule.h" #include "mozilla/ServoImportRule.h" #include "mozilla/ServoFontFeatureValuesRule.h" -#include "mozilla/ServoPageRule.h" #include "mozilla/ServoSupportsRule.h" #include "mozilla/StyleSheet.h" @@ -108,7 +108,7 @@ ServoCSSRuleList::GetRule(uint32_t aIndex) CASE_RULE_CSS(KEYFRAMES, Keyframes) CASE_RULE_CSS(MEDIA, Media) CASE_RULE_CSS(NAMESPACE, Namespace) - CASE_RULE(PAGE, Page) + CASE_RULE_CSS(PAGE, Page) CASE_RULE(SUPPORTS, Supports) CASE_RULE(DOCUMENT, Document) CASE_RULE(IMPORT, Import) diff --git a/layout/style/ServoPageRule.cpp b/layout/style/ServoPageRule.cpp deleted file mode 100644 index 4ae78010494f..000000000000 --- a/layout/style/ServoPageRule.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* -*- 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/. */ - -/* representation of CSSPageRule for stylo */ - -#include "mozilla/ServoPageRule.h" - -#include "mozilla/DeclarationBlock.h" -#include "mozilla/ServoBindings.h" - -using namespace mozilla::dom; - -namespace mozilla { - -// -- ServoPageRuleDeclaration --------------------------------------- - -ServoPageRuleDeclaration::ServoPageRuleDeclaration( - already_AddRefed aDecls) - : mDecls(new DeclarationBlock(std::move(aDecls))) -{ -} - -ServoPageRuleDeclaration::~ServoPageRuleDeclaration() -{ - mDecls->SetOwningRule(nullptr); -} - -// QueryInterface implementation for ServoPageRuleDeclaration -NS_INTERFACE_MAP_BEGIN(ServoPageRuleDeclaration) - NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY - // We forward the cycle collection interfaces to Rule(), which is - // never null (in fact, we're part of that object!) - if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) || - aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) { - return Rule()->QueryInterface(aIID, aInstancePtr); - } - else -NS_IMPL_QUERY_TAIL_INHERITING(nsDOMCSSDeclaration) - -NS_IMPL_ADDREF_USING_AGGREGATOR(ServoPageRuleDeclaration, Rule()) -NS_IMPL_RELEASE_USING_AGGREGATOR(ServoPageRuleDeclaration, Rule()) - -/* nsDOMCSSDeclaration implementation */ - -css::Rule* -ServoPageRuleDeclaration::GetParentRule() -{ - return Rule(); -} - -nsINode* -ServoPageRuleDeclaration::GetParentObject() -{ - return Rule()->GetParentObject(); -} - -DeclarationBlock* -ServoPageRuleDeclaration::GetCSSDeclaration(Operation aOperation) -{ - return mDecls; -} - -nsresult -ServoPageRuleDeclaration::SetCSSDeclaration(DeclarationBlock* aDecl) -{ - MOZ_ASSERT(aDecl, "must be non-null"); - ServoPageRule* rule = Rule(); - - if (aDecl != mDecls) { - mDecls->SetOwningRule(nullptr); - RefPtr decls = aDecl; - Servo_PageRule_SetStyle(rule->Raw(), decls->Raw()); - mDecls = decls.forget(); - mDecls->SetOwningRule(rule); - } - - return NS_OK; -} - -nsIDocument* -ServoPageRuleDeclaration::DocToUpdate() -{ - return nullptr; -} - -nsDOMCSSDeclaration::ParsingEnvironment -ServoPageRuleDeclaration::GetParsingEnvironment( - nsIPrincipal* aSubjectPrincipal) const -{ - return GetParsingEnvironmentForRule(Rule()); -} - -// -- ServoPageRule -------------------------------------------------- - -ServoPageRule::ServoPageRule(RefPtr aRawRule, - uint32_t aLine, uint32_t aColumn) - : CSSPageRule(aLine, aColumn) - , mRawRule(std::move(aRawRule)) - , mDecls(Servo_PageRule_GetStyle(mRawRule).Consume()) -{ -} - -ServoPageRule::~ServoPageRule() -{ -} - -NS_IMPL_ADDREF_INHERITED(ServoPageRule, CSSPageRule) -NS_IMPL_RELEASE_INHERITED(ServoPageRule, CSSPageRule) - -// QueryInterface implementation for PageRule -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ServoPageRule) -NS_INTERFACE_MAP_END_INHERITING(CSSPageRule) - -NS_IMPL_CYCLE_COLLECTION_CLASS(ServoPageRule) - -NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(ServoPageRule, CSSPageRule) - // Keep this in sync with IsCCLeaf. - - // Trace the wrapper for our declaration. This just expands out - // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use - // directly because the wrapper is on the declaration, not on us. - tmp->mDecls.TraceWrapper(aCallbacks, aClosure); -NS_IMPL_CYCLE_COLLECTION_TRACE_END - -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ServoPageRule, CSSPageRule) - // Keep this in sync with IsCCLeaf. - - // Unlink the wrapper for our declaraton. This just expands out - // NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use - // directly because the wrapper is on the declaration, not on us. - tmp->mDecls.ReleaseWrapper(static_cast(p)); - tmp->mDecls.mDecls->SetOwningRule(nullptr); -NS_IMPL_CYCLE_COLLECTION_UNLINK_END - -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ServoPageRule, CSSPageRule) - // Keep this in sync with IsCCLeaf. -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END - -bool -ServoPageRule::IsCCLeaf() const -{ - if (!Rule::IsCCLeaf()) { - return false; - } - - return !mDecls.PreservingWrapper(); -} - -size_t -ServoPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const -{ - // TODO Implement this! - return aMallocSizeOf(this); -} - -#ifdef DEBUG -void -ServoPageRule::List(FILE* out, int32_t aIndent) const -{ - nsAutoCString str; - for (int32_t i = 0; i < aIndent; i++) { - str.AppendLiteral(" "); - } - Servo_PageRule_Debug(mRawRule, &str); - fprintf_stderr(out, "%s\n", str.get()); -} -#endif - -/* CSSRule implementation */ - -void -ServoPageRule::GetCssText(nsAString& aCssText) const -{ - Servo_PageRule_GetCssText(mRawRule, &aCssText); -} - -/* CSSPageRule implementation */ - -nsICSSDeclaration* -ServoPageRule::Style() -{ - return &mDecls; -} - -} // namespace mozilla diff --git a/layout/style/ServoPageRule.h b/layout/style/ServoPageRule.h deleted file mode 100644 index c07d6de8e497..000000000000 --- a/layout/style/ServoPageRule.h +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- 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/. */ - -/* representation of CSSPageRule for stylo */ - -#ifndef mozilla_ServoPageRule_h -#define mozilla_ServoPageRule_h - -#include "mozilla/dom/CSSPageRule.h" -#include "mozilla/ServoBindingTypes.h" - -#include "nsDOMCSSDeclaration.h" - -namespace mozilla { - -namespace dom { -class DocGroup; -} // namespace dom - -class DeclarationBlock; -class ServoPageRule; - -class ServoPageRuleDeclaration final : public nsDOMCSSDeclaration -{ -public: - NS_DECL_ISUPPORTS_INHERITED - - css::Rule* GetParentRule() final; - nsINode* GetParentObject() final; - -protected: - DeclarationBlock* GetCSSDeclaration(Operation aOperation) final; - nsresult SetCSSDeclaration(DeclarationBlock* aDecl) final; - nsIDocument* DocToUpdate() final; - nsDOMCSSDeclaration::ParsingEnvironment - GetParsingEnvironment(nsIPrincipal* aSubjectPrincipal) const final; - -private: - // For accessing the constructor. - friend class ServoPageRule; - - explicit ServoPageRuleDeclaration( - already_AddRefed aDecls); - ~ServoPageRuleDeclaration(); - - inline ServoPageRule* Rule(); - inline const ServoPageRule* Rule() const; - - RefPtr mDecls; -}; - -class ServoPageRule final : public dom::CSSPageRule -{ -public: - ServoPageRule(RefPtr aRawRule, - uint32_t aLine, uint32_t aColumn); - - NS_DECL_ISUPPORTS_INHERITED - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED( - ServoPageRule, dom::CSSPageRule - ) - bool IsCCLeaf() const final; - - RawServoPageRule* Raw() const { return mRawRule; } - - // WebIDL interface - void GetCssText(nsAString& aCssText) const final; - nsICSSDeclaration* Style() final; - - // Methods of mozilla::css::Rule - size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) - const final; - -#ifdef DEBUG - void List(FILE* out = stdout, int32_t aIndent = 0) const final; -#endif - -private: - virtual ~ServoPageRule(); - - // For computing the offset of mDecls. - friend class ServoPageRuleDeclaration; - - RefPtr mRawRule; - ServoPageRuleDeclaration mDecls; -}; - -ServoPageRule* -ServoPageRuleDeclaration::Rule() -{ - return reinterpret_cast( - reinterpret_cast(this) - offsetof(ServoPageRule, mDecls)); -} - -const ServoPageRule* -ServoPageRuleDeclaration::Rule() const -{ - return reinterpret_cast( - reinterpret_cast(this) - offsetof(ServoPageRule, mDecls)); -} - -} // namespace mozilla - -#endif // mozilla_ServoPageRule_h diff --git a/layout/style/moz.build b/layout/style/moz.build index add1d1636e59..5db20d276947 100644 --- a/layout/style/moz.build +++ b/layout/style/moz.build @@ -89,7 +89,6 @@ EXPORTS.mozilla += [ 'ServoElementSnapshotTable.h', 'ServoFontFeatureValuesRule.h', 'ServoImportRule.h', - 'ServoPageRule.h', 'ServoSpecifiedValues.h', 'ServoStyleSet.h', 'ServoStyleSetInlines.h', @@ -208,7 +207,6 @@ UNIFIED_SOURCES += [ 'ServoElementSnapshot.cpp', 'ServoFontFeatureValuesRule.cpp', 'ServoImportRule.cpp', - 'ServoPageRule.cpp', 'ServoSpecifiedValues.cpp', 'ServoStyleSet.cpp', 'ServoSupportsRule.cpp', diff --git a/layout/style/nsHTMLStyleSheet.cpp b/layout/style/nsHTMLStyleSheet.cpp index 2c26701c1153..c50b39bc1adf 100644 --- a/layout/style/nsHTMLStyleSheet.cpp +++ b/layout/style/nsHTMLStyleSheet.cpp @@ -23,6 +23,7 @@ #include "nsHashKeys.h" #include "mozilla/OperatorNewExtensions.h" #include "mozilla/RestyleManager.h" +#include "mozilla/ServoBindings.h" #include "mozilla/ServoStyleSet.h" using namespace mozilla;