| 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 "ui/aura/dip_util.h" | |
| 6 | |
| 7 #include "ui/aura/env.h" | |
| 8 #include "ui/aura/window.h" | |
| 9 #include "ui/gfx/point.h" | |
| 10 #include "ui/gfx/size.h" | |
| 11 #include "ui/gfx/rect.h" | |
| 12 | |
| 13 #if defined(ENABLE_DIP) | |
| 14 #include "ui/aura/monitor_manager.h" | |
| 15 #include "ui/gfx/monitor.h" | |
| 16 #endif | |
| 17 | |
| 18 namespace aura { | |
| 19 #if defined(ENABLE_DIP) | |
| 20 float GetMonitorScaleFactor(const Window* window) { | |
| 21 gfx::Monitor monitor = aura::Env::GetInstance()->monitor_manager()-> | |
| 22 GetMonitorNearestWindow(window); | |
| 23 return monitor.device_scale_factor(); | |
| 24 } // namespace | |
| 25 #endif | |
| 26 | |
| 27 gfx::Point ConvertPointToDIP(const Window* window, | |
| 28 const gfx::Point& point_in_pixel) { | |
| 29 #if defined(ENABLE_DIP) | |
| 30 return point_in_pixel.Scale(1.0f / GetMonitorScaleFactor(window)); | |
| 31 #else | |
| 32 return point_in_pixel; | |
| 33 #endif | |
| 34 } | |
| 35 | |
| 36 gfx::Size ConvertSizeToDIP(const Window* window, | |
| 37 const gfx::Size& size_in_pixel) { | |
| 38 #if defined(ENABLE_DIP) | |
| 39 return size_in_pixel.Scale(1.0f / GetMonitorScaleFactor(window)); | |
| 40 #else | |
| 41 return size_in_pixel; | |
| 42 #endif | |
| 43 } | |
| 44 | |
| 45 gfx::Rect ConvertRectToDIP(const Window* window, | |
| 46 const gfx::Rect& rect_in_pixel) { | |
| 47 #if defined(ENABLE_DIP) | |
| 48 float scale = 1.0f / GetMonitorScaleFactor(window); | |
| 49 return gfx::Rect(rect_in_pixel.origin().Scale(scale), | |
| 50 rect_in_pixel.size().Scale(scale)); | |
| 51 #else | |
| 52 return rect_in_pixel; | |
| 53 #endif | |
| 54 } | |
| 55 | |
| 56 gfx::Point ConvertPointToPixel(const Window* window, | |
| 57 const gfx::Point& point_in_dip) { | |
| 58 #if defined(ENABLE_DIP) | |
| 59 return point_in_dip.Scale(GetMonitorScaleFactor(window)); | |
| 60 #else | |
| 61 return point_in_dip; | |
| 62 #endif | |
| 63 } | |
| 64 | |
| 65 gfx::Size ConvertSizeToPixel(const Window* window, | |
| 66 const gfx::Size& size_in_dip) { | |
| 67 #if defined(ENABLE_DIP) | |
| 68 return size_in_dip.Scale(GetMonitorScaleFactor(window)); | |
| 69 #else | |
| 70 return size_in_dip; | |
| 71 #endif | |
| 72 } | |
| 73 | |
| 74 gfx::Rect ConvertRectToPixel(const Window* window, | |
| 75 const gfx::Rect& rect_in_dip) { | |
| 76 #if defined(ENABLE_DIP) | |
| 77 float scale = GetMonitorScaleFactor(window); | |
| 78 return gfx::Rect(rect_in_dip.origin().Scale(scale), | |
| 79 rect_in_dip.size().Scale(scale)); | |
| 80 #else | |
| 81 return rect_in_dip; | |
| 82 #endif | |
| 83 } | |
| 84 } // namespace aura | |
| OLD | NEW |