Fix search results being clipped in app list.
[chromium-blink-merge.git] / ui / gfx / geometry / dip_util.cc
blob702d6d36d143b4164e272c5e6aef5d748c8dece3
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.
5 #include "ui/gfx/geometry/dip_util.h"
7 #include "ui/gfx/geometry/point.h"
8 #include "ui/gfx/geometry/point_conversions.h"
9 #include "ui/gfx/geometry/point_f.h"
10 #include "ui/gfx/geometry/rect.h"
11 #include "ui/gfx/geometry/rect_conversions.h"
12 #include "ui/gfx/geometry/size.h"
13 #include "ui/gfx/geometry/size_conversions.h"
15 namespace gfx {
17 gfx::Point ConvertPointToDIP(float scale_factor,
18 const gfx::Point& point_in_pixel) {
19 return gfx::ToFlooredPoint(
20 gfx::ScalePoint(point_in_pixel, 1.0f / scale_factor));
23 gfx::PointF ConvertPointToDIP(float scale_factor,
24 const gfx::PointF& point_in_pixel) {
25 return gfx::ScalePoint(point_in_pixel, 1.0f / scale_factor);
28 gfx::Size ConvertSizeToDIP(float scale_factor, const gfx::Size& size_in_pixel) {
29 return gfx::ToFlooredSize(gfx::ScaleSize(size_in_pixel, 1.0f / scale_factor));
32 gfx::Rect ConvertRectToDIP(float scale_factor, const gfx::Rect& rect_in_pixel) {
33 return gfx::ToFlooredRectDeprecated(
34 gfx::ScaleRect(rect_in_pixel, 1.0f / scale_factor));
37 gfx::Point ConvertPointToPixel(float scale_factor,
38 const gfx::Point& point_in_dip) {
39 return gfx::ToFlooredPoint(gfx::ScalePoint(point_in_dip, scale_factor));
42 gfx::Size ConvertSizeToPixel(float scale_factor, const gfx::Size& size_in_dip) {
43 return gfx::ToFlooredSize(gfx::ScaleSize(size_in_dip, scale_factor));
46 gfx::Rect ConvertRectToPixel(float scale_factor, const gfx::Rect& rect_in_dip) {
47 // Use ToEnclosingRect() to ensure we paint all the possible pixels
48 // touched. ToEnclosingRect() floors the origin, and ceils the max
49 // coordinate. To do otherwise (such as flooring the size) potentially
50 // results in rounding down and not drawing all the pixels that are
51 // touched.
52 return gfx::ToEnclosingRect(
53 gfx::RectF(gfx::ScalePoint(rect_in_dip.origin(), scale_factor),
54 gfx::ScaleSize(rect_in_dip.size(), scale_factor)));
57 } // namespace gfx