OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.graphics.Canvas; | 8 import android.graphics.Canvas; |
9 import android.graphics.drawable.Drawable; | 9 import android.graphics.drawable.Drawable; |
10 import android.view.MotionEvent; | 10 import android.view.MotionEvent; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 private float mHotspotY; | 52 private float mHotspotY; |
53 | 53 |
54 private float mAlpha; | 54 private float mAlpha; |
55 | 55 |
56 private final int[] mTempScreenCoords = new int[2]; | 56 private final int[] mTempScreenCoords = new int[2]; |
57 | 57 |
58 static final int LEFT = 0; | 58 static final int LEFT = 0; |
59 static final int CENTER = 1; | 59 static final int CENTER = 1; |
60 static final int RIGHT = 2; | 60 static final int RIGHT = 2; |
61 private int mOrientation = -1; | 61 private int mOrientation = -1; |
62 private boolean mDownTouch = false; | |
62 | 63 |
63 /** | 64 /** |
64 * Provides additional interaction behaviors necessary for handle | 65 * Provides additional interaction behaviors necessary for handle |
65 * manipulation and interaction. | 66 * manipulation and interaction. |
66 */ | 67 */ |
67 public interface PopupTouchHandleDrawableDelegate { | 68 public interface PopupTouchHandleDrawableDelegate { |
68 /** | 69 /** |
69 * @return The parent View of the PopupWindow. | 70 * @return The parent View of the PopupWindow. |
70 */ | 71 */ |
71 View getParent(); | 72 View getParent(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 111 |
111 // Convert from PopupWindow local coordinates to | 112 // Convert from PopupWindow local coordinates to |
112 // parent view local coordinates prior to forwarding. | 113 // parent view local coordinates prior to forwarding. |
113 delegate.getParent().getLocationOnScreen(mTempScreenCoords); | 114 delegate.getParent().getLocationOnScreen(mTempScreenCoords); |
114 final float offsetX = event.getRawX() - event.getX() - mTempScreenCoords [0]; | 115 final float offsetX = event.getRawX() - event.getX() - mTempScreenCoords [0]; |
115 final float offsetY = event.getRawY() - event.getY() - mTempScreenCoords [1]; | 116 final float offsetY = event.getRawY() - event.getY() - mTempScreenCoords [1]; |
116 final MotionEvent offsetEvent = MotionEvent.obtainNoHistory(event); | 117 final MotionEvent offsetEvent = MotionEvent.obtainNoHistory(event); |
117 offsetEvent.offsetLocation(offsetX, offsetY); | 118 offsetEvent.offsetLocation(offsetX, offsetY); |
118 final boolean handled = delegate.onTouchHandleEvent(offsetEvent); | 119 final boolean handled = delegate.onTouchHandleEvent(offsetEvent); |
119 offsetEvent.recycle(); | 120 offsetEvent.recycle(); |
121 // Listening for the down and up touch events | |
122 // to enable accessibility services for a user | |
123 // who cannot click touch screen. | |
124 switch (event.getAction()) { | |
125 case MotionEvent.ACTION_DOWN: | |
126 mDownTouch = true; | |
127 break; | |
128 case MotionEvent.ACTION_UP: | |
129 if (mDownTouch) { | |
130 mDownTouch = false; | |
131 performClick(); | |
newt (away)
2014/10/20 22:20:53
This isn't how performClick() should be used. See
jdduke (slow)
2014/10/20 23:06:17
I'm not familiar (at all) with Android's accesibil
wajahat
2014/10/21 14:34:56
So going with the comments, it is ok to suppress t
| |
132 } | |
133 } | |
120 return handled; | 134 return handled; |
121 } | 135 } |
122 | 136 |
137 @Override | |
138 public boolean performClick() { | |
139 super.performClick(); | |
140 return true; | |
141 } | |
142 | |
123 private void setOrientation(int orientation) { | 143 private void setOrientation(int orientation) { |
124 assert orientation >= LEFT && orientation <= RIGHT; | 144 assert orientation >= LEFT && orientation <= RIGHT; |
125 if (mOrientation == orientation) return; | 145 if (mOrientation == orientation) return; |
126 | 146 |
127 final boolean hadValidOrientation = mOrientation != -1; | 147 final boolean hadValidOrientation = mOrientation != -1; |
128 mOrientation = orientation; | 148 mOrientation = orientation; |
129 | 149 |
130 final int oldAdjustedPositionX = getAdjustedPositionX(); | 150 final int oldAdjustedPositionX = getAdjustedPositionX(); |
131 final int oldAdjustedPositionY = getAdjustedPositionY(); | 151 final int oldAdjustedPositionY = getAdjustedPositionY(); |
132 | 152 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 private boolean intersectsWith(float x, float y, float width, float height) { | 308 private boolean intersectsWith(float x, float y, float width, float height) { |
289 if (mDrawable == null) return false; | 309 if (mDrawable == null) return false; |
290 final int drawableWidth = mDrawable.getIntrinsicWidth(); | 310 final int drawableWidth = mDrawable.getIntrinsicWidth(); |
291 final int drawableHeight = mDrawable.getIntrinsicHeight(); | 311 final int drawableHeight = mDrawable.getIntrinsicHeight(); |
292 return !(x >= mPositionX + drawableWidth | 312 return !(x >= mPositionX + drawableWidth |
293 || y >= mPositionY + drawableHeight | 313 || y >= mPositionY + drawableHeight |
294 || x + width <= mPositionX | 314 || x + width <= mPositionX |
295 || y + height <= mPositionY); | 315 || y + height <= mPositionY); |
296 } | 316 } |
297 } | 317 } |
OLD | NEW |