| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_WRENCH_MENU_MODEL_H_ | 5 #ifndef CHROME_BROWSER_WRENCH_MENU_MODEL_H_ |
| 6 #define CHROME_BROWSER_WRENCH_MENU_MODEL_H_ | 6 #define CHROME_BROWSER_WRENCH_MENU_MODEL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "app/menus/accelerator.h" |
| 9 #include "app/menus/button_menu_item_model.h" | 10 #include "app/menus/button_menu_item_model.h" |
| 10 #include "app/menus/simple_menu_model.h" | 11 #include "app/menus/simple_menu_model.h" |
| 11 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 12 #include "chrome/browser/tabs/tab_strip_model.h" | 13 #include "chrome/browser/tabs/tab_strip_model.h" |
| 13 #include "chrome/common/notification_observer.h" | 14 #include "chrome/common/notification_observer.h" |
| 14 #include "chrome/common/notification_registrar.h" | 15 #include "chrome/common/notification_registrar.h" |
| 15 | 16 |
| 16 class Browser; | 17 class Browser; |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 61 |
| 61 private: | 62 private: |
| 62 void Build(Browser* browser); | 63 void Build(Browser* browser); |
| 63 | 64 |
| 64 scoped_ptr<EncodingMenuModel> encoding_menu_model_; | 65 scoped_ptr<EncodingMenuModel> encoding_menu_model_; |
| 65 | 66 |
| 66 DISALLOW_COPY_AND_ASSIGN(ToolsMenuModel); | 67 DISALLOW_COPY_AND_ASSIGN(ToolsMenuModel); |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 // A menu model that builds the contents of the wrench menu. | 70 // A menu model that builds the contents of the wrench menu. |
| 70 class WrenchMenuModel : public menus::SimpleMenuModel, | 71 class WrenchMenuModel : public menus::SimpleMenuModel::Delegate, |
| 71 public menus::ButtonMenuItemModel::Delegate, | 72 public menus::ButtonMenuItemModel::Delegate, |
| 72 public TabStripModelObserver, | 73 public TabStripModelObserver, |
| 73 public NotificationObserver { | 74 public NotificationObserver { |
| 74 public: | 75 public: |
| 75 WrenchMenuModel(menus::SimpleMenuModel::Delegate* delegate, | 76 WrenchMenuModel(menus::AcceleratorProvider* provider, Browser* browser); |
| 76 Browser* browser); | |
| 77 virtual ~WrenchMenuModel(); | 77 virtual ~WrenchMenuModel(); |
| 78 | 78 |
| 79 // Overridden from menus::SimpleMenuModel: | 79 // Overridden for both ButtonMenuItemModel::Delegate and SimpleMenuModel: |
| 80 virtual bool IsLabelDynamicAt(int index) const; | |
| 81 virtual string16 GetLabelAt(int index) const; | |
| 82 virtual bool HasIcons() const { return true; } | |
| 83 virtual bool GetIconAt(int index, SkBitmap* icon) const; | |
| 84 | |
| 85 // Overridden from menus::ButtonMenuItemModel::Delegate: | |
| 86 virtual bool IsLabelForCommandIdDynamic(int command_id) const; | 80 virtual bool IsLabelForCommandIdDynamic(int command_id) const; |
| 87 virtual string16 GetLabelForCommandId(int command_id) const; | 81 virtual string16 GetLabelForCommandId(int command_id) const; |
| 88 virtual void ExecuteCommand(int command_id); | 82 virtual void ExecuteCommand(int command_id); |
| 83 virtual bool IsCommandIdChecked(int command_id) const; |
| 89 virtual bool IsCommandIdEnabled(int command_id) const; | 84 virtual bool IsCommandIdEnabled(int command_id) const; |
| 85 virtual bool GetAcceleratorForCommandId( |
| 86 int command_id, |
| 87 menus::Accelerator* accelerator); |
| 90 | 88 |
| 91 // Overridden from TabStripModelObserver: | 89 // Overridden from TabStripModelObserver: |
| 92 virtual void TabSelectedAt(TabContents* old_contents, | 90 virtual void TabSelectedAt(TabContents* old_contents, |
| 93 TabContents* new_contents, | 91 TabContents* new_contents, |
| 94 int index, | 92 int index, |
| 95 bool user_gesture); | 93 bool user_gesture); |
| 96 virtual void TabReplacedAt(TabContents* old_contents, | 94 virtual void TabReplacedAt(TabContents* old_contents, |
| 97 TabContents* new_contents, int index); | 95 TabContents* new_contents, int index); |
| 98 virtual void TabStripModelDeleted(); | 96 virtual void TabStripModelDeleted(); |
| 99 | 97 |
| 100 // Overridden from NotificationObserver: | 98 // Overridden from NotificationObserver: |
| 101 virtual void Observe(NotificationType type, | 99 virtual void Observe(NotificationType type, |
| 102 const NotificationSource& source, | 100 const NotificationSource& source, |
| 103 const NotificationDetails& details); | 101 const NotificationDetails& details); |
| 104 | 102 |
| 105 // Getters. | 103 // Getters. |
| 106 Browser* browser() const { return browser_; } | 104 Browser* browser() const { return browser_; } |
| 105 menus::SimpleMenuModel* menu_model() { return &model_; } |
| 107 | 106 |
| 108 // Calculates |zoom_label_| in response to a zoom change. | 107 // Calculates |zoom_label_| in response to a zoom change. |
| 109 void UpdateZoomControls(); | 108 void UpdateZoomControls(); |
| 110 | 109 |
| 111 private: | 110 private: |
| 112 // Testing constructor used for mocking. | 111 // Testing constructor used for mocking. |
| 113 friend class ::MockWrenchMenuModel; | 112 friend class ::MockWrenchMenuModel; |
| 114 WrenchMenuModel() : menus::SimpleMenuModel(NULL) {} | 113 WrenchMenuModel(); |
| 115 | 114 |
| 116 void Build(); | 115 void Build(); |
| 117 | 116 |
| 118 // Adds custom items to the menu. Deprecated in favor of a cross platform | 117 // Adds custom items to the menu. Deprecated in favor of a cross platform |
| 119 // model for button items. | 118 // model for button items. |
| 120 void CreateCutCopyPaste(); | 119 void CreateCutCopyPaste(); |
| 121 void CreateZoomFullscreen(); | 120 void CreateZoomFullscreen(); |
| 122 | 121 |
| 123 // Gets the current zoom information from the renderer. | 122 // Gets the current zoom information from the renderer. |
| 124 double GetZoom(bool* enable_increment, bool* enable_decrement); | 123 double GetZoom(bool* enable_increment, bool* enable_decrement); |
| 125 | 124 |
| 126 string16 GetSyncMenuLabel() const; | 125 string16 GetSyncMenuLabel() const; |
| 127 string16 GetAboutEntryMenuLabel() const; | 126 string16 GetAboutEntryMenuLabel() const; |
| 128 bool IsDynamicItem(int index) const; | 127 |
| 128 // Our menu, for which we are the delegate. |
| 129 menus::SimpleMenuModel model_; |
| 129 | 130 |
| 130 // Models for the special menu items with buttons. | 131 // Models for the special menu items with buttons. |
| 131 scoped_ptr<menus::ButtonMenuItemModel> edit_menu_item_model_; | 132 scoped_ptr<menus::ButtonMenuItemModel> edit_menu_item_model_; |
| 132 scoped_ptr<menus::ButtonMenuItemModel> zoom_menu_item_model_; | 133 scoped_ptr<menus::ButtonMenuItemModel> zoom_menu_item_model_; |
| 133 | 134 |
| 134 // Label of the zoom label in the zoom menu item. | 135 // Label of the zoom label in the zoom menu item. |
| 135 string16 zoom_label_; | 136 string16 zoom_label_; |
| 136 | 137 |
| 137 // Tools menu. | 138 // Tools menu. |
| 138 scoped_ptr<ToolsMenuModel> tools_menu_model_; | 139 scoped_ptr<ToolsMenuModel> tools_menu_model_; |
| 139 | 140 |
| 140 menus::SimpleMenuModel::Delegate* delegate_; // weak | 141 menus::AcceleratorProvider* provider_; |
| 141 | 142 |
| 142 Browser* browser_; // weak | 143 Browser* browser_; // weak |
| 143 TabStripModel* tabstrip_model_; // weak | 144 TabStripModel* tabstrip_model_; // weak |
| 144 | 145 |
| 145 NotificationRegistrar registrar_; | 146 NotificationRegistrar registrar_; |
| 146 | 147 |
| 147 DISALLOW_COPY_AND_ASSIGN(WrenchMenuModel); | 148 DISALLOW_COPY_AND_ASSIGN(WrenchMenuModel); |
| 148 }; | 149 }; |
| 149 | 150 |
| 150 #endif // CHROME_BROWSER_WRENCH_MENU_MODEL_H_ | 151 #endif // CHROME_BROWSER_WRENCH_MENU_MODEL_H_ |
| OLD | NEW |