Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Unified Diff: ui/aura/window_unittest.cc

Issue 10543174: Aura: Add Window::MoveCursorTo() taking relative location to the window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fix Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ui/aura/root_window.cc ('K') | « ui/aura/window.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/window_unittest.cc
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 5932a4cc74acd96a075b08a5a0587d3d82e03f5b..59c87f11420f64c5be2b774ffe30037c3139553e 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -14,6 +14,7 @@
#include "ui/aura/event.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/root_window.h"
+#include "ui/aura/root_window_host.h"
#include "ui/aura/root_window_observer.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/event_generator.h"
@@ -302,6 +303,104 @@ TEST_F(WindowTest, ConvertPointToWindow) {
EXPECT_EQ(reference_point, test_point);
}
+TEST_F(WindowTest, MoveCursorTo) {
+ scoped_ptr<Window> w1(
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL));
+ scoped_ptr<Window> w11(
+ CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get()));
+ scoped_ptr<Window> w111(
+ CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get()));
+ scoped_ptr<Window> w1111(
+ CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get()));
+
+ RootWindow* root = root_window();
+ root->MoveCursorTo(gfx::Point(10, 10));
+ EXPECT_EQ("10,10", root->last_mouse_location().ToString());
+ w1->MoveCursorTo(gfx::Point(10, 10));
+ EXPECT_EQ("20,20", root->last_mouse_location().ToString());
+ w11->MoveCursorTo(gfx::Point(10, 10));
+ EXPECT_EQ("25,25", root->last_mouse_location().ToString());
+ w111->MoveCursorTo(gfx::Point(10, 10));
+ EXPECT_EQ("30,30", root->last_mouse_location().ToString());
+ w1111->MoveCursorTo(gfx::Point(10, 10));
+ EXPECT_EQ("35,35", root->last_mouse_location().ToString());
+}
+
+// Test Window::ConvertPointToWindow() with transform to root_window.
+TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) {
+ RootWindow* root = root_window();
+ ui::Transform transform;
+ transform.ConcatScale(2, 5);
+ transform.ConcatRotate(90.0f);
+ transform.ConcatTranslate(100, 100);
+ root->SetTransform(transform);
+ root->MoveCursorTo(gfx::Point(10, 10));
+ EXPECT_EQ("50,120", root->QueryMouseLocationForTest().ToString());
+ EXPECT_EQ("10,10", root->last_mouse_location().ToString());
+}
+
+// Tests Window::ConvertPointToWindow() with transform to non-root windows.
+TEST_F(WindowTest, MoveCursorToWithTransformWindow) {
+ scoped_ptr<Window> w1(
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL));
+
+ RootWindow* root = root_window();
+ ui::Transform transform1;
+ transform1.ConcatScale(2, 2);
+ w1->SetTransform(transform1);
+ w1->MoveCursorTo(gfx::Point(10, 10));
+ EXPECT_EQ("30,30", root->last_mouse_location().ToString());
+
+ ui::Transform transform2;
+ transform2.ConcatTranslate(-10, 20);
+ w1->SetTransform(transform2);
+ w1->MoveCursorTo(gfx::Point(10, 10));
+ EXPECT_EQ("10,40", root->last_mouse_location().ToString());
+
+ ui::Transform transform3;
+ transform3.ConcatRotate(90.0f);
+ w1->SetTransform(transform3);
+ w1->MoveCursorTo(gfx::Point(5, 5));
+ EXPECT_EQ("5,15", root->last_mouse_location().ToString());
+
+ ui::Transform transform4;
+ transform4.ConcatScale(2, 5);
+ transform4.ConcatRotate(90.0f);
+ transform4.ConcatTranslate(100, 100);
+ w1->SetTransform(transform4);
+ w1->MoveCursorTo(gfx::Point(10, 10));
+ EXPECT_EQ("60,130", root->last_mouse_location().ToString());
+}
+
+// Test Window::ConvertPointToWindow() with complex transforms to both root and
+// non-root windows.
+TEST_F(WindowTest, MoveCursorToWithComplexTransform) {
+ scoped_ptr<Window> w1(
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL));
+ scoped_ptr<Window> w11(
+ CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get()));
+ scoped_ptr<Window> w111(
+ CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get()));
+ scoped_ptr<Window> w1111(
+ CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get()));
+
+ RootWindow* root = root_window();
+ ui::Transform transform;
+ transform.ConcatScale(0.3f, 0.5f);
+ transform.ConcatRotate(10.0f);
+ transform.ConcatTranslate(10, 20);
+
+ root->SetTransform(transform);
+ w1->SetTransform(transform);
+ w11->SetTransform(transform);
+ w111->SetTransform(transform);
+ w1111->SetTransform(transform);
+
+ w1111->MoveCursorTo(gfx::Point(10, 10));
+ EXPECT_EQ("11,47", root->QueryMouseLocationForTest().ToString());
+ EXPECT_EQ("20,53", root->last_mouse_location().ToString());
+}
+
TEST_F(WindowTest, HitTest) {
Window w1(new ColorTestWindowDelegate(SK_ColorWHITE));
w1.set_id(1);
« ui/aura/root_window.cc ('K') | « ui/aura/window.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698