-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android][dropdown 1/n] - Refactor Text Selection Menu Population
The previous text selection menu logic for populating items was spread out, hard to understand, and heavily reliant on Android menu APIs. It was also used in two different places SelectionPopupControllerImpl & FloatingPastePopupMenu. Given that we are now planning to add a third menu type (see attached bug), it would be good to somehow centralize this logic while also making it generic enough for use with any menu rendering API. This means doing a few things. 1. Decoupling the menu item provision from the Android menu APIs. 2. Refactoring additional menu item providers (i.e. autofill) to be more generic and providing them to the SelectionPopupController. 3. Refactoring SelectionPopupControllerImpl && FloatingPastePopupMenu to use these new APIs. All of this will need to be done while ensuring the current behavior does not change. This means when and in what order items show up should remain the same. Follow up CLs starting at https://chromium-review.googlesource.com/c/chromium/src/+/4507323 will be used to implement a drop-down style menu that will leverage this refactor. Bug: 1428022 Change-Id: Ic7ad00eb67275b9e4ecb8c8b1324bffb48e61b42 Low-Coverage-Reason: No logic changes in the classes mentioned, only a refactor. Also SelectionPopupControllerImpl has existing test coverage in SelectionPopupControllerTest (unit) & ContentTextSelectionTest (integration) which have been ran and pass locally. Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4547564 Reviewed-by: Peter Beverloo <peter@chromium.org> Reviewed-by: Peter Conn <peconn@chromium.org> Commit-Queue: Wayne Jackson Jr. <wbjacksonjr@chromium.org> Reviewed-by: David Trainor <dtrainor@chromium.org> Reviewed-by: Colin Blundell <blundell@chromium.org> Cr-Commit-Position: refs/heads/main@{#1152130}
- Loading branch information
Wayne Jackson Jr
authored and
Chromium LUCI CQ
committed
Jun 1, 2023
1 parent
cbba035
commit 2a2f22a
Showing
26 changed files
with
1,049 additions
and
587 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 0 additions & 64 deletions
64
...utofill/browser/java/src/org/chromium/components/autofill/AutofillActionModeCallback.java
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
.../browser/java/src/org/chromium/components/autofill/AutofillSelectionMenuItemProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.components.autofill; | ||
|
||
import android.content.Context; | ||
import android.os.Build; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
|
||
import org.chromium.content_public.browser.AdditionalSelectionMenuItemProvider; | ||
import org.chromium.content_public.browser.SelectionMenuItem; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* The class to provide autofill selection context menu items. To match the Android native view | ||
* behavior, the autofill context menu only appears when there is no text selected. | ||
*/ | ||
public class AutofillSelectionMenuItemProvider implements AdditionalSelectionMenuItemProvider { | ||
private final AutofillProvider mAutofillProvider; | ||
private final int mAutofillMenuItemTitle; | ||
|
||
// using getIdentifier to work around not-exposed framework resource ID | ||
@SuppressWarnings("DiscouragedApi") | ||
public AutofillSelectionMenuItemProvider(Context context, AutofillProvider autofillProvider) { | ||
mAutofillProvider = autofillProvider; | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { | ||
mAutofillMenuItemTitle = android.R.string.autofill; | ||
} else { | ||
// The string resource was not made public until O MR1, so on O we look it up by name. | ||
mAutofillMenuItemTitle = | ||
context.getResources().getIdentifier("autofill", "string", "android"); | ||
} | ||
} | ||
|
||
@Override | ||
public List<SelectionMenuItem> getItems() { | ||
List<SelectionMenuItem> autofillItems = new ArrayList<>(); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
if (mAutofillMenuItemTitle != 0 && mAutofillProvider.shouldQueryAutofillSuggestion()) { | ||
SelectionMenuItem autofillItem = | ||
new SelectionMenuItem.Builder(mAutofillMenuItemTitle) | ||
.setId(android.R.id.autofill) | ||
.setOrderInCategory(Menu.CATEGORY_SECONDARY) | ||
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_NEVER | ||
| MenuItem.SHOW_AS_ACTION_WITH_TEXT) | ||
.setClickListener(v -> mAutofillProvider.queryAutofillSuggestion()) | ||
.build(); | ||
autofillItems.add(autofillItem); | ||
} | ||
} | ||
return autofillItems; | ||
} | ||
|
||
@Override | ||
public void onMenuDestroyed() { | ||
// no-op | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 0 additions & 79 deletions
79
content/public/android/java/res/menu/select_action_menu.xml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<!-- Selection Menu Group IDs --> | ||
<item type="id" name="select_action_menu_assist_items" /> | ||
<item type="id" name="select_action_menu_default_items" /> | ||
<item type="id" name="select_action_menu_text_processing_items" /> | ||
|
||
<!-- Selection Menu Items --> | ||
<item type="id" name="select_action_menu_cut" /> | ||
<item type="id" name="select_action_menu_copy" /> | ||
<item type="id" name="select_action_menu_paste" /> | ||
<item type="id" name="select_action_menu_share" /> | ||
<item type="id" name="select_action_menu_select_all" /> | ||
<item type="id" name="select_action_menu_paste_as_plain_text" /> | ||
<item type="id" name="select_action_menu_web_search" /> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.