Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / content / public / android / java / src / org / chromium / content / browser / ContentViewCore.java
index 7f20935..39ab380 100644 (file)
@@ -357,11 +357,6 @@ public class ContentViewCore
     private final RenderCoordinates.NormalizedPoint mEndHandlePoint;
     private final RenderCoordinates.NormalizedPoint mInsertionHandlePoint;
 
-    // Cached copy of the visible rectangle defined by two points. Needed to determine
-    // visibility of insertion/selection handles.
-    private final RenderCoordinates.NormalizedPoint mTopLeftVisibilityClippingPoint;
-    private final RenderCoordinates.NormalizedPoint mBottomRightVisibilityClippingPoint;
-
     // Tracks whether a selection is currently active.  When applied to selected text, indicates
     // whether the last selected text is still highlighted.
     private boolean mHasSelection;
@@ -464,8 +459,6 @@ public class ContentViewCore
         mStartHandlePoint = mRenderCoordinates.createNormalizedPoint();
         mEndHandlePoint = mRenderCoordinates.createNormalizedPoint();
         mInsertionHandlePoint = mRenderCoordinates.createNormalizedPoint();
-        mTopLeftVisibilityClippingPoint = mRenderCoordinates.createNormalizedPoint();
-        mBottomRightVisibilityClippingPoint = mRenderCoordinates.createNormalizedPoint();
         mAccessibilityManager = (AccessibilityManager)
                 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
         mGestureStateListeners = new ObserverList<GestureStateListener>();
@@ -731,6 +724,7 @@ public class ContentViewCore
             @Override
             public void didStartLoading(String url) {
                 hidePopupDialog();
+                resetScrollInProgress();
                 resetGestureDetectors();
             }
         };
@@ -1269,6 +1263,7 @@ public class ContentViewCore
     @SuppressWarnings("unused")
     @CalledByNative
     private void onScrollEndEventAck() {
+        if (!mTouchScrollInProgress) return;
         mTouchScrollInProgress = false;
         updateGestureStateListener(GestureEventType.SCROLL_END);
     }
@@ -1988,7 +1983,6 @@ public class ContentViewCore
             };
 
             mSelectionHandleController.hideAndDisallowAutomaticShowing();
-            updateInsertionSelectionVisibleBounds();
         }
 
         return mSelectionHandleController;
@@ -2027,7 +2021,6 @@ public class ContentViewCore
             };
 
             mInsertionHandleController.hideAndDisallowAutomaticShowing();
-            updateInsertionSelectionVisibleBounds();
         }
 
         return mInsertionHandleController;
@@ -2298,11 +2291,11 @@ public class ContentViewCore
         TraceEvent.instant("ContentViewCore:updateFrameInfo");
         // Adjust contentWidth/Height to be always at least as big as
         // the actual viewport (as set by onSizeChanged).
+        final float deviceScale = mRenderCoordinates.getDeviceScaleFactor();
         contentWidth = Math.max(contentWidth,
-                mRenderCoordinates.fromPixToLocalCss(mViewportWidthPix));
+                mViewportWidthPix / (deviceScale * pageScaleFactor));
         contentHeight = Math.max(contentHeight,
-                mRenderCoordinates.fromPixToLocalCss(mViewportHeightPix));
-
+                mViewportHeightPix / (deviceScale * pageScaleFactor));
         final float contentOffsetYPix = mRenderCoordinates.fromDipToPix(contentOffsetYCss);
 
         final boolean contentSizeChanged =
@@ -2356,7 +2349,6 @@ public class ContentViewCore
         if (contentOffsetChanged) updateHandleScreenPositions();
 
         // Update offsets for fullscreen.
-        final float deviceScale = mRenderCoordinates.getDeviceScaleFactor();
         final float controlsOffsetPix = controlsOffsetYCss * deviceScale;
         final float overdrawBottomHeightPix = overdrawBottomHeightCss * deviceScale;
         getContentViewClient().onOffsetsForFullscreenChanged(
@@ -2517,32 +2509,6 @@ public class ContentViewCore
         }
     }
 
-    @CalledByNative
-    private void setSelectionRootBounds(Rect bounds) {
-        mTopLeftVisibilityClippingPoint.setLocalDip(bounds.left, bounds.top);
-        mBottomRightVisibilityClippingPoint.setLocalDip(bounds.right, bounds.bottom);
-        updateInsertionSelectionVisibleBounds();
-    }
-
-    private void updateInsertionSelectionVisibleBounds() {
-        if (mSelectionHandleController == null && mInsertionHandleController == null) {
-            return;
-        }
-
-        int x1 = Math.round(mTopLeftVisibilityClippingPoint.getXPix());
-        int y1 = Math.round(mTopLeftVisibilityClippingPoint.getYPix());
-        int x2 = Math.round(mBottomRightVisibilityClippingPoint.getXPix());
-        int y2 = Math.round(mBottomRightVisibilityClippingPoint.getYPix());
-
-        if (mSelectionHandleController != null) {
-            mSelectionHandleController.setVisibleClippingRectangle(x1, y1, x2, y2);
-        }
-
-        if (mInsertionHandleController != null) {
-            mInsertionHandleController.setVisibleClippingRectangle(x1, y1, x2, y2);
-        }
-    }
-
     @SuppressWarnings("unused")
     @CalledByNative
     private static void onEvaluateJavaScriptResult(
@@ -2919,8 +2885,11 @@ public class ContentViewCore
      */
     public boolean isDeviceAccessibilityScriptInjectionEnabled() {
         try {
-            if (!CommandLine.getInstance().hasSwitch(
-                    ContentSwitches.ENABLE_ACCESSIBILITY_SCRIPT_INJECTION)) {
+            // On JellyBean and higher, native accessibility is the default so script
+            // injection is only allowed if enabled via a flag.
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN &&
+                    !CommandLine.getInstance().hasSwitch(
+                            ContentSwitches.ENABLE_ACCESSIBILITY_SCRIPT_INJECTION)) {
                 return false;
             }
 
@@ -2970,6 +2939,13 @@ public class ContentViewCore
     }
 
     /**
+     * Returns true if accessibility is on and touch exploration is enabled.
+     */
+    public boolean isTouchExplorationEnabled() {
+        return mTouchExplorationEnabled;
+    }
+
+    /**
      * Turns browser accessibility on or off.
      * If |state| is |false|, this turns off both native and injected accessibility.
      * Otherwise, if accessibility script injection is enabled, this will enable the injected
@@ -3129,6 +3105,23 @@ public class ContentViewCore
         return mContainerView.performLongClick();
     }
 
+    /**
+     * Reset scroll and fling accounting, notifying listeners as appropriate.
+     * This is useful as a failsafe when the input stream may have been interruped.
+     */
+    private void resetScrollInProgress() {
+        if (!isScrollInProgress()) return;
+
+        final boolean touchScrollInProgress = mTouchScrollInProgress;
+        final int potentiallyActiveFlingCount = mPotentiallyActiveFlingCount;
+
+        mTouchScrollInProgress = false;
+        mPotentiallyActiveFlingCount = 0;
+
+        if (touchScrollInProgress) updateGestureStateListener(GestureEventType.SCROLL_END);
+        if (potentiallyActiveFlingCount > 0) updateGestureStateListener(GestureEventType.FLING_END);
+    }
+
     private native long nativeInit(long webContentsPtr,
             long viewAndroidPtr, long windowAndroidPtr);
 
@@ -3147,7 +3140,8 @@ public class ContentViewCore
         // Note that mTouchScrollInProgress should normally be false at this
         // point, but we reset it anyway as another failsafe.
         mTouchScrollInProgress = false;
-        if (mPotentiallyActiveFlingCount > 0) mPotentiallyActiveFlingCount--;
+        if (mPotentiallyActiveFlingCount <= 0) return;
+        mPotentiallyActiveFlingCount--;
         updateGestureStateListener(GestureEventType.FLING_END);
     }