Move textarea cols/rows to the new infrastructure.

This commit is contained in:
Ms2ger 2015-05-09 17:26:50 +02:00
parent f571a69b2e
commit 8b0505930f
4 changed files with 47 additions and 69 deletions

View file

@ -71,7 +71,7 @@ use style::computed_values::content::ContentItem;
use style::computed_values::{content, display, white_space}; use style::computed_values::{content, display, white_space};
use selectors::matching::DeclarationBlock; use selectors::matching::DeclarationBlock;
use selectors::parser::{NamespaceConstraint, AttrSelector}; use selectors::parser::{NamespaceConstraint, AttrSelector};
use style::legacy::{IntegerAttribute, UnsignedIntegerAttribute}; use style::legacy::UnsignedIntegerAttribute;
use style::node::{TElement, TElementAttributes, TNode}; use style::node::{TElement, TElementAttributes, TNode};
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
use util::smallvec::VecLike; use util::smallvec::VecLike;
@ -656,12 +656,6 @@ impl<'le> TElementAttributes<'le> for LayoutElement<'le> {
} }
} }
fn get_integer_attribute(self, integer_attribute: IntegerAttribute) -> Option<i32> {
unsafe {
self.element.get_integer_attribute_for_layout(integer_attribute)
}
}
fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option<u32> { fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option<u32> {
unsafe { unsafe {
self.element.get_unsigned_integer_attribute_for_layout(attribute) self.element.get_unsigned_integer_attribute_for_layout(attribute)

View file

@ -59,10 +59,11 @@ use dom::virtualmethods::{VirtualMethods, vtable_for};
use devtools_traits::AttrInfo; use devtools_traits::AttrInfo;
use style; 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::{PropertyDeclarationBlock, PropertyDeclaration, parse_style_attribute};
use style::properties::DeclaredValue::SpecifiedValue; 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 style::values::specified::{self, CSSColor};
use util::geometry::Au; use util::geometry::Au;
use util::namespace; use util::namespace;
@ -164,8 +165,6 @@ pub trait RawLayoutElementHelpers {
unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, &mut V) unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, &mut V)
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>; where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
unsafe fn get_integer_attribute_for_layout(&self, integer_attribute: IntegerAttribute)
-> Option<i32>;
unsafe fn get_checked_state_for_layout(&self) -> bool; unsafe fn get_checked_state_for_layout(&self) -> bool;
unsafe fn get_indeterminate_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) unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute)
@ -330,26 +329,50 @@ impl RawLayoutElementHelpers for Element {
PropertyDeclaration::Width(SpecifiedValue(width_value)))); PropertyDeclaration::Width(SpecifiedValue(width_value))));
} }
} }
}
#[inline]
unsafe fn get_integer_attribute_for_layout(&self, integer_attribute: IntegerAttribute) let cols = if self.is_htmltextareaelement() {
-> Option<i32> { let this: &HTMLTextAreaElement = mem::transmute(self);
match integer_attribute { match this.get_cols_for_layout() {
IntegerAttribute::Cols => { 0 => None,
if !self.is_htmltextareaelement() { c => Some(c as i32),
panic!("I'm not a textarea element!")
}
let this: &HTMLTextAreaElement = mem::transmute(self);
Some(this.get_cols_for_layout() as i32)
} }
IntegerAttribute::Rows => { } else {
if !self.is_htmltextareaelement() { None
panic!("I'm not a textarea element!") };
}
let this: &HTMLTextAreaElement = mem::transmute(self); if let Some(cols) = cols {
Some(this.get_rows_for_layout() as i32) // TODO(mttr) ServoCharacterWidth uses the size math for <input type="text">, but
// the math for <textarea> is a little different since we need to take
// scrollbar size into consideration (but we don't have a scrollbar yet!)
//
// https://html.spec.whatwg.org/multipage/#textarea-effective-width
let value = specified::Length::ServoCharacterWidth(specified::CharacterWidth(cols));
hints.push(from_declaration(
PropertyDeclaration::Width(SpecifiedValue(
specified::LengthOrPercentageOrAuto::Length(value)))));
}
let rows = if self.is_htmltextareaelement() {
let this: &HTMLTextAreaElement = mem::transmute(self);
match this.get_rows_for_layout() {
0 => None,
r => Some(r as i32),
} }
} else {
None
};
if let Some(rows) = rows {
// TODO(mttr) This should take scrollbar size into consideration.
//
// https://html.spec.whatwg.org/multipage/#textarea-effective-height
let value = specified::Length::FontRelative(specified::FontRelativeLength::Em(rows as CSSFloat));
hints.push(from_declaration(
PropertyDeclaration::Height(SpecifiedValue(
longhands::height::SpecifiedValue(
specified::LengthOrPercentageOrAuto::Length(value))))));
} }
} }

View file

@ -10,7 +10,7 @@ use std::sync::Arc;
use selectors::tree::{TElement, TNode}; use selectors::tree::{TElement, TNode};
use selectors::matching::DeclarationBlock; use selectors::matching::DeclarationBlock;
use node::TElementAttributes; use node::TElementAttributes;
use values::{CSSFloat, specified}; use values::specified;
use properties::DeclaredValue::SpecifiedValue; use properties::DeclaredValue::SpecifiedValue;
use properties::PropertyDeclaration; use properties::PropertyDeclaration;
use properties::longhands; use properties::longhands;
@ -19,13 +19,6 @@ use selector_matching::Stylist;
use util::geometry::Au; use util::geometry::Au;
use util::smallvec::VecLike; use util::smallvec::VecLike;
/// Legacy presentational attributes that take an integer as defined in HTML5 § 2.4.4.2.
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum IntegerAttribute {
Cols,
Rows,
}
/// Legacy presentational attributes that take a nonnegative integer as defined in HTML5 § 2.4.4.2. /// Legacy presentational attributes that take a nonnegative integer as defined in HTML5 § 2.4.4.2.
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq)]
pub enum UnsignedIntegerAttribute { pub enum UnsignedIntegerAttribute {
@ -96,37 +89,6 @@ impl PresentationalHintSynthesis for Stylist {
matching_rules_list, matching_rules_list,
shareable); shareable);
} }
name if *name == atom!("textarea") => {
match element.get_integer_attribute(IntegerAttribute::Cols) {
Some(value) if value != 0 => {
// TODO(mttr) ServoCharacterWidth uses the size math for <input type="text">, but
// the math for <textarea> is a little different since we need to take
// scrollbar size into consideration (but we don't have a scrollbar yet!)
//
// https://html.spec.whatwg.org/multipage/#textarea-effective-width
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 => {}
}
match element.get_integer_attribute(IntegerAttribute::Rows) {
Some(value) if value != 0 => {
// TODO(mttr) This should take scrollbar size into consideration.
//
// https://html.spec.whatwg.org/multipage/#textarea-effective-height
let value = specified::Length::FontRelative(specified::FontRelativeLength::Em(value as CSSFloat));
matching_rules_list.push(from_declaration(
PropertyDeclaration::Height(SpecifiedValue(
longhands::height::SpecifiedValue(
specified::LengthOrPercentageOrAuto::Length(value))))));
*shareable = false
}
Some(_) | None => {}
}
}
_ => {} _ => {}
} }
} }

View file

@ -5,7 +5,7 @@
//! Traits that nodes must implement. Breaks the otherwise-cyclic dependency between layout and //! Traits that nodes must implement. Breaks the otherwise-cyclic dependency between layout and
//! style. //! style.
use legacy::{IntegerAttribute, UnsignedIntegerAttribute}; use legacy::UnsignedIntegerAttribute;
use properties::PropertyDeclaration; use properties::PropertyDeclaration;
use util::smallvec::VecLike; use util::smallvec::VecLike;
@ -16,7 +16,6 @@ use string_cache::{Atom, Namespace};
pub trait TElementAttributes<'a> : Copy { pub trait TElementAttributes<'a> : Copy {
fn synthesize_presentational_hints_for_legacy_attributes<V>(self, &mut V) fn synthesize_presentational_hints_for_legacy_attributes<V>(self, &mut V)
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>; where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
fn get_integer_attribute(self, attribute: IntegerAttribute) -> Option<i32>;
fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option<u32>; fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option<u32>;
fn get_attr(self, namespace: &Namespace, attr: &Atom) -> Option<&'a str>; fn get_attr(self, namespace: &Namespace, attr: &Atom) -> Option<&'a str>;