Add KeyboardEvent stub.

This commit is contained in:
Josh Matthews 2014-10-03 11:12:33 -04:00
parent 1c64dabb15
commit bb7074698a
9 changed files with 122 additions and 24 deletions

View file

@ -4347,12 +4347,7 @@ class CGDictionary(CGThing):
@staticmethod
def makeModuleName(dictionary):
name = dictionary.identifier.name
if name.endswith('Init'):
return toBindingNamespace(name.replace('Init', ''))
#XXXjdm This breaks on the test webidl files, sigh.
#raise TypeError("No idea how to find this dictionary's definition: " + name)
return "/* uh oh */ %s" % name
return dictionary.module()
def getMemberType(self, memberInfo):
member, (_, _, declType, _) = memberInfo
@ -4535,7 +4530,7 @@ class CGBindingRoot(CGThing):
'dom::bindings::utils::{DOMJSClass, JSCLASS_DOM_GLOBAL}',
'dom::bindings::utils::{FindEnumStringIndex, GetArrayIndexFromId}',
'dom::bindings::utils::{GetPropertyOnPrototype, GetProtoOrIfaceArray}',
'dom::bindings::utils::{HasPropertyOnPrototype, IntVal}',
'dom::bindings::utils::{HasPropertyOnPrototype, IntVal, UintVal}',
'dom::bindings::utils::{Reflectable}',
'dom::bindings::utils::{squirrel_away_unique}',
'dom::bindings::utils::{ThrowingConstructor, unwrap, unwrap_jsmanaged}',
@ -5430,7 +5425,8 @@ class GlobalGenRoots():
def Bindings(config):
descriptors = (set(d.name + "Binding" for d in config.getDescriptors(register=True)) |
set(d.unroll().module() for d in config.callbacks))
set(d.unroll().module() for d in config.callbacks) |
set(d.module() for d in config.getDictionaries()))
curr = CGList([CGGeneric("pub mod %s;\n" % name) for name in sorted(descriptors)])
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
return curr

View file

@ -1422,6 +1422,9 @@ class IDLDictionary(IDLObjectWithScope):
self.identifier.name,
[member.location] + locations)
def module(self):
return self.location.filename().split('/')[-1].split('.webidl')[0] + 'Binding'
def addExtendedAttributes(self, attrs):
assert len(attrs) == 0

View file

@ -29,7 +29,7 @@ pub enum EventPhase {
pub enum EventTypeId {
CustomEventTypeId,
HTMLEventTypeId,
KeyEventTypeId,
KeyboardEventTypeId,
MessageEventTypeId,
MouseEventTypeId,
ProgressEventTypeId,

View file

@ -0,0 +1,43 @@
/* 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::KeyboardEventBinding;
use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods;
use dom::bindings::codegen::InheritTypes::KeyboardEventDerived;
use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector/*, reflect_dom_object*/};
use dom::event::{Event, KeyboardEventTypeId};
use dom::uievent::UIEvent;
use servo_util::str::DOMString;
#[jstraceable]
#[must_root]
pub struct KeyboardEvent {
uievent: UIEvent,
}
impl KeyboardEventDerived for Event {
fn is_keyboardevent(&self) -> bool {
*self.type_id() == KeyboardEventTypeId
}
}
impl KeyboardEvent {
pub fn Constructor(_global: &GlobalRef,
_type_: DOMString,
_init: &KeyboardEventBinding::KeyboardEventInit) -> Fallible<Temporary<KeyboardEvent>> {
fail!()
}
}
impl<'a> KeyboardEventMethods for JSRef<'a, KeyboardEvent> {
}
impl Reflectable for KeyboardEvent {
fn reflector<'a>(&'a self) -> &'a Reflector {
self.uievent.reflector()
}
}

View file

@ -21,7 +21,7 @@ use std::default::Default;
#[dom_struct]
pub struct MouseEvent {
mouseevent: UIEvent,
uievent: UIEvent,
screen_x: Cell<i32>,
screen_y: Cell<i32>,
client_x: Cell<i32>,
@ -43,7 +43,7 @@ impl MouseEventDerived for Event {
impl MouseEvent {
fn new_inherited() -> MouseEvent {
MouseEvent {
mouseevent: UIEvent::new_inherited(MouseEventTypeId),
uievent: UIEvent::new_inherited(MouseEventTypeId),
screen_x: Cell::new(0),
screen_y: Cell::new(0),
client_x: Cell::new(0),
@ -91,13 +91,13 @@ impl MouseEvent {
type_: DOMString,
init: &MouseEventBinding::MouseEventInit) -> Fallible<Temporary<MouseEvent>> {
let event = MouseEvent::new(global.as_window(), type_,
init.parent.parent.bubbles,
init.parent.parent.cancelable,
init.parent.view.root_ref(),
init.parent.detail,
init.parent.parent.parent.bubbles,
init.parent.parent.parent.cancelable,
init.parent.parent.view.root_ref(),
init.parent.parent.detail,
init.screenX, init.screenY,
init.clientX, init.clientY, init.ctrlKey,
init.altKey, init.shiftKey, init.metaKey,
init.clientX, init.clientY, init.parent.ctrlKey,
init.parent.altKey, init.parent.shiftKey, init.parent.metaKey,
init.button, init.relatedTarget.root_ref());
Ok(event)
}
@ -178,6 +178,6 @@ impl<'a> MouseEventMethods for JSRef<'a, MouseEvent> {
impl Reflectable for MouseEvent {
fn reflector<'a>(&'a self) -> &'a Reflector {
self.mouseevent.reflector()
self.uievent.reflector()
}
}

View file

@ -0,0 +1,36 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#interface-KeyboardEvent
*
*/
[Constructor(DOMString typeArg, optional KeyboardEventInit keyboardEventInitDict)]
interface KeyboardEvent : UIEvent {
// KeyLocationCode
const unsigned long DOM_KEY_LOCATION_STANDARD = 0x00;
const unsigned long DOM_KEY_LOCATION_LEFT = 0x01;
const unsigned long DOM_KEY_LOCATION_RIGHT = 0x02;
const unsigned long DOM_KEY_LOCATION_NUMPAD = 0x03;
//readonly attribute DOMString key;
//readonly attribute DOMString code;
//readonly attribute unsigned long location;
//readonly attribute boolean ctrlKey;
//readonly attribute boolean shiftKey;
//readonly attribute boolean altKey;
//readonly attribute boolean metaKey;
//readonly attribute boolean repeat;
//readonly attribute boolean isComposing;
//boolean getModifierState (DOMString keyArg);
};
dictionary KeyboardEventInit : SharedKeyboardAndMouseEventInit {
DOMString key = "";
DOMString code = "";
unsigned long location = 0;
boolean repeat = false;
boolean isComposing = false;
};

View file

@ -22,15 +22,11 @@ interface MouseEvent : UIEvent {
};
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#idl-def-MouseEventInit
dictionary MouseEventInit : UIEventInit {
dictionary MouseEventInit : SharedKeyboardAndMouseEventInit {
long screenX = 0;
long screenY = 0;
long clientX = 0;
long clientY = 0;
boolean ctrlKey = false;
boolean shiftKey = false;
boolean altKey = false;
boolean metaKey = false;
short button = 0;
//unsigned short buttons = 0;
EventTarget? relatedTarget = null;

View file

@ -0,0 +1,23 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#idl-def-SharedKeyboardAndMouseEventInit
dictionary SharedKeyboardAndMouseEventInit : UIEventInit {
boolean ctrlKey = false;
boolean shiftKey = false;
boolean altKey = false;
boolean metaKey = false;
boolean keyModifierStateAltGraph = false;
boolean keyModifierStateCapsLock = false;
boolean keyModifierStateFn = false;
boolean keyModifierStateFnLock = false;
boolean keyModifierStateHyper = false;
boolean keyModifierStateNumLock = false;
boolean keyModifierStateOS = false;
boolean keyModifierStateScrollLock = false;
boolean keyModifierStateSuper = false;
boolean keyModifierStateSymbol = false;
boolean keyModifierStateSymbolLock = false;
};

View file

@ -178,6 +178,7 @@ pub mod dom {
pub mod htmlulistelement;
pub mod htmlvideoelement;
pub mod htmlunknownelement;
pub mod keyboardevent;
pub mod location;
pub mod messageevent;
pub mod mouseevent;