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 "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 Loading... |
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 Loading... |
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 |
185 void DisplayController::InitPrimaryDisplay() { | 184 void DisplayController::InitPrimaryDisplay() { |
186 const gfx::Display* primary_candidate = GetDisplayManager()->GetDisplayAt(0); | 185 const gfx::Display* primary_candidate = GetDisplayManager()->GetDisplayAt(0); |
187 #if defined(OS_CHROMEOS) | 186 #if defined(OS_CHROMEOS) |
188 if (base::chromeos::IsRunningOnChromeOS()) { | 187 if (base::chromeos::IsRunningOnChromeOS()) { |
189 internal::MultiDisplayManager* display_manager = GetDisplayManager(); | 188 internal::DisplayManager* display_manager = GetDisplayManager(); |
190 // On ChromeOS device, root windows are stacked vertically, and | 189 // On ChromeOS device, root windows are stacked vertically, and |
191 // default primary is the one on top. | 190 // default primary is the one on top. |
192 int count = display_manager->GetNumDisplays(); | 191 int count = display_manager->GetNumDisplays(); |
193 int y = primary_candidate->bounds_in_pixel().y(); | 192 int y = primary_candidate->bounds_in_pixel().y(); |
194 for (int i = 1; i < count; ++i) { | 193 for (int i = 1; i < count; ++i) { |
195 const gfx::Display* display = display_manager->GetDisplayAt(i); | 194 const gfx::Display* display = display_manager->GetDisplayAt(i); |
196 if (display_manager->IsInternalDisplayId(display->id())) { | 195 if (display_manager->IsInternalDisplayId(display->id())) { |
197 primary_candidate = display; | 196 primary_candidate = display; |
198 break; | 197 break; |
199 } else if (display->bounds_in_pixel().y() < y) { | 198 } else if (display->bounds_in_pixel().y() < y) { |
200 primary_candidate = display; | 199 primary_candidate = display; |
201 y = display->bounds_in_pixel().y(); | 200 y = display->bounds_in_pixel().y(); |
202 } | 201 } |
203 } | 202 } |
204 } | 203 } |
205 #endif | 204 #endif |
206 primary_display_id = primary_candidate->id(); | 205 primary_display_id = primary_candidate->id(); |
207 aura::RootWindow* root = AddRootWindowForDisplay(*primary_candidate); | 206 aura::RootWindow* root = AddRootWindowForDisplay(*primary_candidate); |
208 root->SetHostBounds(primary_candidate->bounds_in_pixel()); | 207 root->SetHostBounds(primary_candidate->bounds_in_pixel()); |
209 UpdateDisplayBoundsForLayout(); | 208 UpdateDisplayBoundsForLayout(); |
210 } | 209 } |
211 | 210 |
212 void DisplayController::InitSecondaryDisplays() { | 211 void DisplayController::InitSecondaryDisplays() { |
213 internal::MultiDisplayManager* display_manager = GetDisplayManager(); | 212 internal::DisplayManager* display_manager = GetDisplayManager(); |
214 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 213 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
215 const gfx::Display* display = display_manager->GetDisplayAt(i); | 214 const gfx::Display* display = display_manager->GetDisplayAt(i); |
216 if (primary_display_id != display->id()) { | 215 if (primary_display_id != display->id()) { |
217 aura::RootWindow* root = AddRootWindowForDisplay(*display); | 216 aura::RootWindow* root = AddRootWindowForDisplay(*display); |
218 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); | 217 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); |
219 } | 218 } |
220 } | 219 } |
221 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 220 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
222 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) { | 221 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) { |
223 std::string value = command_line->GetSwitchValueASCII( | 222 std::string value = command_line->GetSwitchValueASCII( |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 // On release build, just fallback to default instead of blowing up. | 342 // On release build, just fallback to default instead of blowing up. |
344 return default_display_layout_; | 343 return default_display_layout_; |
345 } | 344 } |
346 | 345 |
347 void DisplayController::SetPrimaryDisplayId(int64 id) { | 346 void DisplayController::SetPrimaryDisplayId(int64 id) { |
348 desired_primary_display_id_ = id; | 347 desired_primary_display_id_ = id; |
349 | 348 |
350 if (desired_primary_display_id_ == primary_display_id) | 349 if (desired_primary_display_id_ == primary_display_id) |
351 return; | 350 return; |
352 | 351 |
353 aura::DisplayManager* display_manager = | 352 internal::DisplayManager* display_manager = GetDisplayManager(); |
354 aura::Env::GetInstance()->display_manager(); | |
355 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 353 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
356 gfx::Display* display = display_manager->GetDisplayAt(i); | 354 gfx::Display* display = display_manager->GetDisplayAt(i); |
357 if (display->id() == id) { | 355 if (display->id() == id) { |
358 SetPrimaryDisplay(*display); | 356 SetPrimaryDisplay(*display); |
359 break; | 357 break; |
360 } | 358 } |
361 } | 359 } |
362 } | 360 } |
363 | 361 |
364 void DisplayController::SetPrimaryDisplay( | 362 void DisplayController::SetPrimaryDisplay( |
365 const gfx::Display& new_primary_display) { | 363 const gfx::Display& new_primary_display) { |
366 internal::MultiDisplayManager* display_manager = GetDisplayManager(); | 364 internal::DisplayManager* display_manager = GetDisplayManager(); |
367 DCHECK(new_primary_display.is_valid()); | 365 DCHECK(new_primary_display.is_valid()); |
368 DCHECK(display_manager->IsActiveDisplay(new_primary_display)); | 366 DCHECK(display_manager->IsActiveDisplay(new_primary_display)); |
369 | 367 |
370 if (!new_primary_display.is_valid() || | 368 if (!new_primary_display.is_valid() || |
371 !display_manager->IsActiveDisplay(new_primary_display)) { | 369 !display_manager->IsActiveDisplay(new_primary_display)) { |
372 LOG(ERROR) << "Invalid or non-existent display is requested:" | 370 LOG(ERROR) << "Invalid or non-existent display is requested:" |
373 << new_primary_display.ToString(); | 371 << new_primary_display.ToString(); |
374 return; | 372 return; |
375 } | 373 } |
376 | 374 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 // Update the dispay manager with new display info. | 414 // Update the dispay manager with new display info. |
417 std::vector<gfx::Display> displays; | 415 std::vector<gfx::Display> displays; |
418 displays.push_back(display_manager->GetDisplayForId(primary_display_id)); | 416 displays.push_back(display_manager->GetDisplayForId(primary_display_id)); |
419 displays.push_back(*GetSecondaryDisplay()); | 417 displays.push_back(*GetSecondaryDisplay()); |
420 GetDisplayManager()->set_force_bounds_changed(true); | 418 GetDisplayManager()->set_force_bounds_changed(true); |
421 GetDisplayManager()->OnNativeDisplaysChanged(displays); | 419 GetDisplayManager()->OnNativeDisplaysChanged(displays); |
422 GetDisplayManager()->set_force_bounds_changed(false); | 420 GetDisplayManager()->set_force_bounds_changed(false); |
423 } | 421 } |
424 | 422 |
425 gfx::Display* DisplayController::GetSecondaryDisplay() { | 423 gfx::Display* DisplayController::GetSecondaryDisplay() { |
426 internal::MultiDisplayManager* display_manager = GetDisplayManager(); | 424 internal::DisplayManager* display_manager = GetDisplayManager(); |
427 CHECK_EQ(2U, display_manager->GetNumDisplays()); | 425 CHECK_EQ(2U, display_manager->GetNumDisplays()); |
428 return display_manager->GetDisplayAt(0)->id() == primary_display_id ? | 426 return display_manager->GetDisplayAt(0)->id() == primary_display_id ? |
429 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0); | 427 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0); |
430 } | 428 } |
431 | 429 |
432 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { | 430 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { |
433 NotifyDisplayConfigurationChanging(); | 431 NotifyDisplayConfigurationChanging(); |
434 UpdateDisplayBoundsForLayout(); | 432 UpdateDisplayBoundsForLayout(); |
435 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); | 433 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); |
436 } | 434 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 secondary_display->set_bounds( | 543 secondary_display->set_bounds( |
546 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 544 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
547 secondary_display->UpdateWorkAreaFromInsets(insets); | 545 secondary_display->UpdateWorkAreaFromInsets(insets); |
548 } | 546 } |
549 | 547 |
550 void DisplayController::NotifyDisplayConfigurationChanging() { | 548 void DisplayController::NotifyDisplayConfigurationChanging() { |
551 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 549 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
552 } | 550 } |
553 | 551 |
554 } // namespace ash | 552 } // namespace ash |
OLD | NEW |