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

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

Issue 10826198: Use persistent ID/names for displays. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: kInvalidID -> kInvalidDisplayID since Mac #define "kInvalidID"... Created 8 years, 4 months 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/multi_display_manager.h » ('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/multi_display_manager.h"
(...skipping 25 matching lines...) Expand all
36 : secondary_display_layout_(RIGHT), 36 : secondary_display_layout_(RIGHT),
37 secondary_display_offset_(0), 37 secondary_display_offset_(0),
38 dont_warp_mouse_(false) { 38 dont_warp_mouse_(false) {
39 aura::Env::GetInstance()->display_manager()->AddObserver(this); 39 aura::Env::GetInstance()->display_manager()->AddObserver(this);
40 } 40 }
41 41
42 DisplayController::~DisplayController() { 42 DisplayController::~DisplayController() {
43 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); 43 aura::Env::GetInstance()->display_manager()->RemoveObserver(this);
44 // Delete all root window controllers, which deletes root window 44 // Delete all root window controllers, which deletes root window
45 // from the last so that the primary root window gets deleted last. 45 // from the last so that the primary root window gets deleted last.
46 for (std::map<int, aura::RootWindow*>::const_reverse_iterator it = 46 for (std::map<int64, aura::RootWindow*>::const_reverse_iterator it =
47 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { 47 root_windows_.rbegin(); it != root_windows_.rend(); ++it) {
48 internal::RootWindowController* controller = 48 internal::RootWindowController* controller =
49 GetRootWindowController(it->second); 49 GetRootWindowController(it->second);
50 // RootWindow may not have RootWindowController in non 50 // RootWindow may not have RootWindowController in non
51 // extended desktop mode. 51 // extended desktop mode.
52 if (controller) 52 if (controller)
53 delete controller; 53 delete controller;
54 else 54 else
55 delete it->second; 55 delete it->second;
56 } 56 }
57 } 57 }
58 58
59 void DisplayController::InitPrimaryDisplay() { 59 void DisplayController::InitPrimaryDisplay() {
60 aura::DisplayManager* display_manager = 60 aura::DisplayManager* display_manager =
61 aura::Env::GetInstance()->display_manager(); 61 aura::Env::GetInstance()->display_manager();
62 const gfx::Display* display = display_manager->GetDisplayAt(0); 62 const gfx::Display* display = display_manager->GetDisplayAt(0);
63 DCHECK_EQ(0, display->id()); 63 aura::RootWindow* root = AddRootWindowForDisplay(*display, true);
64 aura::RootWindow* root = AddRootWindowForDisplay(*display);
65 root->SetHostBounds(display->bounds_in_pixel()); 64 root->SetHostBounds(display->bounds_in_pixel());
66 } 65 }
67 66
68 void DisplayController::InitSecondaryDisplays() { 67 void DisplayController::InitSecondaryDisplays() {
69 aura::DisplayManager* display_manager = 68 aura::DisplayManager* display_manager =
70 aura::Env::GetInstance()->display_manager(); 69 aura::Env::GetInstance()->display_manager();
71 for (size_t i = 1; i < display_manager->GetNumDisplays(); ++i) { 70 for (size_t i = 1; i < display_manager->GetNumDisplays(); ++i) {
72 const gfx::Display* display = display_manager->GetDisplayAt(i); 71 const gfx::Display* display = display_manager->GetDisplayAt(i);
73 aura::RootWindow* root = AddRootWindowForDisplay(*display); 72 aura::RootWindow* root = AddRootWindowForDisplay(*display, false);
74 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); 73 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root);
75 } 74 }
76 UpdateDisplayBoundsForLayout(); 75 UpdateDisplayBoundsForLayout();
77 } 76 }
78 77
79 aura::RootWindow* DisplayController::GetPrimaryRootWindow() { 78 aura::RootWindow* DisplayController::GetPrimaryRootWindow() {
80 DCHECK(!root_windows_.empty()); 79 DCHECK(!root_windows_.empty());
81 return root_windows_[0]; 80 aura::DisplayManager* display_manager =
81 aura::Env::GetInstance()->display_manager();
82 return root_windows_[display_manager->GetDisplayAt(0)->id()];
82 } 83 }
83 84
84 aura::RootWindow* DisplayController::GetRootWindowForDisplayId(int id) { 85 aura::RootWindow* DisplayController::GetRootWindowForDisplayId(int id) {
85 return root_windows_[id]; 86 return root_windows_[id];
86 } 87 }
87 88
88 void DisplayController::CloseChildWindows() { 89 void DisplayController::CloseChildWindows() {
89 for (std::map<int, aura::RootWindow*>::const_iterator it = 90 for (std::map<int64, aura::RootWindow*>::const_iterator it =
90 root_windows_.begin(); it != root_windows_.end(); ++it) { 91 root_windows_.begin(); it != root_windows_.end(); ++it) {
91 aura::RootWindow* root_window = it->second; 92 aura::RootWindow* root_window = it->second;
92 internal::RootWindowController* controller = 93 internal::RootWindowController* controller =
93 GetRootWindowController(root_window); 94 GetRootWindowController(root_window);
94 if (controller) { 95 if (controller) {
95 controller->CloseChildWindows(); 96 controller->CloseChildWindows();
96 } else { 97 } else {
97 while (!root_window->children().empty()) { 98 while (!root_window->children().empty()) {
98 aura::Window* child = root_window->children()[0]; 99 aura::Window* child = root_window->children()[0];
99 delete child; 100 delete child;
100 } 101 }
101 } 102 }
102 } 103 }
103 } 104 }
104 105
105 std::vector<aura::RootWindow*> DisplayController::GetAllRootWindows() { 106 std::vector<aura::RootWindow*> DisplayController::GetAllRootWindows() {
106 std::vector<aura::RootWindow*> windows; 107 std::vector<aura::RootWindow*> windows;
107 for (std::map<int, aura::RootWindow*>::const_iterator it = 108 for (std::map<int64, aura::RootWindow*>::const_iterator it =
108 root_windows_.begin(); it != root_windows_.end(); ++it) { 109 root_windows_.begin(); it != root_windows_.end(); ++it) {
109 DCHECK(it->second); 110 DCHECK(it->second);
110 if (GetRootWindowController(it->second)) 111 if (GetRootWindowController(it->second))
111 windows.push_back(it->second); 112 windows.push_back(it->second);
112 } 113 }
113 return windows; 114 return windows;
114 } 115 }
115 116
116 std::vector<internal::RootWindowController*> 117 std::vector<internal::RootWindowController*>
117 DisplayController::GetAllRootWindowControllers() { 118 DisplayController::GetAllRootWindowControllers() {
118 std::vector<internal::RootWindowController*> controllers; 119 std::vector<internal::RootWindowController*> controllers;
119 for (std::map<int, aura::RootWindow*>::const_iterator it = 120 for (std::map<int64, aura::RootWindow*>::const_iterator it =
120 root_windows_.begin(); it != root_windows_.end(); ++it) { 121 root_windows_.begin(); it != root_windows_.end(); ++it) {
121 internal::RootWindowController* controller = 122 internal::RootWindowController* controller =
122 GetRootWindowController(it->second); 123 GetRootWindowController(it->second);
123 if (controller) 124 if (controller)
124 controllers.push_back(controller); 125 controllers.push_back(controller);
125 } 126 }
126 return controllers; 127 return controllers;
127 } 128 }
128 129
129 void DisplayController::SetSecondaryDisplayLayout( 130 void DisplayController::SetSecondaryDisplayLayout(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return false; 184 return false;
184 } 185 }
185 186
186 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { 187 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) {
187 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); 188 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel());
188 UpdateDisplayBoundsForLayout(); 189 UpdateDisplayBoundsForLayout();
189 } 190 }
190 191
191 void DisplayController::OnDisplayAdded(const gfx::Display& display) { 192 void DisplayController::OnDisplayAdded(const gfx::Display& display) {
192 if (root_windows_.empty()) { 193 if (root_windows_.empty()) {
193 DCHECK_EQ(0, display.id());
194 root_windows_[display.id()] = Shell::GetPrimaryRootWindow(); 194 root_windows_[display.id()] = Shell::GetPrimaryRootWindow();
195 Shell::GetPrimaryRootWindow()->SetHostBounds(display.bounds_in_pixel()); 195 Shell::GetPrimaryRootWindow()->SetHostBounds(display.bounds_in_pixel());
196 return; 196 return;
197 } 197 }
198 aura::RootWindow* root = AddRootWindowForDisplay(display); 198 aura::RootWindow* root = AddRootWindowForDisplay(display, false);
199 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); 199 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root);
200 UpdateDisplayBoundsForLayout(); 200 UpdateDisplayBoundsForLayout();
201 } 201 }
202 202
203 void DisplayController::OnDisplayRemoved(const gfx::Display& display) { 203 void DisplayController::OnDisplayRemoved(const gfx::Display& display) {
204 aura::RootWindow* root = root_windows_[display.id()]; 204 aura::RootWindow* root = root_windows_[display.id()];
205 DCHECK(root); 205 DCHECK(root);
206 // Primary display should never be removed by DisplayManager. 206 // Primary display should never be removed by DisplayManager.
207 DCHECK(root != Shell::GetPrimaryRootWindow()); 207 DCHECK(root != Shell::GetPrimaryRootWindow());
208 // Display for root window will be deleted when the Primary RootWindow 208 // Display for root window will be deleted when the Primary RootWindow
(...skipping 13 matching lines...) Expand all
222 222
223 // static 223 // static
224 bool DisplayController::IsExtendedDesktopEnabled(){ 224 bool DisplayController::IsExtendedDesktopEnabled(){
225 static bool extended_desktop_disabled = 225 static bool extended_desktop_disabled =
226 CommandLine::ForCurrentProcess()->HasSwitch( 226 CommandLine::ForCurrentProcess()->HasSwitch(
227 switches::kAshExtendedDesktopDisabled); 227 switches::kAshExtendedDesktopDisabled);
228 return !extended_desktop_disabled; 228 return !extended_desktop_disabled;
229 } 229 }
230 230
231 aura::RootWindow* DisplayController::AddRootWindowForDisplay( 231 aura::RootWindow* DisplayController::AddRootWindowForDisplay(
232 const gfx::Display& display) { 232 const gfx::Display& display, bool is_primary) {
233 aura::RootWindow* root = aura::Env::GetInstance()->display_manager()-> 233 aura::RootWindow* root = aura::Env::GetInstance()->display_manager()->
234 CreateRootWindowForDisplay(display); 234 CreateRootWindowForDisplay(display);
235 root_windows_[display.id()] = root; 235 root_windows_[display.id()] = root;
236 // Confine the cursor within the window if 236 // Confine the cursor within the window if
237 // 1) Extended desktop is enabled or 237 // 1) Extended desktop is enabled or
238 // 2) the display is primary display and the host window 238 // 2) the display is primary display and the host window
239 // is set to be fullscreen (this is old behavior). 239 // is set to be fullscreen (this is old behavior).
240 if (IsExtendedDesktopEnabled() || 240 if (IsExtendedDesktopEnabled() ||
241 (aura::DisplayManager::use_fullscreen_host_window() && 241 (aura::DisplayManager::use_fullscreen_host_window() && is_primary)) {
242 display.id() == 0)) {
243 root->ConfineCursorToWindow(); 242 root->ConfineCursorToWindow();
244 } 243 }
245 return root; 244 return root;
246 } 245 }
247 246
248 void DisplayController::UpdateDisplayBoundsForLayout() { 247 void DisplayController::UpdateDisplayBoundsForLayout() {
249 if (!IsExtendedDesktopEnabled() || gfx::Screen::GetNumDisplays() <= 1) { 248 if (!IsExtendedDesktopEnabled() || gfx::Screen::GetNumDisplays() <= 1) {
250 return; 249 return;
251 } 250 }
252 DCHECK_EQ(2, gfx::Screen::GetNumDisplays()); 251 DCHECK_EQ(2, gfx::Screen::GetNumDisplays());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 break; 287 break;
289 } 288 }
290 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); 289 gfx::Insets insets = secondary_display->GetWorkAreaInsets();
291 secondary_display->set_bounds( 290 secondary_display->set_bounds(
292 gfx::Rect(new_secondary_origin, secondary_bounds.size())); 291 gfx::Rect(new_secondary_origin, secondary_bounds.size()));
293 secondary_display->UpdateWorkAreaFromInsets(insets); 292 secondary_display->UpdateWorkAreaFromInsets(insets);
294 } 293 }
295 294
296 } // namespace internal 295 } // namespace internal
297 } // namespace ash 296 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_controller.h ('k') | ash/display/multi_display_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698