OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/renderer_host/dip_util.h" | |
6 | |
7 #include "content/public/browser/render_widget_host_view.h" | |
8 #include "ui/gfx/monitor.h" | |
9 #include "ui/gfx/point.h" | |
10 #include "ui/gfx/rect.h" | |
11 #include "ui/gfx/screen.h" | |
12 #include "ui/gfx/size.h" | |
13 | |
14 namespace content { | |
15 | |
16 float GetDIPScaleFactor(const RenderWidgetHostView* view) { | |
17 if (gfx::Screen::IsDIPEnabled()) { | |
18 gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow( | |
19 view ? view->GetNativeView() : NULL); | |
20 return monitor.device_scale_factor(); | |
21 } | |
22 return 1.0f; | |
23 } | |
24 | |
25 gfx::Point ConvertPointToDIP(const RenderWidgetHostView* view, | |
26 const gfx::Point& point_in_pixel) { | |
27 return point_in_pixel.Scale(1.0f / GetDIPScaleFactor(view)); | |
28 } | |
29 | |
30 gfx::Size ConvertSizeToDIP(const RenderWidgetHostView* view, | |
31 const gfx::Size& size_in_pixel) { | |
32 return size_in_pixel.Scale(1.0f / GetDIPScaleFactor(view)); | |
33 } | |
34 | |
35 gfx::Rect ConvertRectToDIP(const RenderWidgetHostView* view, | |
36 const gfx::Rect& rect_in_pixel) { | |
37 float scale = 1.0f / GetDIPScaleFactor(view); | |
38 return gfx::Rect(rect_in_pixel.origin().Scale(scale), | |
39 rect_in_pixel.size().Scale(scale)); | |
40 } | |
41 | |
42 gfx::Point ConvertPointToPixel(const RenderWidgetHostView* view, | |
43 const gfx::Point& point_in_dip) { | |
44 return point_in_dip.Scale(GetDIPScaleFactor(view)); | |
45 } | |
46 | |
47 gfx::Size ConvertSizeToPixel(const RenderWidgetHostView* view, | |
48 const gfx::Size& size_in_dip) { | |
49 return size_in_dip.Scale(GetDIPScaleFactor(view)); | |
50 } | |
51 | |
52 gfx::Rect ConvertRectToPixel(const RenderWidgetHostView* view, | |
53 const gfx::Rect& rect_in_dip) { | |
54 float scale = GetDIPScaleFactor(view); | |
55 return gfx::Rect(rect_in_dip.origin().Scale(scale), | |
56 rect_in_dip.size().Scale(scale)); | |
57 } | |
58 | |
59 } // namespace content | |
OLD | NEW |