mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Check for the presence of a window when working with event handlers forwarded to the window
This commit is contained in:
parent
ca73b30fcf
commit
d23b34e243
3 changed files with 12 additions and 3 deletions
|
@ -366,6 +366,9 @@ impl Document {
|
||||||
self.loader.borrow_mut()
|
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
|
/// https://html.spec.whatwg.org/multipage/#concept-document-bc
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn browsing_context(&self) -> Option<Root<BrowsingContext>> {
|
pub fn browsing_context(&self) -> Option<Root<BrowsingContext>> {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use dom::bindings::js::Root;
|
||||||
use dom::bindings::str::DOMString;
|
use dom::bindings::str::DOMString;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node, window_from_node};
|
use dom::node::{Node, document_from_node, window_from_node};
|
||||||
use html5ever_atoms::LocalName;
|
use html5ever_atoms::LocalName;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
|
|
@ -354,12 +354,18 @@ macro_rules! define_event_handler(
|
||||||
macro_rules! define_window_owned_event_handler(
|
macro_rules! define_window_owned_event_handler(
|
||||||
($handler: ident, $event_type: ident, $getter: ident, $setter: ident) => (
|
($handler: ident, $event_type: ident, $getter: ident, $setter: ident) => (
|
||||||
fn $getter(&self) -> Option<::std::rc::Rc<$handler>> {
|
fn $getter(&self) -> Option<::std::rc::Rc<$handler>> {
|
||||||
|
if document_from_node(self).has_browsing_context() {
|
||||||
window_from_node(self).$getter()
|
window_from_node(self).$getter()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn $setter(&self, listener: Option<::std::rc::Rc<$handler>>) {
|
fn $setter(&self, listener: Option<::std::rc::Rc<$handler>>) {
|
||||||
|
if document_from_node(self).has_browsing_context() {
|
||||||
window_from_node(self).$setter(listener)
|
window_from_node(self).$setter(listener)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue