| 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.ClipboardManager; | 7 import android.content.ClipboardManager; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.res.TypedArray; | 9 import android.content.res.TypedArray; |
| 10 import android.graphics.drawable.Drawable; | 10 import android.graphics.drawable.Drawable; |
| 11 import android.view.Gravity; | 11 import android.view.Gravity; |
| 12 import android.view.LayoutInflater; | 12 import android.view.LayoutInflater; |
| 13 import android.view.View; | 13 import android.view.View; |
| 14 import android.view.View.OnClickListener; | 14 import android.view.View.OnClickListener; |
| 15 import android.view.ViewGroup; | 15 import android.view.ViewGroup; |
| 16 import android.view.ViewGroup.LayoutParams; | 16 import android.view.ViewGroup.LayoutParams; |
| 17 import android.widget.PopupWindow; | 17 import android.widget.PopupWindow; |
| 18 | 18 |
| 19 import com.google.common.annotations.VisibleForTesting; | 19 import com.google.common.annotations.VisibleForTesting; |
| 20 | 20 |
| 21 import org.chromium.content.browser.PositionObserverInterface; |
| 22 |
| 21 /** | 23 /** |
| 22 * CursorController for inserting text at the cursor position. | 24 * CursorController for inserting text at the cursor position. |
| 23 */ | 25 */ |
| 24 public abstract class InsertionHandleController implements CursorController { | 26 public abstract class InsertionHandleController implements CursorController { |
| 25 | 27 |
| 26 /** The handle view, lazily created when first shown */ | 28 /** The handle view, lazily created when first shown */ |
| 27 private HandleView mHandle; | 29 private HandleView mHandle; |
| 28 | 30 |
| 29 /** The view over which the insertion handle should be shown */ | 31 /** The view over which the insertion handle should be shown */ |
| 30 private View mParent; | 32 private View mParent; |
| 31 | 33 |
| 32 /** True iff the insertion handle is currently showing */ | 34 /** True iff the insertion handle is currently showing */ |
| 33 private boolean mIsShowing; | 35 private boolean mIsShowing; |
| 34 | 36 |
| 35 /** True iff the insertion handle can be shown automatically when selection
changes */ | 37 /** True iff the insertion handle can be shown automatically when selection
changes */ |
| 36 private boolean mAllowAutomaticShowing; | 38 private boolean mAllowAutomaticShowing; |
| 37 | 39 |
| 38 private Context mContext; | 40 private Context mContext; |
| 39 | 41 |
| 40 public InsertionHandleController(View parent) { | 42 private HandleView.Delegate mHandleDelegate; |
| 43 |
| 44 private PositionObserverInterface mPositionObserver; |
| 45 |
| 46 public InsertionHandleController(View parent, PositionObserverInterface posi
tionObserver) { |
| 41 mParent = parent; | 47 mParent = parent; |
| 48 mHandleDelegate = new HandleView.ViewDelegate(parent); |
| 49 |
| 42 mContext = parent.getContext(); | 50 mContext = parent.getContext(); |
| 51 mPositionObserver = positionObserver; |
| 43 } | 52 } |
| 44 | 53 |
| 45 /** Allows the handle to be shown automatically when cursor position changes
*/ | 54 /** Allows the handle to be shown automatically when cursor position changes
*/ |
| 46 public void allowAutomaticShowing() { | 55 public void allowAutomaticShowing() { |
| 47 mAllowAutomaticShowing = true; | 56 mAllowAutomaticShowing = true; |
| 48 } | 57 } |
| 49 | 58 |
| 50 /** Disallows the handle from being shown automatically when cursor position
changes */ | 59 /** Disallows the handle from being shown automatically when cursor position
changes */ |
| 51 public void hideAndDisallowAutomaticShowing() { | 60 public void hideAndDisallowAutomaticShowing() { |
| 52 hide(); | 61 hide(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 169 |
| 161 @Override | 170 @Override |
| 162 public void onDetached() {} | 171 public void onDetached() {} |
| 163 | 172 |
| 164 boolean canPaste() { | 173 boolean canPaste() { |
| 165 return ((ClipboardManager)mContext.getSystemService( | 174 return ((ClipboardManager)mContext.getSystemService( |
| 166 Context.CLIPBOARD_SERVICE)).hasPrimaryClip(); | 175 Context.CLIPBOARD_SERVICE)).hasPrimaryClip(); |
| 167 } | 176 } |
| 168 | 177 |
| 169 private void createHandleIfNeeded() { | 178 private void createHandleIfNeeded() { |
| 170 if (mHandle == null) mHandle = new HandleView(this, HandleView.CENTER, m
Parent); | 179 if (mHandle == null) { |
| 180 mHandle = new HandleView(this, HandleView.CENTER, mHandleDelegate, m
PositionObserver); |
| 181 } |
| 171 } | 182 } |
| 172 | 183 |
| 173 private void showHandleIfNeeded() { | 184 private void showHandleIfNeeded() { |
| 174 if (!mIsShowing) { | 185 if (!mIsShowing) { |
| 175 mIsShowing = true; | 186 mIsShowing = true; |
| 176 mHandle.show(); | 187 mHandle.show(); |
| 177 setHandleVisibility(HandleView.VISIBLE); | 188 setHandleVisibility(HandleView.VISIBLE); |
| 178 } | 189 } |
| 179 } | 190 } |
| 180 | 191 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } else { | 319 } else { |
| 309 // Horizontal clipping | 320 // Horizontal clipping |
| 310 coords[0] = Math.max(0, coords[0]); | 321 coords[0] = Math.max(0, coords[0]); |
| 311 coords[0] = Math.min(screenWidth - width, coords[0]); | 322 coords[0] = Math.min(screenWidth - width, coords[0]); |
| 312 } | 323 } |
| 313 | 324 |
| 314 mContainer.showAtLocation(mParent, Gravity.NO_GRAVITY, coords[0], co
ords[1]); | 325 mContainer.showAtLocation(mParent, Gravity.NO_GRAVITY, coords[0], co
ords[1]); |
| 315 } | 326 } |
| 316 } | 327 } |
| 317 } | 328 } |
| OLD | NEW |