wrench_menu_model.h revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_ 6#define CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_ 7#pragma once 8 9#include "base/scoped_ptr.h" 10#include "chrome/browser/tabs/tab_strip_model_observer.h" 11#include "chrome/common/notification_observer.h" 12#include "chrome/common/notification_registrar.h" 13#include "ui/base/models/accelerator.h" 14#include "ui/base/models/button_menu_item_model.h" 15#include "ui/base/models/simple_menu_model.h" 16 17class Browser; 18class TabStripModel; 19 20namespace { 21class MockWrenchMenuModel; 22} // namespace 23 24// A menu model that builds the contents of an encoding menu. 25class EncodingMenuModel : public ui::SimpleMenuModel, 26 public ui::SimpleMenuModel::Delegate { 27 public: 28 explicit EncodingMenuModel(Browser* browser); 29 virtual ~EncodingMenuModel(); 30 31 // Overridden from ui::SimpleMenuModel::Delegate: 32 virtual bool IsCommandIdChecked(int command_id) const; 33 virtual bool IsCommandIdEnabled(int command_id) const; 34 virtual bool GetAcceleratorForCommandId(int command_id, 35 ui::Accelerator* accelerator); 36 virtual void ExecuteCommand(int command_id); 37 38 private: 39 void Build(); 40 41 Browser* browser_; // weak 42 43 DISALLOW_COPY_AND_ASSIGN(EncodingMenuModel); 44}; 45 46// A menu model that builds the contents of the zoom menu. 47class ZoomMenuModel : public ui::SimpleMenuModel { 48 public: 49 explicit ZoomMenuModel(ui::SimpleMenuModel::Delegate* delegate); 50 virtual ~ZoomMenuModel(); 51 52 private: 53 void Build(); 54 55 DISALLOW_COPY_AND_ASSIGN(ZoomMenuModel); 56}; 57 58class ToolsMenuModel : public ui::SimpleMenuModel { 59 public: 60 ToolsMenuModel(ui::SimpleMenuModel::Delegate* delegate, Browser* browser); 61 virtual ~ToolsMenuModel(); 62 63 private: 64 void Build(Browser* browser); 65 66 scoped_ptr<EncodingMenuModel> encoding_menu_model_; 67 68 DISALLOW_COPY_AND_ASSIGN(ToolsMenuModel); 69}; 70 71// A menu model that builds the contents of the wrench menu. 72class WrenchMenuModel : public ui::SimpleMenuModel, 73 public ui::SimpleMenuModel::Delegate, 74 public ui::ButtonMenuItemModel::Delegate, 75 public TabStripModelObserver, 76 public NotificationObserver { 77 public: 78 WrenchMenuModel(ui::AcceleratorProvider* provider, Browser* browser); 79 virtual ~WrenchMenuModel(); 80 81 // Overridden for ButtonMenuItemModel::Delegate: 82 virtual bool DoesCommandIdDismissMenu(int command_id) const; 83 84 // Overridden for both ButtonMenuItemModel::Delegate and SimpleMenuModel: 85 virtual bool IsItemForCommandIdDynamic(int command_id) const; 86 virtual string16 GetLabelForCommandId(int command_id) const; 87 virtual void ExecuteCommand(int command_id); 88 virtual bool IsCommandIdChecked(int command_id) const; 89 virtual bool IsCommandIdEnabled(int command_id) const; 90 virtual bool IsCommandIdVisible(int command_id) const; 91 virtual bool GetAcceleratorForCommandId( 92 int command_id, 93 ui::Accelerator* accelerator); 94 95 // Overridden from TabStripModelObserver: 96 virtual void TabSelectedAt(TabContentsWrapper* old_contents, 97 TabContentsWrapper* new_contents, 98 int index, 99 bool user_gesture); 100 virtual void TabReplacedAt(TabStripModel* tab_strip_model, 101 TabContentsWrapper* old_contents, 102 TabContentsWrapper* new_contents, 103 int index); 104 virtual void TabStripModelDeleted(); 105 106 // Overridden from NotificationObserver: 107 virtual void Observe(NotificationType type, 108 const NotificationSource& source, 109 const NotificationDetails& details); 110 111 // Getters. 112 Browser* browser() const { return browser_; } 113 114 // Calculates |zoom_label_| in response to a zoom change. 115 void UpdateZoomControls(); 116 117 private: 118 // Testing constructor used for mocking. 119 friend class ::MockWrenchMenuModel; 120 WrenchMenuModel(); 121 122 void Build(); 123 124 // Adds custom items to the menu. Deprecated in favor of a cross platform 125 // model for button items. 126 void CreateCutCopyPaste(); 127 void CreateZoomFullscreen(); 128 129 string16 GetSyncMenuLabel() const; 130 131 // Models for the special menu items with buttons. 132 scoped_ptr<ui::ButtonMenuItemModel> edit_menu_item_model_; 133 scoped_ptr<ui::ButtonMenuItemModel> zoom_menu_item_model_; 134 135 // Label of the zoom label in the zoom menu item. 136 string16 zoom_label_; 137 138 // Tools menu. 139 scoped_ptr<ToolsMenuModel> tools_menu_model_; 140 141 ui::AcceleratorProvider* provider_; // weak 142 143 Browser* browser_; // weak 144 TabStripModel* tabstrip_model_; // weak 145 146 NotificationRegistrar registrar_; 147 148 DISALLOW_COPY_AND_ASSIGN(WrenchMenuModel); 149}; 150 151#endif // CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_ 152