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 8d68dec508e005f667ccb4a217df24a9d35b9e3a..4970d1787e1a8148842dd151ab0e0d88c85e97cc 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,9 +50,9 @@ public class PopupTouchHandleDrawable extends View { |
private int mParentPositionX; |
private int mParentPositionY; |
- // The offset from this handles position to the "tip" of the handle. |
- private float mHotspotX; |
- private float mHotspotY; |
+ // The mirror values based on which the handles are inverted about X and Y axes. |
+ private boolean mMirrorHorizontal; |
+ private boolean mMirrorVertical; |
private float mAlpha; |
@@ -145,46 +145,42 @@ 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) { |
+ mDrawable.setAlpha((int) (255 * mAlpha)); |
+ } |
+ |
+ private Drawable getHandleDrawable() { |
+ switch (mOrientation) { |
case TouchHandleOrientation.LEFT: { |
- mDrawable = HandleViewResources.getLeftHandleDrawable(mContext); |
- mHotspotX = (mDrawable.getIntrinsicWidth() * 3) / 4f; |
- break; |
+ return HandleViewResources.getLeftHandleDrawable(mContext); |
} |
case TouchHandleOrientation.RIGHT: { |
- mDrawable = HandleViewResources.getRightHandleDrawable(mContext); |
- mHotspotX = mDrawable.getIntrinsicWidth() / 4f; |
- break; |
+ return HandleViewResources.getRightHandleDrawable(mContext); |
} |
case TouchHandleOrientation.CENTER: { |
- mDrawable = HandleViewResources.getCenterHandleDrawable(mContext); |
- mHotspotX = mDrawable.getIntrinsicWidth() / 2f; |
- break; |
+ return HandleViewResources.getCenterHandleDrawable(mContext); |
} |
case TouchHandleOrientation.UNDEFINED: |
default: |
- break; |
+ assert false; |
+ return HandleViewResources.getCenterHandleDrawable(mContext); |
} |
- mHotspotY = 0; |
- |
- // Force handle repositioning to accommodate the new orientation's hotspot. |
- if (hadValidOrientation) setFocus(oldAdjustedPositionX, oldAdjustedPositionY); |
- mDrawable.setAlpha((int) (255 * mAlpha)); |
- scheduleInvalidate(); |
} |
private void updateParentPosition(int parentPositionX, int parentPositionY) { |
@@ -299,9 +295,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(); |
} |
@Override |
@@ -310,18 +314,6 @@ public class PopupTouchHandleDrawable extends View { |
hide(); |
} |
- // Returns the x coordinate of the position that the handle appears to be pointing to relative |
- // to the handles "parent" view. |
- private int getAdjustedPositionX() { |
- return mPositionX + Math.round(mHotspotX); |
- } |
- |
- // Returns the y coordinate of the position that the handle appears to be pointing to relative |
- // to the handles "parent" view. |
- private int getAdjustedPositionY() { |
- return mPositionY + Math.round(mHotspotY); |
- } |
- |
private PopupTouchHandleDrawableDelegate getDelegateAndHideIfNull() { |
final PopupTouchHandleDrawableDelegate delegate = mDelegate.get(); |
// If the delegate is gone, we should immediately dispose of the popup. |
@@ -369,12 +361,10 @@ public class PopupTouchHandleDrawable extends View { |
} |
@CalledByNative |
- private void setFocus(float focusX, float focusY) { |
- int x = (int) focusX - Math.round(mHotspotX); |
- int y = (int) focusY - Math.round(mHotspotY); |
- if (mPositionX == x && mPositionY == y) return; |
- mPositionX = x; |
- mPositionY = y; |
+ private void setOrigin(float originX, float originY) { |
+ if (mPositionX == originX && mPositionY == originY) return; |
+ mPositionX = (int) originX; |
+ mPositionY = (int) originY; |
if (isScrollInProgress()) { |
temporarilyHide(); |
} else { |
@@ -396,6 +386,11 @@ public class PopupTouchHandleDrawable extends View { |
} |
@CalledByNative |
+ private float getHandleHorizontalPaddingRatio() { |
+ return HandleViewResources.getHandleHorizontalPaddingRatio(); |
+ } |
+ |
+ @CalledByNative |
private int getPositionY() { |
return mPositionY; |
} |