OLD | NEW |
1 // Copyright 2016 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 #ifndef UI_DISPLAY_DISPLAY_H_ | 5 #ifndef UI_DISPLAY_DISPLAY_H_ |
6 #define UI_DISPLAY_DISPLAY_H_ | 6 #define UI_DISPLAY_DISPLAY_H_ |
7 | 7 |
8 #include "ui/gfx/display.h" | 8 #include <stdint.h> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "ui/display/display_export.h" |
| 12 #include "ui/gfx/geometry/rect.h" |
9 | 13 |
10 namespace display { | 14 namespace display { |
11 | 15 |
12 // TODO(oshima): move the gfx::Display to display::Display. | 16 // This class typically, but does not always, correspond to a physical display |
13 using Display = gfx::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 DISPLAY_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 }; |
14 | 35 |
15 } // display | 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 gfx::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 display::Screen's coordinates. |
| 85 const gfx::Rect& bounds() const { return bounds_; } |
| 86 void set_bounds(const gfx::Rect& bounds) { bounds_ = bounds; } |
| 87 |
| 88 // Gets/Sets the display's work area in display::Screen's coordinates. |
| 89 const gfx::Rect& work_area() const { return work_area_; } |
| 90 void set_work_area(const gfx::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 gfx::Size& size() const { return bounds_.size(); } |
| 110 const gfx::Size& work_area_size() const { return work_area_.size(); } |
| 111 |
| 112 // Returns the work area insets. |
| 113 gfx::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 gfx::Size& maximum_cursor_size() const { return maximum_cursor_size_; } |
| 153 void set_maximum_cursor_size(const gfx::Size& size) { |
| 154 maximum_cursor_size_ = size; |
| 155 } |
| 156 |
| 157 private: |
| 158 int64_t id_; |
| 159 gfx::Rect bounds_; |
| 160 gfx::Rect work_area_; |
| 161 float device_scale_factor_; |
| 162 Rotation rotation_; |
| 163 TouchSupport touch_support_; |
| 164 gfx::Size maximum_cursor_size_; |
| 165 }; |
| 166 |
| 167 } // namespace display |
16 | 168 |
17 #endif // UI_DISPLAY_DISPLAY_H_ | 169 #endif // UI_DISPLAY_DISPLAY_H_ |
OLD | NEW |