Chromium Code Reviews| 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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 ignore_capture_lost_(false) { | 91 ignore_capture_lost_(false) { |
| 92 set_auto_release_capture(false); | 92 set_auto_release_capture(false); |
| 93 } | 93 } |
| 94 | 94 |
| 95 MenuHost::~MenuHost() { | 95 MenuHost::~MenuHost() { |
| 96 } | 96 } |
| 97 | 97 |
| 98 void MenuHost::InitMenuHost(Widget* parent, | 98 void MenuHost::InitMenuHost(Widget* parent, |
| 99 const gfx::Rect& bounds, | 99 const gfx::Rect& bounds, |
| 100 View* contents_view, | 100 View* contents_view, |
| 101 bool do_capture) { | 101 bool do_capture, |
| 102 bool cancel_active_touches) { | |
|
xiyuan
2017/05/12 20:24:56
How about get this from MenuController instead of
| |
| 102 TRACE_EVENT0("views", "MenuHost::InitMenuHost"); | 103 TRACE_EVENT0("views", "MenuHost::InitMenuHost"); |
| 103 Widget::InitParams params(Widget::InitParams::TYPE_MENU); | 104 Widget::InitParams params(Widget::InitParams::TYPE_MENU); |
| 104 const MenuController* menu_controller = | 105 const MenuController* menu_controller = |
| 105 submenu_->GetMenuItem()->GetMenuController(); | 106 submenu_->GetMenuItem()->GetMenuController(); |
| 106 const MenuConfig& menu_config = MenuConfig::instance(); | 107 const MenuConfig& menu_config = MenuConfig::instance(); |
| 107 bool rounded_border = menu_controller && menu_config.corner_radius > 0; | 108 bool rounded_border = menu_controller && menu_config.corner_radius > 0; |
| 108 bool bubble_border = submenu_->GetScrollViewContainer() && | 109 bool bubble_border = submenu_->GetScrollViewContainer() && |
| 109 submenu_->GetScrollViewContainer()->HasBubbleBorder(); | 110 submenu_->GetScrollViewContainer()->HasBubbleBorder(); |
| 110 params.shadow_type = bubble_border ? Widget::InitParams::SHADOW_TYPE_NONE | 111 params.shadow_type = bubble_border ? Widget::InitParams::SHADOW_TYPE_NONE |
| 111 : Widget::InitParams::SHADOW_TYPE_DROP; | 112 : Widget::InitParams::SHADOW_TYPE_DROP; |
| 112 params.opacity = (bubble_border || rounded_border) ? | 113 params.opacity = (bubble_border || rounded_border) ? |
| 113 Widget::InitParams::TRANSLUCENT_WINDOW : | 114 Widget::InitParams::TRANSLUCENT_WINDOW : |
| 114 Widget::InitParams::OPAQUE_WINDOW; | 115 Widget::InitParams::OPAQUE_WINDOW; |
| 115 params.parent = parent ? parent->GetNativeView() : NULL; | 116 params.parent = parent ? parent->GetNativeView() : NULL; |
| 116 params.bounds = bounds; | 117 params.bounds = bounds; |
| 117 #if defined(OS_WIN) | 118 #if defined(OS_WIN) |
| 118 // On Windows use the software compositor to ensure that we don't block | 119 // On Windows use the software compositor to ensure that we don't block |
| 119 // the UI thread blocking issue during command buffer creation. We can | 120 // the UI thread blocking issue during command buffer creation. We can |
| 120 // revert this change once http://crbug.com/125248 is fixed. | 121 // revert this change once http://crbug.com/125248 is fixed. |
| 121 params.force_software_compositing = true; | 122 params.force_software_compositing = true; |
| 122 #endif | 123 #endif |
| 123 Init(params); | 124 Init(params); |
| 124 | 125 |
| 125 #if !defined(OS_MACOSX) | 126 #if !defined(OS_MACOSX) |
| 126 pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler( | 127 pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler( |
| 127 menu_controller, submenu_, GetNativeView())); | 128 menu_controller, submenu_, GetNativeView())); |
| 128 #endif | 129 #endif |
| 129 | 130 |
| 131 owner_ = parent; | |
| 132 | |
| 133 TransferEvents(owner_, this); | |
|
xiyuan
2017/05/12 20:24:56
We probably should only do this for the out-most m
| |
| 134 | |
| 130 SetContentsView(contents_view); | 135 SetContentsView(contents_view); |
| 131 ShowMenuHost(do_capture); | 136 ShowMenuHost(do_capture, cancel_active_touches); |
| 137 } | |
| 138 | |
| 139 void MenuHost::TransferEvents(Widget* source, Widget* target) { | |
| 140 ui::GestureRecognizer::Get()->TransferEventsTo( | |
| 141 source->GetNativeView(), target->GetNativeView(), | |
| 142 ui::GestureRecognizer::ShouldCancelTouches::DontCancel); | |
| 132 } | 143 } |
| 133 | 144 |
| 134 bool MenuHost::IsMenuHostVisible() { | 145 bool MenuHost::IsMenuHostVisible() { |
| 135 return IsVisible(); | 146 return IsVisible(); |
| 136 } | 147 } |
| 137 | 148 |
| 138 void MenuHost::ShowMenuHost(bool do_capture) { | 149 void MenuHost::ShowMenuHost(bool do_capture, bool cancel_active_touches) { |
| 139 // Doing a capture may make us get capture lost. Ignore it while we're in the | 150 // Doing a capture may make us get capture lost. Ignore it while we're in the |
| 140 // process of showing. | 151 // process of showing. |
| 141 base::AutoReset<bool> reseter(&ignore_capture_lost_, true); | 152 base::AutoReset<bool> reseter(&ignore_capture_lost_, true); |
| 142 ShowInactive(); | 153 ShowInactive(); |
| 154 if (cancel_active_touches) { | |
|
xiyuan
2017/05/12 20:24:56
This should probably be in the if (do_capture) dow
| |
| 155 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); | |
| 156 } | |
| 143 if (do_capture) { | 157 if (do_capture) { |
| 144 // Cancel existing touches, so we don't miss some touch release/cancel | 158 // Cancel existing touches, so we don't miss some touch release/cancel |
| 145 // events due to the menu taking capture. | 159 // events due to the menu taking capture. |
| 146 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); | |
| 147 native_widget_private()->SetCapture(); | 160 native_widget_private()->SetCapture(); |
| 148 } | 161 } |
| 149 } | 162 } |
| 150 | 163 |
| 151 void MenuHost::HideMenuHost() { | 164 void MenuHost::HideMenuHost() { |
| 165 if (owner_) { | |
| 166 TransferEvents(this, owner_); | |
|
xiyuan
2017/05/12 20:24:56
Similarly, we need to figure out how to do this on
| |
| 167 owner_ = NULL; | |
| 168 } | |
| 152 ignore_capture_lost_ = true; | 169 ignore_capture_lost_ = true; |
| 153 ReleaseMenuHostCapture(); | 170 ReleaseMenuHostCapture(); |
| 154 Hide(); | 171 Hide(); |
| 155 ignore_capture_lost_ = false; | 172 ignore_capture_lost_ = false; |
| 156 } | 173 } |
| 157 | 174 |
| 158 void MenuHost::DestroyMenuHost() { | 175 void MenuHost::DestroyMenuHost() { |
| 159 HideMenuHost(); | 176 HideMenuHost(); |
| 160 destroying_ = true; | 177 destroying_ = true; |
| 161 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu(); | 178 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 } | 256 } |
| 240 menu_controller->OnDragComplete(should_close); | 257 menu_controller->OnDragComplete(should_close); |
| 241 | 258 |
| 242 // We may have lost capture in the drag and drop, but are remaining open. | 259 // We may have lost capture in the drag and drop, but are remaining open. |
| 243 // Return capture so we get MouseCaptureLost events. | 260 // Return capture so we get MouseCaptureLost events. |
| 244 if (!should_close) | 261 if (!should_close) |
| 245 native_widget_private()->SetCapture(); | 262 native_widget_private()->SetCapture(); |
| 246 } | 263 } |
| 247 | 264 |
| 248 } // namespace views | 265 } // namespace views |
| OLD | NEW |