Cherry pick [Android] Hide handles when the containing view moves

Cherry pick of https://codereview.chromium.org/26575006/

Bug: 10892868

Original description:
[Android] Hide handles when the containing view moves

We temporarily hide handles when there is a scroll or zoom in the
content area. When the containing view is moved, we should also hide
the handles. This is particularly important for webview where scrolling
is often handled outside of the webview itself (and is sometimes mixed
between the two).

BUG=b/10892868

Change-Id: I79e5238f3c61d7fee725f4eab8fe29363409b80d
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
index 794fabe..2cfd201 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
@@ -367,6 +367,7 @@
     private Runnable mDeferredHandleFadeInRunnable;
 
     private PositionObserver mPositionObserver;
+    private PositionObserver.Listener mPositionListener;
 
     // Size of the viewport in physical pixels as set from onSizeChanged.
     private int mViewportWidthPix;
@@ -709,6 +710,14 @@
 
         mContainerView = containerView;
         mPositionObserver = new ViewPositionObserver(mContainerView);
+        mPositionListener = new PositionObserver.Listener() {
+            @Override
+            public void onPositionChanged(int x, int y) {
+                if (isSelectionHandleShowing() || isInsertionHandleShowing()) {
+                    temporarilyHideTextHandles();
+                }
+            }
+        };
 
         int windowNativePointer = windowAndroid != null ? windowAndroid.getNativePointer() : 0;
 
@@ -2100,6 +2109,7 @@
         if (mInsertionHandleController != null) {
             mInsertionHandleController.hideAndDisallowAutomaticShowing();
         }
+        mPositionObserver.removeListener(mPositionListener);
     }
 
     private void showSelectActionBar() {
@@ -2473,6 +2483,9 @@
             }
             mHasSelection = false;
         }
+        if (isSelectionHandleShowing() || isInsertionHandleShowing()) {
+            mPositionObserver.addListener(mPositionListener);
+        }
     }
 
     @SuppressWarnings("unused")