mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Makes layout respect <textarea> cols attribute
This commit is contained in:
parent
905c30d697
commit
2c7f6076d1
4 changed files with 52 additions and 4 deletions
|
@ -19,7 +19,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, ElementDerived, EventTar
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLInputElementCast};
|
use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLInputElementCast};
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLTableElementCast};
|
use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLTableElementCast};
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLTableElementDerived, HTMLTableCellElementDerived};
|
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::codegen::InheritTypes::{HTMLTableSectionElementDerived, NodeCast};
|
||||||
use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, TemporaryPushable};
|
use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, TemporaryPushable};
|
||||||
use dom::bindings::js::{OptionalRootable, Root};
|
use dom::bindings::js::{OptionalRootable, Root};
|
||||||
|
@ -41,6 +41,7 @@ use dom::htmltableelement::{HTMLTableElement, HTMLTableElementHelpers};
|
||||||
use dom::htmltablecellelement::{HTMLTableCellElement, HTMLTableCellElementHelpers};
|
use dom::htmltablecellelement::{HTMLTableCellElement, HTMLTableCellElementHelpers};
|
||||||
use dom::htmltablerowelement::{HTMLTableRowElement, HTMLTableRowElementHelpers};
|
use dom::htmltablerowelement::{HTMLTableRowElement, HTMLTableRowElementHelpers};
|
||||||
use dom::htmltablesectionelement::{HTMLTableSectionElement, HTMLTableSectionElementHelpers};
|
use dom::htmltablesectionelement::{HTMLTableSectionElement, HTMLTableSectionElementHelpers};
|
||||||
|
use dom::htmltextareaelement::{HTMLTextAreaElement, RawLayoutHTMLTextAreaElementHelpers};
|
||||||
use dom::node::{CLICK_IN_PROGRESS, ElementNodeTypeId, LayoutNodeHelpers, Node, NodeHelpers};
|
use dom::node::{CLICK_IN_PROGRESS, ElementNodeTypeId, LayoutNodeHelpers, Node, NodeHelpers};
|
||||||
use dom::node::{NodeIterator, NodeStyleDamaged, OtherNodeDamage, document_from_node};
|
use dom::node::{NodeIterator, NodeStyleDamaged, OtherNodeDamage, document_from_node};
|
||||||
use dom::node::{window_from_node};
|
use dom::node::{window_from_node};
|
||||||
|
@ -49,7 +50,7 @@ use dom::virtualmethods::{VirtualMethods, vtable_for};
|
||||||
use devtools_traits::AttrInfo;
|
use devtools_traits::AttrInfo;
|
||||||
use style::{mod, AuthorOrigin, BgColorSimpleColorAttribute, BorderUnsignedIntegerAttribute};
|
use style::{mod, AuthorOrigin, BgColorSimpleColorAttribute, BorderUnsignedIntegerAttribute};
|
||||||
use style::{ColSpanUnsignedIntegerAttribute, IntegerAttribute, LengthAttribute, ParserContext};
|
use style::{ColSpanUnsignedIntegerAttribute, IntegerAttribute, LengthAttribute, ParserContext};
|
||||||
use style::{SimpleColorAttribute, SizeIntegerAttribute, UnsignedIntegerAttribute};
|
use style::{SimpleColorAttribute, SizeIntegerAttribute, ColsIntegerAttribute, UnsignedIntegerAttribute};
|
||||||
use style::{WidthLengthAttribute, matches};
|
use style::{WidthLengthAttribute, matches};
|
||||||
use servo_util::namespace;
|
use servo_util::namespace;
|
||||||
use servo_util::str::{DOMString, LengthOrPercentageOrAuto};
|
use servo_util::str::{DOMString, LengthOrPercentageOrAuto};
|
||||||
|
@ -323,6 +324,13 @@ impl RawLayoutElementHelpers for Element {
|
||||||
let this: &HTMLInputElement = mem::transmute(self);
|
let this: &HTMLInputElement = mem::transmute(self);
|
||||||
Some(this.get_size_for_layout() as i32)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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::attr::AttrHelpers;
|
||||||
use dom::bindings::cell::DOMRefCell;
|
use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
|
@ -34,6 +34,7 @@ use std::cell::Cell;
|
||||||
pub struct HTMLTextAreaElement {
|
pub struct HTMLTextAreaElement {
|
||||||
htmlelement: HTMLElement,
|
htmlelement: HTMLElement,
|
||||||
textinput: DOMRefCell<TextInput>,
|
textinput: DOMRefCell<TextInput>,
|
||||||
|
cols: Cell<u32>,
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/forms.html#concept-textarea-dirty
|
// https://html.spec.whatwg.org/multipage/forms.html#concept-textarea-dirty
|
||||||
value_changed: Cell<bool>,
|
value_changed: Cell<bool>,
|
||||||
|
@ -49,6 +50,10 @@ pub trait LayoutHTMLTextAreaElementHelpers {
|
||||||
unsafe fn get_value_for_layout(self) -> String;
|
unsafe fn get_value_for_layout(self) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait RawLayoutHTMLTextAreaElementHelpers {
|
||||||
|
unsafe fn get_cols_for_layout(&self) -> u32;
|
||||||
|
}
|
||||||
|
|
||||||
impl LayoutHTMLTextAreaElementHelpers for JS<HTMLTextAreaElement> {
|
impl LayoutHTMLTextAreaElementHelpers for JS<HTMLTextAreaElement> {
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
unsafe fn get_value_for_layout(self) -> String {
|
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_COLS: u32 = 20;
|
||||||
static DEFAULT_ROWS: u32 = 2;
|
static DEFAULT_ROWS: u32 = 2;
|
||||||
|
|
||||||
|
@ -64,6 +76,7 @@ impl HTMLTextAreaElement {
|
||||||
HTMLTextAreaElement {
|
HTMLTextAreaElement {
|
||||||
htmlelement: HTMLElement::new_inherited(HTMLTextAreaElementTypeId, localName, prefix, document),
|
htmlelement: HTMLElement::new_inherited(HTMLTextAreaElementTypeId, localName, prefix, document),
|
||||||
textinput: DOMRefCell::new(TextInput::new(Multiple, "".to_string())),
|
textinput: DOMRefCell::new(TextInput::new(Multiple, "".to_string())),
|
||||||
|
cols: Cell::new(DEFAULT_COLS),
|
||||||
value_changed: Cell::new(false),
|
value_changed: Cell::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,6 +199,12 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTextAreaElement> {
|
||||||
node.set_disabled_state(true);
|
node.set_disabled_state(true);
|
||||||
node.set_enabled_state(false);
|
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.set_enabled_state(true);
|
||||||
node.check_ancestors_disabled_state_for_form_control();
|
node.check_ancestors_disabled_state_for_form_control();
|
||||||
},
|
},
|
||||||
|
&atom!("cols") => {
|
||||||
|
self.cols.set(DEFAULT_COLS);
|
||||||
|
},
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ pub enum LengthAttribute {
|
||||||
pub enum IntegerAttribute {
|
pub enum IntegerAttribute {
|
||||||
/// `<input size>`
|
/// `<input size>`
|
||||||
SizeIntegerAttribute,
|
SizeIntegerAttribute,
|
||||||
|
ColsIntegerAttribute,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
|
@ -160,6 +161,23 @@ impl PresentationalHintSynthesis for Stylist {
|
||||||
Some(_) | None => {}
|
Some(_) | None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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
|
||||||
|
// 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/rendering.html#textarea-effective-width
|
||||||
|
let value = specified::ServoCharacterWidth(value);
|
||||||
|
matching_rules_list.vec_push(DeclarationBlock::from_declaration(
|
||||||
|
WidthDeclaration(SpecifiedValue(specified::LPA_Length(
|
||||||
|
value)))));
|
||||||
|
*shareable = false
|
||||||
|
}
|
||||||
|
Some(_) | None => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ pub use cssparser::{Color, RGBA};
|
||||||
pub use legacy::{BgColorSimpleColorAttribute, BorderUnsignedIntegerAttribute};
|
pub use legacy::{BgColorSimpleColorAttribute, BorderUnsignedIntegerAttribute};
|
||||||
pub use legacy::{ColSpanUnsignedIntegerAttribute, IntegerAttribute, LengthAttribute};
|
pub use legacy::{ColSpanUnsignedIntegerAttribute, IntegerAttribute, LengthAttribute};
|
||||||
pub use legacy::{SimpleColorAttribute, SizeIntegerAttribute, UnsignedIntegerAttribute};
|
pub use legacy::{SimpleColorAttribute, SizeIntegerAttribute, UnsignedIntegerAttribute};
|
||||||
pub use legacy::{WidthLengthAttribute};
|
pub use legacy::{WidthLengthAttribute, ColsIntegerAttribute};
|
||||||
pub use font_face::{Source, LocalSource, UrlSource_};
|
pub use font_face::{Source, LocalSource, UrlSource_};
|
||||||
|
|
||||||
mod stylesheets;
|
mod stylesheets;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue