| 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 return insets_in_pixel.Scale(1.0f / scale_factor); |
| 21 } |
| 22 |
| 17 Point ConvertPointToDIP(float scale_factor, const Point& point_in_pixel) { | 23 Point ConvertPointToDIP(float scale_factor, const Point& point_in_pixel) { |
| 18 return ScaleToFlooredPoint(point_in_pixel, 1.0f / scale_factor); | 24 return ScaleToFlooredPoint(point_in_pixel, 1.0f / scale_factor); |
| 19 } | 25 } |
| 20 | 26 |
| 21 PointF ConvertPointToDIP(float scale_factor, const PointF& point_in_pixel) { | 27 PointF ConvertPointToDIP(float scale_factor, const PointF& point_in_pixel) { |
| 22 return ScalePoint(point_in_pixel, 1.0f / scale_factor); | 28 return ScalePoint(point_in_pixel, 1.0f / scale_factor); |
| 23 } | 29 } |
| 24 | 30 |
| 25 Size ConvertSizeToDIP(float scale_factor, const Size& size_in_pixel) { | 31 Size ConvertSizeToDIP(float scale_factor, const Size& size_in_pixel) { |
| 26 return ScaleToFlooredSize(size_in_pixel, 1.0f / scale_factor); | 32 return ScaleToFlooredSize(size_in_pixel, 1.0f / scale_factor); |
| 27 } | 33 } |
| 28 | 34 |
| 29 Rect ConvertRectToDIP(float scale_factor, const Rect& rect_in_pixel) { | 35 Rect ConvertRectToDIP(float scale_factor, const Rect& rect_in_pixel) { |
| 30 return ToFlooredRectDeprecated( | 36 return ToFlooredRectDeprecated( |
| 31 ScaleRect(RectF(rect_in_pixel), 1.0f / scale_factor)); | 37 ScaleRect(RectF(rect_in_pixel), 1.0f / scale_factor)); |
| 32 } | 38 } |
| 33 | 39 |
| 40 Insets ConvertInsetsToPixel(float scale_factor, |
| 41 const gfx::Insets& insets_in_dip) { |
| 42 return insets_in_dip.Scale(scale_factor); |
| 43 } |
| 44 |
| 34 Point ConvertPointToPixel(float scale_factor, const Point& point_in_dip) { | 45 Point ConvertPointToPixel(float scale_factor, const Point& point_in_dip) { |
| 35 return ScaleToFlooredPoint(point_in_dip, scale_factor); | 46 return ScaleToFlooredPoint(point_in_dip, scale_factor); |
| 36 } | 47 } |
| 37 | 48 |
| 38 Size ConvertSizeToPixel(float scale_factor, const Size& size_in_dip) { | 49 Size ConvertSizeToPixel(float scale_factor, const Size& size_in_dip) { |
| 39 return ScaleToFlooredSize(size_in_dip, scale_factor); | 50 return ScaleToFlooredSize(size_in_dip, scale_factor); |
| 40 } | 51 } |
| 41 | 52 |
| 42 Rect ConvertRectToPixel(float scale_factor, const Rect& rect_in_dip) { | 53 Rect ConvertRectToPixel(float scale_factor, const Rect& rect_in_dip) { |
| 43 // Use ToEnclosingRect() to ensure we paint all the possible pixels | 54 // Use ToEnclosingRect() to ensure we paint all the possible pixels |
| 44 // touched. ToEnclosingRect() floors the origin, and ceils the max | 55 // touched. ToEnclosingRect() floors the origin, and ceils the max |
| 45 // coordinate. To do otherwise (such as flooring the size) potentially | 56 // coordinate. To do otherwise (such as flooring the size) potentially |
| 46 // results in rounding down and not drawing all the pixels that are | 57 // results in rounding down and not drawing all the pixels that are |
| 47 // touched. | 58 // touched. |
| 48 return ToEnclosingRect( | 59 return ToEnclosingRect( |
| 49 RectF(ScalePoint(gfx::PointF(rect_in_dip.origin()), scale_factor), | 60 RectF(ScalePoint(gfx::PointF(rect_in_dip.origin()), scale_factor), |
| 50 ScaleSize(gfx::SizeF(rect_in_dip.size()), scale_factor))); | 61 ScaleSize(gfx::SizeF(rect_in_dip.size()), scale_factor))); |
| 51 } | 62 } |
| 52 | 63 |
| 53 } // namespace gfx | 64 } // namespace gfx |
| OLD | NEW |