| 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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 monitor_(new Monitor()) { | 31 monitor_(new Monitor()) { |
| 32 Init(); | 32 Init(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 SingleMonitorManager::~SingleMonitorManager() { | 35 SingleMonitorManager::~SingleMonitorManager() { |
| 36 if (root_window_) | 36 if (root_window_) |
| 37 root_window_->RemoveObserver(this); | 37 root_window_->RemoveObserver(this); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void SingleMonitorManager::OnNativeMonitorResized(const gfx::Size& size) { | 40 void SingleMonitorManager::OnNativeMonitorResized(const gfx::Size& size) { |
| 41 if (RootWindow::use_fullscreen_host_window()) { | 41 if (use_fullscreen_host_window()) { |
| 42 monitor_->set_size(size); | 42 monitor_->set_size(size); |
| 43 NotifyBoundsChanged(monitor_.get()); | 43 NotifyBoundsChanged(monitor_.get()); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 RootWindow* SingleMonitorManager::CreateRootWindowForMonitor( | 47 RootWindow* SingleMonitorManager::CreateRootWindowForMonitor( |
| 48 const Monitor* monitor) { | 48 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(); | 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 const Monitor* SingleMonitorManager::GetMonitorNearestWindow( |
| 57 const Window* window) const { | 57 const Window* window) const { |
| 58 return monitor_.get(); | 58 return monitor_.get(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 const Monitor* SingleMonitorManager::GetMonitorNearestPoint( | 61 const Monitor* SingleMonitorManager::GetMonitorNearestPoint( |
| 62 const gfx::Point& point) const { | 62 const gfx::Point& point) const { |
| 63 return monitor_.get(); | 63 return monitor_.get(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 const Monitor* SingleMonitorManager::GetPrimaryMonitor() const { | 66 Monitor* SingleMonitorManager::GetMonitorAt(size_t index) { |
| 67 return monitor_.get(); | 67 return !index ? monitor_.get() : NULL; |
| 68 } | 68 } |
| 69 | 69 |
| 70 size_t SingleMonitorManager::GetNumMonitors() const { | 70 size_t SingleMonitorManager::GetNumMonitors() const { |
| 71 return 1; | 71 return 1; |
| 72 } | 72 } |
| 73 | 73 |
| 74 Monitor* SingleMonitorManager::GetMonitorNearestWindow(const Window* window) { | 74 Monitor* SingleMonitorManager::GetMonitorNearestWindow(const Window* window) { |
| 75 return monitor_.get(); | 75 return monitor_.get(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void SingleMonitorManager::OnWindowBoundsChanged( | 78 void SingleMonitorManager::OnWindowBoundsChanged( |
| 79 Window* window, const gfx::Rect& bounds) { | 79 Window* window, const gfx::Rect& bounds) { |
| 80 if (!RootWindow::use_fullscreen_host_window()) { | 80 if (!use_fullscreen_host_window()) { |
| 81 Update(bounds.size()); | 81 Update(bounds.size()); |
| 82 NotifyBoundsChanged(monitor_.get()); | 82 NotifyBoundsChanged(monitor_.get()); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 void SingleMonitorManager::OnWindowDestroying(Window* window) { | 86 void SingleMonitorManager::OnWindowDestroying(Window* window) { |
| 87 if (root_window_ == window) | 87 if (root_window_ == window) |
| 88 root_window_ = NULL; | 88 root_window_ = NULL; |
| 89 } | 89 } |
| 90 | 90 |
| 91 void SingleMonitorManager::Init() { | 91 void SingleMonitorManager::Init() { |
| 92 gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, | |
| 93 kDefaultHostWindowWidth, kDefaultHostWindowHeight); | |
| 94 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 92 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 95 switches::kAuraHostWindowSize); | 93 switches::kAuraHostWindowSize); |
| 96 int x = 0, y = 0, width, height; | 94 monitor_.reset(CreateMonitorFromSpec(size_str)); |
| 97 if (sscanf(size_str.c_str(), "%dx%d", &width, &height) == 2) { | |
| 98 bounds.set_size(gfx::Size(width, height)); | |
| 99 } else if (sscanf(size_str.c_str(), "%d+%d-%dx%d", &x, &y, &width, &height) | |
| 100 == 4) { | |
| 101 bounds = gfx::Rect(x, y, width, height); | |
| 102 } else if (RootWindow::use_fullscreen_host_window()) { | |
| 103 bounds = gfx::Rect(RootWindowHost::GetNativeScreenSize()); | |
| 104 } | |
| 105 monitor_->set_bounds(bounds); | |
| 106 } | 95 } |
| 107 | 96 |
| 108 void SingleMonitorManager::Update(const gfx::Size size) { | 97 void SingleMonitorManager::Update(const gfx::Size size) { |
| 109 monitor_->set_size(size); | 98 monitor_->set_size(size); |
| 110 } | 99 } |
| 111 | 100 |
| 112 } // namespace inernal | 101 } // namespace inernal |
| 113 } // namespace aura | 102 } // namespace aura |
| OLD | NEW |