| Index: content/public/android/java/src/org/chromium/content/browser/input/PopupTouchHandleDrawable.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/input/PopupTouchHandleDrawable.java b/content/public/android/java/src/org/chromium/content/browser/input/PopupTouchHandleDrawable.java
|
| index 56a74a86d02612a88f3eab310031a593996f1b4d..96307c239172755cdf48ddcc3289728fb26237fc 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/input/PopupTouchHandleDrawable.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/input/PopupTouchHandleDrawable.java
|
| @@ -8,6 +8,7 @@ import android.annotation.SuppressLint;
|
| import android.content.Context;
|
| import android.graphics.Canvas;
|
| import android.graphics.drawable.Drawable;
|
| +import android.graphics.drawable.LayerDrawable;
|
| import android.view.MotionEvent;
|
| import android.view.View;
|
| import android.view.animation.AnimationUtils;
|
| @@ -143,10 +144,9 @@ public class PopupTouchHandleDrawable extends View {
|
| }
|
|
|
| @CalledByNative
|
| - private void setOrientation(int orientation) {
|
| + private void setOrientation(int orientation, boolean mirrorVertical, boolean mirrorHorizontal) {
|
| assert (orientation >= TouchHandleOrientation.LEFT
|
| && orientation <= TouchHandleOrientation.UNDEFINED);
|
| - if (mOrientation == orientation) return;
|
|
|
| final boolean hadValidOrientation = mOrientation != TouchHandleOrientation.UNDEFINED;
|
| mOrientation = orientation;
|
| @@ -154,21 +154,22 @@ public class PopupTouchHandleDrawable extends View {
|
| final int oldAdjustedPositionX = getAdjustedPositionX();
|
| final int oldAdjustedPositionY = getAdjustedPositionY();
|
|
|
| + mDrawable = getHandleDrawable(mirrorVertical, mirrorHorizontal);
|
| +
|
| switch (orientation) {
|
| case TouchHandleOrientation.LEFT: {
|
| - mDrawable = HandleViewResources.getLeftHandleDrawable(mContext);
|
| - mHotspotX = (mDrawable.getIntrinsicWidth() * 3) / 4f;
|
| + int drawableWidth = mDrawable.getIntrinsicWidth();
|
| + mHotspotX = mirrorHorizontal ? drawableWidth / 4f : (drawableWidth * 3) / 4f;
|
| break;
|
| }
|
|
|
| case TouchHandleOrientation.RIGHT: {
|
| - mDrawable = HandleViewResources.getRightHandleDrawable(mContext);
|
| - mHotspotX = mDrawable.getIntrinsicWidth() / 4f;
|
| + int drawableWidth = mDrawable.getIntrinsicWidth();
|
| + mHotspotX = mirrorHorizontal ? (drawableWidth * 3) / 4f : drawableWidth / 4f;
|
| break;
|
| }
|
|
|
| case TouchHandleOrientation.CENTER: {
|
| - mDrawable = HandleViewResources.getCenterHandleDrawable(mContext);
|
| mHotspotX = mDrawable.getIntrinsicWidth() / 2f;
|
| break;
|
| }
|
| @@ -177,7 +178,8 @@ public class PopupTouchHandleDrawable extends View {
|
| default:
|
| break;
|
| }
|
| - mHotspotY = 0;
|
| +
|
| + mHotspotY = mirrorVertical ? mDrawable.getIntrinsicHeight() : 0;
|
|
|
| // Force handle repositioning to accommodate the new orientation's hotspot.
|
| if (hadValidOrientation) setFocus(oldAdjustedPositionX, oldAdjustedPositionY);
|
| @@ -185,6 +187,49 @@ public class PopupTouchHandleDrawable extends View {
|
| scheduleInvalidate();
|
| }
|
|
|
| + private Drawable getHandleDrawable(
|
| + final boolean mirrorVertical, final boolean mirrorHorizontal) {
|
| + final Drawable drawable;
|
| +
|
| + switch (mOrientation) {
|
| + case TouchHandleOrientation.LEFT: {
|
| + drawable = HandleViewResources.getLeftHandleDrawable(mContext);
|
| + break;
|
| + }
|
| +
|
| + case TouchHandleOrientation.RIGHT: {
|
| + drawable = HandleViewResources.getRightHandleDrawable(mContext);
|
| + break;
|
| + }
|
| +
|
| + case TouchHandleOrientation.CENTER: {
|
| + drawable = HandleViewResources.getCenterHandleDrawable(mContext);
|
| + break;
|
| + }
|
| +
|
| + case TouchHandleOrientation.UNDEFINED:
|
| + default:
|
| + drawable = HandleViewResources.getCenterHandleDrawable(mContext);
|
| + break;
|
| + }
|
| +
|
| + // Invert about X or/and Y axis based on the mirror values
|
| + final Drawable[] drawableArray = {drawable};
|
| + final float scale_x = mirrorHorizontal ? -1.f : 1.f;
|
| + final float scale_y = mirrorVertical ? -1.f : 1.f;
|
| +
|
| + return new LayerDrawable(drawableArray) {
|
| + @Override
|
| + public void draw(final Canvas canvas) {
|
| + canvas.save();
|
| + canvas.scale(scale_x, scale_y, drawable.getBounds().width() / 2,
|
| + drawable.getBounds().height() / 2);
|
| + super.draw(canvas);
|
| + canvas.restore();
|
| + }
|
| + };
|
| + }
|
| +
|
| private void updateParentPosition(int parentPositionX, int parentPositionY) {
|
| if (mParentPositionX == parentPositionX && mParentPositionY == parentPositionY) return;
|
| mParentPositionX = parentPositionX;
|
|
|