| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.support.annotation.IntDef; | 7 import android.support.annotation.IntDef; |
| 8 import android.text.TextUtils; | 8 import android.text.TextUtils; |
| 9 | 9 |
| 10 import org.chromium.base.annotations.CalledByNative; | 10 import org.chromium.base.annotations.CalledByNative; |
| 11 import org.chromium.base.annotations.JNINamespace; | 11 import org.chromium.base.annotations.JNINamespace; |
| 12 import org.chromium.content_public.browser.WebContents; | 12 import org.chromium.content_public.browser.WebContents; |
| 13 import org.chromium.ui.base.WindowAndroid; | 13 import org.chromium.ui.base.WindowAndroid; |
| 14 import org.chromium.ui.touch_selection.SelectionEventType; | |
| 15 | 14 |
| 16 import java.lang.annotation.Retention; | 15 import java.lang.annotation.Retention; |
| 17 import java.lang.annotation.RetentionPolicy; | 16 import java.lang.annotation.RetentionPolicy; |
| 18 | 17 |
| 19 /** | 18 /** |
| 20 * A class that controls the classification of the textual selection. | 19 * A class that controls the classification of the textual selection. |
| 21 * It requests the selection together with its surrounding text from the focused
frame and sends it | 20 * It requests the selection together with its surrounding text from the focused
frame and sends it |
| 22 * to ContextSelectionProvider which does the classification itself. | 21 * to ContextSelectionProvider which does the classification itself. |
| 23 */ | 22 */ |
| 24 @JNINamespace("content") | 23 @JNINamespace("content") |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 assert nativeContextSelectionClient == mNativeContextSelectionClient; | 69 assert nativeContextSelectionClient == mNativeContextSelectionClient; |
| 71 mNativeContextSelectionClient = 0; | 70 mNativeContextSelectionClient = 0; |
| 72 mProvider.cancelAllRequests(); | 71 mProvider.cancelAllRequests(); |
| 73 } | 72 } |
| 74 | 73 |
| 75 // SelectionClient implementation | 74 // SelectionClient implementation |
| 76 @Override | 75 @Override |
| 77 public void onSelectionChanged(String selection) {} | 76 public void onSelectionChanged(String selection) {} |
| 78 | 77 |
| 79 @Override | 78 @Override |
| 80 public void onSelectionEvent(int eventType, float posXPix, float posYPix) { | 79 public void onSelectionEvent(int eventType, float posXPix, float posYPix) {} |
| 81 switch (eventType) { | |
| 82 case SelectionEventType.SELECTION_HANDLES_SHOWN: | |
| 83 // This event is sent when the long press is detected which caus
es | |
| 84 // selection to appear for the first time. Temporarily hiding th
e | |
| 85 // handles that happens e.g. during scroll does not affect this
event. | |
| 86 requestSurroundingText(SUGGEST_AND_CLASSIFY); | |
| 87 break; | |
| 88 | |
| 89 case SelectionEventType.SELECTION_HANDLES_CLEARED: | |
| 90 // The ActionMode should be stopped when this event comes. | |
| 91 cancelAllRequests(); | |
| 92 break; | |
| 93 | |
| 94 case SelectionEventType.SELECTION_HANDLE_DRAG_STOPPED: | |
| 95 // This event is sent after a user stopped dragging one of the | |
| 96 // selection handles, i.e. stopped modifying the selection. | |
| 97 requestSurroundingText(CLASSIFY); | |
| 98 break; | |
| 99 | |
| 100 default: | |
| 101 break; // ignore | |
| 102 } | |
| 103 } | |
| 104 | 80 |
| 105 @Override | 81 @Override |
| 106 public void showUnhandledTapUIIfNeeded(int x, int y) {} | 82 public void showUnhandledTapUIIfNeeded(int x, int y) {} |
| 107 | 83 |
| 108 @Override | 84 @Override |
| 109 public boolean sendsSelectionPopupUpdates() { | 85 public boolean requestSelectionPopupUpdates(boolean shouldSuggest) { |
| 86 requestSurroundingText(shouldSuggest ? SUGGEST_AND_CLASSIFY : CLASSIFY); |
| 110 return true; | 87 return true; |
| 111 } | 88 } |
| 112 | 89 |
| 113 private void cancelAllRequests() { | 90 @Override |
| 91 public void cancelAllRequests() { |
| 114 if (mNativeContextSelectionClient != 0) { | 92 if (mNativeContextSelectionClient != 0) { |
| 115 nativeCancelAllRequests(mNativeContextSelectionClient); | 93 nativeCancelAllRequests(mNativeContextSelectionClient); |
| 116 } | 94 } |
| 117 | 95 |
| 118 mProvider.cancelAllRequests(); | 96 mProvider.cancelAllRequests(); |
| 119 } | 97 } |
| 120 | 98 |
| 121 private void requestSurroundingText(@RequestType int callbackData) { | 99 private void requestSurroundingText(@RequestType int callbackData) { |
| 122 if (mNativeContextSelectionClient == 0) { | 100 if (mNativeContextSelectionClient == 0) { |
| 123 onSurroundingTextReceived(callbackData, "", 0, 0); | 101 onSurroundingTextReceived(callbackData, "", 0, 0); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 148 assert false : "Unexpected callback data"; | 126 assert false : "Unexpected callback data"; |
| 149 break; | 127 break; |
| 150 } | 128 } |
| 151 } | 129 } |
| 152 | 130 |
| 153 private native long nativeInit(WebContents webContents); | 131 private native long nativeInit(WebContents webContents); |
| 154 private native void nativeRequestSurroundingText( | 132 private native void nativeRequestSurroundingText( |
| 155 long nativeContextSelectionClient, int numExtraCharacters, int callb
ackData); | 133 long nativeContextSelectionClient, int numExtraCharacters, int callb
ackData); |
| 156 private native void nativeCancelAllRequests(long nativeContextSelectionClien
t); | 134 private native void nativeCancelAllRequests(long nativeContextSelectionClien
t); |
| 157 } | 135 } |
| OLD | NEW |