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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // required because ActionMode only exposes a temporary hide routine. | 84 // required because ActionMode only exposes a temporary hide routine. |
85 private final Runnable mRepeatingHideRunnable; | 85 private final Runnable mRepeatingHideRunnable; |
86 | 86 |
87 private View mView; | 87 private View mView; |
88 private ActionMode mActionMode; | 88 private ActionMode mActionMode; |
89 | 89 |
90 // Bit field for mappings from menu item to a flag indicating it is allowed. | 90 // Bit field for mappings from menu item to a flag indicating it is allowed. |
91 private int mAllowedMenuItems; | 91 private int mAllowedMenuItems; |
92 | 92 |
93 private boolean mHidden; | 93 private boolean mHidden; |
94 private boolean mPendingInvalidateContentRect; | |
95 | 94 |
96 private boolean mEditable; | 95 private boolean mEditable; |
97 private boolean mIsPasswordType; | 96 private boolean mIsPasswordType; |
98 private boolean mIsInsertion; | 97 private boolean mIsInsertion; |
99 | 98 |
100 // Indicates whether the action mode needs to be redrawn since last invalida
tion. | 99 // Indicates whether the action mode needs to be redrawn since last invalida
tion. |
101 private boolean mNeedsPrepare; | 100 private boolean mNeedsPrepare; |
102 | 101 |
103 private boolean mUnselectAllOnDismiss; | 102 private boolean mUnselectAllOnDismiss; |
104 private String mLastSelectedText; | 103 private String mLastSelectedText; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 * @see ActionMode#invalidate() | 299 * @see ActionMode#invalidate() |
301 * Note that invalidation will also reset visibility state. The caller | 300 * Note that invalidation will also reset visibility state. The caller |
302 * should account for this when making subsequent visibility updates. | 301 * should account for this when making subsequent visibility updates. |
303 */ | 302 */ |
304 private void invalidateActionMode() { | 303 private void invalidateActionMode() { |
305 if (!isActionModeValid()) return; | 304 if (!isActionModeValid()) return; |
306 if (mHidden) { | 305 if (mHidden) { |
307 assert canHideActionMode(); | 306 assert canHideActionMode(); |
308 mHidden = false; | 307 mHidden = false; |
309 mView.removeCallbacks(mRepeatingHideRunnable); | 308 mView.removeCallbacks(mRepeatingHideRunnable); |
310 mPendingInvalidateContentRect = false; | |
311 } | 309 } |
312 | 310 |
313 // Try/catch necessary for framework bug, crbug.com/446717. | 311 // Try/catch necessary for framework bug, crbug.com/446717. |
314 try { | 312 try { |
315 mActionMode.invalidate(); | 313 mActionMode.invalidate(); |
316 } catch (NullPointerException e) { | 314 } catch (NullPointerException e) { |
317 Log.w(TAG, "Ignoring NPE from ActionMode.invalidate() as workaround
for L", e); | 315 Log.w(TAG, "Ignoring NPE from ActionMode.invalidate() as workaround
for L", e); |
318 } | 316 } |
319 } | 317 } |
320 | 318 |
321 /** | 319 /** |
322 * @see ActionMode#invalidateContentRect() | 320 * @see ActionMode#invalidateContentRect() |
323 */ | 321 */ |
324 public void invalidateContentRect() { | 322 public void invalidateContentRect() { |
325 if (supportsFloatingActionMode()) { | 323 if (supportsFloatingActionMode() && isActionModeValid()) { |
326 if (mHidden) { | 324 mActionMode.invalidateContentRect(); |
327 mPendingInvalidateContentRect = true; | |
328 } else { | |
329 mPendingInvalidateContentRect = false; | |
330 if (isActionModeValid()) mActionMode.invalidateContentRect(); | |
331 } | |
332 } | 325 } |
333 } | 326 } |
334 | 327 |
335 /** | 328 /** |
336 * @see ActionMode#onWindowFocusChanged() | 329 * @see ActionMode#onWindowFocusChanged() |
337 */ | 330 */ |
338 void onWindowFocusChanged(boolean hasWindowFocus) { | 331 void onWindowFocusChanged(boolean hasWindowFocus) { |
339 if (supportsFloatingActionMode() && isActionModeValid()) { | 332 if (supportsFloatingActionMode() && isActionModeValid()) { |
340 mActionMode.onWindowFocusChanged(hasWindowFocus); | 333 mActionMode.onWindowFocusChanged(hasWindowFocus); |
341 } | 334 } |
342 } | 335 } |
343 | 336 |
344 /** | 337 /** |
345 * Hide or reveal the ActionMode. Note that this only has visible | 338 * Hide or reveal the ActionMode. Note that this only has visible |
346 * side-effects if the underlying ActionMode supports hiding. | 339 * side-effects if the underlying ActionMode supports hiding. |
347 * @param hide whether to hide or show the ActionMode. | 340 * @param hide whether to hide or show the ActionMode. |
348 */ | 341 */ |
349 void hideActionMode(boolean hide) { | 342 void hideActionMode(boolean hide) { |
350 if (!canHideActionMode()) return; | 343 if (!canHideActionMode()) return; |
351 if (mHidden == hide) return; | 344 if (mHidden == hide) return; |
352 mHidden = hide; | 345 mHidden = hide; |
353 if (mHidden) { | 346 if (mHidden) { |
354 mRepeatingHideRunnable.run(); | 347 mRepeatingHideRunnable.run(); |
355 } else { | 348 } else { |
356 mHidden = false; | 349 mHidden = false; |
357 mView.removeCallbacks(mRepeatingHideRunnable); | 350 mView.removeCallbacks(mRepeatingHideRunnable); |
358 hideActionModeTemporarily(SHOW_DELAY_MS); | 351 hideActionModeTemporarily(SHOW_DELAY_MS); |
359 if (mPendingInvalidateContentRect) { | |
360 mPendingInvalidateContentRect = false; | |
361 invalidateContentRect(); | |
362 } | |
363 } | 352 } |
364 } | 353 } |
365 | 354 |
366 /** | 355 /** |
367 * @see ActionMode#hide(long) | 356 * @see ActionMode#hide(long) |
368 */ | 357 */ |
369 private void hideActionModeTemporarily(long duration) { | 358 private void hideActionModeTemporarily(long duration) { |
370 assert canHideActionMode(); | 359 assert canHideActionMode(); |
371 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | 360 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
372 if (isActionModeValid()) mActionMode.hide(duration); | 361 if (isActionModeValid()) mActionMode.hide(duration); |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 mIsInsertion = insertion; | 892 mIsInsertion = insertion; |
904 } | 893 } |
905 | 894 |
906 private boolean isShareAvailable() { | 895 private boolean isShareAvailable() { |
907 Intent intent = new Intent(Intent.ACTION_SEND); | 896 Intent intent = new Intent(Intent.ACTION_SEND); |
908 intent.setType("text/plain"); | 897 intent.setType("text/plain"); |
909 return mContext.getPackageManager().queryIntentActivities(intent, | 898 return mContext.getPackageManager().queryIntentActivities(intent, |
910 PackageManager.MATCH_DEFAULT_ONLY).size() > 0; | 899 PackageManager.MATCH_DEFAULT_ONLY).size() > 0; |
911 } | 900 } |
912 } | 901 } |
OLD | NEW |