OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.app.SearchManager; | 9 import android.app.SearchManager; |
10 import android.content.ClipboardManager; | 10 import android.content.ClipboardManager; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 * | 188 * |
189 * <p>Action mode in floating mode is tried first, and then falls back to | 189 * <p>Action mode in floating mode is tried first, and then falls back to |
190 * a normal one. | 190 * a normal one. |
191 * @return {@code true} if the action mode started successfully or is alread
y on. | 191 * @return {@code true} if the action mode started successfully or is alread
y on. |
192 */ | 192 */ |
193 public boolean showActionMode() { | 193 public boolean showActionMode() { |
194 if (isEmpty()) return false; | 194 if (isEmpty()) return false; |
195 | 195 |
196 // Just refreshes the view if it is already showing. | 196 // Just refreshes the view if it is already showing. |
197 if (isActionModeValid()) { | 197 if (isActionModeValid()) { |
198 invalidateActionMode(); | 198 // Try/catch necessary for framework bug, crbug.com/446717. |
| 199 try { |
| 200 mActionMode.invalidate(); |
| 201 } catch (NullPointerException e) { |
| 202 Log.w(TAG, "Ignoring NPE from ActionMode.invalidate() as workaro
und for L", e); |
| 203 } |
| 204 hideActionMode(false); |
199 return true; | 205 return true; |
200 } | 206 } |
201 | 207 assert mWebContents != null; |
202 if (mView.getParent() != null) { | 208 ActionMode actionMode = supportsFloatingActionMode() |
203 // On ICS, startActionMode throws an NPE when getParent() is null. | 209 ? startFloatingActionMode() |
204 assert mWebContents != null; | 210 : mView.startActionMode(mCallback); |
205 ActionMode actionMode = supportsFloatingActionMode() | 211 if (actionMode != null) { |
206 ? startFloatingActionMode() | 212 // This is to work around an LGE email issue. See crbug.com/651706 f
or more details. |
207 : mView.startActionMode(mCallback); | 213 LGEmailActionModeWorkaround.runIfNecessary(mContext, actionMode); |
208 if (actionMode != null) { | |
209 // This is to work around an LGE email issue. See crbug.com/6517
06 for more details. | |
210 LGEmailActionModeWorkaround.runIfNecessary(mContext, actionMode)
; | |
211 } | |
212 mActionMode = actionMode; | |
213 } | 214 } |
| 215 mActionMode = actionMode; |
214 mUnselectAllOnDismiss = true; | 216 mUnselectAllOnDismiss = true; |
215 return isActionModeValid(); | 217 return isActionModeValid(); |
216 } | 218 } |
217 | 219 |
218 @TargetApi(Build.VERSION_CODES.M) | 220 @TargetApi(Build.VERSION_CODES.M) |
219 private ActionMode startFloatingActionMode() { | 221 private ActionMode startFloatingActionMode() { |
220 ActionMode actionMode = mView.startActionMode( | 222 ActionMode actionMode = mView.startActionMode( |
221 new FloatingActionModeCallback(this, mCallback), ActionMode.TYPE
_FLOATING); | 223 new FloatingActionModeCallback(this, mCallback), ActionMode.TYPE
_FLOATING); |
222 return actionMode; | 224 return actionMode; |
223 } | 225 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 public void finishActionMode() { | 291 public void finishActionMode() { |
290 if (isActionModeValid()) { | 292 if (isActionModeValid()) { |
291 mActionMode.finish(); | 293 mActionMode.finish(); |
292 | 294 |
293 // Should be nulled out in case #onDestroyActionMode() is not invoke
d in response. | 295 // Should be nulled out in case #onDestroyActionMode() is not invoke
d in response. |
294 mActionMode = null; | 296 mActionMode = null; |
295 } | 297 } |
296 } | 298 } |
297 | 299 |
298 /** | 300 /** |
299 * @see ActionMode#invalidate() | |
300 * Note that invalidation will also reset visibility state. The caller | |
301 * should account for this when making subsequent visibility updates. | |
302 */ | |
303 private void invalidateActionMode() { | |
304 if (!isActionModeValid()) return; | |
305 if (mHidden) { | |
306 assert canHideActionMode(); | |
307 mHidden = false; | |
308 mView.removeCallbacks(mRepeatingHideRunnable); | |
309 } | |
310 | |
311 // Try/catch necessary for framework bug, crbug.com/446717. | |
312 try { | |
313 mActionMode.invalidate(); | |
314 } catch (NullPointerException e) { | |
315 Log.w(TAG, "Ignoring NPE from ActionMode.invalidate() as workaround
for L", e); | |
316 } | |
317 } | |
318 | |
319 /** | |
320 * @see ActionMode#invalidateContentRect() | 301 * @see ActionMode#invalidateContentRect() |
321 */ | 302 */ |
322 public void invalidateContentRect() { | 303 public void invalidateContentRect() { |
323 if (supportsFloatingActionMode() && isActionModeValid()) { | 304 if (supportsFloatingActionMode() && isActionModeValid()) { |
324 mActionMode.invalidateContentRect(); | 305 mActionMode.invalidateContentRect(); |
325 } | 306 } |
326 } | 307 } |
327 | 308 |
328 /** | 309 /** |
329 * @see ActionMode#onWindowFocusChanged() | 310 * @see ActionMode#onWindowFocusChanged() |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 mIsInsertion = insertion; | 873 mIsInsertion = insertion; |
893 } | 874 } |
894 | 875 |
895 private boolean isShareAvailable() { | 876 private boolean isShareAvailable() { |
896 Intent intent = new Intent(Intent.ACTION_SEND); | 877 Intent intent = new Intent(Intent.ACTION_SEND); |
897 intent.setType("text/plain"); | 878 intent.setType("text/plain"); |
898 return mContext.getPackageManager().queryIntentActivities(intent, | 879 return mContext.getPackageManager().queryIntentActivities(intent, |
899 PackageManager.MATCH_DEFAULT_ONLY).size() > 0; | 880 PackageManager.MATCH_DEFAULT_ONLY).size() > 0; |
900 } | 881 } |
901 } | 882 } |
OLD | NEW |