diff options
author | yoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-26 09:02:09 +0000 |
---|---|---|
committer | yoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-26 09:02:09 +0000 |
commit | 6f16249b5b2fda0743907d80c1bc22ada2b50f03 (patch) | |
tree | e4acb3ce9f1d44620571981b61ecc1036b15061a /ash/magnifier | |
parent | d4c91652b62a8b18c5e6f13fbab0aea13c8f6478 (diff) | |
download | chromium_src-6f16249b5b2fda0743907d80c1bc22ada2b50f03.zip chromium_src-6f16249b5b2fda0743907d80c1bc22ada2b50f03.tar.gz chromium_src-6f16249b5b2fda0743907d80c1bc22ada2b50f03.tar.bz2 |
Magnifier: Move the cursor directly to the root window host.
- Add RootWindow::MoveCursorToInHost() to move the cursor to the specified location in the host.
- Use it in MagnificationController to move the cursor instead of MoveCursorTo().
BUG=223983, 230979
TEST=ash_unittests passes.
Review URL: https://chromiumcodereview.appspot.com/13947045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196683 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/magnifier')
-rw-r--r-- | ash/magnifier/magnification_controller.cc | 7 | ||||
-rw-r--r-- | ash/magnifier/magnification_controller.h | 5 | ||||
-rw-r--r-- | ash/magnifier/magnification_controller_unittest.cc | 292 | ||||
-rw-r--r-- | ash/magnifier/magnifier_constants.h | 5 |
4 files changed, 305 insertions, 4 deletions
diff --git a/ash/magnifier/magnification_controller.cc b/ash/magnifier/magnification_controller.cc index 21cb63b..55785c7 100644 --- a/ash/magnifier/magnification_controller.cc +++ b/ash/magnifier/magnification_controller.cc @@ -10,6 +10,7 @@ #include "ash/shell.h" #include "ash/shell_delegate.h" #include "ash/system/tray/system_tray_delegate.h" +#include "base/synchronization/waitable_event.h" #include "ui/aura/client/cursor_client.h" #include "ui/aura/root_window.h" #include "ui/aura/root_window_transformer.h" @@ -46,7 +47,7 @@ void MoveCursorTo(aura::RootWindow* root_window, const gfx::Point root_location) { gfx::Point3F host_location_3f(root_location); root_window->layer()->transform().TransformPoint(host_location_3f); - root_window->MoveCursorToHostLoation( + root_window->MoveCursorToHostLocation( gfx::ToCeiledPoint(host_location_3f.AsPointF())); } @@ -79,6 +80,10 @@ class MagnificationControllerImpl : virtual public MagnificationController, bool animate) OVERRIDE; virtual void EnsurePointIsVisible(const gfx::Point& point, bool animate) OVERRIDE; + // For test + virtual gfx::Point GetPointOfInterestForTesting() OVERRIDE { + return point_of_interest_; + } private: // ui::ImplicitAnimationObserver overrides: diff --git a/ash/magnifier/magnification_controller.h b/ash/magnifier/magnification_controller.h index aa70618..75d1b2f 100644 --- a/ash/magnifier/magnification_controller.h +++ b/ash/magnifier/magnification_controller.h @@ -47,6 +47,11 @@ class MagnificationController { virtual void EnsureRectIsVisible(const gfx::Rect& rect, bool animate) = 0; virtual void EnsurePointIsVisible(const gfx::Point& point, bool animate) = 0; + // Returns |point_of_interest_| in MagnificationControllerImpl. This is + // the internal variable to stores the last mouse cursor (or last touched) + // location. This method is only for test purpose. + virtual gfx::Point GetPointOfInterestForTesting() = 0; + protected: MagnificationController() {} }; diff --git a/ash/magnifier/magnification_controller_unittest.cc b/ash/magnifier/magnification_controller_unittest.cc index b26ec36..5611b98 100644 --- a/ash/magnifier/magnification_controller_unittest.cc +++ b/ash/magnifier/magnification_controller_unittest.cc @@ -4,11 +4,14 @@ #include "ash/display/display_controller.h" #include "ash/magnifier/magnification_controller.h" +#include "ash/magnifier/magnifier_constants.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" #include "base/stringprintf.h" #include "ui/aura/client/aura_constants.h" +#include "ui/aura/env.h" #include "ui/aura/root_window.h" +#include "ui/aura/test/event_generator.h" #include "ui/gfx/rect_conversions.h" #include "ui/gfx/screen.h" @@ -46,20 +49,37 @@ class MagnificationControllerTest: public test::AshTestBase { } protected: - aura::RootWindow* GetRootWindow() { + aura::RootWindow* GetRootWindow() const { return Shell::GetPrimaryRootWindow(); } - ash::MagnificationController* GetMagnificationController() { + + void MoveCursorWithEvent(gfx::Point point) { + aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); + generator.MoveMouseTo(point.x(), point.y()); + } + + std::string GetHostMouseLocation() { + gfx::Point point; + GetRootWindow()->QueryMouseLocationForTest(&point); + return point.ToString(); + } + + ash::MagnificationController* GetMagnificationController() const { return ash::Shell::GetInstance()->magnification_controller(); } - gfx::Rect GetViewport() { + gfx::Rect GetViewport() const { gfx::RectF bounds(0, 0, kRootWidth, kRootHeight); GetRootWindow()->layer()->transform().TransformRectReverse(&bounds); return gfx::ToEnclosingRect(bounds); } + std::string CurrentPointOfInterest() const { + return GetMagnificationController()-> + GetPointOfInterestForTesting().ToString(); + } + private: DISALLOW_COPY_AND_ASSIGN(MagnificationControllerTest); }; @@ -95,19 +115,23 @@ TEST_F(MagnificationControllerTest, MagnifyAndUnmagnify) { EXPECT_FALSE(GetRootWindow()->layer()->transform().IsIdentity()); EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); EXPECT_EQ("200,150 400x300", GetViewport().ToString()); + EXPECT_EQ("400,300", CurrentPointOfInterest()); // Changes the scale. GetMagnificationController()->SetScale(4.0f, false); EXPECT_EQ(4.0f, GetMagnificationController()->GetScale()); EXPECT_EQ("300,225 200x150", GetViewport().ToString()); + EXPECT_EQ("400,300", CurrentPointOfInterest()); GetMagnificationController()->SetScale(1.0f, false); EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); EXPECT_EQ("0,0 800x600", GetViewport().ToString()); + EXPECT_EQ("400,300", CurrentPointOfInterest()); GetMagnificationController()->SetScale(3.0f, false); EXPECT_EQ(3.0f, GetMagnificationController()->GetScale()); EXPECT_EQ("266,200 267x200", GetViewport().ToString()); + EXPECT_EQ("400,300", CurrentPointOfInterest()); } TEST_F(MagnificationControllerTest, MoveWindow) { @@ -153,5 +177,267 @@ TEST_F(MagnificationControllerTest, MoveWindow) { EXPECT_EQ("400,300 400x300", GetViewport().ToString()); } +TEST_F(MagnificationControllerTest, PointOfInterest) { + MoveCursorWithEvent(gfx::Point(0, 0)); + EXPECT_EQ("0,0", CurrentPointOfInterest()); + + MoveCursorWithEvent(gfx::Point(799, 599)); + EXPECT_EQ("799,599", CurrentPointOfInterest()); + + MoveCursorWithEvent(gfx::Point(400, 300)); + EXPECT_EQ("400,300", CurrentPointOfInterest()); + + GetMagnificationController()->SetEnabled(true); + EXPECT_EQ("400,300", CurrentPointOfInterest()); + + MoveCursorWithEvent(gfx::Point(500, 400)); + EXPECT_EQ("450,350", CurrentPointOfInterest()); +} + +TEST_F(MagnificationControllerTest, PanWindow2xLeftToRight) { + const aura::Env* env = aura::Env::GetInstance(); + + MoveCursorWithEvent(gfx::Point(0, 0)); + EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); + EXPECT_EQ("0,0 800x600", GetViewport().ToString()); + EXPECT_EQ("0,0", env->last_mouse_location().ToString()); + + // Enables magnifier and confirm the viewport is at center. + GetMagnificationController()->SetEnabled(true); + EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); + + GetMagnificationController()->MoveWindow(0, 0, false); + MoveCursorWithEvent(gfx::Point(0, 0)); + EXPECT_EQ("0,0", env->last_mouse_location().ToString()); + EXPECT_EQ("0,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(300, 150)); + EXPECT_EQ("150,75", env->last_mouse_location().ToString()); + EXPECT_EQ("0,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(700, 150)); + EXPECT_EQ("350,75", env->last_mouse_location().ToString()); + EXPECT_EQ("0,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(701, 150)); + EXPECT_EQ("350,75", env->last_mouse_location().ToString()); + EXPECT_EQ("0,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(702, 150)); + EXPECT_EQ("351,75", env->last_mouse_location().ToString()); + EXPECT_EQ("1,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(703, 150)); + EXPECT_EQ("352,75", env->last_mouse_location().ToString()); + EXPECT_EQ("2,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(704, 150)); + EXPECT_EQ("354,75", env->last_mouse_location().ToString()); + EXPECT_EQ("4,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(712, 150)); + EXPECT_EQ("360,75", env->last_mouse_location().ToString()); + EXPECT_EQ("10,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(600, 150)); + EXPECT_EQ("310,75", env->last_mouse_location().ToString()); + EXPECT_EQ("10,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(720, 150)); + EXPECT_EQ("370,75", env->last_mouse_location().ToString()); + EXPECT_EQ("20,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(780, 150)); + EXPECT_EQ("410,75", env->last_mouse_location().ToString()); + EXPECT_EQ("410,75", CurrentPointOfInterest()); + EXPECT_EQ("60,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(799, 150)); + EXPECT_EQ("459,75", env->last_mouse_location().ToString()); + EXPECT_EQ("109,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(702, 150)); + EXPECT_EQ("460,75", env->last_mouse_location().ToString()); + EXPECT_EQ("110,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(780, 150)); + EXPECT_EQ("500,75", env->last_mouse_location().ToString()); + EXPECT_EQ("150,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(780, 150)); + EXPECT_EQ("540,75", env->last_mouse_location().ToString()); + EXPECT_EQ("190,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(780, 150)); + EXPECT_EQ("580,75", env->last_mouse_location().ToString()); + EXPECT_EQ("230,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(780, 150)); + EXPECT_EQ("620,75", env->last_mouse_location().ToString()); + EXPECT_EQ("270,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(780, 150)); + EXPECT_EQ("660,75", env->last_mouse_location().ToString()); + EXPECT_EQ("310,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(780, 150)); + EXPECT_EQ("700,75", env->last_mouse_location().ToString()); + EXPECT_EQ("350,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(780, 150)); + EXPECT_EQ("740,75", env->last_mouse_location().ToString()); + EXPECT_EQ("390,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(780, 150)); + EXPECT_EQ("780,75", env->last_mouse_location().ToString()); + EXPECT_EQ("400,0 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(799, 150)); + EXPECT_EQ("799,75", env->last_mouse_location().ToString()); + EXPECT_EQ("400,0 400x300", GetViewport().ToString()); +} + +TEST_F(MagnificationControllerTest, PanWindow2xRightToLeft) { + const aura::Env* env = aura::Env::GetInstance(); + + MoveCursorWithEvent(gfx::Point(799, 300)); + EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); + EXPECT_EQ("0,0 800x600", GetViewport().ToString()); + EXPECT_EQ("799,300", env->last_mouse_location().ToString()); + + // Enables magnifier and confirm the viewport is at center. + GetMagnificationController()->SetEnabled(true); + + MoveCursorWithEvent(gfx::Point(799, 300)); + EXPECT_EQ("798,300", env->last_mouse_location().ToString()); + EXPECT_EQ("400,150 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(0, 300)); + EXPECT_EQ("400,300", env->last_mouse_location().ToString()); + EXPECT_EQ("350,150 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(0, 300)); + EXPECT_EQ("350,300", env->last_mouse_location().ToString()); + EXPECT_EQ("300,150 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(0, 300)); + EXPECT_EQ("300,300", env->last_mouse_location().ToString()); + EXPECT_EQ("250,150 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(0, 300)); + EXPECT_EQ("250,300", env->last_mouse_location().ToString()); + EXPECT_EQ("200,150 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(0, 300)); + EXPECT_EQ("200,300", env->last_mouse_location().ToString()); + EXPECT_EQ("150,150 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(0, 300)); + EXPECT_EQ("150,300", env->last_mouse_location().ToString()); + EXPECT_EQ("100,150 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(0, 300)); + EXPECT_EQ("100,300", env->last_mouse_location().ToString()); + EXPECT_EQ("50,150 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(0, 300)); + EXPECT_EQ("50,300", env->last_mouse_location().ToString()); + EXPECT_EQ("0,150 400x300", GetViewport().ToString()); + + MoveCursorWithEvent(gfx::Point(0, 300)); + EXPECT_EQ("0,300", env->last_mouse_location().ToString()); + EXPECT_EQ("0,150 400x300", GetViewport().ToString()); +} + +TEST_F(MagnificationControllerTest, PanWindowToRight) { + const aura::Env* env = aura::Env::GetInstance(); + + MoveCursorWithEvent(gfx::Point(400, 300)); + EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); + EXPECT_EQ("0,0 800x600", GetViewport().ToString()); + EXPECT_EQ("400,300", env->last_mouse_location().ToString()); + + float scale = 2.f; + + // Enables magnifier and confirm the viewport is at center. + GetMagnificationController()->SetEnabled(true); + EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale()); + + scale *= kMagnificationScaleFactor; + GetMagnificationController()->SetScale(scale, false); + EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale()); + MoveCursorWithEvent(gfx::Point(400, 300)); + EXPECT_EQ("400,300", env->last_mouse_location().ToString()); + MoveCursorWithEvent(gfx::Point(799, 300)); + EXPECT_EQ("566,299", env->last_mouse_location().ToString()); + EXPECT_EQ("705,300", GetHostMouseLocation()); + + scale *= kMagnificationScaleFactor; + GetMagnificationController()->SetScale(scale, false); + EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale()); + MoveCursorWithEvent(gfx::Point(799, 300)); + EXPECT_EQ("599,299", env->last_mouse_location().ToString()); + EXPECT_EQ("702,300", GetHostMouseLocation()); + + scale *= kMagnificationScaleFactor; + GetMagnificationController()->SetScale(scale, false); + EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale()); + MoveCursorWithEvent(gfx::Point(799, 300)); + EXPECT_EQ("627,298", env->last_mouse_location().ToString()); + EXPECT_EQ("707,300", GetHostMouseLocation()); + + scale *= kMagnificationScaleFactor; + GetMagnificationController()->SetScale(scale, false); + EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); + MoveCursorWithEvent(gfx::Point(799, 300)); + EXPECT_EQ("649,298", env->last_mouse_location().ToString()); + EXPECT_EQ("704,300", GetHostMouseLocation()); +} + +TEST_F(MagnificationControllerTest, PanWindowToLeft) { + const aura::Env* env = aura::Env::GetInstance(); + + MoveCursorWithEvent(gfx::Point(400, 300)); + EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); + EXPECT_EQ("0,0 800x600", GetViewport().ToString()); + EXPECT_EQ("400,300", env->last_mouse_location().ToString()); + + float scale = 2.f; + + // Enables magnifier and confirm the viewport is at center. + GetMagnificationController()->SetEnabled(true); + EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale()); + + scale *= kMagnificationScaleFactor; + GetMagnificationController()->SetScale(scale, false); + EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale()); + MoveCursorWithEvent(gfx::Point(400, 300)); + EXPECT_EQ("400,300", env->last_mouse_location().ToString()); + MoveCursorWithEvent(gfx::Point(0, 300)); + EXPECT_EQ("231,299", env->last_mouse_location().ToString()); + EXPECT_EQ("100,300", GetHostMouseLocation()); + + scale *= kMagnificationScaleFactor; + GetMagnificationController()->SetScale(scale, false); + EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale()); + MoveCursorWithEvent(gfx::Point(0, 300)); + EXPECT_EQ("195,299", env->last_mouse_location().ToString()); + EXPECT_EQ("99,300", GetHostMouseLocation()); + + scale *= kMagnificationScaleFactor; + GetMagnificationController()->SetScale(scale, false); + EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale()); + MoveCursorWithEvent(gfx::Point(0, 300)); + EXPECT_EQ("165,298", env->last_mouse_location().ToString()); + EXPECT_EQ("98,300", GetHostMouseLocation()); + + scale *= kMagnificationScaleFactor; + GetMagnificationController()->SetScale(scale, false); + EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); + MoveCursorWithEvent(gfx::Point(0, 300)); + EXPECT_EQ("140,298", env->last_mouse_location().ToString()); + EXPECT_EQ("100,300", GetHostMouseLocation()); +} + } // namespace internal } // namespace ash diff --git a/ash/magnifier/magnifier_constants.h b/ash/magnifier/magnifier_constants.h index aa7cac7..b286299 100644 --- a/ash/magnifier/magnifier_constants.h +++ b/ash/magnifier/magnifier_constants.h @@ -17,6 +17,11 @@ const int kMaxMagnifierType = 2; const MagnifierType kDefaultMagnifierType = MAGNIFIER_FULL; +// Factor of magnification scale. For example, when this value is 1.189, scale +// value will be changed x1.000, x1.189, x1.414, x1.681, x2.000, ... +// Note: this value is 2.0 ^ (1 / 4). +const float kMagnificationScaleFactor = 1.18920712f; + } // namespace ash #endif // ASH_MAGNIFIER_MAGNIFIER_CONSTANTS_H_ |