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 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1164 void Widget::OnMouseEvent(ui::MouseEvent* event) { | 1164 void Widget::OnMouseEvent(ui::MouseEvent* event) { |
| 1165 View* root_view = GetRootView(); | 1165 View* root_view = GetRootView(); |
| 1166 switch (event->type()) { | 1166 switch (event->type()) { |
| 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 gfx::NativeView current_capture = | |
| 1175 internal::NativeWidgetPrivate::GetCapture( | |
| 1176 native_widget_->GetNativeView()); | |
| 1174 // Make sure we're still visible before we attempt capture as the mouse | 1177 // 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). | 1178 // press processing may have made the window hide (as happens with menus). |
| 1176 | 1179 |
| 1177 // It is possible for a View to show a context menu on mouse-press. Since | 1180 // It is possible for a View to show a context menu on mouse-press, which |
|
sky
2016/05/06 20:03:32
Can you make this comment more general and not ent
jonross
2016/05/09 16:50:25
Done.
| |
| 1178 // the menu does a capture and starts a nested message-loop, the release | 1181 // takes capture. |
| 1179 // would go to the menu. The next click (i.e. both mouse-press and release | 1182 // |
| 1180 // events) also go to the menu. The menu (and the nested message-loop) | 1183 // 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 | 1184 // 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 | 1185 // The menu (and the nested message-loop) gets closed after this second |
| 1183 // capture. | 1186 // release event. The code then resumes from here. So make sure that the |
| 1187 // mouse-button is still down before doing a capture. | |
| 1188 // | |
| 1189 // Menus which do not use a nested message-loop will return here, holding | |
| 1190 // capture. This will lead to capture having changed, in which case we do | |
| 1191 // not give capture back to the |native_widget_|. | |
| 1184 if (root_view && root_view->OnMousePressed(*event) && | 1192 if (root_view && root_view->OnMousePressed(*event) && |
| 1185 widget_deletion_observer.IsWidgetAlive() && IsVisible() && | 1193 widget_deletion_observer.IsWidgetAlive() && IsVisible() && |
| 1186 internal::NativeWidgetPrivate::IsMouseButtonDown()) { | 1194 internal::NativeWidgetPrivate::IsMouseButtonDown() && |
| 1195 current_capture == internal::NativeWidgetPrivate::GetCapture( | |
| 1196 native_widget_->GetNativeView())) { | |
| 1187 is_mouse_button_pressed_ = true; | 1197 is_mouse_button_pressed_ = true; |
| 1188 if (!native_widget_->HasCapture()) | 1198 if (!native_widget_->HasCapture()) |
| 1189 native_widget_->SetCapture(); | 1199 native_widget_->SetCapture(); |
| 1190 event->SetHandled(); | 1200 event->SetHandled(); |
| 1191 } | 1201 } |
| 1192 return; | 1202 return; |
| 1193 } | 1203 } |
| 1194 | 1204 |
| 1195 case ui::ET_MOUSE_RELEASED: | 1205 case ui::ET_MOUSE_RELEASED: |
| 1196 last_mouse_event_was_move_ = false; | 1206 last_mouse_event_was_move_ = false; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1483 | 1493 |
| 1484 //////////////////////////////////////////////////////////////////////////////// | 1494 //////////////////////////////////////////////////////////////////////////////// |
| 1485 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1495 // internal::NativeWidgetPrivate, NativeWidget implementation: |
| 1486 | 1496 |
| 1487 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1497 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
| 1488 return this; | 1498 return this; |
| 1489 } | 1499 } |
| 1490 | 1500 |
| 1491 } // namespace internal | 1501 } // namespace internal |
| 1492 } // namespace views | 1502 } // namespace views |
| OLD | NEW |