script: Add pre element obsolete width attribute support (#31792)

This commit is contained in:
Bastiaan van der Plaat 2024-03-25 12:36:48 +01:00 committed by GitHub
parent bd39e03eeb
commit 97144ddf71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 35 additions and 543 deletions

View file

@ -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 {
@ -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);
}