Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

script: implement autofocus IDL reflection #32170

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions components/script/dom/htmlelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,17 @@ impl HTMLElementMethods for HTMLElement {
internals.set_attached();
Ok(internals)
}

// https://html.spec.whatwg.org/multipage/#dom-fe-autofocus
fn Autofocus(&self) -> bool {
self.element.has_attribute(&local_name!("autofocus"))
}

// https://html.spec.whatwg.org/multipage/#dom-fe-autofocus
fn SetAutofocus(&self, autofocus: bool) {
self.element
.set_bool_attribute(&local_name!("autofocus"), autofocus);
}
}

fn append_text_node_to_fragment(document: &Document, fragment: &DocumentFragment, text: String) {
Expand Down
13 changes: 12 additions & 1 deletion components/script/dom/svgelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use dom_struct::dom_struct;
use html5ever::{namespace_url, ns, LocalName, Prefix};
use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use style_traits::dom::ElementState;

Expand Down Expand Up @@ -76,4 +76,15 @@ impl SVGElementMethods for SVGElement {
)
})
}

// https://html.spec.whatwg.org/multipage/#dom-fe-autofocus
fn Autofocus(&self) -> bool {
self.element.has_attribute(&local_name!("autofocus"))
}

// https://html.spec.whatwg.org/multipage/#dom-fe-autofocus
fn SetAutofocus(&self, autofocus: bool) {
self.element
.set_bool_attribute(&local_name!("autofocus"), autofocus);
}
}
1 change: 1 addition & 0 deletions components/script/dom/webidls/HTMLElement.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ HTMLElement includes GlobalEventHandlers;
HTMLElement includes DocumentAndElementEventHandlers;
HTMLElement includes ElementContentEditable;
HTMLElement includes ElementCSSInlineStyle;
HTMLElement includes HTMLOrSVGElement;
20 changes: 20 additions & 0 deletions components/script/dom/webidls/HTMLOrSVGElement.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/*
* The origin of this IDL file is
* https://html.spec.whatwg.org/multipage/#htmlorsvgelement
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/

interface mixin HTMLOrSVGElement {
// [SameObject] readonly attribute DOMStringMap dataset;
// attribute DOMString nonce; // intentionally no [CEReactions]

[CEReactions] attribute boolean autofocus;
// [CEReactions] attribute long tabIndex;
// undefined focus(optional FocusOptions options = {});
// undefined blur();
};
1 change: 1 addition & 0 deletions components/script/dom/webidls/SVGElement.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ interface SVGElement : Element {
//SVGElement includes GlobalEventHandlers;
//SVGElement includes SVGElementInstance;
SVGElement includes ElementCSSInlineStyle;
SVGElement includes HTMLOrSVGElement;
Original file line number Diff line number Diff line change
Expand Up @@ -4536,12 +4536,6 @@
[HTMLMarqueeElement interface: document.createElement("marquee") must inherit property "onstart" with the proper type]
expected: FAIL

[HTMLElement interface: document.createElement("noscript") must inherit property "autofocus" with the proper type]
expected: FAIL

[HTMLElement interface: attribute autofocus]
expected: FAIL

[HTMLElement interface: attribute onslotchange]
expected: FAIL

Expand Down
Original file line number Diff line number Diff line change
@@ -1,118 +1,4 @@
[reflection-forms-weekmonth.html]
[input.autofocus: typeof IDL attribute]
expected: FAIL

[input.autofocus: IDL get with DOM attribute unset]
expected: FAIL

[input.autofocus: setAttribute() to ""]
expected: FAIL

[input.autofocus: setAttribute() to " foo "]
expected: FAIL

[input.autofocus: setAttribute() to undefined]
expected: FAIL

[input.autofocus: setAttribute() to null]
expected: FAIL

[input.autofocus: setAttribute() to 7]
expected: FAIL

[input.autofocus: setAttribute() to 1.5]
expected: FAIL

[input.autofocus: setAttribute() to "5%"]
expected: FAIL

[input.autofocus: setAttribute() to "+100"]
expected: FAIL

[input.autofocus: setAttribute() to ".5"]
expected: FAIL

[input.autofocus: setAttribute() to true]
expected: FAIL

[input.autofocus: setAttribute() to false]
expected: FAIL

[input.autofocus: setAttribute() to object "[object Object\]"]
expected: FAIL

[input.autofocus: setAttribute() to NaN]
expected: FAIL

[input.autofocus: setAttribute() to Infinity]
expected: FAIL

[input.autofocus: setAttribute() to -Infinity]
expected: FAIL

[input.autofocus: setAttribute() to "\\0"]
expected: FAIL

[input.autofocus: setAttribute() to object "test-toString"]
expected: FAIL

[input.autofocus: setAttribute() to object "test-valueOf"]
expected: FAIL

[input.autofocus: setAttribute() to "autofocus"]
expected: FAIL

[input.autofocus: IDL set to ""]
expected: FAIL

[input.autofocus: IDL set to " foo "]
expected: FAIL

[input.autofocus: IDL set to undefined]
expected: FAIL

[input.autofocus: IDL set to null]
expected: FAIL

[input.autofocus: IDL set to 7]
expected: FAIL

[input.autofocus: IDL set to 1.5]
expected: FAIL

[input.autofocus: IDL set to "5%"]
expected: FAIL

[input.autofocus: IDL set to "+100"]
expected: FAIL

[input.autofocus: IDL set to ".5"]
expected: FAIL

[input.autofocus: IDL set to false]
expected: FAIL

[input.autofocus: IDL set to object "[object Object\]"]
expected: FAIL

[input.autofocus: IDL set to NaN]
expected: FAIL

[input.autofocus: IDL set to Infinity]
expected: FAIL

[input.autofocus: IDL set to -Infinity]
expected: FAIL

[input.autofocus: IDL set to "\\0"]
expected: FAIL

[input.autofocus: IDL set to object "test-toString"]
expected: FAIL

[input.autofocus: IDL set to object "test-valueOf"]
expected: FAIL

[input.accessKey: typeof IDL attribute]
expected: FAIL

Expand Down