Home | History | Annotate | Download | only in renderer_host
      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/display.h"
      9 #include "ui/gfx/point.h"
     10 #include "ui/gfx/point_conversions.h"
     11 #include "ui/gfx/rect.h"
     12 #include "ui/gfx/rect_conversions.h"
     13 #include "ui/gfx/screen.h"
     14 #include "ui/gfx/size.h"
     15 #include "ui/gfx/size_conversions.h"
     16 
     17 namespace content {
     18 namespace {
     19 
     20 float GetScaleForView(const RenderWidgetHostView* view) {
     21   return ui::GetImageScale(GetScaleFactorForView(view));
     22 }
     23 
     24 }  // namespace
     25 
     26 ui::ScaleFactor GetScaleFactorForView(const RenderWidgetHostView* view) {
     27   return ui::GetScaleFactorForNativeView(view ? view->GetNativeView() : NULL);
     28 }
     29 
     30 gfx::Point ConvertViewPointToDIP(const RenderWidgetHostView* view,
     31                                  const gfx::Point& point_in_pixel) {
     32   return gfx::ToFlooredPoint(
     33       gfx::ScalePoint(point_in_pixel, 1.0f / GetScaleForView(view)));
     34 }
     35 
     36 gfx::Size ConvertViewSizeToPixel(const RenderWidgetHostView* view,
     37                                  const gfx::Size& size_in_dip) {
     38   return gfx::ToFlooredSize(
     39       gfx::ScaleSize(size_in_dip, GetScaleForView(view)));
     40 }
     41 
     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) {
     62     return gfx::ToFlooredRectDeprecated(
     63         gfx::ScaleRect(rect_in_dip, scale_factor));
     64 }
     65 
     66 }  // namespace content
     67