OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/dip_util.h" | 5 #include "content/browser/renderer_host/dip_util.h" |
6 | 6 |
7 #include "content/public/browser/render_widget_host_view.h" | 7 #include "content/public/browser/render_widget_host_view.h" |
8 #include "ui/gfx/display.h" | 8 #include "ui/gfx/display.h" |
9 #include "ui/gfx/point.h" | 9 #include "ui/gfx/point.h" |
| 10 #include "ui/gfx/point_conversions.h" |
10 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
11 #include "ui/gfx/screen.h" | 12 #include "ui/gfx/screen.h" |
12 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
| 14 #include "ui/gfx/size_conversions.h" |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 float GetScaleForView(const content::RenderWidgetHostView* view) { | 18 float GetScaleForView(const content::RenderWidgetHostView* view) { |
17 return ui::GetScaleFactorScale(content::GetScaleFactorForView(view)); | 19 return ui::GetScaleFactorScale(content::GetScaleFactorForView(view)); |
18 } | 20 } |
19 | 21 |
20 } // namespace | 22 } // namespace |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 | 25 |
24 ui::ScaleFactor GetScaleFactorForView(const RenderWidgetHostView* view) { | 26 ui::ScaleFactor GetScaleFactorForView(const RenderWidgetHostView* view) { |
25 return ui::GetScaleFactorForNativeView(view ? view->GetNativeView() : NULL); | 27 return ui::GetScaleFactorForNativeView(view ? view->GetNativeView() : NULL); |
26 } | 28 } |
27 | 29 |
28 gfx::Point ConvertPointToDIP(const RenderWidgetHostView* view, | 30 gfx::Point ConvertPointToDIP(const RenderWidgetHostView* view, |
29 const gfx::Point& point_in_pixel) { | 31 const gfx::Point& point_in_pixel) { |
30 return point_in_pixel.Scale(1.0f / GetScaleForView(view)); | 32 return gfx::ToFlooredPoint( |
| 33 point_in_pixel.Scale(1.0f / GetScaleForView(view))); |
31 } | 34 } |
32 | 35 |
33 gfx::Size ConvertSizeToDIP(const RenderWidgetHostView* view, | 36 gfx::Size ConvertSizeToDIP(const RenderWidgetHostView* view, |
34 const gfx::Size& size_in_pixel) { | 37 const gfx::Size& size_in_pixel) { |
35 return size_in_pixel.Scale(1.0f / GetScaleForView(view)); | 38 return gfx::ToFlooredSize( |
| 39 size_in_pixel.Scale(1.0f / GetScaleForView(view))); |
36 } | 40 } |
37 | 41 |
38 gfx::Rect ConvertRectToDIP(const RenderWidgetHostView* view, | 42 gfx::Rect ConvertRectToDIP(const RenderWidgetHostView* view, |
39 const gfx::Rect& rect_in_pixel) { | 43 const gfx::Rect& rect_in_pixel) { |
40 float scale = 1.0f / GetScaleForView(view); | 44 float scale = 1.0f / GetScaleForView(view); |
41 return gfx::Rect(rect_in_pixel.origin().Scale(scale), | 45 return gfx::Rect(gfx::ToFlooredPoint(rect_in_pixel.origin().Scale(scale)), |
42 rect_in_pixel.size().Scale(scale)); | 46 gfx::ToFlooredSize(rect_in_pixel.size().Scale(scale))); |
43 } | 47 } |
44 | 48 |
45 gfx::Point ConvertPointToPixel(const RenderWidgetHostView* view, | 49 gfx::Point ConvertPointToPixel(const RenderWidgetHostView* view, |
46 const gfx::Point& point_in_dip) { | 50 const gfx::Point& point_in_dip) { |
47 return point_in_dip.Scale(GetScaleForView(view)); | 51 return gfx::ToFlooredPoint(point_in_dip.Scale(GetScaleForView(view))); |
48 } | 52 } |
49 | 53 |
50 gfx::Size ConvertSizeToPixel(const RenderWidgetHostView* view, | 54 gfx::Size ConvertSizeToPixel(const RenderWidgetHostView* view, |
51 const gfx::Size& size_in_dip) { | 55 const gfx::Size& size_in_dip) { |
52 return size_in_dip.Scale(GetScaleForView(view)); | 56 return gfx::ToFlooredSize(size_in_dip.Scale(GetScaleForView(view))); |
53 } | 57 } |
54 | 58 |
55 gfx::Rect ConvertRectToPixel(const RenderWidgetHostView* view, | 59 gfx::Rect ConvertRectToPixel(const RenderWidgetHostView* view, |
56 const gfx::Rect& rect_in_dip) { | 60 const gfx::Rect& rect_in_dip) { |
57 float scale = GetScaleForView(view); | 61 float scale = GetScaleForView(view); |
58 return gfx::Rect(rect_in_dip.origin().Scale(scale), | 62 return gfx::Rect(gfx::ToFlooredPoint(rect_in_dip.origin().Scale(scale)), |
59 rect_in_dip.size().Scale(scale)); | 63 gfx::ToFlooredSize(rect_in_dip.size().Scale(scale))); |
60 } | 64 } |
61 | 65 |
62 } // namespace content | 66 } // namespace content |
OLD | NEW |