| 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.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.PositionObserver; |
| 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 View mParent; |
| 32 | 34 |
| 33 private int mFixedHandleX; | 35 private int mFixedHandleX; |
| 34 private int mFixedHandleY; | 36 private int mFixedHandleY; |
| 35 | 37 |
| 36 public SelectionHandleController(View parent) { | 38 private PositionObserver mPositionObserver; |
| 39 |
| 40 public SelectionHandleController(View parent, PositionObserver positionObser
ver) { |
| 37 mParent = parent; | 41 mParent = parent; |
| 42 mPositionObserver = positionObserver; |
| 38 } | 43 } |
| 39 | 44 |
| 40 /** Automatically show selection anchors when text is selected. */ | 45 /** Automatically show selection anchors when text is selected. */ |
| 41 public void allowAutomaticShowing() { | 46 public void allowAutomaticShowing() { |
| 42 mAllowAutomaticShowing = true; | 47 mAllowAutomaticShowing = true; |
| 43 } | 48 } |
| 44 | 49 |
| 45 /** Hide selection anchors, and don't automatically show them. */ | 50 /** Hide selection anchors, and don't automatically show them. */ |
| 46 public void hideAndDisallowAutomaticShowing() { | 51 public void hideAndDisallowAutomaticShowing() { |
| 47 hide(); | 52 hide(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 188 } |
| 184 | 189 |
| 185 @VisibleForTesting | 190 @VisibleForTesting |
| 186 public HandleView getEndHandleViewForTest() { | 191 public HandleView getEndHandleViewForTest() { |
| 187 return mEndHandle; | 192 return mEndHandle; |
| 188 } | 193 } |
| 189 | 194 |
| 190 private void createHandlesIfNeeded(int startDir, int endDir) { | 195 private void createHandlesIfNeeded(int startDir, int endDir) { |
| 191 if (mStartHandle == null) { | 196 if (mStartHandle == null) { |
| 192 mStartHandle = new HandleView(this, | 197 mStartHandle = new HandleView(this, |
| 193 startDir == TEXT_DIRECTION_RTL ? HandleView.RIGHT : HandleView.L
EFT, mParent); | 198 startDir == TEXT_DIRECTION_RTL ? HandleView.RIGHT : HandleVi
ew.LEFT, mParent, |
| 199 mPositionObserver); |
| 194 } | 200 } |
| 195 if (mEndHandle == null) { | 201 if (mEndHandle == null) { |
| 196 mEndHandle = new HandleView(this, | 202 mEndHandle = new HandleView(this, |
| 197 endDir == TEXT_DIRECTION_RTL ? HandleView.LEFT : HandleView.RIGH
T, mParent); | 203 endDir == TEXT_DIRECTION_RTL ? HandleView.LEFT : HandleView.
RIGHT, mParent, |
| 204 mPositionObserver); |
| 198 } | 205 } |
| 199 } | 206 } |
| 200 | 207 |
| 201 private void showHandlesIfNeeded() { | 208 private void showHandlesIfNeeded() { |
| 202 if (!mIsShowing) { | 209 if (!mIsShowing) { |
| 203 mIsShowing = true; | 210 mIsShowing = true; |
| 204 mStartHandle.show(); | 211 mStartHandle.show(); |
| 205 mEndHandle.show(); | 212 mEndHandle.show(); |
| 206 setHandleVisibility(HandleView.VISIBLE); | 213 setHandleVisibility(HandleView.VISIBLE); |
| 207 } | 214 } |
| 208 } | 215 } |
| 209 } | 216 } |
| OLD | NEW |