2019-09-18 19:58:00 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Samuel Attard <sattard@slack-corp.com>
|
|
|
|
Date: Wed, 28 Aug 2019 14:00:54 -0700
|
|
|
|
Subject: Revert "Cleanup: Remove Menu Subtitles/Sublabels"
|
|
|
|
|
|
|
|
This reverts commit 27a7b3648684204ccb16ede5cf3947579bd6c222.
|
|
|
|
|
|
|
|
diff --git a/chrome/browser/renderer_context_menu/mock_render_view_context_menu.cc b/chrome/browser/renderer_context_menu/mock_render_view_context_menu.cc
|
|
|
|
index 273666e278b3c6d1ac1e203f51a6a701366cdf2f..e9ab80665fd54b13c4211016e1607dc6cc5d53c2 100644
|
|
|
|
--- a/chrome/browser/renderer_context_menu/mock_render_view_context_menu.cc
|
|
|
|
+++ b/chrome/browser/renderer_context_menu/mock_render_view_context_menu.cc
|
|
|
|
@@ -157,7 +157,7 @@ void MockRenderViewContextMenu::AppendSubMenuItems(ui::MenuModel* model) {
|
|
|
|
sub_item.enabled = model->IsEnabledAt(i);
|
|
|
|
sub_item.checked = model->IsItemCheckedAt(i);
|
|
|
|
sub_item.hidden = false;
|
|
|
|
- sub_item.title = model->GetLabelAt(i);
|
|
|
|
+ sub_item.title = model->GetSublabelAt(i);
|
|
|
|
items_.push_back(sub_item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
diff --git a/chrome/browser/status_icons/status_icon_menu_model.cc b/chrome/browser/status_icons/status_icon_menu_model.cc
|
|
|
|
index 35d5182b293bcc5e013654f71e2366afef7f3e24..6deae7c286e9da72ab6a35d2e973da7fb32353d6 100644
|
|
|
|
--- a/chrome/browser/status_icons/status_icon_menu_model.cc
|
|
|
|
+++ b/chrome/browser/status_icons/status_icon_menu_model.cc
|
|
|
|
@@ -20,6 +20,7 @@ struct StatusIconMenuModel::ItemState {
|
|
|
|
bool is_dynamic;
|
|
|
|
ui::Accelerator accelerator;
|
|
|
|
base::string16 label;
|
|
|
|
+ base::string16 sublabel;
|
|
|
|
gfx::Image icon;
|
|
|
|
};
|
|
|
|
|
|
|
|
@@ -61,6 +62,13 @@ void StatusIconMenuModel::ChangeLabelForCommandId(int command_id,
|
|
|
|
NotifyMenuStateChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
+void StatusIconMenuModel::ChangeSublabelForCommandId(
|
|
|
|
+ int command_id, const base::string16& sublabel) {
|
|
|
|
+ item_states_[command_id].is_dynamic = true;
|
|
|
|
+ item_states_[command_id].sublabel = sublabel;
|
|
|
|
+ NotifyMenuStateChanged();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
void StatusIconMenuModel::ChangeIconForCommandId(
|
|
|
|
int command_id, const gfx::Image& icon) {
|
|
|
|
item_states_[command_id].is_dynamic = true;
|
|
|
|
@@ -122,6 +130,14 @@ base::string16 StatusIconMenuModel::GetLabelForCommandId(int command_id) const {
|
|
|
|
return base::string16();
|
|
|
|
}
|
|
|
|
|
|
|
|
+base::string16 StatusIconMenuModel::GetSublabelForCommandId(
|
|
|
|
+ int command_id) const {
|
|
|
|
+ auto iter = item_states_.find(command_id);
|
|
|
|
+ if (iter != item_states_.end())
|
|
|
|
+ return iter->second.sublabel;
|
|
|
|
+ return base::string16();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
bool StatusIconMenuModel::GetIconForCommandId(int command_id,
|
|
|
|
gfx::Image* image_skia) const {
|
|
|
|
auto iter = item_states_.find(command_id);
|
|
|
|
diff --git a/chrome/browser/status_icons/status_icon_menu_model.h b/chrome/browser/status_icons/status_icon_menu_model.h
|
|
|
|
index f40a33f7ce6ef9c9c538f44a86a404925eec32b5..556f531fcb66072828f3b5c2c07cd9d6a744ad53 100644
|
|
|
|
--- a/chrome/browser/status_icons/status_icon_menu_model.h
|
|
|
|
+++ b/chrome/browser/status_icons/status_icon_menu_model.h
|
|
|
|
@@ -61,9 +61,11 @@ class StatusIconMenuModel
|
|
|
|
|
|
|
|
// Calling any of these "change" methods will mark the menu item as "dynamic"
|
|
|
|
// (see menu_model.h:IsItemDynamicAt) which many platforms take as a cue to
|
|
|
|
- // refresh the label and icon of the menu item each time the menu is
|
|
|
|
+ // refresh the label, sublabel and icon of the menu item each time the menu is
|
|
|
|
// shown.
|
|
|
|
void ChangeLabelForCommandId(int command_id, const base::string16& label);
|
|
|
|
+ void ChangeSublabelForCommandId(
|
|
|
|
+ int command_id, const base::string16& sublabel);
|
|
|
|
void ChangeIconForCommandId(int command_id, const gfx::Image& icon);
|
|
|
|
|
|
|
|
void AddObserver(Observer* observer);
|
|
|
|
@@ -77,6 +79,7 @@ class StatusIconMenuModel
|
|
|
|
ui::Accelerator* accelerator) const override;
|
|
|
|
bool IsItemForCommandIdDynamic(int command_id) const override;
|
|
|
|
base::string16 GetLabelForCommandId(int command_id) const override;
|
|
|
|
+ base::string16 GetSublabelForCommandId(int command_id) const override;
|
|
|
|
bool GetIconForCommandId(int command_id, gfx::Image* icon) const override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
diff --git a/chrome/browser/status_icons/status_icon_menu_model_unittest.cc b/chrome/browser/status_icons/status_icon_menu_model_unittest.cc
|
|
|
|
index a258d038da4a2bbfc6ec13c250781166235c1fbc..f6dbaa19cdb8938204c3452622589708c7bc3bb2 100644
|
|
|
|
--- a/chrome/browser/status_icons/status_icon_menu_model_unittest.cc
|
|
|
|
+++ b/chrome/browser/status_icons/status_icon_menu_model_unittest.cc
|
|
|
|
@@ -90,6 +90,10 @@ TEST_F(StatusIconMenuModelTest, SetProperties) {
|
|
|
|
menu_model()->ChangeLabelForCommandId(0, ASCIIToUTF16("label2"));
|
|
|
|
EXPECT_EQ(ASCIIToUTF16("label2"), menu_model()->GetLabelForCommandId(0));
|
|
|
|
|
|
|
|
+ // Set the sublabel and icon image for the second menu item.
|
|
|
|
+ menu_model()->ChangeSublabelForCommandId(1, ASCIIToUTF16("sublabel"));
|
|
|
|
+ EXPECT_EQ(ASCIIToUTF16("sublabel"), menu_model()->GetSublabelForCommandId(1));
|
|
|
|
+
|
|
|
|
// Try setting icon image and changing it.
|
|
|
|
menu_model()->ChangeIconForCommandId(1, test_image1);
|
|
|
|
EXPECT_TRUE(menu_model()->GetIconForCommandId(1, &image_arg));
|
|
|
|
@@ -98,8 +102,9 @@ TEST_F(StatusIconMenuModelTest, SetProperties) {
|
|
|
|
// Ensure changes to one menu item does not affect the other menu item.
|
|
|
|
EXPECT_FALSE(menu_model()->GetAcceleratorForCommandId(1, &accel_arg));
|
|
|
|
EXPECT_EQ(base::string16(), menu_model()->GetLabelForCommandId(1));
|
|
|
|
+ EXPECT_EQ(base::string16(), menu_model()->GetSublabelForCommandId(0));
|
|
|
|
EXPECT_FALSE(menu_model()->GetIconForCommandId(0, &image_arg));
|
|
|
|
|
|
|
|
- // Menu state should have changed 6 times in this test.
|
|
|
|
- EXPECT_EQ(6, changed_count());
|
|
|
|
+ // Menu state should have changed 7 times in this test.
|
|
|
|
+ EXPECT_EQ(7, changed_count());
|
|
|
|
}
|
|
|
|
diff --git a/chrome/browser/ui/views/menu_item_view_interactive_uitest.cc b/chrome/browser/ui/views/menu_item_view_interactive_uitest.cc
|
2019-12-11 00:22:35 +00:00
|
|
|
index 1d7f5dc3abe95ffaa847454e2be1e9872fedc287..6e67fff6631d2d5339df6a912d917862bce37f3d 100644
|
2019-09-18 19:58:00 +00:00
|
|
|
--- a/chrome/browser/ui/views/menu_item_view_interactive_uitest.cc
|
|
|
|
+++ b/chrome/browser/ui/views/menu_item_view_interactive_uitest.cc
|
|
|
|
@@ -91,8 +91,8 @@ class MenuItemViewTestInsert : public MenuTestBase {
|
|
|
|
|
|
|
|
inserted_item_ = menu()->AddMenuItemAt(
|
|
|
|
INSERT_INDEX, 1000, ASCIIToUTF16("inserted item"), base::string16(),
|
|
|
|
- nullptr, gfx::ImageSkia(), nullptr, views::MenuItemView::NORMAL,
|
|
|
|
- ui::NORMAL_SEPARATOR);
|
|
|
|
+ base::string16(), nullptr, gfx::ImageSkia(), nullptr,
|
|
|
|
+ views::MenuItemView::NORMAL, ui::NORMAL_SEPARATOR);
|
|
|
|
ASSERT_TRUE(inserted_item_);
|
|
|
|
menu()->ChildrenChanged();
|
|
|
|
|
|
|
|
@@ -186,8 +186,8 @@ class MenuItemViewTestInsertWithSubmenu : public MenuTestBase {
|
|
|
|
void Step2() {
|
|
|
|
inserted_item_ = menu()->AddMenuItemAt(
|
|
|
|
INSERT_INDEX, 1000, ASCIIToUTF16("inserted item"), base::string16(),
|
|
|
|
- nullptr, gfx::ImageSkia(), nullptr, views::MenuItemView::NORMAL,
|
|
|
|
- ui::NORMAL_SEPARATOR);
|
|
|
|
+ base::string16(), nullptr, gfx::ImageSkia(), nullptr,
|
|
|
|
+ views::MenuItemView::NORMAL, ui::NORMAL_SEPARATOR);
|
|
|
|
ASSERT_TRUE(inserted_item_);
|
|
|
|
menu()->ChildrenChanged();
|
|
|
|
|
|
|
|
diff --git a/chrome/browser/ui/views/status_icons/concat_menu_model.cc b/chrome/browser/ui/views/status_icons/concat_menu_model.cc
|
|
|
|
index ead2226583589c2921db7a0d5e97dc6388c49b6c..d537405caad6c30af0f48a168a17252756250e46 100644
|
|
|
|
--- a/chrome/browser/ui/views/status_icons/concat_menu_model.cc
|
|
|
|
+++ b/chrome/browser/ui/views/status_icons/concat_menu_model.cc
|
|
|
|
@@ -33,6 +33,10 @@ base::string16 ConcatMenuModel::GetLabelAt(int index) const {
|
|
|
|
return GetterImpl(&ui::MenuModel::GetLabelAt, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
+base::string16 ConcatMenuModel::GetSublabelAt(int index) const {
|
|
|
|
+ return GetterImpl(&ui::MenuModel::GetSublabelAt, index);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
base::string16 ConcatMenuModel::GetMinorTextAt(int index) const {
|
|
|
|
return GetterImpl(&ui::MenuModel::GetMinorTextAt, index);
|
|
|
|
}
|
|
|
|
diff --git a/chrome/browser/ui/views/status_icons/concat_menu_model.h b/chrome/browser/ui/views/status_icons/concat_menu_model.h
|
|
|
|
index 0ad30d57d6d13bc8d42920010145595ce0031573..7b73b5753cfd4595121e5b81fd3c95682869e17b 100644
|
|
|
|
--- a/chrome/browser/ui/views/status_icons/concat_menu_model.h
|
|
|
|
+++ b/chrome/browser/ui/views/status_icons/concat_menu_model.h
|
|
|
|
@@ -23,6 +23,7 @@ class ConcatMenuModel : public ui::MenuModel {
|
|
|
|
ui::MenuSeparatorType GetSeparatorTypeAt(int index) const override;
|
|
|
|
int GetCommandIdAt(int index) const override;
|
|
|
|
base::string16 GetLabelAt(int index) const override;
|
|
|
|
+ base::string16 GetSublabelAt(int index) const override;
|
|
|
|
base::string16 GetMinorTextAt(int index) const override;
|
|
|
|
const gfx::VectorIcon* GetMinorIconAt(int index) const override;
|
|
|
|
bool IsItemDynamicAt(int index) const override;
|
|
|
|
diff --git a/ui/base/models/menu_model.cc b/ui/base/models/menu_model.cc
|
|
|
|
index 73f0ab6d84d2cab6732866a6dc4b781faf630c0e..3319d058e8303066e0159d02d27ee2e8a46b38ec 100644
|
|
|
|
--- a/ui/base/models/menu_model.cc
|
|
|
|
+++ b/ui/base/models/menu_model.cc
|
|
|
|
@@ -46,6 +46,10 @@ bool MenuModel::GetModelAndIndexForCommandId(int command_id,
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
+base::string16 MenuModel::GetSublabelAt(int index) const {
|
|
|
|
+ return base::string16();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
base::string16 MenuModel::GetMinorTextAt(int index) const {
|
|
|
|
return base::string16();
|
|
|
|
}
|
|
|
|
diff --git a/ui/base/models/menu_model.h b/ui/base/models/menu_model.h
|
2019-12-11 00:22:35 +00:00
|
|
|
index 5bcc6204c2b579fb2cba47ba1bc156967ec87faf..34e647d56dfe583a3484fb8df0a148064eacb07b 100644
|
2019-09-18 19:58:00 +00:00
|
|
|
--- a/ui/base/models/menu_model.h
|
|
|
|
+++ b/ui/base/models/menu_model.h
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -67,6 +67,10 @@ class UI_BASE_EXPORT MenuModel : public base::SupportsWeakPtr<MenuModel> {
|
2019-09-18 19:58:00 +00:00
|
|
|
// Returns the label of the item at the specified index.
|
|
|
|
virtual base::string16 GetLabelAt(int index) const = 0;
|
|
|
|
|
|
|
|
+ // Returns the sublabel of the item at the specified index. The sublabel
|
|
|
|
+ // is rendered beneath the label and using the font GetLabelFontAt().
|
|
|
|
+ virtual base::string16 GetSublabelAt(int index) const;
|
|
|
|
+
|
|
|
|
// Returns the minor text of the item at the specified index. The minor text
|
|
|
|
// is rendered to the right of the label and using the font GetLabelFontAt().
|
|
|
|
virtual base::string16 GetMinorTextAt(int index) const;
|
|
|
|
diff --git a/ui/base/models/simple_menu_model.cc b/ui/base/models/simple_menu_model.cc
|
2019-12-11 00:22:35 +00:00
|
|
|
index 6a55c0f82ce3df3d8b2b31dbb67830bb5464019c..c42dee1fc9ddccf5b5556fff7282a64d14c8333d 100644
|
2019-09-18 19:58:00 +00:00
|
|
|
--- a/ui/base/models/simple_menu_model.cc
|
|
|
|
+++ b/ui/base/models/simple_menu_model.cc
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -46,6 +46,16 @@ base::string16 SimpleMenuModel::Delegate::GetLabelForCommandId(
|
2019-09-18 19:58:00 +00:00
|
|
|
return base::string16();
|
|
|
|
}
|
|
|
|
|
|
|
|
+base::string16 SimpleMenuModel::Delegate::GetSublabelForCommandId(
|
|
|
|
+ int command_id) const {
|
|
|
|
+ return base::string16();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void SimpleMenuModel::SetSublabel(int index, const base::string16& sublabel) {
|
|
|
|
+ items_[ValidateItemIndex(index)].sublabel = sublabel;
|
|
|
|
+ MenuItemsChanged();
|
|
|
|
+}
|
|
|
|
+
|
2019-12-11 00:22:35 +00:00
|
|
|
bool SimpleMenuModel::Delegate::GetIconForCommandId(
|
|
|
|
int command_id, gfx::Image* image_skia) const {
|
|
|
|
return false;
|
|
|
|
@@ -404,6 +414,12 @@ base::string16 SimpleMenuModel::GetLabelAt(int index) const {
|
2019-09-18 19:58:00 +00:00
|
|
|
return items_[ValidateItemIndex(index)].label;
|
|
|
|
}
|
|
|
|
|
|
|
|
+base::string16 SimpleMenuModel::GetSublabelAt(int index) const {
|
|
|
|
+ if (IsItemDynamicAt(index))
|
|
|
|
+ return delegate_->GetSublabelForCommandId(GetCommandIdAt(index));
|
|
|
|
+ return items_[ValidateItemIndex(index)].sublabel;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
base::string16 SimpleMenuModel::GetMinorTextAt(int index) const {
|
2019-12-11 00:22:35 +00:00
|
|
|
return items_[ValidateItemIndex(index)].minor_text;
|
|
|
|
}
|
2019-09-18 19:58:00 +00:00
|
|
|
diff --git a/ui/base/models/simple_menu_model.h b/ui/base/models/simple_menu_model.h
|
2019-12-11 00:22:35 +00:00
|
|
|
index 1ae8909a1404a43b34b9ef585511c7a3de39fa28..0d2a74ab5e9d55201a4992d81aecf9c2a83af5b8 100644
|
2019-09-18 19:58:00 +00:00
|
|
|
--- a/ui/base/models/simple_menu_model.h
|
|
|
|
+++ b/ui/base/models/simple_menu_model.h
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -47,6 +47,7 @@ class UI_BASE_EXPORT SimpleMenuModel : public MenuModel {
|
|
|
|
// Some command ids have labels and icons that change over time.
|
2019-09-18 19:58:00 +00:00
|
|
|
virtual bool IsItemForCommandIdDynamic(int command_id) const;
|
|
|
|
virtual base::string16 GetLabelForCommandId(int command_id) const;
|
|
|
|
+ virtual base::string16 GetSublabelForCommandId(int command_id) const;
|
|
|
|
// Gets the icon for the item with the specified id, returning true if there
|
|
|
|
// is an icon, false otherwise.
|
2019-12-11 00:22:35 +00:00
|
|
|
virtual bool GetIconForCommandId(int command_id,
|
|
|
|
@@ -174,6 +175,9 @@ class UI_BASE_EXPORT SimpleMenuModel : public MenuModel {
|
2019-09-18 19:58:00 +00:00
|
|
|
// Sets the label for the item at |index|.
|
|
|
|
void SetLabel(int index, const base::string16& label);
|
|
|
|
|
|
|
|
+ // Sets the sublabel for the item at |index|.
|
|
|
|
+ void SetSublabel(int index, const base::string16& sublabel);
|
|
|
|
+
|
|
|
|
// Sets the minor text for the item at |index|.
|
|
|
|
void SetMinorText(int index, const base::string16& minor_text);
|
|
|
|
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -200,6 +204,7 @@ class UI_BASE_EXPORT SimpleMenuModel : public MenuModel {
|
2019-09-18 19:58:00 +00:00
|
|
|
ui::MenuSeparatorType GetSeparatorTypeAt(int index) const override;
|
|
|
|
int GetCommandIdAt(int index) const override;
|
|
|
|
base::string16 GetLabelAt(int index) const override;
|
|
|
|
+ base::string16 GetSublabelAt(int index) const override;
|
|
|
|
base::string16 GetMinorTextAt(int index) const override;
|
|
|
|
const gfx::VectorIcon* GetMinorIconAt(int index) const override;
|
|
|
|
bool IsItemDynamicAt(int index) const override;
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -235,6 +240,7 @@ class UI_BASE_EXPORT SimpleMenuModel : public MenuModel {
|
2019-09-18 19:58:00 +00:00
|
|
|
int command_id = 0;
|
|
|
|
ItemType type = TYPE_COMMAND;
|
|
|
|
base::string16 label;
|
|
|
|
+ base::string16 sublabel;
|
|
|
|
base::string16 minor_text;
|
|
|
|
const gfx::VectorIcon* minor_icon = nullptr;
|
|
|
|
gfx::Image icon;
|
|
|
|
diff --git a/ui/views/controls/menu/menu_item_view.cc b/ui/views/controls/menu/menu_item_view.cc
|
2019-12-11 00:22:35 +00:00
|
|
|
index e86941132ce80e262d1961ff3cdad79b44abb878..6e67ffea103e7169d35b37455ded83d8d812d77b 100644
|
2019-09-18 19:58:00 +00:00
|
|
|
--- a/ui/views/controls/menu/menu_item_view.cc
|
|
|
|
+++ b/ui/views/controls/menu/menu_item_view.cc
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -278,6 +278,7 @@ MenuItemView* MenuItemView::AddMenuItemAt(
|
2019-09-18 19:58:00 +00:00
|
|
|
int index,
|
|
|
|
int item_id,
|
|
|
|
const base::string16& label,
|
|
|
|
+ const base::string16& sublabel,
|
|
|
|
const base::string16& minor_text,
|
|
|
|
const gfx::VectorIcon* minor_icon,
|
|
|
|
const gfx::ImageSkia& icon,
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -298,6 +299,7 @@ MenuItemView* MenuItemView::AddMenuItemAt(
|
2019-09-18 19:58:00 +00:00
|
|
|
item->SetTitle(GetDelegate()->GetLabel(item_id));
|
|
|
|
else
|
|
|
|
item->SetTitle(label);
|
|
|
|
+ item->SetSubtitle(sublabel);
|
|
|
|
item->SetMinorText(minor_text);
|
|
|
|
item->SetMinorIcon(minor_icon);
|
|
|
|
if (vector_icon) {
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -339,21 +341,22 @@ void MenuItemView::RemoveAllMenuItems() {
|
2019-09-18 19:58:00 +00:00
|
|
|
MenuItemView* MenuItemView::AppendMenuItem(int item_id,
|
|
|
|
const base::string16& label,
|
2019-12-11 00:22:35 +00:00
|
|
|
const gfx::ImageSkia& icon) {
|
|
|
|
- return AppendMenuItemImpl(item_id, label, icon, NORMAL);
|
|
|
|
+ return AppendMenuItemImpl(item_id, label, base::string16(), icon, NORMAL);
|
2019-09-18 19:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MenuItemView* MenuItemView::AppendSubMenu(int item_id,
|
2019-12-11 00:22:35 +00:00
|
|
|
const base::string16& label,
|
|
|
|
const gfx::ImageSkia& icon) {
|
|
|
|
- return AppendMenuItemImpl(item_id, label, icon, SUBMENU);
|
|
|
|
+ return AppendMenuItemImpl(item_id, label, base::string16(), icon, SUBMENU);
|
2019-09-18 19:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MenuItemView::AppendSeparator() {
|
2019-12-11 00:22:35 +00:00
|
|
|
- AppendMenuItemImpl(0, base::string16(), gfx::ImageSkia(), SEPARATOR);
|
|
|
|
+ AppendMenuItemImpl(0, base::string16(), base::string16(), gfx::ImageSkia(), SEPARATOR);
|
2019-09-18 19:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MenuItemView::AddSeparatorAt(int index) {
|
|
|
|
AddMenuItemAt(index, /*item_id=*/0, /*label=*/base::string16(),
|
|
|
|
+ /*sub_label=*/base::string16(),
|
|
|
|
/*minor_text=*/base::string16(), /*minor_icon=*/nullptr,
|
|
|
|
/*icon=*/gfx::ImageSkia(), /*vector_icon=*/nullptr,
|
|
|
|
/*type=*/SEPARATOR,
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -362,10 +365,11 @@ void MenuItemView::AddSeparatorAt(int index) {
|
2019-09-18 19:58:00 +00:00
|
|
|
|
2019-12-11 00:22:35 +00:00
|
|
|
MenuItemView* MenuItemView::AppendMenuItemImpl(int item_id,
|
|
|
|
const base::string16& label,
|
|
|
|
+ const base::string16& sublabel,
|
|
|
|
const gfx::ImageSkia& icon,
|
|
|
|
Type type) {
|
2019-09-18 19:58:00 +00:00
|
|
|
const int index = submenu_ ? int{submenu_->children().size()} : 0;
|
2019-12-11 00:22:35 +00:00
|
|
|
- return AddMenuItemAt(index, item_id, label, base::string16(), nullptr, icon,
|
|
|
|
+ return AddMenuItemAt(index, item_id, label, sublabel, base::string16(), nullptr, icon,
|
|
|
|
nullptr, type, ui::NORMAL_SEPARATOR);
|
2019-09-18 19:58:00 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -398,6 +402,11 @@ void MenuItemView::SetTitle(const base::string16& title) {
|
2019-09-18 19:58:00 +00:00
|
|
|
invalidate_dimensions(); // Triggers preferred size recalculation.
|
|
|
|
}
|
|
|
|
|
|
|
|
+void MenuItemView::SetSubtitle(const base::string16& subtitle) {
|
|
|
|
+ subtitle_ = subtitle;
|
|
|
|
+ invalidate_dimensions(); // Triggers preferred size recalculation.
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
void MenuItemView::SetMinorText(const base::string16& minor_text) {
|
|
|
|
minor_text_ = minor_text;
|
|
|
|
invalidate_dimensions(); // Triggers preferred size recalculation.
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -987,13 +996,23 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
|
2019-09-18 19:58:00 +00:00
|
|
|
(!delegate ||
|
|
|
|
delegate->ShouldReserveSpaceForSubmenuIndicator() ?
|
|
|
|
item_right_margin_ : config.arrow_to_edge_padding);
|
|
|
|
- gfx::Rect text_bounds(label_start, top_margin, width, available_height);
|
|
|
|
+ gfx::Rect text_bounds(label_start, top_margin, width,
|
|
|
|
+ subtitle_.empty() ? available_height
|
|
|
|
+ : available_height / 2);
|
|
|
|
text_bounds.set_x(GetMirroredXForRect(text_bounds));
|
|
|
|
int flags = GetDrawStringFlags();
|
2019-10-18 19:57:34 +00:00
|
|
|
if (mode == PaintButtonMode::kForDrag)
|
2019-09-18 19:58:00 +00:00
|
|
|
flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING;
|
|
|
|
canvas->DrawStringRectWithFlags(title(), style.font_list, style.foreground,
|
|
|
|
text_bounds, flags);
|
|
|
|
+ if (!subtitle_.empty()) {
|
|
|
|
+ canvas->DrawStringRectWithFlags(
|
|
|
|
+ subtitle_, style.font_list,
|
|
|
|
+ GetNativeTheme()->GetSystemColor(
|
|
|
|
+ ui::NativeTheme::kColorId_MenuItemMinorTextColor),
|
|
|
|
+ text_bounds + gfx::Vector2d(0, style.font_list.GetHeight()), flags);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
PaintMinorIconAndText(canvas, style);
|
|
|
|
|
|
|
|
// Set the submenu indicator (arrow) image and color.
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -1244,6 +1263,11 @@ MenuItemView::MenuItemDimensions MenuItemView::CalculateDimensions() const {
|
2019-09-18 19:58:00 +00:00
|
|
|
|
|
|
|
// Determine the length of the label text.
|
|
|
|
int string_width = gfx::GetStringWidth(title_, style.font_list);
|
|
|
|
+ if (!subtitle_.empty()) {
|
|
|
|
+ string_width =
|
|
|
|
+ std::max(string_width, gfx::GetStringWidth(subtitle_, style.font_list));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
dimensions.standard_width = string_width + label_start +
|
|
|
|
item_right_margin_;
|
|
|
|
// Determine the length of the right-side text.
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -1251,9 +1275,10 @@ MenuItemView::MenuItemDimensions MenuItemView::CalculateDimensions() const {
|
2019-09-18 19:58:00 +00:00
|
|
|
minor_text.empty() ? 0 : gfx::GetStringWidth(minor_text, style.font_list);
|
|
|
|
|
|
|
|
// Determine the height to use.
|
|
|
|
- dimensions.height =
|
|
|
|
- std::max(dimensions.height, style.font_list.GetHeight() +
|
|
|
|
- GetBottomMargin() + GetTopMargin());
|
|
|
|
+ dimensions.height = std::max(
|
|
|
|
+ dimensions.height, (subtitle_.empty() ? 0 : style.font_list.GetHeight()) +
|
|
|
|
+ style.font_list.GetHeight() + GetBottomMargin() +
|
|
|
|
+ GetTopMargin());
|
|
|
|
dimensions.height =
|
|
|
|
std::max(dimensions.height, MenuConfig::instance().item_min_height);
|
|
|
|
|
|
|
|
diff --git a/ui/views/controls/menu/menu_item_view.h b/ui/views/controls/menu/menu_item_view.h
|
2019-12-11 00:22:35 +00:00
|
|
|
index c453320c3fbd8ad5581a78b0b63d7a06cda4d542..b92470f17446698515ae2e973e51628023d075de 100644
|
2019-09-18 19:58:00 +00:00
|
|
|
--- a/ui/views/controls/menu/menu_item_view.h
|
|
|
|
+++ b/ui/views/controls/menu/menu_item_view.h
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -152,6 +152,7 @@ class VIEWS_EXPORT MenuItemView : public View {
|
2019-09-18 19:58:00 +00:00
|
|
|
MenuItemView* AddMenuItemAt(int index,
|
|
|
|
int item_id,
|
|
|
|
const base::string16& label,
|
|
|
|
+ const base::string16& sublabel,
|
|
|
|
const base::string16& minor_text,
|
|
|
|
const gfx::VectorIcon* minor_icon,
|
|
|
|
const gfx::ImageSkia& icon,
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -194,6 +195,7 @@ class VIEWS_EXPORT MenuItemView : public View {
|
2019-09-18 19:58:00 +00:00
|
|
|
// All the AppendXXX methods funnel into this.
|
|
|
|
MenuItemView* AppendMenuItemImpl(int item_id,
|
|
|
|
const base::string16& label,
|
|
|
|
+ const base::string16& sublabel,
|
|
|
|
const gfx::ImageSkia& icon,
|
2019-12-11 00:22:35 +00:00
|
|
|
Type type);
|
|
|
|
|
|
|
|
@@ -218,6 +220,9 @@ class VIEWS_EXPORT MenuItemView : public View {
|
2019-09-18 19:58:00 +00:00
|
|
|
void SetTitle(const base::string16& title);
|
|
|
|
const base::string16& title() const { return title_; }
|
|
|
|
|
|
|
|
+ // Sets the subtitle.
|
|
|
|
+ void SetSubtitle(const base::string16& subtitle);
|
|
|
|
+
|
|
|
|
// Sets the minor text.
|
|
|
|
void SetMinorText(const base::string16& minor_text);
|
|
|
|
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -428,7 +433,7 @@ class VIEWS_EXPORT MenuItemView : public View {
|
2019-09-18 19:58:00 +00:00
|
|
|
void DestroyAllMenuHosts();
|
|
|
|
|
|
|
|
// Returns the text that should be displayed on the end (right) of the menu
|
|
|
|
- // item. This will be the accelerator (if one exists).
|
|
|
|
+ // item. This will be the accelerator (if one exists), otherwise |subtitle_|.
|
|
|
|
base::string16 GetMinorText() const;
|
|
|
|
|
|
|
|
// Returns the icon that should be displayed to the left of the minor text.
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -519,6 +524,9 @@ class VIEWS_EXPORT MenuItemView : public View {
|
2019-09-18 19:58:00 +00:00
|
|
|
// Title.
|
|
|
|
base::string16 title_;
|
|
|
|
|
|
|
|
+ // Subtitle/sublabel.
|
|
|
|
+ base::string16 subtitle_;
|
|
|
|
+
|
|
|
|
// Minor text.
|
|
|
|
base::string16 minor_text_;
|
|
|
|
|
|
|
|
diff --git a/ui/views/controls/menu/menu_item_view_unittest.cc b/ui/views/controls/menu/menu_item_view_unittest.cc
|
2019-12-11 00:22:35 +00:00
|
|
|
index 27d189a5be20d001ac6c457f4540e5e5430dde37..5c749133714d40595ef804d56951eed35abee91e 100644
|
2019-09-18 19:58:00 +00:00
|
|
|
--- a/ui/views/controls/menu/menu_item_view_unittest.cc
|
|
|
|
+++ b/ui/views/controls/menu/menu_item_view_unittest.cc
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -322,10 +322,10 @@ class MenuItemViewPaintUnitTest : public ViewsTestBase {
|
2019-09-18 19:58:00 +00:00
|
|
|
// Provides assertion coverage for painting minor text and icons.
|
|
|
|
TEST_F(MenuItemViewPaintUnitTest, MinorTextAndIconAssertionCoverage) {
|
|
|
|
auto AddItem = [this](auto label, auto minor_label, auto minor_icon) {
|
|
|
|
- menu_item_view()->AddMenuItemAt(0, 1000, base::ASCIIToUTF16(label),
|
|
|
|
- minor_label, minor_icon, gfx::ImageSkia(),
|
|
|
|
- nullptr, views::MenuItemView::NORMAL,
|
|
|
|
- ui::NORMAL_SEPARATOR);
|
|
|
|
+ menu_item_view()->AddMenuItemAt(
|
|
|
|
+ 0, 1000, base::ASCIIToUTF16(label), base::string16(), minor_label,
|
|
|
|
+ minor_icon, gfx::ImageSkia(), nullptr, views::MenuItemView::NORMAL,
|
|
|
|
+ ui::NORMAL_SEPARATOR);
|
|
|
|
};
|
|
|
|
AddItem("No minor content", base::string16(), nullptr);
|
|
|
|
AddItem("Minor text only", base::ASCIIToUTF16("minor text"), nullptr);
|
|
|
|
diff --git a/ui/views/controls/menu/menu_model_adapter.cc b/ui/views/controls/menu/menu_model_adapter.cc
|
2019-12-11 00:22:35 +00:00
|
|
|
index beac9986b2c6d13cde9cb26310eefc01cfbbbe09..ab9ac14fcd346ce5490c916cf3eceb534510fb69 100644
|
2019-09-18 19:58:00 +00:00
|
|
|
--- a/ui/views/controls/menu/menu_model_adapter.cc
|
|
|
|
+++ b/ui/views/controls/menu/menu_model_adapter.cc
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -99,8 +99,8 @@ MenuItemView* MenuModelAdapter::AddMenuItemFromModelAt(ui::MenuModel* model,
|
2019-09-18 19:58:00 +00:00
|
|
|
|
|
|
|
if (*type == MenuItemView::SEPARATOR) {
|
|
|
|
return menu->AddMenuItemAt(menu_index, item_id, base::string16(),
|
|
|
|
- base::string16(), nullptr, gfx::ImageSkia(),
|
|
|
|
- nullptr, *type,
|
|
|
|
+ base::string16(), base::string16(), nullptr,
|
|
|
|
+ gfx::ImageSkia(), nullptr, *type,
|
|
|
|
model->GetSeparatorTypeAt(model_index));
|
|
|
|
}
|
|
|
|
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -108,7 +108,8 @@ MenuItemView* MenuModelAdapter::AddMenuItemFromModelAt(ui::MenuModel* model,
|
2019-09-18 19:58:00 +00:00
|
|
|
model->GetIconAt(model_index, &icon);
|
|
|
|
return menu->AddMenuItemAt(
|
|
|
|
menu_index, item_id, model->GetLabelAt(model_index),
|
|
|
|
- model->GetMinorTextAt(model_index), model->GetMinorIconAt(model_index),
|
|
|
|
+ model->GetSublabelAt(model_index), model->GetMinorTextAt(model_index),
|
|
|
|
+ model->GetMinorIconAt(model_index),
|
|
|
|
icon.IsEmpty() ? gfx::ImageSkia() : *icon.ToImageSkia(),
|
|
|
|
icon.IsEmpty() ? model->GetVectorIconAt(model_index) : nullptr, *type,
|
|
|
|
ui::NORMAL_SEPARATOR);
|