Error and resize get special getter/setters for reflection

This commit is contained in:
Patrick Shaughnessy 2020-01-29 21:10:22 -05:00
parent 6d220d02de
commit f043a3eee2
5 changed files with 60 additions and 75 deletions

View file

@ -5,6 +5,7 @@
use crate::dom::activation::{synthetic_click_activation, ActivationSource}; use crate::dom::activation::{synthetic_click_activation, ActivationSource};
use crate::dom::attr::Attr; use crate::dom::attr::Attr;
use crate::dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use crate::dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
use crate::dom::bindings::codegen::Bindings::EventHandlerBinding::OnErrorEventHandlerNonNull;
use crate::dom::bindings::codegen::Bindings::HTMLElementBinding; use crate::dom::bindings::codegen::Bindings::HTMLElementBinding;
use crate::dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods; use crate::dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods;
use crate::dom::bindings::codegen::Bindings::HTMLLabelElementBinding::HTMLLabelElementMethods; use crate::dom::bindings::codegen::Bindings::HTMLLabelElementBinding::HTMLLabelElementMethods;
@ -181,6 +182,35 @@ impl HTMLElementMethods for HTMLElement {
self.dataset.or_init(|| DOMStringMap::new(self)) self.dataset.or_init(|| DOMStringMap::new(self))
} }
// https://html.spec.whatwg.org/multipage/#handler-onerror
fn GetOnerror(&self) -> Option<Rc<OnErrorEventHandlerNonNull>> {
if self.is_body_or_frameset() {
let document = document_from_node(self);
if document.has_browsing_context() {
document.window().GetOnerror()
} else {
None
}
} else {
self.upcast::<EventTarget>()
.get_event_handler_common("error")
}
}
// https://html.spec.whatwg.org/multipage/#handler-onerror
fn SetOnerror(&self, listener: Option<Rc<OnErrorEventHandlerNonNull>>) {
if self.is_body_or_frameset() {
let document = document_from_node(self);
if document.has_browsing_context() {
document.window().SetOnerror(listener)
}
} else {
// special setter for error
self.upcast::<EventTarget>()
.set_error_event_handler("error", listener)
}
}
// https://html.spec.whatwg.org/multipage/#handler-onload // https://html.spec.whatwg.org/multipage/#handler-onload
fn GetOnload(&self) -> Option<Rc<EventHandlerNonNull>> { fn GetOnload(&self) -> Option<Rc<EventHandlerNonNull>> {
if self.is_body_or_frameset() { if self.is_body_or_frameset() {
@ -209,34 +239,6 @@ impl HTMLElementMethods for HTMLElement {
} }
} }
// https://html.spec.whatwg.org/multipage/#handler-onresize
fn GetOnresize(&self) -> Option<Rc<EventHandlerNonNull>> {
if self.is_body_or_frameset() {
let document = document_from_node(self);
if document.has_browsing_context() {
document.window().GetOnload()
} else {
None
}
} else {
self.upcast::<EventTarget>()
.get_event_handler_common("resize")
}
}
// https://html.spec.whatwg.org/multipage/#handler-onresize
fn SetOnresize(&self, listener: Option<Rc<EventHandlerNonNull>>) {
if self.is_body_or_frameset() {
let document = document_from_node(self);
if document.has_browsing_context() {
document.window().SetOnresize(listener);
}
} else {
self.upcast::<EventTarget>()
.set_event_handler_common("resize", listener)
}
}
// https://html.spec.whatwg.org/multipage/#handler-onblur // https://html.spec.whatwg.org/multipage/#handler-onblur
fn GetOnblur(&self) -> Option<Rc<EventHandlerNonNull>> { fn GetOnblur(&self) -> Option<Rc<EventHandlerNonNull>> {
if self.is_body_or_frameset() { if self.is_body_or_frameset() {
@ -293,6 +295,34 @@ impl HTMLElementMethods for HTMLElement {
} }
} }
// https://html.spec.whatwg.org/multipage/#handler-onresize
fn GetOnresize(&self) -> Option<Rc<EventHandlerNonNull>> {
if self.is_body_or_frameset() {
let document = document_from_node(self);
if document.has_browsing_context() {
document.window().GetOnresize()
} else {
None
}
} else {
self.upcast::<EventTarget>()
.get_event_handler_common("resize")
}
}
// https://html.spec.whatwg.org/multipage/#handler-onresize
fn SetOnresize(&self, listener: Option<Rc<EventHandlerNonNull>>) {
if self.is_body_or_frameset() {
let document = document_from_node(self);
if document.has_browsing_context() {
document.window().SetOnresize(listener)
}
} else {
self.upcast::<EventTarget>()
.set_event_handler_common("resize", listener)
}
}
// https://html.spec.whatwg.org/multipage/#handler-onscroll // https://html.spec.whatwg.org/multipage/#handler-onscroll
fn GetOnscroll(&self) -> Option<Rc<EventHandlerNonNull>> { fn GetOnscroll(&self) -> Option<Rc<EventHandlerNonNull>> {
if self.is_body_or_frameset() { if self.is_body_or_frameset() {

View file

@ -430,7 +430,9 @@ macro_rules! window_owned_beforeunload_event_handler(
// As more methods get added, just update them here. // As more methods get added, just update them here.
macro_rules! global_event_handlers( macro_rules! global_event_handlers(
() => ( () => (
// These are special when on body/frameset elements
event_handler!(blur, GetOnblur, SetOnblur); event_handler!(blur, GetOnblur, SetOnblur);
error_event_handler!(error, GetOnerror, SetOnerror);
event_handler!(focus, GetOnfocus, SetOnfocus); event_handler!(focus, GetOnfocus, SetOnfocus);
event_handler!(load, GetOnload, SetOnload); event_handler!(load, GetOnload, SetOnload);
event_handler!(resize, GetOnresize, SetOnresize); event_handler!(resize, GetOnresize, SetOnresize);
@ -460,7 +462,6 @@ macro_rules! global_event_handlers(
event_handler!(durationchange, GetOndurationchange, SetOndurationchange); event_handler!(durationchange, GetOndurationchange, SetOndurationchange);
event_handler!(emptied, GetOnemptied, SetOnemptied); event_handler!(emptied, GetOnemptied, SetOnemptied);
event_handler!(ended, GetOnended, SetOnended); event_handler!(ended, GetOnended, SetOnended);
error_event_handler!(error, GetOnerror, SetOnerror);
event_handler!(formdata, GetOnformdata, SetOnformdata); event_handler!(formdata, GetOnformdata, SetOnformdata);
event_handler!(input, GetOninput, SetOninput); event_handler!(input, GetOninput, SetOninput);
event_handler!(invalid, GetOninvalid, SetOninvalid); event_handler!(invalid, GetOninvalid, SetOninvalid);

View file

@ -1,14 +1,9 @@
[event-handler-attributes-body-window.html] [event-handler-attributes-body-window.html]
type: testharness type: testharness
[error]
expected: FAIL
[HTMLBodyElement event handlers] [HTMLBodyElement event handlers]
expected: FAIL expected: FAIL
[shadowed error (document.body)]
expected: FAIL
[not shadowed auxclick (document.body)] [not shadowed auxclick (document.body)]
expected: FAIL expected: FAIL
@ -27,9 +22,6 @@
[not shadowed paste (document.body)] [not shadowed paste (document.body)]
expected: FAIL expected: FAIL
[shadowed error (document.createElement("body"))]
expected: FAIL
[not shadowed auxclick (document.createElement("body"))] [not shadowed auxclick (document.createElement("body"))]
expected: FAIL expected: FAIL
@ -48,27 +40,15 @@
[not shadowed paste (document.createElement("body"))] [not shadowed paste (document.createElement("body"))]
expected: FAIL expected: FAIL
[shadowed resize (window)]
expected: FAIL
[not shadowed loadend (window)] [not shadowed loadend (window)]
expected: FAIL expected: FAIL
[shadowed resize (document.body)]
expected: FAIL
[shadowed resize (document.createElement("body"))]
expected: FAIL
[not shadowed securitypolicyviolation (window)] [not shadowed securitypolicyviolation (window)]
expected: FAIL expected: FAIL
[not shadowed auxclick (window)] [not shadowed auxclick (window)]
expected: FAIL expected: FAIL
[shadowed error (window)]
expected: FAIL
[not shadowed slotchange (window)] [not shadowed slotchange (window)]
expected: FAIL expected: FAIL
@ -113,4 +93,3 @@
[not shadowed webkitanimationstart (window)] [not shadowed webkitanimationstart (window)]
expected: FAIL expected: FAIL

View file

@ -1,19 +1,7 @@
[event-handler-attributes-frameset-window.html] [event-handler-attributes-frameset-window.html]
[shadowed resize (window)]
expected: FAIL
[shadowed error (document.createElement("frameset"))]
expected: FAIL
[not shadowed paste (document.createElement("frameset"))] [not shadowed paste (document.createElement("frameset"))]
expected: FAIL expected: FAIL
[shadowed resize (document.body)]
expected: FAIL
[shadowed resize (document.createElement("frameset"))]
expected: FAIL
[not shadowed securitypolicyviolation (document.body)] [not shadowed securitypolicyviolation (document.body)]
expected: FAIL expected: FAIL
@ -44,9 +32,6 @@
[not shadowed paste (document.body)] [not shadowed paste (document.body)]
expected: FAIL expected: FAIL
[shadowed error (document.body)]
expected: FAIL
[not shadowed copy (document.body)] [not shadowed copy (document.body)]
expected: FAIL expected: FAIL
@ -56,9 +41,6 @@
[not shadowed cut (document.createElement("frameset"))] [not shadowed cut (document.createElement("frameset"))]
expected: FAIL expected: FAIL
[shadowed error (window)]
expected: FAIL
[not shadowed auxclick (document.createElement("frameset"))] [not shadowed auxclick (document.createElement("frameset"))]
expected: FAIL expected: FAIL
@ -106,4 +88,3 @@
[not shadowed webkitanimationiteration (document.body)] [not shadowed webkitanimationiteration (document.body)]
expected: FAIL expected: FAIL

View file

@ -2,9 +2,6 @@
[event-handler-attributes-windowless-body] [event-handler-attributes-windowless-body]
expected: FAIL expected: FAIL
[Ignore setting of error window event handlers on windowless body]
expected: FAIL
[auxclick is unaffected on a windowless body] [auxclick is unaffected on a windowless body]
expected: FAIL expected: FAIL
@ -14,9 +11,6 @@
[securitypolicyviolation is unaffected on a windowless body] [securitypolicyviolation is unaffected on a windowless body]
expected: FAIL expected: FAIL
[Ignore setting of error window event handlers on windowless frameset]
expected: FAIL
[auxclick is unaffected on a windowless frameset] [auxclick is unaffected on a windowless frameset]
expected: FAIL expected: FAIL