| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // Methods compiled on all toolkit-views platforms (including Mac). | 5 // Methods compiled on all toolkit-views platforms (including Mac). |
| 6 | 6 |
| 7 #include "chrome/test/base/interactive_test_utils.h" | 7 #include "chrome/test/base/interactive_test_utils.h" |
| 8 | 8 |
| 9 #include "ui/compositor/layer.h" | 9 #include "ui/compositor/layer.h" |
| 10 #include "ui/compositor/layer_animator.h" | 10 #include "ui/compositor/layer_animator.h" |
| 11 #include "ui/views/view.h" | 11 #include "ui/views/view.h" |
| 12 #include "ui/views/widget/widget.h" | 12 #include "ui/views/widget/widget.h" |
| 13 | 13 |
| 14 namespace ui_test_utils { | 14 namespace ui_test_utils { |
| 15 | 15 |
| 16 void MoveMouseToCenterAndPress(views::View* view, | 16 void MoveMouseToCenterAndPress(views::View* view, |
| 17 ui_controls::MouseButton button, | 17 ui_controls::MouseButton button, |
| 18 int state, | 18 int state, |
| 19 const base::Closure& closure) { | 19 const base::Closure& closure) { |
| 20 if (g_crbug_639350_logging) |
| 21 LOG(ERROR) << "crbug.com/639350 MoveMouseToCenterAndPress A"; |
| 20 DCHECK(view); | 22 DCHECK(view); |
| 21 DCHECK(view->GetWidget()); | 23 DCHECK(view->GetWidget()); |
| 22 // Complete any in-progress animation before sending the events so that the | 24 // Complete any in-progress animation before sending the events so that the |
| 23 // mouse-event targetting happens reliably, and does not flake because of | 25 // mouse-event targetting happens reliably, and does not flake because of |
| 24 // unreliable animation state. | 26 // unreliable animation state. |
| 25 ui::Layer* layer = view->GetWidget()->GetLayer(); | 27 ui::Layer* layer = view->GetWidget()->GetLayer(); |
| 26 if (layer) { | 28 if (layer) { |
| 29 if (g_crbug_639350_logging) |
| 30 LOG(ERROR) << "crbug.com/639350 MoveMouseToCenterAndPress B"; |
| 27 ui::LayerAnimator* animator = layer->GetAnimator(); | 31 ui::LayerAnimator* animator = layer->GetAnimator(); |
| 28 if (animator && animator->is_animating()) | 32 if (animator && animator->is_animating()) |
| 29 animator->StopAnimating(); | 33 animator->StopAnimating(); |
| 34 if (g_crbug_639350_logging) |
| 35 LOG(ERROR) << "crbug.com/639350 MoveMouseToCenterAndPress C"; |
| 30 } | 36 } |
| 31 | 37 |
| 38 if (g_crbug_639350_logging) |
| 39 LOG(ERROR) << "crbug.com/639350 MoveMouseToCenterAndPress D"; |
| 32 gfx::Point view_center(view->width() / 2, view->height() / 2); | 40 gfx::Point view_center(view->width() / 2, view->height() / 2); |
| 33 views::View::ConvertPointToScreen(view, &view_center); | 41 views::View::ConvertPointToScreen(view, &view_center); |
| 42 if (g_crbug_639350_logging) |
| 43 LOG(ERROR) << "crbug.com/639350 MoveMouseToCenterAndPress E"; |
| 34 ui_controls::SendMouseMoveNotifyWhenDone( | 44 ui_controls::SendMouseMoveNotifyWhenDone( |
| 35 view_center.x(), | 45 view_center.x(), |
| 36 view_center.y(), | 46 view_center.y(), |
| 37 base::Bind(&internal::ClickTask, button, state, closure)); | 47 base::Bind(&internal::ClickTask, button, state, closure)); |
| 48 if (g_crbug_639350_logging) |
| 49 LOG(ERROR) << "crbug.com/639350 MoveMouseToCenterAndPress F"; |
| 38 } | 50 } |
| 39 | 51 |
| 40 } // namespace ui_test_utils | 52 } // namespace ui_test_utils |
| OLD | NEW |