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 3 // found in the LICENSE file. 4 5 #ifndef UI_GFX_GEOMETRY_DIP_UTIL_H_ 6 #define UI_GFX_GEOMETRY_DIP_UTIL_H_ 7 8 #include "ui/gfx/geometry/geometry_export.h" 9 10 namespace gfx { 11 12 class Insets; 13 class InsetsF; 14 class Point; 15 class PointF; 16 class Rect; 17 class RectF; 18 class Size; 19 class SizeF; 20 21 // This file contains helper functions to move between DIPs (device-independent 22 // pixels) and physical pixels, by multiplying or dividing by device scale 23 // factor. These help show the intent of the caller by naming the operation, 24 // instead of directly performing a scale operation. More complicated 25 // transformations between coordinate spaces than DIP<->physical pixels should 26 // be done via more explicit means. 27 // 28 // Note that functions that receive integer values will convert them to floating 29 // point values, which can itself be a lossy operation for large integers. The 30 // intention of these methods is to be used for UI values which are relatively 31 // small. 32 33 GEOMETRY_EXPORT gfx::PointF ConvertPointToDips( 34 const gfx::Point& point_in_pixels, 35 float device_scale_factor); 36 GEOMETRY_EXPORT gfx::PointF ConvertPointToDips( 37 const gfx::PointF& point_in_pixels, 38 float device_scale_factor); 39 40 GEOMETRY_EXPORT gfx::PointF ConvertPointToPixels( 41 const gfx::Point& point_in_dips, 42 float device_scale_factor); 43 GEOMETRY_EXPORT gfx::PointF ConvertPointToPixels( 44 const gfx::PointF& point_in_dips, 45 float device_scale_factor); 46 47 GEOMETRY_EXPORT gfx::SizeF ConvertSizeToDips(const gfx::Size& size_in_pixels, 48 float device_scale_factor); 49 GEOMETRY_EXPORT gfx::SizeF ConvertSizeToDips(const gfx::SizeF& size_in_pixels, 50 float device_scale_factor); 51 52 GEOMETRY_EXPORT gfx::SizeF ConvertSizeToPixels(const gfx::Size& size_in_dips, 53 float device_scale_factor); 54 GEOMETRY_EXPORT gfx::SizeF ConvertSizeToPixels(const gfx::SizeF& size_in_dips, 55 float device_scale_factor); 56 57 GEOMETRY_EXPORT gfx::RectF ConvertRectToDips(const gfx::Rect& rect_in_pixels, 58 float device_scale_factor); 59 GEOMETRY_EXPORT gfx::RectF ConvertRectToDips(const gfx::RectF& rect_in_pixels, 60 float device_scale_factor); 61 62 GEOMETRY_EXPORT gfx::RectF ConvertRectToPixels(const gfx::Rect& rect_in_dips, 63 float device_scale_factor); 64 GEOMETRY_EXPORT gfx::RectF ConvertRectToPixels(const gfx::RectF& rect_in_dips, 65 float device_scale_factor); 66 67 GEOMETRY_EXPORT gfx::InsetsF ConvertInsetsToDips( 68 const gfx::Insets& insets_in_pixels, 69 float device_scale_factor); 70 GEOMETRY_EXPORT gfx::InsetsF ConvertInsetsToDips( 71 const gfx::InsetsF& insets_in_pixels, 72 float device_scale_factor); 73 74 GEOMETRY_EXPORT gfx::InsetsF ConvertInsetsToPixels( 75 const gfx::Insets& insets_in_dips, 76 float device_scale_factor); 77 GEOMETRY_EXPORT gfx::InsetsF ConvertInsetsToPixels( 78 const gfx::InsetsF& insets_in_dips, 79 float device_scale_factor); 80 81 } // namespace gfx 82 83 #endif // UI_GFX_GEOMETRY_DIP_UTIL_H_ 84