Chromium Code Reviews| 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 720534c628e6c35b71cb89f5870c755ce41a07f1..fbe3b0f85190ca96a54c3946bff5734b1c66b86e 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 |
| @@ -50,6 +50,10 @@ public class PopupTouchHandleDrawable extends View { |
| private int mParentPositionX; |
| private int mParentPositionY; |
| + // The mirror values based on which the handles are inverted |
| + private boolean mMirrorHorizontal; |
| + private boolean mMirrorVertical; |
| + |
| // The offset from this handles position to the "tip" of the handle. |
| private float mHotspotX; |
| private float mHotspotY; |
| @@ -142,32 +146,37 @@ 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; |
| + final boolean orientationChanged = mOrientation != orientation; |
| mOrientation = orientation; |
| + mMirrorHorizontal = mirrorHorizontal; |
| + mMirrorVertical = mirrorVertical; |
| final int oldAdjustedPositionX = getAdjustedPositionX(); |
| final int oldAdjustedPositionY = getAdjustedPositionY(); |
| + // Create new InvertedDrawable only if orientation has changed. |
| + // Otherwise, change the mirror values to scale canvas on draw() calls. |
| + if (orientationChanged) mDrawable = getHandleDrawable(); |
| + |
| 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; |
|
jdduke (slow)
2015/06/19 14:33:58
Hmm, it's a bit odd to have the handle padding com
AviD
2015/06/19 15:25:29
mfomitchev suggested moving this logic of setting
|
| 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; |
| } |
| @@ -176,7 +185,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); |
| @@ -184,6 +194,27 @@ public class PopupTouchHandleDrawable extends View { |
| scheduleInvalidate(); |
| } |
| + private Drawable getHandleDrawable() { |
| + switch (mOrientation) { |
| + case TouchHandleOrientation.LEFT: { |
| + return HandleViewResources.getLeftHandleDrawable(mContext); |
| + } |
| + |
| + case TouchHandleOrientation.RIGHT: { |
| + return HandleViewResources.getRightHandleDrawable(mContext); |
| + } |
| + |
| + case TouchHandleOrientation.CENTER: { |
| + return HandleViewResources.getCenterHandleDrawable(mContext); |
| + } |
| + |
| + case TouchHandleOrientation.UNDEFINED: |
| + default: |
| + assert false; |
| + return HandleViewResources.getCenterHandleDrawable(mContext); |
| + } |
| + } |
| + |
| private void updateParentPosition(int parentPositionX, int parentPositionY) { |
| if (mParentPositionX == parentPositionX && mParentPositionY == parentPositionY) return; |
| mParentPositionX = parentPositionX; |
| @@ -284,9 +315,17 @@ public class PopupTouchHandleDrawable extends View { |
| @Override |
| protected void onDraw(Canvas c) { |
| if (mDrawable == null) return; |
| + final boolean needsMirror = mMirrorHorizontal || mMirrorVertical; |
| + if (needsMirror) { |
| + c.save(); |
| + float scaleX = mMirrorHorizontal ? -1.f : 1.f; |
| + float scaleY = mMirrorVertical ? -1.f : 1.f; |
| + c.scale(scaleX, scaleY, getWidth() / 2.0f, getHeight() / 2.0f); |
| + } |
| updateAlpha(); |
| mDrawable.setBounds(0, 0, getRight() - getLeft(), getBottom() - getTop()); |
| mDrawable.draw(c); |
| + if (needsMirror) c.restore(); |
| } |
| // Returns the x coordinate of the position that the handle appears to be pointing to relative |
| @@ -373,6 +412,16 @@ public class PopupTouchHandleDrawable extends View { |
| } |
| @CalledByNative |
| + private float getHandleVerticalPadding() { |
| + return HandleViewResources.getHandleVerticalPadding(); |
| + } |
| + |
| + @CalledByNative |
| + private float getHandleHorizontalPadding() { |
| + return HandleViewResources.getHandleHorizontalPadding(); |
| + } |
| + |
| + @CalledByNative |
| private int getPositionY() { |
| return mPositionY; |
| } |