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/rect.h" | 10 #include "ui/gfx/rect.h" |
11 #include "ui/gfx/screen.h" | 11 #include "ui/gfx/screen.h" |
12 #include "ui/gfx/size.h" | 12 #include "ui/gfx/size.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 float GetDIPScaleFactor(const RenderWidgetHostView* view) { | 16 float GetDIPScaleFactor(const RenderWidgetHostView* view) { |
17 if (gfx::Screen::IsDIPEnabled()) { | 17 if (gfx::Screen::IsDIPEnabled()) { |
18 gfx::Display display = gfx::Screen::GetDisplayNearestWindow( | 18 gfx::NativeView native_view = view ? view->GetNativeView() : NULL; |
19 view ? view->GetNativeView() : NULL); | 19 gfx::Display display = gfx::Screen::GetDisplayNearestWindow(native_view); |
20 return display.device_scale_factor(); | 20 return display.device_scale_factor(); |
21 } | 21 } |
22 return 1.0f; | 22 return 1.0f; |
23 } | 23 } |
24 | 24 |
25 gfx::Point ConvertPointToDIP(const RenderWidgetHostView* view, | 25 gfx::Point ConvertPointToDIP(const RenderWidgetHostView* view, |
26 const gfx::Point& point_in_pixel) { | 26 const gfx::Point& point_in_pixel) { |
27 return point_in_pixel.Scale(1.0f / GetDIPScaleFactor(view)); | 27 return point_in_pixel.Scale(1.0f / GetDIPScaleFactor(view)); |
28 } | 28 } |
29 | 29 |
(...skipping 20 matching lines...) Expand all Loading... |
50 } | 50 } |
51 | 51 |
52 gfx::Rect ConvertRectToPixel(const RenderWidgetHostView* view, | 52 gfx::Rect ConvertRectToPixel(const RenderWidgetHostView* view, |
53 const gfx::Rect& rect_in_dip) { | 53 const gfx::Rect& rect_in_dip) { |
54 float scale = GetDIPScaleFactor(view); | 54 float scale = GetDIPScaleFactor(view); |
55 return gfx::Rect(rect_in_dip.origin().Scale(scale), | 55 return gfx::Rect(rect_in_dip.origin().Scale(scale), |
56 rect_in_dip.size().Scale(scale)); | 56 rect_in_dip.size().Scale(scale)); |
57 } | 57 } |
58 | 58 |
59 } // namespace content | 59 } // namespace content |
OLD | NEW |