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..23f8a69fbc2a38d7d49bdfe505ed74419baaee9c 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,40 @@ public class PopupTouchHandleDrawable extends View { |
| } |
| @CalledByNative |
| - private void setOrientation(int orientation) { |
| + private void setOrientation(int orientation, boolean mirrorVertical, boolean mirrorHorizontal, |
| + boolean mirrorChanged) { |
|
jdduke (slow)
2015/06/08 15:24:46
Looks like we no longer need the "mirrorChanged" a
AviD
2015/06/16 14:09:14
This was being used in composited_touch_handle_dra
|
| 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(); |
| + } |
|
mfomitchev
2015/06/08 18:06:09
nit: no need for brackets
AviD
2015/06/16 14:09:14
Done.
|
| + |
| 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; |
| } |
| @@ -176,7 +188,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 +197,26 @@ 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: |
| + return HandleViewResources.getCenterHandleDrawable(mContext); |
|
jdduke (slow)
2015/06/08 15:24:46
Can you add "assert false;" here before returning?
AviD
2015/06/16 14:09:14
Done.
|
| + } |
| + } |
| + |
| private void updateParentPosition(int parentPositionX, int parentPositionY) { |
| if (mParentPositionX == parentPositionX && mParentPositionY == parentPositionY) return; |
| mParentPositionX = parentPositionX; |
| @@ -284,9 +317,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 |