dom: Add missing event handlers

Adding:
* global event handlers,
* window event handlers,
* document and element handlers,
* and support for BeforeUnloadEvent.

Signed-off-by: Piotr Stankiewicz <bionicrift@gmail.com>
This commit is contained in:
Piotr Stankiewicz 2016-05-15 23:47:15 +01:00
parent 4590fe230f
commit d1af39c114
21 changed files with 373 additions and 861 deletions

View file

@ -137,6 +137,9 @@ impl HTMLElementMethods for HTMLElement {
// https://html.spec.whatwg.org/multipage/#globaleventhandlers
global_event_handlers!(NoOnload);
// https://html.spec.whatwg.org/multipage/#documentandelementeventhandlers
document_and_element_event_handlers!();
// https://html.spec.whatwg.org/multipage/#dom-dataset
fn Dataset(&self) -> Root<DOMStringMap> {
self.dataset.or_init(|| DOMStringMap::new(self))
@ -196,6 +199,42 @@ 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()
} else {
self.upcast::<EventTarget>().get_event_handler_common("focus")
}
}
// 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)
} else {
self.upcast::<EventTarget>().set_event_handler_common("focus", listener)
}
}
// 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()
} else {
self.upcast::<EventTarget>().get_event_handler_common("scroll")
}
}
// 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)
} else {
self.upcast::<EventTarget>().set_event_handler_common("scroll", listener)
}
}
// https://html.spec.whatwg.org/multipage/#dom-click
fn Click(&self) {
if !self.upcast::<Element>().disabled_state() {