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

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

Issue 2904033002: Use hasSelection() instead of mHasSelection (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.ClipData; 10 import android.content.ClipData;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 /** 226 /**
227 * Show (activate) android action mode by starting it. 227 * Show (activate) android action mode by starting it.
228 * 228 *
229 * <p>Action mode in floating mode is tried first, and then falls back to 229 * <p>Action mode in floating mode is tried first, and then falls back to
230 * a normal one. 230 * a normal one.
231 * <p> If the action mode cannot be created the selection is cleared. 231 * <p> If the action mode cannot be created the selection is cleared.
232 */ 232 */
233 public void showActionModeOrClearOnFailure() { 233 public void showActionModeOrClearOnFailure() {
234 mPendingShowActionMode = false; 234 mPendingShowActionMode = false;
235 235
236 if (!isActionModeSupported() || !mHasSelection) return; 236 if (!isActionModeSupported() || !hasSelection()) return;
237 237
238 // Just refresh the view if action mode already exists. 238 // Just refresh the view if action mode already exists.
239 if (isActionModeValid()) { 239 if (isActionModeValid()) {
240 // Try/catch necessary for framework bug, crbug.com/446717. 240 // Try/catch necessary for framework bug, crbug.com/446717.
241 try { 241 try {
242 mActionMode.invalidate(); 242 mActionMode.invalidate();
243 } catch (NullPointerException e) { 243 } catch (NullPointerException e) {
244 Log.w(TAG, "Ignoring NPE from ActionMode.invalidate() as workaro und for L", e); 244 Log.w(TAG, "Ignoring NPE from ActionMode.invalidate() as workaro und for L", e);
245 } 245 }
246 hideActionMode(false); 246 hideActionMode(false);
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 return isAllowedByClient && isShareAvailable(); 902 return isAllowedByClient && isShareAvailable();
903 } 903 }
904 return isAllowedByClient; 904 return isAllowedByClient;
905 } 905 }
906 906
907 @Override 907 @Override
908 public void onReceivedProcessTextResult(int resultCode, Intent data) { 908 public void onReceivedProcessTextResult(int resultCode, Intent data) {
909 if (mWebContents == null || resultCode != Activity.RESULT_OK || data == null) return; 909 if (mWebContents == null || resultCode != Activity.RESULT_OK || data == null) return;
910 910
911 // Do not handle the result if no text is selected or current selection is not editable. 911 // Do not handle the result if no text is selected or current selection is not editable.
912 if (!mHasSelection || !isSelectionEditable()) return; 912 if (!hasSelection() || !isSelectionEditable()) return;
913 913
914 CharSequence result = data.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEX T); 914 CharSequence result = data.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEX T);
915 if (result != null) { 915 if (result != null) {
916 // TODO(hush): Use a variant of replace that re-selects the replaced text. 916 // TODO(hush): Use a variant of replace that re-selects the replaced text.
917 // crbug.com/546710 917 // crbug.com/546710
918 mWebContents.replace(result.toString()); 918 mWebContents.replace(result.toString());
919 } 919 }
920 } 920 }
921 921
922 void restoreSelectionPopupsIfNecessary() { 922 void restoreSelectionPopupsIfNecessary() {
923 if (mHasSelection && !isActionModeValid()) { 923 if (hasSelection() && !isActionModeValid()) {
924 showActionModeOrClearOnFailure(); 924 showActionModeOrClearOnFailure();
925 } 925 }
926 } 926 }
927 927
928 // All coordinates are in DIP. 928 // All coordinates are in DIP.
929 @CalledByNative 929 @CalledByNative
930 private void onSelectionEvent(int eventType, int left, int top, int right, i nt bottom) { 930 private void onSelectionEvent(int eventType, int left, int top, int right, i nt bottom) {
931 // Ensure the provided selection coordinates form a non-empty rect, as r equired by 931 // Ensure the provided selection coordinates form a non-empty rect, as r equired by
932 // the selection action mode. 932 // the selection action mode.
933 if (left == right) ++right; 933 if (left == right) ++right;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 /** 1093 /**
1094 * @return Whether the page has an active, touch-controlled selection region . 1094 * @return Whether the page has an active, touch-controlled selection region .
1095 */ 1095 */
1096 @VisibleForTesting 1096 @VisibleForTesting
1097 public boolean hasSelection() { 1097 public boolean hasSelection() {
1098 return mHasSelection; 1098 return mHasSelection;
1099 } 1099 }
1100 1100
1101 @Override 1101 @Override
1102 public String getSelectedText() { 1102 public String getSelectedText() {
1103 return mHasSelection ? mLastSelectedText : ""; 1103 return hasSelection() ? mLastSelectedText : "";
1104 } 1104 }
1105 1105
1106 private boolean isShareAvailable() { 1106 private boolean isShareAvailable() {
1107 Intent intent = new Intent(Intent.ACTION_SEND); 1107 Intent intent = new Intent(Intent.ACTION_SEND);
1108 intent.setType("text/plain"); 1108 intent.setType("text/plain");
1109 return mContext.getPackageManager().queryIntentActivities(intent, 1109 return mContext.getPackageManager().queryIntentActivities(intent,
1110 PackageManager.MATCH_DEFAULT_ONLY).size() > 0; 1110 PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
1111 } 1111 }
1112 1112
1113 // TODO(timav): Use |TextClassifier| instead of |Object| after we switch to Android SDK 26. 1113 // TODO(timav): Use |TextClassifier| instead of |Object| after we switch to Android SDK 26.
(...skipping 20 matching lines...) Expand all
1134 */ 1134 */
1135 public Object getCustomTextClassifier() { 1135 public Object getCustomTextClassifier() {
1136 return mSelectionClient == null ? null : mSelectionClient.getCustomTextC lassifier(); 1136 return mSelectionClient == null ? null : mSelectionClient.getCustomTextC lassifier();
1137 } 1137 }
1138 1138
1139 // The callback class that delivers result from a SmartSelectionClient. 1139 // The callback class that delivers result from a SmartSelectionClient.
1140 private class SmartSelectionCallback implements SmartSelectionProvider.Resul tCallback { 1140 private class SmartSelectionCallback implements SmartSelectionProvider.Resul tCallback {
1141 @Override 1141 @Override
1142 public void onClassified(SmartSelectionProvider.Result result) { 1142 public void onClassified(SmartSelectionProvider.Result result) {
1143 // If the selection does not exist any more, discard |result|. 1143 // If the selection does not exist any more, discard |result|.
1144 if (!mHasSelection) { 1144 if (!hasSelection()) {
1145 assert !mHidden; 1145 assert !mHidden;
1146 assert mClassificationResult == null; 1146 assert mClassificationResult == null;
1147 mPendingShowActionMode = false; 1147 mPendingShowActionMode = false;
1148 return; 1148 return;
1149 } 1149 }
1150 1150
1151 // Do not allow classifier to shorten the selection. If the suggeste d selection is 1151 // Do not allow classifier to shorten the selection. If the suggeste d selection is
1152 // smaller than the original we throw away classification result and show the menu. 1152 // smaller than the original we throw away classification result and show the menu.
1153 // TODO(amaralp): This was added to fix the SelectAll problem in 1153 // TODO(amaralp): This was added to fix the SelectAll problem in
1154 // http://crbug.com/714106. Once we know the cause of the original s election we can 1154 // http://crbug.com/714106. Once we know the cause of the original s election we can
(...skipping 25 matching lines...) Expand all
1180 if (mPendingShowActionMode) return; 1180 if (mPendingShowActionMode) return;
1181 } 1181 }
1182 1182
1183 // Rely on this method to clear |mHidden| and unhide the action mode . 1183 // Rely on this method to clear |mHidden| and unhide the action mode .
1184 showActionModeOrClearOnFailure(); 1184 showActionModeOrClearOnFailure();
1185 } 1185 }
1186 }; 1186 };
1187 1187
1188 private native void nativeInit(WebContents webContents); 1188 private native void nativeInit(WebContents webContents);
1189 } 1189 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698