OLD | NEW |
1 // Copyright (c) 2011 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 "views/controls/menu/menu_host.h" | 5 #include "views/controls/menu/menu_host.h" |
6 | 6 |
7 #include "views/controls/menu/menu_controller.h" | 7 #include "views/controls/menu/menu_controller.h" |
8 #include "views/controls/menu/menu_host_root_view.h" | 8 #include "views/controls/menu/menu_host_root_view.h" |
9 #include "views/controls/menu/menu_item_view.h" | 9 #include "views/controls/menu/menu_item_view.h" |
10 #include "views/controls/menu/native_menu_host.h" | 10 #include "views/controls/menu/native_menu_host.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 destroying_(false) { | 24 destroying_(false) { |
25 } | 25 } |
26 | 26 |
27 MenuHost::~MenuHost() { | 27 MenuHost::~MenuHost() { |
28 } | 28 } |
29 | 29 |
30 void MenuHost::InitMenuHost(gfx::NativeWindow parent, | 30 void MenuHost::InitMenuHost(gfx::NativeWindow parent, |
31 const gfx::Rect& bounds, | 31 const gfx::Rect& bounds, |
32 View* contents_view, | 32 View* contents_view, |
33 bool do_capture) { | 33 bool do_capture) { |
34 Widget::InitParams params; | 34 Widget::InitParams params(Widget::InitParams::TYPE_MENU); |
35 params.type = Widget::InitParams::TYPE_MENU; | |
36 params.has_dropshadow = true; | 35 params.has_dropshadow = true; |
37 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
38 params.parent = parent; | 37 params.parent = parent; |
39 #elif defined(TOOLKIT_USES_GTK) | 38 #elif defined(TOOLKIT_USES_GTK) |
40 params.parent = GTK_WIDGET(parent); | 39 params.parent = GTK_WIDGET(parent); |
41 #endif | 40 #endif |
42 params.bounds = bounds; | 41 params.bounds = bounds; |
| 42 params.native_widget = native_menu_host_->AsNativeWidget(); |
43 GetWidget()->Init(params); | 43 GetWidget()->Init(params); |
44 GetWidget()->SetContentsView(contents_view); | 44 GetWidget()->SetContentsView(contents_view); |
45 ShowMenuHost(do_capture); | 45 ShowMenuHost(do_capture); |
46 } | 46 } |
47 | 47 |
48 bool MenuHost::IsMenuHostVisible() { | 48 bool MenuHost::IsMenuHostVisible() { |
49 return GetWidget()->IsVisible(); | 49 return GetWidget()->IsVisible(); |
50 } | 50 } |
51 | 51 |
52 void MenuHost::ShowMenuHost(bool do_capture) { | 52 void MenuHost::ShowMenuHost(bool do_capture) { |
(...skipping 25 matching lines...) Expand all Loading... |
78 | 78 |
79 Widget* MenuHost::GetWidget() { | 79 Widget* MenuHost::GetWidget() { |
80 return native_menu_host_->AsNativeWidget()->GetWidget(); | 80 return native_menu_host_->AsNativeWidget()->GetWidget(); |
81 } | 81 } |
82 | 82 |
83 NativeWidget* MenuHost::GetNativeWidget() { | 83 NativeWidget* MenuHost::GetNativeWidget() { |
84 return native_menu_host_->AsNativeWidget(); | 84 return native_menu_host_->AsNativeWidget(); |
85 } | 85 } |
86 | 86 |
87 //////////////////////////////////////////////////////////////////////////////// | 87 //////////////////////////////////////////////////////////////////////////////// |
| 88 // MenuHost, Widget overrides: |
| 89 |
| 90 |
| 91 RootView* MenuHost::CreateRootView() { |
| 92 return new MenuHostRootView(GetWidget(), submenu_); |
| 93 } |
| 94 |
| 95 bool MenuHost::ShouldReleaseCaptureOnMouseReleased() const { |
| 96 return false; |
| 97 } |
| 98 |
| 99 //////////////////////////////////////////////////////////////////////////////// |
88 // MenuHost, internal::NativeMenuHostDelegate implementation: | 100 // MenuHost, internal::NativeMenuHostDelegate implementation: |
89 | 101 |
90 void MenuHost::OnNativeMenuHostDestroy() { | 102 void MenuHost::OnNativeMenuHostDestroy() { |
91 if (!destroying_) { | 103 if (!destroying_) { |
92 // We weren't explicitly told to destroy ourselves, which means the menu was | 104 // We weren't explicitly told to destroy ourselves, which means the menu was |
93 // deleted out from under us (the window we're parented to was closed). Tell | 105 // deleted out from under us (the window we're parented to was closed). Tell |
94 // the SubmenuView to drop references to us. | 106 // the SubmenuView to drop references to us. |
95 submenu_->MenuHostDestroyed(); | 107 submenu_->MenuHostDestroyed(); |
96 } | 108 } |
97 } | 109 } |
98 | 110 |
99 void MenuHost::OnNativeMenuHostCancelCapture() { | 111 void MenuHost::OnNativeMenuHostCancelCapture() { |
100 if (destroying_) | 112 if (destroying_) |
101 return; | 113 return; |
102 MenuController* menu_controller = | 114 MenuController* menu_controller = |
103 submenu_->GetMenuItem()->GetMenuController(); | 115 submenu_->GetMenuItem()->GetMenuController(); |
104 if (menu_controller && !menu_controller->drag_in_progress()) | 116 if (menu_controller && !menu_controller->drag_in_progress()) |
105 menu_controller->CancelAll(); | 117 menu_controller->CancelAll(); |
106 } | 118 } |
107 | 119 |
108 RootView* MenuHost::CreateRootView() { | 120 internal::NativeWidgetDelegate* MenuHost::AsNativeWidgetDelegate() { |
109 return new MenuHostRootView(GetWidget(), submenu_); | 121 return this; |
110 } | |
111 | |
112 bool MenuHost::ShouldReleaseCaptureOnMouseRelease() const { | |
113 return false; | |
114 } | 122 } |
115 | 123 |
116 } // namespace views | 124 } // namespace views |
OLD | NEW |