Implement <hr> element 'width' attribute

This commit is contained in:
Corey Farwell 2015-11-09 18:18:06 -05:00
parent 337066063a
commit 02a8e8dd16
8 changed files with 66 additions and 137 deletions

View file

@ -390,6 +390,9 @@ impl LayoutElementHelpers for LayoutJS<Element> {
this.get_width() this.get_width()
} else if let Some(this) = self.downcast::<HTMLTableCellElement>() { } else if let Some(this) = self.downcast::<HTMLTableCellElement>() {
this.get_width() 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 { } else {
LengthOrPercentageOrAuto::Auto LengthOrPercentageOrAuto::Auto
}; };

View file

@ -13,7 +13,7 @@ use dom::htmlelement::HTMLElement;
use dom::node::Node; use dom::node::Node;
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use string_cache::Atom; use string_cache::Atom;
use util::str::DOMString; use util::str::{DOMString, LengthOrPercentageOrAuto};
#[dom_struct] #[dom_struct]
pub struct HTMLHRElement { pub struct HTMLHRElement {
@ -42,10 +42,17 @@ impl HTMLHRElementMethods for HTMLHRElement {
// https://html.spec.whatwg.org/multipage/#dom-hr-color // https://html.spec.whatwg.org/multipage/#dom-hr-color
make_legacy_color_setter!(SetColor, "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 { pub trait HTMLHRLayoutHelpers {
fn get_color(&self) -> Option<RGBA>; fn get_color(&self) -> Option<RGBA>;
fn get_width(&self) -> LengthOrPercentageOrAuto;
} }
impl HTMLHRLayoutHelpers for LayoutJS<HTMLHRElement> { impl HTMLHRLayoutHelpers for LayoutJS<HTMLHRElement> {
@ -58,6 +65,17 @@ impl HTMLHRLayoutHelpers for LayoutJS<HTMLHRElement> {
.cloned() .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 { fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
match name { match name {
&atom!("color") => AttrValue::from_legacy_color(value), &atom!("color") => AttrValue::from_legacy_color(value),
&atom!("width") => AttrValue::from_dimension(value),
_ => self.super_type().unwrap().parse_plain_attribute(name, value), _ => self.super_type().unwrap().parse_plain_attribute(name, value),
} }
} }

View file

@ -14,5 +14,5 @@ partial interface HTMLHRElement {
attribute DOMString color; attribute DOMString color;
// attribute boolean noShade; // attribute boolean noShade;
// attribute DOMString size; // attribute DOMString size;
// attribute DOMString width; attribute DOMString width;
}; };

View file

@ -4495,6 +4495,16 @@
], ],
"url": "/html/rendering/non-replaced-elements/the-hr-element-0/color.html" "url": "/html/rendering/non-replaced-elements/the-hr-element-0/color.html"
}, },
{
"path": "html/rendering/non-replaced-elements/the-hr-element-0/width.html",
"references": [
[
"/html/rendering/non-replaced-elements/the-hr-element-0/width-ref.html",
"=="
]
],
"url": "/html/rendering/non-replaced-elements/the-hr-element-0/width.html"
},
{ {
"path": "html/rendering/non-replaced-elements/the-page/body_text_00ffff.xhtml", "path": "html/rendering/non-replaced-elements/the-page/body_text_00ffff.xhtml",
"references": [ "references": [

View file

@ -2313,9 +2313,6 @@
[HTMLHRElement interface: attribute size] [HTMLHRElement interface: attribute size]
expected: FAIL expected: FAIL
[HTMLHRElement interface: attribute width]
expected: FAIL
[HTMLHRElement interface: document.createElement("hr") must inherit property "align" with the proper type (0)] [HTMLHRElement interface: document.createElement("hr") must inherit property "align" with the proper type (0)]
expected: FAIL expected: FAIL
@ -2325,9 +2322,6 @@
[HTMLHRElement interface: document.createElement("hr") must inherit property "size" with the proper type (3)] [HTMLHRElement interface: document.createElement("hr") must inherit property "size" with the proper type (3)]
expected: FAIL expected: FAIL
[HTMLHRElement interface: document.createElement("hr") must inherit property "width" with the proper type (4)]
expected: FAIL
[HTMLPreElement interface: existence and properties of interface object] [HTMLPreElement interface: existence and properties of interface object]
expected: FAIL expected: FAIL

View file

@ -1686,135 +1686,6 @@
[hr.size: IDL set to object "test-valueOf" followed by IDL get] [hr.size: IDL set to object "test-valueOf" followed by IDL get]
expected: FAIL expected: FAIL
[hr.width: typeof IDL attribute]
expected: FAIL
[hr.width: IDL get with DOM attribute unset]
expected: FAIL
[hr.width: setAttribute() to "" followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo " followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to undefined followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to 7 followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to 1.5 followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to true followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to false followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to object "[object Object\]" followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to NaN followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to Infinity followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to -Infinity followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to "\\0" followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to null followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to object "test-toString" followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to object "test-valueOf" followed by IDL get]
expected: FAIL
[hr.width: IDL set to "" followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo " followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to undefined followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to undefined followed by IDL get]
expected: FAIL
[hr.width: IDL set to 7 followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to 7 followed by IDL get]
expected: FAIL
[hr.width: IDL set to 1.5 followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to 1.5 followed by IDL get]
expected: FAIL
[hr.width: IDL set to true followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to true followed by IDL get]
expected: FAIL
[hr.width: IDL set to false followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to false followed by IDL get]
expected: FAIL
[hr.width: IDL set to object "[object Object\]" followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to object "[object Object\]" followed by IDL get]
expected: FAIL
[hr.width: IDL set to NaN followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to NaN followed by IDL get]
expected: FAIL
[hr.width: IDL set to Infinity followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to Infinity followed by IDL get]
expected: FAIL
[hr.width: IDL set to -Infinity followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to -Infinity followed by IDL get]
expected: FAIL
[hr.width: IDL set to "\\0" followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to null followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to null followed by IDL get]
expected: FAIL
[hr.width: IDL set to object "test-toString" followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to object "test-toString" followed by IDL get]
expected: FAIL
[hr.width: IDL set to object "test-valueOf" followed by IDL get]
expected: FAIL
[hr.itemScope: typeof IDL attribute] [hr.itemScope: typeof IDL attribute]
expected: FAIL expected: FAIL

View file

@ -0,0 +1,18 @@
<style>
.hr {
color: gray;
border-style: inset;
border-width: 1px;
margin: 0.5em auto;
}
</style>
<div class=hr></div>
<div class=hr style="width: 50%"></div>
<div class=hr style="width: 100px"></div>
<div class=hr style="width: 100px"></div>
<div class=hr style="width: 100px"></div>
<div class=hr style="width: 0%"></div>
<div class=hr style="width: 0%"></div>
<div class=hr style="width: 0%"></div>
<div class=hr style="width: 0%"></div>
<div class=hr></div>

View file

@ -0,0 +1,14 @@
<!doctype html>
<meta charset="utf-8">
<title></title>
<link rel="match" href="width-ref.html">
<hr>
<hr width='50%'>
<hr width='100'>
<hr width='100foo'>
<hr width=' 100 '>
<hr width='0'>
<hr width='00'>
<hr width='+0'>
<hr width='+00'>
<hr width='++0'>