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

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

Issue 10909043: Cancel drag if display configuration changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 else if (layout == 'r') 173 else if (layout == 'r')
174 default_display_layout_.position = DisplayLayout::RIGHT; 174 default_display_layout_.position = DisplayLayout::RIGHT;
175 else if (layout == 'l') 175 else if (layout == 'l')
176 default_display_layout_.position = DisplayLayout::LEFT; 176 default_display_layout_.position = DisplayLayout::LEFT;
177 default_display_layout_.offset = offset; 177 default_display_layout_.offset = offset;
178 } 178 }
179 } 179 }
180 UpdateDisplayBoundsForLayout(); 180 UpdateDisplayBoundsForLayout();
181 } 181 }
182 182
183 void DisplayController::AddObserver(Observer* observer) {
184 observers_.AddObserver(observer);
185 }
186
187 void DisplayController::RemoveObserver(Observer* observer) {
188 observers_.RemoveObserver(observer);
189 }
190
183 aura::RootWindow* DisplayController::GetPrimaryRootWindow() { 191 aura::RootWindow* DisplayController::GetPrimaryRootWindow() {
184 DCHECK(!root_windows_.empty()); 192 DCHECK(!root_windows_.empty());
185 aura::DisplayManager* display_manager = 193 aura::DisplayManager* display_manager =
186 aura::Env::GetInstance()->display_manager(); 194 aura::Env::GetInstance()->display_manager();
187 return root_windows_[display_manager->GetDisplayAt(0)->id()]; 195 return root_windows_[display_manager->GetDisplayAt(0)->id()];
188 } 196 }
189 197
190 aura::RootWindow* DisplayController::GetRootWindowForDisplayId(int64 id) { 198 aura::RootWindow* DisplayController::GetRootWindowForDisplayId(int64 id) {
191 return root_windows_[id]; 199 return root_windows_[id];
192 } 200 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 root_windows_.begin(); it != root_windows_.end(); ++it) { 234 root_windows_.begin(); it != root_windows_.end(); ++it) {
227 internal::RootWindowController* controller = 235 internal::RootWindowController* controller =
228 GetRootWindowController(it->second); 236 GetRootWindowController(it->second);
229 if (controller) 237 if (controller)
230 controllers.push_back(controller); 238 controllers.push_back(controller);
231 } 239 }
232 return controllers; 240 return controllers;
233 } 241 }
234 242
235 void DisplayController::SetDefaultDisplayLayout(const DisplayLayout& layout) { 243 void DisplayController::SetDefaultDisplayLayout(const DisplayLayout& layout) {
236 default_display_layout_ = layout; 244 if (default_display_layout_.position != layout.position ||
237 UpdateDisplayBoundsForLayout(); 245 default_display_layout_.offset != layout.offset) {
246 default_display_layout_ = layout;
247 NotifyDisplayConfigurationChanging();
248 UpdateDisplayBoundsForLayout();
249 }
238 } 250 }
239 251
240 void DisplayController::SetLayoutForDisplayName(const std::string& name, 252 void DisplayController::SetLayoutForDisplayName(const std::string& name,
241 const DisplayLayout& layout) { 253 const DisplayLayout& layout) {
242 secondary_layouts_[name] = layout; 254 DisplayLayout& display_for_name = secondary_layouts_[name];
243 UpdateDisplayBoundsForLayout(); 255 if (display_for_name.position != layout.position ||
256 display_for_name.offset != layout.offset) {
257 secondary_layouts_[name] = layout;
258 NotifyDisplayConfigurationChanging();
259 UpdateDisplayBoundsForLayout();
260 }
244 } 261 }
245 262
246 const DisplayLayout& DisplayController::GetLayoutForDisplayName( 263 const DisplayLayout& DisplayController::GetLayoutForDisplayName(
247 const std::string& name) { 264 const std::string& name) {
248 std::map<std::string, DisplayLayout>::const_iterator it = 265 std::map<std::string, DisplayLayout>::const_iterator it =
249 secondary_layouts_.find(name); 266 secondary_layouts_.find(name);
250 267
251 if (it != secondary_layouts_.end()) 268 if (it != secondary_layouts_.end())
252 return it->second; 269 return it->second;
253 return default_display_layout_; 270 return default_display_layout_;
254 } 271 }
255 272
256 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { 273 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) {
274 NotifyDisplayConfigurationChanging();
257 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); 275 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel());
258 UpdateDisplayBoundsForLayout(); 276 UpdateDisplayBoundsForLayout();
259 } 277 }
260 278
261 void DisplayController::OnDisplayAdded(const gfx::Display& display) { 279 void DisplayController::OnDisplayAdded(const gfx::Display& display) {
262 DCHECK(!root_windows_.empty()); 280 DCHECK(!root_windows_.empty());
281 NotifyDisplayConfigurationChanging();
263 aura::RootWindow* root = AddRootWindowForDisplay(display); 282 aura::RootWindow* root = AddRootWindowForDisplay(display);
264 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); 283 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root);
265 UpdateDisplayBoundsForLayout(); 284 UpdateDisplayBoundsForLayout();
266 } 285 }
267 286
268 void DisplayController::OnDisplayRemoved(const gfx::Display& display) { 287 void DisplayController::OnDisplayRemoved(const gfx::Display& display) {
269 aura::RootWindow* root = root_windows_[display.id()]; 288 aura::RootWindow* root = root_windows_[display.id()];
270 DCHECK(root); 289 DCHECK(root);
271 // Primary display should never be removed by DisplayManager. 290 // Primary display should never be removed by DisplayManager.
272 DCHECK(root != GetPrimaryRootWindow()); 291 DCHECK(root != GetPrimaryRootWindow());
292 NotifyDisplayConfigurationChanging();
273 // Display for root window will be deleted when the Primary RootWindow 293 // Display for root window will be deleted when the Primary RootWindow
274 // is deleted by the Shell. 294 // is deleted by the Shell.
275 if (root != GetPrimaryRootWindow()) { 295 if (root != GetPrimaryRootWindow()) {
276 root_windows_.erase(display.id()); 296 root_windows_.erase(display.id());
277 internal::RootWindowController* controller = 297 internal::RootWindowController* controller =
278 GetRootWindowController(root); 298 GetRootWindowController(root);
279 if (controller) { 299 if (controller) {
280 controller->MoveWindowsTo(GetPrimaryRootWindow()); 300 controller->MoveWindowsTo(GetPrimaryRootWindow());
281 delete controller; 301 delete controller;
282 } else { 302 } else {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 case DisplayLayout::LEFT: 370 case DisplayLayout::LEFT:
351 new_secondary_origin.Offset(-secondary_bounds.width(), offset); 371 new_secondary_origin.Offset(-secondary_bounds.width(), offset);
352 break; 372 break;
353 } 373 }
354 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); 374 gfx::Insets insets = secondary_display->GetWorkAreaInsets();
355 secondary_display->set_bounds( 375 secondary_display->set_bounds(
356 gfx::Rect(new_secondary_origin, secondary_bounds.size())); 376 gfx::Rect(new_secondary_origin, secondary_bounds.size()));
357 secondary_display->UpdateWorkAreaFromInsets(insets); 377 secondary_display->UpdateWorkAreaFromInsets(insets);
358 } 378 }
359 379
380 void DisplayController::NotifyDisplayConfigurationChanging() {
381 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging());
382 }
383
360 } // namespace ash 384 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698