Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: ash/display/display_manager.cc

Issue 11363124: Move DisplayManager and DisplayChangeObserverX11 from aura to ash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix rebase Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/display/display_manager.h ('k') | ash/display/display_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ash/display/multi_display_manager.h" 5 #include "ash/display/display_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/display/display_controller.h" 10 #include "ash/display/display_controller.h"
11 #include "ash/screen_ash.h"
11 #include "ash/shell.h" 12 #include "ash/shell.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/stl_util.h" 14 #include "base/stl_util.h"
14 #include "base/string_split.h" 15 #include "base/string_split.h"
15 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
16 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
17 #include "grit/ash_strings.h" 18 #include "grit/ash_strings.h"
18 #include "ui/aura/aura_switches.h" 19 #include "ui/aura/aura_switches.h"
19 #include "ui/aura/client/screen_position_client.h" 20 #include "ui/aura/client/screen_position_client.h"
21 #include "ui/aura/display_util.h"
20 #include "ui/aura/env.h" 22 #include "ui/aura/env.h"
21 #include "ui/aura/root_window.h" 23 #include "ui/aura/root_window.h"
22 #include "ui/aura/root_window_host.h" 24 #include "ui/aura/root_window_host.h"
23 #include "ui/aura/window_property.h" 25 #include "ui/aura/window_property.h"
24 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/gfx/display.h" 27 #include "ui/gfx/display.h"
26 #include "ui/gfx/screen.h" 28 #include "ui/gfx/screen.h"
27 #include "ui/gfx/rect.h" 29 #include "ui/gfx/rect.h"
28 #include "ui/gfx/size_conversions.h" 30 #include "ui/gfx/size_conversions.h"
29 31
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } // namespace 74 } // namespace
73 75
74 using aura::RootWindow; 76 using aura::RootWindow;
75 using aura::Window; 77 using aura::Window;
76 using std::string; 78 using std::string;
77 using std::vector; 79 using std::vector;
78 80
79 DEFINE_WINDOW_PROPERTY_KEY(int64, kDisplayIdKey, 81 DEFINE_WINDOW_PROPERTY_KEY(int64, kDisplayIdKey,
80 gfx::Display::kInvalidDisplayID); 82 gfx::Display::kInvalidDisplayID);
81 83
82 MultiDisplayManager::MultiDisplayManager() : 84 DisplayManager::DisplayManager() :
83 internal_display_id_(gfx::Display::kInvalidDisplayID), 85 internal_display_id_(gfx::Display::kInvalidDisplayID),
84 force_bounds_changed_(false) { 86 force_bounds_changed_(false) {
85 Init(); 87 Init();
86 } 88 }
87 89
88 MultiDisplayManager::~MultiDisplayManager() { 90 DisplayManager::~DisplayManager() {
89 } 91 }
90 92
91 // static 93 // static
92 void MultiDisplayManager::CycleDisplay() { 94 void DisplayManager::CycleDisplay() {
93 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( 95 Shell::GetInstance()->display_manager()->CycleDisplayImpl();
94 aura::Env::GetInstance()->display_manager());
95 manager->CycleDisplayImpl();
96 } 96 }
97 97
98 // static 98 // static
99 void MultiDisplayManager::ToggleDisplayScale() { 99 void DisplayManager::ToggleDisplayScale() {
100 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( 100 Shell::GetInstance()->display_manager()->ScaleDisplayImpl();
101 aura::Env::GetInstance()->display_manager());
102 manager->ScaleDisplayImpl();
103 } 101 }
104 102
105 bool MultiDisplayManager::IsActiveDisplay(const gfx::Display& display) const { 103 bool DisplayManager::IsActiveDisplay(const gfx::Display& display) const {
106 for (DisplayList::const_iterator iter = displays_.begin(); 104 for (DisplayList::const_iterator iter = displays_.begin();
107 iter != displays_.end(); ++iter) { 105 iter != displays_.end(); ++iter) {
108 if ((*iter).id() == display.id()) 106 if ((*iter).id() == display.id())
109 return true; 107 return true;
110 } 108 }
111 return false; 109 return false;
112 } 110 }
113 111
114 bool MultiDisplayManager::HasInternalDisplay() const { 112 bool DisplayManager::HasInternalDisplay() const {
115 return internal_display_id_ != gfx::Display::kInvalidDisplayID; 113 return internal_display_id_ != gfx::Display::kInvalidDisplayID;
116 } 114 }
117 115
118 bool MultiDisplayManager::IsInternalDisplayId(int64 id) const { 116 bool DisplayManager::IsInternalDisplayId(int64 id) const {
119 return internal_display_id_ == id; 117 return internal_display_id_ == id;
120 } 118 }
121 119
122 bool MultiDisplayManager::UpdateWorkAreaOfDisplayNearestWindow( 120 bool DisplayManager::UpdateWorkAreaOfDisplayNearestWindow(
123 const aura::Window* window, 121 const aura::Window* window,
124 const gfx::Insets& insets) { 122 const gfx::Insets& insets) {
125 const RootWindow* root = window->GetRootWindow(); 123 const RootWindow* root = window->GetRootWindow();
126 gfx::Display& display = FindDisplayForRootWindow(root); 124 gfx::Display& display = FindDisplayForRootWindow(root);
127 gfx::Rect old_work_area = display.work_area(); 125 gfx::Rect old_work_area = display.work_area();
128 display.UpdateWorkAreaFromInsets(insets); 126 display.UpdateWorkAreaFromInsets(insets);
129 return old_work_area != display.work_area(); 127 return old_work_area != display.work_area();
130 } 128 }
131 129
132 const gfx::Display& MultiDisplayManager::GetDisplayForId(int64 id) const { 130 const gfx::Display& DisplayManager::GetDisplayForId(int64 id) const {
133 return const_cast<MultiDisplayManager*>(this)->FindDisplayForId(id); 131 return const_cast<DisplayManager*>(this)->FindDisplayForId(id);
134 } 132 }
135 133
136 const gfx::Display& MultiDisplayManager::FindDisplayContainingPoint( 134 const gfx::Display& DisplayManager::FindDisplayContainingPoint(
137 const gfx::Point& point_in_screen) const { 135 const gfx::Point& point_in_screen) const {
138 for (DisplayList::const_iterator iter = displays_.begin(); 136 for (DisplayList::const_iterator iter = displays_.begin();
139 iter != displays_.end(); ++iter) { 137 iter != displays_.end(); ++iter) {
140 const gfx::Display& display = *iter; 138 const gfx::Display& display = *iter;
141 if (display.bounds().Contains(point_in_screen)) 139 if (display.bounds().Contains(point_in_screen))
142 return display; 140 return display;
143 } 141 }
144 return GetInvalidDisplay(); 142 return GetInvalidDisplay();
145 } 143 }
146 144
147 void MultiDisplayManager::SetOverscanInsets(int64 display_id, 145 void DisplayManager::SetOverscanInsets(int64 display_id,
148 const gfx::Insets& insets_in_dip) { 146 const gfx::Insets& insets_in_dip) {
149 DisplayList displays = displays_; 147 DisplayList displays = displays_;
150 std::map<int64, gfx::Insets>::const_iterator old_overscan = 148 std::map<int64, gfx::Insets>::const_iterator old_overscan =
151 overscan_mapping_.find(display_id); 149 overscan_mapping_.find(display_id);
152 if (old_overscan != overscan_mapping_.end()) { 150 if (old_overscan != overscan_mapping_.end()) {
153 gfx::Insets old_insets = old_overscan->second; 151 gfx::Insets old_insets = old_overscan->second;
154 for (DisplayList::iterator iter = displays.begin(); 152 for (DisplayList::iterator iter = displays.begin();
155 iter != displays.end(); ++iter) { 153 iter != displays.end(); ++iter) {
156 if (iter->id() == display_id) { 154 if (iter->id() == display_id) {
157 // Undo the existing insets before applying the new insets. 155 // Undo the existing insets before applying the new insets.
158 gfx::Rect bounds = iter->bounds_in_pixel(); 156 gfx::Rect bounds = iter->bounds_in_pixel();
159 bounds.Inset(old_insets.Scale(-iter->device_scale_factor())); 157 bounds.Inset(old_insets.Scale(-iter->device_scale_factor()));
160 iter->SetScaleAndBounds(iter->device_scale_factor(), bounds); 158 iter->SetScaleAndBounds(iter->device_scale_factor(), bounds);
161 break; 159 break;
162 } 160 }
163 } 161 }
164 } 162 }
165 overscan_mapping_[display_id] = insets_in_dip; 163 overscan_mapping_[display_id] = insets_in_dip;
166 OnNativeDisplaysChanged(displays); 164 OnNativeDisplaysChanged(displays);
167 } 165 }
168 166
169 gfx::Insets MultiDisplayManager::GetOverscanInsets(int64 display_id) const { 167 gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const {
170 std::map<int64, gfx::Insets>::const_iterator it = 168 std::map<int64, gfx::Insets>::const_iterator it =
171 overscan_mapping_.find(display_id); 169 overscan_mapping_.find(display_id);
172 return (it != overscan_mapping_.end()) ? it->second : gfx::Insets(); 170 return (it != overscan_mapping_.end()) ? it->second : gfx::Insets();
173 } 171 }
174 172
175 void MultiDisplayManager::OnNativeDisplaysChanged( 173 void DisplayManager::OnNativeDisplaysChanged(
176 const std::vector<gfx::Display>& updated_displays) { 174 const std::vector<gfx::Display>& updated_displays) {
177 if (updated_displays.empty()) { 175 if (updated_displays.empty()) {
178 // Don't update the displays when all displays are disconnected. 176 // Don't update the displays when all displays are disconnected.
179 // This happens when: 177 // This happens when:
180 // - the device is idle and powerd requested to turn off all displays. 178 // - the device is idle and powerd requested to turn off all displays.
181 // - the device is suspended. (kernel turns off all displays) 179 // - the device is suspended. (kernel turns off all displays)
182 // - the internal display's brightness is set to 0 and no external 180 // - the internal display's brightness is set to 0 and no external
183 // display is connected. 181 // display is connected.
184 // - the internal display's brightness is 0 and external display is 182 // - the internal display's brightness is 0 and external display is
185 // disconnected. 183 // disconnected.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 iter->SetScaleAndBounds(iter->device_scale_factor(), bounds); 221 iter->SetScaleAndBounds(iter->device_scale_factor(), bounds);
224 } 222 }
225 } 223 }
226 224
227 std::sort(displays_.begin(), displays_.end(), DisplaySortFunctor()); 225 std::sort(displays_.begin(), displays_.end(), DisplaySortFunctor());
228 std::sort(new_displays.begin(), new_displays.end(), DisplaySortFunctor()); 226 std::sort(new_displays.begin(), new_displays.end(), DisplaySortFunctor());
229 DisplayList removed_displays; 227 DisplayList removed_displays;
230 std::vector<size_t> changed_display_indices; 228 std::vector<size_t> changed_display_indices;
231 std::vector<size_t> added_display_indices; 229 std::vector<size_t> added_display_indices;
232 gfx::Display current_primary; 230 gfx::Display current_primary;
233 if (Shell::HasInstance()) 231 if (DisplayController::HasPrimaryDisplay())
234 current_primary = Shell::GetScreen()->GetPrimaryDisplay(); 232 current_primary = DisplayController::GetPrimaryDisplay();
235 233
236 for (DisplayList::iterator curr_iter = displays_.begin(), 234 for (DisplayList::iterator curr_iter = displays_.begin(),
237 new_iter = new_displays.begin(); 235 new_iter = new_displays.begin();
238 curr_iter != displays_.end() || new_iter != new_displays.end();) { 236 curr_iter != displays_.end() || new_iter != new_displays.end();) {
239 if (curr_iter == displays_.end()) { 237 if (curr_iter == displays_.end()) {
240 // more displays in new list. 238 // more displays in new list.
241 added_display_indices.push_back(new_iter - new_displays.begin()); 239 added_display_indices.push_back(new_iter - new_displays.begin());
242 ++new_iter; 240 ++new_iter;
243 } else if (new_iter == new_displays.end()) { 241 } else if (new_iter == new_displays.end()) {
244 // more displays in current list. 242 // more displays in current list.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 282
285 displays_ = new_displays; 283 displays_ = new_displays;
286 RefreshDisplayNames(); 284 RefreshDisplayNames();
287 285
288 // Temporarily add displays to be removed because display object 286 // Temporarily add displays to be removed because display object
289 // being removed are accessed during shutting down the root. 287 // being removed are accessed during shutting down the root.
290 displays_.insert(displays_.end(), removed_displays.begin(), 288 displays_.insert(displays_.end(), removed_displays.begin(),
291 removed_displays.end()); 289 removed_displays.end());
292 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); 290 for (std::vector<size_t>::iterator iter = changed_display_indices.begin();
293 iter != changed_display_indices.end(); ++iter) { 291 iter != changed_display_indices.end(); ++iter) {
294 NotifyBoundsChanged(displays_[*iter]); 292 Shell::GetInstance()->screen()->NotifyBoundsChanged(displays_[*iter]);
295 } 293 }
296 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); 294 for (std::vector<size_t>::iterator iter = added_display_indices.begin();
297 iter != added_display_indices.end(); ++iter) { 295 iter != added_display_indices.end(); ++iter) {
298 NotifyDisplayAdded(displays_[*iter]); 296 Shell::GetInstance()->screen()->NotifyDisplayAdded(displays_[*iter]);
299 } 297 }
300
301 for (DisplayList::const_reverse_iterator iter = removed_displays.rbegin(); 298 for (DisplayList::const_reverse_iterator iter = removed_displays.rbegin();
302 iter != removed_displays.rend(); ++iter) { 299 iter != removed_displays.rend(); ++iter) {
303 NotifyDisplayRemoved(displays_.back()); 300 Shell::GetInstance()->screen()->NotifyDisplayRemoved(displays_.back());
304 displays_.pop_back(); 301 displays_.pop_back();
305 } 302 }
306 EnsurePointerInDisplays(); 303 EnsurePointerInDisplays();
307 } 304 }
308 305
309 RootWindow* MultiDisplayManager::CreateRootWindowForDisplay( 306 RootWindow* DisplayManager::CreateRootWindowForDisplay(
310 const gfx::Display& display) { 307 const gfx::Display& display) {
311
312 RootWindow::CreateParams params(display.bounds_in_pixel()); 308 RootWindow::CreateParams params(display.bounds_in_pixel());
313 #if defined(OS_WIN) 309 #if defined(OS_WIN)
314 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 310 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
315 params.host = aura::RemoteRootWindowHostWin::Create( 311 params.host = aura::RemoteRootWindowHostWin::Create(
316 display.bounds_in_pixel()); 312 display.bounds_in_pixel());
317 } 313 }
318 #endif 314 #endif
319 aura::RootWindow* root_window = new aura::RootWindow(params); 315 aura::RootWindow* root_window = new aura::RootWindow(params);
320 // No need to remove RootWindowObserver because 316 // No need to remove RootWindowObserver because
321 // the DisplayManager object outlives RootWindow objects. 317 // the DisplayManager object outlives RootWindow objects.
322 root_window->AddRootWindowObserver(this); 318 root_window->AddRootWindowObserver(this);
323 root_window->SetProperty(kDisplayIdKey, display.id()); 319 root_window->SetProperty(kDisplayIdKey, display.id());
324 root_window->Init(); 320 root_window->Init();
325 return root_window; 321 return root_window;
326 } 322 }
327 323
328 gfx::Display* MultiDisplayManager::GetDisplayAt(size_t index) { 324 gfx::Display* DisplayManager::GetDisplayAt(size_t index) {
329 return index < displays_.size() ? &displays_[index] : NULL; 325 return index < displays_.size() ? &displays_[index] : NULL;
330 } 326 }
331 327
332 size_t MultiDisplayManager::GetNumDisplays() const { 328 size_t DisplayManager::GetNumDisplays() const {
333 return displays_.size(); 329 return displays_.size();
334 } 330 }
335 331
336 const gfx::Display& MultiDisplayManager::GetDisplayNearestWindow( 332 const gfx::Display& DisplayManager::GetDisplayNearestWindow(
337 const Window* window) const { 333 const Window* window) const {
338 if (!window) 334 if (!window)
339 return DisplayController::GetPrimaryDisplay(); 335 return DisplayController::GetPrimaryDisplay();
340 const RootWindow* root = window->GetRootWindow(); 336 const RootWindow* root = window->GetRootWindow();
341 MultiDisplayManager* manager = const_cast<MultiDisplayManager*>(this); 337 DisplayManager* manager = const_cast<DisplayManager*>(this);
342 return root ? 338 return root ?
343 manager->FindDisplayForRootWindow(root) : 339 manager->FindDisplayForRootWindow(root) :
344 DisplayController::GetPrimaryDisplay(); 340 DisplayController::GetPrimaryDisplay();
345 } 341 }
346 342
347 const gfx::Display& MultiDisplayManager::GetDisplayNearestPoint( 343 const gfx::Display& DisplayManager::GetDisplayNearestPoint(
348 const gfx::Point& point) const { 344 const gfx::Point& point) const {
349 // Fallback to the primary display if there is no root display containing 345 // Fallback to the primary display if there is no root display containing
350 // the |point|. 346 // the |point|.
351 const gfx::Display& display = FindDisplayContainingPoint(point); 347 const gfx::Display& display = FindDisplayContainingPoint(point);
352 return display.is_valid() ? display : DisplayController::GetPrimaryDisplay(); 348 return display.is_valid() ? display : DisplayController::GetPrimaryDisplay();
353 } 349 }
354 350
355 const gfx::Display& MultiDisplayManager::GetDisplayMatching( 351 const gfx::Display& DisplayManager::GetDisplayMatching(
356 const gfx::Rect& rect) const { 352 const gfx::Rect& rect) const {
357 if (rect.IsEmpty()) 353 if (rect.IsEmpty())
358 return GetDisplayNearestPoint(rect.origin()); 354 return GetDisplayNearestPoint(rect.origin());
359 355
360 int max = 0; 356 int max = 0;
361 const gfx::Display* matching = 0; 357 const gfx::Display* matching = 0;
362 for (std::vector<gfx::Display>::const_iterator iter = displays_.begin(); 358 for (std::vector<gfx::Display>::const_iterator iter = displays_.begin();
363 iter != displays_.end(); ++iter) { 359 iter != displays_.end(); ++iter) {
364 const gfx::Display& display = *iter; 360 const gfx::Display& display = *iter;
365 gfx::Rect intersect = gfx::IntersectRects(display.bounds(), rect); 361 gfx::Rect intersect = gfx::IntersectRects(display.bounds(), rect);
366 int area = intersect.width() * intersect.height(); 362 int area = intersect.width() * intersect.height();
367 if (area > max) { 363 if (area > max) {
368 max = area; 364 max = area;
369 matching = &(*iter); 365 matching = &(*iter);
370 } 366 }
371 } 367 }
372 // Fallback to the primary display if there is no matching display. 368 // Fallback to the primary display if there is no matching display.
373 return matching ? *matching : DisplayController::GetPrimaryDisplay(); 369 return matching ? *matching : DisplayController::GetPrimaryDisplay();
374 } 370 }
375 371
376 std::string MultiDisplayManager::GetDisplayNameFor( 372 std::string DisplayManager::GetDisplayNameFor(
377 const gfx::Display& display) { 373 const gfx::Display& display) {
378 if (!display.is_valid()) 374 if (!display.is_valid())
379 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); 375 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
380 376
381 std::map<int64, std::string>::const_iterator iter = 377 std::map<int64, std::string>::const_iterator iter =
382 display_names_.find(display.id()); 378 display_names_.find(display.id());
383 if (iter != display_names_.end()) 379 if (iter != display_names_.end())
384 return iter->second; 380 return iter->second;
385 381
386 return base::StringPrintf("Display %d", static_cast<int>(display.id())); 382 return base::StringPrintf("Display %d", static_cast<int>(display.id()));
387 } 383 }
388 384
389 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, 385 void DisplayManager::OnRootWindowResized(const aura::RootWindow* root,
390 const gfx::Size& old_size) { 386 const gfx::Size& old_size) {
391 if (!use_fullscreen_host_window()) { 387 if (!aura::UseFullscreenHostWindow()) {
392 gfx::Display& display = FindDisplayForRootWindow(root); 388 gfx::Display& display = FindDisplayForRootWindow(root);
393 if (display.size() != root->GetHostSize()) { 389 if (display.size() != root->GetHostSize()) {
394 display.SetSize(root->GetHostSize()); 390 display.SetSize(root->GetHostSize());
395 NotifyBoundsChanged(display); 391 Shell::GetInstance()->screen()->NotifyBoundsChanged(display);
396 } 392 }
397 } 393 }
398 } 394 }
399 395
400 void MultiDisplayManager::Init() { 396 void DisplayManager::Init() {
401 #if defined(OS_CHROMEOS) 397 #if defined(OS_CHROMEOS)
402 if (base::chromeos::IsRunningOnChromeOS()) { 398 if (base::chromeos::IsRunningOnChromeOS()) {
403 std::vector<XID> outputs; 399 std::vector<XID> outputs;
404 ui::GetOutputDeviceHandles(&outputs); 400 ui::GetOutputDeviceHandles(&outputs);
405 std::vector<std::string> output_names = ui::GetOutputNames(outputs); 401 std::vector<std::string> output_names = ui::GetOutputNames(outputs);
406 for (size_t i = 0; i < output_names.size(); ++i) { 402 for (size_t i = 0; i < output_names.size(); ++i) {
407 if (chromeos::OutputConfigurator::IsInternalOutputName( 403 if (chromeos::OutputConfigurator::IsInternalOutputName(
408 output_names[i])) { 404 output_names[i])) {
409 internal_display_id_ = GetDisplayIdForOutput(outputs[i]); 405 internal_display_id_ = GetDisplayIdForOutput(outputs[i]);
410 break; 406 break;
411 } 407 }
412 } 408 }
413 } 409 }
414 #endif 410 #endif
415 411
416 RefreshDisplayNames(); 412 RefreshDisplayNames();
417 413
418 #if defined(OS_WIN) 414 #if defined(OS_WIN)
419 if (base::win::GetVersion() >= base::win::VERSION_WIN8) 415 if (base::win::GetVersion() >= base::win::VERSION_WIN8)
420 set_use_fullscreen_host_window(true); 416 aura::SetUseFullscreenHostWindow(true);
421 #endif 417 #endif
422 // TODO(oshima): Move this logic to DisplayChangeObserver. 418 // TODO(oshima): Move this logic to DisplayChangeObserver.
423 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 419 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
424 switches::kAuraHostWindowSize); 420 switches::kAuraHostWindowSize);
425 vector<string> parts; 421 vector<string> parts;
426 base::SplitString(size_str, ',', &parts); 422 base::SplitString(size_str, ',', &parts);
427 for (vector<string>::const_iterator iter = parts.begin(); 423 for (vector<string>::const_iterator iter = parts.begin();
428 iter != parts.end(); ++iter) { 424 iter != parts.end(); ++iter) {
429 AddDisplayFromSpec(*iter); 425 AddDisplayFromSpec(*iter);
430 } 426 }
431 if (displays_.empty()) 427 if (displays_.empty())
432 AddDisplayFromSpec(std::string() /* default */); 428 AddDisplayFromSpec(std::string() /* default */);
433 } 429 }
434 430
435 void MultiDisplayManager::CycleDisplayImpl() { 431 void DisplayManager::CycleDisplayImpl() {
436 DCHECK(!displays_.empty()); 432 DCHECK(!displays_.empty());
437 std::vector<gfx::Display> new_displays; 433 std::vector<gfx::Display> new_displays;
438 new_displays.push_back(DisplayController::GetPrimaryDisplay()); 434 new_displays.push_back(DisplayController::GetPrimaryDisplay());
439 // Add if there is only one display. 435 // Add if there is only one display.
440 if (displays_.size() == 1) 436 if (displays_.size() == 1)
441 new_displays.push_back(CreateDisplayFromSpec("100+200-500x400")); 437 new_displays.push_back(aura::CreateDisplayFromSpec("100+200-500x400"));
442 OnNativeDisplaysChanged(new_displays); 438 OnNativeDisplaysChanged(new_displays);
443 } 439 }
444 440
445 void MultiDisplayManager::ScaleDisplayImpl() { 441 void DisplayManager::ScaleDisplayImpl() {
446 DCHECK(!displays_.empty()); 442 DCHECK(!displays_.empty());
447 std::vector<gfx::Display> new_displays; 443 std::vector<gfx::Display> new_displays;
448 for (DisplayList::const_iterator iter = displays_.begin(); 444 for (DisplayList::const_iterator iter = displays_.begin();
449 iter != displays_.end(); ++iter) { 445 iter != displays_.end(); ++iter) {
450 gfx::Display display = *iter; 446 gfx::Display display = *iter;
451 float factor = display.device_scale_factor() == 1.0f ? 2.0f : 1.0f; 447 float factor = display.device_scale_factor() == 1.0f ? 2.0f : 1.0f;
452 gfx::Point display_origin = display.bounds_in_pixel().origin(); 448 gfx::Point display_origin = display.bounds_in_pixel().origin();
453 gfx::Size display_size = gfx::ToFlooredSize( 449 gfx::Size display_size = gfx::ToFlooredSize(
454 gfx::ScaleSize(display.size(), factor)); 450 gfx::ScaleSize(display.size(), factor));
455 display.SetScaleAndBounds(factor, gfx::Rect(display_origin, display_size)); 451 display.SetScaleAndBounds(factor, gfx::Rect(display_origin, display_size));
456 new_displays.push_back(display); 452 new_displays.push_back(display);
457 } 453 }
458 OnNativeDisplaysChanged(new_displays); 454 OnNativeDisplaysChanged(new_displays);
459 } 455 }
460 456
461 gfx::Display& MultiDisplayManager::FindDisplayForRootWindow( 457 gfx::Display& DisplayManager::FindDisplayForRootWindow(
462 const aura::RootWindow* root_window) { 458 const aura::RootWindow* root_window) {
463 int64 id = root_window->GetProperty(kDisplayIdKey); 459 int64 id = root_window->GetProperty(kDisplayIdKey);
464 // if id is |kInvaildDisplayID|, it's being deleted. 460 // if id is |kInvaildDisplayID|, it's being deleted.
465 DCHECK(id != gfx::Display::kInvalidDisplayID); 461 DCHECK(id != gfx::Display::kInvalidDisplayID);
466 gfx::Display& display = FindDisplayForId(id); 462 gfx::Display& display = FindDisplayForId(id);
467 DCHECK(display.is_valid()); 463 DCHECK(display.is_valid());
468 return display; 464 return display;
469 } 465 }
470 466
471 gfx::Display& MultiDisplayManager::FindDisplayForId(int64 id) { 467 gfx::Display& DisplayManager::FindDisplayForId(int64 id) {
472 for (DisplayList::iterator iter = displays_.begin(); 468 for (DisplayList::iterator iter = displays_.begin();
473 iter != displays_.end(); ++iter) { 469 iter != displays_.end(); ++iter) {
474 if ((*iter).id() == id) 470 if ((*iter).id() == id)
475 return *iter; 471 return *iter;
476 } 472 }
477 DLOG(WARNING) << "Could not find display:" << id; 473 DLOG(WARNING) << "Could not find display:" << id;
478 return GetInvalidDisplay(); 474 return GetInvalidDisplay();
479 } 475 }
480 476
481 void MultiDisplayManager::AddDisplayFromSpec(const std::string& spec) { 477 void DisplayManager::AddDisplayFromSpec(const std::string& spec) {
482 gfx::Display display = CreateDisplayFromSpec(spec); 478 gfx::Display display = aura::CreateDisplayFromSpec(spec);
483 479
484 const gfx::Insets insets = display.GetWorkAreaInsets(); 480 const gfx::Insets insets = display.GetWorkAreaInsets();
485 const gfx::Rect& native_bounds = display.bounds_in_pixel(); 481 const gfx::Rect& native_bounds = display.bounds_in_pixel();
486 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds); 482 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds);
487 display.UpdateWorkAreaFromInsets(insets); 483 display.UpdateWorkAreaFromInsets(insets);
488 displays_.push_back(display); 484 displays_.push_back(display);
489 } 485 }
490 486
491 int64 MultiDisplayManager::SetFirstDisplayAsInternalDisplayForTest() { 487 int64 DisplayManager::SetFirstDisplayAsInternalDisplayForTest() {
492 internal_display_id_ = displays_[0].id(); 488 internal_display_id_ = displays_[0].id();
493 internal_display_.reset(new gfx::Display); 489 internal_display_.reset(new gfx::Display);
494 *internal_display_ = displays_[0]; 490 *internal_display_ = displays_[0];
495 return internal_display_id_; 491 return internal_display_id_;
496 } 492 }
497 493
498 void MultiDisplayManager::EnsurePointerInDisplays() { 494 void DisplayManager::EnsurePointerInDisplays() {
499 // Don't try to move the pointer during the boot/startup. 495 // Don't try to move the pointer during the boot/startup.
500 if (!Shell::HasInstance()) 496 if (!DisplayController::HasPrimaryDisplay())
501 return; 497 return;
502 gfx::Point location_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); 498 gfx::Point location_in_screen = Shell::GetScreen()->GetCursorScreenPoint();
503 gfx::Point target_location; 499 gfx::Point target_location;
504 int64 closest_distance_squared = -1; 500 int64 closest_distance_squared = -1;
505 501
506 for (DisplayList::const_iterator iter = displays_.begin(); 502 for (DisplayList::const_iterator iter = displays_.begin();
507 iter != displays_.end(); ++iter) { 503 iter != displays_.end(); ++iter) {
508 const gfx::Rect& display_bounds = iter->bounds(); 504 const gfx::Rect& display_bounds = iter->bounds();
509 505
510 if (display_bounds.Contains(location_in_screen)) { 506 if (display_bounds.Contains(location_in_screen)) {
(...skipping 15 matching lines...) Expand all
526 } 522 }
527 523
528 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 524 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
529 aura::client::ScreenPositionClient* client = 525 aura::client::ScreenPositionClient* client =
530 aura::client::GetScreenPositionClient(root_window); 526 aura::client::GetScreenPositionClient(root_window);
531 client->ConvertPointFromScreen(root_window, &target_location); 527 client->ConvertPointFromScreen(root_window, &target_location);
532 528
533 root_window->MoveCursorTo(target_location); 529 root_window->MoveCursorTo(target_location);
534 } 530 }
535 531
536 void MultiDisplayManager::RefreshDisplayNames() { 532 void DisplayManager::RefreshDisplayNames() {
537 display_names_.clear(); 533 display_names_.clear();
538 534
539 #if defined(OS_CHROMEOS) 535 #if defined(OS_CHROMEOS)
540 if (!base::chromeos::IsRunningOnChromeOS()) 536 if (!base::chromeos::IsRunningOnChromeOS())
541 return; 537 return;
542 #endif 538 #endif
543 539
544 #if defined(USE_X11) 540 #if defined(USE_X11)
545 std::vector<XID> outputs; 541 std::vector<XID> outputs;
546 if (!ui::GetOutputDeviceHandles(&outputs)) 542 if (!ui::GetOutputDeviceHandles(&outputs))
(...skipping 10 matching lines...) Expand all
557 display_names_[id] = 553 display_names_[id] =
558 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME); 554 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME);
559 } else { 555 } else {
560 display_names_[id] = name; 556 display_names_[id] = name;
561 } 557 }
562 } 558 }
563 } 559 }
564 #endif 560 #endif
565 } 561 }
566 562
567 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const { 563 void DisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const {
568 DisplayList::iterator iter_to_update = to_update->begin(); 564 DisplayList::iterator iter_to_update = to_update->begin();
569 DisplayList::const_iterator iter = displays_.begin(); 565 DisplayList::const_iterator iter = displays_.begin();
570 for (; iter != displays_.end() && iter_to_update != to_update->end(); 566 for (; iter != displays_.end() && iter_to_update != to_update->end();
571 ++iter, ++iter_to_update) { 567 ++iter, ++iter_to_update) {
572 (*iter_to_update).set_id((*iter).id()); 568 (*iter_to_update).set_id((*iter).id());
573 } 569 }
574 } 570 }
575 571
576 } // namespace internal 572 } // namespace internal
577 } // namespace ash 573 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_manager.h ('k') | ash/display/display_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698