diff options
author | Patrick Walton <pcwalton@mimiga.net> | 2014-12-07 22:59:38 -0800 |
---|---|---|
committer | Patrick Walton <pcwalton@mimiga.net> | 2014-12-15 17:41:44 -0800 |
commit | 14bafb11bec973cd1362ff38a8e4aa2385c6ff37 (patch) | |
tree | e1dd41c6f1a2829e2be800cb27e7bdd4ee5f0a4f /components/script/dom/element.rs | |
parent | 10f1ed5e311e7092d3e24b58c4960f5e8a511ac0 (diff) | |
download | servo-14bafb11bec973cd1362ff38a8e4aa2385c6ff37.tar.gz servo-14bafb11bec973cd1362ff38a8e4aa2385c6ff37.zip |
style: Parse the legacy `bgcolor` attribute per the HTML5 specification.
Additionally, this patch cleans up some miscellaneous formatting issues.
Diffstat (limited to 'components/script/dom/element.rs')
-rw-r--r-- | components/script/dom/element.rs | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index db2b8d3d096..0cdf78b697d 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -16,9 +16,10 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods; use dom::bindings::codegen::InheritTypes::{ElementCast, ElementDerived, EventTargetCast}; -use dom::bindings::codegen::InheritTypes::{HTMLInputElementCast, HTMLInputElementDerived}; -use dom::bindings::codegen::InheritTypes::{HTMLTableElementCast, HTMLTableElementDerived}; -use dom::bindings::codegen::InheritTypes::{HTMLTableCellElementDerived, NodeCast}; +use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLInputElementCast}; +use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLTableElementCast}; +use dom::bindings::codegen::InheritTypes::{HTMLTableElementDerived, HTMLTableCellElementDerived}; +use dom::bindings::codegen::InheritTypes::{NodeCast}; use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, TemporaryPushable}; use dom::bindings::js::{OptionalRootable, Root}; use dom::bindings::utils::{Reflectable, Reflector}; @@ -31,6 +32,7 @@ use dom::document::{Document, DocumentHelpers, LayoutDocumentHelpers}; use dom::domtokenlist::DOMTokenList; use dom::event::Event; use dom::eventtarget::{EventTarget, NodeTargetTypeId, EventTargetHelpers}; +use dom::htmlbodyelement::{HTMLBodyElement, HTMLBodyElementHelpers}; use dom::htmlcollection::HTMLCollection; use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers}; use dom::htmlserializer::serialize; @@ -42,12 +44,11 @@ use dom::node::{window_from_node}; use dom::nodelist::NodeList; use dom::virtualmethods::{VirtualMethods, vtable_for}; use devtools_traits::AttrInfo; -use style::{BorderUnsignedIntegerAttribute, IntegerAttribute, LengthAttribute}; -use style::{SizeIntegerAttribute, UnsignedIntegerAttribute, WidthLengthAttribute}; -use style::{matches, parse_selector_list_from_str}; -use style; +use style::{mod, BgColorSimpleColorAttribute, BorderUnsignedIntegerAttribute, IntegerAttribute}; +use style::{LengthAttribute, SimpleColorAttribute, SizeIntegerAttribute, UnsignedIntegerAttribute}; +use style::{WidthLengthAttribute, matches, parse_selector_list_from_str}; use servo_util::namespace; -use servo_util::str::{DOMString, LengthOrPercentageOrAuto}; +use servo_util::str::{DOMString, LengthOrPercentageOrAuto, SimpleColor}; use std::ascii::AsciiExt; use std::cell::{Ref, RefMut}; @@ -207,6 +208,8 @@ pub trait RawLayoutElementHelpers { unsafe fn get_checked_state_for_layout(&self) -> bool; unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute) -> Option<u32>; + unsafe fn get_simple_color_attribute_for_layout(&self, attribute: SimpleColorAttribute) + -> Option<SimpleColor>; fn local_name<'a>(&'a self) -> &'a Atom; fn namespace<'a>(&'a self) -> &'a Namespace; fn style_attribute<'a>(&'a self) -> &'a DOMRefCell<Option<style::PropertyDeclarationBlock>>; @@ -349,6 +352,28 @@ impl RawLayoutElementHelpers for Element { } } + #[inline] + #[allow(unrooted_must_root)] + unsafe fn get_simple_color_attribute_for_layout(&self, attribute: SimpleColorAttribute) + -> Option<SimpleColor> { + match attribute { + BgColorSimpleColorAttribute => { + if self.is_htmlbodyelement() { + let this: &HTMLBodyElement = mem::transmute(self); + this.get_background_color() + } else if self.is_htmltableelement() { + let this: &HTMLTableElement = mem::transmute(self); + this.get_background_color() + } else if self.is_htmltablecellelement() { + let this: &HTMLTableCellElement = mem::transmute(self); + this.get_background_color() + } else { + panic!("I'm not a body, table, or table cell!") + } + } + } + } + // Getters used in components/layout/wrapper.rs fn local_name<'a>(&'a self) -> &'a Atom { |