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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/input/SelectionHandleController.java

Issue 24449007: [Android] Allow text handles to observe position of "parent" view (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.view.View; 7 import android.view.View;
8 8
9 import com.google.common.annotations.VisibleForTesting; 9 import com.google.common.annotations.VisibleForTesting;
10 10
11 import org.chromium.content.browser.PositionObserverInterface;
12
11 /** 13 /**
12 * CursorController for selecting a range of text. 14 * CursorController for selecting a range of text.
13 */ 15 */
14 public abstract class SelectionHandleController implements CursorController { 16 public abstract class SelectionHandleController implements CursorController {
15 17
16 // The following constants match the ones in 18 // The following constants match the ones in
17 // third_party/WebKit/public/web/WebTextDirection.h 19 // third_party/WebKit/public/web/WebTextDirection.h
18 private static final int TEXT_DIRECTION_DEFAULT = 0; 20 private static final int TEXT_DIRECTION_DEFAULT = 0;
19 private static final int TEXT_DIRECTION_LTR = 1; 21 private static final int TEXT_DIRECTION_LTR = 1;
20 private static final int TEXT_DIRECTION_RTL = 2; 22 private static final int TEXT_DIRECTION_RTL = 2;
21 23
22 /** The cursor controller images, lazily created when shown. */ 24 /** The cursor controller images, lazily created when shown. */
23 private HandleView mStartHandle, mEndHandle; 25 private HandleView mStartHandle, mEndHandle;
24 26
25 /** Whether handles should show automatically when text is selected. */ 27 /** Whether handles should show automatically when text is selected. */
26 private boolean mAllowAutomaticShowing = true; 28 private boolean mAllowAutomaticShowing = true;
27 29
28 /** Whether selection anchors are active. */ 30 /** Whether selection anchors are active. */
29 private boolean mIsShowing; 31 private boolean mIsShowing;
30 32
31 private View mParent; 33 private HandleView.Delegate mStartHandleDelegate;
34 private HandleView.Delegate mEndHandleDelegate;
32 35
33 private int mFixedHandleX; 36 private int mFixedHandleX;
34 private int mFixedHandleY; 37 private int mFixedHandleY;
35 38
36 public SelectionHandleController(View parent) { 39 private PositionObserverInterface mPositionObserver;
37 mParent = parent; 40
41 public SelectionHandleController(HandleView.Delegate startHandleDelegate,
42 HandleView.Delegate endHandleDelegate, PositionObserverInterface pos itionObserver) {
43 mStartHandleDelegate = startHandleDelegate;
44 mEndHandleDelegate = endHandleDelegate;
45 mPositionObserver = positionObserver;
38 } 46 }
39 47
40 /** Automatically show selection anchors when text is selected. */ 48 /** Automatically show selection anchors when text is selected. */
41 public void allowAutomaticShowing() { 49 public void allowAutomaticShowing() {
42 mAllowAutomaticShowing = true; 50 mAllowAutomaticShowing = true;
43 } 51 }
44 52
45 /** Hide selection anchors, and don't automatically show them. */ 53 /** Hide selection anchors, and don't automatically show them. */
46 public void hideAndDisallowAutomaticShowing() { 54 public void hideAndDisallowAutomaticShowing() {
47 hide(); 55 hide();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 191 }
184 192
185 @VisibleForTesting 193 @VisibleForTesting
186 public HandleView getEndHandleViewForTest() { 194 public HandleView getEndHandleViewForTest() {
187 return mEndHandle; 195 return mEndHandle;
188 } 196 }
189 197
190 private void createHandlesIfNeeded(int startDir, int endDir) { 198 private void createHandlesIfNeeded(int startDir, int endDir) {
191 if (mStartHandle == null) { 199 if (mStartHandle == null) {
192 mStartHandle = new HandleView(this, 200 mStartHandle = new HandleView(this,
193 startDir == TEXT_DIRECTION_RTL ? HandleView.RIGHT : HandleView.L EFT, mParent); 201 startDir == TEXT_DIRECTION_RTL ? HandleView.RIGHT : HandleVi ew.LEFT,
202 mStartHandleDelegate, mPositionObserver);
194 } 203 }
195 if (mEndHandle == null) { 204 if (mEndHandle == null) {
196 mEndHandle = new HandleView(this, 205 mEndHandle = new HandleView(this,
197 endDir == TEXT_DIRECTION_RTL ? HandleView.LEFT : HandleView.RIGH T, mParent); 206 endDir == TEXT_DIRECTION_RTL ? HandleView.LEFT : HandleView. RIGHT,
207 mEndHandleDelegate, mPositionObserver);
198 } 208 }
199 } 209 }
200 210
201 private void showHandlesIfNeeded() { 211 private void showHandlesIfNeeded() {
202 if (!mIsShowing) { 212 if (!mIsShowing) {
203 mIsShowing = true; 213 mIsShowing = true;
204 mStartHandle.show(); 214 mStartHandle.show();
205 mEndHandle.show(); 215 mEndHandle.show();
206 setHandleVisibility(HandleView.VISIBLE); 216 setHandleVisibility(HandleView.VISIBLE);
207 } 217 }
208 } 218 }
209 } 219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698