| OLD | NEW |
| (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 root_window_->RemoveObserver(this); |
| 31 } |
| 32 |
| 33 // MonitorManager overrides: |
| 34 virtual const Monitor* GetMonitorNearestWindow(const Window* window) const { |
| 35 return monitor_.get(); |
| 36 } |
| 37 virtual const Monitor* GetMonitorNearestPoint(const gfx::Point& point) const { |
| 38 return monitor_.get(); |
| 39 } |
| 40 virtual const Monitor* GetPrimaryMonitor() const { |
| 41 return monitor_.get(); |
| 42 } |
| 43 virtual size_t GetNumMonitors() const { |
| 44 return 1; |
| 45 } |
| 46 virtual Monitor* GetMonitorNearestWindow(const Window* window) { |
| 47 return monitor_.get(); |
| 48 } |
| 49 |
| 50 // WindowObserver overrides: |
| 51 virtual void OnWindowBoundsChanged(Window* window, const gfx::Rect& bounds) |
| 52 OVERRIDE { |
| 53 Update(bounds.size()); |
| 54 } |
| 55 |
| 56 private: |
| 57 void Update(const gfx::Size size) { |
| 58 gfx::Rect new_bounds(size); |
| 59 monitor_->set_bounds(new_bounds); |
| 60 } |
| 61 |
| 62 RootWindow* root_window_; |
| 63 scoped_ptr<Monitor> monitor_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(SingleMonitorManager); |
| 66 }; |
| 67 |
| 68 } // namespace |
| 69 |
| 70 MonitorManager::MonitorManager() { |
| 71 } |
| 72 |
| 73 MonitorManager::~MonitorManager() { |
| 74 } |
| 75 |
| 76 // static |
| 77 MonitorManager* CreateSingleMonitorManager(RootWindow* root_window) { |
| 78 return new SingleMonitorManager(root_window); |
| 79 } |
| 80 |
| 81 } // namespace aura |
| OLD | NEW |