OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content.browser.input; | 5 package org.chromium.content.browser.input; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.TypedArray; | 8 import android.content.res.TypedArray; |
9 import android.graphics.Canvas; | 9 import android.graphics.Canvas; |
10 import android.graphics.Rect; | 10 import android.graphics.Rect; |
11 import android.graphics.drawable.Drawable; | 11 import android.graphics.drawable.Drawable; |
12 import android.os.SystemClock; | 12 import android.os.SystemClock; |
13 import android.util.TypedValue; | 13 import android.util.TypedValue; |
14 import android.view.Gravity; | 14 import android.view.Gravity; |
15 import android.view.LayoutInflater; | 15 import android.view.LayoutInflater; |
16 import android.view.MotionEvent; | 16 import android.view.MotionEvent; |
17 import android.view.View; | 17 import android.view.View; |
18 import android.view.ViewConfiguration; | 18 import android.view.ViewConfiguration; |
19 import android.view.ViewGroup; | 19 import android.view.ViewGroup; |
20 import android.view.ViewParent; | 20 import android.view.ViewParent; |
21 import android.view.WindowManager; | 21 import android.view.WindowManager; |
22 import android.view.View.OnClickListener; | 22 import android.view.View.OnClickListener; |
23 import android.view.ViewGroup.LayoutParams; | 23 import android.view.ViewGroup.LayoutParams; |
24 import android.widget.PopupWindow; | 24 import android.widget.PopupWindow; |
25 import android.widget.TextView; | 25 import android.widget.TextView; |
26 | 26 |
| 27 import org.chromium.content.browser.PositionObserverInterface; |
| 28 |
27 /** | 29 /** |
28 * View that displays a selection or insertion handle for text editing. | 30 * View that displays a selection or insertion handle for text editing. |
| 31 * |
| 32 * While a HandleView is logically a child of some other view, it does not exist
in that View's |
| 33 * hierarchy. |
| 34 * |
29 */ | 35 */ |
30 public class HandleView extends View { | 36 public class HandleView extends View { |
31 private static final float FADE_DURATION = 200.f; | 37 private static final float FADE_DURATION = 200.f; |
32 | 38 |
33 private Drawable mDrawable; | 39 private Drawable mDrawable; |
34 private final PopupWindow mContainer; | 40 |
| 41 // The position of the handle relative to the parent view. |
35 private int mPositionX; | 42 private int mPositionX; |
36 private int mPositionY; | 43 private int mPositionY; |
| 44 |
| 45 // The position of the parent relative to the application's root view. |
| 46 private int mParentPositionX; |
| 47 private int mParentPositionY; |
| 48 |
| 49 // The offset from this handles position to the "tip" of the handle. |
| 50 private float mHotspotX; |
| 51 private float mHotspotY; |
| 52 |
37 private final CursorController mController; | 53 private final CursorController mController; |
38 private boolean mIsDragging; | 54 private boolean mIsDragging; |
39 private float mTouchToWindowOffsetX; | 55 private float mTouchToWindowOffsetX; |
40 private float mTouchToWindowOffsetY; | 56 private float mTouchToWindowOffsetY; |
41 private float mHotspotX; | 57 |
42 private float mHotspotY; | |
43 private int mLineOffsetY; | 58 private int mLineOffsetY; |
44 private int mLastParentX; | |
45 private int mLastParentY; | |
46 private float mDownPositionX, mDownPositionY; | 59 private float mDownPositionX, mDownPositionY; |
47 private int mContainerPositionX, mContainerPositionY; | |
48 private long mTouchTimer; | 60 private long mTouchTimer; |
49 private boolean mIsInsertionHandle = false; | 61 private boolean mIsInsertionHandle = false; |
50 private float mAlpha; | 62 private float mAlpha; |
51 private long mFadeStartTime; | 63 private long mFadeStartTime; |
52 | 64 |
53 private View mParent; | |
54 private InsertionHandleController.PastePopupMenu mPastePopupWindow; | 65 private InsertionHandleController.PastePopupMenu mPastePopupWindow; |
55 | 66 |
56 private final int mTextSelectHandleLeftRes; | 67 private final int mTextSelectHandleLeftRes; |
57 private final int mTextSelectHandleRightRes; | 68 private final int mTextSelectHandleRightRes; |
58 private final int mTextSelectHandleRes; | 69 private final int mTextSelectHandleRes; |
59 | 70 |
60 private Drawable mSelectHandleLeft; | 71 private Drawable mSelectHandleLeft; |
61 private Drawable mSelectHandleRight; | 72 private Drawable mSelectHandleRight; |
62 private Drawable mSelectHandleCenter; | 73 private Drawable mSelectHandleCenter; |
63 | 74 |
64 private final int[] mTempCoords = new int[2]; | |
65 private final Rect mTempRect = new Rect(); | |
66 | |
67 static final int LEFT = 0; | 75 static final int LEFT = 0; |
68 static final int CENTER = 1; | 76 static final int CENTER = 1; |
69 static final int RIGHT = 2; | 77 static final int RIGHT = 2; |
70 | 78 |
| 79 private Delegate mParent; |
| 80 private PositionObserverInterface mParentPositionObserver; |
| 81 private PositionObserverInterface.Listener mParentPositionListener; |
| 82 |
71 // Number of dips to subtract from the handle's y position to give a suitabl
e | 83 // Number of dips to subtract from the handle's y position to give a suitabl
e |
72 // y coordinate for the corresponding text position. This is to compensate f
or the fact | 84 // y coordinate for the corresponding text position. This is to compensate f
or the fact |
73 // that the handle position is at the base of the line of text. | 85 // that the handle position is at the base of the line of text. |
74 private static final float LINE_OFFSET_Y_DIP = 5.0f; | 86 private static final float LINE_OFFSET_Y_DIP = 5.0f; |
75 | 87 |
76 private static final int[] TEXT_VIEW_HANDLE_ATTRS = { | 88 private static final int[] TEXT_VIEW_HANDLE_ATTRS = { |
77 android.R.attr.textSelectHandleLeft, | 89 android.R.attr.textSelectHandleLeft, |
78 android.R.attr.textSelectHandle, | 90 android.R.attr.textSelectHandle, |
79 android.R.attr.textSelectHandleRight, | 91 android.R.attr.textSelectHandleRight, |
80 }; | 92 }; |
81 | 93 |
82 HandleView(CursorController controller, int pos, View parent) { | 94 public interface Delegate { |
| 95 /** |
| 96 * @return The application context. |
| 97 */ |
| 98 public Context getContext(); |
| 99 |
| 100 /** |
| 101 * @return Whether this position (relative to the root view) is visible
in the handle's |
| 102 * parent. |
| 103 */ |
| 104 public boolean isPositionVisible(int x, int y); |
| 105 |
| 106 /** |
| 107 * Dismiss the container containing the handle. |
| 108 */ |
| 109 public void dismissContainer(); |
| 110 |
| 111 /** |
| 112 * @return Whether the container is showing. |
| 113 */ |
| 114 public boolean isContainerShowing(); |
| 115 |
| 116 /** |
| 117 * Show the container for this handle. |
| 118 * |
| 119 * @param view The view to show in the container. |
| 120 * @param x The x position (relative to the root view) to show the conta
iner at. |
| 121 * @param y The y position (relative to the root view) to show the conta
iner at. |
| 122 */ |
| 123 public void showContainerAtPosition(View view, int x, int y); |
| 124 |
| 125 /** |
| 126 * Set the position and size of the container. |
| 127 */ |
| 128 public void updateContainerPosition(int x, int y, int width, int height)
; |
| 129 } |
| 130 |
| 131 /** |
| 132 * A delegate for displaying a HandleView in a PopupWindow. |
| 133 */ |
| 134 public static class ViewDelegate implements Delegate { |
| 135 private final View mView; |
| 136 private final PopupWindow mContainer; |
| 137 private final Rect mTempRect = new Rect(); |
| 138 |
| 139 public ViewDelegate(View view) { |
| 140 mView = view; |
| 141 mContainer = new PopupWindow(getContext(), null, |
| 142 android.R.attr.textSelectHandleWindowStyle); |
| 143 mContainer.setSplitTouchEnabled(true); |
| 144 mContainer.setClippingEnabled(false); |
| 145 } |
| 146 |
| 147 public Context getContext() { |
| 148 return mView.getContext(); |
| 149 } |
| 150 |
| 151 public boolean isPositionVisible(int x, int y) { |
| 152 final Rect clip = mTempRect; |
| 153 clip.left = 0; |
| 154 clip.top = 0; |
| 155 clip.right = mView.getWidth(); |
| 156 clip.bottom = mView.getHeight(); |
| 157 |
| 158 final ViewParent parent = mView.getParent(); |
| 159 if (parent == null || !parent.getChildVisibleRect(mView, clip, null)
) { |
| 160 return false; |
| 161 } |
| 162 |
| 163 return x >= clip.left && x <= clip.right && |
| 164 y >= clip.top && y <= clip.bottom; |
| 165 } |
| 166 |
| 167 public void dismissContainer() { |
| 168 mContainer.dismiss(); |
| 169 } |
| 170 |
| 171 public boolean isContainerShowing() { |
| 172 return mContainer.isShowing(); |
| 173 } |
| 174 |
| 175 public void showContainerAtPosition(View view, int x, int y) { |
| 176 mContainer.setContentView(view); |
| 177 mContainer.showAtLocation(mView, 0, x, y); |
| 178 } |
| 179 |
| 180 public void updateContainerPosition(int x, int y, int width, int height)
{ |
| 181 mContainer.update(x, y, width, height); |
| 182 } |
| 183 } |
| 184 |
| 185 HandleView(CursorController controller, int pos, Delegate parent, |
| 186 PositionObserverInterface parentPositionObserver) { |
83 super(parent.getContext()); | 187 super(parent.getContext()); |
84 Context context = parent.getContext(); | |
85 mParent = parent; | 188 mParent = parent; |
86 mController = controller; | 189 mController = controller; |
87 mContainer = new PopupWindow(context, null, android.R.attr.textSelectHan
dleWindowStyle); | |
88 mContainer.setSplitTouchEnabled(true); | |
89 mContainer.setClippingEnabled(false); | |
90 | 190 |
91 TypedArray a = context.obtainStyledAttributes(TEXT_VIEW_HANDLE_ATTRS); | 191 TypedArray a = mParent.getContext().obtainStyledAttributes(TEXT_VIEW_HAN
DLE_ATTRS); |
92 mTextSelectHandleLeftRes = a.getResourceId(a.getIndex(LEFT), 0); | 192 mTextSelectHandleLeftRes = a.getResourceId(a.getIndex(LEFT), 0); |
93 mTextSelectHandleRes = a.getResourceId(a.getIndex(CENTER), 0); | 193 mTextSelectHandleRes = a.getResourceId(a.getIndex(CENTER), 0); |
94 mTextSelectHandleRightRes = a.getResourceId(a.getIndex(RIGHT), 0); | 194 mTextSelectHandleRightRes = a.getResourceId(a.getIndex(RIGHT), 0); |
95 a.recycle(); | 195 a.recycle(); |
96 | 196 |
97 setOrientation(pos); | 197 setOrientation(pos); |
98 | 198 |
99 // Convert line offset dips to pixels. | 199 // Convert line offset dips to pixels. |
100 mLineOffsetY = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_D
IP, | 200 mLineOffsetY = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_D
IP, |
101 LINE_OFFSET_Y_DIP, context.getResources().getDisplayMetrics()); | 201 LINE_OFFSET_Y_DIP, mParent.getContext().getResources().getDispla
yMetrics()); |
102 | 202 |
103 mAlpha = 1.f; | 203 mAlpha = 1.f; |
| 204 |
| 205 mParentPositionListener = new PositionObserverInterface.Listener() { |
| 206 @Override |
| 207 public void onPositionChanged(int x, int y) { |
| 208 updateParentPosition(x, y); |
| 209 } |
| 210 }; |
| 211 mParentPositionObserver = parentPositionObserver; |
104 } | 212 } |
105 | 213 |
106 void setOrientation(int pos) { | 214 void setOrientation(int pos) { |
107 int handleWidth; | 215 int handleWidth; |
108 switch (pos) { | 216 switch (pos) { |
109 case LEFT: { | 217 case LEFT: { |
110 if (mSelectHandleLeft == null) { | 218 if (mSelectHandleLeft == null) { |
111 mSelectHandleLeft = getContext().getResources().getDrawable( | 219 mSelectHandleLeft = getContext().getResources().getDrawable( |
112 mTextSelectHandleLeftRes); | 220 mTextSelectHandleLeftRes); |
113 } | 221 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 mHotspotY = 0; | 253 mHotspotY = 0; |
146 invalidate(); | 254 invalidate(); |
147 } | 255 } |
148 | 256 |
149 @Override | 257 @Override |
150 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 258 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
151 setMeasuredDimension(mDrawable.getIntrinsicWidth(), | 259 setMeasuredDimension(mDrawable.getIntrinsicWidth(), |
152 mDrawable.getIntrinsicHeight()); | 260 mDrawable.getIntrinsicHeight()); |
153 } | 261 } |
154 | 262 |
155 private void updateContainerPosition() { | 263 private void updateParentPosition(int parentPositionX, int parentPositionY)
{ |
156 final int[] coords = mTempCoords; | 264 // Hide paste popup window as soon as a scroll occurs. |
157 mParent.getLocationInWindow(coords); | 265 if (mPastePopupWindow != null) { |
158 mContainerPositionX = coords[0] + mPositionX; | 266 mPastePopupWindow.hide(); |
159 mContainerPositionY = coords[1] + mPositionY; | 267 } |
| 268 |
| 269 mTouchToWindowOffsetX += parentPositionX - mParentPositionX; |
| 270 mTouchToWindowOffsetY += parentPositionY - mParentPositionY; |
| 271 mParentPositionX = parentPositionX; |
| 272 mParentPositionY = parentPositionY; |
| 273 onPositionChanged(); |
| 274 } |
| 275 |
| 276 private int getContainerPositionX() { |
| 277 return mParentPositionX + mPositionX; |
| 278 } |
| 279 |
| 280 private int getContainerPositionY() { |
| 281 return mParentPositionY + mPositionY; |
| 282 } |
| 283 |
| 284 private void onPositionChanged() { |
| 285 mParent.updateContainerPosition(getContainerPositionX(), getContainerPos
itionY(), |
| 286 getRight() - getLeft(), getBottom() - getTop()); |
| 287 } |
| 288 |
| 289 private void showContainer() { |
| 290 mParent.showContainerAtPosition(this, getContainerPositionX(), getContai
nerPositionY()); |
160 } | 291 } |
161 | 292 |
162 void show() { | 293 void show() { |
| 294 // While hidden, the parent position may have become stale. It must be u
pdated before |
| 295 // checking isPositionVisible(). |
| 296 updateParentPosition(mParentPositionObserver.getPositionX(), |
| 297 mParentPositionObserver.getPositionY()); |
163 if (!isPositionVisible()) { | 298 if (!isPositionVisible()) { |
164 hide(); | 299 hide(); |
165 return; | 300 return; |
166 } | 301 } |
167 mContainer.setContentView(this); | 302 mParentPositionObserver.addListener(mParentPositionListener); |
168 updateContainerPosition(); | 303 showContainer(); |
169 mContainer.showAtLocation(mParent, 0, mContainerPositionX, mContainerPos
itionY); | |
170 | 304 |
171 // Hide paste view when handle is moved on screen. | 305 // Hide paste view when handle is moved on screen. |
172 if (mPastePopupWindow != null) { | 306 if (mPastePopupWindow != null) { |
173 mPastePopupWindow.hide(); | 307 mPastePopupWindow.hide(); |
174 } | 308 } |
175 } | 309 } |
176 | 310 |
177 void hide() { | 311 void hide() { |
178 mIsDragging = false; | 312 mIsDragging = false; |
179 mContainer.dismiss(); | 313 mParent.dismissContainer(); |
| 314 mParentPositionObserver.removeListener(mParentPositionListener); |
180 if (mPastePopupWindow != null) { | 315 if (mPastePopupWindow != null) { |
181 mPastePopupWindow.hide(); | 316 mPastePopupWindow.hide(); |
182 } | 317 } |
183 } | 318 } |
184 | 319 |
185 boolean isShowing() { | 320 boolean isShowing() { |
186 return mContainer.isShowing(); | 321 return mParent.isContainerShowing(); |
187 } | 322 } |
188 | 323 |
189 private boolean isPositionVisible() { | 324 private boolean isPositionVisible() { |
190 // Always show a dragging handle. | 325 // Always show a dragging handle. |
191 if (mIsDragging) { | 326 if (mIsDragging) { |
192 return true; | 327 return true; |
193 } | 328 } |
194 | 329 |
195 final Rect clip = mTempRect; | 330 final int posX = getRootViewRelativePositionX(); |
196 clip.left = 0; | 331 final int posY = getRootViewRelativePositionY(); |
197 clip.top = 0; | |
198 clip.right = mParent.getWidth(); | |
199 clip.bottom = mParent.getHeight(); | |
200 | 332 |
201 final ViewParent parent = mParent.getParent(); | 333 return mParent.isPositionVisible(posX, posY); |
202 if (parent == null || !parent.getChildVisibleRect(mParent, clip, null))
{ | |
203 return false; | |
204 } | |
205 | |
206 final int[] coords = mTempCoords; | |
207 mParent.getLocationInWindow(coords); | |
208 final int posX = coords[0] + mPositionX + (int) mHotspotX; | |
209 final int posY = coords[1] + mPositionY + (int) mHotspotY; | |
210 | |
211 return posX >= clip.left && posX <= clip.right && | |
212 posY >= clip.top && posY <= clip.bottom; | |
213 } | 334 } |
214 | 335 |
215 // x and y are in physical pixels. | 336 // x and y are in physical pixels. |
216 void moveTo(int x, int y) { | 337 void moveTo(int x, int y) { |
| 338 int previousPositionX = mPositionX; |
| 339 int previousPositionY = mPositionY; |
| 340 |
217 mPositionX = x; | 341 mPositionX = x; |
218 mPositionY = y; | 342 mPositionY = y; |
219 if (isPositionVisible()) { | 343 if (isPositionVisible()) { |
220 int[] coords = null; | 344 if (mParent.isContainerShowing()) { |
221 if (mContainer.isShowing()) { | 345 onPositionChanged(); |
222 coords = mTempCoords; | 346 // Hide paste popup window as soon as the handle is dragged. |
223 mParent.getLocationInWindow(coords); | 347 if (mPastePopupWindow != null && |
224 final int containerPositionX = coords[0] + mPositionX; | 348 (previousPositionX != mPositionX || previousPositionY !=
mPositionY)) { |
225 final int containerPositionY = coords[1] + mPositionY; | 349 mPastePopupWindow.hide(); |
226 | |
227 if (containerPositionX != mContainerPositionX || | |
228 containerPositionY != mContainerPositionY) { | |
229 mContainerPositionX = containerPositionX; | |
230 mContainerPositionY = containerPositionY; | |
231 | |
232 mContainer.update(mContainerPositionX, mContainerPositionY, | |
233 getRight() - getLeft(), getBottom() - getTop()); | |
234 | |
235 // Hide paste popup window as soon as a scroll occurs. | |
236 if (mPastePopupWindow != null) { | |
237 mPastePopupWindow.hide(); | |
238 } | |
239 } | 350 } |
240 } else { | 351 } else { |
241 show(); | 352 show(); |
242 } | 353 } |
243 | 354 |
244 if (mIsDragging) { | 355 if (mIsDragging) { |
245 if (coords == null) { | |
246 coords = mTempCoords; | |
247 mParent.getLocationInWindow(coords); | |
248 } | |
249 if (coords[0] != mLastParentX || coords[1] != mLastParentY) { | |
250 mTouchToWindowOffsetX += coords[0] - mLastParentX; | |
251 mTouchToWindowOffsetY += coords[1] - mLastParentY; | |
252 mLastParentX = coords[0]; | |
253 mLastParentY = coords[1]; | |
254 } | |
255 // Hide paste popup window as soon as the handle is dragged. | 356 // Hide paste popup window as soon as the handle is dragged. |
256 if (mPastePopupWindow != null) { | 357 if (mPastePopupWindow != null) { |
257 mPastePopupWindow.hide(); | 358 mPastePopupWindow.hide(); |
258 } | 359 } |
259 } | 360 } |
260 } else { | 361 } else { |
261 hide(); | 362 hide(); |
262 } | 363 } |
263 } | 364 } |
264 | 365 |
265 @Override | 366 @Override |
266 protected void onDraw(Canvas c) { | 367 protected void onDraw(Canvas c) { |
267 updateAlpha(); | 368 updateAlpha(); |
268 updateContainerPosition(); | |
269 mContainer.update(mContainerPositionX, mContainerPositionY, | |
270 getRight() - getLeft(), getBottom() - getTop()); | |
271 mDrawable.setBounds(0, 0, getRight() - getLeft(), getBottom() - getTop()
); | 369 mDrawable.setBounds(0, 0, getRight() - getLeft(), getBottom() - getTop()
); |
272 mDrawable.draw(c); | 370 mDrawable.draw(c); |
273 } | 371 } |
274 | 372 |
275 @Override | 373 @Override |
276 public boolean onTouchEvent(MotionEvent ev) { | 374 public boolean onTouchEvent(MotionEvent ev) { |
277 switch (ev.getActionMasked()) { | 375 switch (ev.getActionMasked()) { |
278 case MotionEvent.ACTION_DOWN: { | 376 case MotionEvent.ACTION_DOWN: { |
279 mDownPositionX = ev.getRawX(); | 377 mDownPositionX = ev.getRawX(); |
280 mDownPositionY = ev.getRawY(); | 378 mDownPositionY = ev.getRawY(); |
281 mTouchToWindowOffsetX = mDownPositionX - mPositionX; | 379 mTouchToWindowOffsetX = mDownPositionX - mPositionX; |
282 mTouchToWindowOffsetY = mDownPositionY - mPositionY; | 380 mTouchToWindowOffsetY = mDownPositionY - mPositionY; |
283 final int[] coords = mTempCoords; | |
284 mParent.getLocationInWindow(coords); | |
285 mLastParentX = coords[0]; | |
286 mLastParentY = coords[1]; | |
287 mIsDragging = true; | 381 mIsDragging = true; |
288 mController.beforeStartUpdatingPosition(this); | 382 mController.beforeStartUpdatingPosition(this); |
289 mTouchTimer = SystemClock.uptimeMillis(); | 383 mTouchTimer = SystemClock.uptimeMillis(); |
290 break; | 384 break; |
291 } | 385 } |
292 | 386 |
293 case MotionEvent.ACTION_MOVE: { | 387 case MotionEvent.ACTION_MOVE: { |
294 updatePosition(ev.getRawX(), ev.getRawY()); | 388 updatePosition(ev.getRawX(), ev.getRawY()); |
295 break; | 389 break; |
296 } | 390 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 434 |
341 private void updatePosition(float rawX, float rawY) { | 435 private void updatePosition(float rawX, float rawY) { |
342 final float newPosX = rawX - mTouchToWindowOffsetX + mHotspotX; | 436 final float newPosX = rawX - mTouchToWindowOffsetX + mHotspotX; |
343 final float newPosY = rawY - mTouchToWindowOffsetY + mHotspotY - mLineOf
fsetY; | 437 final float newPosY = rawY - mTouchToWindowOffsetY + mHotspotY - mLineOf
fsetY; |
344 | 438 |
345 mController.updatePosition(this, Math.round(newPosX), Math.round(newPosY
)); | 439 mController.updatePosition(this, Math.round(newPosX), Math.round(newPosY
)); |
346 } | 440 } |
347 | 441 |
348 // x and y are in physical pixels. | 442 // x and y are in physical pixels. |
349 void positionAt(int x, int y) { | 443 void positionAt(int x, int y) { |
350 moveTo((int)(x - mHotspotX), (int)(y - mHotspotY)); | 444 moveTo(x - Math.round(mHotspotX), y - Math.round(mHotspotY)); |
351 } | 445 } |
352 | 446 |
353 // Returns the x coordinate of the position that the handle appears to be po
inting to. | 447 // Returns the x coordinate of the position that the handle appears to be po
inting to relative |
| 448 // to the handles "parent" view. |
354 int getAdjustedPositionX() { | 449 int getAdjustedPositionX() { |
355 return (int) (mPositionX + mHotspotX); | 450 return mPositionX + Math.round(mHotspotX); |
356 } | 451 } |
357 | 452 |
358 // Returns the y coordinate of the position that the handle appears to be po
inting to. | 453 // Returns the y coordinate of the position that the handle appears to be po
inting to relative |
| 454 // to the handles "parent" view. |
359 int getAdjustedPositionY() { | 455 int getAdjustedPositionY() { |
360 return (int) (mPositionY + mHotspotY); | 456 return mPositionY + Math.round(mHotspotY); |
| 457 } |
| 458 |
| 459 // Returns the x coordinate of the postion that the handle appears to be poi
nting to relative to |
| 460 // the root view of the application. |
| 461 int getRootViewRelativePositionX() { |
| 462 return getContainerPositionX() + Math.round(mHotspotX); |
| 463 } |
| 464 |
| 465 // Returns the y coordinate of the postion that the handle appears to be poi
nting to relative to |
| 466 // the root view of the application. |
| 467 int getRootViewRelativePositionY() { |
| 468 return getContainerPositionY() + Math.round(mHotspotY); |
361 } | 469 } |
362 | 470 |
363 // Returns a suitable y coordinate for the text position corresponding to th
e handle. | 471 // Returns a suitable y coordinate for the text position corresponding to th
e handle. |
364 // As the handle points to a position on the base of the line of text, this
method | 472 // As the handle points to a position on the base of the line of text, this
method |
365 // returns a coordinate a small number of pixels higher (i.e. a slightly sma
ller number) | 473 // returns a coordinate a small number of pixels higher (i.e. a slightly sma
ller number) |
366 // than getAdjustedPositionY. | 474 // than getAdjustedPositionY. |
367 int getLineAdjustedPositionY() { | 475 int getLineAdjustedPositionY() { |
368 return (int) (mPositionY + mHotspotY - mLineOffsetY); | 476 return (int) (mPositionY + mHotspotY - mLineOffsetY); |
369 } | 477 } |
370 | 478 |
(...skipping 22 matching lines...) Expand all Loading... |
393 InsertionHandleController ihc = (InsertionHandleController) mController; | 501 InsertionHandleController ihc = (InsertionHandleController) mController; |
394 if (mIsInsertionHandle && ihc.canPaste()) { | 502 if (mIsInsertionHandle && ihc.canPaste()) { |
395 if (mPastePopupWindow == null) { | 503 if (mPastePopupWindow == null) { |
396 // Lazy initialization: create when actually shown only. | 504 // Lazy initialization: create when actually shown only. |
397 mPastePopupWindow = ihc.new PastePopupMenu(); | 505 mPastePopupWindow = ihc.new PastePopupMenu(); |
398 } | 506 } |
399 mPastePopupWindow.show(); | 507 mPastePopupWindow.show(); |
400 } | 508 } |
401 } | 509 } |
402 } | 510 } |
OLD | NEW |