Skip to content

Commit

Permalink
[SendTabToSelf] Add icon and separator to menu item on desktop
Browse files Browse the repository at this point in the history
Add icon to the left of the item string.

Add separator accordingly to make send tab to self item
in a separate menu section.

Applying to tab context menu, content menu and omnibox menu.

Bug: 944696
Change-Id: I0df9d3e7e61fc1dc02e35033a2ce1301aeb861cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1534653
Reviewed-by: Jeffrey Cohen <jeffreycohen@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645955}
  • Loading branch information
Tina Wang authored and Commit Bot committed Mar 29, 2019
1 parent 23604c6 commit f1dad3c
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1359,8 +1359,11 @@ void RenderViewContextMenu::AppendPageItems() {
GetBrowser()->tab_strip_model()->GetActiveWebContents())) {
base::RecordAction(
UserMetricsAction("ViewContextMenu_SendTabToSelf_Shown"));
menu_model_.AddItemWithStringId(IDC_SEND_TAB_TO_SELF,
IDS_CONTEXT_MENU_SEND_TAB_TO_SELF);
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
menu_model_.AddItemWithStringIdAndIcon(IDC_SEND_TAB_TO_SELF,
IDS_CONTEXT_MENU_SEND_TAB_TO_SELF,
*send_tab_to_self::GetImageSkia());
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
}
if (TranslateService::IsTranslatableURL(params_.page_url)) {
std::unique_ptr<translate::TranslatePrefs> prefs(
Expand Down
12 changes: 12 additions & 0 deletions chrome/browser/send_tab_to_self/send_tab_to_self_desktop_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include "components/send_tab_to_self/send_tab_to_self_sync_service.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/native_theme/native_theme.h"
#include "ui/resources/grit/ui_resources.h"
#include "url/gurl.h"

namespace send_tab_to_self {
Expand All @@ -37,4 +40,13 @@ void CreateNewEntry(content::WebContents* tab, Profile* profile) {
}
}

gfx::ImageSkia* GetImageSkia() {
const ui::NativeTheme* native_theme =
ui::NativeTheme::GetInstanceForNativeUi();
bool is_dark = native_theme && native_theme->SystemDarkModeEnabled();
int resource_id = is_dark ? IDR_SEND_TAB_TO_SELF_ICON_DARK
: IDR_SEND_TAB_TO_SELF_ICON_LIGHT;
return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
}

} // namespace send_tab_to_self
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ namespace content {
class WebContents;
}

namespace gfx {
class ImageSkia;
}

namespace send_tab_to_self {

// Add a new entry to SendTabToSelfModel when user click "Share to my devices"
// option
// TODO(crbug.com/945386): Flip parameter order.
void CreateNewEntry(content::WebContents* tab, Profile* profile);

// Get the icon for send tab to self menu item.
gfx::ImageSkia* GetImageSkia();

} // namespace send_tab_to_self

#endif // CHROME_BROWSER_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_DESKTOP_UTIL_H_
6 changes: 4 additions & 2 deletions chrome/browser/ui/tabs/tab_menu_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ void TabMenuModel::Build(TabStripModel* tab_strip, int index) {
if (send_tab_to_self::ShouldOfferFeature(
tab_strip->profile(), tab_strip->GetWebContentsAt(index))) {
base::RecordAction(UserMetricsAction("TabContextMenu_SendTabToSelf_Shown"));
AddItemWithStringId(TabStripModel::CommandSendTabToSelf,
IDS_CONTEXT_MENU_SEND_TAB_TO_SELF);
AddSeparator(ui::NORMAL_SEPARATOR);
AddItemWithStringIdAndIcon(TabStripModel::CommandSendTabToSelf,
IDS_CONTEXT_MENU_SEND_TAB_TO_SELF,
*send_tab_to_self::GetImageSkia());
}
AddSeparator(ui::NORMAL_SEPARATOR);
AddItem(TabStripModel::CommandCloseTab,
Expand Down
12 changes: 9 additions & 3 deletions chrome/browser/ui/views/omnibox/omnibox_view_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/selection_model.h"
#include "ui/gfx/text_elider.h"
#include "ui/gfx/text_utils.h"
Expand Down Expand Up @@ -1718,10 +1719,15 @@ void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) {
location_bar_view_->profile(),
location_bar_view_->GetWebContents())) {
RecordSendTabToSelf(UmaEnumOmniboxSendTabToSelf::kShowItem);
int position = menu_contents->GetIndexOfCommandId(IDS_APP_UNDO);
menu_contents->InsertSeparatorAt(position, ui::NORMAL_SEPARATOR);
menu_contents->InsertItemWithStringIdAt(position, IDC_SEND_TAB_TO_SELF,
int index = menu_contents->GetIndexOfCommandId(IDS_APP_UNDO);
// Add a separator if this is not the first item.
if (index)
menu_contents->InsertSeparatorAt(index++, ui::NORMAL_SEPARATOR);
menu_contents->InsertItemWithStringIdAt(index, IDC_SEND_TAB_TO_SELF,
IDS_CONTEXT_MENU_SEND_TAB_TO_SELF);
menu_contents->SetIcon(index,
gfx::Image(*send_tab_to_self::GetImageSkia()));
menu_contents->InsertSeparatorAt(++index, ui::NORMAL_SEPARATOR);
}

int paste_position = menu_contents->GetIndexOfCommandId(IDS_APP_PASTE);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions ui/resources/ui_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
<structure type="chrome_scaled_image" name="IDR_EASY_UNLOCK_UNLOCKED_PRESSED" file="common/easy_unlock_unlocked_pressed.png" />
<structure type="chrome_scaled_image" name="IDR_FOLDER_CLOSED" file="common/folder_closed.png" />
<structure type="chrome_scaled_image" name="IDR_FOLDER_CLOSED_RTL" file="common/folder_closed_rtl.png" />
<structure type="chrome_scaled_image" name="IDR_SEND_TAB_TO_SELF_ICON_LIGHT" file="common/send_tab_to_self_light_mode_icon.png" />
<structure type="chrome_scaled_image" name="IDR_SEND_TAB_TO_SELF_ICON_DARK" file="common/send_tab_to_self_dark_mode_icon.png" />
<if expr="toolkit_views and not is_macosx">
<structure type="chrome_scaled_image" name="IDR_NOTIFICATION_SETTINGS" file="common/notification_settings.png"/>
</if>
Expand Down

0 comments on commit f1dad3c

Please sign in to comment.