allow_setting_secondary_label_via_simplemenumodel.patch 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: deepak1556 <[email protected]>
  3. Date: Thu, 21 May 2020 13:58:01 -0700
  4. Subject: Allow setting secondary label via SimpleMenuModel
  5. Builds on https://chromium-review.googlesource.com/c/chromium/src/+/2208976
  6. diff --git a/ui/menus/simple_menu_model.cc b/ui/menus/simple_menu_model.cc
  7. index 9f56505d9502c685f66ab082b60eaae4011e76b7..35ee633305f6dd5910e1c19dcc8c9df064757c57 100644
  8. --- a/ui/menus/simple_menu_model.cc
  9. +++ b/ui/menus/simple_menu_model.cc
  10. @@ -54,6 +54,11 @@ std::u16string SimpleMenuModel::Delegate::GetLabelForCommandId(
  11. return std::u16string();
  12. }
  13. +std::u16string SimpleMenuModel::Delegate::GetSecondaryLabelForCommandId(
  14. + int command_id) const {
  15. + return std::u16string();
  16. +}
  17. +
  18. ImageModel SimpleMenuModel::Delegate::GetIconForCommandId(
  19. int command_id) const {
  20. return ImageModel();
  21. @@ -347,6 +352,11 @@ void SimpleMenuModel::SetAcceleratorAt(size_t index,
  22. MenuItemsChanged();
  23. }
  24. +void SimpleMenuModel::SetSecondaryLabel(size_t index, const std::u16string& secondary_label) {
  25. + items_[ValidateItemIndex(index)].secondary_label = secondary_label;
  26. + MenuItemsChanged();
  27. +}
  28. +
  29. void SimpleMenuModel::SetMinorText(size_t index,
  30. const std::u16string& minor_text) {
  31. items_[ValidateItemIndex(index)].minor_text = minor_text;
  32. @@ -453,6 +463,12 @@ std::u16string SimpleMenuModel::GetLabelAt(size_t index) const {
  33. return items_[ValidateItemIndex(index)].label;
  34. }
  35. +std::u16string SimpleMenuModel::GetSecondaryLabelAt(size_t index) const {
  36. + if (IsItemDynamicAt(index))
  37. + return delegate_->GetSecondaryLabelForCommandId(GetCommandIdAt(index));
  38. + return items_[ValidateItemIndex(index)].secondary_label;
  39. +}
  40. +
  41. std::u16string SimpleMenuModel::GetMinorTextAt(size_t index) const {
  42. return items_[ValidateItemIndex(index)].minor_text;
  43. }
  44. diff --git a/ui/menus/simple_menu_model.h b/ui/menus/simple_menu_model.h
  45. index 596663d62632e4331f8aad421298d1fcdc9ab05e..469778f0c13e6d3fd30023af9b19c4a4cb7969be 100644
  46. --- a/ui/menus/simple_menu_model.h
  47. +++ b/ui/menus/simple_menu_model.h
  48. @@ -99,6 +99,7 @@ class COMPONENT_EXPORT(UI_MENUS) SimpleMenuModel : public MenuModel {
  49. // Some command ids have labels and icons that change over time.
  50. virtual bool IsItemForCommandIdDynamic(int command_id) const;
  51. virtual std::u16string GetLabelForCommandId(int command_id) const;
  52. + virtual std::u16string GetSecondaryLabelForCommandId(int command_id) const;
  53. // Gets the icon for the item with the specified id.
  54. virtual ImageModel GetIconForCommandId(int command_id) const;
  55. @@ -224,6 +225,9 @@ class COMPONENT_EXPORT(UI_MENUS) SimpleMenuModel : public MenuModel {
  56. // former is set).
  57. void SetAcceleratorAt(size_t index, const ui::Accelerator& accelerator);
  58. + // Sets the secondary_label for the item at |index|.
  59. + void SetSecondaryLabel(size_t index, const std::u16string& secondary_label);
  60. +
  61. // Sets the minor text for the item at |index|.
  62. void SetMinorText(size_t index, const std::u16string& minor_text);
  63. @@ -274,6 +278,7 @@ class COMPONENT_EXPORT(UI_MENUS) SimpleMenuModel : public MenuModel {
  64. ui::MenuSeparatorType GetSeparatorTypeAt(size_t index) const override;
  65. int GetCommandIdAt(size_t index) const override;
  66. std::u16string GetLabelAt(size_t index) const override;
  67. + std::u16string GetSecondaryLabelAt(size_t index) const override;
  68. std::u16string GetMinorTextAt(size_t index) const override;
  69. ImageModel GetMinorIconAt(size_t index) const override;
  70. bool IsItemDynamicAt(size_t index) const override;
  71. @@ -321,6 +326,7 @@ class COMPONENT_EXPORT(UI_MENUS) SimpleMenuModel : public MenuModel {
  72. ItemType type = TYPE_COMMAND;
  73. std::u16string label;
  74. ui::Accelerator accelerator;
  75. + std::u16string secondary_label;
  76. std::u16string minor_text;
  77. ImageModel minor_icon;
  78. ImageModel icon;