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 #ifndef UI_GFX_DISPLAY_H_ | |
6 #define UI_GFX_DISPLAY_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include "base/compiler_specific.h" | |
11 #include "ui/gfx/geometry/rect.h" | |
12 #include "ui/gfx/gfx_export.h" | |
13 | |
14 namespace gfx { | |
15 | |
16 // This class typically, but does not always, correspond to a physical display | |
17 // connected to the system. A fake Display may exist on a headless system, or a | |
18 // Display may correspond to a remote, virtual display. | |
19 // | |
20 // Note: The screen and display currently uses pixel coordinate | |
21 // system. For platforms that support DIP (density independent pixel), | |
22 // |bounds()| and |work_area| will return values in DIP coordinate | |
23 // system, not in backing pixels. | |
24 class GFX_EXPORT Display final { | |
25 public: | |
26 // Screen Rotation in clock-wise degrees. | |
27 // This enum corresponds to DisplayRotationDefaultProto::Rotation in | |
28 // chrome/browser/chromeos/policy/proto/chrome_device_policy.proto. | |
29 enum Rotation { | |
30 ROTATE_0 = 0, | |
31 ROTATE_90, | |
32 ROTATE_180, | |
33 ROTATE_270, | |
34 }; | |
35 | |
36 // The display rotation can have multiple causes for change. A user can set a | |
37 // preference. On devices with accelerometers, they can change the rotation. | |
38 // RotationSource allows for the tracking of a Rotation per source of the | |
39 // change. ROTATION_SOURCE_ACTIVE is the current rotation of the display. | |
40 // Rotation changes not due to an accelerometer, nor the user, are to use this | |
41 // source directly. ROTATION_SOURCE_UNKNOWN is when no rotation source has | |
42 // been provided. | |
43 enum RotationSource { | |
44 ROTATION_SOURCE_ACCELEROMETER = 0, | |
45 ROTATION_SOURCE_ACTIVE, | |
46 ROTATION_SOURCE_USER, | |
47 ROTATION_SOURCE_UNKNOWN, | |
48 }; | |
49 | |
50 // Touch support for the display. | |
51 enum TouchSupport { | |
52 TOUCH_SUPPORT_UNKNOWN, | |
53 TOUCH_SUPPORT_AVAILABLE, | |
54 TOUCH_SUPPORT_UNAVAILABLE, | |
55 }; | |
56 | |
57 enum : int64_t { kInvalidDisplayID = -1 }; | |
58 | |
59 // Creates a display with kInvalidDisplayID as default. | |
60 Display(); | |
61 explicit Display(int64_t id); | |
62 Display(int64_t id, const Rect& bounds); | |
63 Display(const Display& other); | |
64 ~Display(); | |
65 | |
66 // Returns the forced device scale factor, which is given by | |
67 // "--force-device-scale-factor". | |
68 static float GetForcedDeviceScaleFactor(); | |
69 | |
70 // Indicates if a device scale factor is being explicitly enforced from the | |
71 // command line via "--force-device-scale-factor". | |
72 static bool HasForceDeviceScaleFactor(); | |
73 | |
74 // Resets the caches used to determine if a device scale factor is being | |
75 // forced from the command line via "--force-device-scale-factor", and thus | |
76 // ensures that the command line is reevaluated. | |
77 static void ResetForceDeviceScaleFactorForTesting(); | |
78 | |
79 // Sets/Gets unique identifier associated with the display. | |
80 // -1 means invalid display and it doesn't not exit. | |
81 int64_t id() const { return id_; } | |
82 void set_id(int64_t id) { id_ = id; } | |
83 | |
84 // Gets/Sets the display's bounds in gfx::Screen's coordinates. | |
85 const Rect& bounds() const { return bounds_; } | |
86 void set_bounds(const Rect& bounds) { bounds_ = bounds; } | |
87 | |
88 // Gets/Sets the display's work area in gfx::Screen's coordinates. | |
89 const Rect& work_area() const { return work_area_; } | |
90 void set_work_area(const Rect& work_area) { work_area_ = work_area; } | |
91 | |
92 // Output device's pixel scale factor. This specifies how much the | |
93 // UI should be scaled when the actual output has more pixels than | |
94 // standard displays (which is around 100~120dpi.) The potential return | |
95 // values depend on each platforms. | |
96 float device_scale_factor() const { return device_scale_factor_; } | |
97 void set_device_scale_factor(float scale) { device_scale_factor_ = scale; } | |
98 | |
99 Rotation rotation() const { return rotation_; } | |
100 void set_rotation(Rotation rotation) { rotation_ = rotation; } | |
101 int RotationAsDegree() const; | |
102 void SetRotationAsDegree(int rotation); | |
103 | |
104 TouchSupport touch_support() const { return touch_support_; } | |
105 void set_touch_support(TouchSupport support) { touch_support_ = support; } | |
106 | |
107 // Utility functions that just return the size of display and | |
108 // work area. | |
109 const Size& size() const { return bounds_.size(); } | |
110 const Size& work_area_size() const { return work_area_.size(); } | |
111 | |
112 // Returns the work area insets. | |
113 Insets GetWorkAreaInsets() const; | |
114 | |
115 // Sets the device scale factor and display bounds in pixel. This | |
116 // updates the work are using the same insets between old bounds and | |
117 // work area. | |
118 void SetScaleAndBounds(float device_scale_factor, | |
119 const gfx::Rect& bounds_in_pixel); | |
120 | |
121 // Sets the display's size. This updates the work area using the same insets | |
122 // between old bounds and work area. | |
123 void SetSize(const gfx::Size& size_in_pixel); | |
124 | |
125 // Computes and updates the display's work are using | |
126 // |work_area_insets| and the bounds. | |
127 void UpdateWorkAreaFromInsets(const gfx::Insets& work_area_insets); | |
128 | |
129 // Returns the display's size in pixel coordinates. | |
130 gfx::Size GetSizeInPixel() const; | |
131 | |
132 // Returns a string representation of the display; | |
133 std::string ToString() const; | |
134 | |
135 // True if the display contains valid display id. | |
136 bool is_valid() const { return id_ != kInvalidDisplayID; } | |
137 | |
138 // True if the display corresponds to internal panel. | |
139 bool IsInternal() const; | |
140 | |
141 // Gets/Sets an id of display corresponding to internal panel. | |
142 static int64_t InternalDisplayId(); | |
143 static void SetInternalDisplayId(int64_t internal_display_id); | |
144 | |
145 // Test if the |id| is for the internal display if any. | |
146 static bool IsInternalDisplayId(int64_t id); | |
147 | |
148 // True if there is an internal display. | |
149 static bool HasInternalDisplay(); | |
150 | |
151 // Maximum cursor size in native pixels. | |
152 const Size& maximum_cursor_size() const { return maximum_cursor_size_; } | |
153 void set_maximum_cursor_size(const Size& size) { | |
154 maximum_cursor_size_ = size; | |
155 } | |
156 | |
157 private: | |
158 int64_t id_; | |
159 Rect bounds_; | |
160 Rect work_area_; | |
161 float device_scale_factor_; | |
162 Rotation rotation_; | |
163 TouchSupport touch_support_; | |
164 Size maximum_cursor_size_; | |
165 }; | |
166 | |
167 // This is declared here for use in gtest-based unit tests but is defined in | |
168 // the gfx_test_support target. Depend on that to use this in your unit test. | |
169 // This should not be used in production code - call ToString() instead. | |
170 void PrintTo(const Display& display, ::std::ostream* os); | |
171 | |
172 } // namespace gfx | |
173 | |
174 #endif // UI_GFX_DISPLAY_H_ | |
OLD | NEW |