summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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) {