Commit afdb0d4c authored by Yasmin's avatar Yasmin Committed by Commit Bot

Implement right click menu item(s) for shared clipboard feature.

Bug: 992355
Change-Id: Iddb778995efaab12cd0ad87b18d5a2096f019c29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1755992
Commit-Queue: Yasmin Molazadeh <yasmo@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688483}
parent 30c7f73d
...@@ -59,6 +59,8 @@ ...@@ -59,6 +59,8 @@
#include "chrome/browser/send_tab_to_self/send_tab_to_self_util.h" #include "chrome/browser/send_tab_to_self/send_tab_to_self_util.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_context_menu_observer.h" #include "chrome/browser/sharing/click_to_call/click_to_call_context_menu_observer.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_utils.h" #include "chrome/browser/sharing/click_to_call/click_to_call_utils.h"
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_context_menu_observer.h"
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_utils.h"
#include "chrome/browser/spellchecker/spellcheck_service.h" #include "chrome/browser/spellchecker/spellcheck_service.h"
#include "chrome/browser/translate/chrome_translate_client.h" #include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/translate/translate_service.h" #include "chrome/browser/translate/translate_service.h"
...@@ -357,13 +359,15 @@ const std::map<int, int>& GetIdcToUmaMap(UmaEnumIdLookupType type) { ...@@ -357,13 +359,15 @@ const std::map<int, int>& GetIdcToUmaMap(UmaEnumIdLookupType type) {
{IDC_CONTENT_LINK_SEND_TAB_TO_SELF_SINGLE_TARGET, 105}, {IDC_CONTENT_LINK_SEND_TAB_TO_SELF_SINGLE_TARGET, 105},
{IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_SINGLE_DEVICE, 106}, {IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_SINGLE_DEVICE, 106},
{IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_MULTIPLE_DEVICES, 107}, {IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_MULTIPLE_DEVICES, 107},
{IDC_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_SINGLE_DEVICE, 108},
{IDC_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_MULTIPLE_DEVICES, 109},
// To add new items: // To add new items:
// - Add one more line above this comment block, using the UMA value // - Add one more line above this comment block, using the UMA value
// from the line below this comment block. // from the line below this comment block.
// - Increment the UMA value in that latter line. // - Increment the UMA value in that latter line.
// - Add the new item to the RenderViewContextMenuItem enum in // - Add the new item to the RenderViewContextMenuItem enum in
// tools/metrics/histograms/enums.xml. // tools/metrics/histograms/enums.xml.
{0, 108}}); {0, 110}});
// These UMA values are for the the ContextMenuOptionDesktop enum, used for // These UMA values are for the the ContextMenuOptionDesktop enum, used for
// the ContextMenu.SelectedOptionDesktop histograms. // the ContextMenu.SelectedOptionDesktop histograms.
...@@ -853,8 +857,10 @@ void RenderViewContextMenu::InitMenu() { ...@@ -853,8 +857,10 @@ void RenderViewContextMenu::InitMenu() {
if (editable) if (editable)
AppendEditableItems(); AppendEditableItems();
// Add shared clipboard menu item and copy items.
if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_COPY)) { if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_COPY)) {
DCHECK(!editable); DCHECK(!editable);
AppendSharedClipboardItems();
AppendCopyItem(); AppendCopyItem();
} }
...@@ -1573,6 +1579,18 @@ void RenderViewContextMenu::AppendCopyItem() { ...@@ -1573,6 +1579,18 @@ void RenderViewContextMenu::AppendCopyItem() {
IDS_CONTENT_CONTEXT_COPY); IDS_CONTENT_CONTEXT_COPY);
} }
void RenderViewContextMenu::AppendSharedClipboardItems() {
// Context menu item for shared clipboard on selected text.
if (ShouldOfferSharedClipboard(browser_context_, params_.selection_text)) {
if (!shared_clipboard_context_menu_observer_) {
shared_clipboard_context_menu_observer_ =
std::make_unique<SharedClipboardContextMenuObserver>(this);
observers_.AddObserver(shared_clipboard_context_menu_observer_.get());
}
shared_clipboard_context_menu_observer_->InitMenu(params_);
}
}
void RenderViewContextMenu::AppendPrintItem() { void RenderViewContextMenu::AppendPrintItem() {
if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) && if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) &&
(params_.media_type == WebContextMenuData::kMediaTypeNone || (params_.media_type == WebContextMenuData::kMediaTypeNone ||
......
...@@ -37,6 +37,7 @@ class AccessibilityLabelsMenuObserver; ...@@ -37,6 +37,7 @@ class AccessibilityLabelsMenuObserver;
class ClickToCallContextMenuObserver; class ClickToCallContextMenuObserver;
class PrintPreviewContextMenuObserver; class PrintPreviewContextMenuObserver;
class Profile; class Profile;
class SharedClipboardContextMenuObserver;
class SpellingMenuObserver; class SpellingMenuObserver;
class SpellingOptionsSubMenuObserver; class SpellingOptionsSubMenuObserver;
...@@ -173,6 +174,7 @@ class RenderViewContextMenu : public RenderViewContextMenuBase { ...@@ -173,6 +174,7 @@ class RenderViewContextMenu : public RenderViewContextMenuBase {
void AppendEditableItems(); void AppendEditableItems();
void AppendLanguageSettings(); void AppendLanguageSettings();
void AppendSpellingSuggestionItems(); void AppendSpellingSuggestionItems();
void AppendSharedClipboardItems();
// Returns true if the items were appended. This might not happen in all // Returns true if the items were appended. This might not happen in all
// cases, e.g. these are only appended if a screen reader is enabled. // cases, e.g. these are only appended if a screen reader is enabled.
bool AppendAccessibilityLabelsItems(); bool AppendAccessibilityLabelsItems();
...@@ -291,6 +293,10 @@ class RenderViewContextMenu : public RenderViewContextMenuBase { ...@@ -291,6 +293,10 @@ class RenderViewContextMenu : public RenderViewContextMenuBase {
std::unique_ptr<ClickToCallContextMenuObserver> std::unique_ptr<ClickToCallContextMenuObserver>
click_to_call_context_menu_observer_; click_to_call_context_menu_observer_;
// Shared clipboard menu observer.
std::unique_ptr<SharedClipboardContextMenuObserver>
shared_clipboard_context_menu_observer_;
DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu); DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu);
}; };
......
...@@ -51435,6 +51435,10 @@ Called by update_net_trust_anchors.py.--> ...@@ -51435,6 +51435,10 @@ Called by update_net_trust_anchors.py.-->
label="IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_SINGLE_DEVICE"/> label="IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_SINGLE_DEVICE"/>
<int value="107" <int value="107"
label="IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_MULTIPLE_DEVICES"/> label="IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_MULTIPLE_DEVICES"/>
<int value="108"
label="IDC_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_SINGLE_DEVICE"/>
<int value="109"
label="IDC_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_MULTIPLE_DEVICES"/>
</enum> </enum>
<enum name="ReopenTabPromoStepAtDismissal"> <enum name="ReopenTabPromoStepAtDismissal">
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