Bug 779930: Reflect the images for RTL. [r=wesj, r=mfinkle]
This commit is contained in:
@@ -31,12 +31,16 @@ class TextSelectionHandle extends ImageView implements View.OnTouchListener {
|
||||
|
||||
private int mLeft;
|
||||
private int mTop;
|
||||
private boolean mIsRTL;
|
||||
private PointF mGeckoPoint;
|
||||
private int mTouchStartX;
|
||||
private int mTouchStartY;
|
||||
|
||||
private RelativeLayout.LayoutParams mLayoutParams;
|
||||
|
||||
private static final int IMAGE_LEVEL_LTR = 0;
|
||||
private static final int IMAGE_LEVEL_RTL = 1;
|
||||
|
||||
TextSelectionHandle(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setOnTouchListener(this);
|
||||
@@ -51,6 +55,7 @@ class TextSelectionHandle extends ImageView implements View.OnTouchListener {
|
||||
else
|
||||
mHandleType = HandleType.END;
|
||||
|
||||
mIsRTL = false;
|
||||
mGeckoPoint = new PointF(0.0f, 0.0f);
|
||||
|
||||
mWidth = getResources().getDimensionPixelSize(R.dimen.text_selection_handle_width);
|
||||
@@ -97,13 +102,7 @@ class TextSelectionHandle extends ImageView implements View.OnTouchListener {
|
||||
return;
|
||||
}
|
||||
// Send x coordinate on the right side of the start handle, left side of the end handle.
|
||||
float left = (float) mLeft;
|
||||
if (mHandleType.equals(HandleType.START))
|
||||
left += mWidth - mShadow;
|
||||
else if (mHandleType.equals(HandleType.MIDDLE))
|
||||
left += (float) ((mWidth - mShadow) / 2);
|
||||
else
|
||||
left += mShadow;
|
||||
float left = (float) mLeft + adjustLeftForHandle();
|
||||
|
||||
PointF geckoPoint = new PointF(left, (float) mTop);
|
||||
geckoPoint = layerView.convertViewPointToLayerPoint(geckoPoint);
|
||||
@@ -121,7 +120,7 @@ class TextSelectionHandle extends ImageView implements View.OnTouchListener {
|
||||
setLayoutPosition();
|
||||
}
|
||||
|
||||
void positionFromGecko(int left, int top) {
|
||||
void positionFromGecko(int left, int top, boolean rtl) {
|
||||
LayerView layerView = GeckoApp.mAppContext.getLayerView();
|
||||
if (layerView == null) {
|
||||
Log.e(LOGTAG, "Can't position handle because layerView is null");
|
||||
@@ -129,6 +128,11 @@ class TextSelectionHandle extends ImageView implements View.OnTouchListener {
|
||||
}
|
||||
|
||||
mGeckoPoint = new PointF((float) left, (float) top);
|
||||
if (mIsRTL != rtl) {
|
||||
mIsRTL = rtl;
|
||||
setImageLevel(mIsRTL ? IMAGE_LEVEL_RTL : IMAGE_LEVEL_LTR);
|
||||
}
|
||||
|
||||
ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
|
||||
repositionWithViewport(metrics.viewportRectLeft, metrics.viewportRectTop, metrics.zoomFactor);
|
||||
}
|
||||
@@ -137,19 +141,21 @@ class TextSelectionHandle extends ImageView implements View.OnTouchListener {
|
||||
PointF viewPoint = new PointF((mGeckoPoint.x * zoom) - x,
|
||||
(mGeckoPoint.y * zoom) - y);
|
||||
|
||||
mLeft = Math.round(viewPoint.x);
|
||||
if (mHandleType.equals(HandleType.START))
|
||||
mLeft -= mWidth - mShadow;
|
||||
else if (mHandleType.equals(HandleType.MIDDLE))
|
||||
mLeft -= (float) ((mWidth - mShadow) / 2);
|
||||
else
|
||||
mLeft -= mShadow;
|
||||
|
||||
mLeft = Math.round(viewPoint.x) - (int) adjustLeftForHandle();
|
||||
mTop = Math.round(viewPoint.y);
|
||||
|
||||
setLayoutPosition();
|
||||
}
|
||||
|
||||
private float adjustLeftForHandle() {
|
||||
if (mHandleType.equals(HandleType.START))
|
||||
return mIsRTL ? mShadow : mWidth - mShadow;
|
||||
else if (mHandleType.equals(HandleType.MIDDLE))
|
||||
return (float) ((mWidth - mShadow) / 2);
|
||||
else
|
||||
return mIsRTL ? mWidth - mShadow : mShadow;
|
||||
}
|
||||
|
||||
private void setLayoutPosition() {
|
||||
if (mLayoutParams == null) {
|
||||
mLayoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
|
||||
|
||||
Reference in New Issue
Block a user