| 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/rect_conversions.h" |
| 13 #include "ui/gfx/screen.h" | 13 #include "ui/gfx/screen.h" |
| 14 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
| 15 #include "ui/gfx/size_conversions.h" | 15 #include "ui/gfx/size_conversions.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 float GetScaleForView(const RenderWidgetHostView* view) { | 20 float GetScaleForView(const RenderWidgetHostView* view) { |
| 21 return ui::GetScaleFactorScale(GetScaleFactorForView(view)); | 21 return ui::GetScaleFactorScale(GetScaleFactorForView(view)); |
| 22 } | 22 } |
| 23 | 23 |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 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 ConvertViewPointToDIP(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(const RenderWidgetHostView* view, | 36 gfx::Size ConvertViewSizeToPixel(const RenderWidgetHostView* view, |
| 37 const gfx::Size& size_in_pixel) { | 37 const gfx::Size& size_in_dip) { |
| 38 return gfx::ToFlooredSize( | |
| 39 gfx::ScaleSize(size_in_pixel, 1.0f / GetScaleForView(view))); | |
| 40 } | |
| 41 | |
| 42 gfx::Rect ConvertRectToDIP(const RenderWidgetHostView* view, | |
| 43 const gfx::Rect& rect_in_pixel) { | |
| 44 float scale = 1.0f / GetScaleForView(view); | |
| 45 return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_pixel, scale)); | |
| 46 } | |
| 47 | |
| 48 gfx::Point ConvertPointToPixel(const RenderWidgetHostView* view, | |
| 49 const gfx::Point& point_in_dip) { | |
| 50 return gfx::ToFlooredPoint( | |
| 51 gfx::ScalePoint(point_in_dip, GetScaleForView(view))); | |
| 52 } | |
| 53 | |
| 54 gfx::Size ConvertSizeToPixel(const RenderWidgetHostView* view, | |
| 55 const gfx::Size& size_in_dip) { | |
| 56 return gfx::ToFlooredSize( | 38 return gfx::ToFlooredSize( |
| 57 gfx::ScaleSize(size_in_dip, GetScaleForView(view))); | 39 gfx::ScaleSize(size_in_dip, GetScaleForView(view))); |
| 58 } | 40 } |
| 59 | 41 |
| 60 gfx::Rect ConvertRectToPixel(const RenderWidgetHostView* view, | 42 gfx::Rect ConvertViewRectToPixel(const RenderWidgetHostView* view, |
| 43 const gfx::Rect& rect_in_dip) { |
| 44 return ConvertRectToPixel(GetScaleForView(view), rect_in_dip); |
| 45 } |
| 46 |
| 47 gfx::Size ConvertSizeToDIP(float scale_factor, |
| 48 const gfx::Size& size_in_pixel) { |
| 49 return gfx::ToFlooredSize( |
| 50 gfx::ScaleSize(size_in_pixel, 1.0f / scale_factor)); |
| 51 } |
| 52 |
| 53 gfx::Rect ConvertRectToDIP(float scale_factor, |
| 54 const gfx::Rect& rect_in_pixel) { |
| 55 return gfx::ToFlooredRectDeprecated( |
| 56 gfx::ScaleRect(rect_in_pixel, 1.0f / scale_factor)); |
| 57 } |
| 58 |
| 59 |
| 60 gfx::Rect ConvertRectToPixel(float scale_factor, |
| 61 const gfx::Rect& rect_in_dip) { | 61 const gfx::Rect& rect_in_dip) { |
| 62 float scale = GetScaleForView(view); | 62 return gfx::ToFlooredRectDeprecated( |
| 63 return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_dip, scale)); | 63 gfx::ScaleRect(rect_in_dip, scale_factor)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 } // namespace content | 66 } // namespace content |
| OLD | NEW |