mirror of
https://github.com/servo/servo.git
synced 2025-07-31 03:00:29 +01:00
add popstateevent, hashchangeevent, pagetransitionevent
This commit is contained in:
parent
641b374f0b
commit
11dd0d7c46
13 changed files with 298 additions and 230 deletions
|
@ -44,6 +44,7 @@ use dom::event::{Event, EventBubbles, EventCancelable};
|
|||
use dom::eventtarget::EventTarget;
|
||||
use dom::focusevent::FocusEvent;
|
||||
use dom::forcetouchevent::ForceTouchEvent;
|
||||
use dom::hashchangeevent::HashChangeEvent;
|
||||
use dom::htmlanchorelement::HTMLAnchorElement;
|
||||
use dom::htmlappletelement::HTMLAppletElement;
|
||||
use dom::htmlareaelement::HTMLAreaElement;
|
||||
|
@ -69,6 +70,8 @@ use dom::mouseevent::MouseEvent;
|
|||
use dom::node::{self, CloneChildrenFlag, Node, NodeDamage, window_from_node};
|
||||
use dom::nodeiterator::NodeIterator;
|
||||
use dom::nodelist::NodeList;
|
||||
use dom::pagetransitionevent::PageTransitionEvent;
|
||||
use dom::popstateevent::PopStateEvent;
|
||||
use dom::processinginstruction::ProcessingInstruction;
|
||||
use dom::progressevent::ProgressEvent;
|
||||
use dom::range::Range;
|
||||
|
@ -2195,6 +2198,12 @@ impl DocumentMethods for Document {
|
|||
Ok(Root::upcast(ErrorEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
||||
"closeevent" =>
|
||||
Ok(Root::upcast(CloseEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
||||
"popstateevent" =>
|
||||
Ok(Root::upcast(PopStateEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
||||
"hashchangeevent" =>
|
||||
Ok(Root::upcast(HashChangeEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
||||
"pagetransitionevent" =>
|
||||
Ok(Root::upcast(PageTransitionEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
||||
_ =>
|
||||
Err(Error::NotSupported),
|
||||
}
|
||||
|
|
87
components/script/dom/hashchangeevent.rs
Normal file
87
components/script/dom/hashchangeevent.rs
Normal file
|
@ -0,0 +1,87 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||
use dom::bindings::codegen::Bindings::HashChangeEventBinding;
|
||||
use dom::bindings::codegen::Bindings::HashChangeEventBinding::HashChangeEventMethods;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::reflector::reflect_dom_object;
|
||||
use dom::bindings::str::USVString;
|
||||
use dom::event::Event;
|
||||
use string_cache::Atom;
|
||||
use util::str::DOMString;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#hashchangeevent
|
||||
#[dom_struct]
|
||||
pub struct HashChangeEvent {
|
||||
event: Event,
|
||||
old_url: String,
|
||||
new_url: String,
|
||||
}
|
||||
|
||||
impl HashChangeEvent {
|
||||
fn new_inherited(old_url: String, new_url: String) -> HashChangeEvent {
|
||||
HashChangeEvent {
|
||||
event: Event::new_inherited(),
|
||||
old_url: old_url,
|
||||
new_url: new_url,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_uninitialized(global: GlobalRef)
|
||||
-> Root<HashChangeEvent> {
|
||||
reflect_dom_object(box HashChangeEvent::new_inherited(String::new(), String::new()),
|
||||
global,
|
||||
HashChangeEventBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn new(global: GlobalRef,
|
||||
type_: Atom,
|
||||
bubbles: bool,
|
||||
cancelable: bool,
|
||||
old_url: String,
|
||||
new_url: String)
|
||||
-> Root<HashChangeEvent> {
|
||||
let ev = reflect_dom_object(box HashChangeEvent::new_inherited(old_url, new_url),
|
||||
global,
|
||||
HashChangeEventBinding::Wrap);
|
||||
{
|
||||
let event = ev.upcast::<Event>();
|
||||
event.init_event(type_, bubbles, cancelable);
|
||||
}
|
||||
ev
|
||||
}
|
||||
|
||||
pub fn Constructor(global: GlobalRef,
|
||||
type_: DOMString,
|
||||
init: &HashChangeEventBinding::HashChangeEventInit)
|
||||
-> Fallible<Root<HashChangeEvent>> {
|
||||
Ok(HashChangeEvent::new(global,
|
||||
Atom::from(type_),
|
||||
init.parent.bubbles,
|
||||
init.parent.cancelable,
|
||||
init.oldURL.0.clone(),
|
||||
init.newURL.0.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
impl HashChangeEventMethods for HashChangeEvent {
|
||||
// https://html.spec.whatwg.org/multipage/#dom-hashchangeevent-oldurl
|
||||
fn OldURL(&self) -> USVString {
|
||||
USVString(self.old_url.clone())
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-hashchangeevent-newurl
|
||||
fn NewURL(&self) -> USVString {
|
||||
USVString(self.new_url.clone())
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-istrusted
|
||||
fn IsTrusted(&self) -> bool {
|
||||
self.event.IsTrusted()
|
||||
}
|
||||
}
|
|
@ -264,6 +264,7 @@ pub mod filereader;
|
|||
pub mod focusevent;
|
||||
pub mod forcetouchevent;
|
||||
pub mod formdata;
|
||||
pub mod hashchangeevent;
|
||||
pub mod htmlanchorelement;
|
||||
pub mod htmlappletelement;
|
||||
pub mod htmlareaelement;
|
||||
|
@ -350,10 +351,12 @@ pub mod navigatorinfo;
|
|||
pub mod node;
|
||||
pub mod nodeiterator;
|
||||
pub mod nodelist;
|
||||
pub mod pagetransitionevent;
|
||||
pub mod performance;
|
||||
pub mod performancetiming;
|
||||
pub mod plugin;
|
||||
pub mod pluginarray;
|
||||
pub mod popstateevent;
|
||||
pub mod processinginstruction;
|
||||
pub mod progressevent;
|
||||
pub mod radionodelist;
|
||||
|
|
76
components/script/dom/pagetransitionevent.rs
Normal file
76
components/script/dom/pagetransitionevent.rs
Normal file
|
@ -0,0 +1,76 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||
use dom::bindings::codegen::Bindings::PageTransitionEventBinding;
|
||||
use dom::bindings::codegen::Bindings::PageTransitionEventBinding::PageTransitionEventMethods;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::reflector::reflect_dom_object;
|
||||
use dom::event::Event;
|
||||
use std::cell::Cell;
|
||||
use string_cache::Atom;
|
||||
use util::str::DOMString;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#pagetransitionevent
|
||||
#[dom_struct]
|
||||
pub struct PageTransitionEvent {
|
||||
event: Event,
|
||||
persisted: Cell<bool>,
|
||||
}
|
||||
|
||||
impl PageTransitionEvent {
|
||||
fn new_inherited() -> PageTransitionEvent {
|
||||
PageTransitionEvent {
|
||||
event: Event::new_inherited(),
|
||||
persisted: Cell::new(false),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_uninitialized(global: GlobalRef) -> Root<PageTransitionEvent> {
|
||||
reflect_dom_object(box PageTransitionEvent::new_inherited(),
|
||||
global,
|
||||
PageTransitionEventBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn new(global: GlobalRef,
|
||||
type_: Atom,
|
||||
bubbles: bool,
|
||||
cancelable: bool,
|
||||
persisted: bool)
|
||||
-> Root<PageTransitionEvent> {
|
||||
let ev = PageTransitionEvent::new_uninitialized(global);
|
||||
ev.persisted.set(persisted);
|
||||
{
|
||||
let event = ev.upcast::<Event>();
|
||||
event.init_event(type_, bubbles, cancelable);
|
||||
}
|
||||
ev
|
||||
}
|
||||
|
||||
pub fn Constructor(global: GlobalRef,
|
||||
type_: DOMString,
|
||||
init: &PageTransitionEventBinding::PageTransitionEventInit)
|
||||
-> Fallible<Root<PageTransitionEvent>> {
|
||||
Ok(PageTransitionEvent::new(global,
|
||||
Atom::from(type_),
|
||||
init.parent.bubbles,
|
||||
init.parent.cancelable,
|
||||
init.persisted))
|
||||
}
|
||||
}
|
||||
|
||||
impl PageTransitionEventMethods for PageTransitionEvent {
|
||||
// https://html.spec.whatwg.org/multipage/#dom-pagetransitionevent-persisted
|
||||
fn Persisted(&self) -> bool {
|
||||
self.persisted.get()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-istrusted
|
||||
fn IsTrusted(&self) -> bool {
|
||||
self.event.IsTrusted()
|
||||
}
|
||||
}
|
79
components/script/dom/popstateevent.rs
Normal file
79
components/script/dom/popstateevent.rs
Normal file
|
@ -0,0 +1,79 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||
use dom::bindings::codegen::Bindings::PopStateEventBinding;
|
||||
use dom::bindings::codegen::Bindings::PopStateEventBinding::PopStateEventMethods;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::js::{MutHeapJSVal, Root};
|
||||
use dom::bindings::reflector::reflect_dom_object;
|
||||
use dom::event::Event;
|
||||
use js::jsapi::{HandleValue, JSContext};
|
||||
use js::jsval::JSVal;
|
||||
use string_cache::Atom;
|
||||
use util::str::DOMString;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#the-popstateevent-interface
|
||||
#[dom_struct]
|
||||
pub struct PopStateEvent {
|
||||
event: Event,
|
||||
#[ignore_heap_size_of = "Defined in rust-mozjs"]
|
||||
state: MutHeapJSVal,
|
||||
}
|
||||
|
||||
impl PopStateEvent {
|
||||
fn new_inherited() -> PopStateEvent {
|
||||
PopStateEvent {
|
||||
event: Event::new_inherited(),
|
||||
state: MutHeapJSVal::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_uninitialized(global: GlobalRef) -> Root<PopStateEvent> {
|
||||
reflect_dom_object(box PopStateEvent::new_inherited(),
|
||||
global,
|
||||
PopStateEventBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn new(global: GlobalRef,
|
||||
type_: Atom,
|
||||
bubbles: bool,
|
||||
cancelable: bool,
|
||||
state: HandleValue)
|
||||
-> Root<PopStateEvent> {
|
||||
let ev = PopStateEvent::new_uninitialized(global);
|
||||
ev.state.set(state.get());
|
||||
{
|
||||
let event = ev.upcast::<Event>();
|
||||
event.init_event(type_, bubbles, cancelable);
|
||||
}
|
||||
ev
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn Constructor(global: GlobalRef,
|
||||
type_: DOMString,
|
||||
init: &PopStateEventBinding::PopStateEventInit)
|
||||
-> Fallible<Root<PopStateEvent>> {
|
||||
Ok(PopStateEvent::new(global,
|
||||
Atom::from(type_),
|
||||
init.parent.bubbles,
|
||||
init.parent.cancelable,
|
||||
unsafe { HandleValue::from_marked_location(&init.state) }))
|
||||
}
|
||||
}
|
||||
|
||||
impl PopStateEventMethods for PopStateEvent {
|
||||
// https://html.spec.whatwg.org/multipage/#dom-popstateevent-state
|
||||
fn State(&self, _cx: *mut JSContext) -> JSVal {
|
||||
self.state.get()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-istrusted
|
||||
fn IsTrusted(&self) -> bool {
|
||||
self.event.IsTrusted()
|
||||
}
|
||||
}
|
15
components/script/dom/webidls/HashChangeEvent.webidl
Normal file
15
components/script/dom/webidls/HashChangeEvent.webidl
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#hashchangeevent
|
||||
[Constructor(DOMString type, optional HashChangeEventInit eventInitDict)/*, Exposed=(Window,Worker)*/]
|
||||
interface HashChangeEvent : Event {
|
||||
readonly attribute USVString oldURL;
|
||||
readonly attribute USVString newURL;
|
||||
};
|
||||
|
||||
dictionary HashChangeEventInit : EventInit {
|
||||
USVString oldURL = "";
|
||||
USVString newURL = "";
|
||||
};
|
13
components/script/dom/webidls/PageTransitionEvent.webidl
Normal file
13
components/script/dom/webidls/PageTransitionEvent.webidl
Normal file
|
@ -0,0 +1,13 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#the-pagetransitionevent-interface
|
||||
[Constructor(DOMString type, optional PageTransitionEventInit eventInitDict)/*, Exposed=(Window,Worker)*/]
|
||||
interface PageTransitionEvent : Event {
|
||||
readonly attribute boolean persisted;
|
||||
};
|
||||
|
||||
dictionary PageTransitionEventInit : EventInit {
|
||||
boolean persisted = false;
|
||||
};
|
13
components/script/dom/webidls/PopStateEvent.webidl
Normal file
13
components/script/dom/webidls/PopStateEvent.webidl
Normal file
|
@ -0,0 +1,13 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#the-popstateevent-interface
|
||||
[Constructor(DOMString type, optional PopStateEventInit eventInitDict)/*, Exposed=(Window,Worker)*/]
|
||||
interface PopStateEvent : Event {
|
||||
readonly attribute any state;
|
||||
};
|
||||
|
||||
dictionary PopStateEventInit : EventInit {
|
||||
any state = null;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue