OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/menu/menu_host.h" | 5 #include "ui/views/controls/menu/menu_host.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "ui/events/gestures/gesture_recognizer.h" | 9 #include "ui/events/gestures/gesture_recognizer.h" |
10 #include "ui/gfx/path.h" | 10 #include "ui/gfx/path.h" |
11 #include "ui/native_theme/native_theme.h" | 11 #include "ui/native_theme/native_theme.h" |
12 #include "ui/views/controls/menu/menu_controller.h" | 12 #include "ui/views/controls/menu/menu_controller.h" |
13 #include "ui/views/controls/menu/menu_host_root_view.h" | 13 #include "ui/views/controls/menu/menu_host_root_view.h" |
14 #include "ui/views/controls/menu/menu_item_view.h" | 14 #include "ui/views/controls/menu/menu_item_view.h" |
15 #include "ui/views/controls/menu/menu_scroll_view_container.h" | 15 #include "ui/views/controls/menu/menu_scroll_view_container.h" |
16 #include "ui/views/controls/menu/submenu_view.h" | 16 #include "ui/views/controls/menu/submenu_view.h" |
17 #include "ui/views/round_rect_painter.h" | 17 #include "ui/views/round_rect_painter.h" |
18 #include "ui/views/widget/native_widget_private.h" | 18 #include "ui/views/widget/native_widget_private.h" |
19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
20 #include "ui/wm/core/shadow_types.h" | |
21 | 20 |
22 namespace views { | 21 namespace views { |
23 | 22 |
24 //////////////////////////////////////////////////////////////////////////////// | 23 //////////////////////////////////////////////////////////////////////////////// |
25 // MenuHost, public: | 24 // MenuHost, public: |
26 | 25 |
27 MenuHost::MenuHost(SubmenuView* submenu) | 26 MenuHost::MenuHost(SubmenuView* submenu) |
28 : submenu_(submenu), | 27 : submenu_(submenu), |
29 destroying_(false), | 28 destroying_(false), |
30 ignore_capture_lost_(false) { | 29 ignore_capture_lost_(false) { |
(...skipping 17 matching lines...) Expand all Loading... |
48 submenu_->GetScrollViewContainer()->HasBubbleBorder(); | 47 submenu_->GetScrollViewContainer()->HasBubbleBorder(); |
49 params.has_dropshadow = !bubble_border; | 48 params.has_dropshadow = !bubble_border; |
50 params.opacity = (bubble_border || rounded_border) ? | 49 params.opacity = (bubble_border || rounded_border) ? |
51 Widget::InitParams::TRANSLUCENT_WINDOW : | 50 Widget::InitParams::TRANSLUCENT_WINDOW : |
52 Widget::InitParams::OPAQUE_WINDOW; | 51 Widget::InitParams::OPAQUE_WINDOW; |
53 params.parent = parent ? parent->GetNativeView() : NULL; | 52 params.parent = parent ? parent->GetNativeView() : NULL; |
54 params.bounds = bounds; | 53 params.bounds = bounds; |
55 Init(params); | 54 Init(params); |
56 | 55 |
57 if (bubble_border) | 56 if (bubble_border) |
58 SetShadowType(GetNativeView(), wm::SHADOW_TYPE_NONE); | 57 SetHasActivationShadow(false); |
59 | 58 |
60 SetContentsView(contents_view); | 59 SetContentsView(contents_view); |
61 if (bubble_border || rounded_border) | 60 if (bubble_border || rounded_border) |
62 SetOpacity(0); | 61 SetOpacity(0); |
63 ShowMenuHost(do_capture); | 62 ShowMenuHost(do_capture); |
64 } | 63 } |
65 | 64 |
66 bool MenuHost::IsMenuHostVisible() { | 65 bool MenuHost::IsMenuHostVisible() { |
67 return IsVisible(); | 66 return IsVisible(); |
68 } | 67 } |
69 | 68 |
70 void MenuHost::ShowMenuHost(bool do_capture) { | 69 void MenuHost::ShowMenuHost(bool do_capture) { |
71 // Doing a capture may make us get capture lost. Ignore it while we're in the | 70 // Doing a capture may make us get capture lost. Ignore it while we're in the |
72 // process of showing. | 71 // process of showing. |
73 base::AutoReset<bool> reseter(&ignore_capture_lost_, true); | 72 base::AutoReset<bool> reseter(&ignore_capture_lost_, true); |
74 ShowInactive(); | 73 ShowInactive(); |
75 if (do_capture) { | 74 if (do_capture) { |
76 // Cancel existing touches, so we don't miss some touch release/cancel | 75 // Cancel existing touches, so we don't miss some touch release/cancel |
77 // events due to the menu taking capture. | 76 // events due to the menu taking capture. |
78 ui::GestureRecognizer::Get()->TransferEventsTo(GetNativeWindow(), NULL); | 77 ui::GestureRecognizer::Get()->TransferEventsTo(NULL, NULL); |
79 native_widget_private()->SetCapture(); | 78 native_widget_private()->SetCapture(); |
80 } | 79 } |
81 } | 80 } |
82 | 81 |
83 void MenuHost::HideMenuHost() { | 82 void MenuHost::HideMenuHost() { |
84 ignore_capture_lost_ = true; | 83 ignore_capture_lost_ = true; |
85 ReleaseMenuHostCapture(); | 84 ReleaseMenuHostCapture(); |
86 Hide(); | 85 Hide(); |
87 ignore_capture_lost_ = false; | 86 ignore_capture_lost_ = false; |
88 } | 87 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 if (destroying_) | 133 if (destroying_) |
135 return; | 134 return; |
136 | 135 |
137 MenuController* menu_controller = | 136 MenuController* menu_controller = |
138 submenu_->GetMenuItem()->GetMenuController(); | 137 submenu_->GetMenuItem()->GetMenuController(); |
139 if (menu_controller && !menu_controller->drag_in_progress()) | 138 if (menu_controller && !menu_controller->drag_in_progress()) |
140 menu_controller->CancelAll(); | 139 menu_controller->CancelAll(); |
141 } | 140 } |
142 | 141 |
143 } // namespace views | 142 } // namespace views |
OLD | NEW |