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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/input/InsertionHandleController.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.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.PositionObserver;
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 PositionObserver mPositionObserver;
43
44 public InsertionHandleController(View parent, PositionObserver positionObser ver) {
41 mParent = parent; 45 mParent = parent;
46
42 mContext = parent.getContext(); 47 mContext = parent.getContext();
48 mPositionObserver = positionObserver;
43 } 49 }
44 50
45 /** Allows the handle to be shown automatically when cursor position changes */ 51 /** Allows the handle to be shown automatically when cursor position changes */
46 public void allowAutomaticShowing() { 52 public void allowAutomaticShowing() {
47 mAllowAutomaticShowing = true; 53 mAllowAutomaticShowing = true;
48 } 54 }
49 55
50 /** Disallows the handle from being shown automatically when cursor position changes */ 56 /** Disallows the handle from being shown automatically when cursor position changes */
51 public void hideAndDisallowAutomaticShowing() { 57 public void hideAndDisallowAutomaticShowing() {
52 hide(); 58 hide();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 166
161 @Override 167 @Override
162 public void onDetached() {} 168 public void onDetached() {}
163 169
164 boolean canPaste() { 170 boolean canPaste() {
165 return ((ClipboardManager)mContext.getSystemService( 171 return ((ClipboardManager)mContext.getSystemService(
166 Context.CLIPBOARD_SERVICE)).hasPrimaryClip(); 172 Context.CLIPBOARD_SERVICE)).hasPrimaryClip();
167 } 173 }
168 174
169 private void createHandleIfNeeded() { 175 private void createHandleIfNeeded() {
170 if (mHandle == null) mHandle = new HandleView(this, HandleView.CENTER, m Parent); 176 if (mHandle == null) {
177 mHandle = new HandleView(this, HandleView.CENTER, mParent, mPosition Observer);
178 }
171 } 179 }
172 180
173 private void showHandleIfNeeded() { 181 private void showHandleIfNeeded() {
174 if (!mIsShowing) { 182 if (!mIsShowing) {
175 mIsShowing = true; 183 mIsShowing = true;
176 mHandle.show(); 184 mHandle.show();
177 setHandleVisibility(HandleView.VISIBLE); 185 setHandleVisibility(HandleView.VISIBLE);
178 } 186 }
179 } 187 }
180 188
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 } else { 316 } else {
309 // Horizontal clipping 317 // Horizontal clipping
310 coords[0] = Math.max(0, coords[0]); 318 coords[0] = Math.max(0, coords[0]);
311 coords[0] = Math.min(screenWidth - width, coords[0]); 319 coords[0] = Math.min(screenWidth - width, coords[0]);
312 } 320 }
313 321
314 mContainer.showAtLocation(mParent, Gravity.NO_GRAVITY, coords[0], co ords[1]); 322 mContainer.showAtLocation(mParent, Gravity.NO_GRAVITY, coords[0], co ords[1]);
315 } 323 }
316 } 324 }
317 } 325 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698