[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / ui / gfx / display.h
blob650c95f15ee2699695276b7d3290504fb4bd63a7
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.
5 #ifndef UI_GFX_DISPLAY_H_
6 #define UI_GFX_DISPLAY_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "ui/gfx/geometry/rect.h"
11 #include "ui/gfx/gfx_export.h"
13 namespace gfx {
15 // This class typically, but does not always, correspond to a physical display
16 // connected to the system. A fake Display may exist on a headless system, or a
17 // Display may correspond to a remote, virtual display.
19 // Note: The screen and display currently uses pixel coordinate
20 // system. For platforms that support DIP (density independent pixel),
21 // |bounds()| and |work_area| will return values in DIP coordinate
22 // system, not in backing pixels.
23 class GFX_EXPORT Display {
24 public:
25 // Screen Rotation in clock-wise degrees.
26 enum Rotation {
27 ROTATE_0 = 0,
28 ROTATE_90,
29 ROTATE_180,
30 ROTATE_270,
33 // The display rotation can have multiple causes for change. A user can set a
34 // preference. On devices with accelerometers, they can change the rotation.
35 // RotationSource allows for the tracking of a Rotation per source of the
36 // change. ROTATION_SOURCE_ACTIVE is the current rotation of the display.
37 // Rotation changes not due to an accelerometer, nor the user, are to use this
38 // source directly.
39 enum RotationSource {
40 ROTATION_SOURCE_ACCELEROMETER = 0,
41 ROTATION_SOURCE_ACTIVE,
42 ROTATION_SOURCE_USER,
45 // Touch support for the display.
46 enum TouchSupport {
47 TOUCH_SUPPORT_UNKNOWN,
48 TOUCH_SUPPORT_AVAILABLE,
49 TOUCH_SUPPORT_UNAVAILABLE,
52 // Creates a display with kInvalidDisplayID as default.
53 Display();
54 explicit Display(int64 id);
55 Display(int64 id, const Rect& bounds);
56 ~Display();
58 // Returns the forced device scale factor, which is given by
59 // "--force-device-scale-factor".
60 static float GetForcedDeviceScaleFactor();
62 // Indicates if a device scale factor is being explicitly enforced from the
63 // command line via "--force-device-scale-factor".
64 static bool HasForceDeviceScaleFactor();
66 // Resets the caches used to determine if a device scale factor is being
67 // forced from the command line via "--force-device-scale-factor", and thus
68 // ensures that the command line is reevaluated.
69 static void ResetForceDeviceScaleFactorForTesting();
71 // Sets/Gets unique identifier associated with the display.
72 // -1 means invalid display and it doesn't not exit.
73 int64 id() const { return id_; }
74 void set_id(int64 id) { id_ = id; }
76 // Gets/Sets the display's bounds in gfx::Screen's coordinates.
77 const Rect& bounds() const { return bounds_; }
78 void set_bounds(const Rect& bounds) { bounds_ = bounds; }
80 // Gets/Sets the display's work area in gfx::Screen's coordinates.
81 const Rect& work_area() const { return work_area_; }
82 void set_work_area(const Rect& work_area) { work_area_ = work_area; }
84 // Output device's pixel scale factor. This specifies how much the
85 // UI should be scaled when the actual output has more pixels than
86 // standard displays (which is around 100~120dpi.) The potential return
87 // values depend on each platforms.
88 float device_scale_factor() const { return device_scale_factor_; }
89 void set_device_scale_factor(float scale) { device_scale_factor_ = scale; }
91 Rotation rotation() const { return rotation_; }
92 void set_rotation(Rotation rotation) { rotation_ = rotation; }
93 int RotationAsDegree() const;
94 void SetRotationAsDegree(int rotation);
96 TouchSupport touch_support() const { return touch_support_; }
97 void set_touch_support(TouchSupport support) { touch_support_ = support; }
99 // Utility functions that just return the size of display and
100 // work area.
101 const Size& size() const { return bounds_.size(); }
102 const Size& work_area_size() const { return work_area_.size(); }
104 // Returns the work area insets.
105 Insets GetWorkAreaInsets() const;
107 // Sets the device scale factor and display bounds in pixel. This
108 // updates the work are using the same insets between old bounds and
109 // work area.
110 void SetScaleAndBounds(float device_scale_factor,
111 const gfx::Rect& bounds_in_pixel);
113 // Sets the display's size. This updates the work area using the same insets
114 // between old bounds and work area.
115 void SetSize(const gfx::Size& size_in_pixel);
117 // Computes and updates the display's work are using
118 // |work_area_insets| and the bounds.
119 void UpdateWorkAreaFromInsets(const gfx::Insets& work_area_insets);
121 // Returns the display's size in pixel coordinates.
122 gfx::Size GetSizeInPixel() const;
124 // Returns a string representation of the display;
125 std::string ToString() const;
127 // True if the display contains valid display id.
128 bool is_valid() const { return id_ != kInvalidDisplayID; }
130 // True if the display corresponds to internal panel.
131 bool IsInternal() const;
133 // Gets/Sets an id of display corresponding to internal panel.
134 static int64 InternalDisplayId();
135 static void SetInternalDisplayId(int64 internal_display_id);
137 // Test if the |id| is for the internal display if any.
138 static bool IsInternalDisplayId(int64 id);
140 // True if there is an internal display.
141 static bool HasInternalDisplay();
143 static const int64 kInvalidDisplayID;
145 private:
146 int64 id_;
147 Rect bounds_;
148 Rect work_area_;
149 float device_scale_factor_;
150 Rotation rotation_;
151 TouchSupport touch_support_;
154 } // namespace gfx
156 #endif // UI_GFX_DISPLAY_H_