| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/aura/window_targeter.h" | 5 #include "ui/aura/window_targeter.h" |
| 6 | 6 |
| 7 #include "ui/aura/scoped_window_targeter.h" | 7 #include "ui/aura/scoped_window_targeter.h" |
| 8 #include "ui/aura/test/aura_test_base.h" | 8 #include "ui/aura/test/aura_test_base.h" |
| 9 #include "ui/aura/test/test_event_handler.h" | 9 #include "ui/aura/test/test_event_handler.h" |
| 10 #include "ui/aura/test/test_window_delegate.h" | 10 #include "ui/aura/test/test_window_delegate.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 class WindowTargeterTest : public test::AuraTestBase { | 35 class WindowTargeterTest : public test::AuraTestBase { |
| 36 public: | 36 public: |
| 37 WindowTargeterTest() {} | 37 WindowTargeterTest() {} |
| 38 virtual ~WindowTargeterTest() {} | 38 virtual ~WindowTargeterTest() {} |
| 39 | 39 |
| 40 Window* root_window() { return AuraTestBase::root_window(); } | 40 Window* root_window() { return AuraTestBase::root_window(); } |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 gfx::RectF GetEffectiveVisibleBoundsInRootWindow(Window* window) { | |
| 44 gfx::RectF bounds = gfx::Rect(window->bounds().size()); | |
| 45 Window* root = window->GetRootWindow(); | |
| 46 CHECK(window->layer()); | |
| 47 CHECK(root->layer()); | |
| 48 gfx::Transform transform; | |
| 49 if (!window->layer()->GetTargetTransformRelativeTo(root->layer(), &transform)) | |
| 50 return gfx::RectF(); | |
| 51 transform.TransformRect(&bounds); | |
| 52 return bounds; | |
| 53 } | |
| 54 | |
| 55 TEST_F(WindowTargeterTest, Basic) { | 43 TEST_F(WindowTargeterTest, Basic) { |
| 56 test::TestWindowDelegate delegate; | 44 test::TestWindowDelegate delegate; |
| 57 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), &delegate)); | 45 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), &delegate)); |
| 58 Window* one = CreateNormalWindow(2, window.get(), &delegate); | 46 Window* one = CreateNormalWindow(2, window.get(), &delegate); |
| 59 Window* two = CreateNormalWindow(3, window.get(), &delegate); | 47 Window* two = CreateNormalWindow(3, window.get(), &delegate); |
| 60 | 48 |
| 61 window->SetBounds(gfx::Rect(0, 0, 100, 100)); | 49 window->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 62 one->SetBounds(gfx::Rect(0, 0, 500, 100)); | 50 one->SetBounds(gfx::Rect(0, 0, 500, 100)); |
| 63 two->SetBounds(gfx::Rect(501, 0, 500, 1000)); | 51 two->SetBounds(gfx::Rect(501, 0, 500, 1000)); |
| 64 | 52 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 122 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
| 135 ui::EF_NONE, ui::EF_NONE); | 123 ui::EF_NONE, ui::EF_NONE); |
| 136 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root_target, &mouse)); | 124 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root_target, &mouse)); |
| 137 } | 125 } |
| 138 | 126 |
| 139 // Scale |window| by 50%. This should move it away from underneath | 127 // Scale |window| by 50%. This should move it away from underneath |
| 140 // |event_location|, so an event in that location will not be targeted to it. | 128 // |event_location|, so an event in that location will not be targeted to it. |
| 141 gfx::Transform transform; | 129 gfx::Transform transform; |
| 142 transform.Scale(0.5, 0.5); | 130 transform.Scale(0.5, 0.5); |
| 143 window->SetTransform(transform); | 131 window->SetTransform(transform); |
| 144 EXPECT_EQ(gfx::RectF(100, 20, 200, 40).ToString(), | 132 EXPECT_EQ(gfx::Rect(100, 20, 200, 40).ToString(), |
| 145 GetEffectiveVisibleBoundsInRootWindow(window.get()).ToString()); | 133 window->GetBoundsInRootWindow().ToString()); |
| 146 { | 134 { |
| 147 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 135 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
| 148 ui::EF_NONE, ui::EF_NONE); | 136 ui::EF_NONE, ui::EF_NONE); |
| 149 EXPECT_EQ(root_window(), targeter->FindTargetForEvent(root_target, &mouse)); | 137 EXPECT_EQ(root_window(), targeter->FindTargetForEvent(root_target, &mouse)); |
| 150 } | 138 } |
| 151 | 139 |
| 152 transform = gfx::Transform(); | 140 transform = gfx::Transform(); |
| 153 transform.Translate(200, 10); | 141 transform.Translate(200, 10); |
| 154 transform.Scale(0.5, 0.5); | 142 transform.Scale(0.5, 0.5); |
| 155 window->SetTransform(transform); | 143 window->SetTransform(transform); |
| 156 EXPECT_EQ(gfx::RectF(300, 30, 200, 40).ToString(), | 144 EXPECT_EQ(gfx::Rect(300, 30, 200, 40).ToString(), |
| 157 GetEffectiveVisibleBoundsInRootWindow(window.get()).ToString()); | 145 window->GetBoundsInRootWindow().ToString()); |
| 158 { | 146 { |
| 159 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 147 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
| 160 ui::EF_NONE, ui::EF_NONE); | 148 ui::EF_NONE, ui::EF_NONE); |
| 161 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root_target, &mouse)); | 149 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root_target, &mouse)); |
| 162 } | 150 } |
| 163 } | 151 } |
| 164 | 152 |
| 165 } // namespace aura | 153 } // namespace aura |
| OLD | NEW |