Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Side by Side Diff: ui/aura/monitor_manager.cc

Issue 9699013: MonitorManager to manage multiple monitors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #include "ui/aura/monitor_manager.h"
6
7 #include "base/basictypes.h"
8 #include "base/stl_util.h"
9 #include "ui/aura/monitor.h"
10 #include "ui/aura/root_window.h"
11 #include "ui/aura/window.h"
12 #include "ui/aura/window_observer.h"
13 #include "ui/gfx/rect.h"
14
15 namespace aura {
16 namespace {
17
18 // A monitor manager assuming there is one monitor.
19 class SingleMonitorManager : public MonitorManager,
20 public WindowObserver {
21 public:
22 SingleMonitorManager(RootWindow* root_window)
23 : root_window_(root_window),
24 monitor_(new Monitor()) {
25 root_window_->AddObserver(this);
26 Update(root_window_->bounds().size());
27 }
28
29 virtual ~SingleMonitorManager() {
30 if (root_window_)
31 root_window_->RemoveObserver(this);
32 }
33
34 // MonitorManager overrides:
35 virtual const Monitor* GetMonitorNearestWindow(const Window* window) const {
36 return monitor_.get();
37 }
38 virtual const Monitor* GetMonitorNearestPoint(const gfx::Point& point) const {
39 return monitor_.get();
40 }
41 virtual const Monitor* GetPrimaryMonitor() const {
42 return monitor_.get();
43 }
44 virtual size_t GetNumMonitors() const {
45 return 1;
46 }
47 virtual Monitor* GetMonitorNearestWindow(const Window* window) {
48 return monitor_.get();
49 }
50
51 // WindowObserver overrides:
52 virtual void OnWindowBoundsChanged(Window* window, const gfx::Rect& bounds)
53 OVERRIDE {
54 Update(bounds.size());
55 }
56 virtual void OnWindowDestroying(Window* window) {
57 if (root_window_ == window)
58 root_window_ = NULL;
59 }
60
61 private:
62 void Update(const gfx::Size size) {
63 gfx::Rect new_bounds(size);
64 monitor_->set_bounds(new_bounds);
65 }
66
67 RootWindow* root_window_;
68 scoped_ptr<Monitor> monitor_;
69
70 DISALLOW_COPY_AND_ASSIGN(SingleMonitorManager);
71 };
72
73 } // namespace
74
75 MonitorManager::MonitorManager() {
76 }
77
78 MonitorManager::~MonitorManager() {
79 }
80
81 // static
82 MonitorManager* CreateSingleMonitorManager(RootWindow* root_window) {
83 return new SingleMonitorManager(root_window);
84 }
85
86 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698