diff options
author | backer@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-08 15:31:11 +0000 |
---|---|---|
committer | backer@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-08 15:31:11 +0000 |
commit | 80248e3395ac8f5d52e8e290435cdce6482a6726 (patch) | |
tree | 397cbe07f35593f6c77c539dbddca331bf7439a5 /views | |
parent | a9f090b9d48e668ec4e155b247b2d7fe25fe0f01 (diff) | |
download | chromium_src-80248e3395ac8f5d52e8e290435cdce6482a6726.zip chromium_src-80248e3395ac8f5d52e8e290435cdce6482a6726.tar.gz chromium_src-80248e3395ac8f5d52e8e290435cdce6482a6726.tar.bz2 |
Use SkMatrix44 for the underlying implementation of ui::Transform
BUG=
TEST=ui_unittest
Review URL: http://codereview.chromium.org/7044062
Patch from Ian Vollick <vollick@chromium.org>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91855 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/view.cc | 9 | ||||
-rw-r--r-- | views/view_unittest.cc | 62 |
2 files changed, 47 insertions, 24 deletions
diff --git a/views/view.cc b/views/view.cc index 5f126a7..98ae12b 100644 --- a/views/view.cc +++ b/views/view.cc @@ -17,6 +17,7 @@ #include "ui/gfx/compositor/compositor.h" #include "ui/gfx/compositor/layer.h" #include "ui/gfx/path.h" +#include "ui/gfx/point3.h" #include "ui/gfx/transform.h" #include "views/background.h" #include "views/context_menu_controller.h" @@ -1715,7 +1716,9 @@ bool View::ConvertPointForAncestor(const View* ancestor, ui::Transform trans; // TODO(sad): Have some way of caching the transformation results. bool result = GetTransformRelativeTo(ancestor, &trans); - trans.TransformPoint(point); + gfx::Point3f p(*point); + trans.TransformPoint(p); + *point = p.AsPoint(); return result; } @@ -1723,7 +1726,9 @@ bool View::ConvertPointFromAncestor(const View* ancestor, gfx::Point* point) const { ui::Transform trans; bool result = GetTransformRelativeTo(ancestor, &trans); - trans.TransformPointReverse(point); + gfx::Point3f p(*point); + trans.TransformPointReverse(p); + *point = p.AsPoint(); return result; } diff --git a/views/view_unittest.cc b/views/view_unittest.cc index c01fd72..6d96195 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -613,6 +613,18 @@ gfx::Point ConvertPointToView(View* view, const gfx::Point& p) { return tmp; } +void RotateCounterclockwise(ui::Transform& transform) { + transform.matrix().set3x3(0, -1, 0, + 1, 0, 0, + 0, 0, 1); +} + +void RotateClockwise(ui::Transform& transform) { + transform.matrix().set3x3( 0, 1, 0, + -1, 0, 0, + 0, 0, 1); +} + } // namespace TEST_F(ViewTest, HitTestMasks) { @@ -1521,7 +1533,7 @@ TEST_F(ViewTest, TransformPaint) { // Rotate |v1| counter-clockwise. ui::Transform transform; - transform.SetRotate(-90.0f); + RotateCounterclockwise(transform); transform.SetTranslateY(500.0f); v1->SetTransform(transform); @@ -1555,7 +1567,7 @@ TEST_F(ViewTest, TransformEvent) { // Rotate |v1| counter-clockwise. ui::Transform transform(v1->GetTransform()); - transform.SetRotate(-90.0f); + RotateCounterclockwise(transform); transform.SetTranslateY(500.0f); v1->SetTransform(transform); @@ -1577,7 +1589,7 @@ TEST_F(ViewTest, TransformEvent) { // Now rotate |v2| inside |v1| clockwise. transform = v2->GetTransform(); - transform.SetRotate(90.0f); + RotateClockwise(transform); transform.SetTranslateX(100.0f); v2->SetTransform(transform); @@ -1607,7 +1619,7 @@ TEST_F(ViewTest, TransformEvent) { // Rotate |v3| clockwise with respect to |v2|. transform = v1->GetTransform(); - transform.SetRotate(90.0f); + RotateClockwise(transform); transform.SetTranslateX(30.0f); v3->SetTransform(transform); @@ -1643,7 +1655,7 @@ TEST_F(ViewTest, TransformEvent) { // Rotate |v3| clockwise with respect to |v2|, and scale it along both axis. transform = v3->GetTransform(); - transform.SetRotate(90.0f); + RotateClockwise(transform); transform.SetTranslateX(30.0f); // Rotation sets some scaling transformation. Using SetScale would overwrite // that and pollute the rotation. So combine the scaling with the existing @@ -1696,7 +1708,7 @@ TEST_F(ViewTest, TransformVisibleBound) { // Rotate |child| counter-clockwise ui::Transform transform; - transform.SetRotate(-90.0f); + RotateCounterclockwise(transform); transform.SetTranslateY(50.0f); child->SetTransform(transform); EXPECT_EQ(gfx::Rect(40, 0, 10, 50), child->GetVisibleBounds()); @@ -1827,12 +1839,15 @@ TEST_F(ViewTest, ConvertPointToViewWithTransform) { transform.ConcatScale(100, 55); transform.ConcatTranslate(110, -110); - EXPECT_EQ(210, transform.matrix().getTranslateX()); - EXPECT_EQ(-55, transform.matrix().getTranslateY()); - EXPECT_EQ(100, transform.matrix().getScaleX()); - EXPECT_EQ(55, transform.matrix().getScaleY()); - EXPECT_EQ(0, transform.matrix().getSkewX()); - EXPECT_EQ(0, transform.matrix().getSkewY()); + // convert to a 3x3 matrix. + const SkMatrix& matrix = transform.matrix(); + + EXPECT_EQ(210, matrix.getTranslateX()); + EXPECT_EQ(-55, matrix.getTranslateY()); + EXPECT_EQ(100, matrix.getScaleX()); + EXPECT_EQ(55, matrix.getScaleY()); + EXPECT_EQ(0, matrix.getSkewX()); + EXPECT_EQ(0, matrix.getSkewY()); } { @@ -1845,12 +1860,15 @@ TEST_F(ViewTest, ConvertPointToViewWithTransform) { transform.ConcatTransform(t2); transform.ConcatTransform(t3); - EXPECT_EQ(210, transform.matrix().getTranslateX()); - EXPECT_EQ(-55, transform.matrix().getTranslateY()); - EXPECT_EQ(100, transform.matrix().getScaleX()); - EXPECT_EQ(55, transform.matrix().getScaleY()); - EXPECT_EQ(0, transform.matrix().getSkewX()); - EXPECT_EQ(0, transform.matrix().getSkewY()); + // convert to a 3x3 matrix + const SkMatrix& matrix = transform.matrix(); + + EXPECT_EQ(210, matrix.getTranslateX()); + EXPECT_EQ(-55, matrix.getTranslateY()); + EXPECT_EQ(100, matrix.getScaleX()); + EXPECT_EQ(55, matrix.getScaleY()); + EXPECT_EQ(0, matrix.getSkewX()); + EXPECT_EQ(0, matrix.getSkewY()); } // Conversions from child->top and top->child. @@ -1926,7 +1944,7 @@ TEST_F(ViewTest, ConvertRectWithTransform) { // Rotate |v2| ui::Transform t2; - t2.SetRotate(-90.0f); + RotateCounterclockwise(t2); t2.SetTranslateY(100.0f); v2->SetTransform(t2); @@ -2571,13 +2589,13 @@ TEST_F(ViewLayerTest, ToggleVisibilityWithTransform) { transform.SetScale(2.0f, 2.0f); view->SetTransform(transform); widget()->SetContentsView(view); - EXPECT_EQ(2.0f, view->GetTransform().matrix()[0]); + EXPECT_EQ(2.0f, view->GetTransform().matrix().get(0, 0)); view->SetVisible(false); - EXPECT_EQ(2.0f, view->GetTransform().matrix()[0]); + EXPECT_EQ(2.0f, view->GetTransform().matrix().get(0, 0)); view->SetVisible(true); - EXPECT_EQ(2.0f, view->GetTransform().matrix()[0]); + EXPECT_EQ(2.0f, view->GetTransform().matrix().get(0, 0)); } // Verifies a transform persists after removing/adding a view with a transform. |