OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/chromeos/views/native_menu_domui.h" | 5 #include "chrome/browser/chromeos/views/native_menu_domui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "chrome/browser/chromeos/dom_ui/menu_ui.h" | 11 #include "chrome/browser/chromeos/dom_ui/menu_ui.h" |
12 #include "chrome/browser/chromeos/views/domui_menu_widget.h" | |
13 #include "chrome/browser/chromeos/views/menu_locator.h" | 12 #include "chrome/browser/chromeos/views/menu_locator.h" |
| 13 #include "chrome/browser/chromeos/views/webui_menu_widget.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
17 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
19 #include "gfx/rect.h" | 19 #include "gfx/rect.h" |
20 #include "ui/base/models/menu_model.h" | 20 #include "ui/base/models/menu_model.h" |
21 #include "views/controls/menu/menu_2.h" | 21 #include "views/controls/menu/menu_2.h" |
22 #include "views/controls/menu/nested_dispatcher_gtk.h" | 22 #include "views/controls/menu/nested_dispatcher_gtk.h" |
23 | 23 |
24 #if defined(TOUCH_UI) | 24 #if defined(TOUCH_UI) |
25 #include "views/focus/accelerator_handler.h" | 25 #include "views/focus/accelerator_handler.h" |
26 #include "views/controls/menu/native_menu_x.h" | 26 #include "views/controls/menu/native_menu_x.h" |
27 #else | 27 #else |
28 #include "views/controls/menu/native_menu_gtk.h" | 28 #include "views/controls/menu/native_menu_gtk.h" |
29 #endif | 29 #endif |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 using chromeos::NativeMenuDOMUI; | 33 using chromeos::NativeMenuDOMUI; |
34 using chromeos::DOMUIMenuWidget; | 34 using chromeos::WebUIMenuWidget; |
35 | 35 |
36 // Returns true if the menu item type specified can be executed as a command. | 36 // Returns true if the menu item type specified can be executed as a command. |
37 bool MenuTypeCanExecute(ui::MenuModel::ItemType type) { | 37 bool MenuTypeCanExecute(ui::MenuModel::ItemType type) { |
38 return type == ui::MenuModel::TYPE_COMMAND || | 38 return type == ui::MenuModel::TYPE_COMMAND || |
39 type == ui::MenuModel::TYPE_CHECK || | 39 type == ui::MenuModel::TYPE_CHECK || |
40 type == ui::MenuModel::TYPE_RADIO; | 40 type == ui::MenuModel::TYPE_RADIO; |
41 } | 41 } |
42 | 42 |
43 gboolean Destroy(GtkWidget* widget, gpointer data) { | 43 gboolean Destroy(GtkWidget* widget, gpointer data) { |
44 DOMUIMenuWidget* menu_widget = static_cast<DOMUIMenuWidget*>(data); | 44 WebUIMenuWidget* menu_widget = static_cast<WebUIMenuWidget*>(data); |
45 NativeMenuDOMUI* domui_menu = menu_widget->domui_menu(); | 45 NativeMenuDOMUI* domui_menu = menu_widget->domui_menu(); |
46 // domui_menu can be NULL if widget is destroyed by signal. | 46 // domui_menu can be NULL if widget is destroyed by signal. |
47 if (domui_menu) | 47 if (domui_menu) |
48 domui_menu->Hide(); | 48 domui_menu->Hide(); |
49 return true; | 49 return true; |
50 } | 50 } |
51 | 51 |
52 // Returns the active toplevel window. | 52 // Returns the active toplevel window. |
53 gfx::NativeWindow FindActiveToplevelWindow() { | 53 gfx::NativeWindow FindActiveToplevelWindow() { |
54 GList* toplevels = gtk_window_list_toplevels(); | 54 GList* toplevels = gtk_window_list_toplevels(); |
(...skipping 15 matching lines...) Expand all Loading... |
70 namespace chromeos { | 70 namespace chromeos { |
71 | 71 |
72 // static | 72 // static |
73 void NativeMenuDOMUI::SetMenuURL(views::Menu2* menu2, const GURL& url) { | 73 void NativeMenuDOMUI::SetMenuURL(views::Menu2* menu2, const GURL& url) { |
74 // No-op if DOMUI menu is disabled. | 74 // No-op if DOMUI menu is disabled. |
75 if (!MenuUI::IsEnabled()) | 75 if (!MenuUI::IsEnabled()) |
76 return; | 76 return; |
77 | 77 |
78 gfx::NativeView native = menu2->GetNativeMenu(); | 78 gfx::NativeView native = menu2->GetNativeMenu(); |
79 DCHECK(native); | 79 DCHECK(native); |
80 DOMUIMenuWidget* widget = DOMUIMenuWidget::FindDOMUIMenuWidget(native); | 80 WebUIMenuWidget* widget = WebUIMenuWidget::FindWebUIMenuWidget(native); |
81 DCHECK(widget); | 81 DCHECK(widget); |
82 widget->domui_menu()->set_menu_url(url); | 82 widget->domui_menu()->set_menu_url(url); |
83 } | 83 } |
84 | 84 |
85 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
86 // NativeMenuDOMUI, public: | 86 // NativeMenuDOMUI, public: |
87 | 87 |
88 NativeMenuDOMUI::NativeMenuDOMUI(ui::MenuModel* menu_model, bool root) | 88 NativeMenuDOMUI::NativeMenuDOMUI(ui::MenuModel* menu_model, bool root) |
89 : parent_(NULL), | 89 : parent_(NULL), |
90 submenu_(NULL), | 90 submenu_(NULL), |
91 model_(menu_model), | 91 model_(menu_model), |
92 menu_widget_(NULL), | 92 menu_widget_(NULL), |
93 menu_shown_(false), | 93 menu_shown_(false), |
94 activated_menu_(NULL), | 94 activated_menu_(NULL), |
95 activated_index_(-1), | 95 activated_index_(-1), |
96 menu_action_(MENU_ACTION_NONE), | 96 menu_action_(MENU_ACTION_NONE), |
97 menu_url_(StringPrintf("chrome://%s", chrome::kChromeUIMenu)), | 97 menu_url_(StringPrintf("chrome://%s", chrome::kChromeUIMenu)), |
98 on_menu_opened_called_(false), | 98 on_menu_opened_called_(false), |
99 nested_dispatcher_(NULL) { | 99 nested_dispatcher_(NULL) { |
100 menu_widget_ = new DOMUIMenuWidget(this, root); | 100 menu_widget_ = new WebUIMenuWidget(this, root); |
101 // Set the initial location off the screen not to show small | 101 // Set the initial location off the screen not to show small |
102 // window with dropshadow. | 102 // window with dropshadow. |
103 menu_widget_->Init(NULL, gfx::Rect(-10000, -10000, 1, 1)); | 103 menu_widget_->Init(NULL, gfx::Rect(-10000, -10000, 1, 1)); |
104 } | 104 } |
105 | 105 |
106 NativeMenuDOMUI::~NativeMenuDOMUI() { | 106 NativeMenuDOMUI::~NativeMenuDOMUI() { |
107 if (nested_dispatcher_) { | 107 if (nested_dispatcher_) { |
108 // Menu is destroyed while its in message loop. | 108 // Menu is destroyed while its in message loop. |
109 // Let nested dispatcher know the creator is deleted. | 109 // Let nested dispatcher know the creator is deleted. |
110 nested_dispatcher_->CreatorDestroyed(); | 110 nested_dispatcher_->CreatorDestroyed(); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 NativeMenuDOMUI* found = submenu_->FindMenuAt(point); | 393 NativeMenuDOMUI* found = submenu_->FindMenuAt(point); |
394 if (found) | 394 if (found) |
395 return found; | 395 return found; |
396 } | 396 } |
397 gfx::Rect bounds; | 397 gfx::Rect bounds; |
398 menu_widget_->GetBounds(&bounds, false); | 398 menu_widget_->GetBounds(&bounds, false); |
399 return bounds.Contains(point) ? this : NULL; | 399 return bounds.Contains(point) ? this : NULL; |
400 } | 400 } |
401 | 401 |
402 } // namespace chromeos | 402 } // namespace chromeos |
OLD | NEW |