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