mirror of
https://github.com/servo/servo.git
synced 2025-06-20 15:18:58 +01:00
Implement <hr> element 'width' attribute
This commit is contained in:
parent
337066063a
commit
02a8e8dd16
8 changed files with 66 additions and 137 deletions
|
@ -390,6 +390,9 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
this.get_width()
|
||||
} else if let Some(this) = self.downcast::<HTMLTableCellElement>() {
|
||||
this.get_width()
|
||||
} else if let Some(this) = self.downcast::<HTMLHRElement>() {
|
||||
// https://html.spec.whatwg.org/multipage/#the-hr-element-2:attr-hr-width
|
||||
this.get_width()
|
||||
} else {
|
||||
LengthOrPercentageOrAuto::Auto
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ use dom::htmlelement::HTMLElement;
|
|||
use dom::node::Node;
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
use string_cache::Atom;
|
||||
use util::str::DOMString;
|
||||
use util::str::{DOMString, LengthOrPercentageOrAuto};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct HTMLHRElement {
|
||||
|
@ -42,10 +42,17 @@ impl HTMLHRElementMethods for HTMLHRElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-hr-color
|
||||
make_legacy_color_setter!(SetColor, "color");
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-hr-width
|
||||
make_getter!(Width);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-hr-width
|
||||
make_dimension_setter!(SetWidth, "width");
|
||||
}
|
||||
|
||||
pub trait HTMLHRLayoutHelpers {
|
||||
fn get_color(&self) -> Option<RGBA>;
|
||||
fn get_width(&self) -> LengthOrPercentageOrAuto;
|
||||
}
|
||||
|
||||
impl HTMLHRLayoutHelpers for LayoutJS<HTMLHRElement> {
|
||||
|
@ -58,6 +65,17 @@ impl HTMLHRLayoutHelpers for LayoutJS<HTMLHRElement> {
|
|||
.cloned()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_width(&self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
(&*self.upcast::<Element>().unsafe_get())
|
||||
.get_attr_for_layout(&ns!(""), &atom!("width"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -69,6 +87,7 @@ impl VirtualMethods for HTMLHRElement {
|
|||
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
|
||||
match name {
|
||||
&atom!("color") => AttrValue::from_legacy_color(value),
|
||||
&atom!("width") => AttrValue::from_dimension(value),
|
||||
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,5 +14,5 @@ partial interface HTMLHRElement {
|
|||
attribute DOMString color;
|
||||
// attribute boolean noShade;
|
||||
// attribute DOMString size;
|
||||
// attribute DOMString width;
|
||||
attribute DOMString width;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue