diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-04-07 16:03:25 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-04-09 18:15:53 +0800 |
commit | 53cad6227edcb1dc25fbad3e8afbb2b52a647b85 (patch) | |
tree | 4c5a2ab8b22165c656c9be6c6aa97910e0bca2b5 /components/script/dom | |
parent | df29d02026fce1dee57cbd6720c24a4c74f70d48 (diff) | |
download | servo-53cad6227edcb1dc25fbad3e8afbb2b52a647b85.tar.gz servo-53cad6227edcb1dc25fbad3e8afbb2b52a647b85.zip |
script: Map HTMLCanvasElement width and height attributes.
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/document.rs | 9 | ||||
-rw-r--r-- | components/script/dom/element.rs | 16 | ||||
-rw-r--r-- | components/script/dom/htmlcanvaselement.rs | 24 |
3 files changed, 46 insertions, 3 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 8dd3cd17aec..ee79d710563 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -133,7 +133,7 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use style::attr::AttrValue; use style::context::{QuirksMode, ReflowGoal}; -use style::restyle_hints::{RestyleHint, RESTYLE_STYLE_ATTRIBUTE}; +use style::restyle_hints::{RestyleHint, RESTYLE_SELF, RESTYLE_STYLE_ATTRIBUTE}; use style::selector_parser::{RestyleDamage, Snapshot}; use style::shared_lock::SharedRwLock as StyleSharedRwLock; use style::str::{HTML_SPACE_CHARACTERS, split_html_space_chars, str_join}; @@ -2355,6 +2355,13 @@ impl Document { entry.hint |= RESTYLE_STYLE_ATTRIBUTE; } + // FIXME(emilio): This should become something like + // element.is_attribute_mapped(attr.local_name()). + if attr.local_name() == &local_name!("width") || + attr.local_name() == &local_name!("height") { + entry.hint |= RESTYLE_SELF; + } + let mut snapshot = entry.snapshot.as_mut().unwrap(); if snapshot.attrs.is_none() { let attrs = el.attrs() diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 311d0500d3f..4b3a6010a9a 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -41,6 +41,7 @@ use dom::eventtarget::EventTarget; use dom::htmlanchorelement::HTMLAnchorElement; use dom::htmlbodyelement::{HTMLBodyElement, HTMLBodyElementLayoutHelpers}; use dom::htmlbuttonelement::HTMLButtonElement; +use dom::htmlcanvaselement::{HTMLCanvasElement, LayoutHTMLCanvasElementHelpers}; use dom::htmlcollection::HTMLCollection; use dom::htmlelement::HTMLElement; use dom::htmlfieldsetelement::HTMLFieldSetElement; @@ -381,6 +382,7 @@ impl LayoutElementHelpers for LayoutJS<Element> { unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V) where V: Push<ApplicableDeclarationBlock> { + // FIXME(emilio): Just a single PDB should be enough. #[inline] fn from_declaration(shared_lock: &SharedRwLock, declaration: PropertyDeclaration) -> ApplicableDeclarationBlock { @@ -541,10 +543,13 @@ impl LayoutElementHelpers for LayoutJS<Element> { } else if let Some(this) = self.downcast::<HTMLHRElement>() { // https://html.spec.whatwg.org/multipage/#the-hr-element-2:attr-hr-width this.get_width() + } else if let Some(this) = self.downcast::<HTMLCanvasElement>() { + this.get_width() } else { LengthOrPercentageOrAuto::Auto }; + // FIXME(emilio): Use from_computed value here and below. match width { LengthOrPercentageOrAuto::Auto => {} LengthOrPercentageOrAuto::Percentage(percentage) => { @@ -568,6 +573,8 @@ impl LayoutElementHelpers for LayoutJS<Element> { this.get_height() } else if let Some(this) = self.downcast::<HTMLImageElement>() { this.get_height() + } else if let Some(this) = self.downcast::<HTMLCanvasElement>() { + this.get_height() } else { LengthOrPercentageOrAuto::Auto }; @@ -2231,7 +2238,14 @@ impl VirtualMethods for Element { } } }, - _ => {}, + _ => { + // FIXME(emilio): This is pretty dubious, and should be done in + // the relevant super-classes. + if attr.namespace() == &ns!() && + attr.local_name() == &local_name!("src") { + node.dirty(NodeDamage::OtherNodeDamage); + } + }, }; // Make sure we rev the version even if we didn't dirty the node. If we diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index dad4ebcc207..577537b421f 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -36,7 +36,7 @@ use js::jsapi::{HandleValue, JSContext}; use offscreen_gl_context::GLContextAttributes; use script_layout_interface::HTMLCanvasData; use std::iter::repeat; -use style::attr::AttrValue; +use style::attr::{AttrValue, LengthOrPercentageOrAuto}; const DEFAULT_WIDTH: u32 = 300; const DEFAULT_HEIGHT: u32 = 150; @@ -97,6 +97,8 @@ impl HTMLCanvasElement { pub trait LayoutHTMLCanvasElementHelpers { fn data(&self) -> HTMLCanvasData; + fn get_width(&self) -> LengthOrPercentageOrAuto; + fn get_height(&self) -> LengthOrPercentageOrAuto; } impl LayoutHTMLCanvasElementHelpers for LayoutJS<HTMLCanvasElement> { @@ -124,6 +126,26 @@ impl LayoutHTMLCanvasElementHelpers for LayoutJS<HTMLCanvasElement> { } } } + + #[allow(unsafe_code)] + fn get_width(&self) -> LengthOrPercentageOrAuto { + unsafe { + (&*self.upcast::<Element>().unsafe_get()) + .get_attr_for_layout(&ns!(), &local_name!("width")) + .map(AttrValue::as_uint_px_dimension) + .unwrap_or(LengthOrPercentageOrAuto::Auto) + } + } + + #[allow(unsafe_code)] + fn get_height(&self) -> LengthOrPercentageOrAuto { + unsafe { + (&*self.upcast::<Element>().unsafe_get()) + .get_attr_for_layout(&ns!(), &local_name!("height")) + .map(AttrValue::as_uint_px_dimension) + .unwrap_or(LengthOrPercentageOrAuto::Auto) + } + } } |