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