Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various events-related improvements #15133

Merged
merged 10 commits into from Jan 21, 2017
@@ -13,7 +13,7 @@ use dom::bindings::js::Root;
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::globalscope::GlobalScope;
use dom::window::Window;
use servo_atoms::Atom;

// https://html.spec.whatwg.org/multipage/#beforeunloadevent
@@ -31,17 +31,17 @@ impl BeforeUnloadEvent {
}
}

pub fn new_uninitialized(global: &GlobalScope) -> Root<BeforeUnloadEvent> {
pub fn new_uninitialized(window: &Window) -> Root<BeforeUnloadEvent> {
reflect_dom_object(box BeforeUnloadEvent::new_inherited(),
global,
window,
BeforeUnloadEventBinding::Wrap)
}

pub fn new(global: &GlobalScope,
pub fn new(window: &Window,
type_: Atom,
bubbles: EventBubbles,
cancelable: EventCancelable) -> Root<BeforeUnloadEvent> {
let ev = BeforeUnloadEvent::new_uninitialized(global);
let ev = BeforeUnloadEvent::new_uninitialized(window);
{
let event = ev.upcast::<Event>();
event.init_event(type_, bool::from(bubbles),
@@ -7,6 +7,7 @@ use devtools_traits::ScriptToDevtoolsControlMsg;
use document_loader::{DocumentLoader, LoadType};
use dom::activation::{ActivationSource, synthetic_click_activation};
use dom::attr::Attr;
use dom::beforeunloadevent::BeforeUnloadEvent;
use dom::bindings::callback::ExceptionHandling;
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods;
@@ -2603,6 +2604,8 @@ impl DocumentMethods for Document {
fn CreateEvent(&self, mut interface: DOMString) -> Fallible<Root<Event>> {
interface.make_ascii_lowercase();
match &*interface {
"beforeunloadevent" =>
Ok(Root::upcast(BeforeUnloadEvent::new_uninitialized(&self.window))),
"closeevent" =>
Ok(Root::upcast(CloseEvent::new_uninitialized(self.window.upcast()))),
"customevent" =>
@@ -2612,19 +2615,19 @@ impl DocumentMethods for Document {
"events" | "event" | "htmlevents" | "svgevents" =>
Ok(Event::new_uninitialized(&self.window.upcast())),
"focusevent" =>
Ok(Root::upcast(FocusEvent::new_uninitialized(self.window.upcast()))),
Ok(Root::upcast(FocusEvent::new_uninitialized(&self.window))),
"hashchangeevent" =>
Ok(Root::upcast(HashChangeEvent::new_uninitialized(&self.window.upcast()))),
Ok(Root::upcast(HashChangeEvent::new_uninitialized(&self.window))),
"keyboardevent" =>
Ok(Root::upcast(KeyboardEvent::new_uninitialized(&self.window))),
"messageevent" =>
Ok(Root::upcast(MessageEvent::new_uninitialized(self.window.upcast()))),
"mouseevent" | "mouseevents" =>
Ok(Root::upcast(MouseEvent::new_uninitialized(&self.window))),
"pagetransitionevent" =>
Ok(Root::upcast(PageTransitionEvent::new_uninitialized(self.window.upcast()))),
Ok(Root::upcast(PageTransitionEvent::new_uninitialized(&self.window))),
"popstateevent" =>
Ok(Root::upcast(PopStateEvent::new_uninitialized(self.window.upcast()))),
Ok(Root::upcast(PopStateEvent::new_uninitialized(&self.window))),
"progressevent" =>
Ok(Root::upcast(ProgressEvent::new_uninitialized(self.window.upcast()))),
"storageevent" => {
@@ -12,7 +12,6 @@ use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::event::{EventBubbles, EventCancelable};
use dom::eventtarget::EventTarget;
use dom::globalscope::GlobalScope;
use dom::uievent::UIEvent;
use dom::window::Window;
use std::default::Default;
@@ -31,9 +30,9 @@ impl FocusEvent {
}
}

pub fn new_uninitialized(global: &GlobalScope) -> Root<FocusEvent> {
pub fn new_uninitialized(window: &Window) -> Root<FocusEvent> {
reflect_dom_object(box FocusEvent::new_inherited(),
global,
window,
FocusEventBinding::Wrap)
}

@@ -44,7 +43,7 @@ impl FocusEvent {
view: Option<&Window>,
detail: i32,
related_target: Option<&EventTarget>) -> Root<FocusEvent> {
let ev = FocusEvent::new_uninitialized(window.upcast());
let ev = FocusEvent::new_uninitialized(window);
ev.upcast::<UIEvent>().InitUIEvent(type_,
bool::from(can_bubble),
bool::from(cancelable),
@@ -11,7 +11,7 @@ use dom::bindings::js::Root;
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::{DOMString, USVString};
use dom::event::Event;
use dom::globalscope::GlobalScope;
use dom::window::Window;
use servo_atoms::Atom;

// https://html.spec.whatwg.org/multipage/#hashchangeevent
@@ -31,21 +31,21 @@ impl HashChangeEvent {
}
}

pub fn new_uninitialized(global: &GlobalScope) -> Root<HashChangeEvent> {
pub fn new_uninitialized(window: &Window) -> Root<HashChangeEvent> {
reflect_dom_object(box HashChangeEvent::new_inherited(String::new(), String::new()),
global,
window,
HashChangeEventBinding::Wrap)
}

pub fn new(global: &GlobalScope,
pub fn new(window: &Window,
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,
window,
HashChangeEventBinding::Wrap);
{
let event = ev.upcast::<Event>();
@@ -54,11 +54,11 @@ impl HashChangeEvent {
ev
}

pub fn Constructor(global: &GlobalScope,
pub fn Constructor(window: &Window,
type_: DOMString,
init: &HashChangeEventBinding::HashChangeEventInit)
-> Fallible<Root<HashChangeEvent>> {
Ok(HashChangeEvent::new(global,
Ok(HashChangeEvent::new(window,
Atom::from(type_),
init.parent.bubbles,
init.parent.cancelable,
@@ -11,7 +11,7 @@ use dom::bindings::js::Root;
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::event::Event;
use dom::globalscope::GlobalScope;
use dom::window::Window;
use servo_atoms::Atom;
use std::cell::Cell;

@@ -30,19 +30,19 @@ impl PageTransitionEvent {
}
}

pub fn new_uninitialized(global: &GlobalScope) -> Root<PageTransitionEvent> {
pub fn new_uninitialized(window: &Window) -> Root<PageTransitionEvent> {
reflect_dom_object(box PageTransitionEvent::new_inherited(),
global,
window,
PageTransitionEventBinding::Wrap)
}

pub fn new(global: &GlobalScope,
pub fn new(window: &Window,
type_: Atom,
bubbles: bool,
cancelable: bool,
persisted: bool)
-> Root<PageTransitionEvent> {
let ev = PageTransitionEvent::new_uninitialized(global);
let ev = PageTransitionEvent::new_uninitialized(window);
ev.persisted.set(persisted);
{
let event = ev.upcast::<Event>();
@@ -51,11 +51,11 @@ impl PageTransitionEvent {
ev
}

pub fn Constructor(global: &GlobalScope,
pub fn Constructor(window: &Window,
type_: DOMString,
init: &PageTransitionEventBinding::PageTransitionEventInit)
-> Fallible<Root<PageTransitionEvent>> {
Ok(PageTransitionEvent::new(global,
Ok(PageTransitionEvent::new(window,
Atom::from(type_),
init.parent.bubbles,
init.parent.cancelable,
@@ -11,7 +11,7 @@ use dom::bindings::js::{MutHeapJSVal, Root};
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::event::Event;
use dom::globalscope::GlobalScope;
use dom::window::Window;
use js::jsapi::{HandleValue, JSContext};
use js::jsval::JSVal;
use servo_atoms::Atom;
@@ -32,19 +32,19 @@ impl PopStateEvent {
}
}

pub fn new_uninitialized(global: &GlobalScope) -> Root<PopStateEvent> {
pub fn new_uninitialized(window: &Window) -> Root<PopStateEvent> {
reflect_dom_object(box PopStateEvent::new_inherited(),
global,
window,
PopStateEventBinding::Wrap)
}

pub fn new(global: &GlobalScope,
pub fn new(window: &Window,
type_: Atom,
bubbles: bool,
cancelable: bool,
state: HandleValue)
-> Root<PopStateEvent> {
let ev = PopStateEvent::new_uninitialized(global);
let ev = PopStateEvent::new_uninitialized(window);
ev.state.set(state.get());
{
let event = ev.upcast::<Event>();
@@ -54,11 +54,11 @@ impl PopStateEvent {
}

#[allow(unsafe_code)]
pub fn Constructor(global: &GlobalScope,
pub fn Constructor(window: &Window,
type_: DOMString,
init: &PopStateEventBinding::PopStateEventInit)
-> Fallible<Root<PopStateEvent>> {
Ok(PopStateEvent::new(global,
Ok(PopStateEvent::new(window,
Atom::from(type_),
init.parent.bubbles,
init.parent.cancelable,
@@ -12,7 +12,6 @@ use dom::bindings::num::Finite;
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::event::Event;
use dom::globalscope::GlobalScope;
use dom::window::Window;
use servo_atoms::Atom;

@@ -25,7 +24,7 @@ pub struct TransitionEvent {
}

impl TransitionEvent {
pub fn new_inherited(init: &TransitionEventInit) -> TransitionEvent {
fn new_inherited(init: &TransitionEventInit) -> TransitionEvent {
TransitionEvent {
event: Event::new_inherited(),
property_name: Atom::from(init.propertyName.clone()),
@@ -34,11 +33,11 @@ impl TransitionEvent {
}
}

pub fn new(global: &GlobalScope,
pub fn new(window: &Window,
type_: Atom,
init: &TransitionEventInit) -> Root<TransitionEvent> {
let ev = reflect_dom_object(box TransitionEvent::new_inherited(init),
global,
window,
TransitionEventBinding::Wrap);
{
let event = ev.upcast::<Event>();
@@ -50,8 +49,7 @@ impl TransitionEvent {
pub fn Constructor(window: &Window,
type_: DOMString,
init: &TransitionEventInit) -> Fallible<Root<TransitionEvent>> {
let global = window.upcast::<GlobalScope>();
Ok(TransitionEvent::new(global, Atom::from(type_), init))
Ok(TransitionEvent::new(window, Atom::from(type_), init))
}
}

@@ -6,7 +6,7 @@
* https://html.spec.whatwg.org/multipage/#beforeunloadevent
*/

[Exposed=(Window,Worker)]
[Exposed=Window]
interface BeforeUnloadEvent : Event {
attribute DOMString returnValue;
};
@@ -3,7 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// https://w3c.github.io/uievents/#interface-FocusEvent
[Constructor(DOMString typeArg, optional FocusEventInit focusEventInitDict)]
[Constructor(DOMString typeArg, optional FocusEventInit focusEventInitDict),
Exposed=Window]
interface FocusEvent : UIEvent {
readonly attribute EventTarget? relatedTarget;
};
@@ -3,7 +3,8 @@
* 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)]
[Constructor(DOMString type, optional HashChangeEventInit eventInitDict),
Exposed=Window]
interface HashChangeEvent : Event {
readonly attribute USVString oldURL;
readonly attribute USVString newURL;
@@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// https://html.spec.whatwg.org/multipage/#location
[Exposed=(Window,Worker), Unforgeable] interface Location {
[Exposed=Window, Unforgeable] interface Location {
/*stringifier*/ attribute USVString href;
readonly attribute USVString origin;
attribute USVString protocol;
@@ -3,7 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// https://w3c.github.io/uievents/#interface-mouseevent
[Constructor(DOMString typeArg, optional MouseEventInit mouseEventInitDict)]
[Constructor(DOMString typeArg, optional MouseEventInit mouseEventInitDict),
Exposed=Window]
interface MouseEvent : UIEvent {
readonly attribute long screenX;
readonly attribute long screenY;
@@ -3,7 +3,8 @@
* 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)]
[Constructor(DOMString type, optional PageTransitionEventInit eventInitDict),
Exposed=Window]
interface PageTransitionEvent : Event {
readonly attribute boolean persisted;
};
@@ -3,7 +3,8 @@
* 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)]
[Constructor(DOMString type, optional PopStateEventInit eventInitDict),
Exposed=Window]
interface PopStateEvent : Event {
readonly attribute any state;
};
@@ -1624,7 +1624,7 @@ impl ScriptThread {
// FIXME: Handle pseudo-elements properly
pseudoElement: DOMString::new()
};
let transition_event = TransitionEvent::new(window.upcast(),
let transition_event = TransitionEvent::new(&window,
atom!("transitionend"),
&init);
transition_event.upcast::<Event>().fire(node.upcast());
@@ -3,9 +3,6 @@
[If the event's initialized flag is not set, an InvalidStateError must be thrown (AnimationEvent).]
expected: FAIL
[If the event's initialized flag is not set, an InvalidStateError must be thrown (BeforeUnloadEvent).]
expected: FAIL

[If the event's initialized flag is not set, an InvalidStateError must be thrown (CompositionEvent).]
expected: FAIL

@@ -19,24 +19,6 @@
[createEvent('ANIMATIONEVENT') should be initialized correctly.]
expected: FAIL

[BeforeUnloadEvent should be an alias for BeforeUnloadEvent.]
expected: FAIL

[createEvent('BeforeUnloadEvent') should be initialized correctly.]
expected: FAIL

[beforeunloadevent should be an alias for BeforeUnloadEvent.]
expected: FAIL

[createEvent('beforeunloadevent') should be initialized correctly.]
expected: FAIL

[BEFOREUNLOADEVENT should be an alias for BeforeUnloadEvent.]
expected: FAIL

[createEvent('BEFOREUNLOADEVENT') should be initialized correctly.]
expected: FAIL

[CompositionEvent should be an alias for CompositionEvent.]
expected: FAIL

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.