| 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 #include "ui/aura/single_monitor_manager.h" | 5 #include "ui/aura/single_monitor_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "ui/aura/aura_switches.h" | 10 #include "ui/aura/aura_switches.h" |
| 11 #include "ui/aura/monitor.h" | |
| 12 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
| 13 #include "ui/aura/root_window_host.h" | 12 #include "ui/aura/root_window_host.h" |
| 13 #include "ui/gfx/monitor.h" |
| 14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 15 | 15 |
| 16 namespace aura { | 16 namespace aura { |
| 17 | 17 |
| 18 using std::string; | 18 using std::string; |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 // Default bounds for the primary monitor. | 21 // Default bounds for the primary monitor. |
| 22 static const int kDefaultHostWindowX = 200; | 22 static const int kDefaultHostWindowX = 200; |
| 23 static const int kDefaultHostWindowY = 200; | 23 static const int kDefaultHostWindowY = 200; |
| 24 static const int kDefaultHostWindowWidth = 1280; | 24 static const int kDefaultHostWindowWidth = 1280; |
| 25 static const int kDefaultHostWindowHeight = 1024; | 25 static const int kDefaultHostWindowHeight = 1024; |
| 26 } | 26 } |
| 27 | 27 |
| 28 SingleMonitorManager::SingleMonitorManager() | 28 SingleMonitorManager::SingleMonitorManager() |
| 29 : root_window_(NULL) { | 29 : root_window_(NULL) { |
| 30 Init(); | 30 Init(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 SingleMonitorManager::~SingleMonitorManager() { | 33 SingleMonitorManager::~SingleMonitorManager() { |
| 34 // All monitors must have been deleted when monitor manager is deleted. | 34 // All monitors must have been deleted when monitor manager is deleted. |
| 35 CHECK(!root_window_); | 35 CHECK(!root_window_); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void SingleMonitorManager::OnNativeMonitorsChanged( | 38 void SingleMonitorManager::OnNativeMonitorsChanged( |
| 39 const std::vector<const Monitor*>& monitors) { | 39 const std::vector<const gfx::Monitor*>& monitors) { |
| 40 DCHECK(monitors.size() > 0); | 40 DCHECK(monitors.size() > 0); |
| 41 if (use_fullscreen_host_window()) { | 41 if (use_fullscreen_host_window()) { |
| 42 monitor_->set_size(monitors[0]->bounds().size()); | 42 monitor_->SetSizeAndUpdateWorkArea(monitors[0]->bounds().size()); |
| 43 NotifyBoundsChanged(monitor_.get()); | 43 NotifyBoundsChanged(monitor_.get()); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 RootWindow* SingleMonitorManager::CreateRootWindowForMonitor( | 47 RootWindow* SingleMonitorManager::CreateRootWindowForMonitor( |
| 48 Monitor* monitor) { | 48 gfx::Monitor* monitor) { |
| 49 DCHECK(!root_window_); | 49 DCHECK(!root_window_); |
| 50 DCHECK_EQ(monitor_.get(), monitor); | 50 DCHECK_EQ(monitor_.get(), monitor); |
| 51 root_window_ = new RootWindow(monitor->bounds()); | 51 root_window_ = new RootWindow(monitor->bounds()); |
| 52 root_window_->AddObserver(this); | 52 root_window_->AddObserver(this); |
| 53 return root_window_; | 53 return root_window_; |
| 54 } | 54 } |
| 55 | 55 |
| 56 const Monitor* SingleMonitorManager::GetMonitorNearestWindow( | 56 gfx::Monitor* SingleMonitorManager::GetMonitorAt(size_t index) { |
| 57 const Window* window) const { | |
| 58 return monitor_.get(); | |
| 59 } | |
| 60 | |
| 61 const Monitor* SingleMonitorManager::GetMonitorNearestPoint( | |
| 62 const gfx::Point& point) const { | |
| 63 return monitor_.get(); | |
| 64 } | |
| 65 | |
| 66 Monitor* SingleMonitorManager::GetMonitorAt(size_t index) { | |
| 67 return !index ? monitor_.get() : NULL; | 57 return !index ? monitor_.get() : NULL; |
| 68 } | 58 } |
| 69 | 59 |
| 70 size_t SingleMonitorManager::GetNumMonitors() const { | 60 size_t SingleMonitorManager::GetNumMonitors() const { |
| 71 return 1; | 61 return 1; |
| 72 } | 62 } |
| 73 | 63 |
| 74 Monitor* SingleMonitorManager::GetMonitorNearestWindow(const Window* window) { | 64 const gfx::Monitor* SingleMonitorManager::GetMonitorNearestWindow( |
| 65 const Window* window) const { |
| 75 return monitor_.get(); | 66 return monitor_.get(); |
| 76 } | 67 } |
| 77 | 68 |
| 69 gfx::Monitor* SingleMonitorManager::GetMonitorNearestWindow( |
| 70 const Window* window) { |
| 71 return monitor_.get(); |
| 72 } |
| 73 |
| 74 const gfx::Monitor* SingleMonitorManager::GetMonitorNearestPoint( |
| 75 const gfx::Point& point) const { |
| 76 return monitor_.get(); |
| 77 } |
| 78 |
| 78 void SingleMonitorManager::OnWindowBoundsChanged( | 79 void SingleMonitorManager::OnWindowBoundsChanged( |
| 79 Window* window, const gfx::Rect& bounds) { | 80 Window* window, const gfx::Rect& bounds) { |
| 80 if (!use_fullscreen_host_window()) { | 81 if (!use_fullscreen_host_window()) { |
| 81 Update(bounds.size()); | 82 Update(bounds.size()); |
| 82 NotifyBoundsChanged(monitor_.get()); | 83 NotifyBoundsChanged(monitor_.get()); |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 | 86 |
| 86 void SingleMonitorManager::OnWindowDestroying(Window* window) { | 87 void SingleMonitorManager::OnWindowDestroying(Window* window) { |
| 87 if (root_window_ == window) | 88 if (root_window_ == window) |
| 88 root_window_ = NULL; | 89 root_window_ = NULL; |
| 89 } | 90 } |
| 90 | 91 |
| 91 void SingleMonitorManager::Init() { | 92 void SingleMonitorManager::Init() { |
| 92 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 93 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 93 switches::kAuraHostWindowSize); | 94 switches::kAuraHostWindowSize); |
| 94 monitor_.reset(CreateMonitorFromSpec(size_str)); | 95 monitor_.reset(CreateMonitorFromSpec(size_str)); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void SingleMonitorManager::Update(const gfx::Size size) { | 98 void SingleMonitorManager::Update(const gfx::Size size) { |
| 98 monitor_->set_size(size); | 99 monitor_->SetSizeAndUpdateWorkArea(size); |
| 99 } | 100 } |
| 100 | 101 |
| 101 } // namespace aura | 102 } // namespace aura |
| OLD | NEW |