Bug 1343964 part 7 - Use URLExtraData for declaration modification directly for Servo backend. r=heycam

MozReview-Commit-ID: 78JRYKk9hgV

--HG--
extra : rebase_source : 1a86db507451637379e35ea17d9dbd88e8dc6902
This commit is contained in:
Xidorn Quan 2017-04-04 16:09:20 +10:00
Родитель 3d5b648721
Коммит 987754e4dc
12 изменённых файлов: 89 добавлений и 9 удалений

Просмотреть файл

@ -94,9 +94,17 @@ void
ServoStyleRuleDeclaration::GetCSSParsingEnvironment(
CSSParsingEnvironment& aCSSParseEnv)
{
MOZ_ASSERT_UNREACHABLE("GetCSSParsingEnvironment "
"shouldn't be calling for a Servo rule");
GetCSSParsingEnvironmentForRule(Rule(), aCSSParseEnv);
}
URLExtraData*
ServoStyleRuleDeclaration::GetURLData() const
{
return GetURLDataForRule(Rule());
}
// -- ServoStyleRule --------------------------------------------------
ServoStyleRule::ServoStyleRule(already_AddRefed<RawServoStyleRule> aRawRule)

Просмотреть файл

@ -33,6 +33,7 @@ protected:
nsresult SetCSSDeclaration(DeclarationBlock* aDecl) final;
nsIDocument* DocToUpdate() final;
void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) final;
URLExtraData* GetURLData() const final;
private:
// For accessing the constructor.

Просмотреть файл

@ -82,6 +82,8 @@ public:
Inner()->mSheet = aSheet;
}
URLExtraData* URLData() const { return Inner()->mURLData; }
// WebIDL CSSStyleSheet API
// Can't be inline because we can't include ImportRule here. And can't be
// called GetOwnerRule because that would be ambiguous with the ImportRule

Просмотреть файл

@ -1062,6 +1062,7 @@ public:
virtual DeclarationBlock* GetCSSDeclaration(Operation aOperation) override;
virtual nsresult SetCSSDeclaration(DeclarationBlock* aDecl) override;
virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) override;
URLExtraData* GetURLData() const final;
virtual nsIDocument* DocToUpdate() override;
// Override |AddRef| and |Release| for being owned by StyleRule. Also, we
@ -1120,6 +1121,13 @@ DOMCSSDeclarationImpl::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParse
GetCSSParsingEnvironmentForRule(mRule, aCSSParseEnv);
}
URLExtraData*
DOMCSSDeclarationImpl::GetURLData() const
{
MOZ_ASSERT_UNREACHABLE("GetURLData shouldn't be calling on a Gecko rule");
return GetURLDataForRule(mRule);
}
NS_IMETHODIMP
DOMCSSDeclarationImpl::GetParentRule(nsIDOMCSSRule **aParent)
{

Просмотреть файл

@ -1602,6 +1602,13 @@ nsCSSKeyframeStyleDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment& a
GetCSSParsingEnvironmentForRule(mRule, aCSSParseEnv);
}
URLExtraData*
nsCSSKeyframeStyleDeclaration::GetURLData() const
{
MOZ_ASSERT_UNREACHABLE("GetURLData shouldn't be calling on a Gecko rule");
return GetURLDataForRule(mRule);
}
NS_IMETHODIMP
nsCSSKeyframeStyleDeclaration::GetParentRule(nsIDOMCSSRule **aParent)
{
@ -2112,6 +2119,13 @@ nsCSSPageStyleDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSP
GetCSSParsingEnvironmentForRule(mRule, aCSSParseEnv);
}
URLExtraData*
nsCSSPageStyleDeclaration::GetURLData() const
{
MOZ_ASSERT_UNREACHABLE("GetURLData shouldn't be calling on a Gecko rule");
return GetURLDataForRule(mRule);
}
NS_IMETHODIMP
nsCSSPageStyleDeclaration::GetParentRule(nsIDOMCSSRule** aParent)
{

Просмотреть файл

@ -247,6 +247,7 @@ public:
virtual mozilla::DeclarationBlock* GetCSSDeclaration(Operation aOperation) override;
virtual nsresult SetCSSDeclaration(mozilla::DeclarationBlock* aDecl) override;
virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) override;
mozilla::URLExtraData* GetURLData() const final;
virtual nsIDocument* DocToUpdate() override;
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@ -387,6 +388,7 @@ public:
virtual mozilla::DeclarationBlock* GetCSSDeclaration(Operation aOperation) override;
virtual nsresult SetCSSDeclaration(mozilla::DeclarationBlock* aDecl) override;
virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) override;
mozilla::URLExtraData* GetURLData() const final;
virtual nsIDocument* DocToUpdate() override;
NS_DECL_CYCLE_COLLECTING_ISUPPORTS

Просмотреть файл

@ -741,6 +741,13 @@ nsComputedDOMStyle::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv
aCSSParseEnv.mPrincipal = nullptr;
}
URLExtraData*
nsComputedDOMStyle::GetURLData() const
{
NS_RUNTIMEABORT("called nsComputedDOMStyle::GetURLData");
return nullptr;
}
void
nsComputedDOMStyle::ClearStyleContext()
{

Просмотреть файл

@ -136,6 +136,7 @@ public:
virtual nsresult SetCSSDeclaration(mozilla::DeclarationBlock*) override;
virtual nsIDocument* DocToUpdate() override;
virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) override;
mozilla::URLExtraData* GetURLData() const final;
static already_AddRefed<nsROCSSPrimitiveValue>
MatrixToCSSValue(const mozilla::gfx::Matrix4x4& aMatrix);

Просмотреть файл

@ -173,6 +173,12 @@ nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment& aC
aCSSParseEnv.mCSSLoader = doc->CSSLoader();
}
URLExtraData*
nsDOMCSSAttributeDeclaration::GetURLData() const
{
return mElement->GetURLDataForStyleAttr();
}
NS_IMETHODIMP
nsDOMCSSAttributeDeclaration::GetParentRule(nsIDOMCSSRule **aParent)
{

Просмотреть файл

@ -32,6 +32,7 @@ public:
// is owned by our current style rule.
virtual mozilla::DeclarationBlock* GetCSSDeclaration(Operation aOperation) override;
virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) override;
mozilla::URLExtraData* GetURLData() const final;
NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent) override;
virtual nsINode* GetParentObject() override;

Просмотреть файл

@ -117,9 +117,17 @@ nsDOMCSSDeclaration::SetCssText(const nsAString& aCssText)
}
CSSParsingEnvironment env;
GetCSSParsingEnvironment(env);
if (!env.mPrincipal) {
return NS_ERROR_NOT_AVAILABLE;
URLExtraData* urlData = nullptr;
if (olddecl->IsGecko()) {
GetCSSParsingEnvironment(env);
if (!env.mPrincipal) {
return NS_ERROR_NOT_AVAILABLE;
}
} else {
urlData = GetURLData();
if (!urlData) {
return NS_ERROR_NOT_AVAILABLE;
}
}
// For nsDOMCSSAttributeDeclaration, SetCSSDeclaration will lead to
@ -131,9 +139,7 @@ nsDOMCSSDeclaration::SetCssText(const nsAString& aCssText)
RefPtr<DeclarationBlock> newdecl;
if (olddecl->IsServo()) {
RefPtr<URLExtraData> data =
new URLExtraData(env.mBaseURI, env.mSheetURI, env.mPrincipal);
newdecl = ServoDeclarationBlock::FromCssText(aCssText, data);
newdecl = ServoDeclarationBlock::FromCssText(aCssText, urlData);
} else {
RefPtr<css::Declaration> decl(new css::Declaration());
decl->InitializeEmpty();
@ -276,6 +282,15 @@ nsDOMCSSDeclaration::GetCSSParsingEnvironmentForRule(css::Rule* aRule,
aCSSParseEnv.mCSSLoader = document ? document->CSSLoader() : nullptr;
}
/* static */ URLExtraData*
nsDOMCSSDeclaration::GetURLDataForRule(const css::Rule* aRule)
{
if (StyleSheet* sheet = aRule ? aRule->GetStyleSheet() : nullptr) {
return sheet->AsServo()->URLData();
}
return nullptr;
}
template<typename GeckoFunc, typename ServoFunc>
nsresult
nsDOMCSSDeclaration::ModifyDeclaration(GeckoFunc aGeckoFunc,
@ -287,9 +302,17 @@ nsDOMCSSDeclaration::ModifyDeclaration(GeckoFunc aGeckoFunc,
}
CSSParsingEnvironment env;
GetCSSParsingEnvironment(env);
if (!env.mPrincipal) {
return NS_ERROR_NOT_AVAILABLE;
URLExtraData* urlData = nullptr;
if (olddecl->IsGecko()) {
GetCSSParsingEnvironment(env);
if (!env.mPrincipal) {
return NS_ERROR_NOT_AVAILABLE;
}
} else {
urlData = GetURLData();
if (!urlData) {
return NS_ERROR_NOT_AVAILABLE;
}
}
// For nsDOMCSSAttributeDeclaration, SetCSSDeclaration will lead to

Просмотреть файл

@ -156,6 +156,13 @@ protected:
static void GetCSSParsingEnvironmentForRule(mozilla::css::Rule* aRule,
CSSParsingEnvironment& aCSSParseEnv);
// An implementation for GetURLData for callers wrapping a css::Rule.
static mozilla::URLExtraData* GetURLDataForRule(const mozilla::css::Rule* aRule);
// Returns URL data for parsing url values in CSS.
// Returns nullptr on failure.
virtual mozilla::URLExtraData* GetURLData() const = 0;
nsresult ParsePropertyValue(const nsCSSPropertyID aPropID,
const nsAString& aPropValue,
bool aIsImportant);