Skip to content

Commit

Permalink
script: Fix base url for style-rule-owned declarations.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Jan 28, 2017
1 parent dd90366 commit 9b06932
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
5 changes: 3 additions & 2 deletions components/script/dom/csskeyframerule.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -47,8 +48,8 @@ impl CSSKeyframeRuleMethods for CSSKeyframeRule {
fn Style(&self) -> Root<CSSStyleDeclaration> {
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)
})
Expand Down
25 changes: 18 additions & 7 deletions components/script/dom/cssstyledeclaration.rs
Expand Up @@ -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;
Expand All @@ -34,7 +36,7 @@ pub struct CSSStyleDeclaration {
#[must_root]
pub enum CSSStyleOwner {
Element(JS<Element>),
CSSRule(JS<Window>,
CSSRule(JS<CSSRule>,
#[ignore_heap_size_of = "Arc"]
Arc<RwLock<PropertyDeclarationBlock>>),
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -119,7 +121,16 @@ impl CSSStyleOwner {
fn window(&self) -> Root<Window> {
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()
}
}
}
}
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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());
});
Expand Down
5 changes: 3 additions & 2 deletions components/script/dom/cssstylerule.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -58,8 +59,8 @@ impl CSSStyleRuleMethods for CSSStyleRule {
fn Style(&self) -> Root<CSSStyleDeclaration> {
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)
})
Expand Down

0 comments on commit 9b06932

Please sign in to comment.