Skip to content

Commit

Permalink
script: Add pre element obsolete width attribute support
Browse files Browse the repository at this point in the history
  • Loading branch information
bplaat committed Mar 21, 2024
1 parent 02a0cdd commit 4f0b96d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 429 deletions.
31 changes: 30 additions & 1 deletion components/script/dom/htmlpreelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
use html5ever::{local_name, LocalName, Prefix};
use js::rust::HandleObject;
use style::attr::AttrValue;

use crate::dom::bindings::codegen::Bindings::HTMLPreElementBinding::HTMLPreElementMethods;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document;
use crate::dom::htmlelement::HTMLElement;
use crate::dom::node::Node;
use crate::dom::virtualmethods::VirtualMethods;

#[dom_struct]
pub struct HTMLPreElement {
Expand Down Expand Up @@ -41,3 +46,27 @@ impl HTMLPreElement {
)
}
}

impl VirtualMethods for HTMLPreElement {
fn super_type(&self) -> Option<&dyn VirtualMethods> {
Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
}

fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match *name {
local_name!("width") => AttrValue::from_limited_i32(value.into(), 0),
_ => self
.super_type()
.unwrap()
.parse_plain_attribute(name, value),
}
}
}

impl HTMLPreElementMethods for HTMLPreElement {
// https://html.spec.whatwg.org/multipage/#dom-pre-width
make_int_getter!(Width, "width", 0);

// https://html.spec.whatwg.org/multipage/#dom-pre-width
make_int_setter!(SetWidth, "width", 0);
}
4 changes: 4 additions & 0 deletions components/script/dom/virtualmethods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use crate::dom::htmlobjectelement::HTMLObjectElement;
use crate::dom::htmloptgroupelement::HTMLOptGroupElement;
use crate::dom::htmloptionelement::HTMLOptionElement;
use crate::dom::htmloutputelement::HTMLOutputElement;
use crate::dom::htmlpreelement::HTMLPreElement;
use crate::dom::htmlscriptelement::HTMLScriptElement;
use crate::dom::htmlselectelement::HTMLSelectElement;
use crate::dom::htmlsourceelement::HTMLSourceElement;
Expand Down Expand Up @@ -233,6 +234,9 @@ pub fn vtable_for(node: &Node) -> &dyn VirtualMethods {
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOutputElement)) => {
node.downcast::<HTMLOutputElement>().unwrap() as &dyn VirtualMethods
},
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLPreElement)) => {
node.downcast::<HTMLPreElement>().unwrap() as &dyn VirtualMethods
},
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLScriptElement)) => {
node.downcast::<HTMLScriptElement>().unwrap() as &dyn VirtualMethods
},
Expand Down
3 changes: 1 addition & 2 deletions components/script/dom/webidls/HTMLPreElement.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ interface HTMLPreElement : HTMLElement {

// https://html.spec.whatwg.org/multipage/#HTMLPreElement-partial
partial interface HTMLPreElement {
// [CEReactions]
// attribute long width;
[CEReactions] attribute long width;
};
12 changes: 0 additions & 12 deletions tests/wpt/meta-legacy-layout/html/dom/idlharness.https.html.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2823,9 +2823,6 @@
[HTMLAllCollection interface: existence and properties of interface prototype object]
expected: FAIL

[HTMLPreElement interface: document.createElement("listing") must inherit property "width" with the proper type]
expected: FAIL

[HTMLHRElement interface: document.createElement("hr") must inherit property "noShade" with the proper type]
expected: FAIL

Expand Down Expand Up @@ -3867,9 +3864,6 @@
[HTMLAreaElement interface: attribute referrerPolicy]
expected: FAIL

[HTMLPreElement interface: attribute width]
expected: FAIL

[HTMLInputElement interface: createInput("week") must inherit property "height" with the proper type]
expected: FAIL

Expand Down Expand Up @@ -4272,9 +4266,6 @@
[HTMLParamElement interface: attribute type]
expected: FAIL
[HTMLPreElement interface: document.createElement("xmp") must inherit property "width" with the proper type]
expected: FAIL
[HTMLTableRowElement interface: document.createElement("tr") must inherit property "ch" with the proper type]
expected: FAIL
Expand Down Expand Up @@ -4566,9 +4557,6 @@
[HTMLInputElement interface: createInput("week") must inherit property "autofocus" with the proper type]
expected: FAIL

[HTMLPreElement interface: document.createElement("pre") must inherit property "width" with the proper type]
expected: FAIL

[HTMLOptGroupElement interface: attribute label]
expected: FAIL

Expand Down

0 comments on commit 4f0b96d

Please sign in to comment.