| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/menu/menu_model_adapter.h" | 5 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/base/models/menu_model.h" | 8 #include "ui/base/models/menu_model.h" |
| 9 #include "ui/base/models/menu_model_delegate.h" | 9 #include "ui/base/models/menu_model_delegate.h" |
| 10 #include "ui/views/controls/menu/menu_item_view.h" | 10 #include "ui/views/controls/menu/menu_item_view.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 explicit MenuModelBase(int command_id_base) | 23 explicit MenuModelBase(int command_id_base) |
| 24 : command_id_base_(command_id_base), | 24 : command_id_base_(command_id_base), |
| 25 last_activation_(-1) { | 25 last_activation_(-1) { |
| 26 } | 26 } |
| 27 | 27 |
| 28 virtual ~MenuModelBase() { | 28 virtual ~MenuModelBase() { |
| 29 } | 29 } |
| 30 | 30 |
| 31 // ui::MenuModel implementation: | 31 // ui::MenuModel implementation: |
| 32 | 32 |
| 33 virtual bool HasIcons() const OVERRIDE { | 33 virtual bool HasIcons() const override { |
| 34 return false; | 34 return false; |
| 35 } | 35 } |
| 36 | 36 |
| 37 virtual int GetItemCount() const OVERRIDE { | 37 virtual int GetItemCount() const override { |
| 38 return static_cast<int>(items_.size()); | 38 return static_cast<int>(items_.size()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual ItemType GetTypeAt(int index) const OVERRIDE { | 41 virtual ItemType GetTypeAt(int index) const override { |
| 42 return items_[index].type; | 42 return items_[index].type; |
| 43 } | 43 } |
| 44 | 44 |
| 45 virtual ui::MenuSeparatorType GetSeparatorTypeAt( | 45 virtual ui::MenuSeparatorType GetSeparatorTypeAt( |
| 46 int index) const OVERRIDE { | 46 int index) const override { |
| 47 return ui::NORMAL_SEPARATOR; | 47 return ui::NORMAL_SEPARATOR; |
| 48 } | 48 } |
| 49 | 49 |
| 50 virtual int GetCommandIdAt(int index) const OVERRIDE { | 50 virtual int GetCommandIdAt(int index) const override { |
| 51 return index + command_id_base_; | 51 return index + command_id_base_; |
| 52 } | 52 } |
| 53 | 53 |
| 54 virtual base::string16 GetLabelAt(int index) const OVERRIDE { | 54 virtual base::string16 GetLabelAt(int index) const override { |
| 55 return items_[index].label; | 55 return items_[index].label; |
| 56 } | 56 } |
| 57 | 57 |
| 58 virtual bool IsItemDynamicAt(int index) const OVERRIDE { | 58 virtual bool IsItemDynamicAt(int index) const override { |
| 59 return false; | 59 return false; |
| 60 } | 60 } |
| 61 | 61 |
| 62 virtual const gfx::FontList* GetLabelFontListAt(int index) const OVERRIDE { | 62 virtual const gfx::FontList* GetLabelFontListAt(int index) const override { |
| 63 return NULL; | 63 return NULL; |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual bool GetAcceleratorAt(int index, | 66 virtual bool GetAcceleratorAt(int index, |
| 67 ui::Accelerator* accelerator) const OVERRIDE { | 67 ui::Accelerator* accelerator) const override { |
| 68 return false; | 68 return false; |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual bool IsItemCheckedAt(int index) const OVERRIDE { | 71 virtual bool IsItemCheckedAt(int index) const override { |
| 72 return false; | 72 return false; |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual int GetGroupIdAt(int index) const OVERRIDE { | 75 virtual int GetGroupIdAt(int index) const override { |
| 76 return 0; | 76 return 0; |
| 77 } | 77 } |
| 78 | 78 |
| 79 virtual bool GetIconAt(int index, gfx::Image* icon) OVERRIDE { | 79 virtual bool GetIconAt(int index, gfx::Image* icon) override { |
| 80 return false; | 80 return false; |
| 81 } | 81 } |
| 82 | 82 |
| 83 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt( | 83 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt( |
| 84 int index) const OVERRIDE { | 84 int index) const override { |
| 85 return NULL; | 85 return NULL; |
| 86 } | 86 } |
| 87 | 87 |
| 88 virtual bool IsEnabledAt(int index) const OVERRIDE { | 88 virtual bool IsEnabledAt(int index) const override { |
| 89 return true; | 89 return true; |
| 90 } | 90 } |
| 91 | 91 |
| 92 virtual bool IsVisibleAt(int index) const OVERRIDE { | 92 virtual bool IsVisibleAt(int index) const override { |
| 93 return true; | 93 return true; |
| 94 } | 94 } |
| 95 | 95 |
| 96 virtual MenuModel* GetSubmenuModelAt(int index) const OVERRIDE { | 96 virtual MenuModel* GetSubmenuModelAt(int index) const override { |
| 97 return items_[index].submenu; | 97 return items_[index].submenu; |
| 98 } | 98 } |
| 99 | 99 |
| 100 virtual void HighlightChangedTo(int index) OVERRIDE { | 100 virtual void HighlightChangedTo(int index) override { |
| 101 } | 101 } |
| 102 | 102 |
| 103 virtual void ActivatedAt(int index) OVERRIDE { | 103 virtual void ActivatedAt(int index) override { |
| 104 set_last_activation(index); | 104 set_last_activation(index); |
| 105 } | 105 } |
| 106 | 106 |
| 107 virtual void ActivatedAt(int index, int event_flags) OVERRIDE { | 107 virtual void ActivatedAt(int index, int event_flags) override { |
| 108 ActivatedAt(index); | 108 ActivatedAt(index); |
| 109 } | 109 } |
| 110 | 110 |
| 111 virtual void MenuWillShow() OVERRIDE { | 111 virtual void MenuWillShow() override { |
| 112 } | 112 } |
| 113 | 113 |
| 114 virtual void MenuClosed() OVERRIDE { | 114 virtual void MenuClosed() override { |
| 115 } | 115 } |
| 116 | 116 |
| 117 virtual void SetMenuModelDelegate( | 117 virtual void SetMenuModelDelegate( |
| 118 ui::MenuModelDelegate* delegate) OVERRIDE { | 118 ui::MenuModelDelegate* delegate) override { |
| 119 } | 119 } |
| 120 | 120 |
| 121 virtual ui::MenuModelDelegate* GetMenuModelDelegate() const OVERRIDE { | 121 virtual ui::MenuModelDelegate* GetMenuModelDelegate() const override { |
| 122 return NULL; | 122 return NULL; |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Item definition. | 125 // Item definition. |
| 126 struct Item { | 126 struct Item { |
| 127 Item(ItemType item_type, | 127 Item(ItemType item_type, |
| 128 const std::string& item_label, | 128 const std::string& item_label, |
| 129 ui::MenuModel* item_submenu) | 129 ui::MenuModel* item_submenu) |
| 130 : type(item_type), | 130 : type(item_type), |
| 131 label(base::ASCIIToUTF16(item_label)), | 131 label(base::ASCIIToUTF16(item_label)), |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 submodel->set_last_activation(-1); | 300 submodel->set_last_activation(-1); |
| 301 } | 301 } |
| 302 | 302 |
| 303 // Check that selecting the root item is safe. The MenuModel does | 303 // Check that selecting the root item is safe. The MenuModel does |
| 304 // not care about the root so MenuModelAdapter should do nothing | 304 // not care about the root so MenuModelAdapter should do nothing |
| 305 // (not hit the NOTREACHED check) when the root is selected. | 305 // (not hit the NOTREACHED check) when the root is selected. |
| 306 static_cast<views::MenuDelegate*>(&delegate)->SelectionChanged(menu); | 306 static_cast<views::MenuDelegate*>(&delegate)->SelectionChanged(menu); |
| 307 } | 307 } |
| 308 | 308 |
| 309 } // namespace views | 309 } // namespace views |
| OLD | NEW |