Bug 1310403, Remove special mouse handling for buttons which fixes extra focus events, r=smaug
authorNeil Deakin <neil@mozilla.com>
Fri, 11 Nov 2016 10:30:36 -0500
changeset 322090 733596007d62aafce8e07da062881c24c7450e5c
parent 322089 3f11622c5a784b8789c220e4c10345d36dfc74f4
child 322091 e976fd4936e3e686719230b04a7e57ba19888f17
push id83787
push userneil@mozilla.com
push dateFri, 11 Nov 2016 15:33:01 +0000
treeherdermozilla-inbound@e976fd4936e3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1310403
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1310403, Remove special mouse handling for buttons which fixes extra focus events, r=smaug
dom/html/HTMLButtonElement.cpp
dom/html/test/mochitest.ini
dom/html/test/test_focusshift_button.html
dom/tests/browser/browser_focus_steal_from_chrome.js
--- a/dom/html/HTMLButtonElement.cpp
+++ b/dom/html/HTMLButtonElement.cpp
@@ -293,79 +293,16 @@ HTMLButtonElement::PostHandleEvent(Event
                eKeyUp == aVisitor.mEvent->mMessage)) {
             DispatchSimulatedClick(this, aVisitor.mEvent->IsTrusted(),
                                    aVisitor.mPresContext);
             aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
           }
         }
         break;
 
-      case eMouseDown:
-        {
-          WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent();
-          if (mouseEvent->button == WidgetMouseEvent::eLeftButton) {
-            if (mouseEvent->IsTrusted()) {
-              EventStateManager* esm =
-                aVisitor.mPresContext->EventStateManager();
-              EventStateManager::SetActiveManager(
-                static_cast<EventStateManager*>(esm), this);
-            }
-            nsIFocusManager* fm = nsFocusManager::GetFocusManager();
-            if (fm) {
-              uint32_t flags = nsIFocusManager::FLAG_BYMOUSE |
-                               nsIFocusManager::FLAG_NOSCROLL;
-              // If this was a touch-generated event, pass that information:
-              if (mouseEvent->inputSource == nsIDOMMouseEvent::MOZ_SOURCE_TOUCH) {
-                flags |= nsIFocusManager::FLAG_BYTOUCH;
-              }
-              fm->SetFocus(this, flags);
-            }
-            mouseEvent->mFlags.mMultipleActionsPrevented = true;
-          } else if (mouseEvent->button == WidgetMouseEvent::eMiddleButton ||
-                     mouseEvent->button == WidgetMouseEvent::eRightButton) {
-            // cancel all of these events for buttons
-            //XXXsmaug What to do with these events? Why these should be cancelled?
-            if (aVisitor.mDOMEvent) {
-              aVisitor.mDOMEvent->StopPropagation();
-            }
-          }
-        }
-        break;
-
-      // cancel all of these events for buttons
-      //XXXsmaug What to do with these events? Why these should be cancelled?
-      case eMouseUp:
-      case eMouseDoubleClick:
-        {
-          WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent();
-          if (aVisitor.mDOMEvent &&
-              (mouseEvent->button == WidgetMouseEvent::eMiddleButton ||
-               mouseEvent->button == WidgetMouseEvent::eRightButton)) {
-            aVisitor.mDOMEvent->StopPropagation();
-          }
-        }
-        break;
-
-      case eMouseOver:
-        {
-          aVisitor.mPresContext->EventStateManager()->
-            SetContentState(this, NS_EVENT_STATE_HOVER);
-          aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
-        }
-        break;
-
-        // XXX this doesn't seem to do anything yet
-      case eMouseOut:
-        {
-          aVisitor.mPresContext->EventStateManager()->
-            SetContentState(nullptr, NS_EVENT_STATE_HOVER);
-          aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
-        }
-        break;
-
       default:
         break;
     }
     if (aVisitor.mItemFlags & NS_OUTER_ACTIVATE_EVENT) {
       if (mForm && (mType == NS_FORM_BUTTON_SUBMIT ||
                     mType == NS_FORM_BUTTON_RESET)) {
         InternalFormEvent event(true,
           (mType == NS_FORM_BUTTON_RESET) ? eFormReset : eFormSubmit);
--- a/dom/html/test/mochitest.ini
+++ b/dom/html/test/mochitest.ini
@@ -444,16 +444,17 @@ support-files =
 [test_bug1264157.html]
 [test_bug1287321.html]
 [test_change_crossorigin.html]
 [test_checked.html]
 [test_dir_attributes_reflection.html]
 [test_dl_attributes_reflection.html]
 [test_element_prototype.html]
 [test_embed_attributes_reflection.html]
+[test_focusshift_button.html]
 [test_formData.html]
 [test_formSubmission.html]
 skip-if = toolkit == 'android' #TIMED_OUT
 [test_formSubmission2.html]
 skip-if = toolkit == 'android'
 [test_formelements.html]
 [test_fullscreen-api.html]
 tags = fullscreen
new file mode 100644
--- /dev/null
+++ b/dom/html/test/test_focusshift_button.html
@@ -0,0 +1,40 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for shifting focus while mouse clicking on button</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+
+<script class="testbody" type="application/javascript;version=1.7">
+
+var result = "";
+
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(function() {
+  synthesizeMouseAtCenter(document.getElementById("button"), { });
+  if (/Mac/.test(navigator.platform)) {
+    // Buttons don't focus when clicked on Mac.
+    is(result, "", "Focus button then input");
+  }
+  else {
+    is(result, "(focus button)(blur button)(focus input)", "Focus button then input");
+  }
+  SimpleTest.finish();
+});
+</script>
+
+
+<button id="button" onfocus="result += '(focus button)'; document.getElementById('input').focus()"
+                    onblur="result += '(blur button)'">Focus</button>
+<input id="input" value="Test" onfocus="result += '(focus input)'"
+                               onblur="result += '(blur input)'">
+
+</body>
+</html>
--- a/dom/tests/browser/browser_focus_steal_from_chrome.js
+++ b/dom/tests/browser/browser_focus_steal_from_chrome.js
@@ -25,29 +25,16 @@ add_task(function* () {
       "  var event = document.createEvent('MouseEvent');" +
       "  event.initMouseEvent('click', true, true, window," +
       "    1, 0, 0, 0, 0, false, false, false, false, 0, element);" +
       "  element.dispatchEvent(event); }, 10);\">" +
       "<label id='target'><input></label></body>",
       tagName: "INPUT", methodName: "click event on the label element" },
   ];
 
-  if (navigator.platform.indexOf("Mac") == -1) {
-    // clicking buttons doesn't focus on mac, so skip this test
-    testingList.push(
-      { uri: "data:text/html,<body onload=\"setTimeout(function () {" +
-        "  var element = document.getElementById('target');" +
-        "  var event = document.createEvent('MouseEvent');" +
-        "  event.initMouseEvent('mousedown', true, true, window," +
-        "    0, 0, 0, 0, 0, false, false, false, false, 0, element);" +
-        "  element.dispatchEvent(event); }, 10);\">" +
-        "<button id='target'>button</button></body>",
-        tagName: "BUTTON", methodName: "mousedown event on the button element" });
-  }
-
   yield BrowserTestUtils.withNewTab("about:blank", function*(bg) {
     yield BrowserTestUtils.withNewTab("about:blank", function*(fg) {
       for (let test of testingList) {
         // Focus the foreground tab's content
         fg.focus();
 
         // Load the URIs.
         yield BrowserTestUtils.loadURI(bg, test.uri);