diff --git a/components/script/dom/bindings/codegen/parser/module.patch b/components/script/dom/bindings/codegen/parser/module.patch index 977947b4c636..f2ed1aff9440 100644 --- a/components/script/dom/bindings/codegen/parser/module.patch +++ b/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 diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 680b77cd4239..9c7050ec8a17 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -438,7 +438,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> = KeyboardEventCast::to_ref(event); keyevent.map(|event| { match self.textinput.borrow_mut().handle_keydown(event) { diff --git a/components/script/dom/keyboardevent.rs b/components/script/dom/keyboardevent.rs index a6b488d947e6..3a097fb54e2b 100644 --- a/components/script/dom/keyboardevent.rs +++ b/components/script/dom/keyboardevent.rs @@ -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), } } } @@ -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 => "}", @@ -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 { +fn key_charcode(key: constellation_msg::Key, mods: constellation_msg::KeyModifiers) -> Option { let key = key_value(key, mods); if key.len() == 1 { Some(key.char_at(0) as u32) @@ -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, @@ -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, } } diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 5ed9023b5e5a..087e3fdf0430 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -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}; @@ -950,19 +951,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(); diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 6dc24962aeae..940b9919e769 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -106,9 +106,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; } @@ -118,7 +120,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; } diff --git a/ports/glfw/window.rs b/ports/glfw/window.rs index a13bf571a6d0..0fe1b30f4b24 100644 --- a/ports/glfw/window.rs +++ b/ports/glfw/window.rs @@ -454,127 +454,135 @@ fn glfw_mods_to_script_mods(mods: glfw::Modifiers) -> constellation_msg::KeyModi result } +macro_rules! glfw_keys_to_script_keys( + ($key:expr, $($name:ident),+) => ( + match $key { + $(glfw::$name => constellation_msg::$name,)+ + } + ); +) + fn glfw_key_to_script_key(key: glfw::Key) -> constellation_msg::Key { - match key { - glfw::KeySpace => constellation_msg::KeySpace, - glfw::KeyApostrophe => constellation_msg::KeyApostrophe, - glfw::KeyComma => constellation_msg::KeyComma, - glfw::KeyMinus => constellation_msg::KeyMinus, - glfw::KeyPeriod => constellation_msg::KeyPeriod, - glfw::KeySlash => constellation_msg::KeySlash, - glfw::Key0 => constellation_msg::Key0, - glfw::Key1 => constellation_msg::Key1, - glfw::Key2 => constellation_msg::Key2, - glfw::Key3 => constellation_msg::Key3, - glfw::Key4 => constellation_msg::Key4, - glfw::Key5 => constellation_msg::Key5, - glfw::Key6 => constellation_msg::Key6, - glfw::Key7 => constellation_msg::Key7, - glfw::Key8 => constellation_msg::Key8, - glfw::Key9 => constellation_msg::Key9, - glfw::KeySemicolon => constellation_msg::KeySemicolon, - glfw::KeyEqual => constellation_msg::KeyEqual, - glfw::KeyA => constellation_msg::KeyA, - glfw::KeyB => constellation_msg::KeyB, - glfw::KeyC => constellation_msg::KeyC, - glfw::KeyD => constellation_msg::KeyD, - glfw::KeyE => constellation_msg::KeyE, - glfw::KeyF => constellation_msg::KeyF, - glfw::KeyG => constellation_msg::KeyG, - glfw::KeyH => constellation_msg::KeyH, - glfw::KeyI => constellation_msg::KeyI, - glfw::KeyJ => constellation_msg::KeyJ, - glfw::KeyK => constellation_msg::KeyK, - glfw::KeyL => constellation_msg::KeyL, - glfw::KeyM => constellation_msg::KeyM, - glfw::KeyN => constellation_msg::KeyN, - glfw::KeyO => constellation_msg::KeyO, - glfw::KeyP => constellation_msg::KeyP, - glfw::KeyQ => constellation_msg::KeyQ, - glfw::KeyR => constellation_msg::KeyR, - glfw::KeyS => constellation_msg::KeyS, - glfw::KeyT => constellation_msg::KeyT, - glfw::KeyU => constellation_msg::KeyU, - glfw::KeyV => constellation_msg::KeyV, - glfw::KeyW => constellation_msg::KeyW, - glfw::KeyX => constellation_msg::KeyX, - glfw::KeyY => constellation_msg::KeyY, - glfw::KeyZ => constellation_msg::KeyZ, - glfw::KeyLeftBracket => constellation_msg::KeyLeftBracket, - glfw::KeyBackslash => constellation_msg::KeyBackslash, - glfw::KeyRightBracket => constellation_msg::KeyRightBracket, - glfw::KeyGraveAccent => constellation_msg::KeyGraveAccent, - glfw::KeyWorld1 => constellation_msg::KeyWorld1, - glfw::KeyWorld2 => constellation_msg::KeyWorld2, - glfw::KeyEscape => constellation_msg::KeyEscape, - glfw::KeyEnter => constellation_msg::KeyEnter, - glfw::KeyTab => constellation_msg::KeyTab, - glfw::KeyBackspace => constellation_msg::KeyBackspace, - glfw::KeyInsert => constellation_msg::KeyInsert, - glfw::KeyDelete => constellation_msg::KeyDelete, - glfw::KeyRight => constellation_msg::KeyRight, - glfw::KeyLeft => constellation_msg::KeyLeft, - glfw::KeyDown => constellation_msg::KeyDown, - glfw::KeyUp => constellation_msg::KeyUp, - glfw::KeyPageUp => constellation_msg::KeyPageUp, - glfw::KeyPageDown => constellation_msg::KeyPageDown, - glfw::KeyHome => constellation_msg::KeyHome, - glfw::KeyEnd => constellation_msg::KeyEnd, - glfw::KeyCapsLock => constellation_msg::KeyCapsLock, - glfw::KeyScrollLock => constellation_msg::KeyScrollLock, - glfw::KeyNumLock => constellation_msg::KeyNumLock, - glfw::KeyPrintScreen => constellation_msg::KeyPrintScreen, - glfw::KeyPause => constellation_msg::KeyPause, - glfw::KeyF1 => constellation_msg::KeyF1, - glfw::KeyF2 => constellation_msg::KeyF2, - glfw::KeyF3 => constellation_msg::KeyF3, - glfw::KeyF4 => constellation_msg::KeyF4, - glfw::KeyF5 => constellation_msg::KeyF5, - glfw::KeyF6 => constellation_msg::KeyF6, - glfw::KeyF7 => constellation_msg::KeyF7, - glfw::KeyF8 => constellation_msg::KeyF8, - glfw::KeyF9 => constellation_msg::KeyF9, - glfw::KeyF10 => constellation_msg::KeyF10, - glfw::KeyF11 => constellation_msg::KeyF11, - glfw::KeyF12 => constellation_msg::KeyF12, - glfw::KeyF13 => constellation_msg::KeyF13, - glfw::KeyF14 => constellation_msg::KeyF14, - glfw::KeyF15 => constellation_msg::KeyF15, - glfw::KeyF16 => constellation_msg::KeyF16, - glfw::KeyF17 => constellation_msg::KeyF17, - glfw::KeyF18 => constellation_msg::KeyF18, - glfw::KeyF19 => constellation_msg::KeyF19, - glfw::KeyF20 => constellation_msg::KeyF20, - glfw::KeyF21 => constellation_msg::KeyF21, - glfw::KeyF22 => constellation_msg::KeyF22, - glfw::KeyF23 => constellation_msg::KeyF23, - glfw::KeyF24 => constellation_msg::KeyF24, - glfw::KeyF25 => constellation_msg::KeyF25, - glfw::KeyKp0 => constellation_msg::KeyKp0, - glfw::KeyKp1 => constellation_msg::KeyKp1, - glfw::KeyKp2 => constellation_msg::KeyKp2, - glfw::KeyKp3 => constellation_msg::KeyKp3, - glfw::KeyKp4 => constellation_msg::KeyKp4, - glfw::KeyKp5 => constellation_msg::KeyKp5, - glfw::KeyKp6 => constellation_msg::KeyKp6, - glfw::KeyKp7 => constellation_msg::KeyKp7, - glfw::KeyKp8 => constellation_msg::KeyKp8, - glfw::KeyKp9 => constellation_msg::KeyKp9, - glfw::KeyKpDecimal => constellation_msg::KeyKpDecimal, - glfw::KeyKpDivide => constellation_msg::KeyKpDivide, - glfw::KeyKpMultiply => constellation_msg::KeyKpMultiply, - glfw::KeyKpSubtract => constellation_msg::KeyKpSubtract, - glfw::KeyKpAdd => constellation_msg::KeyKpAdd, - glfw::KeyKpEnter => constellation_msg::KeyKpEnter, - glfw::KeyKpEqual => constellation_msg::KeyKpEqual, - glfw::KeyLeftShift => constellation_msg::KeyLeftShift, - glfw::KeyLeftControl => constellation_msg::KeyLeftControl, - glfw::KeyLeftAlt => constellation_msg::KeyLeftAlt, - glfw::KeyLeftSuper => constellation_msg::KeyLeftSuper, - glfw::KeyRightShift => constellation_msg::KeyRightShift, - glfw::KeyRightControl => constellation_msg::KeyRightControl, - glfw::KeyRightAlt => constellation_msg::KeyRightAlt, - glfw::KeyRightSuper => constellation_msg::KeyRightSuper, - glfw::KeyMenu => constellation_msg::KeyMenu, - } + glfw_keys_to_script_keys!(key, + KeySpace, + KeyApostrophe, + KeyComma, + KeyMinus, + KeyPeriod, + KeySlash, + Key0, + Key1, + Key2, + Key3, + Key4, + Key5, + Key6, + Key7, + Key8, + Key9, + KeySemicolon, + KeyEqual, + KeyA, + KeyB, + KeyC, + KeyD, + KeyE, + KeyF, + KeyG, + KeyH, + KeyI, + KeyJ, + KeyK, + KeyL, + KeyM, + KeyN, + KeyO, + KeyP, + KeyQ, + KeyR, + KeyS, + KeyT, + KeyU, + KeyV, + KeyW, + KeyX, + KeyY, + KeyZ, + KeyLeftBracket, + KeyBackslash, + KeyRightBracket, + KeyGraveAccent, + KeyWorld1, + KeyWorld2, + + KeyEscape, + KeyEnter, + KeyTab, + KeyBackspace, + KeyInsert, + KeyDelete, + KeyRight, + KeyLeft, + KeyDown, + KeyUp, + KeyPageUp, + KeyPageDown, + KeyHome, + KeyEnd, + KeyCapsLock, + KeyScrollLock, + KeyNumLock, + KeyPrintScreen, + KeyPause, + KeyF1, + KeyF2, + KeyF3, + KeyF4, + KeyF5, + KeyF6, + KeyF7, + KeyF8, + KeyF9, + KeyF10, + KeyF11, + KeyF12, + KeyF13, + KeyF14, + KeyF15, + KeyF16, + KeyF17, + KeyF18, + KeyF19, + KeyF20, + KeyF21, + KeyF22, + KeyF23, + KeyF24, + KeyF25, + KeyKp0, + KeyKp1, + KeyKp2, + KeyKp3, + KeyKp4, + KeyKp5, + KeyKp6, + KeyKp7, + KeyKp8, + KeyKp9, + KeyKpDecimal, + KeyKpDivide, + KeyKpMultiply, + KeyKpSubtract, + KeyKpAdd, + KeyKpEnter, + KeyKpEqual, + KeyLeftShift, + KeyLeftControl, + KeyLeftAlt, + KeyLeftSuper, + KeyRightShift, + KeyRightControl, + KeyRightAlt, + KeyRightSuper, + KeyMenu) } diff --git a/tests/content/test_interfaces.html b/tests/content/test_interfaces.html index 696d6dcc7dab..1a1fa9f1cd0a 100644 --- a/tests/content/test_interfaces.html +++ b/tests/content/test_interfaces.html @@ -142,6 +142,7 @@ "HTMLUListElement", "HTMLUnknownElement", "HTMLVideoElement", + "KeyboardEvent", "Location", "MessageEvent", "MouseEvent",