Auto merge of #18093 - pyfisch:compositionevent, r=jdm

Add CompositionEvent bindings

<!-- Please describe your changes on the following line: -->
Needed for better keyboard input. See also #17578

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18093)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-08-22 16:03:23 -05:00 committed by GitHub
commit 111e9951c9
4 changed files with 86 additions and 0 deletions

View file

@ -0,0 +1,64 @@
/* 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::CompositionEventBinding::{self, CompositionEventMethods};
use dom::bindings::codegen::Bindings::UIEventBinding::UIEventBinding::UIEventMethods;
use dom::bindings::error::Fallible;
use dom::bindings::js::{Root, RootedReference};
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::uievent::UIEvent;
use dom::window::Window;
use dom_struct::dom_struct;
#[dom_struct]
pub struct CompositionEvent {
uievent: UIEvent,
data: DOMString,
}
impl CompositionEvent {
pub fn new(window: &Window,
type_: DOMString,
can_bubble: bool,
cancelable: bool,
view: Option<&Window>,
detail: i32,
data: DOMString) -> Root<CompositionEvent> {
let ev = reflect_dom_object(box CompositionEvent {
uievent: UIEvent::new_inherited(),
data: data,
},
window,
CompositionEventBinding::Wrap);
ev.uievent.InitUIEvent(type_, can_bubble, cancelable, view, detail);
ev
}
pub fn Constructor(window: &Window,
type_: DOMString,
init: &CompositionEventBinding::CompositionEventInit)
-> Fallible<Root<CompositionEvent>> {
let event = CompositionEvent::new(window,
type_,
init.parent.parent.bubbles,
init.parent.parent.cancelable,
init.parent.view.r(),
init.parent.detail,
init.data.clone());
Ok(event)
}
}
impl CompositionEventMethods for CompositionEvent {
// https://w3c.github.io/uievents/#dom-compositionevent-data
fn Data(&self) -> DOMString {
self.data.clone()
}
// https://dom.spec.whatwg.org/#dom-event-istrusted
fn IsTrusted(&self) -> bool {
self.uievent.IsTrusted()
}
}

View file

@ -236,6 +236,7 @@ pub mod characterdata;
pub mod client;
pub mod closeevent;
pub mod comment;
pub mod compositionevent;
pub mod console;
mod create;
pub mod crypto;

View file

@ -0,0 +1,20 @@
/* 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/. */
/*
* The origin of this IDL file is
* https://w3c.github.io/uievents/#idl-compositionevent
*
*/
// https://w3c.github.io/uievents/#idl-compositionevent
[Pref="dom.compositionevent.enabled", Constructor(DOMString type, optional CompositionEventInit eventInitDict)]
interface CompositionEvent : UIEvent {
readonly attribute DOMString data;
};
// https://w3c.github.io/uievents/#idl-compositioneventinit
dictionary CompositionEventInit : UIEventInit {
DOMString data = "";
};

View file

@ -1,6 +1,7 @@
{
"dom.bluetooth.enabled": false,
"dom.bluetooth.testing.enabled": false,
"dom.compositionevent.enabled": false,
"dom.customelements.enabled": false,
"dom.forcetouch.enabled": false,
"dom.gamepad.enabled": false,