| 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/aura/window.h" | 5 #include "ui/aura/window.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 gfx::Point reference_point(100, 100); | 266 gfx::Point reference_point(100, 100); |
| 267 gfx::Point test_point = reference_point; | 267 gfx::Point test_point = reference_point; |
| 268 Window::ConvertPointToWindow(NULL, w1.get(), &test_point); | 268 Window::ConvertPointToWindow(NULL, w1.get(), &test_point); |
| 269 EXPECT_EQ(reference_point, test_point); | 269 EXPECT_EQ(reference_point, test_point); |
| 270 } | 270 } |
| 271 | 271 |
| 272 TEST_F(WindowTest, HitTest) { | 272 TEST_F(WindowTest, HitTest) { |
| 273 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); | 273 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); |
| 274 w1.set_id(1); | 274 w1.set_id(1); |
| 275 w1.Init(ui::Layer::LAYER_TEXTURED); | 275 w1.Init(ui::Layer::LAYER_TEXTURED); |
| 276 w1.SetBounds(gfx::Rect(10, 10, 50, 50)); | 276 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); |
| 277 w1.Show(); | 277 w1.Show(); |
| 278 w1.SetParent(NULL); | 278 w1.SetParent(NULL); |
| 279 | 279 |
| 280 // Points are in the Window's coordinates. | 280 // Points are in the Window's coordinates. |
| 281 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); | 281 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); |
| 282 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1))); | 282 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1))); |
| 283 | 283 |
| 284 // We can expand the bounds slightly to track events outside our border. |
| 285 w1.set_hit_test_bounds_inset(-1); |
| 286 EXPECT_TRUE(w1.HitTest(gfx::Point(-1, -1))); |
| 287 EXPECT_FALSE(w1.HitTest(gfx::Point(-2, -2))); |
| 288 |
| 284 // TODO(beng): clip Window to parent. | 289 // TODO(beng): clip Window to parent. |
| 285 } | 290 } |
| 286 | 291 |
| 287 TEST_F(WindowTest, GetEventHandlerForPoint) { | 292 TEST_F(WindowTest, GetEventHandlerForPoint) { |
| 288 scoped_ptr<Window> w1( | 293 scoped_ptr<Window> w1( |
| 289 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); | 294 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); |
| 290 scoped_ptr<Window> w11( | 295 scoped_ptr<Window> w11( |
| 291 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 296 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 292 scoped_ptr<Window> w111( | 297 scoped_ptr<Window> w111( |
| 293 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 298 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
| (...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1722 | 1727 |
| 1723 w1.reset(); // Deletes w11 and w111. | 1728 w1.reset(); // Deletes w11 and w111. |
| 1724 w11 = NULL; | 1729 w11 = NULL; |
| 1725 w111 = NULL; | 1730 w111 = NULL; |
| 1726 EXPECT_EQ(2, observer.added_count()); | 1731 EXPECT_EQ(2, observer.added_count()); |
| 1727 EXPECT_EQ(2, observer.removed_count()); | 1732 EXPECT_EQ(2, observer.removed_count()); |
| 1728 } | 1733 } |
| 1729 | 1734 |
| 1730 } // namespace test | 1735 } // namespace test |
| 1731 } // namespace aura | 1736 } // namespace aura |
| OLD | NEW |