| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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_CHROMEOS_WEBUI_MENU_UI_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_WEBUI_MENU_UI_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
| 12 #include "content/browser/webui/web_ui.h" | |
| 13 | |
| 14 class DictionaryValue; | |
| 15 | |
| 16 namespace ui{ | |
| 17 class MenuModel; | |
| 18 } // namespace ui | |
| 19 | |
| 20 namespace chromeos { | |
| 21 | |
| 22 class WebUIMenuControl; | |
| 23 | |
| 24 // MenuSourceDelegate class allows subclass to injects specific values | |
| 25 // to menu javascript code. | |
| 26 class MenuSourceDelegate { | |
| 27 public: | |
| 28 virtual ~MenuSourceDelegate() {} | |
| 29 // Subclass can add extra parameters or replaces default configuration. | |
| 30 virtual void AddCustomConfigValues(DictionaryValue* config) const {} | |
| 31 | |
| 32 // Subclass can add their values to |localized_strings| and those values | |
| 33 // are used by JS template builder and could be accessed via JS class | |
| 34 // LocalStrings. | |
| 35 virtual void AddLocalizedStrings(DictionaryValue* localized_strings) const {} | |
| 36 }; | |
| 37 | |
| 38 class MenuUI : public WebUI { | |
| 39 public: | |
| 40 explicit MenuUI(TabContents* contents); | |
| 41 | |
| 42 // A callback method that is invoked when a menu model associated | |
| 43 // with the WebUI Menu gets updated. | |
| 44 virtual void ModelUpdated(const ui::MenuModel* new_model); | |
| 45 | |
| 46 // Creates a menu item for the menu item at index in the model. | |
| 47 virtual DictionaryValue* CreateMenuItem(const ui::MenuModel* model, | |
| 48 int index, | |
| 49 const char* type, | |
| 50 int* max_icon_width, | |
| 51 bool* has_accel) const; | |
| 52 | |
| 53 // A utility function which creates a concrete html file from | |
| 54 // template file |menu_resource_id| and |menu_css_id| for given |menu_class|. | |
| 55 // The resource_name is the host part of WebUI's url. | |
| 56 static ChromeURLDataManager::DataSource* CreateMenuUIHTMLSource( | |
| 57 const MenuSourceDelegate* delegate, | |
| 58 const std::string& source_name, | |
| 59 const std::string& menu_class, | |
| 60 int menu_source_res_id, | |
| 61 int menu_css_res_id); | |
| 62 | |
| 63 // Returns true if DMOUI menu is enabled. | |
| 64 static bool IsEnabled(); | |
| 65 | |
| 66 protected: | |
| 67 // A constructor for subclass to initialize the MenuUI with | |
| 68 // different data source. | |
| 69 MenuUI(TabContents* contents, ChromeURLDataManager::DataSource* source); | |
| 70 | |
| 71 private: | |
| 72 // Create HTML Data source for the menu. | |
| 73 ChromeURLDataManager::DataSource* CreateDataSource(); | |
| 74 | |
| 75 DISALLOW_COPY_AND_ASSIGN(MenuUI); | |
| 76 }; | |
| 77 | |
| 78 // Base class for MenuUI's WebUIMessageHandler. | |
| 79 class MenuHandlerBase : public WebUIMessageHandler { | |
| 80 public: | |
| 81 MenuHandlerBase() : WebUIMessageHandler() {} | |
| 82 | |
| 83 // Returns the menu control that is associated with the | |
| 84 // MenuUI. This may return null when menu is being deleted. | |
| 85 WebUIMenuControl* GetMenuControl(); | |
| 86 | |
| 87 // Returns the menu model for this menu ui. | |
| 88 // This may return null when menu is being deleted. | |
| 89 ui::MenuModel* GetMenuModel(); | |
| 90 | |
| 91 private: | |
| 92 DISALLOW_COPY_AND_ASSIGN(MenuHandlerBase); | |
| 93 }; | |
| 94 | |
| 95 } // namespace chromeos | |
| 96 | |
| 97 #endif // CHROME_BROWSER_CHROMEOS_WEBUI_MENU_UI_H_ | |
| OLD | NEW |