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" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 void MenuHost::OnOwnerClosing() { | 128 void MenuHost::OnOwnerClosing() { |
129 if (destroying_) | 129 if (destroying_) |
130 return; | 130 return; |
131 | 131 |
132 MenuController* menu_controller = | 132 MenuController* menu_controller = |
133 submenu_->GetMenuItem()->GetMenuController(); | 133 submenu_->GetMenuItem()->GetMenuController(); |
134 if (menu_controller && !menu_controller->drag_in_progress()) | 134 if (menu_controller && !menu_controller->drag_in_progress()) |
135 menu_controller->CancelAll(); | 135 menu_controller->CancelAll(); |
136 } | 136 } |
137 | 137 |
138 void MenuHost::OnDragWillStart() { | |
139 MenuController* menu_controller = | |
140 submenu_->GetMenuItem()->GetMenuController(); | |
141 if (menu_controller) | |
sky
2014/07/14 15:19:05
The if should be a DCHECK
Devlin
2014/07/16 16:00:45
Done. For my own edification, why should it be DC
sky
2014/07/16 19:19:00
MenuHost may outlive MenuController, hence the nec
| |
142 menu_controller->OnDragWillStart(); | |
143 } | |
144 | |
145 void MenuHost::OnDragComplete(View* dragged_view) { | |
146 MenuController* menu_controller = | |
147 submenu_->GetMenuItem()->GetMenuController(); | |
148 if (destroying_ || !menu_controller) | |
149 return; | |
150 | |
151 bool should_close = true; | |
152 // If the view came from outside menu code (i.e., not a MenuItemView), we | |
153 // should consult the MenuDelegate to determine whether or not to close on | |
154 // exit. | |
155 if (dragged_view && dragged_view->id() != MenuItemView::kMenuItemViewID) { | |
Devlin
2014/07/11 20:28:15
I think this should work for ensuring the delegate
sky
2014/07/14 15:19:05
It would be safer to make MenuController know it i
Devlin
2014/07/16 16:00:45
Done.
| |
156 MenuDelegate* menu_delegate = submenu_->GetMenuItem()->GetDelegate(); | |
157 should_close = | |
158 menu_delegate ? menu_delegate->ShouldCloseOnDragComplete() : should_close; | |
159 } | |
160 menu_controller->OnDragComplete(should_close); | |
161 | |
162 // We may have lost capture in the drag and drop, but are remaining open. | |
163 // Return capture so we get MouseCaptureLost events. | |
164 if (!should_close) | |
165 native_widget_private()->SetCapture(); | |
166 } | |
167 | |
138 } // namespace views | 168 } // namespace views |
OLD | NEW |