display.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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 "base/basictypes.h"
9#include "base/compiler_specific.h"
10#include "ui/gfx/gfx_export.h"
11#include "ui/gfx/rect.h"
12
13namespace gfx {
14
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.
18//
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.
23class 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,
31  };
32
33  // Creates a display with kInvalidDisplayID as default.
34  Display();
35  explicit Display(int64 id);
36  Display(int64 id, const Rect& bounds);
37  ~Display();
38
39  // Returns the forced device scale factor, which is given by
40  // "--force-device-scale-factor".
41  static float GetForcedDeviceScaleFactor();
42
43  // Indicates if a device scale factor is being explicitly enforced from the
44  // command line via "--force-device-scale-factor".
45  static bool HasForceDeviceScaleFactor();
46
47  // Sets/Gets unique identifier associated with the display.
48  // -1 means invalid display and it doesn't not exit.
49  int64 id() const { return id_; }
50  void set_id(int64 id) { id_ = id; }
51
52  // Gets/Sets the display's bounds in gfx::Screen's coordinates.
53  const Rect& bounds() const { return bounds_; }
54  void set_bounds(const Rect& bounds) { bounds_ = bounds; }
55
56  // Gets/Sets the display's work area in gfx::Screen's coordinates.
57  const Rect& work_area() const { return work_area_; }
58  void set_work_area(const Rect& work_area) { work_area_ = work_area; }
59
60  // Output device's pixel scale factor. This specifies how much the
61  // UI should be scaled when the actual output has more pixels than
62  // standard displays (which is around 100~120dpi.) The potential return
63  // values depend on each platforms.
64  float device_scale_factor() const { return device_scale_factor_; }
65  void set_device_scale_factor(float scale) { device_scale_factor_ = scale; }
66
67  Rotation rotation() const { return rotation_; }
68  void set_rotation(Rotation rotation) { rotation_ = rotation; }
69
70  // Utility functions that just return the size of display and
71  // work area.
72  const Size& size() const { return bounds_.size(); }
73  const Size& work_area_size() const { return work_area_.size(); }
74
75  // Returns the work area insets.
76  Insets GetWorkAreaInsets() const;
77
78  // Sets the device scale factor and display bounds in pixel. This
79  // updates the work are using the same insets between old bounds and
80  // work area.
81  void SetScaleAndBounds(float device_scale_factor,
82                         const gfx::Rect& bounds_in_pixel);
83
84  // Sets the display's size. This updates the work area using the same insets
85  // between old bounds and work area.
86  void SetSize(const gfx::Size& size_in_pixel);
87
88  // Computes and updates the display's work are using
89  // |work_area_insets| and the bounds.
90  void UpdateWorkAreaFromInsets(const gfx::Insets& work_area_insets);
91
92  // Returns the display's size in pixel coordinates.
93  gfx::Size GetSizeInPixel() const;
94
95  // Returns a string representation of the display;
96  std::string ToString() const;
97
98  // True if the display contains valid display id.
99  bool is_valid() const { return id_ != kInvalidDisplayID; }
100
101  // True if the display corresponds to internal panel.
102  bool IsInternal() const;
103
104  // Gets/Sets an id of display corresponding to internal panel.
105  static int64 InternalDisplayId();
106  static void SetInternalDisplayId(int64 internal_display_id);
107
108  static const int64 kInvalidDisplayID;
109
110 private:
111  int64 id_;
112  Rect bounds_;
113  Rect work_area_;
114  float device_scale_factor_;
115  Rotation rotation_;
116};
117
118}  // namespace gfx
119
120#endif  // UI_GFX_DISPLAY_H_
121