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

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

Issue 1066053002: [Android] Allow custom ActionMode creation via ContentViewClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final fix Created 5 years, 8 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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; 5 package org.chromium.content.browser;
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.graphics.Rect;
9 import android.view.ActionMode; 10 import android.view.ActionMode;
10 import android.view.Menu; 11 import android.view.Menu;
11 import android.view.MenuItem; 12 import android.view.MenuItem;
13 import android.view.View;
12 14
13 import org.chromium.content.R; 15 import org.chromium.content.R;
14 16
15 /** 17 /**
16 * An ActionMode.Callback for in-page selection. This class handles both the edi table and 18 * An ActionMode.Callback for in-page selection. This class handles both the edi table and
17 * non-editable cases. 19 * non-editable cases.
18 */ 20 */
19 public class SelectActionModeCallback implements ActionMode.Callback { 21 public class SelectActionModeCallback implements ActionMode.Callback {
20 /** 22 /**
21 * An interface to retrieve information about the current selection, and als o to perform 23 * An interface to retrieve information about the current selection, and als o to perform
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 * @return true iff the current selection is editable (e.g. text within an input field). 58 * @return true iff the current selection is editable (e.g. text within an input field).
57 */ 59 */
58 boolean isSelectionEditable(); 60 boolean isSelectionEditable();
59 61
60 /** 62 /**
61 * Called when the onDestroyActionMode of the SelectActionmodeCallback i s called. 63 * Called when the onDestroyActionMode of the SelectActionmodeCallback i s called.
62 */ 64 */
63 void onDestroyActionMode(); 65 void onDestroyActionMode();
64 66
65 /** 67 /**
68 * Called when the onGetContentRect of the SelectActionModeCallback is c alled.
69 * @param outRect The Rect to be populated with the content position.
70 */
71 void onGetContentRect(Rect outRect);
72
73 /**
66 * @return Whether or not share is available. 74 * @return Whether or not share is available.
67 */ 75 */
68 boolean isShareAvailable(); 76 boolean isShareAvailable();
69 77
70 /** 78 /**
71 * @return Whether or not web search is available. 79 * @return Whether or not web search is available.
72 */ 80 */
73 boolean isWebSearchAvailable(); 81 boolean isWebSearchAvailable();
74 82
75 /** 83 /**
76 * @return true if the current selection is of password type. 84 * @return true if the current selection is of password type.
77 */ 85 */
78 boolean isSelectionPassword(); 86 boolean isSelectionPassword();
87
88 /**
89 * @return true if the current selection is an insertion point.
90 */
91 boolean isInsertion();
92
93 /**
94 * @return true if the current selection is for incognito content.
95 * Note: This should remain constant for the callback's lifetime .
96 */
97 boolean isIncognito();
79 } 98 }
80 99
100 protected final ActionHandler mActionHandler;
81 private final Context mContext; 101 private final Context mContext;
82 private final ActionHandler mActionHandler;
83 private final boolean mIncognito;
84 private boolean mEditable; 102 private boolean mEditable;
85 private boolean mIsPasswordType; 103 private boolean mIsPasswordType;
104 private boolean mIsInsertion;
86 105
87 protected SelectActionModeCallback( 106 public SelectActionModeCallback(Context context, ActionHandler actionHandler ) {
88 Context context, ActionHandler actionHandler, boolean incognito) {
89 mContext = context; 107 mContext = context;
90 mActionHandler = actionHandler; 108 mActionHandler = actionHandler;
91 mIncognito = incognito;
92 } 109 }
93 110
94 protected Context getContext() { 111 protected Context getContext() {
95 return mContext; 112 return mContext;
96 } 113 }
97 114
98 @Override 115 @Override
99 public boolean onCreateActionMode(ActionMode mode, Menu menu) { 116 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
100 mode.setTitle(null); 117 mode.setTitle(null);
101 mode.setSubtitle(null); 118 mode.setSubtitle(null);
102 mEditable = mActionHandler.isSelectionEditable(); 119 mEditable = mActionHandler.isSelectionEditable();
103 mIsPasswordType = mActionHandler.isSelectionPassword(); 120 mIsPasswordType = mActionHandler.isSelectionPassword();
121 mIsInsertion = mActionHandler.isInsertion();
104 createActionMenu(mode, menu); 122 createActionMenu(mode, menu);
105 return true; 123 return true;
106 } 124 }
107 125
108 @Override 126 @Override
109 public boolean onPrepareActionMode(ActionMode mode, Menu menu) { 127 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
110 boolean isEditableNow = mActionHandler.isSelectionEditable(); 128 boolean isEditableNow = mActionHandler.isSelectionEditable();
111 boolean isPasswordNow = mActionHandler.isSelectionPassword(); 129 boolean isPasswordNow = mActionHandler.isSelectionPassword();
112 if (mEditable != isEditableNow || mIsPasswordType != isPasswordNow) { 130 boolean isInsertionNow = mActionHandler.isInsertion();
131 if (mEditable != isEditableNow || mIsPasswordType != isPasswordNow
132 || mIsInsertion != isInsertionNow) {
113 mEditable = isEditableNow; 133 mEditable = isEditableNow;
114 mIsPasswordType = isPasswordNow; 134 mIsPasswordType = isPasswordNow;
135 mIsInsertion = isInsertionNow;
115 menu.clear(); 136 menu.clear();
116 createActionMenu(mode, menu); 137 createActionMenu(mode, menu);
117 return true; 138 return true;
118 } 139 }
119 return false; 140 return false;
120 } 141 }
121 142
122 private void createActionMenu(ActionMode mode, Menu menu) { 143 private void createActionMenu(ActionMode mode, Menu menu) {
123 mode.getMenuInflater().inflate(R.menu.select_action_menu, menu); 144 mode.getMenuInflater().inflate(R.menu.select_action_menu, menu);
124 145
146 if (mIsInsertion) {
147 menu.removeItem(R.id.select_action_menu_select_all);
148 menu.removeItem(R.id.select_action_menu_cut);
149 menu.removeItem(R.id.select_action_menu_copy);
150 menu.removeItem(R.id.select_action_menu_share);
151 menu.removeItem(R.id.select_action_menu_web_search);
152 return;
153 }
154
125 if (!mEditable || !canPaste()) { 155 if (!mEditable || !canPaste()) {
126 menu.removeItem(R.id.select_action_menu_paste); 156 menu.removeItem(R.id.select_action_menu_paste);
127 } 157 }
128 158
129 if (!mEditable) { 159 if (!mEditable) {
130 menu.removeItem(R.id.select_action_menu_cut); 160 menu.removeItem(R.id.select_action_menu_cut);
131 } 161 }
132 162
133 if (mEditable || !mActionHandler.isShareAvailable()) { 163 if (mEditable || !mActionHandler.isShareAvailable()) {
134 menu.removeItem(R.id.select_action_menu_share); 164 menu.removeItem(R.id.select_action_menu_share);
135 } 165 }
136 166
137 if (mEditable || mIncognito || !mActionHandler.isWebSearchAvailable()) { 167 if (mEditable || mActionHandler.isIncognito() || !mActionHandler.isWebSe archAvailable()) {
138 menu.removeItem(R.id.select_action_menu_web_search); 168 menu.removeItem(R.id.select_action_menu_web_search);
139 } 169 }
170
140 if (mIsPasswordType) { 171 if (mIsPasswordType) {
141 menu.removeItem(R.id.select_action_menu_copy); 172 menu.removeItem(R.id.select_action_menu_copy);
142 menu.removeItem(R.id.select_action_menu_cut); 173 menu.removeItem(R.id.select_action_menu_cut);
143 } 174 }
144 } 175 }
145 176
146 @Override 177 @Override
147 public boolean onActionItemClicked(ActionMode mode, MenuItem item) { 178 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
148 int id = item.getItemId(); 179 int id = item.getItemId();
149 180
(...skipping 18 matching lines...) Expand all
168 return false; 199 return false;
169 } 200 }
170 return true; 201 return true;
171 } 202 }
172 203
173 @Override 204 @Override
174 public void onDestroyActionMode(ActionMode mode) { 205 public void onDestroyActionMode(ActionMode mode) {
175 mActionHandler.onDestroyActionMode(); 206 mActionHandler.onDestroyActionMode();
176 } 207 }
177 208
209 /**
210 * Called when an ActionMode needs to be positioned on screen, potentially o ccluding view
211 * content. Note this may be called on a per-frame basis.
212 *
213 * @param mode The ActionMode that requires positioning.
214 * @param view The View that originated the ActionMode, in whose coordinates the Rect should
215 * be provided.
216 * @param outRect The Rect to be populated with the content position.
217 */
218 public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
219 mActionHandler.onGetContentRect(outRect);
220 }
221
178 private boolean canPaste() { 222 private boolean canPaste() {
179 ClipboardManager clipMgr = (ClipboardManager) 223 ClipboardManager clipMgr = (ClipboardManager)
180 getContext().getSystemService(Context.CLIPBOARD_SERVICE); 224 getContext().getSystemService(Context.CLIPBOARD_SERVICE);
181 return clipMgr.hasPrimaryClip(); 225 return clipMgr.hasPrimaryClip();
182 } 226 }
183 } 227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698