OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_AURA_MONITOR_MANAGER_H_ | 5 #ifndef UI_AURA_MONITOR_MANAGER_H_ |
6 #define UI_AURA_MONITOR_MANAGER_H_ | 6 #define UI_AURA_MONITOR_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "ui/aura/aura_export.h" | 14 #include "ui/aura/aura_export.h" |
15 | 15 |
16 namespace gfx { | 16 namespace gfx { |
| 17 class Monitor; |
17 class Point; | 18 class Point; |
18 class Size; | 19 class Size; |
19 } | 20 } |
20 | 21 |
21 namespace aura { | 22 namespace aura { |
22 class Monitor; | 23 class MonitorObserver; |
23 class RootWindow; | 24 class RootWindow; |
24 class Window; | 25 class Window; |
25 | 26 |
26 // Observers for monitor configuration changes. | |
27 // TODO(oshima): multiple monitor support. | |
28 class MonitorObserver { | |
29 public: | |
30 virtual void OnMonitorBoundsChanged(const Monitor* monitor) = 0; | |
31 virtual void OnMonitorAdded(Monitor* new_monitor) = 0; | |
32 virtual void OnMonitorRemoved(const Monitor* old_monitor) = 0; | |
33 }; | |
34 | |
35 // MonitorManager creates, deletes and updates Monitor objects when | 27 // MonitorManager creates, deletes and updates Monitor objects when |
36 // monitor configuration changes, and notifies MonitorObservers about | 28 // monitor configuration changes, and notifies MonitorObservers about |
37 // the change. This is owned by Env and its lifetime is longer than | 29 // the change. This is owned by Env and its lifetime is longer than |
38 // any windows. | 30 // any windows. |
39 class AURA_EXPORT MonitorManager { | 31 class AURA_EXPORT MonitorManager { |
40 public: | 32 public: |
41 static void set_use_fullscreen_host_window(bool use_fullscreen) { | 33 static void set_use_fullscreen_host_window(bool use_fullscreen) { |
42 use_fullscreen_host_window_ = use_fullscreen; | 34 use_fullscreen_host_window_ = use_fullscreen; |
43 } | 35 } |
44 static bool use_fullscreen_host_window() { | 36 static bool use_fullscreen_host_window() { |
45 return use_fullscreen_host_window_; | 37 return use_fullscreen_host_window_; |
46 } | 38 } |
47 | 39 |
48 // Creates a monitor from string spec. 100+200-1440x800 creates monitor | 40 // Creates a monitor from string spec. 100+200-1440x800 creates monitor |
49 // whose size is 1440x800 at the location (100, 200) in screen's coordinates. | 41 // whose size is 1440x800 at the location (100, 200) in screen's coordinates. |
50 // The location can be omitted and be just "1440x800", which creates | 42 // The location can be omitted and be just "1440x800", which creates |
51 // monitor at the origin of the screen. An empty string creates | 43 // monitor at the origin of the screen. An empty string creates |
52 // the monitor with default size. | 44 // the monitor with default size. |
53 static Monitor* CreateMonitorFromSpec(const std::string& spec); | 45 static gfx::Monitor CreateMonitorFromSpec(const std::string& spec); |
54 | 46 |
55 // A utility function to create a root window for primary monitor. | 47 // A utility function to create a root window for primary monitor. |
56 static RootWindow* CreateRootWindowForPrimaryMonitor(); | 48 static RootWindow* CreateRootWindowForPrimaryMonitor(); |
57 | 49 |
58 MonitorManager(); | 50 MonitorManager(); |
59 virtual ~MonitorManager(); | 51 virtual ~MonitorManager(); |
60 | 52 |
61 // Adds/removes MonitorObservers. | 53 // Adds/removes MonitorObservers. |
62 void AddObserver(MonitorObserver* observer); | 54 void AddObserver(MonitorObserver* observer); |
63 void RemoveObserver(MonitorObserver* observer); | 55 void RemoveObserver(MonitorObserver* observer); |
64 | 56 |
65 // Called when monitor configuration has changed. The new monitor | 57 // Called when monitor configuration has changed. The new monitor |
66 // configurations is passed as a vector of Monitor object, which | 58 // configurations is passed as a vector of Monitor object, which |
67 // contains each monitor's new infomration. | 59 // contains each monitor's new infomration. |
68 virtual void OnNativeMonitorsChanged( | 60 virtual void OnNativeMonitorsChanged( |
69 const std::vector<const Monitor*>& monitors) = 0; | 61 const std::vector<gfx::Monitor>& monitors) = 0; |
70 | 62 |
71 // Create a root window for given |monitor|. | 63 // Create a root window for given |monitor|. |
72 virtual RootWindow* CreateRootWindowForMonitor(Monitor* monitor) = 0; | 64 virtual RootWindow* CreateRootWindowForMonitor( |
73 | 65 const gfx::Monitor& monitor) = 0; |
74 // Returns the monitor object nearest given |window|. | |
75 virtual const Monitor* GetMonitorNearestWindow( | |
76 const Window* window) const = 0; | |
77 virtual Monitor* GetMonitorNearestWindow(const Window* window) = 0; | |
78 | |
79 // Returns the monitor object nearest given |pint|. | |
80 virtual const Monitor* GetMonitorNearestPoint( | |
81 const gfx::Point& point) const = 0; | |
82 | 66 |
83 // Returns the monitor at |index|. The monitor at 0 is considered | 67 // Returns the monitor at |index|. The monitor at 0 is considered |
84 // "primary". | 68 // "primary". |
85 virtual Monitor* GetMonitorAt(size_t index) = 0; | 69 virtual const gfx::Monitor& GetMonitorAt(size_t index) = 0; |
86 | 70 |
87 virtual size_t GetNumMonitors() const = 0; | 71 virtual size_t GetNumMonitors() const = 0; |
88 | 72 |
| 73 // Returns the monitor object nearest given |window|. |
| 74 virtual const gfx::Monitor& GetMonitorNearestWindow( |
| 75 const Window* window) const = 0; |
| 76 |
| 77 // Returns the monitor object nearest given |pint|. |
| 78 virtual const gfx::Monitor& GetMonitorNearestPoint( |
| 79 const gfx::Point& point) const = 0; |
| 80 |
89 protected: | 81 protected: |
90 // Calls observers' OnMonitorBoundsChanged methods. | 82 // Calls observers' OnMonitorBoundsChanged methods. |
91 void NotifyBoundsChanged(const Monitor* monitor); | 83 void NotifyBoundsChanged(const gfx::Monitor& monitor); |
92 void NotifyMonitorAdded(Monitor* monitor); | 84 void NotifyMonitorAdded(const gfx::Monitor& monitor); |
93 void NotifyMonitorRemoved(const Monitor* monitor); | 85 void NotifyMonitorRemoved(const gfx::Monitor& monitor); |
94 | 86 |
95 private: | 87 private: |
96 // If set before the RootWindow is created, the host window will cover the | 88 // If set before the RootWindow is created, the host window will cover the |
97 // entire monitor. Note that this can still be overridden via the | 89 // entire monitor. Note that this can still be overridden via the |
98 // switches::kAuraHostWindowSize flag. | 90 // switches::kAuraHostWindowSize flag. |
99 static bool use_fullscreen_host_window_; | 91 static bool use_fullscreen_host_window_; |
100 | 92 |
101 ObserverList<MonitorObserver> observers_; | 93 ObserverList<MonitorObserver> observers_; |
102 DISALLOW_COPY_AND_ASSIGN(MonitorManager); | 94 DISALLOW_COPY_AND_ASSIGN(MonitorManager); |
103 }; | 95 }; |
104 | 96 |
105 } // namespace aura | 97 } // namespace aura |
106 | 98 |
107 #endif // UI_AURA_MONITOR_MANAGER_H_ | 99 #endif // UI_AURA_MONITOR_MANAGER_H_ |
OLD | NEW |