| 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 "ash/magnifier/magnification_controller.h" | 5 #include "ash/magnifier/magnification_controller.h" |
| 6 | 6 |
| 7 #include "ash/magnifier/magnifier_constants.h" | |
| 8 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 9 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 10 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 11 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
| 12 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
| 13 #include "ui/aura/test/aura_test_utils.h" | 12 #include "ui/aura/test/aura_test_utils.h" |
| 14 #include "ui/aura/window_tree_host.h" | 13 #include "ui/aura/window_tree_host.h" |
| 15 #include "ui/base/ime/input_method.h" | 14 #include "ui/base/ime/input_method.h" |
| 15 #include "ui/chromeos/accessibility_types.h" |
| 16 #include "ui/events/test/event_generator.h" | 16 #include "ui/events/test/event_generator.h" |
| 17 #include "ui/gfx/rect_conversions.h" | 17 #include "ui/gfx/rect_conversions.h" |
| 18 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
| 19 #include "ui/views/controls/textfield/textfield.h" | 19 #include "ui/views/controls/textfield/textfield.h" |
| 20 #include "ui/views/layout/fill_layout.h" | 20 #include "ui/views/layout/fill_layout.h" |
| 21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 22 #include "ui/views/widget/widget_delegate.h" | 22 #include "ui/views/widget/widget_delegate.h" |
| 23 #include "ui/wm/core/coordinate_conversion.h" | 23 #include "ui/wm/core/coordinate_conversion.h" |
| 24 | 24 |
| 25 namespace ash { | 25 namespace ash { |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); | 434 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
| 435 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); | 435 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 436 EXPECT_EQ("400,300", env->last_mouse_location().ToString()); | 436 EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
| 437 | 437 |
| 438 float scale = 2.f; | 438 float scale = 2.f; |
| 439 | 439 |
| 440 // Enables magnifier and confirm the viewport is at center. | 440 // Enables magnifier and confirm the viewport is at center. |
| 441 GetMagnificationController()->SetEnabled(true); | 441 GetMagnificationController()->SetEnabled(true); |
| 442 EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale()); | 442 EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale()); |
| 443 | 443 |
| 444 scale *= kMagnificationScaleFactor; | 444 scale *= ui::kMagnificationScaleFactor; |
| 445 GetMagnificationController()->SetScale(scale, false); | 445 GetMagnificationController()->SetScale(scale, false); |
| 446 EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale()); | 446 EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale()); |
| 447 generator.MoveMouseToInHost(gfx::Point(400, 300)); | 447 generator.MoveMouseToInHost(gfx::Point(400, 300)); |
| 448 EXPECT_EQ("400,300", env->last_mouse_location().ToString()); | 448 EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
| 449 generator.MoveMouseToInHost(gfx::Point(799, 300)); | 449 generator.MoveMouseToInHost(gfx::Point(799, 300)); |
| 450 EXPECT_EQ("566,299", env->last_mouse_location().ToString()); | 450 EXPECT_EQ("566,299", env->last_mouse_location().ToString()); |
| 451 EXPECT_EQ("705,300", GetHostMouseLocation()); | 451 EXPECT_EQ("705,300", GetHostMouseLocation()); |
| 452 | 452 |
| 453 scale *= kMagnificationScaleFactor; | 453 scale *= ui::kMagnificationScaleFactor; |
| 454 GetMagnificationController()->SetScale(scale, false); | 454 GetMagnificationController()->SetScale(scale, false); |
| 455 EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale()); | 455 EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale()); |
| 456 generator.MoveMouseToInHost(gfx::Point(799, 300)); | 456 generator.MoveMouseToInHost(gfx::Point(799, 300)); |
| 457 EXPECT_EQ("599,299", env->last_mouse_location().ToString()); | 457 EXPECT_EQ("599,299", env->last_mouse_location().ToString()); |
| 458 EXPECT_EQ("702,300", GetHostMouseLocation()); | 458 EXPECT_EQ("702,300", GetHostMouseLocation()); |
| 459 | 459 |
| 460 scale *= kMagnificationScaleFactor; | 460 scale *= ui::kMagnificationScaleFactor; |
| 461 GetMagnificationController()->SetScale(scale, false); | 461 GetMagnificationController()->SetScale(scale, false); |
| 462 EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale()); | 462 EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale()); |
| 463 generator.MoveMouseToInHost(gfx::Point(799, 300)); | 463 generator.MoveMouseToInHost(gfx::Point(799, 300)); |
| 464 EXPECT_EQ("627,298", env->last_mouse_location().ToString()); | 464 EXPECT_EQ("627,298", env->last_mouse_location().ToString()); |
| 465 EXPECT_EQ("707,300", GetHostMouseLocation()); | 465 EXPECT_EQ("707,300", GetHostMouseLocation()); |
| 466 | 466 |
| 467 scale *= kMagnificationScaleFactor; | 467 scale *= ui::kMagnificationScaleFactor; |
| 468 GetMagnificationController()->SetScale(scale, false); | 468 GetMagnificationController()->SetScale(scale, false); |
| 469 EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); | 469 EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); |
| 470 generator.MoveMouseToInHost(gfx::Point(799, 300)); | 470 generator.MoveMouseToInHost(gfx::Point(799, 300)); |
| 471 EXPECT_EQ("649,298", env->last_mouse_location().ToString()); | 471 EXPECT_EQ("649,298", env->last_mouse_location().ToString()); |
| 472 EXPECT_EQ("704,300", GetHostMouseLocation()); | 472 EXPECT_EQ("704,300", GetHostMouseLocation()); |
| 473 } | 473 } |
| 474 | 474 |
| 475 TEST_F(MagnificationControllerTest, PanWindowToLeft) { | 475 TEST_F(MagnificationControllerTest, PanWindowToLeft) { |
| 476 const aura::Env* env = aura::Env::GetInstance(); | 476 const aura::Env* env = aura::Env::GetInstance(); |
| 477 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 477 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 478 | 478 |
| 479 generator.MoveMouseToInHost(gfx::Point(400, 300)); | 479 generator.MoveMouseToInHost(gfx::Point(400, 300)); |
| 480 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); | 480 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
| 481 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); | 481 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 482 EXPECT_EQ("400,300", env->last_mouse_location().ToString()); | 482 EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
| 483 | 483 |
| 484 float scale = 2.f; | 484 float scale = 2.f; |
| 485 | 485 |
| 486 // Enables magnifier and confirm the viewport is at center. | 486 // Enables magnifier and confirm the viewport is at center. |
| 487 GetMagnificationController()->SetEnabled(true); | 487 GetMagnificationController()->SetEnabled(true); |
| 488 EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale()); | 488 EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale()); |
| 489 | 489 |
| 490 scale *= kMagnificationScaleFactor; | 490 scale *= ui::kMagnificationScaleFactor; |
| 491 GetMagnificationController()->SetScale(scale, false); | 491 GetMagnificationController()->SetScale(scale, false); |
| 492 EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale()); | 492 EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale()); |
| 493 generator.MoveMouseToInHost(gfx::Point(400, 300)); | 493 generator.MoveMouseToInHost(gfx::Point(400, 300)); |
| 494 EXPECT_EQ("400,300", env->last_mouse_location().ToString()); | 494 EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
| 495 generator.MoveMouseToInHost(gfx::Point(0, 300)); | 495 generator.MoveMouseToInHost(gfx::Point(0, 300)); |
| 496 EXPECT_EQ("231,299", env->last_mouse_location().ToString()); | 496 EXPECT_EQ("231,299", env->last_mouse_location().ToString()); |
| 497 EXPECT_EQ("100,300", GetHostMouseLocation()); | 497 EXPECT_EQ("100,300", GetHostMouseLocation()); |
| 498 | 498 |
| 499 scale *= kMagnificationScaleFactor; | 499 scale *= ui::kMagnificationScaleFactor; |
| 500 GetMagnificationController()->SetScale(scale, false); | 500 GetMagnificationController()->SetScale(scale, false); |
| 501 EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale()); | 501 EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale()); |
| 502 generator.MoveMouseToInHost(gfx::Point(0, 300)); | 502 generator.MoveMouseToInHost(gfx::Point(0, 300)); |
| 503 EXPECT_EQ("194,299", env->last_mouse_location().ToString()); | 503 EXPECT_EQ("194,299", env->last_mouse_location().ToString()); |
| 504 EXPECT_EQ("99,300", GetHostMouseLocation()); | 504 EXPECT_EQ("99,300", GetHostMouseLocation()); |
| 505 | 505 |
| 506 scale *= kMagnificationScaleFactor; | 506 scale *= ui::kMagnificationScaleFactor; |
| 507 GetMagnificationController()->SetScale(scale, false); | 507 GetMagnificationController()->SetScale(scale, false); |
| 508 EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale()); | 508 EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale()); |
| 509 generator.MoveMouseToInHost(gfx::Point(0, 300)); | 509 generator.MoveMouseToInHost(gfx::Point(0, 300)); |
| 510 EXPECT_EQ("164,298", env->last_mouse_location().ToString()); | 510 EXPECT_EQ("164,298", env->last_mouse_location().ToString()); |
| 511 EXPECT_EQ("98,300", GetHostMouseLocation()); | 511 EXPECT_EQ("98,300", GetHostMouseLocation()); |
| 512 | 512 |
| 513 scale *= kMagnificationScaleFactor; | 513 scale *= ui::kMagnificationScaleFactor; |
| 514 GetMagnificationController()->SetScale(scale, false); | 514 GetMagnificationController()->SetScale(scale, false); |
| 515 EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); | 515 EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); |
| 516 generator.MoveMouseToInHost(gfx::Point(0, 300)); | 516 generator.MoveMouseToInHost(gfx::Point(0, 300)); |
| 517 EXPECT_EQ("139,298", env->last_mouse_location().ToString()); | 517 EXPECT_EQ("139,298", env->last_mouse_location().ToString()); |
| 518 EXPECT_EQ("100,300", GetHostMouseLocation()); | 518 EXPECT_EQ("100,300", GetHostMouseLocation()); |
| 519 } | 519 } |
| 520 | 520 |
| 521 TEST_F(MagnificationControllerTest, FollowTextInputFieldFocus) { | 521 TEST_F(MagnificationControllerTest, FollowTextInputFieldFocus) { |
| 522 CreateAndShowTextInputView(gfx::Rect(500, 300, 80, 80)); | 522 CreateAndShowTextInputView(gfx::Rect(500, 300, 80, 80)); |
| 523 gfx::Rect text_input_bounds = GetTextInputViewBounds(); | 523 gfx::Rect text_input_bounds = GetTextInputViewBounds(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 gfx::Rect caret_bounds = GetCaretBounds(); | 578 gfx::Rect caret_bounds = GetCaretBounds(); |
| 579 EXPECT_FALSE(view_port.Intersects(caret_bounds)); | 579 EXPECT_FALSE(view_port.Intersects(caret_bounds)); |
| 580 | 580 |
| 581 gfx::Rect new_view_port = GetViewport(); | 581 gfx::Rect new_view_port = GetViewport(); |
| 582 EXPECT_TRUE(new_view_port.Contains(caret_bounds)); | 582 EXPECT_TRUE(new_view_port.Contains(caret_bounds)); |
| 583 EXPECT_EQ(caret_bounds.x(), new_view_port.CenterPoint().x()); | 583 EXPECT_EQ(caret_bounds.x(), new_view_port.CenterPoint().x()); |
| 584 EXPECT_EQ(view_port.y(), new_view_port.y()); | 584 EXPECT_EQ(view_port.y(), new_view_port.y()); |
| 585 } | 585 } |
| 586 | 586 |
| 587 } // namespace ash | 587 } // namespace ash |
| OLD | NEW |