Bug 1065955 - Filter collapsed selection change events but exclude the shortcut mode that the touch caret is visible, r=ehsan
authorPeter Chang <pchang@mozilla.com>
Wed, 22 Oct 2014 17:05:06 +0800
changeset 212878 03600247f685d0f4f5b6e87467fe9b6b639aa8d7
parent 212877 442f9ab1d578b1a1d8c9a63c99b8e0b7997c7bc5
child 212879 10333db03e198d1e608b4a66f072d0c1a22e74d7
push id27734
push userryanvm@gmail.com
push dateWed, 29 Oct 2014 20:15:52 +0000
treeherdermozilla-central@8345ae427a3f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1065955
milestone36.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 1065955 - Filter collapsed selection change events but exclude the shortcut mode that the touch caret is visible, r=ehsan
dom/base/nsGlobalWindow.cpp
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -197,16 +197,17 @@
 #include "mozilla/Telemetry.h"
 #include "nsLocation.h"
 #include "nsHTMLDocument.h"
 #include "nsWrapperCacheInlines.h"
 #include "mozilla/DOMEventTargetHelper.h"
 #include "prrng.h"
 #include "nsSandboxFlags.h"
 #include "TimeChangeObserver.h"
+#include "TouchCaret.h"
 #include "mozilla/dom/AudioContext.h"
 #include "mozilla/dom/BlobBinding.h"
 #include "mozilla/dom/BrowserElementDictionariesBinding.h"
 #include "mozilla/dom/Console.h"
 #include "mozilla/dom/Fetch.h"
 #include "mozilla/dom/FunctionBinding.h"
 #include "mozilla/dom/HashChangeEvent.h"
 #include "mozilla/dom/MozSelfSupportBinding.h"
@@ -9351,16 +9352,34 @@ nsGlobalWindow::UpdateCommands(const nsA
                                                             anAction));
     }
   }
 
   if (gSelectionCaretPrefEnabled && mDoc && anAction.EqualsLiteral("selectionchange")) {
     SelectionChangeEventInit init;
     init.mBubbles = true;
     if (aSel) {
+      bool isTouchCaretVisible = false;
+      bool isCollapsed = aSel->Collapsed();
+
+      nsIPresShell *shell = mDoc->GetShell();
+      if (shell) {
+        nsRefPtr<TouchCaret> touchCaret = shell->GetTouchCaret();
+        if (touchCaret) {
+          isTouchCaretVisible = touchCaret->GetVisibility();
+        }
+      }
+
+      // Dispatch selection change events when touch caret is visible even if selection
+      // is collapsed because it could be the shortcut mode, otherwise ignore this
+      // UpdateCommands
+      if (isCollapsed && !isTouchCaretVisible) {
+        return NS_OK;
+      }
+
       Selection* selection = static_cast<Selection*>(aSel);
       int32_t rangeCount = selection->GetRangeCount();
       nsLayoutUtils::RectAccumulator accumulator;
       for (int32_t idx = 0; idx < rangeCount; ++idx) {
         nsRange* range = selection->GetRangeAt(idx);
         nsRange::CollectClientRects(&accumulator, range,
                                     range->GetStartParent(), range->StartOffset(),
                                     range->GetEndParent(), range->EndOffset(),