From 83f4b077eb37733bf2be22e315f0e0569b284c62 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 28 Apr 2015 11:43:48 +0200 Subject: [PATCH 1/4] Move table cellspacing to the new infrastructure. --- components/script/dom/element.rs | 32 +++++++++++++++++++++----------- components/style/legacy.rs | 19 +------------------ 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 4989039802d..c12abc32c96 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -62,7 +62,9 @@ use style; 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 style::properties::longhands::border_spacing; +use style::values::specified::{self, CSSColor}; +use util::geometry::Au; use util::namespace; use util::smallvec::VecLike; use util::str::{DOMString, LengthOrPercentageOrAuto}; @@ -260,6 +262,24 @@ impl RawLayoutElementHelpers for Element { PropertyDeclaration::BackgroundColor(SpecifiedValue( CSSColor { parsed: Color::RGBA(color), authored: None })))); } + + + let cellspacing = if self.is_htmltableelement() { + let this: &HTMLTableElement = mem::transmute(self); + this.get_cellspacing() + } else { + None + }; + + if let Some(cellspacing) = cellspacing { + let width_value = specified::Length::Absolute(Au::from_px(cellspacing as i32)); + hints.push(from_declaration( + PropertyDeclaration::BorderSpacing(SpecifiedValue( + border_spacing::SpecifiedValue { + horizontal: width_value, + vertical: width_value, + })))); + } } #[inline] @@ -345,16 +365,6 @@ impl RawLayoutElementHelpers for Element { None } } - UnsignedIntegerAttribute::CellSpacing => { - if self.is_htmltableelement() { - let this: &HTMLTableElement = mem::transmute(self); - this.get_cellspacing() - } else { - // Don't panic since `display` can cause this to be called on arbitrary - // elements. - None - } - } UnsignedIntegerAttribute::ColSpan => { if self.is_htmltablecellelement() { let this: &HTMLTableCellElement = mem::transmute(self); diff --git a/components/style/legacy.rs b/components/style/legacy.rs index b10376981a8..57343341e29 100644 --- a/components/style/legacy.rs +++ b/components/style/legacy.rs @@ -13,7 +13,7 @@ use node::TElementAttributes; use values::{CSSFloat, specified}; use properties::DeclaredValue::SpecifiedValue; use properties::PropertyDeclaration; -use properties::longhands::{self, border_spacing}; +use properties::longhands; use selector_matching::Stylist; use util::geometry::Au; @@ -41,8 +41,6 @@ pub enum IntegerAttribute { pub enum UnsignedIntegerAttribute { /// `` Border, - /// `` - CellSpacing, /// `
` ColSpan, } @@ -123,21 +121,6 @@ impl PresentationalHintSynthesis for Stylist { element, matching_rules_list, shareable); - match element.get_unsigned_integer_attribute( - UnsignedIntegerAttribute::CellSpacing) { - None => {} - Some(length) => { - let width_value = specified::Length::Absolute(Au::from_px(length as i32)); - matching_rules_list.push(from_declaration( - PropertyDeclaration::BorderSpacing( - SpecifiedValue( - border_spacing::SpecifiedValue { - horizontal: width_value, - vertical: width_value, - })))); - *shareable = false - } - } } name if *name == atom!("input") => { // FIXME(pcwalton): More use of atoms, please! From 0c8e55bff1983e03979435ef7cb7053c18a031a3 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 28 Apr 2015 14:26:03 +0200 Subject: [PATCH 2/4] Move input size to the new infrastructure. --- components/script/dom/element.rs | 34 +++++++++++++++++++++++++------- components/style/legacy.rs | 21 -------------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index c12abc32c96..4fbb432614c 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -280,6 +280,33 @@ impl RawLayoutElementHelpers for Element { vertical: width_value, })))); } + + + let size = if self.is_htmlinputelement() { + // FIXME(pcwalton): More use of atoms, please! + // FIXME(Ms2ger): this is nonsense! Invalid values also end up as + // a text field + match self.get_attr_val_for_layout(&ns!(""), &atom!("type")) { + Some("text") | Some("password") => { + let this: &HTMLInputElement = mem::transmute(self); + match this.get_size_for_layout() { + 0 => None, + s => Some(s as i32), + } + } + _ => None + } + } else { + None + }; + + if let Some(size) = size { + let value = specified::Length::ServoCharacterWidth( + specified::CharacterWidth(size)); + hints.push(from_declaration( + PropertyDeclaration::Width(SpecifiedValue( + specified::LengthOrPercentageOrAuto::Length(value))))); + } } #[inline] @@ -304,13 +331,6 @@ impl RawLayoutElementHelpers for Element { unsafe fn get_integer_attribute_for_layout(&self, integer_attribute: IntegerAttribute) -> Option { match integer_attribute { - IntegerAttribute::Size => { - if !self.is_htmlinputelement() { - panic!("I'm not a form input!") - } - let this: &HTMLInputElement = mem::transmute(self); - Some(this.get_size_for_layout() as i32) - } IntegerAttribute::Cols => { if !self.is_htmltextareaelement() { panic!("I'm not a textarea element!") diff --git a/components/style/legacy.rs b/components/style/legacy.rs index 57343341e29..8c4ed130916 100644 --- a/components/style/legacy.rs +++ b/components/style/legacy.rs @@ -30,8 +30,6 @@ pub enum LengthAttribute { /// Legacy presentational attributes that take an integer as defined in HTML5 § 2.4.4.2. #[derive(Copy, Clone, PartialEq, Eq)] pub enum IntegerAttribute { - /// `` - Size, Cols, Rows, } @@ -122,25 +120,6 @@ impl PresentationalHintSynthesis for Stylist { matching_rules_list, shareable); } - name if *name == atom!("input") => { - // FIXME(pcwalton): More use of atoms, please! - match element.get_attr(&ns!(""), &atom!("type")) { - Some("text") | Some("password") => { - match element.get_integer_attribute(IntegerAttribute::Size) { - Some(value) if value != 0 => { - let value = specified::Length::ServoCharacterWidth( - specified::CharacterWidth(value)); - matching_rules_list.push(from_declaration( - PropertyDeclaration::Width(SpecifiedValue( - specified::LengthOrPercentageOrAuto::Length(value))))); - *shareable = false - } - Some(_) | None => {} - } - } - _ => {} - }; - } name if *name == atom!("textarea") => { match element.get_integer_attribute(IntegerAttribute::Cols) { Some(value) if value != 0 => { From f571a69b2e02535cf240700463181b9221a56c25 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 8 May 2015 21:24:31 +0200 Subject: [PATCH 3/4] Move table/td width to the new infrastructure. --- components/layout/wrapper.rs | 11 ++----- components/script/dom/element.rs | 41 ++++++++++++++------------ components/style/legacy.rs | 49 -------------------------------- components/style/node.rs | 4 +-- 4 files changed, 26 insertions(+), 79 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 33e343df99f..c6549fde57c 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -60,7 +60,7 @@ use script::dom::node::{HAS_CHANGED, IS_DIRTY, HAS_DIRTY_SIBLINGS, HAS_DIRTY_DES use script::dom::text::Text; use script::layout_interface::LayoutChan; use msg::constellation_msg::{PipelineId, SubpageId}; -use util::str::{LengthOrPercentageOrAuto, is_whitespace}; +use util::str::is_whitespace; use std::borrow::ToOwned; use std::cell::{Ref, RefMut}; use std::marker::PhantomData; @@ -71,8 +71,7 @@ use style::computed_values::content::ContentItem; use style::computed_values::{content, display, white_space}; use selectors::matching::DeclarationBlock; use selectors::parser::{NamespaceConstraint, AttrSelector}; -use style::legacy::{IntegerAttribute, LengthAttribute}; -use style::legacy::{UnsignedIntegerAttribute}; +use style::legacy::{IntegerAttribute, UnsignedIntegerAttribute}; use style::node::{TElement, TElementAttributes, TNode}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use util::smallvec::VecLike; @@ -657,12 +656,6 @@ impl<'le> TElementAttributes<'le> for LayoutElement<'le> { } } - fn get_length_attribute(self, length_attribute: LengthAttribute) -> LengthOrPercentageOrAuto { - unsafe { - self.element.get_length_attribute_for_layout(length_attribute) - } - } - fn get_integer_attribute(self, integer_attribute: IntegerAttribute) -> Option { unsafe { self.element.get_integer_attribute_for_layout(integer_attribute) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 4fbb432614c..5034da72235 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -59,7 +59,7 @@ use dom::virtualmethods::{VirtualMethods, vtable_for}; use devtools_traits::AttrInfo; use style; -use style::legacy::{UnsignedIntegerAttribute, IntegerAttribute, LengthAttribute, from_declaration}; +use style::legacy::{UnsignedIntegerAttribute, IntegerAttribute, from_declaration}; use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, parse_style_attribute}; use style::properties::DeclaredValue::SpecifiedValue; use style::properties::longhands::border_spacing; @@ -164,8 +164,6 @@ pub trait RawLayoutElementHelpers { unsafe fn synthesize_presentational_hints_for_legacy_attributes(&self, &mut V) where V: VecLike>>; - unsafe fn get_length_attribute_for_layout(&self, length_attribute: LengthAttribute) - -> LengthOrPercentageOrAuto; unsafe fn get_integer_attribute_for_layout(&self, integer_attribute: IntegerAttribute) -> Option; unsafe fn get_checked_state_for_layout(&self) -> bool; @@ -307,22 +305,29 @@ impl RawLayoutElementHelpers for Element { PropertyDeclaration::Width(SpecifiedValue( specified::LengthOrPercentageOrAuto::Length(value))))); } - } - #[inline] - unsafe fn get_length_attribute_for_layout(&self, length_attribute: LengthAttribute) - -> LengthOrPercentageOrAuto { - match length_attribute { - LengthAttribute::Width => { - if self.is_htmltableelement() { - let this: &HTMLTableElement = mem::transmute(self); - this.get_width() - } else if self.is_htmltablecellelement() { - let this: &HTMLTableCellElement = mem::transmute(self); - this.get_width() - } else { - panic!("I'm not a table or table cell!") - } + + let width = if self.is_htmltableelement() { + let this: &HTMLTableElement = mem::transmute(self); + this.get_width() + } else if self.is_htmltabledatacellelement() { + let this: &HTMLTableCellElement = mem::transmute(self); + this.get_width() + } else { + LengthOrPercentageOrAuto::Auto + }; + + match width { + LengthOrPercentageOrAuto::Auto => {} + LengthOrPercentageOrAuto::Percentage(percentage) => { + let width_value = specified::LengthOrPercentageOrAuto::Percentage(percentage); + hints.push(from_declaration( + PropertyDeclaration::Width(SpecifiedValue(width_value)))); + } + LengthOrPercentageOrAuto::Length(length) => { + let width_value = specified::LengthOrPercentageOrAuto::Length(specified::Length::Absolute(length)); + hints.push(from_declaration( + PropertyDeclaration::Width(SpecifiedValue(width_value)))); } } } diff --git a/components/style/legacy.rs b/components/style/legacy.rs index 8c4ed130916..18b28ec7fa5 100644 --- a/components/style/legacy.rs +++ b/components/style/legacy.rs @@ -18,14 +18,6 @@ use selector_matching::Stylist; use util::geometry::Au; use util::smallvec::VecLike; -use util::str::LengthOrPercentageOrAuto; - -/// Legacy presentational attributes that take a length as defined in HTML5 § 2.4.4.4. -#[derive(Copy, Clone, PartialEq, Eq)] -pub enum LengthAttribute { - /// `` - Width, -} /// Legacy presentational attributes that take an integer as defined in HTML5 § 2.4.4.2. #[derive(Copy, Clone, PartialEq, Eq)] @@ -71,14 +63,6 @@ pub trait PresentationalHintSynthesis { E: TElement<'a> + TElementAttributes<'a>, V: VecLike>>; - /// Synthesizes rules for the legacy `width` attribute. - fn synthesize_presentational_hint_for_legacy_width_attribute<'a,E,V>( - &self, - element: E, - matching_rules_list: &mut V, - shareable: &mut bool) - where E: TElement<'a> + TElementAttributes<'a>, - V: VecLike>>; } impl PresentationalHintSynthesis for Stylist { @@ -101,20 +85,12 @@ impl PresentationalHintSynthesis for Stylist { match element.get_local_name() { name if *name == atom!("td") => { - self.synthesize_presentational_hint_for_legacy_width_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_width_attribute( - element, - matching_rules_list, - shareable); self.synthesize_presentational_hint_for_legacy_border_attribute( element, matching_rules_list, @@ -184,31 +160,6 @@ impl PresentationalHintSynthesis for Stylist { } } } - - fn synthesize_presentational_hint_for_legacy_width_attribute<'a,E,V>( - &self, - element: E, - matching_rules_list: &mut V, - shareable: &mut bool) - where E: TElement<'a> + TElementAttributes<'a>, - V: VecLike>> { - match element.get_length_attribute(LengthAttribute::Width) { - LengthOrPercentageOrAuto::Auto => {} - LengthOrPercentageOrAuto::Percentage(percentage) => { - let width_value = specified::LengthOrPercentageOrAuto::Percentage(percentage); - matching_rules_list.push(from_declaration( - PropertyDeclaration::Width(SpecifiedValue(width_value)))); - *shareable = false - } - LengthOrPercentageOrAuto::Length(length) => { - let width_value = specified::LengthOrPercentageOrAuto::Length( - specified::Length::Absolute(length)); - matching_rules_list.push(from_declaration( - PropertyDeclaration::Width(SpecifiedValue(width_value)))); - *shareable = false - } - } - } } diff --git a/components/style/node.rs b/components/style/node.rs index ebfcf7d9068..f01da162364 100644 --- a/components/style/node.rs +++ b/components/style/node.rs @@ -5,10 +5,9 @@ //! Traits that nodes must implement. Breaks the otherwise-cyclic dependency between layout and //! style. -use legacy::{IntegerAttribute, LengthAttribute, UnsignedIntegerAttribute}; +use legacy::{IntegerAttribute, UnsignedIntegerAttribute}; use properties::PropertyDeclaration; use util::smallvec::VecLike; -use util::str::LengthOrPercentageOrAuto; use selectors::matching::DeclarationBlock; pub use selectors::tree::{TNode, TElement}; @@ -17,7 +16,6 @@ use string_cache::{Atom, Namespace}; pub trait TElementAttributes<'a> : Copy { fn synthesize_presentational_hints_for_legacy_attributes(self, &mut V) where V: VecLike>>; - fn get_length_attribute(self, attribute: LengthAttribute) -> LengthOrPercentageOrAuto; fn get_integer_attribute(self, attribute: IntegerAttribute) -> Option; fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option; From 8b0505930f72752a392308e67f009ddb5fb92419 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 9 May 2015 17:26:50 +0200 Subject: [PATCH 4/4] Move textarea cols/rows to the new infrastructure. --- components/layout/wrapper.rs | 8 +--- components/script/dom/element.rs | 65 +++++++++++++++++++++----------- components/style/legacy.rs | 40 +------------------- components/style/node.rs | 3 +- 4 files changed, 47 insertions(+), 69 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index c6549fde57c..f9a214daf20 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -71,7 +71,7 @@ use style::computed_values::content::ContentItem; use style::computed_values::{content, display, white_space}; use selectors::matching::DeclarationBlock; use selectors::parser::{NamespaceConstraint, AttrSelector}; -use style::legacy::{IntegerAttribute, UnsignedIntegerAttribute}; +use style::legacy::UnsignedIntegerAttribute; use style::node::{TElement, TElementAttributes, TNode}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use util::smallvec::VecLike; @@ -656,12 +656,6 @@ impl<'le> TElementAttributes<'le> for LayoutElement<'le> { } } - fn get_integer_attribute(self, integer_attribute: IntegerAttribute) -> Option { - unsafe { - self.element.get_integer_attribute_for_layout(integer_attribute) - } - } - fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option { unsafe { self.element.get_unsigned_integer_attribute_for_layout(attribute) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 5034da72235..18481db2c2d 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -59,10 +59,11 @@ use dom::virtualmethods::{VirtualMethods, vtable_for}; use devtools_traits::AttrInfo; use style; -use style::legacy::{UnsignedIntegerAttribute, IntegerAttribute, from_declaration}; +use style::legacy::{UnsignedIntegerAttribute, from_declaration}; use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, parse_style_attribute}; use style::properties::DeclaredValue::SpecifiedValue; -use style::properties::longhands::border_spacing; +use style::properties::longhands::{self, border_spacing}; +use style::values::CSSFloat; use style::values::specified::{self, CSSColor}; use util::geometry::Au; use util::namespace; @@ -164,8 +165,6 @@ pub trait RawLayoutElementHelpers { unsafe fn synthesize_presentational_hints_for_legacy_attributes(&self, &mut V) where V: VecLike>>; - unsafe fn get_integer_attribute_for_layout(&self, integer_attribute: IntegerAttribute) - -> Option; unsafe fn get_checked_state_for_layout(&self) -> bool; unsafe fn get_indeterminate_state_for_layout(&self) -> bool; unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute) @@ -330,26 +329,50 @@ impl RawLayoutElementHelpers for Element { PropertyDeclaration::Width(SpecifiedValue(width_value)))); } } - } - #[inline] - unsafe fn get_integer_attribute_for_layout(&self, integer_attribute: IntegerAttribute) - -> Option { - match integer_attribute { - IntegerAttribute::Cols => { - if !self.is_htmltextareaelement() { - panic!("I'm not a textarea element!") - } - let this: &HTMLTextAreaElement = mem::transmute(self); - Some(this.get_cols_for_layout() as i32) + + let cols = if self.is_htmltextareaelement() { + let this: &HTMLTextAreaElement = mem::transmute(self); + match this.get_cols_for_layout() { + 0 => None, + c => Some(c as i32), } - IntegerAttribute::Rows => { - if !self.is_htmltextareaelement() { - panic!("I'm not a textarea element!") - } - let this: &HTMLTextAreaElement = mem::transmute(self); - Some(this.get_rows_for_layout() as i32) + } else { + None + }; + + if let Some(cols) = cols { + // TODO(mttr) ServoCharacterWidth uses the size math for , but + // the math for