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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/aura/monitor_manager.cc
diff --git a/ui/aura/monitor_manager.cc b/ui/aura/monitor_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..62b59b9dcfcb22c7e6648d318c6b058dd2a23098
--- /dev/null
+++ b/ui/aura/monitor_manager.cc
@@ -0,0 +1,86 @@
+// 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.
+
+#include "ui/aura/monitor_manager.h"
+
+#include "base/basictypes.h"
+#include "base/stl_util.h"
+#include "ui/aura/monitor.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/window.h"
+#include "ui/aura/window_observer.h"
+#include "ui/gfx/rect.h"
+
+namespace aura {
+namespace {
+
+// A monitor manager assuming there is one monitor.
+class SingleMonitorManager : public MonitorManager,
+ public WindowObserver {
+ public:
+ SingleMonitorManager(RootWindow* root_window)
+ : root_window_(root_window),
+ monitor_(new Monitor()) {
+ root_window_->AddObserver(this);
+ Update(root_window_->bounds().size());
+ }
+
+ virtual ~SingleMonitorManager() {
+ if (root_window_)
+ root_window_->RemoveObserver(this);
+ }
+
+ // MonitorManager overrides:
+ virtual const Monitor* GetMonitorNearestWindow(const Window* window) const {
+ return monitor_.get();
+ }
+ virtual const Monitor* GetMonitorNearestPoint(const gfx::Point& point) const {
+ return monitor_.get();
+ }
+ virtual const Monitor* GetPrimaryMonitor() const {
+ return monitor_.get();
+ }
+ virtual size_t GetNumMonitors() const {
+ return 1;
+ }
+ virtual Monitor* GetMonitorNearestWindow(const Window* window) {
+ return monitor_.get();
+ }
+
+ // WindowObserver overrides:
+ virtual void OnWindowBoundsChanged(Window* window, const gfx::Rect& bounds)
+ OVERRIDE {
+ Update(bounds.size());
+ }
+ virtual void OnWindowDestroying(Window* window) {
+ if (root_window_ == window)
+ root_window_ = NULL;
+ }
+
+ private:
+ void Update(const gfx::Size size) {
+ gfx::Rect new_bounds(size);
+ monitor_->set_bounds(new_bounds);
+ }
+
+ RootWindow* root_window_;
+ scoped_ptr<Monitor> monitor_;
+
+ DISALLOW_COPY_AND_ASSIGN(SingleMonitorManager);
+};
+
+} // namespace
+
+MonitorManager::MonitorManager() {
+}
+
+MonitorManager::~MonitorManager() {
+}
+
+// static
+MonitorManager* CreateSingleMonitorManager(RootWindow* root_window) {
+ return new SingleMonitorManager(root_window);
+}
+
+} // namespace aura

Powered by Google App Engine
This is Rietveld 408576698