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<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_); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 RootWindow* SingleMonitorManager::CreateRootWindowForMonitor( | 47 RootWindow* SingleMonitorManager::CreateRootWindowForMonitor( |
48 Monitor* monitor) { | 48 const gfx::Monitor& monitor) { |
49 DCHECK(!root_window_); | 49 DCHECK(!root_window_); |
50 DCHECK_EQ(monitor_.get(), monitor); | 50 DCHECK_EQ(monitor_.id(), monitor.id()); |
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 const gfx::Monitor& SingleMonitorManager::GetMonitorAt(size_t index) { |
57 const Window* window) const { | 57 return monitor_; |
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; | |
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( |
75 return monitor_.get(); | 65 const Window* window) const { |
| 66 return monitor_; |
| 67 } |
| 68 |
| 69 const gfx::Monitor& SingleMonitorManager::GetMonitorNearestPoint( |
| 70 const gfx::Point& point) const { |
| 71 return monitor_; |
76 } | 72 } |
77 | 73 |
78 void SingleMonitorManager::OnWindowBoundsChanged( | 74 void SingleMonitorManager::OnWindowBoundsChanged( |
79 Window* window, const gfx::Rect& bounds) { | 75 Window* window, const gfx::Rect& bounds) { |
80 if (!use_fullscreen_host_window()) { | 76 if (!use_fullscreen_host_window()) { |
81 Update(bounds.size()); | 77 Update(bounds.size()); |
82 NotifyBoundsChanged(monitor_.get()); | 78 NotifyBoundsChanged(monitor_); |
83 } | 79 } |
84 } | 80 } |
85 | 81 |
86 void SingleMonitorManager::OnWindowDestroying(Window* window) { | 82 void SingleMonitorManager::OnWindowDestroying(Window* window) { |
87 if (root_window_ == window) | 83 if (root_window_ == window) |
88 root_window_ = NULL; | 84 root_window_ = NULL; |
89 } | 85 } |
90 | 86 |
91 void SingleMonitorManager::Init() { | 87 void SingleMonitorManager::Init() { |
92 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 88 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
93 switches::kAuraHostWindowSize); | 89 switches::kAuraHostWindowSize); |
94 monitor_.reset(CreateMonitorFromSpec(size_str)); | 90 monitor_ = CreateMonitorFromSpec(size_str); |
95 } | 91 } |
96 | 92 |
97 void SingleMonitorManager::Update(const gfx::Size size) { | 93 void SingleMonitorManager::Update(const gfx::Size size) { |
98 monitor_->set_size(size); | 94 monitor_.SetSizeAndUpdateWorkArea(size); |
99 } | 95 } |
100 | 96 |
101 } // namespace aura | 97 } // namespace aura |
OLD | NEW |