diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 33e343df99f..f9a214daf20 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::UnsignedIntegerAttribute; use style::node::{TElement, TElementAttributes, TNode}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use util::smallvec::VecLike; @@ -657,18 +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) - } - } - 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 4989039802d..18481db2c2d 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -59,10 +59,13 @@ use dom::virtualmethods::{VirtualMethods, vtable_for}; use devtools_traits::AttrInfo; use style; -use style::legacy::{UnsignedIntegerAttribute, IntegerAttribute, LengthAttribute, from_declaration}; +use style::legacy::{UnsignedIntegerAttribute, from_declaration}; use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, parse_style_attribute}; use style::properties::DeclaredValue::SpecifiedValue; -use style::values::specified::CSSColor; +use style::properties::longhands::{self, border_spacing}; +use style::values::CSSFloat; +use style::values::specified::{self, CSSColor}; +use util::geometry::Au; use util::namespace; use util::smallvec::VecLike; use util::str::{DOMString, LengthOrPercentageOrAuto}; @@ -162,10 +165,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; unsafe fn get_indeterminate_state_for_layout(&self) -> bool; unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute) @@ -260,51 +259,120 @@ impl RawLayoutElementHelpers for Element { PropertyDeclaration::BackgroundColor(SpecifiedValue( CSSColor { parsed: Color::RGBA(color), authored: None })))); } - } - #[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 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, + })))); + } + + + 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))))); + } + + + 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)))); } } - } - #[inline] - 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) + + 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::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) - } - 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