| 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 } | 212 } |
| 213 | 213 |
| 214 void MenuHost::OnDragWillStart() { | 214 void MenuHost::OnDragWillStart() { |
| 215 MenuController* menu_controller = | 215 MenuController* menu_controller = |
| 216 submenu_->GetMenuItem()->GetMenuController(); | 216 submenu_->GetMenuItem()->GetMenuController(); |
| 217 DCHECK(menu_controller); | 217 DCHECK(menu_controller); |
| 218 menu_controller->OnDragWillStart(); | 218 menu_controller->OnDragWillStart(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void MenuHost::OnDragComplete() { | 221 void MenuHost::OnDragComplete() { |
| 222 // If we are being destroyed there is no guarantee that the menu items are |
| 223 // available. |
| 224 if (destroying_) |
| 225 return; |
| 222 MenuController* menu_controller = | 226 MenuController* menu_controller = |
| 223 submenu_->GetMenuItem()->GetMenuController(); | 227 submenu_->GetMenuItem()->GetMenuController(); |
| 224 if (destroying_ || !menu_controller) | 228 if (!menu_controller) |
| 225 return; | 229 return; |
| 226 | 230 |
| 227 bool should_close = true; | 231 bool should_close = true; |
| 228 // If the view came from outside menu code (i.e., not a MenuItemView), we | 232 // If the view came from outside menu code (i.e., not a MenuItemView), we |
| 229 // should consult the MenuDelegate to determine whether or not to close on | 233 // should consult the MenuDelegate to determine whether or not to close on |
| 230 // exit. | 234 // exit. |
| 231 if (!menu_controller->did_initiate_drag()) { | 235 if (!menu_controller->did_initiate_drag()) { |
| 232 MenuDelegate* menu_delegate = submenu_->GetMenuItem()->GetDelegate(); | 236 MenuDelegate* menu_delegate = submenu_->GetMenuItem()->GetDelegate(); |
| 233 should_close = | 237 should_close = |
| 234 menu_delegate ? menu_delegate->ShouldCloseOnDragComplete() : should_close; | 238 menu_delegate ? menu_delegate->ShouldCloseOnDragComplete() : should_close; |
| 235 } | 239 } |
| 236 menu_controller->OnDragComplete(should_close); | 240 menu_controller->OnDragComplete(should_close); |
| 237 | 241 |
| 238 // We may have lost capture in the drag and drop, but are remaining open. | 242 // We may have lost capture in the drag and drop, but are remaining open. |
| 239 // Return capture so we get MouseCaptureLost events. | 243 // Return capture so we get MouseCaptureLost events. |
| 240 if (!should_close) | 244 if (!should_close) |
| 241 native_widget_private()->SetCapture(); | 245 native_widget_private()->SetCapture(); |
| 242 } | 246 } |
| 243 | 247 |
| 244 } // namespace views | 248 } // namespace views |
| OLD | NEW |