mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
servo: Merge #15359 - Event handlers forwarded to a window check for window presence (from freeatnet:15332-macroed-event-handlers-check-for-window); r=KiChjang
<!-- Please describe your changes on the following line: --> This change adds a check for the presence of a window in event handlers of `body` and `frameset` that are forwarded to the window. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15332 <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> I'm new to both Servo and Rust — so any suggestions for improvement are very welcome. Source-Repo: https://github.com/servo/servo Source-Revision: 8926db302a71079b8c116247abbcf059fde4e808 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : e8861adf5d8ce432fe03ed6ee18a06a612272e04
This commit is contained in:
parent
168749a3e5
commit
2ccd8afaca
@ -367,6 +367,9 @@ impl Document {
|
||||
self.loader.borrow_mut()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn has_browsing_context(&self) -> bool { self.has_browsing_context }
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#concept-document-bc
|
||||
#[inline]
|
||||
pub fn browsing_context(&self) -> Option<Root<BrowsingContext>> {
|
||||
|
@ -151,7 +151,12 @@ impl HTMLElementMethods for HTMLElement {
|
||||
// https://html.spec.whatwg.org/multipage/#handler-onload
|
||||
fn GetOnload(&self) -> Option<Rc<EventHandlerNonNull>> {
|
||||
if self.is_body_or_frameset() {
|
||||
window_from_node(self).GetOnload()
|
||||
let document = document_from_node(self);
|
||||
if document.has_browsing_context() {
|
||||
document.window().GetOnload()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
self.upcast::<EventTarget>().get_event_handler_common("load")
|
||||
}
|
||||
@ -160,7 +165,10 @@ impl HTMLElementMethods for HTMLElement {
|
||||
// https://html.spec.whatwg.org/multipage/#handler-onload
|
||||
fn SetOnload(&self, listener: Option<Rc<EventHandlerNonNull>>) {
|
||||
if self.is_body_or_frameset() {
|
||||
window_from_node(self).SetOnload(listener)
|
||||
let document = document_from_node(self);
|
||||
if document.has_browsing_context() {
|
||||
document.window().SetOnload(listener)
|
||||
}
|
||||
} else {
|
||||
self.upcast::<EventTarget>().set_event_handler_common("load", listener)
|
||||
}
|
||||
@ -169,7 +177,12 @@ impl HTMLElementMethods for HTMLElement {
|
||||
// https://html.spec.whatwg.org/multipage/#handler-onresize
|
||||
fn GetOnresize(&self) -> Option<Rc<EventHandlerNonNull>> {
|
||||
if self.is_body_or_frameset() {
|
||||
window_from_node(self).GetOnload()
|
||||
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")
|
||||
}
|
||||
@ -178,7 +191,10 @@ impl HTMLElementMethods for HTMLElement {
|
||||
// https://html.spec.whatwg.org/multipage/#handler-onresize
|
||||
fn SetOnresize(&self, listener: Option<Rc<EventHandlerNonNull>>) {
|
||||
if self.is_body_or_frameset() {
|
||||
window_from_node(self).SetOnresize(listener);
|
||||
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)
|
||||
}
|
||||
@ -187,7 +203,12 @@ impl HTMLElementMethods for HTMLElement {
|
||||
// https://html.spec.whatwg.org/multipage/#handler-onblur
|
||||
fn GetOnblur(&self) -> Option<Rc<EventHandlerNonNull>> {
|
||||
if self.is_body_or_frameset() {
|
||||
window_from_node(self).GetOnblur()
|
||||
let document = document_from_node(self);
|
||||
if document.has_browsing_context() {
|
||||
document.window().GetOnblur()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
self.upcast::<EventTarget>().get_event_handler_common("blur")
|
||||
}
|
||||
@ -196,7 +217,10 @@ impl HTMLElementMethods for HTMLElement {
|
||||
// https://html.spec.whatwg.org/multipage/#handler-onblur
|
||||
fn SetOnblur(&self, listener: Option<Rc<EventHandlerNonNull>>) {
|
||||
if self.is_body_or_frameset() {
|
||||
window_from_node(self).SetOnblur(listener)
|
||||
let document = document_from_node(self);
|
||||
if document.has_browsing_context() {
|
||||
document.window().SetOnblur(listener)
|
||||
}
|
||||
} else {
|
||||
self.upcast::<EventTarget>().set_event_handler_common("blur", listener)
|
||||
}
|
||||
@ -205,7 +229,12 @@ impl HTMLElementMethods for HTMLElement {
|
||||
// https://html.spec.whatwg.org/multipage/#handler-onfocus
|
||||
fn GetOnfocus(&self) -> Option<Rc<EventHandlerNonNull>> {
|
||||
if self.is_body_or_frameset() {
|
||||
window_from_node(self).GetOnfocus()
|
||||
let document = document_from_node(self);
|
||||
if document.has_browsing_context() {
|
||||
document.window().GetOnfocus()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
self.upcast::<EventTarget>().get_event_handler_common("focus")
|
||||
}
|
||||
@ -214,7 +243,10 @@ impl HTMLElementMethods for HTMLElement {
|
||||
// https://html.spec.whatwg.org/multipage/#handler-onfocus
|
||||
fn SetOnfocus(&self, listener: Option<Rc<EventHandlerNonNull>>) {
|
||||
if self.is_body_or_frameset() {
|
||||
window_from_node(self).SetOnfocus(listener)
|
||||
let document = document_from_node(self);
|
||||
if document.has_browsing_context() {
|
||||
document.window().SetOnfocus(listener)
|
||||
}
|
||||
} else {
|
||||
self.upcast::<EventTarget>().set_event_handler_common("focus", listener)
|
||||
}
|
||||
@ -223,7 +255,12 @@ impl HTMLElementMethods for HTMLElement {
|
||||
// https://html.spec.whatwg.org/multipage/#handler-onscroll
|
||||
fn GetOnscroll(&self) -> Option<Rc<EventHandlerNonNull>> {
|
||||
if self.is_body_or_frameset() {
|
||||
window_from_node(self).GetOnscroll()
|
||||
let document = document_from_node(self);
|
||||
if document.has_browsing_context() {
|
||||
document.window().GetOnscroll()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
self.upcast::<EventTarget>().get_event_handler_common("scroll")
|
||||
}
|
||||
@ -232,7 +269,10 @@ impl HTMLElementMethods for HTMLElement {
|
||||
// https://html.spec.whatwg.org/multipage/#handler-onscroll
|
||||
fn SetOnscroll(&self, listener: Option<Rc<EventHandlerNonNull>>) {
|
||||
if self.is_body_or_frameset() {
|
||||
window_from_node(self).SetOnscroll(listener)
|
||||
let document = document_from_node(self);
|
||||
if document.has_browsing_context() {
|
||||
document.window().SetOnscroll(listener)
|
||||
}
|
||||
} else {
|
||||
self.upcast::<EventTarget>().set_event_handler_common("scroll", listener)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use dom::bindings::js::Root;
|
||||
use dom::bindings::str::DOMString;
|
||||
use dom::document::Document;
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::{Node, window_from_node};
|
||||
use dom::node::{Node, document_from_node};
|
||||
use html5ever_atoms::LocalName;
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -354,11 +354,19 @@ macro_rules! define_event_handler(
|
||||
macro_rules! define_window_owned_event_handler(
|
||||
($handler: ident, $event_type: ident, $getter: ident, $setter: ident) => (
|
||||
fn $getter(&self) -> Option<::std::rc::Rc<$handler>> {
|
||||
window_from_node(self).$getter()
|
||||
let document = document_from_node(self);
|
||||
if document.has_browsing_context() {
|
||||
document.window().$getter()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn $setter(&self, listener: Option<::std::rc::Rc<$handler>>) {
|
||||
window_from_node(self).$setter(listener)
|
||||
let document = document_from_node(self);
|
||||
if document.has_browsing_context() {
|
||||
document.window().$setter(listener)
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user