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