| 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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 ui::ScaleFactor GetScaleFactorForView(const RenderWidgetHostView* view) { | 26 ui::ScaleFactor GetScaleFactorForView(const RenderWidgetHostView* view) { |
| 27 return ui::GetScaleFactorForNativeView(view ? view->GetNativeView() : NULL); | 27 return ui::GetScaleFactorForNativeView(view ? view->GetNativeView() : NULL); |
| 28 } | 28 } |
| 29 | 29 |
| 30 gfx::Point ConvertPointToDIP(const RenderWidgetHostView* view, | 30 gfx::Point ConvertPointToDIP(const RenderWidgetHostView* view, |
| 31 const gfx::Point& point_in_pixel) { | 31 const gfx::Point& point_in_pixel) { |
| 32 return gfx::ToFlooredPoint( | 32 return gfx::ToFlooredPoint( |
| 33 gfx::ScalePoint(point_in_pixel, 1.0f / GetScaleForView(view))); | 33 gfx::ScalePoint(point_in_pixel, 1.0f / GetScaleForView(view))); |
| 34 } | 34 } |
| 35 | 35 |
| 36 gfx::Size ConvertSizeToDIP(float scale_factor, |
| 37 const gfx::Size& size_in_pixel) { |
| 38 return gfx::ToFlooredSize( |
| 39 gfx::ScaleSize(size_in_pixel, 1.0f / scale_factor)); |
| 40 } |
| 41 |
| 36 gfx::Size ConvertSizeToDIP(const RenderWidgetHostView* view, | 42 gfx::Size ConvertSizeToDIP(const RenderWidgetHostView* view, |
| 37 const gfx::Size& size_in_pixel) { | 43 const gfx::Size& size_in_pixel) { |
| 38 return gfx::ToFlooredSize( | 44 return ConvertSizeToDIP(GetScaleForView(view), size_in_pixel); |
| 39 gfx::ScaleSize(size_in_pixel, 1.0f / GetScaleForView(view))); | 45 } |
| 46 |
| 47 gfx::Rect ConvertRectToDIP(float scale_factor, |
| 48 const gfx::Rect& rect_in_pixel) { |
| 49 return gfx::ToFlooredRectDeprecated( |
| 50 gfx::ScaleRect(rect_in_pixel, 1.0f / scale_factor)); |
| 40 } | 51 } |
| 41 | 52 |
| 42 gfx::Rect ConvertRectToDIP(const RenderWidgetHostView* view, | 53 gfx::Rect ConvertRectToDIP(const RenderWidgetHostView* view, |
| 43 const gfx::Rect& rect_in_pixel) { | 54 const gfx::Rect& rect_in_pixel) { |
| 44 float scale = 1.0f / GetScaleForView(view); | 55 return ConvertRectToDIP(GetScaleForView(view), rect_in_pixel); |
| 45 return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_pixel, scale)); | |
| 46 } | 56 } |
| 47 | 57 |
| 48 gfx::Point ConvertPointToPixel(const RenderWidgetHostView* view, | 58 gfx::Point ConvertPointToPixel(const RenderWidgetHostView* view, |
| 49 const gfx::Point& point_in_dip) { | 59 const gfx::Point& point_in_dip) { |
| 50 return gfx::ToFlooredPoint( | 60 return gfx::ToFlooredPoint( |
| 51 gfx::ScalePoint(point_in_dip, GetScaleForView(view))); | 61 gfx::ScalePoint(point_in_dip, GetScaleForView(view))); |
| 52 } | 62 } |
| 53 | 63 |
| 54 gfx::Size ConvertSizeToPixel(const RenderWidgetHostView* view, | 64 gfx::Size ConvertSizeToPixel(const RenderWidgetHostView* view, |
| 55 const gfx::Size& size_in_dip) { | 65 const gfx::Size& size_in_dip) { |
| 56 return gfx::ToFlooredSize( | 66 return gfx::ToFlooredSize( |
| 57 gfx::ScaleSize(size_in_dip, GetScaleForView(view))); | 67 gfx::ScaleSize(size_in_dip, GetScaleForView(view))); |
| 58 } | 68 } |
| 59 | 69 |
| 70 gfx::Rect ConvertRectToPixel(float scale_factor, |
| 71 const gfx::Rect& rect_in_dip) { |
| 72 return gfx::ToFlooredRectDeprecated( |
| 73 gfx::ScaleRect(rect_in_dip, scale_factor)); |
| 74 } |
| 75 |
| 60 gfx::Rect ConvertRectToPixel(const RenderWidgetHostView* view, | 76 gfx::Rect ConvertRectToPixel(const RenderWidgetHostView* view, |
| 61 const gfx::Rect& rect_in_dip) { | 77 const gfx::Rect& rect_in_dip) { |
| 62 float scale = GetScaleForView(view); | 78 return ConvertRectToPixel(GetScaleForView(view), rect_in_dip); |
| 63 return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_dip, scale)); | |
| 64 } | 79 } |
| 65 | 80 |
| 66 } // namespace content | 81 } // namespace content |
| OLD | NEW |