summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-24 16:08:47 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-24 16:08:47 +0000
commite2ca8cc8afff4e85bdb090e487c9b1ff70b677c8 (patch)
tree5986b0f1fd6a317eb41d4d087679e800580db348
parentea218e8454e5ed8ed09a93f9b5540ee94f734dfc (diff)
downloadchromium_src-e2ca8cc8afff4e85bdb090e487c9b1ff70b677c8.zip
chromium_src-e2ca8cc8afff4e85bdb090e487c9b1ff70b677c8.tar.gz
chromium_src-e2ca8cc8afff4e85bdb090e487c9b1ff70b677c8.tar.bz2
Fixes rounding bug in transform. This is needed to avoid rounding
something like -.9998 to 0 instead of -1. Without this a transformed views bounds would end up with an extra scale-1 pixels on the left edge. BUG=none TEST=covered by unit test R=ben@chromium.org,wjmaclean@chromium.org Review URL: http://codereview.chromium.org/7066010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86430 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/gfx/transform.cc8
-rw-r--r--views/view_unittest.cc9
2 files changed, 15 insertions, 2 deletions
diff --git a/ui/gfx/transform.cc b/ui/gfx/transform.cc
index d335166..55edb4c 100644
--- a/ui/gfx/transform.cc
+++ b/ui/gfx/transform.cc
@@ -4,6 +4,8 @@
#include "ui/gfx/transform.h"
+#include <cmath>
+
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/skia_util.h"
@@ -71,7 +73,8 @@ bool Transform::HasChange() const {
bool Transform::TransformPoint(gfx::Point* point) {
SkPoint skp;
matrix_.mapXY(SkIntToScalar(point->x()), SkIntToScalar(point->y()), &skp);
- point->SetPoint(static_cast<int>(skp.fX), static_cast<int>(skp.fY));
+ point->SetPoint(static_cast<int>(std::floor(skp.fX)),
+ static_cast<int>(std::floor(skp.fY)));
return true;
}
@@ -81,7 +84,8 @@ bool Transform::TransformPointReverse(gfx::Point* point) {
if (matrix_.invert(&inverse)) {
SkPoint skp;
inverse.mapXY(SkIntToScalar(point->x()), SkIntToScalar(point->y()), &skp);
- point->SetPoint(static_cast<int>(skp.fX), static_cast<int>(skp.fY));
+ point->SetPoint(static_cast<int>(std::floor(skp.fX)),
+ static_cast<int>(std::floor(skp.fY)));
return true;
}
return false;
diff --git a/views/view_unittest.cc b/views/view_unittest.cc
index 3d12188..5f86edd 100644
--- a/views/view_unittest.cc
+++ b/views/view_unittest.cc
@@ -1979,6 +1979,15 @@ TEST_F(ViewTest, ConvertPointToViewWithTransform) {
EXPECT_EQ(5, point.x());
EXPECT_EQ(5, point.y());
}
+
+ // Conversions from top_view to child with a value that should be negative.
+ // This ensures we don't round up with negative numbers.
+ {
+ gfx::Point point(6, 18);
+ View::ConvertPointToView(&top_view, child, &point);
+ EXPECT_EQ(-1, point.x());
+ EXPECT_EQ(-1, point.y());
+ }
}
TEST_F(ViewTest, Contains) {