1// Copyright 2014 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 ASH_DISPLAY_SCREEN_ASH_H_
6#define ASH_DISPLAY_SCREEN_ASH_H_
7
8#include "ash/ash_export.h"
9#include "base/compiler_specific.h"
10#include "base/observer_list.h"
11#include "ui/gfx/display_observer.h"
12#include "ui/gfx/screen.h"
13
14namespace gfx {
15class Rect;
16}
17
18namespace ash {
19namespace  internal {
20class DisplayManager;
21}
22
23// Aura implementation of gfx::Screen. Implemented here to avoid circular
24// dependencies.
25class ASH_EXPORT ScreenAsh : public gfx::Screen {
26 public:
27  ScreenAsh();
28  virtual ~ScreenAsh();
29
30  // Finds the display that contains |point| in screeen coordinates.
31  // Returns invalid display if there is no display that can satisfy
32  // the condition.
33  static gfx::Display FindDisplayContainingPoint(const gfx::Point& point);
34
35  // Returns the bounds for maximized windows in parent coordinates.
36  // Maximized windows trigger auto-hiding the shelf.
37  static gfx::Rect GetMaximizedWindowBoundsInParent(aura::Window* window);
38
39  // Returns the display bounds in parent coordinates.
40  static gfx::Rect GetDisplayBoundsInParent(aura::Window* window);
41
42  // Returns the display's work area bounds in parent coordinates.
43  static gfx::Rect GetDisplayWorkAreaBoundsInParent(aura::Window* window);
44
45  // Converts |rect| from |window|'s coordinates to the virtual screen
46  // coordinates.
47  static gfx::Rect ConvertRectToScreen(aura::Window* window,
48                                       const gfx::Rect& rect);
49
50  // Converts |rect| from virtual screen coordinates to the |window|'s
51  // coordinates.
52  static gfx::Rect ConvertRectFromScreen(aura::Window* window,
53                                         const gfx::Rect& rect);
54
55  // Returns a gfx::Display object for secondary display. Returns
56  // invalid display if there is no secondary display connected.
57  static const gfx::Display& GetSecondaryDisplay();
58
59  // Returns a gfx::Display object for the specified id.  Returns
60  // invalid display if no such display is connected.
61  static const gfx::Display& GetDisplayForId(int64 display_id);
62
63  // gfx::Screen overrides:
64  virtual bool IsDIPEnabled() OVERRIDE;
65  virtual gfx::Point GetCursorScreenPoint() OVERRIDE;
66  virtual gfx::NativeWindow GetWindowUnderCursor() OVERRIDE;
67  virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point)
68      OVERRIDE;
69  virtual int GetNumDisplays() const OVERRIDE;
70  virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE;
71  virtual gfx::Display GetDisplayNearestWindow(
72      gfx::NativeView view) const OVERRIDE;
73  virtual gfx::Display GetDisplayNearestPoint(
74      const gfx::Point& point) const OVERRIDE;
75  virtual gfx::Display GetDisplayMatching(
76      const gfx::Rect& match_rect) const OVERRIDE;
77  virtual gfx::Display GetPrimaryDisplay() const OVERRIDE;
78  virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE;
79  virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE;
80
81 private:
82  friend class DisplayManager;
83
84  // Notifies observers of display configuration changes.
85  void NotifyMetricsChanged(const gfx::Display& display, uint32_t metrics);
86  void NotifyDisplayAdded(const gfx::Display& display);
87  void NotifyDisplayRemoved(const gfx::Display& display);
88
89  // Creates a screen that can be used during shutdown.
90  // It simply has a copy of the displays.
91  gfx::Screen* CloneForShutdown();
92
93  ObserverList<gfx::DisplayObserver> observers_;
94
95  DISALLOW_COPY_AND_ASSIGN(ScreenAsh);
96};
97
98}  // namespace ash
99
100#endif  // ASH_DISPLAY_SCREEN_ASH_H_
101