aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Rasmus <mattr@zzntd.com>2014-12-12 12:52:46 -0800
committerMatthew Rasmus <mattr@zzntd.com>2014-12-16 11:02:01 -0800
commitfc0748f50e3bc4965ff8a5ada9d352675cdd1778 (patch)
tree068025f29639d25143f377dd3a4b912ad02832b6
parent2c7f6076d174e9b47bb710031a5b6c427e83320f (diff)
downloadservo-fc0748f50e3bc4965ff8a5ada9d352675cdd1778.tar.gz
servo-fc0748f50e3bc4965ff8a5ada9d352675cdd1778.zip
Makes layout respect <textarea> rows attribute
review addresssing
-rw-r--r--components/script/dom/element.rs11
-rw-r--r--components/script/dom/htmltextareaelement.rs17
-rw-r--r--components/style/legacy.rs20
-rw-r--r--components/style/lib.rs2
4 files changed, 44 insertions, 6 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index a43e2176b9f..c3c0b9fcb28 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -50,8 +50,8 @@ use dom::virtualmethods::{VirtualMethods, vtable_for};
use devtools_traits::AttrInfo;
use style::{mod, AuthorOrigin, BgColorSimpleColorAttribute, BorderUnsignedIntegerAttribute};
use style::{ColSpanUnsignedIntegerAttribute, IntegerAttribute, LengthAttribute, ParserContext};
-use style::{SimpleColorAttribute, SizeIntegerAttribute, ColsIntegerAttribute, UnsignedIntegerAttribute};
-use style::{WidthLengthAttribute, matches};
+use style::{SimpleColorAttribute, SizeIntegerAttribute, ColsIntegerAttribute, RowsIntegerAttribute};
+use style::{UnsignedIntegerAttribute, WidthLengthAttribute, matches};
use servo_util::namespace;
use servo_util::str::{DOMString, LengthOrPercentageOrAuto};
@@ -331,6 +331,13 @@ impl RawLayoutElementHelpers for Element {
let this: &HTMLTextAreaElement = mem::transmute(self);
Some(this.get_cols_for_layout() as i32)
}
+ RowsIntegerAttribute => {
+ 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)
+ }
}
}
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index 4c3789599be..642feb38b93 100644
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -35,6 +35,7 @@ pub struct HTMLTextAreaElement {
htmlelement: HTMLElement,
textinput: DOMRefCell<TextInput>,
cols: Cell<u32>,
+ rows: Cell<u32>,
// https://html.spec.whatwg.org/multipage/forms.html#concept-textarea-dirty
value_changed: Cell<bool>,
@@ -52,6 +53,7 @@ pub trait LayoutHTMLTextAreaElementHelpers {
pub trait RawLayoutHTMLTextAreaElementHelpers {
unsafe fn get_cols_for_layout(&self) -> u32;
+ unsafe fn get_rows_for_layout(&self) -> u32;
}
impl LayoutHTMLTextAreaElementHelpers for JS<HTMLTextAreaElement> {
@@ -66,6 +68,11 @@ impl RawLayoutHTMLTextAreaElementHelpers for HTMLTextAreaElement {
unsafe fn get_cols_for_layout(&self) -> u32 {
self.cols.get()
}
+
+ #[allow(unrooted_must_root)]
+ unsafe fn get_rows_for_layout(&self) -> u32 {
+ self.rows.get()
+ }
}
static DEFAULT_COLS: u32 = 20;
@@ -77,6 +84,7 @@ impl HTMLTextAreaElement {
htmlelement: HTMLElement::new_inherited(HTMLTextAreaElementTypeId, localName, prefix, document),
textinput: DOMRefCell::new(TextInput::new(Multiple, "".to_string())),
cols: Cell::new(DEFAULT_COLS),
+ rows: Cell::new(DEFAULT_ROWS),
value_changed: Cell::new(false),
}
}
@@ -205,6 +213,12 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTextAreaElement> {
_ => panic!("Expected a UIntAttrValue"),
}
},
+ &atom!("rows") => {
+ match *attr.value() {
+ UIntAttrValue(_, value) => self.rows.set(value),
+ _ => panic!("Expected a UIntAttrValue"),
+ }
+ },
_ => ()
}
}
@@ -225,6 +239,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTextAreaElement> {
&atom!("cols") => {
self.cols.set(DEFAULT_COLS);
},
+ &atom!("rows") => {
+ self.rows.set(DEFAULT_ROWS);
+ },
_ => ()
}
}
diff --git a/components/style/legacy.rs b/components/style/legacy.rs
index b808427b316..09da76d1694 100644
--- a/components/style/legacy.rs
+++ b/components/style/legacy.rs
@@ -6,8 +6,8 @@
//! `<input size>`, and so forth.
use node::{TElement, TElementAttributes, TNode};
-use properties::{BackgroundColorDeclaration, BorderBottomWidthDeclaration};
-use properties::{BorderLeftWidthDeclaration, BorderRightWidthDeclaration};
+use properties::{BackgroundColorDeclaration, BorderBottomWidthDeclaration, CSSFloat};
+use properties::{BorderLeftWidthDeclaration, BorderRightWidthDeclaration, HeightDeclaration};
use properties::{BorderTopWidthDeclaration, SpecifiedValue, WidthDeclaration, specified};
use selector_matching::{DeclarationBlock, Stylist};
@@ -27,6 +27,7 @@ pub enum IntegerAttribute {
/// `<input size>`
SizeIntegerAttribute,
ColsIntegerAttribute,
+ RowsIntegerAttribute,
}
/// Legacy presentational attributes that take a nonnegative integer as defined in HTML5 § 2.4.4.2.
@@ -164,7 +165,7 @@ impl PresentationalHintSynthesis for Stylist {
name if *name == atom!("textarea") => {
match element.get_integer_attribute(ColsIntegerAttribute) {
Some(value) if value != 0 => {
- // TODO ServoCharacterWidth uses the size math for <input type="text">, but
+ // 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!)
//
@@ -177,6 +178,19 @@ impl PresentationalHintSynthesis for Stylist {
}
Some(_) | None => {}
}
+ match element.get_integer_attribute(RowsIntegerAttribute) {
+ Some(value) if value != 0 => {
+ // TODO(mttr) This should take scrollbar size into consideration.
+ //
+ // https://html.spec.whatwg.org/multipage/rendering.html#textarea-effective-height
+ let value = specified::Em(value as CSSFloat);
+ matching_rules_list.vec_push(DeclarationBlock::from_declaration(
+ HeightDeclaration(SpecifiedValue(specified::LPA_Length(
+ value)))));
+ *shareable = false
+ }
+ Some(_) | None => {}
+ }
}
_ => {}
}
diff --git a/components/style/lib.rs b/components/style/lib.rs
index 775b57e7b27..9f016806ccc 100644
--- a/components/style/lib.rs
+++ b/components/style/lib.rs
@@ -57,7 +57,7 @@ pub use cssparser::{Color, RGBA};
pub use legacy::{BgColorSimpleColorAttribute, BorderUnsignedIntegerAttribute};
pub use legacy::{ColSpanUnsignedIntegerAttribute, IntegerAttribute, LengthAttribute};
pub use legacy::{SimpleColorAttribute, SizeIntegerAttribute, UnsignedIntegerAttribute};
-pub use legacy::{WidthLengthAttribute, ColsIntegerAttribute};
+pub use legacy::{WidthLengthAttribute, ColsIntegerAttribute, RowsIntegerAttribute};
pub use font_face::{Source, LocalSource, UrlSource_};
mod stylesheets;