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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 // revert this change once http://crbug.com/125248 is fixed. | 120 // revert this change once http://crbug.com/125248 is fixed. |
| 121 params.force_software_compositing = true; | 121 params.force_software_compositing = true; |
| 122 #endif | 122 #endif |
| 123 Init(params); | 123 Init(params); |
| 124 | 124 |
| 125 #if !defined(OS_MACOSX) | 125 #if !defined(OS_MACOSX) |
| 126 pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler( | 126 pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler( |
| 127 menu_controller, submenu_, GetNativeView())); | 127 menu_controller, submenu_, GetNativeView())); |
| 128 #endif | 128 #endif |
| 129 | 129 |
| 130 if (parent && !views::MenuController::DoCancel()) { | |
|
xiyuan
2017/05/15 19:20:52
nit: Use |menu_controller| instance after making D
minch1
2017/05/16 22:13:39
Done.
| |
| 131 owner_ = parent; | |
| 132 TransferEvents(owner_, this); | |
| 133 } | |
| 130 SetContentsView(contents_view); | 134 SetContentsView(contents_view); |
| 131 ShowMenuHost(do_capture); | 135 ShowMenuHost(do_capture); |
| 132 } | 136 } |
| 133 | 137 |
| 138 void MenuHost::TransferEvents(Widget* source, Widget* target) { | |
| 139 ui::GestureRecognizer::Get()->TransferEventsTo( | |
| 140 source->GetNativeView(), target->GetNativeView(), | |
| 141 ui::GestureRecognizer::ShouldCancelTouches::DontCancel); | |
| 142 } | |
| 143 | |
| 134 bool MenuHost::IsMenuHostVisible() { | 144 bool MenuHost::IsMenuHostVisible() { |
| 135 return IsVisible(); | 145 return IsVisible(); |
| 136 } | 146 } |
| 137 | 147 |
| 138 void MenuHost::ShowMenuHost(bool do_capture) { | 148 void MenuHost::ShowMenuHost(bool do_capture) { |
| 139 // Doing a capture may make us get capture lost. Ignore it while we're in the | 149 // Doing a capture may make us get capture lost. Ignore it while we're in the |
| 140 // process of showing. | 150 // process of showing. |
| 141 base::AutoReset<bool> reseter(&ignore_capture_lost_, true); | 151 base::AutoReset<bool> reseter(&ignore_capture_lost_, true); |
| 142 ShowInactive(); | 152 ShowInactive(); |
| 143 if (do_capture) { | 153 if (do_capture) { |
| 144 // Cancel existing touches, so we don't miss some touch release/cancel | 154 // Cancel existing touches, so we don't miss some touch release/cancel |
| 145 // events due to the menu taking capture. | 155 // events due to the menu taking capture. |
| 146 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); | 156 if (views::MenuController::DoCancel()) |
| 157 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); | |
| 147 native_widget_private()->SetCapture(); | 158 native_widget_private()->SetCapture(); |
| 148 } | 159 } |
| 149 } | 160 } |
| 150 | 161 |
| 151 void MenuHost::HideMenuHost() { | 162 void MenuHost::HideMenuHost() { |
| 163 if (owner_ && !views::MenuController::DoCancel()) { | |
| 164 TransferEvents(this, owner_); | |
| 165 owner_ = NULL; | |
| 166 views::MenuController::SetDoCancel(true); | |
|
xiyuan
2017/05/15 19:20:52
Is this call necessary?
minch1
2017/05/15 22:16:34
Yes. I think this is necessary.
1. Press the shel
xiyuan
2017/05/15 22:41:10
That would be another reason to make |do_cancel_|
| |
| 167 } | |
| 152 ignore_capture_lost_ = true; | 168 ignore_capture_lost_ = true; |
| 153 ReleaseMenuHostCapture(); | 169 ReleaseMenuHostCapture(); |
| 154 Hide(); | 170 Hide(); |
| 155 ignore_capture_lost_ = false; | 171 ignore_capture_lost_ = false; |
| 156 } | 172 } |
| 157 | 173 |
| 158 void MenuHost::DestroyMenuHost() { | 174 void MenuHost::DestroyMenuHost() { |
| 159 HideMenuHost(); | 175 HideMenuHost(); |
| 160 destroying_ = true; | 176 destroying_ = true; |
| 161 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu(); | 177 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 } | 255 } |
| 240 menu_controller->OnDragComplete(should_close); | 256 menu_controller->OnDragComplete(should_close); |
| 241 | 257 |
| 242 // We may have lost capture in the drag and drop, but are remaining open. | 258 // We may have lost capture in the drag and drop, but are remaining open. |
| 243 // Return capture so we get MouseCaptureLost events. | 259 // Return capture so we get MouseCaptureLost events. |
| 244 if (!should_close) | 260 if (!should_close) |
| 245 native_widget_private()->SetCapture(); | 261 native_widget_private()->SetCapture(); |
| 246 } | 262 } |
| 247 | 263 |
| 248 } // namespace views | 264 } // namespace views |
| OLD | NEW |