servo: Merge #12365 - Issue #12071: Don't submit forms when typing Tab on an input (from simartin:issue_12071); r=KiChjang
authorSimon Martin <simartin@users.sourceforge.net>
Tue, 12 Jul 2016 16:27:36 -0700
changeset 339276 40a5a9a1f0832cebfe70a947f767216bf4f96b75
parent 339275 b3c359d819abbd4ad662fbdc67406224851509aa
child 339277 6ad159ec3b5998745e905573a79b25c2cfd30bc9
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersKiChjang
servo: Merge #12365 - Issue #12071: Don't submit forms when typing Tab on an input (from simartin:issue_12071); r=KiChjang <!-- Please describe your changes on the following line: --> Fixes https://github.com/servo/servo/issues/12071 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #12071 <!-- Either: --> - [X] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 3c3c32f95e7e125117b0dc5d6e7eacea3422749c
servo/components/script/dom/htmlinputelement.rs
--- a/servo/components/script/dom/htmlinputelement.rs
+++ b/servo/components/script/dom/htmlinputelement.rs
@@ -28,16 +28,17 @@ use dom::htmlformelement::{ResetFrom, Su
 use dom::keyboardevent::KeyboardEvent;
 use dom::node::{Node, NodeDamage, UnbindContext};
 use dom::node::{document_from_node, window_from_node};
 use dom::nodelist::NodeList;
 use dom::validation::Validatable;
 use dom::virtualmethods::VirtualMethods;
 use ipc_channel::ipc::{self, IpcSender};
 use mime_guess;
+use msg::constellation_msg::Key;
 use net_traits::IpcSend;
 use net_traits::filemanager_thread::{FileManagerThreadMsg, FilterPattern};
 use script_traits::ScriptMsg as ConstellationMsg;
 use std::borrow::ToOwned;
 use std::cell::Cell;
 use std::ops::Range;
 use string_cache::Atom;
 use style::attr::AttrValue;
@@ -1041,20 +1042,28 @@ impl VirtualMethods for HTMLInputElement
             (self.input_type.get() == InputType::InputText ||
              self.input_type.get() == InputType::InputPassword) {
                 if let Some(keyevent) = event.downcast::<KeyboardEvent>() {
                     // This can't be inlined, as holding on to textinput.borrow_mut()
                     // during self.implicit_submission will cause a panic.
                     let action = self.textinput.borrow_mut().handle_keydown(keyevent);
                     match action {
                         TriggerDefaultAction => {
-                            self.implicit_submission(keyevent.CtrlKey(),
-                                                     keyevent.ShiftKey(),
-                                                     keyevent.AltKey(),
-                                                     keyevent.MetaKey());
+                            if let Some(key) = keyevent.get_key() {
+                                match key {
+                                    Key::Enter | Key::KpEnter =>
+                                        self.implicit_submission(keyevent.CtrlKey(),
+                                                                 keyevent.ShiftKey(),
+                                                                 keyevent.AltKey(),
+                                                                 keyevent.MetaKey()),
+                                    // Issue #12071: Tab should not submit forms
+                                    // TODO(3982): Implement form keyboard navigation
+                                    _ => (),
+                                }
+                            };
                         },
                         DispatchInput => {
                             self.value_changed.set(true);
                             self.update_placeholder_shown_state();
 
                             if event.IsTrusted() {
                                 let window = window_from_node(self);
                                 let _ = window.user_interaction_task_source().queue_event(