Commit e2ca8cc8 authored by sky@chromium.org's avatar sky@chromium.org

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
parent ea218e84
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
#include <cmath>
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
...@@ -71,7 +73,8 @@ bool Transform::HasChange() const { ...@@ -71,7 +73,8 @@ bool Transform::HasChange() const {
bool Transform::TransformPoint(gfx::Point* point) { bool Transform::TransformPoint(gfx::Point* point) {
SkPoint skp; SkPoint skp;
matrix_.mapXY(SkIntToScalar(point->x()), SkIntToScalar(point->y()), &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; return true;
} }
...@@ -81,7 +84,8 @@ bool Transform::TransformPointReverse(gfx::Point* point) { ...@@ -81,7 +84,8 @@ bool Transform::TransformPointReverse(gfx::Point* point) {
if (matrix_.invert(&inverse)) { if (matrix_.invert(&inverse)) {
SkPoint skp; SkPoint skp;
inverse.mapXY(SkIntToScalar(point->x()), SkIntToScalar(point->y()), &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 true;
} }
return false; return false;
......
...@@ -1979,6 +1979,15 @@ TEST_F(ViewTest, ConvertPointToViewWithTransform) { ...@@ -1979,6 +1979,15 @@ TEST_F(ViewTest, ConvertPointToViewWithTransform) {
EXPECT_EQ(5, point.x()); EXPECT_EQ(5, point.x());
EXPECT_EQ(5, point.y()); 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) { TEST_F(ViewTest, Contains) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment