Commit ffe1fe8d authored by Shimi Zhang's avatar Shimi Zhang Committed by Commit Bot

[Android] Add Java conterpart of MenuSourceType

Doing so for adding logging for Smart Selection http://crrev/c/720270.

We need to distinguish the showSelectionMenu() event to know if it
comes from selection expansion/reset/dragging etc.

Bug: 731644
Change-Id: I5d9e69c4fcecd60ed2e92268cd2f5c9b91bc5b28
Reviewed-on: https://chromium-review.googlesource.com/723784Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarChris Blume <cblume@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Shimi Zhang <ctzsm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510208}
parent 70155edf
...@@ -161,7 +161,7 @@ bool SelectionPopupController::ShowSelectionMenu( ...@@ -161,7 +161,7 @@ bool SelectionPopupController::ShowSelectionMenu(
params.selection_rect.right(), params.selection_rect.right(),
params.selection_rect.bottom() + handle_height, params.is_editable, params.selection_rect.bottom() + handle_height, params.is_editable,
is_password_type, jselected_text, can_select_all, can_edit_richly, is_password_type, jselected_text, can_select_all, can_edit_richly,
should_suggest, from_selection_adjustment); should_suggest, params.source_type);
return true; return true;
} }
......
...@@ -48,6 +48,7 @@ import org.chromium.content_public.browser.ActionModeCallbackHelper; ...@@ -48,6 +48,7 @@ import org.chromium.content_public.browser.ActionModeCallbackHelper;
import org.chromium.content_public.browser.SelectionClient; import org.chromium.content_public.browser.SelectionClient;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.DeviceFormFactor; import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.base.MenuSourceType;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.touch_selection.SelectionEventType; import org.chromium.ui.touch_selection.SelectionEventType;
...@@ -260,7 +261,7 @@ public class SelectionPopupController extends ActionModeCallbackHelper { ...@@ -260,7 +261,7 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
@CalledByNative @CalledByNative
public void showSelectionMenu(int left, int top, int right, int bottom, boolean isEditable, public void showSelectionMenu(int left, int top, int right, int bottom, boolean isEditable,
boolean isPasswordType, String selectionText, boolean canSelectAll, boolean isPasswordType, String selectionText, boolean canSelectAll,
boolean canRichlyEdit, boolean shouldSuggest, boolean fromSelectionAdjustment) { boolean canRichlyEdit, boolean shouldSuggest, @MenuSourceType int sourceType) {
mSelectionRect.set(left, top, right, bottom); mSelectionRect.set(left, top, right, bottom);
mEditable = isEditable; mEditable = isEditable;
mLastSelectedText = selectionText; mLastSelectedText = selectionText;
...@@ -271,7 +272,7 @@ public class SelectionPopupController extends ActionModeCallbackHelper { ...@@ -271,7 +272,7 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
mUnselectAllOnDismiss = true; mUnselectAllOnDismiss = true;
if (hasSelection()) { if (hasSelection()) {
// From selection adjustment, show menu directly. // From selection adjustment, show menu directly.
if (fromSelectionAdjustment) { if (sourceType == MenuSourceType.MENU_SOURCE_ADJUST_SELECTION) {
showActionModeOrClearOnFailure(); showActionModeOrClearOnFailure();
return; return;
} }
......
...@@ -32,6 +32,7 @@ import org.chromium.base.test.util.Feature; ...@@ -32,6 +32,7 @@ import org.chromium.base.test.util.Feature;
import org.chromium.content_public.browser.SelectionClient; import org.chromium.content_public.browser.SelectionClient;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.testing.local.LocalRobolectricTestRunner; import org.chromium.testing.local.LocalRobolectricTestRunner;
import org.chromium.ui.base.MenuSourceType;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
/** /**
...@@ -130,7 +131,7 @@ public class SelectionPopupControllerTest { ...@@ -130,7 +131,7 @@ public class SelectionPopupControllerTest {
mController.showSelectionMenu(0, 0, 0, 0, /* isEditable = */ true, mController.showSelectionMenu(0, 0, 0, 0, /* isEditable = */ true,
/* isPasswordType = */ false, AMPHITHEATRE, /* canSelectAll = */ true, /* isPasswordType = */ false, AMPHITHEATRE, /* canSelectAll = */ true,
/* canRichlyEdit = */ true, /* shouldSuggest = */ true, /* canRichlyEdit = */ true, /* shouldSuggest = */ true,
/* fromSelectionAdjustment = */ false); MenuSourceType.MENU_SOURCE_LONG_PRESS);
// adjustSelectionByCharacterOffset() should be called. // adjustSelectionByCharacterOffset() should be called.
order.verify(mWebContents) order.verify(mWebContents)
...@@ -145,7 +146,7 @@ public class SelectionPopupControllerTest { ...@@ -145,7 +146,7 @@ public class SelectionPopupControllerTest {
/* isPasswordType = */ false, AMPHITHEATRE_FULL, /* isPasswordType = */ false, AMPHITHEATRE_FULL,
/* canSelectAll = */ true, /* canSelectAll = */ true,
/* canRichlyEdit = */ true, /* shouldSuggest = */ true, /* canRichlyEdit = */ true, /* shouldSuggest = */ true,
/* fromSelectionAdjustment = */ true); MenuSourceType.MENU_SOURCE_ADJUST_SELECTION);
order.verify(mView).startActionMode( order.verify(mView).startActionMode(
isA(FloatingActionModeCallback.class), eq(ActionMode.TYPE_FLOATING)); isA(FloatingActionModeCallback.class), eq(ActionMode.TYPE_FLOATING));
...@@ -175,7 +176,7 @@ public class SelectionPopupControllerTest { ...@@ -175,7 +176,7 @@ public class SelectionPopupControllerTest {
mController.showSelectionMenu(0, 0, 0, 0, /* isEditable = */ true, mController.showSelectionMenu(0, 0, 0, 0, /* isEditable = */ true,
/* isPasswordType = */ false, AMPHITHEATRE, /* canSelectAll = */ true, /* isPasswordType = */ false, AMPHITHEATRE, /* canSelectAll = */ true,
/* canRichlyEdit = */ true, /* shouldSuggest = */ true, /* canRichlyEdit = */ true, /* shouldSuggest = */ true,
/* fromSelectionAdjustment = */ false); MenuSourceType.MENU_SOURCE_LONG_PRESS);
// adjustSelectionByCharacterOffset() should be called. // adjustSelectionByCharacterOffset() should be called.
order.verify(mWebContents) order.verify(mWebContents)
...@@ -187,7 +188,7 @@ public class SelectionPopupControllerTest { ...@@ -187,7 +188,7 @@ public class SelectionPopupControllerTest {
mController.showSelectionMenu(0, 0, 0, 0, /* isEditable = */ true, mController.showSelectionMenu(0, 0, 0, 0, /* isEditable = */ true,
/* isPasswordType = */ false, MOUNTAIN, /* canSelectAll = */ true, /* isPasswordType = */ false, MOUNTAIN, /* canSelectAll = */ true,
/* canRichlyEdit = */ true, /* shouldSuggest = */ true, /* canRichlyEdit = */ true, /* shouldSuggest = */ true,
/* fromSelectionAdjustment = */ false); MenuSourceType.MENU_SOURCE_LONG_PRESS);
order.verify(mWebContents) order.verify(mWebContents)
.adjustSelectionByCharacterOffset(newResult.startAdjust, newResult.endAdjust, true); .adjustSelectionByCharacterOffset(newResult.startAdjust, newResult.endAdjust, true);
assertFalse(mController.isActionModeValid()); assertFalse(mController.isActionModeValid());
...@@ -200,7 +201,7 @@ public class SelectionPopupControllerTest { ...@@ -200,7 +201,7 @@ public class SelectionPopupControllerTest {
/* isPasswordType = */ false, AMPHITHEATRE_FULL, /* isPasswordType = */ false, AMPHITHEATRE_FULL,
/* canSelectAll = */ true, /* canSelectAll = */ true,
/* canRichlyEdit = */ true, /* shouldSuggest = */ true, /* canRichlyEdit = */ true, /* shouldSuggest = */ true,
/* fromSelectionAdjustment = */ true); MenuSourceType.MENU_SOURCE_ADJUST_SELECTION);
SelectionClient.Result returnResult = mController.getClassificationResult(); SelectionClient.Result returnResult = mController.getClassificationResult();
assertEquals(-21, returnResult.startAdjust); assertEquals(-21, returnResult.startAdjust);
...@@ -212,7 +213,7 @@ public class SelectionPopupControllerTest { ...@@ -212,7 +213,7 @@ public class SelectionPopupControllerTest {
/* isPasswordType = */ false, MOUNTAIN_FULL, /* isPasswordType = */ false, MOUNTAIN_FULL,
/* canSelectAll = */ true, /* canSelectAll = */ true,
/* canRichlyEdit = */ true, /* shouldSuggest = */ true, /* canRichlyEdit = */ true, /* shouldSuggest = */ true,
/* fromSelectionAdjustment = */ true); MenuSourceType.MENU_SOURCE_ADJUST_SELECTION);
order.verify(mView).startActionMode( order.verify(mView).startActionMode(
isA(FloatingActionModeCallback.class), eq(ActionMode.TYPE_FLOATING)); isA(FloatingActionModeCallback.class), eq(ActionMode.TYPE_FLOATING));
...@@ -234,13 +235,13 @@ public class SelectionPopupControllerTest { ...@@ -234,13 +235,13 @@ public class SelectionPopupControllerTest {
mController.showSelectionMenu(0, 0, 0, 0, /* isEditable = */ true, mController.showSelectionMenu(0, 0, 0, 0, /* isEditable = */ true,
/* isPasswordType = */ false, AMPHITHEATRE, /* canSelectAll = */ true, /* isPasswordType = */ false, AMPHITHEATRE, /* canSelectAll = */ true,
/* canRichlyEdit = */ true, /* shouldSuggest = */ true, /* canRichlyEdit = */ true, /* shouldSuggest = */ true,
/* fromSelectionAdjustment = */ false); MenuSourceType.MENU_SOURCE_LONG_PRESS);
// Another long press triggered showSelectionMenu() call. // Another long press triggered showSelectionMenu() call.
mController.showSelectionMenu(0, 0, 0, 0, /* isEditable = */ true, mController.showSelectionMenu(0, 0, 0, 0, /* isEditable = */ true,
/* isPasswordType = */ false, MOUNTAIN, /* canSelectAll = */ true, /* isPasswordType = */ false, MOUNTAIN, /* canSelectAll = */ true,
/* canRichlyEdit = */ true, /* shouldSuggest = */ true, /* canRichlyEdit = */ true, /* shouldSuggest = */ true,
/* fromSelectionAdjustment = */ false); MenuSourceType.MENU_SOURCE_LONG_PRESS);
// Then we done with the first classification. // Then we done with the first classification.
mController.getResultCallback().onClassified(result); mController.getResultCallback().onClassified(result);
...@@ -263,7 +264,7 @@ public class SelectionPopupControllerTest { ...@@ -263,7 +264,7 @@ public class SelectionPopupControllerTest {
/* isPasswordType = */ false, AMPHITHEATRE_FULL, /* isPasswordType = */ false, AMPHITHEATRE_FULL,
/* canSelectAll = */ true, /* canSelectAll = */ true,
/* canRichlyEdit = */ true, /* shouldSuggest = */ true, /* canRichlyEdit = */ true, /* shouldSuggest = */ true,
/* fromSelectionAdjustment = */ true); MenuSourceType.MENU_SOURCE_ADJUST_SELECTION);
SelectionClient.Result returnResult = mController.getClassificationResult(); SelectionClient.Result returnResult = mController.getClassificationResult();
assertEquals(-21, returnResult.startAdjust); assertEquals(-21, returnResult.startAdjust);
...@@ -275,7 +276,7 @@ public class SelectionPopupControllerTest { ...@@ -275,7 +276,7 @@ public class SelectionPopupControllerTest {
/* isPasswordType = */ false, MOUNTAIN_FULL, /* isPasswordType = */ false, MOUNTAIN_FULL,
/* canSelectAll = */ true, /* canSelectAll = */ true,
/* canRichlyEdit = */ true, /* shouldSuggest = */ true, /* canRichlyEdit = */ true, /* shouldSuggest = */ true,
/* fromSelectionAdjustment = */ true); MenuSourceType.MENU_SOURCE_ADJUST_SELECTION);
order.verify(mView).startActionMode( order.verify(mView).startActionMode(
isA(FloatingActionModeCallback.class), eq(ActionMode.TYPE_FLOATING)); isA(FloatingActionModeCallback.class), eq(ActionMode.TYPE_FLOATING));
......
...@@ -105,6 +105,7 @@ java_cpp_enum("java_enums_srcjar") { ...@@ -105,6 +105,7 @@ java_cpp_enum("java_enums_srcjar") {
"../base/ime/text_input_type.h", "../base/ime/text_input_type.h",
"../base/page_transition_types.h", "../base/page_transition_types.h",
"../base/touch/touch_device.h", "../base/touch/touch_device.h",
"../base/ui_base_types.h",
"../gfx/android/java_bitmap.h", "../gfx/android/java_bitmap.h",
"resources/resource_manager.h", "resources/resource_manager.h",
"resources/system_ui_resource_type.h", "resources/system_ui_resource_type.h",
......
...@@ -40,6 +40,8 @@ enum ModalType { ...@@ -40,6 +40,8 @@ enum ModalType {
}; };
// TODO(varunjain): Remove MENU_SOURCE_NONE (crbug.com/250964) // TODO(varunjain): Remove MENU_SOURCE_NONE (crbug.com/250964)
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.ui.base
enum MenuSourceType { enum MenuSourceType {
MENU_SOURCE_NONE = 0, MENU_SOURCE_NONE = 0,
MENU_SOURCE_MOUSE = 1, MENU_SOURCE_MOUSE = 1,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment