From 9b069325357ae139b8655117b61d26f63e70a200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 27 Jan 2017 19:39:00 +0100 Subject: [PATCH] script: Fix base url for style-rule-owned declarations. --- components/script/dom/csskeyframerule.rs | 5 ++-- components/script/dom/cssstyledeclaration.rs | 25 ++++++++++++++------ components/script/dom/cssstylerule.rs | 5 ++-- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/components/script/dom/csskeyframerule.rs b/components/script/dom/csskeyframerule.rs index 9d245d98343c..db0a88edc6fc 100644 --- a/components/script/dom/csskeyframerule.rs +++ b/components/script/dom/csskeyframerule.rs @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::Bindings::CSSKeyframeRuleBinding::{self, CSSKeyframeRuleMethods}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableJS, Root}; use dom::bindings::reflector::{DomObject, reflect_dom_object}; use dom::bindings::str::DOMString; @@ -47,8 +48,8 @@ impl CSSKeyframeRuleMethods for CSSKeyframeRule { fn Style(&self) -> Root { self.style_decl.or_init(|| { CSSStyleDeclaration::new(self.global().as_window(), - CSSStyleOwner::CSSRule(JS::from_ref(self.global().as_window()), - self.keyframerule.read().block.clone()), + CSSStyleOwner::CSSRule(JS::from_ref(self.upcast()), + self.keyframerule.read().block.clone()), None, CSSModificationAccess::ReadWrite) }) diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index de6deaf7e114..1af030613b96 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -7,12 +7,14 @@ use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root}; -use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::str::DOMString; +use dom::cssrule::CSSRule; use dom::element::Element; use dom::node::{Node, NodeDamage, window_from_node}; use dom::window::Window; use parking_lot::RwLock; +use servo_url::ServoUrl; use std::ascii::AsciiExt; use std::sync::Arc; use style::parser::ParserContextExtraData; @@ -34,7 +36,7 @@ pub struct CSSStyleDeclaration { #[must_root] pub enum CSSStyleOwner { Element(JS), - CSSRule(JS, + CSSRule(JS, #[ignore_heap_size_of = "Arc"] Arc>), } @@ -84,10 +86,10 @@ impl CSSStyleOwner { } result } - CSSStyleOwner::CSSRule(ref win, ref pdb) => { + CSSStyleOwner::CSSRule(ref rule, ref pdb) => { let result = f(&mut *pdb.write(), &mut changed); if changed { - win.Document().invalidate_stylesheets(); + rule.global().as_window().Document().invalidate_stylesheets(); } result } @@ -119,7 +121,16 @@ impl CSSStyleOwner { fn window(&self) -> Root { match *self { CSSStyleOwner::Element(ref el) => window_from_node(&**el), - CSSStyleOwner::CSSRule(ref window, _) => Root::from_ref(&**window), + CSSStyleOwner::CSSRule(ref rule, _) => Root::from_ref(rule.global().as_window()), + } + } + + fn base_url(&self) -> ServoUrl { + match *self { + CSSStyleOwner::Element(ref el) => window_from_node(&**el).get_url(), + CSSStyleOwner::CSSRule(ref rule, _) => { + rule.parent_stylesheet().style_stylesheet().base_url.clone() + } } } } @@ -228,7 +239,7 @@ impl CSSStyleDeclaration { // Step 6 let window = self.owner.window(); let declarations = - parse_one_declaration(id, &value, &window.get_url(), + parse_one_declaration(id, &value, &self.owner.base_url(), window.css_error_reporter(), ParserContextExtraData::default()); @@ -414,7 +425,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { self.owner.mutate_associated_block(|mut pdb, mut _changed| { // Step 3 *pdb = parse_style_attribute(&value, - &window.get_url(), + &self.owner.base_url(), window.css_error_reporter(), ParserContextExtraData::default()); }); diff --git a/components/script/dom/cssstylerule.rs b/components/script/dom/cssstylerule.rs index 1eb6e74df8b4..5bd40dbe88ca 100644 --- a/components/script/dom/cssstylerule.rs +++ b/components/script/dom/cssstylerule.rs @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::Bindings::CSSStyleRuleBinding::{self, CSSStyleRuleMethods}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableJS, Root}; use dom::bindings::reflector::{DomObject, reflect_dom_object}; use dom::bindings::str::DOMString; @@ -58,8 +59,8 @@ impl CSSStyleRuleMethods for CSSStyleRule { fn Style(&self) -> Root { self.style_decl.or_init(|| { CSSStyleDeclaration::new(self.global().as_window(), - CSSStyleOwner::CSSRule(JS::from_ref(self.global().as_window()), - self.stylerule.read().block.clone()), + CSSStyleOwner::CSSRule(JS::from_ref(self.upcast()), + self.stylerule.read().block.clone()), None, CSSModificationAccess::ReadWrite) })