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 "ash/monitor/multi_monitor_manager.h" | |
6 | |
7 #include <string> | |
8 #include <vector> | |
9 | |
10 #include "base/command_line.h" | |
11 #include "base/stl_util.h" | |
12 #include "base/string_split.h" | |
13 #include "ui/aura/aura_switches.h" | |
14 #include "ui/aura/env.h" | |
15 #include "ui/aura/monitor.h" | |
16 #include "ui/aura/root_window.h" | |
17 #include "ui/aura/root_window_host.h" | |
18 #include "ui/gfx/rect.h" | |
19 #include "ui/aura/window_property.h" | |
20 | |
21 DECLARE_WINDOW_PROPERTY_TYPE(aura::Monitor*); | |
22 | |
23 namespace ash { | |
24 namespace internal { | |
25 | |
26 DEFINE_WINDOW_PROPERTY_KEY(aura::Monitor*, kMonitorKey, NULL); | |
27 | |
28 using std::string; | |
29 using std::vector; | |
30 using aura::Monitor; | |
31 using aura::RootWindow; | |
32 using aura::Window; | |
33 | |
34 MultiMonitorManager::MultiMonitorManager() { | |
35 Init(); | |
36 } | |
37 | |
38 MultiMonitorManager::~MultiMonitorManager() { | |
39 STLDeleteContainerPointers(monitors_.begin(), monitors_.end()); | |
40 } | |
41 | |
42 void MultiMonitorManager::OnNativeMonitorResized(const gfx::Size& size) { | |
43 // TODO(oshima): Update monitors using xrandr and notify observers | |
44 // Just update the primary for now. | |
45 if (use_fullscreen_host_window()) { | |
46 Monitor* monitor = | |
47 aura::Env::GetInstance()->monitor_manager()->GetMonitorAt(0); | |
48 monitor->set_size(size); | |
49 NotifyBoundsChanged(monitor); | |
50 } | |
51 } | |
52 | |
53 RootWindow* MultiMonitorManager::CreateRootWindowForMonitor( | |
54 Monitor* monitor) { | |
55 RootWindow* root_window = new RootWindow(monitor->bounds()); | |
56 root_window->AddObserver(this); | |
57 root_window->SetProperty(kMonitorKey, monitor); | |
58 return root_window; | |
59 } | |
60 | |
61 const Monitor* MultiMonitorManager::GetMonitorNearestWindow( | |
62 const Window* window) const { | |
63 if (!window) { | |
64 MultiMonitorManager* manager = const_cast<MultiMonitorManager*>(this); | |
65 return manager->GetMonitorAt(0); | |
66 } | |
67 const RootWindow* root = window->GetRootWindow(); | |
68 return root ? root->GetProperty(kMonitorKey) : NULL; | |
69 } | |
70 | |
71 const Monitor* MultiMonitorManager::GetMonitorNearestPoint( | |
72 const gfx::Point& point) const { | |
73 // TODO(oshima): For m19, mouse is constrained within | |
74 // the primary wnidow. | |
Ben Goodger (Google)
2012/03/20 17:09:02
window
oshima
2012/03/20 19:26:36
Done.
| |
75 MultiMonitorManager* manager = const_cast<MultiMonitorManager*>(this); | |
76 return manager->GetMonitorAt(0); | |
77 } | |
78 | |
79 Monitor* MultiMonitorManager::GetMonitorAt(size_t index) { | |
80 return index < monitors_.size() ? monitors_[index] : NULL; | |
81 } | |
82 | |
83 size_t MultiMonitorManager::GetNumMonitors() const { | |
84 return monitors_.size(); | |
85 } | |
86 | |
87 Monitor* MultiMonitorManager::GetMonitorNearestWindow(const Window* window) { | |
88 const MonitorManager* manager = this; | |
89 return const_cast<Monitor*>(manager->GetMonitorNearestWindow(window)); | |
90 } | |
91 | |
92 void MultiMonitorManager::OnWindowBoundsChanged( | |
93 Window* window, const gfx::Rect& bounds) { | |
94 if (!use_fullscreen_host_window()) { | |
95 Monitor* monitor = window->GetProperty(kMonitorKey); | |
96 monitor->set_size(bounds.size()); | |
97 NotifyBoundsChanged(monitor); | |
98 } | |
99 } | |
100 | |
101 void MultiMonitorManager::OnWindowDestroying(Window* window) { | |
102 Monitor* monitor = window->GetProperty(kMonitorKey); | |
103 monitors_.erase(std::find(monitors_.begin(), monitors_.end(), monitor)); | |
104 delete monitor; | |
105 } | |
106 | |
107 void MultiMonitorManager::Init() { | |
108 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
109 switches::kAuraHostWindowSize); | |
110 vector<string> parts; | |
111 base::SplitString(size_str, ',', &parts); | |
112 for (vector<string>::const_iterator iter = parts.begin(); | |
113 iter != parts.end(); ++iter) { | |
114 monitors_.push_back(CreateMonitorFromSpec(*iter)); | |
115 } | |
116 if (monitors_.empty()) | |
117 monitors_.push_back(CreateMonitorFromSpec("" /* default */)); | |
118 } | |
119 | |
120 } // namespace internal | |
121 } // namespace ash | |
OLD | NEW |