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" |
11 #include "ui/aura/client/capture_client.h" | 11 #include "ui/aura/client/capture_client.h" |
12 #include "ui/aura/client/stacking_client.h" | 12 #include "ui/aura/client/stacking_client.h" |
13 #include "ui/aura/client/visibility_client.h" | 13 #include "ui/aura/client/visibility_client.h" |
14 #include "ui/aura/event.h" | 14 #include "ui/aura/event.h" |
15 #include "ui/aura/layout_manager.h" | 15 #include "ui/aura/layout_manager.h" |
16 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
| 17 #include "ui/aura/root_window_host.h" |
17 #include "ui/aura/root_window_observer.h" | 18 #include "ui/aura/root_window_observer.h" |
18 #include "ui/aura/test/aura_test_base.h" | 19 #include "ui/aura/test/aura_test_base.h" |
19 #include "ui/aura/test/event_generator.h" | 20 #include "ui/aura/test/event_generator.h" |
20 #include "ui/aura/test/test_window_delegate.h" | 21 #include "ui/aura/test/test_window_delegate.h" |
21 #include "ui/aura/test/test_windows.h" | 22 #include "ui/aura/test/test_windows.h" |
22 #include "ui/aura/window_delegate.h" | 23 #include "ui/aura/window_delegate.h" |
23 #include "ui/aura/window_observer.h" | 24 #include "ui/aura/window_observer.h" |
24 #include "ui/aura/window_property.h" | 25 #include "ui/aura/window_property.h" |
25 #include "ui/base/gestures/gesture_configuration.h" | 26 #include "ui/base/gestures/gesture_configuration.h" |
26 #include "ui/base/hit_test.h" | 27 #include "ui/base/hit_test.h" |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 // Window::ConvertPointToWindow is mostly identical to | 296 // Window::ConvertPointToWindow is mostly identical to |
296 // Layer::ConvertPointToLayer, except NULL values for |source| are permitted, | 297 // Layer::ConvertPointToLayer, except NULL values for |source| are permitted, |
297 // in which case the function just returns. | 298 // in which case the function just returns. |
298 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 299 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); |
299 gfx::Point reference_point(100, 100); | 300 gfx::Point reference_point(100, 100); |
300 gfx::Point test_point = reference_point; | 301 gfx::Point test_point = reference_point; |
301 Window::ConvertPointToWindow(NULL, w1.get(), &test_point); | 302 Window::ConvertPointToWindow(NULL, w1.get(), &test_point); |
302 EXPECT_EQ(reference_point, test_point); | 303 EXPECT_EQ(reference_point, test_point); |
303 } | 304 } |
304 | 305 |
| 306 TEST_F(WindowTest, MoveCursorTo) { |
| 307 scoped_ptr<Window> w1( |
| 308 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); |
| 309 scoped_ptr<Window> w11( |
| 310 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 311 scoped_ptr<Window> w111( |
| 312 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
| 313 scoped_ptr<Window> w1111( |
| 314 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
| 315 |
| 316 RootWindow* root = root_window(); |
| 317 root->MoveCursorTo(gfx::Point(10, 10)); |
| 318 EXPECT_EQ("10,10", root->last_mouse_location().ToString()); |
| 319 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 320 EXPECT_EQ("20,20", root->last_mouse_location().ToString()); |
| 321 w11->MoveCursorTo(gfx::Point(10, 10)); |
| 322 EXPECT_EQ("25,25", root->last_mouse_location().ToString()); |
| 323 w111->MoveCursorTo(gfx::Point(10, 10)); |
| 324 EXPECT_EQ("30,30", root->last_mouse_location().ToString()); |
| 325 w1111->MoveCursorTo(gfx::Point(10, 10)); |
| 326 EXPECT_EQ("35,35", root->last_mouse_location().ToString()); |
| 327 } |
| 328 |
| 329 // Test Window::ConvertPointToWindow() with transform to root_window. |
| 330 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { |
| 331 RootWindow* root = root_window(); |
| 332 ui::Transform transform; |
| 333 transform.ConcatScale(2, 5); |
| 334 transform.ConcatRotate(90.0f); |
| 335 transform.ConcatTranslate(100, 100); |
| 336 root->SetTransform(transform); |
| 337 root->MoveCursorTo(gfx::Point(10, 10)); |
| 338 EXPECT_EQ("50,120", root->QueryMouseLocationForTest().ToString()); |
| 339 EXPECT_EQ("10,10", root->last_mouse_location().ToString()); |
| 340 } |
| 341 |
| 342 // Tests Window::ConvertPointToWindow() with transform to non-root windows. |
| 343 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { |
| 344 scoped_ptr<Window> w1( |
| 345 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); |
| 346 |
| 347 RootWindow* root = root_window(); |
| 348 ui::Transform transform1; |
| 349 transform1.ConcatScale(2, 2); |
| 350 w1->SetTransform(transform1); |
| 351 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 352 EXPECT_EQ("30,30", root->last_mouse_location().ToString()); |
| 353 |
| 354 ui::Transform transform2; |
| 355 transform2.ConcatTranslate(-10, 20); |
| 356 w1->SetTransform(transform2); |
| 357 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 358 EXPECT_EQ("10,40", root->last_mouse_location().ToString()); |
| 359 |
| 360 ui::Transform transform3; |
| 361 transform3.ConcatRotate(90.0f); |
| 362 w1->SetTransform(transform3); |
| 363 w1->MoveCursorTo(gfx::Point(5, 5)); |
| 364 EXPECT_EQ("5,15", root->last_mouse_location().ToString()); |
| 365 |
| 366 ui::Transform transform4; |
| 367 transform4.ConcatScale(2, 5); |
| 368 transform4.ConcatRotate(90.0f); |
| 369 transform4.ConcatTranslate(100, 100); |
| 370 w1->SetTransform(transform4); |
| 371 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 372 EXPECT_EQ("60,130", root->last_mouse_location().ToString()); |
| 373 } |
| 374 |
| 375 // Test Window::ConvertPointToWindow() with complex transforms to both root and |
| 376 // non-root windows. |
| 377 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { |
| 378 scoped_ptr<Window> w1( |
| 379 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); |
| 380 scoped_ptr<Window> w11( |
| 381 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 382 scoped_ptr<Window> w111( |
| 383 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
| 384 scoped_ptr<Window> w1111( |
| 385 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
| 386 |
| 387 RootWindow* root = root_window(); |
| 388 ui::Transform transform; |
| 389 transform.ConcatScale(0.3f, 0.5f); |
| 390 transform.ConcatRotate(10.0f); |
| 391 transform.ConcatTranslate(10, 20); |
| 392 |
| 393 root->SetTransform(transform); |
| 394 w1->SetTransform(transform); |
| 395 w11->SetTransform(transform); |
| 396 w111->SetTransform(transform); |
| 397 w1111->SetTransform(transform); |
| 398 |
| 399 w1111->MoveCursorTo(gfx::Point(10, 10)); |
| 400 EXPECT_EQ("11,47", root->QueryMouseLocationForTest().ToString()); |
| 401 EXPECT_EQ("20,53", root->last_mouse_location().ToString()); |
| 402 } |
| 403 |
305 TEST_F(WindowTest, HitTest) { | 404 TEST_F(WindowTest, HitTest) { |
306 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); | 405 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); |
307 w1.set_id(1); | 406 w1.set_id(1); |
308 w1.Init(ui::LAYER_TEXTURED); | 407 w1.Init(ui::LAYER_TEXTURED); |
309 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); | 408 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); |
310 w1.Show(); | 409 w1.Show(); |
311 w1.SetParent(NULL); | 410 w1.SetParent(NULL); |
312 | 411 |
313 // Points are in the Window's coordinates. | 412 // Points are in the Window's coordinates. |
314 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); | 413 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); |
(...skipping 1974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2289 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 2388 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
2290 | 2389 |
2291 // No bounds changed notification at the end of animation since layer | 2390 // No bounds changed notification at the end of animation since layer |
2292 // delegate is NULL. | 2391 // delegate is NULL. |
2293 EXPECT_FALSE(delegate.bounds_changed()); | 2392 EXPECT_FALSE(delegate.bounds_changed()); |
2294 EXPECT_NE("0,0 100x100", window->bounds().ToString()); | 2393 EXPECT_NE("0,0 100x100", window->bounds().ToString()); |
2295 } | 2394 } |
2296 | 2395 |
2297 } // namespace test | 2396 } // namespace test |
2298 } // namespace aura | 2397 } // namespace aura |
OLD | NEW |