aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorMatthew Rasmus <mattr@zzntd.com>2014-12-12 11:56:54 -0800
committerMatthew Rasmus <mattr@zzntd.com>2014-12-16 10:44:15 -0800
commit2c7f6076d174e9b47bb710031a5b6c427e83320f (patch)
treebdc3fd39501e2c86f4aca7b7310e8b07645b4dd3 /components/script/dom
parent905c30d69739fcacfe67cb2605eb9f669ae9a82f (diff)
downloadservo-2c7f6076d174e9b47bb710031a5b6c427e83320f.tar.gz
servo-2c7f6076d174e9b47bb710031a5b6c427e83320f.zip
Makes layout respect <textarea> cols attribute
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/element.rs12
-rw-r--r--components/script/dom/htmltextareaelement.rs24
2 files changed, 33 insertions, 3 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 3d7a6a861e9..a43e2176b9f 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -19,7 +19,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, ElementDerived, EventTar
use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLInputElementCast};
use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLTableElementCast};
use dom::bindings::codegen::InheritTypes::{HTMLTableElementDerived, HTMLTableCellElementDerived};
-use dom::bindings::codegen::InheritTypes::{HTMLTableRowElementDerived};
+use dom::bindings::codegen::InheritTypes::{HTMLTableRowElementDerived, HTMLTextAreaElementDerived};
use dom::bindings::codegen::InheritTypes::{HTMLTableSectionElementDerived, NodeCast};
use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, TemporaryPushable};
use dom::bindings::js::{OptionalRootable, Root};
@@ -41,6 +41,7 @@ use dom::htmltableelement::{HTMLTableElement, HTMLTableElementHelpers};
use dom::htmltablecellelement::{HTMLTableCellElement, HTMLTableCellElementHelpers};
use dom::htmltablerowelement::{HTMLTableRowElement, HTMLTableRowElementHelpers};
use dom::htmltablesectionelement::{HTMLTableSectionElement, HTMLTableSectionElementHelpers};
+use dom::htmltextareaelement::{HTMLTextAreaElement, RawLayoutHTMLTextAreaElementHelpers};
use dom::node::{CLICK_IN_PROGRESS, ElementNodeTypeId, LayoutNodeHelpers, Node, NodeHelpers};
use dom::node::{NodeIterator, NodeStyleDamaged, OtherNodeDamage, document_from_node};
use dom::node::{window_from_node};
@@ -49,7 +50,7 @@ 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, UnsignedIntegerAttribute};
+use style::{SimpleColorAttribute, SizeIntegerAttribute, ColsIntegerAttribute, UnsignedIntegerAttribute};
use style::{WidthLengthAttribute, matches};
use servo_util::namespace;
use servo_util::str::{DOMString, LengthOrPercentageOrAuto};
@@ -323,6 +324,13 @@ impl RawLayoutElementHelpers for Element {
let this: &HTMLInputElement = mem::transmute(self);
Some(this.get_size_for_layout() as i32)
}
+ ColsIntegerAttribute => {
+ 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)
+ }
}
}
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index 05d3a5d0868..4c3789599be 100644
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-use dom::attr::{Attr, AttrValue};
+use dom::attr::{Attr, AttrValue, UIntAttrValue};
use dom::attr::AttrHelpers;
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
@@ -34,6 +34,7 @@ use std::cell::Cell;
pub struct HTMLTextAreaElement {
htmlelement: HTMLElement,
textinput: DOMRefCell<TextInput>,
+ cols: Cell<u32>,
// https://html.spec.whatwg.org/multipage/forms.html#concept-textarea-dirty
value_changed: Cell<bool>,
@@ -49,6 +50,10 @@ pub trait LayoutHTMLTextAreaElementHelpers {
unsafe fn get_value_for_layout(self) -> String;
}
+pub trait RawLayoutHTMLTextAreaElementHelpers {
+ unsafe fn get_cols_for_layout(&self) -> u32;
+}
+
impl LayoutHTMLTextAreaElementHelpers for JS<HTMLTextAreaElement> {
#[allow(unrooted_must_root)]
unsafe fn get_value_for_layout(self) -> String {
@@ -56,6 +61,13 @@ impl LayoutHTMLTextAreaElementHelpers for JS<HTMLTextAreaElement> {
}
}
+impl RawLayoutHTMLTextAreaElementHelpers for HTMLTextAreaElement {
+ #[allow(unrooted_must_root)]
+ unsafe fn get_cols_for_layout(&self) -> u32 {
+ self.cols.get()
+ }
+}
+
static DEFAULT_COLS: u32 = 20;
static DEFAULT_ROWS: u32 = 2;
@@ -64,6 +76,7 @@ impl HTMLTextAreaElement {
HTMLTextAreaElement {
htmlelement: HTMLElement::new_inherited(HTMLTextAreaElementTypeId, localName, prefix, document),
textinput: DOMRefCell::new(TextInput::new(Multiple, "".to_string())),
+ cols: Cell::new(DEFAULT_COLS),
value_changed: Cell::new(false),
}
}
@@ -186,6 +199,12 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTextAreaElement> {
node.set_disabled_state(true);
node.set_enabled_state(false);
},
+ &atom!("cols") => {
+ match *attr.value() {
+ UIntAttrValue(_, value) => self.cols.set(value),
+ _ => panic!("Expected a UIntAttrValue"),
+ }
+ },
_ => ()
}
}
@@ -203,6 +222,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTextAreaElement> {
node.set_enabled_state(true);
node.check_ancestors_disabled_state_for_form_control();
},
+ &atom!("cols") => {
+ self.cols.set(DEFAULT_COLS);
+ },
_ => ()
}
}