diff options
author | Ms2ger <ms2ger@gmail.com> | 2015-04-26 22:22:12 +0200 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2015-04-26 22:25:11 +0200 |
commit | e3440c8a593b4b64908f0ca42b5d17c82965a7f4 (patch) | |
tree | aead8f47ed499363ad05bd39c25235967096432e /components | |
parent | 582ee1c2b3eced29a942ac692943a8b8a093e46f (diff) | |
download | servo-e3440c8a593b4b64908f0ca42b5d17c82965a7f4.tar.gz servo-e3440c8a593b4b64908f0ca42b5d17c82965a7f4.zip |
Move bgcolor over to the new infrastructure.
Note that I call is_htmltabledatacellelement in
synthesize_presentational_hints_for_legacy_attributes, rather than
is_htmltablecellelement (which was used in
get_simple_color_attribute_for_layout), because that function was never called
for th elements.
Diffstat (limited to 'components')
-rw-r--r-- | components/layout/wrapper.rs | 9 | ||||
-rw-r--r-- | components/script/dom/element.rs | 64 | ||||
-rw-r--r-- | components/style/legacy.rs | 58 | ||||
-rw-r--r-- | components/style/node.rs | 4 |
4 files changed, 33 insertions, 102 deletions
diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 7d919f49f29..d572475abc6 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -39,7 +39,6 @@ use incremental::RestyleDamage; use data::{LayoutDataAccess, LayoutDataFlags, LayoutDataWrapper, PrivateLayoutData}; use opaque_node::OpaqueNodeMethods; -use cssparser::RGBA; use gfx::display_list::OpaqueNode; use script::dom::bindings::codegen::InheritTypes::{CharacterDataCast, ElementCast}; use script::dom::bindings::codegen::InheritTypes::{HTMLIFrameElementCast, HTMLCanvasElementCast}; @@ -73,7 +72,7 @@ use style::computed_values::{content, display, white_space}; use selectors::matching::DeclarationBlock; use selectors::parser::{NamespaceConstraint, AttrSelector}; use selectors::smallvec::VecLike; -use style::legacy::{IntegerAttribute, LengthAttribute, SimpleColorAttribute}; +use style::legacy::{IntegerAttribute, LengthAttribute}; use style::legacy::{UnsignedIntegerAttribute}; use style::node::{TElement, TElementAttributes, TNode}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; @@ -686,12 +685,6 @@ impl<'le> TElementAttributes for LayoutElement<'le> { self.element.get_unsigned_integer_attribute_for_layout(attribute) } } - - fn get_simple_color_attribute(self, attribute: SimpleColorAttribute) -> Option<RGBA> { - unsafe { - self.element.get_simple_color_attribute_for_layout(attribute) - } - } } fn get_content(content_list: &content::T) -> Vec<ContentItem> { diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 4e6644f0a97..74bf0cb5feb 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -23,6 +23,7 @@ use dom::bindings::codegen::InheritTypes::{HTMLTableElementDerived, HTMLTableCel use dom::bindings::codegen::InheritTypes::{HTMLTableRowElementDerived, HTMLTextAreaElementDerived}; use dom::bindings::codegen::InheritTypes::{HTMLTableSectionElementDerived, NodeCast}; use dom::bindings::codegen::InheritTypes::HTMLAnchorElementCast; +use dom::bindings::codegen::InheritTypes::HTMLTableDataCellElementDerived; use dom::bindings::codegen::UnionTypes::NodeOrString; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::error::Error::{InvalidCharacter, Syntax}; @@ -57,12 +58,14 @@ use dom::virtualmethods::{VirtualMethods, vtable_for}; use devtools_traits::AttrInfo; use style; -use style::legacy::{SimpleColorAttribute, UnsignedIntegerAttribute, IntegerAttribute, LengthAttribute}; +use style::legacy::{UnsignedIntegerAttribute, IntegerAttribute, LengthAttribute, from_declaration}; use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, parse_style_attribute}; +use style::properties::DeclaredValue::SpecifiedValue; +use style::values::specified::CSSColor; use util::namespace; use util::str::{DOMString, LengthOrPercentageOrAuto}; -use cssparser::RGBA; +use cssparser::Color; use html5ever::serialize; use html5ever::serialize::SerializeOpts; use html5ever::serialize::TraversalScope; @@ -167,8 +170,7 @@ pub trait RawLayoutElementHelpers { unsafe fn get_indeterminate_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<RGBA>; + fn local_name<'a>(&'a self) -> &'a Atom; fn namespace<'a>(&'a self) -> &'a Namespace; fn style_attribute<'a>(&'a self) -> &'a DOMRefCell<Option<PropertyDeclarationBlock>>; @@ -231,9 +233,33 @@ impl RawLayoutElementHelpers for Element { }) } - unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, _: &mut V) + unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V) where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> { + let bgcolor = 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_htmltabledatacellelement() { + let this: &HTMLTableCellElement = mem::transmute(self); + this.get_background_color() + } else if self.is_htmltablerowelement() { + let this: &HTMLTableRowElement = mem::transmute(self); + this.get_background_color() + } else if self.is_htmltablesectionelement() { + let this: &HTMLTableSectionElement = mem::transmute(self); + this.get_background_color() + } else { + None + }; + + if let Some(color) = bgcolor { + hints.vec_push(from_declaration( + PropertyDeclaration::BackgroundColor(SpecifiedValue( + CSSColor { parsed: Color::RGBA(color), authored: None })))); + } } #[inline] @@ -342,34 +368,6 @@ impl RawLayoutElementHelpers for Element { } } - #[inline] - #[allow(unrooted_must_root)] - unsafe fn get_simple_color_attribute_for_layout(&self, attribute: SimpleColorAttribute) - -> Option<RGBA> { - match attribute { - SimpleColorAttribute::BgColor => { - 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 if self.is_htmltablerowelement() { - let this: &HTMLTableRowElement = mem::transmute(self); - this.get_background_color() - } else if self.is_htmltablesectionelement() { - let this: &HTMLTableSectionElement = mem::transmute(self); - this.get_background_color() - } else { - None - } - } - } - } - // Getters used in components/layout/wrapper.rs fn local_name<'a>(&'a self) -> &'a Atom { diff --git a/components/style/legacy.rs b/components/style/legacy.rs index a44193c8390..2cf4d9d2a60 100644 --- a/components/style/legacy.rs +++ b/components/style/legacy.rs @@ -10,14 +10,12 @@ use std::sync::Arc; use selectors::tree::{TElement, TNode}; use selectors::matching::DeclarationBlock; use node::TElementAttributes; -use values::specified::CSSColor; use values::{CSSFloat, specified}; use properties::DeclaredValue::SpecifiedValue; use properties::PropertyDeclaration; use properties::longhands::{self, border_spacing}; use selector_matching::Stylist; -use cssparser::Color; use selectors::smallvec::VecLike; use util::geometry::Au; use util::str::LengthOrPercentageOrAuto; @@ -49,13 +47,6 @@ pub enum UnsignedIntegerAttribute { ColSpan, } -/// Legacy presentational attributes that take a simple color as defined in HTML5 § 2.4.6. -#[derive(Copy, PartialEq, Eq)] -pub enum SimpleColorAttribute { - /// `<body bgcolor>` - BgColor, -} - /// Extension methods for `Stylist` that cause rules to be synthesized for legacy attributes. pub trait PresentationalHintSynthesis { /// Synthesizes rules from various HTML attributes (mostly legacy junk from HTML4) that confer @@ -74,18 +65,6 @@ pub trait PresentationalHintSynthesis { where N: TNode<'a>, N::Element: TElementAttributes, V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>; - /// Synthesizes rules for the legacy `bgcolor` attribute. - fn synthesize_presentational_hint_for_legacy_background_color_attribute<'a,E,V>( - &self, - element: E, - matching_rules_list: - &mut V, - shareable: &mut bool) - where - E: TElement<'a> + - TElementAttributes, - V: VecLike< - DeclarationBlock<Vec<PropertyDeclaration>>>; /// Synthesizes rules for the legacy `border` attribute. fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>( &self, @@ -133,20 +112,12 @@ impl PresentationalHintSynthesis for Stylist { *shareable = false } } - self.synthesize_presentational_hint_for_legacy_background_color_attribute( - element, - matching_rules_list, - shareable); self.synthesize_presentational_hint_for_legacy_border_attribute( element, matching_rules_list, shareable); } name if *name == atom!("table") => { - self.synthesize_presentational_hint_for_legacy_background_color_attribute( - element, - matching_rules_list, - shareable); self.synthesize_presentational_hint_for_legacy_border_attribute( element, matching_rules_list, @@ -167,13 +138,6 @@ impl PresentationalHintSynthesis for Stylist { } } } - name if *name == atom!("body") || *name == atom!("tr") || *name == atom!("thead") || - *name == atom!("tbody") || *name == atom!("tfoot") => { - self.synthesize_presentational_hint_for_legacy_background_color_attribute( - element, - matching_rules_list, - shareable); - } name if *name == atom!("input") => { // FIXME(pcwalton): More use of atoms, please! match element.get_attr(&ns!(""), &atom!("type")) { @@ -228,28 +192,6 @@ impl PresentationalHintSynthesis for Stylist { } } - fn synthesize_presentational_hint_for_legacy_background_color_attribute<'a,E,V>( - &self, - element: E, - matching_rules_list: - &mut V, - shareable: &mut bool) - where - E: TElement<'a> + - TElementAttributes, - V: VecLike< - DeclarationBlock<Vec<PropertyDeclaration>>> { - match element.get_simple_color_attribute(SimpleColorAttribute::BgColor) { - None => {} - Some(color) => { - matching_rules_list.vec_push(from_declaration( - PropertyDeclaration::BackgroundColor(SpecifiedValue( - CSSColor { parsed: Color::RGBA(color), authored: None })))); - *shareable = false - } - } - } - fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>( &self, element: E, diff --git a/components/style/node.rs b/components/style/node.rs index 4e667ef1286..6d2c84ac8cc 100644 --- a/components/style/node.rs +++ b/components/style/node.rs @@ -5,8 +5,7 @@ //! Traits that nodes must implement. Breaks the otherwise-cyclic dependency between layout and //! style. -use cssparser::RGBA; -use legacy::{IntegerAttribute, LengthAttribute, SimpleColorAttribute, UnsignedIntegerAttribute}; +use legacy::{IntegerAttribute, LengthAttribute, UnsignedIntegerAttribute}; use properties::PropertyDeclaration; use util::str::LengthOrPercentageOrAuto; @@ -20,5 +19,4 @@ pub trait TElementAttributes : Copy { fn get_length_attribute(self, attribute: LengthAttribute) -> LengthOrPercentageOrAuto; fn get_integer_attribute(self, attribute: IntegerAttribute) -> Option<i32>; fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option<u32>; - fn get_simple_color_attribute(self, attribute: SimpleColorAttribute) -> Option<RGBA>; } |