Bug 1090682 - Do not consume NS_MOUSE_MOZLONGTAP if SelectWord failed. f=mtseng, r=roc
authorTing-Yu Lin <tlin@mozilla.com>
Wed, 24 Dec 2014 19:14:00 +0100
changeset 247827 597b1585ab72a17551beedf8003ffe1cbcd5bb6d
parent 247826 f60d4ad64070be0ae3427d52f9f7b5b1f1b0fc77
child 247828 e7edb75d2debac96e39a71f55490a1d95b6d75bb
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1090682
milestone37.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 1090682 - Do not consume NS_MOUSE_MOZLONGTAP if SelectWord failed. f=mtseng, r=roc
layout/base/SelectionCarets.cpp
layout/base/SelectionCarets.h
--- a/layout/base/SelectionCarets.cpp
+++ b/layout/base/SelectionCarets.cpp
@@ -257,17 +257,23 @@ SelectionCarets::HandleEvent(WidgetEvent
     nsPoint delta = mDownPoint - ptInRoot;
     if (NS_hypot(delta.x, delta.y) >
           nsPresContext::AppUnitsPerCSSPixel() * kMoveStartTolerancePx) {
       CancelLongTapDetector();
     }
   } else if (aEvent->message == NS_MOUSE_MOZLONGTAP) {
     if (!mVisible) {
       SELECTIONCARETS_LOG("SelectWord from APZ");
-      SelectWord();
+      nsresult wordSelected = SelectWord();
+
+      if (NS_FAILED(wordSelected)) {
+        SELECTIONCARETS_LOG("SelectWord from APZ failed!")
+        return nsEventStatus_eIgnore;
+      }
+
       return nsEventStatus_eConsumeNoDefault;
     }
   }
   return nsEventStatus_eIgnore;
 }
 
 static void
 SetElementVisibility(dom::Element* aElement, bool aVisible)
@@ -548,35 +554,35 @@ SelectionCarets::UpdateSelectionCarets()
   }
   SetTilted(isTilt);
 }
 
 nsresult
 SelectionCarets::SelectWord()
 {
   if (!mPresShell) {
-    return NS_OK;
+    return NS_ERROR_UNEXPECTED;
   }
 
   nsIFrame* rootFrame = mPresShell->GetRootFrame();
   if (!rootFrame) {
-    return NS_OK;
+    return NS_ERROR_NOT_AVAILABLE;
   }
 
   // Find content offsets for mouse down point
   nsIFrame *ptFrame = nsLayoutUtils::GetFrameForPoint(rootFrame, mDownPoint,
     nsLayoutUtils::IGNORE_PAINT_SUPPRESSION | nsLayoutUtils::IGNORE_CROSS_DOC);
   if (!ptFrame) {
-    return NS_OK;
+    return NS_ERROR_FAILURE;
   }
 
   bool selectable;
   ptFrame->IsSelectable(&selectable, nullptr);
   if (!selectable) {
-    return NS_OK;
+    return NS_ERROR_FAILURE;
   }
 
   nsPoint ptInFrame = mDownPoint;
   nsLayoutUtils::TransformPoint(rootFrame, ptFrame, ptInFrame);
 
   // If target frame is editable, we should move focus to targe frame. If
   // target frame isn't editable and our focus content is editable, we should
   // clear focus.
@@ -1207,17 +1213,21 @@ SelectionCarets::CancelLongTapDetector()
 /* static */void
 SelectionCarets::FireLongTap(nsITimer* aTimer, void* aSelectionCarets)
 {
   nsRefPtr<SelectionCarets> self = static_cast<SelectionCarets*>(aSelectionCarets);
   NS_PRECONDITION(aTimer == self->mLongTapDetectorTimer,
                   "Unexpected timer");
 
   SELECTIONCARETS_LOG_STATIC("SelectWord from non-APZ");
-  self->SelectWord();
+  nsresult wordSelected = self->SelectWord();
+
+  if (NS_FAILED(wordSelected)) {
+    SELECTIONCARETS_LOG_STATIC("SelectWord from non-APZ failed!");
+  }
 }
 
 void
 SelectionCarets::LaunchScrollEndDetector()
 {
   if (!mScrollEndDetectorTimer) {
     mScrollEndDetectorTimer = do_CreateInstance("@mozilla.org/timer;1");
   }
--- a/layout/base/SelectionCarets.h
+++ b/layout/base/SelectionCarets.h
@@ -116,18 +116,18 @@ private:
   void SetVisibility(bool aVisible);
 
   /**
    * Update selection caret position base on current selection range.
    */
   void UpdateSelectionCarets();
 
   /**
-   * Select word base on current position, only active when element
-   * is focused. Triggered by long tap event.
+   * Select a word base on current position, which activates only if element is
+   * selectable. Triggered by long tap event.
    */
   nsresult SelectWord();
 
   /**
    * Move selection base on current touch/mouse point
    */
   nsEventStatus DragSelection(const nsPoint &movePoint);