Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2105)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/input/PopupTouchHandleDrawable.java

Issue 481683003: Support for Adaptive Handle Orientation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..28d3bcd92bfa5d4ad61126f322177ed418bee631 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 getHandleHorizontalPadding() {
+ return HandleViewResources.getHandleHorizontalPadding();
+ }
+
+ @CalledByNative
private int getPositionY() {
return mPositionY;
}

Powered by Google App Engine
This is Rietveld 408576698