OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/geometry/dip_util.h" | 5 #include "ui/gfx/geometry/dip_util.h" |
6 | 6 |
7 #include "ui/gfx/geometry/point.h" | 7 #include "ui/gfx/geometry/point.h" |
8 #include "ui/gfx/geometry/point_conversions.h" | 8 #include "ui/gfx/geometry/point_conversions.h" |
9 #include "ui/gfx/geometry/point_f.h" | 9 #include "ui/gfx/geometry/point_f.h" |
10 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
11 #include "ui/gfx/geometry/rect_conversions.h" | 11 #include "ui/gfx/geometry/rect_conversions.h" |
12 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
13 #include "ui/gfx/geometry/size_conversions.h" | 13 #include "ui/gfx/geometry/size_conversions.h" |
14 | 14 |
15 namespace gfx { | 15 namespace gfx { |
16 | 16 |
17 Point ConvertPointToDIP(float scale_factor, const Point& point_in_pixel) { | 17 Point ConvertPointToDIP(float scale_factor, const Point& point_in_pixel) { |
18 return ToFlooredPoint(ScalePoint(point_in_pixel, 1.0f / scale_factor)); | 18 return ScaleToFlooredPoint(point_in_pixel, 1.0f / scale_factor); |
19 } | 19 } |
20 | 20 |
21 PointF ConvertPointToDIP(float scale_factor, const PointF& point_in_pixel) { | 21 PointF ConvertPointToDIP(float scale_factor, const PointF& point_in_pixel) { |
22 return ScalePoint(point_in_pixel, 1.0f / scale_factor); | 22 return ScalePoint(point_in_pixel, 1.0f / scale_factor); |
23 } | 23 } |
24 | 24 |
25 Size ConvertSizeToDIP(float scale_factor, const Size& size_in_pixel) { | 25 Size ConvertSizeToDIP(float scale_factor, const Size& size_in_pixel) { |
26 return ScaleToFlooredSize(size_in_pixel, 1.0f / scale_factor); | 26 return ScaleToFlooredSize(size_in_pixel, 1.0f / scale_factor); |
27 } | 27 } |
28 | 28 |
29 Rect ConvertRectToDIP(float scale_factor, const Rect& rect_in_pixel) { | 29 Rect ConvertRectToDIP(float scale_factor, const Rect& rect_in_pixel) { |
30 return ToFlooredRectDeprecated( | 30 return ToFlooredRectDeprecated( |
31 ScaleRect(RectF(rect_in_pixel), 1.0f / scale_factor)); | 31 ScaleRect(RectF(rect_in_pixel), 1.0f / scale_factor)); |
32 } | 32 } |
33 | 33 |
34 Point ConvertPointToPixel(float scale_factor, const Point& point_in_dip) { | 34 Point ConvertPointToPixel(float scale_factor, const Point& point_in_dip) { |
35 return ToFlooredPoint(ScalePoint(point_in_dip, scale_factor)); | 35 return ScaleToFlooredPoint(point_in_dip, scale_factor); |
36 } | 36 } |
37 | 37 |
38 Size ConvertSizeToPixel(float scale_factor, const Size& size_in_dip) { | 38 Size ConvertSizeToPixel(float scale_factor, const Size& size_in_dip) { |
39 return ScaleToFlooredSize(size_in_dip, scale_factor); | 39 return ScaleToFlooredSize(size_in_dip, scale_factor); |
40 } | 40 } |
41 | 41 |
42 Rect ConvertRectToPixel(float scale_factor, const Rect& rect_in_dip) { | 42 Rect ConvertRectToPixel(float scale_factor, const Rect& rect_in_dip) { |
43 // Use ToEnclosingRect() to ensure we paint all the possible pixels | 43 // Use ToEnclosingRect() to ensure we paint all the possible pixels |
44 // touched. ToEnclosingRect() floors the origin, and ceils the max | 44 // touched. ToEnclosingRect() floors the origin, and ceils the max |
45 // coordinate. To do otherwise (such as flooring the size) potentially | 45 // coordinate. To do otherwise (such as flooring the size) potentially |
46 // results in rounding down and not drawing all the pixels that are | 46 // results in rounding down and not drawing all the pixels that are |
47 // touched. | 47 // touched. |
48 return ToEnclosingRect( | 48 return ToEnclosingRect( |
49 RectF(ScalePoint(rect_in_dip.origin(), scale_factor), | 49 RectF(ScalePoint(gfx::PointF(rect_in_dip.origin()), scale_factor), |
50 ScaleSize(gfx::SizeF(rect_in_dip.size()), scale_factor))); | 50 ScaleSize(gfx::SizeF(rect_in_dip.size()), scale_factor))); |
51 } | 51 } |
52 | 52 |
53 } // namespace gfx | 53 } // namespace gfx |
OLD | NEW |