Bug 1120358 - Part 1: Handle scroll position change that is not triggered by APZ. r=roc
authorJeremy Chen <jichen@mozilla.com>
Thu, 15 Jan 2015 00:42:00 -0500
changeset 226358 c9b47c5f0dd4019bb79b1c19d80522010de340ce
parent 226357 6e36a128e1c5d23d21adae5ff7be067628ed11fe
child 226359 0f327677b913e4a94abcc9b195dac6ec6461b473
push id54825
push userryanvm@gmail.com
push dateWed, 28 Jan 2015 20:16:29 +0000
treeherdermozilla-inbound@dcbd25d0bf52 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1120358
milestone38.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 1120358 - Part 1: Handle scroll position change that is not triggered by APZ. r=roc
layout/base/SelectionCarets.cpp
layout/base/SelectionCarets.h
--- a/layout/base/SelectionCarets.cpp
+++ b/layout/base/SelectionCarets.cpp
@@ -73,16 +73,17 @@ NS_IMPL_ISUPPORTS(SelectionCarets,
 /*static*/ int32_t SelectionCarets::sSelectionCaretsInflateSize = 0;
 
 SelectionCarets::SelectionCarets(nsIPresShell* aPresShell)
   : mPresShell(aPresShell)
   , mActiveTouchId(-1)
   , mCaretCenterToDownPointOffsetY(0)
   , mDragMode(NONE)
   , mAsyncPanZoomEnabled(false)
+  , mInAsyncPanZoomGesture(false)
   , mEndCaretVisible(false)
   , mStartCaretVisible(false)
   , mSelectionVisibleInScrollFrames(true)
   , mVisible(false)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
 #ifdef PR_LOGGING
@@ -1178,48 +1179,58 @@ DispatchScrollViewChangeEvent(nsIPresShe
     event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;
     doc->DispatchEvent(event, &ret);
   }
 }
 
 void
 SelectionCarets::AsyncPanZoomStarted(const mozilla::CSSIntPoint aScrollPos)
 {
+  mInAsyncPanZoomGesture = true;
   SetVisibility(false);
 
   SELECTIONCARETS_LOG("Dispatch scroll started with position x=%d, y=%d",
                       aScrollPos.x, aScrollPos.y);
   DispatchScrollViewChangeEvent(mPresShell, dom::ScrollState::Started, aScrollPos);
 }
 
 void
 SelectionCarets::AsyncPanZoomStopped(const mozilla::CSSIntPoint aScrollPos)
 {
+  mInAsyncPanZoomGesture = false;
   SELECTIONCARETS_LOG("Update selection carets after APZ is stopped!");
   UpdateSelectionCarets();
 
   // SelectionStateChangedEvent should be dispatched before ScrollViewChangeEvent.
   DispatchSelectionStateChangedEvent(GetSelection(),
                                      SelectionState::Updateposition);
 
   SELECTIONCARETS_LOG("Dispatch scroll stopped with position x=%d, y=%d",
                       aScrollPos.x, aScrollPos.y);
 
   DispatchScrollViewChangeEvent(mPresShell, dom::ScrollState::Stopped, aScrollPos);
 }
 
 void
 SelectionCarets::ScrollPositionChanged()
 {
-  if (!mAsyncPanZoomEnabled && mVisible) {
-    SetVisibility(false);
-    //TODO: handling scrolling for selection bubble when APZ is off
+  if (mVisible) {
+    if (!mAsyncPanZoomEnabled) {
+      SetVisibility(false);
+      //TODO: handling scrolling for selection bubble when APZ is off
 
-    SELECTIONCARETS_LOG("Launch scroll end detector");
-    LaunchScrollEndDetector();
+      SELECTIONCARETS_LOG("Launch scroll end detector");
+      LaunchScrollEndDetector();
+    } else {
+      if (!mInAsyncPanZoomGesture) {
+        UpdateSelectionCarets();
+        DispatchSelectionStateChangedEvent(GetSelection(),
+                                           SelectionState::Updateposition);
+      }
+    }
   }
 }
 
 void
 SelectionCarets::LaunchLongTapDetector()
 {
   if (mAsyncPanZoomEnabled) {
     return;
--- a/layout/base/SelectionCarets.h
+++ b/layout/base/SelectionCarets.h
@@ -255,16 +255,18 @@ private:
   // Otherwise, the selection range changes to one character only
   // which causes the bad user experience.
   nscoord mDragDownYBoundary;
 
   DragMode mDragMode;
 
   // True if AsyncPanZoom is enabled
   bool mAsyncPanZoomEnabled;
+  // True if AsyncPanZoom is started
+  bool mInAsyncPanZoomGesture;
 
   bool mEndCaretVisible;
   bool mStartCaretVisible;
   bool mSelectionVisibleInScrollFrames;
   bool mVisible;
 
   // Preference
   static int32_t sSelectionCaretsInflateSize;