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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 } | 73 } |
| 74 | 74 |
| 75 MenuController* menu_controller_; | 75 MenuController* menu_controller_; |
| 76 SubmenuView* submenu_; | 76 SubmenuView* submenu_; |
| 77 aura::Window* window_; | 77 aura::Window* window_; |
| 78 | 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(PreMenuEventDispatchHandler); | 79 DISALLOW_COPY_AND_ASSIGN(PreMenuEventDispatchHandler); |
| 80 }; | 80 }; |
| 81 #endif // OS_MACOSX | 81 #endif // OS_MACOSX |
| 82 | 82 |
| 83 #if !defined(OS_MACOSX) | |
| 84 void TransferGesture(Widget* source, Widget* target) { | |
|
msw
2017/05/17 23:03:30
nit: comment, maybe seek menu review from sky@?
| |
| 85 ui::GestureRecognizer::Get()->TransferEventsTo( | |
| 86 source->GetNativeView(), target->GetNativeView(), | |
| 87 ui::GestureRecognizer::ShouldCancelTouches::DontCancel); | |
| 88 } | |
| 89 #endif | |
| 90 | |
| 83 } // namespace internal | 91 } // namespace internal |
| 84 | 92 |
| 85 //////////////////////////////////////////////////////////////////////////////// | 93 //////////////////////////////////////////////////////////////////////////////// |
| 86 // MenuHost, public: | 94 // MenuHost, public: |
| 87 | 95 |
| 88 MenuHost::MenuHost(SubmenuView* submenu) | 96 MenuHost::MenuHost(SubmenuView* submenu) |
| 89 : submenu_(submenu), | 97 : submenu_(submenu), |
| 90 destroying_(false), | 98 destroying_(false), |
| 91 ignore_capture_lost_(false) { | 99 ignore_capture_lost_(false) { |
| 92 set_auto_release_capture(false); | 100 set_auto_release_capture(false); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 118 // On Windows use the software compositor to ensure that we don't block | 126 // 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 | 127 // the UI thread blocking issue during command buffer creation. We can |
| 120 // revert this change once http://crbug.com/125248 is fixed. | 128 // revert this change once http://crbug.com/125248 is fixed. |
| 121 params.force_software_compositing = true; | 129 params.force_software_compositing = true; |
| 122 #endif | 130 #endif |
| 123 Init(params); | 131 Init(params); |
| 124 | 132 |
| 125 #if !defined(OS_MACOSX) | 133 #if !defined(OS_MACOSX) |
| 126 pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler( | 134 pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler( |
| 127 menu_controller, submenu_, GetNativeView())); | 135 menu_controller, submenu_, GetNativeView())); |
| 136 owner_ = parent; | |
| 128 #endif | 137 #endif |
| 129 | 138 |
| 130 SetContentsView(contents_view); | 139 SetContentsView(contents_view); |
| 131 ShowMenuHost(do_capture); | 140 ShowMenuHost(do_capture); |
| 132 } | 141 } |
| 133 | 142 |
| 134 bool MenuHost::IsMenuHostVisible() { | 143 bool MenuHost::IsMenuHostVisible() { |
| 135 return IsVisible(); | 144 return IsVisible(); |
| 136 } | 145 } |
| 137 | 146 |
| 138 void MenuHost::ShowMenuHost(bool do_capture) { | 147 void MenuHost::ShowMenuHost(bool do_capture) { |
| 139 // Doing a capture may make us get capture lost. Ignore it while we're in the | 148 // Doing a capture may make us get capture lost. Ignore it while we're in the |
| 140 // process of showing. | 149 // process of showing. |
| 141 base::AutoReset<bool> reseter(&ignore_capture_lost_, true); | 150 base::AutoReset<bool> reseter(&ignore_capture_lost_, true); |
| 142 ShowInactive(); | 151 ShowInactive(); |
| 143 if (do_capture) { | 152 if (do_capture) { |
| 144 // Cancel existing touches, so we don't miss some touch release/cancel | 153 // Cancel existing touches, so we don't miss some touch release/cancel |
|
msw
2017/05/17 23:03:30
nit: move comment into else?
minch1
2017/05/26 23:01:12
Done.
| |
| 145 // events due to the menu taking capture. | 154 // events due to the menu taking capture. |
| 155 #if !defined(OS_MACOSX) | |
| 156 MenuController* menu_controller = | |
| 157 submenu_->GetMenuItem()->GetMenuController(); | |
| 158 if (menu_controller) { | |
| 159 if (menu_controller->owner_needs_gesture_events()) { | |
| 160 // TransferGesture when owner needs gesture events so that the incoming | |
| 161 // touch events after MenuHost is created are properly translated into | |
| 162 // gesture events instead of being dropped. | |
| 163 internal::TransferGesture(owner_, this); | |
| 164 } else { | |
| 165 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); | |
| 166 } | |
| 167 } | |
| 168 #else | |
| 146 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); | 169 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); |
| 170 #endif | |
| 147 native_widget_private()->SetCapture(); | 171 native_widget_private()->SetCapture(); |
| 148 } | 172 } |
| 149 } | 173 } |
| 150 | 174 |
| 151 void MenuHost::HideMenuHost() { | 175 void MenuHost::HideMenuHost() { |
| 176 #if !defined(OS_MACOSX) | |
| 177 MenuController* menu_controller = | |
| 178 submenu_->GetMenuItem()->GetMenuController(); | |
| 179 if (owner_ && menu_controller && | |
| 180 menu_controller->owner_needs_gesture_events()) { | |
| 181 internal::TransferGesture(this, owner_); | |
| 182 owner_ = nullptr; | |
| 183 } | |
| 184 #endif | |
| 152 ignore_capture_lost_ = true; | 185 ignore_capture_lost_ = true; |
| 153 ReleaseMenuHostCapture(); | 186 ReleaseMenuHostCapture(); |
| 154 Hide(); | 187 Hide(); |
| 155 ignore_capture_lost_ = false; | 188 ignore_capture_lost_ = false; |
| 156 } | 189 } |
| 157 | 190 |
| 158 void MenuHost::DestroyMenuHost() { | 191 void MenuHost::DestroyMenuHost() { |
| 159 HideMenuHost(); | 192 HideMenuHost(); |
| 160 destroying_ = true; | 193 destroying_ = true; |
| 161 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu(); | 194 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 } | 272 } |
| 240 menu_controller->OnDragComplete(should_close); | 273 menu_controller->OnDragComplete(should_close); |
| 241 | 274 |
| 242 // We may have lost capture in the drag and drop, but are remaining open. | 275 // We may have lost capture in the drag and drop, but are remaining open. |
| 243 // Return capture so we get MouseCaptureLost events. | 276 // Return capture so we get MouseCaptureLost events. |
| 244 if (!should_close) | 277 if (!should_close) |
| 245 native_widget_private()->SetCapture(); | 278 native_widget_private()->SetCapture(); |
| 246 } | 279 } |
| 247 | 280 |
| 248 } // namespace views | 281 } // namespace views |
| OLD | NEW |