blob: c17e0ed1fffbf3f219ba85a8838b601f04bc6a29 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/aura/dip_util.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/gfx/point.h"
#include "ui/gfx/size.h"
#include "ui/gfx/rect.h"
#if defined(ENABLE_DIP)
#include "ui/aura/monitor_manager.h"
#include "ui/gfx/monitor.h"
#endif
namespace aura {
#if defined(ENABLE_DIP)
float GetMonitorScaleFactor(const Window* window) {
gfx::Monitor monitor = aura::Env::GetInstance()->monitor_manager()->
GetMonitorNearestWindow(window);
return monitor.device_scale_factor();
} // namespace
#endif
gfx::Point ConvertPointToDIP(const Window* window,
const gfx::Point& point_in_pixel) {
#if defined(ENABLE_DIP)
return point_in_pixel.Scale(1.0f / GetMonitorScaleFactor(window));
#else
return point_in_pixel;
#endif
}
gfx::Size ConvertSizeToDIP(const Window* window,
const gfx::Size& size_in_pixel) {
#if defined(ENABLE_DIP)
return size_in_pixel.Scale(1.0f / GetMonitorScaleFactor(window));
#else
return size_in_pixel;
#endif
}
gfx::Rect ConvertRectToDIP(const Window* window,
const gfx::Rect& rect_in_pixel) {
#if defined(ENABLE_DIP)
float scale = 1.0f / GetMonitorScaleFactor(window);
return gfx::Rect(rect_in_pixel.origin().Scale(scale),
rect_in_pixel.size().Scale(scale));
#else
return rect_in_pixel;
#endif
}
gfx::Point ConvertPointToPixel(const Window* window,
const gfx::Point& point_in_dip) {
#if defined(ENABLE_DIP)
return point_in_dip.Scale(GetMonitorScaleFactor(window));
#else
return point_in_dip;
#endif
}
gfx::Size ConvertSizeToPixel(const Window* window,
const gfx::Size& size_in_dip) {
#if defined(ENABLE_DIP)
return size_in_dip.Scale(GetMonitorScaleFactor(window));
#else
return size_in_dip;
#endif
}
gfx::Rect ConvertRectToPixel(const Window* window,
const gfx::Rect& rect_in_dip) {
#if defined(ENABLE_DIP)
float scale = GetMonitorScaleFactor(window);
return gfx::Rect(rect_in_dip.origin().Scale(scale),
rect_in_dip.size().Scale(scale));
#else
return rect_in_dip;
#endif
}
} // namespace aura
|