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

Side by Side Diff: ash/display/display_controller.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_controller.h ('k') | ash/display/display_controller_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/display_controller.h" 5 #include "ash/display/display_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/display/multi_display_manager.h" 10 #include "ash/display/display_manager.h"
11 #include "ash/root_window_controller.h" 11 #include "ash/root_window_controller.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/wm/coordinate_conversion.h" 13 #include "ash/wm/coordinate_conversion.h"
14 #include "ash/wm/property_util.h" 14 #include "ash/wm/property_util.h"
15 #include "ash/wm/window_util.h" 15 #include "ash/wm/window_util.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/json/json_value_converter.h" 17 #include "base/json/json_value_converter.h"
18 #include "base/string_piece.h" 18 #include "base/string_piece.h"
19 #include "base/stringprintf.h" 19 #include "base/stringprintf.h"
20 #include "base/values.h" 20 #include "base/values.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 case DisplayLayout::BOTTOM: 71 case DisplayLayout::BOTTOM:
72 return std::string("bottom"); 72 return std::string("bottom");
73 case DisplayLayout::RIGHT: 73 case DisplayLayout::RIGHT:
74 return std::string("right"); 74 return std::string("right");
75 case DisplayLayout::LEFT: 75 case DisplayLayout::LEFT:
76 return std::string("left"); 76 return std::string("left");
77 } 77 }
78 return std::string("unknown"); 78 return std::string("unknown");
79 } 79 }
80 80
81 internal::MultiDisplayManager* GetDisplayManager() { 81 internal::DisplayManager* GetDisplayManager() {
82 return static_cast<internal::MultiDisplayManager*>( 82 return Shell::GetInstance()->display_manager();
83 aura::Env::GetInstance()->display_manager());
84 } 83 }
85 84
86 } // namespace 85 } // namespace
87 86
88 DisplayLayout::DisplayLayout() 87 DisplayLayout::DisplayLayout()
89 : position(RIGHT), 88 : position(RIGHT),
90 offset(0) {} 89 offset(0) {}
91 90
92 DisplayLayout::DisplayLayout(DisplayLayout::Position position, int offset) 91 DisplayLayout::DisplayLayout(DisplayLayout::Position position, int offset)
93 : position(position), 92 : position(position),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 "position", &DisplayLayout::position, &GetPositionFromString); 153 "position", &DisplayLayout::position, &GetPositionFromString);
155 converter->RegisterIntField("offset", &DisplayLayout::offset); 154 converter->RegisterIntField("offset", &DisplayLayout::offset);
156 } 155 }
157 156
158 DisplayController::DisplayController() 157 DisplayController::DisplayController()
159 : desired_primary_display_id_(gfx::Display::kInvalidDisplayID) { 158 : desired_primary_display_id_(gfx::Display::kInvalidDisplayID) {
160 // Reset primary display to make sure that tests don't use 159 // Reset primary display to make sure that tests don't use
161 // stale display info from previous tests. 160 // stale display info from previous tests.
162 primary_display_id = gfx::Display::kInvalidDisplayID; 161 primary_display_id = gfx::Display::kInvalidDisplayID;
163 162
164 GetDisplayManager()->AddObserver(this); 163 Shell::GetScreen()->AddObserver(this);
165 } 164 }
166 165
167 DisplayController::~DisplayController() { 166 DisplayController::~DisplayController() {
168 GetDisplayManager()->RemoveObserver(this); 167 Shell::GetScreen()->RemoveObserver(this);
169 // Delete all root window controllers, which deletes root window 168 // Delete all root window controllers, which deletes root window
170 // from the last so that the primary root window gets deleted last. 169 // from the last so that the primary root window gets deleted last.
171 for (std::map<int64, aura::RootWindow*>::const_reverse_iterator it = 170 for (std::map<int64, aura::RootWindow*>::const_reverse_iterator it =
172 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { 171 root_windows_.rbegin(); it != root_windows_.rend(); ++it) {
173 internal::RootWindowController* controller = 172 internal::RootWindowController* controller =
174 GetRootWindowController(it->second); 173 GetRootWindowController(it->second);
175 DCHECK(controller); 174 DCHECK(controller);
176 delete controller; 175 delete controller;
177 } 176 }
178 } 177 }
179 // static 178 // static
180 const gfx::Display& DisplayController::GetPrimaryDisplay() { 179 const gfx::Display& DisplayController::GetPrimaryDisplay() {
181 DCHECK_NE(primary_display_id, gfx::Display::kInvalidDisplayID); 180 DCHECK_NE(primary_display_id, gfx::Display::kInvalidDisplayID);
182 return GetDisplayManager()->GetDisplayForId(primary_display_id); 181 return GetDisplayManager()->GetDisplayForId(primary_display_id);
183 } 182 }
184 183
184 // static
185 bool DisplayController::HasPrimaryDisplay() {
186 return primary_display_id != gfx::Display::kInvalidDisplayID;
187 }
188
185 void DisplayController::InitPrimaryDisplay() { 189 void DisplayController::InitPrimaryDisplay() {
186 const gfx::Display* primary_candidate = GetDisplayManager()->GetDisplayAt(0); 190 const gfx::Display* primary_candidate = GetDisplayManager()->GetDisplayAt(0);
187 #if defined(OS_CHROMEOS) 191 #if defined(OS_CHROMEOS)
188 if (base::chromeos::IsRunningOnChromeOS()) { 192 if (base::chromeos::IsRunningOnChromeOS()) {
189 internal::MultiDisplayManager* display_manager = GetDisplayManager(); 193 internal::DisplayManager* display_manager = GetDisplayManager();
190 // On ChromeOS device, root windows are stacked vertically, and 194 // On ChromeOS device, root windows are stacked vertically, and
191 // default primary is the one on top. 195 // default primary is the one on top.
192 int count = display_manager->GetNumDisplays(); 196 int count = display_manager->GetNumDisplays();
193 int y = primary_candidate->bounds_in_pixel().y(); 197 int y = primary_candidate->bounds_in_pixel().y();
194 for (int i = 1; i < count; ++i) { 198 for (int i = 1; i < count; ++i) {
195 const gfx::Display* display = display_manager->GetDisplayAt(i); 199 const gfx::Display* display = display_manager->GetDisplayAt(i);
196 if (display_manager->IsInternalDisplayId(display->id())) { 200 if (display_manager->IsInternalDisplayId(display->id())) {
197 primary_candidate = display; 201 primary_candidate = display;
198 break; 202 break;
199 } else if (display->bounds_in_pixel().y() < y) { 203 } else if (display->bounds_in_pixel().y() < y) {
200 primary_candidate = display; 204 primary_candidate = display;
201 y = display->bounds_in_pixel().y(); 205 y = display->bounds_in_pixel().y();
202 } 206 }
203 } 207 }
204 } 208 }
205 #endif 209 #endif
206 primary_display_id = primary_candidate->id(); 210 primary_display_id = primary_candidate->id();
207 aura::RootWindow* root = AddRootWindowForDisplay(*primary_candidate); 211 aura::RootWindow* root = AddRootWindowForDisplay(*primary_candidate);
208 root->SetHostBounds(primary_candidate->bounds_in_pixel()); 212 root->SetHostBounds(primary_candidate->bounds_in_pixel());
209 UpdateDisplayBoundsForLayout(); 213 UpdateDisplayBoundsForLayout();
210 } 214 }
211 215
212 void DisplayController::InitSecondaryDisplays() { 216 void DisplayController::InitSecondaryDisplays() {
213 internal::MultiDisplayManager* display_manager = GetDisplayManager(); 217 internal::DisplayManager* display_manager = GetDisplayManager();
214 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { 218 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
215 const gfx::Display* display = display_manager->GetDisplayAt(i); 219 const gfx::Display* display = display_manager->GetDisplayAt(i);
216 if (primary_display_id != display->id()) { 220 if (primary_display_id != display->id()) {
217 aura::RootWindow* root = AddRootWindowForDisplay(*display); 221 aura::RootWindow* root = AddRootWindowForDisplay(*display);
218 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); 222 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root);
219 } 223 }
220 } 224 }
221 CommandLine* command_line = CommandLine::ForCurrentProcess(); 225 CommandLine* command_line = CommandLine::ForCurrentProcess();
222 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) { 226 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) {
223 std::string value = command_line->GetSwitchValueASCII( 227 std::string value = command_line->GetSwitchValueASCII(
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 // On release build, just fallback to default instead of blowing up. 347 // On release build, just fallback to default instead of blowing up.
344 return default_display_layout_; 348 return default_display_layout_;
345 } 349 }
346 350
347 void DisplayController::SetPrimaryDisplayId(int64 id) { 351 void DisplayController::SetPrimaryDisplayId(int64 id) {
348 desired_primary_display_id_ = id; 352 desired_primary_display_id_ = id;
349 353
350 if (desired_primary_display_id_ == primary_display_id) 354 if (desired_primary_display_id_ == primary_display_id)
351 return; 355 return;
352 356
353 aura::DisplayManager* display_manager = 357 internal::DisplayManager* display_manager = GetDisplayManager();
354 aura::Env::GetInstance()->display_manager();
355 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { 358 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
356 gfx::Display* display = display_manager->GetDisplayAt(i); 359 gfx::Display* display = display_manager->GetDisplayAt(i);
357 if (display->id() == id) { 360 if (display->id() == id) {
358 SetPrimaryDisplay(*display); 361 SetPrimaryDisplay(*display);
359 break; 362 break;
360 } 363 }
361 } 364 }
362 } 365 }
363 366
364 void DisplayController::SetPrimaryDisplay( 367 void DisplayController::SetPrimaryDisplay(
365 const gfx::Display& new_primary_display) { 368 const gfx::Display& new_primary_display) {
366 internal::MultiDisplayManager* display_manager = GetDisplayManager(); 369 internal::DisplayManager* display_manager = GetDisplayManager();
367 DCHECK(new_primary_display.is_valid()); 370 DCHECK(new_primary_display.is_valid());
368 DCHECK(display_manager->IsActiveDisplay(new_primary_display)); 371 DCHECK(display_manager->IsActiveDisplay(new_primary_display));
369 372
370 if (!new_primary_display.is_valid() || 373 if (!new_primary_display.is_valid() ||
371 !display_manager->IsActiveDisplay(new_primary_display)) { 374 !display_manager->IsActiveDisplay(new_primary_display)) {
372 LOG(ERROR) << "Invalid or non-existent display is requested:" 375 LOG(ERROR) << "Invalid or non-existent display is requested:"
373 << new_primary_display.ToString(); 376 << new_primary_display.ToString();
374 return; 377 return;
375 } 378 }
376 379
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 // Update the dispay manager with new display info. 419 // Update the dispay manager with new display info.
417 std::vector<gfx::Display> displays; 420 std::vector<gfx::Display> displays;
418 displays.push_back(display_manager->GetDisplayForId(primary_display_id)); 421 displays.push_back(display_manager->GetDisplayForId(primary_display_id));
419 displays.push_back(*GetSecondaryDisplay()); 422 displays.push_back(*GetSecondaryDisplay());
420 GetDisplayManager()->set_force_bounds_changed(true); 423 GetDisplayManager()->set_force_bounds_changed(true);
421 GetDisplayManager()->OnNativeDisplaysChanged(displays); 424 GetDisplayManager()->OnNativeDisplaysChanged(displays);
422 GetDisplayManager()->set_force_bounds_changed(false); 425 GetDisplayManager()->set_force_bounds_changed(false);
423 } 426 }
424 427
425 gfx::Display* DisplayController::GetSecondaryDisplay() { 428 gfx::Display* DisplayController::GetSecondaryDisplay() {
426 internal::MultiDisplayManager* display_manager = GetDisplayManager(); 429 internal::DisplayManager* display_manager = GetDisplayManager();
427 CHECK_EQ(2U, display_manager->GetNumDisplays()); 430 CHECK_EQ(2U, display_manager->GetNumDisplays());
428 return display_manager->GetDisplayAt(0)->id() == primary_display_id ? 431 return display_manager->GetDisplayAt(0)->id() == primary_display_id ?
429 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0); 432 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0);
430 } 433 }
431 434
432 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { 435 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) {
433 NotifyDisplayConfigurationChanging(); 436 NotifyDisplayConfigurationChanging();
434 UpdateDisplayBoundsForLayout(); 437 UpdateDisplayBoundsForLayout();
435 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); 438 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel());
436 } 439 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 secondary_display->set_bounds( 548 secondary_display->set_bounds(
546 gfx::Rect(new_secondary_origin, secondary_bounds.size())); 549 gfx::Rect(new_secondary_origin, secondary_bounds.size()));
547 secondary_display->UpdateWorkAreaFromInsets(insets); 550 secondary_display->UpdateWorkAreaFromInsets(insets);
548 } 551 }
549 552
550 void DisplayController::NotifyDisplayConfigurationChanging() { 553 void DisplayController::NotifyDisplayConfigurationChanging() {
551 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); 554 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging());
552 } 555 }
553 556
554 } // namespace ash 557 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_controller.h ('k') | ash/display/display_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698