зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1352968 part 8 - Construct @import rule object eagerly. r=heycam
MozReview-Commit-ID: HrgZnW21dHz --HG-- extra : source : cedc65c6376373d54e623dc5cfadaa2de92909cb
This commit is contained in:
Родитель
a96cd2ac8a
Коммит
1269699516
|
@ -144,6 +144,8 @@ SERVO_BINDING_FUNC(Servo_StyleRule_GetSelectorText, void,
|
||||||
RawServoStyleRuleBorrowed rule, nsAString* result)
|
RawServoStyleRuleBorrowed rule, nsAString* result)
|
||||||
SERVO_BINDING_FUNC(Servo_ImportRule_GetHref, void,
|
SERVO_BINDING_FUNC(Servo_ImportRule_GetHref, void,
|
||||||
RawServoImportRuleBorrowed rule, nsAString* result)
|
RawServoImportRuleBorrowed rule, nsAString* result)
|
||||||
|
SERVO_BINDING_FUNC(Servo_ImportRule_GetSheet, const RawServoStyleSheet*,
|
||||||
|
RawServoImportRuleBorrowed rule)
|
||||||
SERVO_BINDING_FUNC(Servo_Keyframe_GetKeyText, void,
|
SERVO_BINDING_FUNC(Servo_Keyframe_GetKeyText, void,
|
||||||
RawServoKeyframeBorrowed keyframe, nsAString* result)
|
RawServoKeyframeBorrowed keyframe, nsAString* result)
|
||||||
// Returns whether it successfully changes the key text.
|
// Returns whether it successfully changes the key text.
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "mozilla/ServoCSSRuleList.h"
|
#include "mozilla/ServoCSSRuleList.h"
|
||||||
|
|
||||||
|
#include "mozilla/IntegerRange.h"
|
||||||
#include "mozilla/ServoBindings.h"
|
#include "mozilla/ServoBindings.h"
|
||||||
#include "mozilla/ServoDocumentRule.h"
|
#include "mozilla/ServoDocumentRule.h"
|
||||||
#include "mozilla/ServoImportRule.h"
|
#include "mozilla/ServoImportRule.h"
|
||||||
|
@ -16,6 +17,7 @@
|
||||||
#include "mozilla/ServoNamespaceRule.h"
|
#include "mozilla/ServoNamespaceRule.h"
|
||||||
#include "mozilla/ServoPageRule.h"
|
#include "mozilla/ServoPageRule.h"
|
||||||
#include "mozilla/ServoStyleRule.h"
|
#include "mozilla/ServoStyleRule.h"
|
||||||
|
#include "mozilla/ServoStyleSheet.h"
|
||||||
#include "mozilla/ServoSupportsRule.h"
|
#include "mozilla/ServoSupportsRule.h"
|
||||||
#include "nsCSSCounterStyleRule.h"
|
#include "nsCSSCounterStyleRule.h"
|
||||||
#include "nsCSSFontFaceRule.h"
|
#include "nsCSSFontFaceRule.h"
|
||||||
|
@ -28,9 +30,33 @@ ServoCSSRuleList::ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules,
|
||||||
, mRawRules(aRawRules)
|
, mRawRules(aRawRules)
|
||||||
{
|
{
|
||||||
Servo_CssRules_ListTypes(mRawRules, &mRules);
|
Servo_CssRules_ListTypes(mRawRules, &mRules);
|
||||||
// XXX We may want to eagerly create object for import rule, so that
|
// Only top level rule list can have @import rules.
|
||||||
// we don't lose the reference to child stylesheet when our own
|
if (aDirectOwnerStyleSheet) {
|
||||||
// stylesheet goes away.
|
nsDataHashtable<nsPtrHashKey<const RawServoStyleSheet>,
|
||||||
|
ServoStyleSheet*> stylesheets;
|
||||||
|
aDirectOwnerStyleSheet->EnumerateChildSheets(
|
||||||
|
[&stylesheets](StyleSheet* child) {
|
||||||
|
ServoStyleSheet* servoSheet = child->AsServo();
|
||||||
|
const RawServoStyleSheet* rawSheet = servoSheet->RawSheet();
|
||||||
|
MOZ_ASSERT(!stylesheets.Get(rawSheet, nullptr),
|
||||||
|
"Multiple child sheets with same raw sheet?");
|
||||||
|
stylesheets.Put(rawSheet, servoSheet);
|
||||||
|
});
|
||||||
|
for (auto i : IntegerRange(mRules.Length())) {
|
||||||
|
if (mRules[i] != nsIDOMCSSRule::IMPORT_RULE) {
|
||||||
|
// Only @charset can be put before @import rule, but @charset
|
||||||
|
// rules don't have corresponding object, so if a rule is not
|
||||||
|
// @import rule, there is definitely no @import rule after it.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ConstructImportRule(i, [&stylesheets](const RawServoStyleSheet* raw) {
|
||||||
|
// Child sheets may not correctly cloned for stylo, which is
|
||||||
|
// bug 1367213. That makes it possible to fail to get a style
|
||||||
|
// sheet for the raw sheet here.
|
||||||
|
return stylesheets.GetAndRemove(raw).valueOr(nullptr);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryInterface implementation for ServoCSSRuleList
|
// QueryInterface implementation for ServoCSSRuleList
|
||||||
|
@ -101,7 +127,6 @@ ServoCSSRuleList::GetRule(uint32_t aIndex)
|
||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
CASE_RULE(STYLE, Style)
|
CASE_RULE(STYLE, Style)
|
||||||
CASE_RULE(IMPORT, Import)
|
|
||||||
CASE_RULE(KEYFRAMES, Keyframes)
|
CASE_RULE(KEYFRAMES, Keyframes)
|
||||||
CASE_RULE(MEDIA, Media)
|
CASE_RULE(MEDIA, Media)
|
||||||
CASE_RULE(NAMESPACE, Namespace)
|
CASE_RULE(NAMESPACE, Namespace)
|
||||||
|
@ -121,6 +146,12 @@ ServoCSSRuleList::GetRule(uint32_t aIndex)
|
||||||
ruleObj = Servo_CssRules_GetCounterStyleRuleAt(mRawRules, aIndex);
|
ruleObj = Servo_CssRules_GetCounterStyleRuleAt(mRawRules, aIndex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case nsIDOMCSSRule::IMPORT_RULE:
|
||||||
|
// Currently ConstructImportRule may fail to construct an import
|
||||||
|
// rule eagerly. See comment in that function. This should be
|
||||||
|
// converted into an assertion when those bugs get fixed.
|
||||||
|
NS_WARNING("stylo: this @import rule was not constructed");
|
||||||
|
return nullptr;
|
||||||
case nsIDOMCSSRule::KEYFRAME_RULE:
|
case nsIDOMCSSRule::KEYFRAME_RULE:
|
||||||
MOZ_ASSERT_UNREACHABLE("keyframe rule cannot be here");
|
MOZ_ASSERT_UNREACHABLE("keyframe rule cannot be here");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -184,6 +215,36 @@ ServoCSSRuleList::DropReference()
|
||||||
DropAllRules();
|
DropAllRules();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename ChildSheetGetter>
|
||||||
|
void
|
||||||
|
ServoCSSRuleList::ConstructImportRule(uint32_t aIndex, ChildSheetGetter aGetter)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(mRules[aIndex] == nsIDOMCSSRule::IMPORT_RULE);
|
||||||
|
|
||||||
|
uint32_t line, column;
|
||||||
|
RefPtr<RawServoImportRule> rawRule =
|
||||||
|
Servo_CssRules_GetImportRuleAt(mRawRules, aIndex,
|
||||||
|
&line, &column).Consume();
|
||||||
|
const RawServoStyleSheet*
|
||||||
|
rawChildSheet = Servo_ImportRule_GetSheet(rawRule);
|
||||||
|
ServoStyleSheet* childSheet = aGetter(rawChildSheet);
|
||||||
|
if (!childSheet) {
|
||||||
|
// There are cases that we cannot get the child sheet currently.
|
||||||
|
// See comments in callsites of this function. This should become
|
||||||
|
// an assertion after bug 1367213 and bug 1368381 get fixed.
|
||||||
|
NS_WARNING("stylo: fail to get child sheet for @import rule");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RefPtr<ServoImportRule>
|
||||||
|
ruleObj = new ServoImportRule(Move(rawRule), childSheet, line, column);
|
||||||
|
MOZ_ASSERT(!childSheet->GetOwnerRule(),
|
||||||
|
"Child sheet is already owned by another rule?");
|
||||||
|
MOZ_ASSERT(childSheet->GetParentSheet() == mStyleSheet,
|
||||||
|
"Not a child sheet of the owner of the rule?");
|
||||||
|
childSheet->SetOwnerRule(ruleObj);
|
||||||
|
mRules[aIndex] = CastToUint(ruleObj.forget().take());
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
ServoCSSRuleList::InsertRule(const nsAString& aRule, uint32_t aIndex)
|
ServoCSSRuleList::InsertRule(const nsAString& aRule, uint32_t aIndex)
|
||||||
{
|
{
|
||||||
|
@ -199,8 +260,27 @@ ServoCSSRuleList::InsertRule(const nsAString& aRule, uint32_t aIndex)
|
||||||
nsresult rv = Servo_CssRules_InsertRule(mRawRules, mStyleSheet->RawSheet(),
|
nsresult rv = Servo_CssRules_InsertRule(mRawRules, mStyleSheet->RawSheet(),
|
||||||
&rule, aIndex, nested,
|
&rule, aIndex, nested,
|
||||||
loader, mStyleSheet, &type);
|
loader, mStyleSheet, &type);
|
||||||
if (!NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
mRules.InsertElementAt(aIndex, type);
|
return rv;
|
||||||
|
}
|
||||||
|
mRules.InsertElementAt(aIndex, type);
|
||||||
|
if (type == nsIDOMCSSRule::IMPORT_RULE) {
|
||||||
|
MOZ_ASSERT(!nested, "@import rule cannot be nested");
|
||||||
|
ConstructImportRule(aIndex, [this](const RawServoStyleSheet* raw) {
|
||||||
|
StyleSheet* sheet = mStyleSheet->GetMostRecentlyAddedChildSheet();
|
||||||
|
MOZ_ASSERT(sheet, "Should have at least one "
|
||||||
|
"child stylesheet after inserting @import rule");
|
||||||
|
ServoStyleSheet* servoSheet = sheet->AsServo();
|
||||||
|
// This should always be that case, but currently ServoStyleSheet
|
||||||
|
// may be reused and the reused stylesheet doesn't refer to the
|
||||||
|
// right raw sheet, which is bug 1368381. This should be converted
|
||||||
|
// to an assertion after that bug gets fixed.
|
||||||
|
if (servoSheet->RawSheet() == raw) {
|
||||||
|
NS_WARNING("New child sheet should always be prepended to the list");
|
||||||
|
return static_cast<ServoStyleSheet*>(nullptr);
|
||||||
|
}
|
||||||
|
return servoSheet;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,9 @@ private:
|
||||||
|
|
||||||
void DropAllRules();
|
void DropAllRules();
|
||||||
|
|
||||||
|
template<typename ChildSheetGetter>
|
||||||
|
inline void ConstructImportRule(uint32_t aIndex, ChildSheetGetter aGetter);
|
||||||
|
|
||||||
// mStyleSheet may be nullptr when it drops the reference to us.
|
// mStyleSheet may be nullptr when it drops the reference to us.
|
||||||
ServoStyleSheet* mStyleSheet = nullptr;
|
ServoStyleSheet* mStyleSheet = nullptr;
|
||||||
// mParentRule is nullptr if it isn't a nested rule list.
|
// mParentRule is nullptr if it isn't a nested rule list.
|
||||||
|
|
|
@ -14,10 +14,11 @@
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
ServoImportRule::ServoImportRule(RefPtr<RawServoImportRule> aRawRule,
|
ServoImportRule::ServoImportRule(RefPtr<RawServoImportRule> aRawRule,
|
||||||
|
ServoStyleSheet* aSheet,
|
||||||
uint32_t aLine, uint32_t aColumn)
|
uint32_t aLine, uint32_t aColumn)
|
||||||
: CSSImportRule(aLine, aColumn)
|
: CSSImportRule(aLine, aColumn)
|
||||||
, mRawRule(Move(aRawRule))
|
, mRawRule(Move(aRawRule))
|
||||||
, mChildSheet(nullptr)
|
, mChildSheet(aSheet)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ class ServoImportRule final : public dom::CSSImportRule
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ServoImportRule(RefPtr<RawServoImportRule> aRawRule,
|
ServoImportRule(RefPtr<RawServoImportRule> aRawRule,
|
||||||
|
ServoStyleSheet* aSheet,
|
||||||
uint32_t aLine, uint32_t aColumn);
|
uint32_t aLine, uint32_t aColumn);
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
NS_DECL_ISUPPORTS_INHERITED
|
||||||
|
|
|
@ -170,6 +170,11 @@ public:
|
||||||
void PrependStyleSheet(StyleSheet* aSheet);
|
void PrependStyleSheet(StyleSheet* aSheet);
|
||||||
|
|
||||||
StyleSheet* GetFirstChild() const;
|
StyleSheet* GetFirstChild() const;
|
||||||
|
StyleSheet* GetMostRecentlyAddedChildSheet() const {
|
||||||
|
// New child sheet can only be prepended into the linked list of
|
||||||
|
// child sheets, so the most recently added one is always the first.
|
||||||
|
return GetFirstChild();
|
||||||
|
}
|
||||||
|
|
||||||
// Principal() never returns a null pointer.
|
// Principal() never returns a null pointer.
|
||||||
inline nsIPrincipal* Principal() const;
|
inline nsIPrincipal* Principal() const;
|
||||||
|
@ -253,6 +258,13 @@ public:
|
||||||
nsresult InsertRuleIntoGroup(const nsAString& aRule,
|
nsresult InsertRuleIntoGroup(const nsAString& aRule,
|
||||||
css::GroupRule* aGroup, uint32_t aIndex);
|
css::GroupRule* aGroup, uint32_t aIndex);
|
||||||
|
|
||||||
|
template<typename Func>
|
||||||
|
void EnumerateChildSheets(Func aCallback) {
|
||||||
|
for (StyleSheet* child = GetFirstChild(); child; child = child->mNext) {
|
||||||
|
aCallback(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Get a handle to the various stylesheet bits which live on the 'inner' for
|
// Get a handle to the various stylesheet bits which live on the 'inner' for
|
||||||
// gecko stylesheets and live on the StyleSheet for Servo stylesheets.
|
// gecko stylesheets and live on the StyleSheet for Servo stylesheets.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче