Skip to content

Commit

Permalink
Add KeyboardEvent stub.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm authored and kmcallister committed Nov 4, 2014
1 parent f7c596a commit cc3ed96
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 24 deletions.
14 changes: 5 additions & 9 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -4274,7 +4274,7 @@ def struct(self):
d = self.dictionary
if d.parent:
inheritance = " pub parent: %s::%s<'a, 'b>,\n" % (self.makeModuleName(d.parent),
self.makeClassName(d.parent))
self.makeClassName(d.parent))
else:
inheritance = ""
memberDecls = [" pub %s: %s," %
Expand Down Expand Up @@ -4341,12 +4341,7 @@ def makeClassName(self, dictionary):

@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
Expand Down Expand Up @@ -4529,7 +4524,7 @@ def __init__(self, config, prefix, webIDLFile):
'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}',
Expand Down Expand Up @@ -5425,7 +5420,8 @@ def InterfaceTypes(config):
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
Expand Down
3 changes: 3 additions & 0 deletions components/script/dom/bindings/codegen/parser/WebIDL.py
Expand Up @@ -1422,6 +1422,9 @@ def dictionaryContainsDictionary(dictMember, dictionary):
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

Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/event.rs
Expand Up @@ -29,7 +29,7 @@ pub enum EventPhase {
pub enum EventTypeId {
CustomEventTypeId,
HTMLEventTypeId,
KeyEventTypeId,
KeyboardEventTypeId,
MessageEventTypeId,
MouseEventTypeId,
ProgressEventTypeId,
Expand Down
43 changes: 43 additions & 0 deletions components/script/dom/keyboardevent.rs
@@ -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()
}
}
18 changes: 9 additions & 9 deletions components/script/dom/mouseevent.rs
Expand Up @@ -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>,
Expand All @@ -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),
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
}
}
36 changes: 36 additions & 0 deletions components/script/dom/webidls/KeyboardEvent.webidl
@@ -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;
};
6 changes: 1 addition & 5 deletions components/script/dom/webidls/MouseEvent.webidl
Expand Up @@ -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;
Expand Down
@@ -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;
};
1 change: 1 addition & 0 deletions components/script/lib.rs
Expand Up @@ -177,6 +177,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;
Expand Down

0 comments on commit cc3ed96

Please sign in to comment.