Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.content.Intent; | |
| 9 import android.content.res.Resources; | 10 import android.content.res.Resources; |
| 10 import android.graphics.Rect; | 11 import android.graphics.Rect; |
| 11 import android.view.ActionMode; | 12 import android.view.ActionMode; |
| 12 import android.view.Menu; | 13 import android.view.Menu; |
| 13 import android.view.MenuInflater; | 14 import android.view.MenuInflater; |
| 14 import android.view.MenuItem; | 15 import android.view.MenuItem; |
| 15 import android.view.View; | 16 import android.view.View; |
| 16 | 17 |
| 17 import org.chromium.content.R; | 18 import org.chromium.content.R; |
| 18 import org.chromium.ui.base.DeviceFormFactor; | 19 import org.chromium.ui.base.DeviceFormFactor; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 46 * Perform a paste action. | 47 * Perform a paste action. |
| 47 */ | 48 */ |
| 48 void paste(); | 49 void paste(); |
| 49 | 50 |
| 50 /** | 51 /** |
| 51 * Perform a share action. | 52 * Perform a share action. |
| 52 */ | 53 */ |
| 53 void share(); | 54 void share(); |
| 54 | 55 |
| 55 /** | 56 /** |
| 57 * Perform a processText action (translating the text, for example). | |
| 58 */ | |
| 59 void processText(Intent intent); | |
| 60 | |
| 61 /** | |
| 62 * Intialize the menu items for processing text, if there is any. | |
| 63 */ | |
| 64 void initializeTextProcessingMenu(Menu menu); | |
|
Ted C
2015/09/17 20:34:57
To me, this function doesn't seem like it belongs
hush (inactive)
2015/09/17 21:30:52
Okay. I just moved the related logic from contentv
| |
| 65 | |
| 66 /** | |
| 56 * Perform a search action. | 67 * Perform a search action. |
| 57 */ | 68 */ |
| 58 void search(); | 69 void search(); |
| 59 | 70 |
| 60 /** | 71 /** |
| 61 * @return true iff the current selection is editable (e.g. text within an input field). | 72 * @return true iff the current selection is editable (e.g. text within an input field). |
| 62 */ | 73 */ |
| 63 boolean isSelectionEditable(); | 74 boolean isSelectionEditable(); |
| 64 | 75 |
| 65 /** | 76 /** |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 try { | 161 try { |
| 151 mode.getMenuInflater().inflate(R.menu.select_action_menu, menu); | 162 mode.getMenuInflater().inflate(R.menu.select_action_menu, menu); |
| 152 } catch (Resources.NotFoundException e) { | 163 } catch (Resources.NotFoundException e) { |
| 153 // TODO(tobiasjs) by the time we get here we have already | 164 // TODO(tobiasjs) by the time we get here we have already |
| 154 // caused a resource loading failure to be logged. WebView | 165 // caused a resource loading failure to be logged. WebView |
| 155 // resource access needs to be improved so that this | 166 // resource access needs to be improved so that this |
| 156 // logspam can be avoided. | 167 // logspam can be avoided. |
| 157 new MenuInflater(getContext()).inflate(R.menu.select_action_menu, me nu); | 168 new MenuInflater(getContext()).inflate(R.menu.select_action_menu, me nu); |
| 158 } | 169 } |
| 159 | 170 |
| 171 mActionHandler.initializeTextProcessingMenu(menu); | |
| 172 | |
| 160 if (mIsInsertion) { | 173 if (mIsInsertion) { |
| 161 menu.removeItem(R.id.select_action_menu_select_all); | 174 menu.removeItem(R.id.select_action_menu_select_all); |
| 162 menu.removeItem(R.id.select_action_menu_cut); | 175 menu.removeItem(R.id.select_action_menu_cut); |
| 163 menu.removeItem(R.id.select_action_menu_copy); | 176 menu.removeItem(R.id.select_action_menu_copy); |
| 164 menu.removeItem(R.id.select_action_menu_share); | 177 menu.removeItem(R.id.select_action_menu_share); |
| 165 menu.removeItem(R.id.select_action_menu_web_search); | 178 menu.removeItem(R.id.select_action_menu_web_search); |
| 179 menu.removeGroup(R.id.select_action_menu_text_processing_menus); | |
| 166 return; | 180 return; |
| 167 } | 181 } |
| 168 | 182 |
| 169 if (!mEditable || !canPaste()) { | 183 if (!mEditable || !canPaste()) { |
| 170 menu.removeItem(R.id.select_action_menu_paste); | 184 menu.removeItem(R.id.select_action_menu_paste); |
| 171 } | 185 } |
| 172 | 186 |
| 173 if (!mEditable) { | 187 if (!mEditable) { |
| 174 menu.removeItem(R.id.select_action_menu_cut); | 188 menu.removeItem(R.id.select_action_menu_cut); |
| 175 } | 189 } |
| 176 | 190 |
| 177 if (mEditable || !mActionHandler.isShareAvailable()) { | 191 if (mEditable || !mActionHandler.isShareAvailable()) { |
| 178 menu.removeItem(R.id.select_action_menu_share); | 192 menu.removeItem(R.id.select_action_menu_share); |
| 179 } | 193 } |
| 180 | 194 |
| 181 if (mEditable || mActionHandler.isIncognito() || !mActionHandler.isWebSe archAvailable()) { | 195 if (mEditable || mActionHandler.isIncognito() || !mActionHandler.isWebSe archAvailable()) { |
| 182 menu.removeItem(R.id.select_action_menu_web_search); | 196 menu.removeItem(R.id.select_action_menu_web_search); |
| 183 } | 197 } |
| 184 | 198 |
| 185 if (mIsPasswordType) { | 199 if (mIsPasswordType) { |
| 186 menu.removeItem(R.id.select_action_menu_copy); | 200 menu.removeItem(R.id.select_action_menu_copy); |
| 187 menu.removeItem(R.id.select_action_menu_cut); | 201 menu.removeItem(R.id.select_action_menu_cut); |
| 202 menu.removeGroup(R.id.select_action_menu_text_processing_menus); | |
| 188 } | 203 } |
| 189 } | 204 } |
| 190 | 205 |
| 191 @Override | 206 @Override |
| 192 public boolean onActionItemClicked(ActionMode mode, MenuItem item) { | 207 public boolean onActionItemClicked(ActionMode mode, MenuItem item) { |
| 193 if (mIsDestroyed) return true; | 208 if (mIsDestroyed) return true; |
| 194 | 209 |
| 195 int id = item.getItemId(); | 210 int id = item.getItemId(); |
| 211 int groupId = item.getGroupId(); | |
| 196 | 212 |
| 197 if (id == R.id.select_action_menu_select_all) { | 213 if (id == R.id.select_action_menu_select_all) { |
| 198 mActionHandler.selectAll(); | 214 mActionHandler.selectAll(); |
| 199 } else if (id == R.id.select_action_menu_cut) { | 215 } else if (id == R.id.select_action_menu_cut) { |
| 200 mActionHandler.cut(); | 216 mActionHandler.cut(); |
| 201 mode.finish(); | 217 mode.finish(); |
| 202 } else if (id == R.id.select_action_menu_copy) { | 218 } else if (id == R.id.select_action_menu_copy) { |
| 203 mActionHandler.copy(); | 219 mActionHandler.copy(); |
| 204 mode.finish(); | 220 mode.finish(); |
| 205 } else if (id == R.id.select_action_menu_paste) { | 221 } else if (id == R.id.select_action_menu_paste) { |
| 206 mActionHandler.paste(); | 222 mActionHandler.paste(); |
| 207 mode.finish(); | 223 mode.finish(); |
| 208 } else if (id == R.id.select_action_menu_share) { | 224 } else if (id == R.id.select_action_menu_share) { |
| 209 mActionHandler.share(); | 225 mActionHandler.share(); |
| 210 mode.finish(); | 226 mode.finish(); |
| 211 } else if (id == R.id.select_action_menu_web_search) { | 227 } else if (id == R.id.select_action_menu_web_search) { |
| 212 mActionHandler.search(); | 228 mActionHandler.search(); |
| 213 mode.finish(); | 229 mode.finish(); |
| 230 } else if (groupId == R.id.select_action_menu_text_processing_menus) { | |
| 231 mActionHandler.processText(item.getIntent()); | |
| 232 mode.finish(); | |
| 214 } else { | 233 } else { |
| 215 return false; | 234 return false; |
| 216 } | 235 } |
| 217 return true; | 236 return true; |
| 218 } | 237 } |
| 219 | 238 |
| 220 @Override | 239 @Override |
| 221 public void onDestroyActionMode(ActionMode mode) { | 240 public void onDestroyActionMode(ActionMode mode) { |
| 222 mIsDestroyed = true; | 241 mIsDestroyed = true; |
| 223 mActionHandler.onDestroyActionMode(); | 242 mActionHandler.onDestroyActionMode(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 236 if (mIsDestroyed) return; | 255 if (mIsDestroyed) return; |
| 237 mActionHandler.onGetContentRect(outRect); | 256 mActionHandler.onGetContentRect(outRect); |
| 238 } | 257 } |
| 239 | 258 |
| 240 private boolean canPaste() { | 259 private boolean canPaste() { |
| 241 ClipboardManager clipMgr = (ClipboardManager) | 260 ClipboardManager clipMgr = (ClipboardManager) |
| 242 getContext().getSystemService(Context.CLIPBOARD_SERVICE); | 261 getContext().getSystemService(Context.CLIPBOARD_SERVICE); |
| 243 return clipMgr.hasPrimaryClip(); | 262 return clipMgr.hasPrimaryClip(); |
| 244 } | 263 } |
| 245 } | 264 } |
| OLD | NEW |