From 83f4b077eb37733bf2be22e315f0e0569b284c62 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 28 Apr 2015 11:43:48 +0200 Subject: Move table cellspacing to the new infrastructure. --- components/script/dom/element.rs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'components/script/dom/element.rs') 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); -- cgit v1.2.3 From 0c8e55bff1983e03979435ef7cb7053c18a031a3 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 28 Apr 2015 14:26:03 +0200 Subject: Move input size to the new infrastructure. --- components/script/dom/element.rs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'components/script/dom/element.rs') 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!") -- cgit v1.2.3 From f571a69b2e02535cf240700463181b9221a56c25 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 8 May 2015 21:24:31 +0200 Subject: Move table/td width to the new infrastructure. --- components/script/dom/element.rs | 41 ++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'components/script/dom/element.rs') 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)))); } } } -- cgit v1.2.3 From 8b0505930f72752a392308e67f009ddb5fb92419 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 9 May 2015 17:26:50 +0200 Subject: Move textarea cols/rows to the new infrastructure. --- components/script/dom/element.rs | 65 +++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 21 deletions(-) (limited to 'components/script/dom/element.rs') 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