Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: views/controls/menu/menu_host.cc

Issue 7390032: Fixes regression from menu refactoring. The old windows code wasn't (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename field Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/menu/menu_host.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "views/controls/menu/submenu_view.h" 11 #include "views/controls/menu/submenu_view.h"
12 #include "views/widget/native_widget_private.h" 12 #include "views/widget/native_widget_private.h"
13 #include "views/widget/widget.h" 13 #include "views/widget/widget.h"
14 14
15 namespace views { 15 namespace views {
16 16
17 //////////////////////////////////////////////////////////////////////////////// 17 ////////////////////////////////////////////////////////////////////////////////
18 // MenuHost, public: 18 // MenuHost, public:
19 19
20 MenuHost::MenuHost(SubmenuView* submenu) 20 MenuHost::MenuHost(SubmenuView* submenu)
21 : submenu_(submenu), 21 : submenu_(submenu),
22 destroying_(false), 22 destroying_(false),
23 showing_(false) { 23 ignore_capture_lost_(false) {
24 } 24 }
25 25
26 MenuHost::~MenuHost() { 26 MenuHost::~MenuHost() {
27 } 27 }
28 28
29 void MenuHost::InitMenuHost(gfx::NativeWindow parent, 29 void MenuHost::InitMenuHost(gfx::NativeWindow parent,
30 const gfx::Rect& bounds, 30 const gfx::Rect& bounds,
31 View* contents_view, 31 View* contents_view,
32 bool do_capture) { 32 bool do_capture) {
33 Widget::InitParams params(Widget::InitParams::TYPE_MENU); 33 Widget::InitParams params(Widget::InitParams::TYPE_MENU);
34 params.has_dropshadow = true; 34 params.has_dropshadow = true;
35 #if defined(OS_WIN) 35 #if defined(OS_WIN)
36 params.parent = parent; 36 params.parent = parent;
37 #elif defined(TOOLKIT_USES_GTK) 37 #elif defined(TOOLKIT_USES_GTK)
38 params.parent = GTK_WIDGET(parent); 38 params.parent = GTK_WIDGET(parent);
39 #endif 39 #endif
40 params.bounds = bounds; 40 params.bounds = bounds;
41 Init(params); 41 Init(params);
42 SetContentsView(contents_view); 42 SetContentsView(contents_view);
43 ShowMenuHost(do_capture); 43 ShowMenuHost(do_capture);
44 } 44 }
45 45
46 bool MenuHost::IsMenuHostVisible() { 46 bool MenuHost::IsMenuHostVisible() {
47 return IsVisible(); 47 return IsVisible();
48 } 48 }
49 49
50 void MenuHost::ShowMenuHost(bool do_capture) { 50 void MenuHost::ShowMenuHost(bool do_capture) {
51 // Doing a capture may make us get capture lost. Ignore it while we're in the 51 // Doing a capture may make us get capture lost. Ignore it while we're in the
52 // process of showing. 52 // process of showing.
53 showing_ = true; 53 ignore_capture_lost_ = true;
54 Show(); 54 Show();
55 if (do_capture) { 55 if (do_capture) {
56 native_widget_private()->SetMouseCapture(); 56 native_widget_private()->SetMouseCapture();
57 // We do this to effectively disable window manager keyboard accelerators 57 // We do this to effectively disable window manager keyboard accelerators
58 // for chromeos. Such accelerators could cause cause another window to 58 // for chromeos. Such accelerators could cause cause another window to
59 // become active and confuse things. 59 // become active and confuse things.
60 native_widget_private()->SetKeyboardCapture(); 60 native_widget_private()->SetKeyboardCapture();
61 } 61 }
62 showing_ = false; 62 ignore_capture_lost_ = false;
63 } 63 }
64 64
65 void MenuHost::HideMenuHost() { 65 void MenuHost::HideMenuHost() {
66 ignore_capture_lost_ = true;
66 ReleaseMenuHostCapture(); 67 ReleaseMenuHostCapture();
67 Hide(); 68 Hide();
69 ignore_capture_lost_ = false;
68 } 70 }
69 71
70 void MenuHost::DestroyMenuHost() { 72 void MenuHost::DestroyMenuHost() {
71 HideMenuHost(); 73 HideMenuHost();
72 destroying_ = true; 74 destroying_ = true;
73 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu(); 75 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu();
74 Close(); 76 Close();
75 } 77 }
76 78
77 void MenuHost::SetMenuHostBounds(const gfx::Rect& bounds) { 79 void MenuHost::SetMenuHostBounds(const gfx::Rect& bounds) {
(...skipping 12 matching lines...) Expand all
90 92
91 internal::RootView* MenuHost::CreateRootView() { 93 internal::RootView* MenuHost::CreateRootView() {
92 return new MenuHostRootView(this, submenu_); 94 return new MenuHostRootView(this, submenu_);
93 } 95 }
94 96
95 bool MenuHost::ShouldReleaseCaptureOnMouseReleased() const { 97 bool MenuHost::ShouldReleaseCaptureOnMouseReleased() const {
96 return false; 98 return false;
97 } 99 }
98 100
99 void MenuHost::OnMouseCaptureLost() { 101 void MenuHost::OnMouseCaptureLost() {
100 if (destroying_ || showing_) 102 if (destroying_ || ignore_capture_lost_)
101 return; 103 return;
102 MenuController* menu_controller = 104 MenuController* menu_controller =
103 submenu_->GetMenuItem()->GetMenuController(); 105 submenu_->GetMenuItem()->GetMenuController();
104 if (menu_controller && !menu_controller->drag_in_progress()) 106 if (menu_controller && !menu_controller->drag_in_progress())
105 menu_controller->CancelAll(); 107 menu_controller->CancelAll();
106 Widget::OnMouseCaptureLost(); 108 Widget::OnMouseCaptureLost();
107 } 109 }
108 110
109 void MenuHost::OnNativeWidgetDestroyed() { 111 void MenuHost::OnNativeWidgetDestroyed() {
110 if (!destroying_) { 112 if (!destroying_) {
111 // We weren't explicitly told to destroy ourselves, which means the menu was 113 // We weren't explicitly told to destroy ourselves, which means the menu was
112 // deleted out from under us (the window we're parented to was closed). Tell 114 // deleted out from under us (the window we're parented to was closed). Tell
113 // the SubmenuView to drop references to us. 115 // the SubmenuView to drop references to us.
114 submenu_->MenuHostDestroyed(); 116 submenu_->MenuHostDestroyed();
115 } 117 }
116 Widget::OnNativeWidgetDestroyed(); 118 Widget::OnNativeWidgetDestroyed();
117 } 119 }
118 120
119 } // namespace views 121 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/menu/menu_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698