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"
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
{
25 // Screen Rotation in clock-wise degrees.
33 // Touch support for the display.
35 TOUCH_SUPPORT_UNKNOWN
,
36 TOUCH_SUPPORT_AVAILABLE
,
37 TOUCH_SUPPORT_UNAVAILABLE
,
40 // Creates a display with kInvalidDisplayID as default.
42 explicit Display(int64 id
);
43 Display(int64 id
, const Rect
& bounds
);
46 // Returns the forced device scale factor, which is given by
47 // "--force-device-scale-factor".
48 static float GetForcedDeviceScaleFactor();
50 // Indicates if a device scale factor is being explicitly enforced from the
51 // command line via "--force-device-scale-factor".
52 static bool HasForceDeviceScaleFactor();
54 // Resets the caches used to determine if a device scale factor is being
55 // forced from the command line via "--force-device-scale-factor", and thus
56 // ensures that the command line is reevaluated.
57 static void ResetForceDeviceScaleFactorForTesting();
59 // Sets/Gets unique identifier associated with the display.
60 // -1 means invalid display and it doesn't not exit.
61 int64
id() const { return id_
; }
62 void set_id(int64 id
) { id_
= id
; }
64 // Gets/Sets the display's bounds in gfx::Screen's coordinates.
65 const Rect
& bounds() const { return bounds_
; }
66 void set_bounds(const Rect
& bounds
) { bounds_
= bounds
; }
68 // Gets/Sets the display's work area in gfx::Screen's coordinates.
69 const Rect
& work_area() const { return work_area_
; }
70 void set_work_area(const Rect
& work_area
) { work_area_
= work_area
; }
72 // Output device's pixel scale factor. This specifies how much the
73 // UI should be scaled when the actual output has more pixels than
74 // standard displays (which is around 100~120dpi.) The potential return
75 // values depend on each platforms.
76 float device_scale_factor() const { return device_scale_factor_
; }
77 void set_device_scale_factor(float scale
) { device_scale_factor_
= scale
; }
79 Rotation
rotation() const { return rotation_
; }
80 void set_rotation(Rotation rotation
) { rotation_
= rotation
; }
81 int RotationAsDegree() const;
82 void SetRotationAsDegree(int rotation
);
84 TouchSupport
touch_support() const { return touch_support_
; }
85 void set_touch_support(TouchSupport support
) { touch_support_
= support
; }
87 // Utility functions that just return the size of display and
89 const Size
& size() const { return bounds_
.size(); }
90 const Size
& work_area_size() const { return work_area_
.size(); }
92 // Returns the work area insets.
93 Insets
GetWorkAreaInsets() const;
95 // Sets the device scale factor and display bounds in pixel. This
96 // updates the work are using the same insets between old bounds and
98 void SetScaleAndBounds(float device_scale_factor
,
99 const gfx::Rect
& bounds_in_pixel
);
101 // Sets the display's size. This updates the work area using the same insets
102 // between old bounds and work area.
103 void SetSize(const gfx::Size
& size_in_pixel
);
105 // Computes and updates the display's work are using
106 // |work_area_insets| and the bounds.
107 void UpdateWorkAreaFromInsets(const gfx::Insets
& work_area_insets
);
109 // Returns the display's size in pixel coordinates.
110 gfx::Size
GetSizeInPixel() const;
112 // Returns a string representation of the display;
113 std::string
ToString() const;
115 // True if the display contains valid display id.
116 bool is_valid() const { return id_
!= kInvalidDisplayID
; }
118 // True if the display corresponds to internal panel.
119 bool IsInternal() const;
121 // Gets/Sets an id of display corresponding to internal panel.
122 static int64
InternalDisplayId();
123 static void SetInternalDisplayId(int64 internal_display_id
);
125 static const int64 kInvalidDisplayID
;
131 float device_scale_factor_
;
133 TouchSupport touch_support_
;
138 #endif // UI_GFX_DISPLAY_H_