Bug 1452536 - Don't gesture activate for events targetting editable elements. r=masayuki draft
authorChris Pearce <cpearce@mozilla.com>
Mon, 30 Apr 2018 09:44:31 +1200
changeset 789577 b2267f5ae2c9f0f6626f622bc98e3c5f18faf8bb
parent 789574 8be949228b666a2ff54385f14b38b8f89459b1e2
child 789578 4607e548eb810cc6a124b908a299c9552952370d
push id108288
push userbmo:cpearce@mozilla.com
push dateSun, 29 Apr 2018 23:02:14 +0000
reviewersmasayuki
bugs1452536
milestone61.0a1
Bug 1452536 - Don't gesture activate for events targetting editable elements. r=masayuki We don't want to gesture activate for key and mouse/pointer events sent to editable elements, as that would mean user interaction intended as text input could start media playback, which would not likely be the user's intention. MozReview-Commit-ID: VemPfpuziz
dom/events/EventStateManager.cpp
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -8,16 +8,17 @@
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextComposition.h"
+#include "mozilla/TextEditor.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/DragEvent.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/FrameLoaderBinding.h"
 #include "mozilla/dom/MouseEventBinding.h"
 #include "mozilla/dom/TabChild.h"
@@ -901,16 +902,28 @@ EventStateManager::PreHandleEvent(nsPres
     NotifyTargetUserActivation(aEvent, aTargetContent);
     break;
   default:
     break;
   }
   return NS_OK;
 }
 
+static bool
+IsTextInput(nsIContent* aContent)
+{
+  MOZ_ASSERT(aContent);
+  if (!aContent->IsElement()) {
+    return false;
+  }
+  TextEditor* textEditor =
+    aContent->AsElement()->GetTextEditorInternal();
+  return textEditor && !textEditor->IsReadonly();
+}
+
 void
 EventStateManager::NotifyTargetUserActivation(WidgetEvent* aEvent,
                                               nsIContent* aTargetContent)
 {
   if (!aEvent->IsTrusted()) {
     return;
   }
 
@@ -924,16 +937,24 @@ EventStateManager::NotifyTargetUserActiv
     return;
   }
 
   nsIDocument* doc = node->OwnerDoc();
   if (!doc || doc->HasBeenUserActivated()) {
     return;
   }
 
+  // Don't activate if the target content of the event is contentEditable or
+  // is inside an editable document, or is a text input control. Activating
+  // due to typing/clicking on a text input would be surprising user experience.
+  if (aTargetContent->IsEditable() ||
+      IsTextInput(aTargetContent)) {
+    return;
+  }
+
   // Don't gesture activate for key events for keys which are likely
   // to be interaction with the browser, OS, or likely to be scrolling.
   WidgetKeyboardEvent* keyEvent = aEvent->AsKeyboardEvent();
   if (keyEvent && (!keyEvent->PseudoCharCode() ||
                    (keyEvent->IsControl() && !keyEvent->IsAltGraph()) ||
                    (keyEvent->IsAlt() && !keyEvent->IsAltGraph()) ||
                    keyEvent->IsMeta() || keyEvent->IsOS())) {
     return;