| 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/insets.h" |
| 7 #include "ui/gfx/geometry/point.h" | 8 #include "ui/gfx/geometry/point.h" |
| 8 #include "ui/gfx/geometry/point_conversions.h" | 9 #include "ui/gfx/geometry/point_conversions.h" |
| 9 #include "ui/gfx/geometry/point_f.h" | 10 #include "ui/gfx/geometry/point_f.h" |
| 10 #include "ui/gfx/geometry/rect.h" | 11 #include "ui/gfx/geometry/rect.h" |
| 11 #include "ui/gfx/geometry/rect_conversions.h" | 12 #include "ui/gfx/geometry/rect_conversions.h" |
| 12 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
| 13 #include "ui/gfx/geometry/size_conversions.h" | 14 #include "ui/gfx/geometry/size_conversions.h" |
| 14 | 15 |
| 15 namespace gfx { | 16 namespace gfx { |
| 16 | 17 |
| 18 Insets ConvertInsetsToDIP(float scale_factor, |
| 19 const gfx::Insets& insets_in_pixel) { |
| 20 if (scale_factor == 1.f) |
| 21 return insets_in_pixel; |
| 22 return insets_in_pixel.Scale(1.f / scale_factor); |
| 23 } |
| 24 |
| 17 Point ConvertPointToDIP(float scale_factor, const Point& point_in_pixel) { | 25 Point ConvertPointToDIP(float scale_factor, const Point& point_in_pixel) { |
| 18 return ScaleToFlooredPoint(point_in_pixel, 1.0f / scale_factor); | 26 if (scale_factor == 1.f) |
| 27 return point_in_pixel; |
| 28 return ScaleToFlooredPoint(point_in_pixel, 1.f / scale_factor); |
| 19 } | 29 } |
| 20 | 30 |
| 21 PointF ConvertPointToDIP(float scale_factor, const PointF& point_in_pixel) { | 31 PointF ConvertPointToDIP(float scale_factor, const PointF& point_in_pixel) { |
| 22 return ScalePoint(point_in_pixel, 1.0f / scale_factor); | 32 if (scale_factor == 1.f) |
| 33 return point_in_pixel; |
| 34 return ScalePoint(point_in_pixel, 1.f / scale_factor); |
| 23 } | 35 } |
| 24 | 36 |
| 25 Size ConvertSizeToDIP(float scale_factor, const Size& size_in_pixel) { | 37 Size ConvertSizeToDIP(float scale_factor, const Size& size_in_pixel) { |
| 26 return ScaleToFlooredSize(size_in_pixel, 1.0f / scale_factor); | 38 if (scale_factor == 1.f) |
| 39 return size_in_pixel; |
| 40 return ScaleToFlooredSize(size_in_pixel, 1.f / scale_factor); |
| 27 } | 41 } |
| 28 | 42 |
| 29 Rect ConvertRectToDIP(float scale_factor, const Rect& rect_in_pixel) { | 43 Rect ConvertRectToDIP(float scale_factor, const Rect& rect_in_pixel) { |
| 44 if (scale_factor == 1.f) |
| 45 return rect_in_pixel; |
| 30 return ToFlooredRectDeprecated( | 46 return ToFlooredRectDeprecated( |
| 31 ScaleRect(RectF(rect_in_pixel), 1.0f / scale_factor)); | 47 ScaleRect(RectF(rect_in_pixel), 1.f / scale_factor)); |
| 48 } |
| 49 |
| 50 Insets ConvertInsetsToPixel(float scale_factor, |
| 51 const gfx::Insets& insets_in_dip) { |
| 52 if (scale_factor == 1.f) |
| 53 return insets_in_dip; |
| 54 return insets_in_dip.Scale(scale_factor); |
| 32 } | 55 } |
| 33 | 56 |
| 34 Point ConvertPointToPixel(float scale_factor, const Point& point_in_dip) { | 57 Point ConvertPointToPixel(float scale_factor, const Point& point_in_dip) { |
| 58 if (scale_factor == 1.f) |
| 59 return point_in_dip; |
| 35 return ScaleToFlooredPoint(point_in_dip, scale_factor); | 60 return ScaleToFlooredPoint(point_in_dip, scale_factor); |
| 36 } | 61 } |
| 37 | 62 |
| 38 Size ConvertSizeToPixel(float scale_factor, const Size& size_in_dip) { | 63 Size ConvertSizeToPixel(float scale_factor, const Size& size_in_dip) { |
| 64 if (scale_factor == 1.f) |
| 65 return size_in_dip; |
| 39 return ScaleToFlooredSize(size_in_dip, scale_factor); | 66 return ScaleToFlooredSize(size_in_dip, scale_factor); |
| 40 } | 67 } |
| 41 | 68 |
| 42 Rect ConvertRectToPixel(float scale_factor, const Rect& rect_in_dip) { | 69 Rect ConvertRectToPixel(float scale_factor, const Rect& rect_in_dip) { |
| 43 // Use ToEnclosingRect() to ensure we paint all the possible pixels | 70 // Use ToEnclosingRect() to ensure we paint all the possible pixels |
| 44 // touched. ToEnclosingRect() floors the origin, and ceils the max | 71 // touched. ToEnclosingRect() floors the origin, and ceils the max |
| 45 // coordinate. To do otherwise (such as flooring the size) potentially | 72 // coordinate. To do otherwise (such as flooring the size) potentially |
| 46 // results in rounding down and not drawing all the pixels that are | 73 // results in rounding down and not drawing all the pixels that are |
| 47 // touched. | 74 // touched. |
| 75 if (scale_factor == 1.f) |
| 76 return rect_in_dip; |
| 48 return ToEnclosingRect( | 77 return ToEnclosingRect( |
| 49 RectF(ScalePoint(gfx::PointF(rect_in_dip.origin()), scale_factor), | 78 RectF(ScalePoint(gfx::PointF(rect_in_dip.origin()), scale_factor), |
| 50 ScaleSize(gfx::SizeF(rect_in_dip.size()), scale_factor))); | 79 ScaleSize(gfx::SizeF(rect_in_dip.size()), scale_factor))); |
| 51 } | 80 } |
| 52 | 81 |
| 53 } // namespace gfx | 82 } // namespace gfx |
| OLD | NEW |