Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed Nov 4, 2014
1 parent 00e53c7 commit e3722bd
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 139 deletions.
9 changes: 9 additions & 0 deletions components/script/dom/bindings/codegen/parser/module.patch
@@ -1,5 +1,14 @@
--- WebIDL.py
+++ WebIDL.py
@@ -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
@@ -3398,6 +3398,9 @@ class IDLCallbackType(IDLType, IDLObjectWithScope):
self._treatNonCallableAsNull = False
self._treatNonObjectAsNull = False
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/htmlinputelement.rs
Expand Up @@ -429,7 +429,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> {
let doc = document_from_node(*self).root();
doc.request_focus(ElementCast::from_ref(*self));
} else if "keydown" == event.Type().as_slice() && !event.DefaultPrevented() &&
(self.input_type.get() == InputText|| self.input_type.get() == InputPassword) {
(self.input_type.get() == InputText || self.input_type.get() == InputPassword) {
let keyevent: Option<JSRef<KeyboardEvent>> = KeyboardEventCast::to_ref(event);
keyevent.map(|event| {
match self.textinput.borrow_mut().handle_keydown(event) {
Expand Down
14 changes: 8 additions & 6 deletions components/script/dom/keyboardevent.rs
Expand Up @@ -117,8 +117,8 @@ impl KeyboardEvent {
key: key_value(key, mods),
code: code_value(key),
location: key_location(key),
char_code: key_char_code(key, mods),
key_code: key_key_code(key),
char_code: key_charcode(key, mods),
key_code: key_keycode(key),
}
}
}
Expand Down Expand Up @@ -215,7 +215,7 @@ fn key_value(key: constellation_msg::Key, mods: constellation_msg::KeyModifiers)
constellation_msg::KeyZ if shift => "Z",
constellation_msg::KeyZ => "z",
constellation_msg::KeyLeftBracket if shift => "{",
constellation_msg::KeyLeftBracket => "{",
constellation_msg::KeyLeftBracket => "[",
constellation_msg::KeyBackslash if shift => "|",
constellation_msg::KeyBackslash => "\\",
constellation_msg::KeyRightBracket if shift => "}",
Expand Down Expand Up @@ -444,7 +444,7 @@ fn key_location(key: constellation_msg::Key) -> u32 {
}

// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#widl-KeyboardEvent-charCode
fn key_char_code(key: constellation_msg::Key, mods: constellation_msg::KeyModifiers) -> Option<u32> {
fn key_charcode(key: constellation_msg::Key, mods: constellation_msg::KeyModifiers) -> Option<u32> {
let key = key_value(key, mods);
if key.len() == 1 {
Some(key.char_at(0) as u32)
Expand All @@ -454,7 +454,7 @@ fn key_char_code(key: constellation_msg::Key, mods: constellation_msg::KeyModifi
}

// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#legacy-key-models
fn key_key_code(key: constellation_msg::Key) -> u32 {
fn key_keycode(key: constellation_msg::Key) -> u32 {
match key {
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#legacy-key-models
constellation_msg::KeyBackspace => 8,
Expand Down Expand Up @@ -601,13 +601,15 @@ impl<'a> KeyboardEventMethods for JSRef<'a, KeyboardEvent> {
self.is_composing.get()
}

// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#widl-KeyboardEvent-getModifierState
fn GetModifierState(self, keyArg: DOMString) -> bool {
match keyArg.as_slice() {
"Ctrl" => self.CtrlKey(),
"Alt" => self.AltKey(),
"Shift" => self.ShiftKey(),
"Meta" => self.MetaKey(),
"AltGraph" | "CapsLock" | "NumLock" | "ScrollLock" => false, //FIXME
"AltGraph" | "CapsLock" | "NumLock" | "ScrollLock" | "Accel" |
"Fn" | "FnLock" | "Hyper" | "OS" | "Symbol" | "SymbolLock" => false, //FIXME
_ => false,
}
}
Expand Down
21 changes: 14 additions & 7 deletions components/script/script_task.rs
Expand Up @@ -9,6 +9,7 @@ use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyStateValues};
use dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods;
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, EventCast, ElementCast};
Expand Down Expand Up @@ -1093,19 +1094,25 @@ impl ScriptTask {

let props = KeyboardEvent::key_properties(key, modifiers);

let event = KeyboardEvent::new(*window, ev_type, true, true, Some(*window), 0,
props.key.to_string(), props.code.to_string(), props.location,
is_repeating, is_composing, ctrl, alt, shift, meta,
None, props.key_code).root();
let _ = target.DispatchEvent(EventCast::from_ref(*event));

if state != Released && props.is_printable() {
let keyevent = KeyboardEvent::new(*window, ev_type, true, true, Some(*window), 0,
props.key.to_string(), props.code.to_string(),
props.location, is_repeating, is_composing,
ctrl, alt, shift, meta,
None, props.key_code).root();
let event = EventCast::from_ref(*keyevent);
let _ = target.DispatchEvent(event);

// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keys-cancelable-keys
if state != Released && props.is_printable() && !event.DefaultPrevented() {
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keypress-event-order
let event = KeyboardEvent::new(*window, "keypress".to_string(), true, true, Some(*window),
0, props.key.to_string(), props.code.to_string(),
props.location, is_repeating, is_composing,
ctrl, alt, shift, meta,
props.char_code, 0).root();
let _ = target.DispatchEvent(EventCast::from_ref(*event));

// TODO: if keypress event is canceled, prevent firing input events
}

window.flush_layout();
Expand Down
10 changes: 7 additions & 3 deletions components/script/textinput.rs
Expand Up @@ -104,9 +104,11 @@ impl TextInput {
let prefix_end = if forward {
self.edit_point.index
} else {
//TODO: handle backspacing from position 0 of current line
if self.multiline {
assert!(self.edit_point.index > 0);
//TODO: handle backspacing from position 0 of current line
if self.edit_point.index == 0 {
return;
}
} else if self.edit_point.index == 0 {
return;
}
Expand All @@ -116,7 +118,9 @@ impl TextInput {
let is_eol = self.edit_point.index == self.current_line_length() - 1;
if self.multiline {
//TODO: handle deleting from end position of current line
assert!(!is_eol);
if is_eol {
return;
}
} else if is_eol {
return;
}
Expand Down

0 comments on commit e3722bd

Please sign in to comment.