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/widget/widget.h" | 5 #include "ui/views/widget/widget.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1167 case ui::ET_MOUSE_PRESSED: { | 1167 case ui::ET_MOUSE_PRESSED: { |
| 1168 last_mouse_event_was_move_ = false; | 1168 last_mouse_event_was_move_ = false; |
| 1169 | 1169 |
| 1170 // We may get deleted by the time we return from OnMousePressed. So we | 1170 // We may get deleted by the time we return from OnMousePressed. So we |
| 1171 // use an observer to make sure we are still alive. | 1171 // use an observer to make sure we are still alive. |
| 1172 WidgetDeletionObserver widget_deletion_observer(this); | 1172 WidgetDeletionObserver widget_deletion_observer(this); |
| 1173 | 1173 |
| 1174 // Make sure we're still visible before we attempt capture as the mouse | 1174 // Make sure we're still visible before we attempt capture as the mouse |
| 1175 // press processing may have made the window hide (as happens with menus). | 1175 // press processing may have made the window hide (as happens with menus). |
| 1176 | 1176 |
| 1177 // It is possible for a View to show a context menu on mouse-press. Since | 1177 // It is possible for a View to show a context menu on mouse-press, which |
| 1178 // the menu does a capture and starts a nested message-loop, the release | 1178 // takes capture. |
| 1179 // would go to the menu. The next click (i.e. both mouse-press and release | 1179 // |
| 1180 // events) also go to the menu. The menu (and the nested message-loop) | 1180 // Menus which use a nested message-loop, receive the release. The next |
| 1181 // gets closed after this second release event. The code then resumes from | 1181 // click (i.e. both mouse-press and release events) also go to the menu. |
| 1182 // here. So make sure that the mouse-button is still down before doing a | 1182 // The menu (and the nested message-loop) gets closed after this second |
| 1183 // capture. | 1183 // release event. The code then resumes from here. So make sure that the |
| 1184 // mouse-button is still down before doing a capture. | |
| 1185 // | |
| 1186 // Menus which do not use a nested message-loop will return here, holding | |
| 1187 // capture. If there is an active MenuController do not reassign capture | |
| 1188 // to |native_widget_|. | |
| 1184 if (root_view && root_view->OnMousePressed(*event) && | 1189 if (root_view && root_view->OnMousePressed(*event) && |
| 1185 widget_deletion_observer.IsWidgetAlive() && IsVisible() && | 1190 widget_deletion_observer.IsWidgetAlive() && IsVisible() && |
| 1186 internal::NativeWidgetPrivate::IsMouseButtonDown()) { | 1191 internal::NativeWidgetPrivate::IsMouseButtonDown() && |
| 1192 !MenuController::GetActiveInstance()) { | |
|
sky
2016/05/05 16:34:39
I don't like having to special case the check for
jonross
2016/05/05 17:50:42
I believe that could account for this. I'm not awa
| |
| 1187 is_mouse_button_pressed_ = true; | 1193 is_mouse_button_pressed_ = true; |
| 1188 if (!native_widget_->HasCapture()) | 1194 if (!native_widget_->HasCapture()) |
| 1189 native_widget_->SetCapture(); | 1195 native_widget_->SetCapture(); |
| 1190 event->SetHandled(); | 1196 event->SetHandled(); |
| 1191 } | 1197 } |
| 1192 return; | 1198 return; |
| 1193 } | 1199 } |
| 1194 | 1200 |
| 1195 case ui::ET_MOUSE_RELEASED: | 1201 case ui::ET_MOUSE_RELEASED: |
| 1196 last_mouse_event_was_move_ = false; | 1202 last_mouse_event_was_move_ = false; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1483 | 1489 |
| 1484 //////////////////////////////////////////////////////////////////////////////// | 1490 //////////////////////////////////////////////////////////////////////////////// |
| 1485 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1491 // internal::NativeWidgetPrivate, NativeWidget implementation: |
| 1486 | 1492 |
| 1487 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1493 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
| 1488 return this; | 1494 return this; |
| 1489 } | 1495 } |
| 1490 | 1496 |
| 1491 } // namespace internal | 1497 } // namespace internal |
| 1492 } // namespace views | 1498 } // namespace views |
| OLD | NEW |