summaryrefslogtreecommitdiffstats
path: root/ui/aura/monitor_manager.h
blob: 9bbd028df9173d6d1b754d4c347a68d6ad2a10bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_AURA_MONITOR_MANAGER_H_
#define UI_AURA_MONITOR_MANAGER_H_
#pragma once

#include <string>
#include <vector>

#include "base/basictypes.h"
#include "base/observer_list.h"
#include "ui/aura/aura_export.h"

namespace gfx {
class Point;
class Size;
}

namespace aura {
class Monitor;
class RootWindow;
class Window;

// Observers for monitor configuration changes.
// TODO(oshima): multiple monitor support.
class MonitorObserver {
 public:
  virtual void OnMonitorBoundsChanged(const Monitor* monitor) = 0;
  virtual void OnMonitorAdded(Monitor* new_monitor) = 0;
  virtual void OnMonitorRemoved(const Monitor* old_monitor) = 0;
};

// MonitorManager creates, deletes and updates Monitor objects when
// monitor configuration changes, and notifies MonitorObservers about
// the change. This is owned by Env and its lifetime is longer than
// any windows.
class AURA_EXPORT MonitorManager {
 public:
  static void set_use_fullscreen_host_window(bool use_fullscreen) {
    use_fullscreen_host_window_ = use_fullscreen;
  }
  static bool use_fullscreen_host_window() {
    return use_fullscreen_host_window_;
  }

  // Creates a monitor from string spec. 100+200-1440x800 creates monitor
  // whose size is 1440x800 at the location (100, 200) in screen's coordinates.
  // The location can be omitted and be just "1440x800", which creates
  // monitor at the origin of the screen. An empty string creates
  // the monitor with default size.
  static Monitor* CreateMonitorFromSpec(const std::string& spec);

  // A utility function to create a root window for primary monitor.
  static RootWindow* CreateRootWindowForPrimaryMonitor();

  MonitorManager();
  virtual ~MonitorManager();

  // Adds/removes MonitorObservers.
  void AddObserver(MonitorObserver* observer);
  void RemoveObserver(MonitorObserver* observer);

  // Called when monitor configuration has changed. The new monitor
  // configurations is passed as a vector of Monitor object, which
  // contains each monitor's new infomration.
  virtual void OnNativeMonitorsChanged(
      const std::vector<const Monitor*>& monitors) = 0;

  // Create a root window for given |monitor|.
  virtual RootWindow* CreateRootWindowForMonitor(Monitor* monitor) = 0;

  // Returns the monitor object nearest given |window|.
  virtual const Monitor* GetMonitorNearestWindow(
      const Window* window) const = 0;
  virtual Monitor* GetMonitorNearestWindow(const Window* window) = 0;

  // Returns the monitor object nearest given |pint|.
  virtual  const Monitor* GetMonitorNearestPoint(
      const gfx::Point& point) const = 0;

  // Returns the monitor at |index|. The monitor at 0 is considered
  // "primary".
  virtual Monitor* GetMonitorAt(size_t index) = 0;

  virtual size_t GetNumMonitors() const = 0;

 protected:
  // Calls observers' OnMonitorBoundsChanged methods.
  void NotifyBoundsChanged(const Monitor* monitor);
  void NotifyMonitorAdded(Monitor* monitor);
  void NotifyMonitorRemoved(const Monitor* monitor);

 private:
  // If set before the RootWindow is created, the host window will cover the
  // entire monitor.  Note that this can still be overridden via the
  // switches::kAuraHostWindowSize flag.
  static bool use_fullscreen_host_window_;

  ObserverList<MonitorObserver> observers_;
  DISALLOW_COPY_AND_ASSIGN(MonitorManager);
};

}  // namespace aura

#endif  // UI_AURA_MONITOR_MANAGER_H_