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/base/models/simple_menu_model.cc b/ui/base/models/simple_menu_model.cc
  7. index 1fc029cb37562dc32a961666c3af3b0c27b04e5a..e1c6fe2ea2c3c89e10ff4ae27d16baf053e8a3a0 100644
  8. --- a/ui/base/models/simple_menu_model.cc
  9. +++ b/ui/base/models/simple_menu_model.cc
  10. @@ -49,6 +49,11 @@ base::string16 SimpleMenuModel::Delegate::GetLabelForCommandId(
  11. return base::string16();
  12. }
  13. +base::string16 SimpleMenuModel::Delegate::GetSecondaryLabelForCommandId(
  14. + int command_id) const {
  15. + return base::string16();
  16. +}
  17. +
  18. ImageModel SimpleMenuModel::Delegate::GetIconForCommandId(
  19. int command_id) const {
  20. return ImageModel();
  21. @@ -291,6 +296,11 @@ void SimpleMenuModel::SetLabel(int index, const base::string16& label) {
  22. MenuItemsChanged();
  23. }
  24. +void SimpleMenuModel::SetSecondaryLabel(int index, const base::string16& secondary_label) {
  25. + items_[ValidateItemIndex(index)].secondary_label = secondary_label;
  26. + MenuItemsChanged();
  27. +}
  28. +
  29. void SimpleMenuModel::SetMinorText(int index,
  30. const base::string16& minor_text) {
  31. items_[ValidateItemIndex(index)].minor_text = minor_text;
  32. @@ -368,6 +378,12 @@ base::string16 SimpleMenuModel::GetLabelAt(int index) const {
  33. return items_[ValidateItemIndex(index)].label;
  34. }
  35. +base::string16 SimpleMenuModel::GetSecondaryLabelAt(int index) const {
  36. + if (IsItemDynamicAt(index))
  37. + return delegate_->GetSecondaryLabelForCommandId(GetCommandIdAt(index));
  38. + return items_[ValidateItemIndex(index)].secondary_label;
  39. +}
  40. +
  41. base::string16 SimpleMenuModel::GetMinorTextAt(int index) const {
  42. return items_[ValidateItemIndex(index)].minor_text;
  43. }
  44. diff --git a/ui/base/models/simple_menu_model.h b/ui/base/models/simple_menu_model.h
  45. index 3067f9beba9e79e18d341aea052d82aad34039d0..ffd8d7c53378b490e54af430371dc8a44121f72b 100644
  46. --- a/ui/base/models/simple_menu_model.h
  47. +++ b/ui/base/models/simple_menu_model.h
  48. @@ -44,6 +44,7 @@ class COMPONENT_EXPORT(UI_BASE) 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 base::string16 GetLabelForCommandId(int command_id) const;
  52. + virtual base::string16 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. @@ -147,6 +148,9 @@ class COMPONENT_EXPORT(UI_BASE) SimpleMenuModel : public MenuModel {
  56. // Sets the label for the item at |index|.
  57. void SetLabel(int index, const base::string16& label);
  58. + // Sets the secondary_label for the item at |index|.
  59. + void SetSecondaryLabel(int index, const base::string16& secondary_label);
  60. +
  61. // Sets the minor text for the item at |index|.
  62. void SetMinorText(int index, const base::string16& minor_text);
  63. @@ -176,6 +180,7 @@ class COMPONENT_EXPORT(UI_BASE) SimpleMenuModel : public MenuModel {
  64. ui::MenuSeparatorType GetSeparatorTypeAt(int index) const override;
  65. int GetCommandIdAt(int index) const override;
  66. base::string16 GetLabelAt(int index) const override;
  67. + base::string16 GetSecondaryLabelAt(int index) const override;
  68. base::string16 GetMinorTextAt(int index) const override;
  69. ImageModel GetMinorIconAt(int index) const override;
  70. bool IsItemDynamicAt(int index) const override;
  71. @@ -211,6 +216,7 @@ class COMPONENT_EXPORT(UI_BASE) SimpleMenuModel : public MenuModel {
  72. int command_id = 0;
  73. ItemType type = TYPE_COMMAND;
  74. base::string16 label;
  75. + base::string16 secondary_label;
  76. base::string16 minor_text;
  77. ImageModel minor_icon;
  78. ImageModel icon;