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

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

Issue 10836046: Allow offset for secondary display position in chrome://settings/display. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use std::min/max 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') | chrome/browser/chromeos/preferences.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>
8
7 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
8 #include "ash/display/multi_display_manager.h" 10 #include "ash/display/multi_display_manager.h"
9 #include "ash/root_window_controller.h" 11 #include "ash/root_window_controller.h"
10 #include "ash/screen_ash.h" 12 #include "ash/screen_ash.h"
11 #include "ash/shell.h" 13 #include "ash/shell.h"
12 #include "ash/wm/property_util.h" 14 #include "ash/wm/property_util.h"
13 #include "ash/wm/window_util.h" 15 #include "ash/wm/window_util.h"
14 #include "base/command_line.h" 16 #include "base/command_line.h"
15 #include "ui/aura/client/screen_position_client.h" 17 #include "ui/aura/client/screen_position_client.h"
16 #include "ui/aura/env.h" 18 #include "ui/aura/env.h"
17 #include "ui/aura/root_window.h" 19 #include "ui/aura/root_window.h"
18 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
19 #include "ui/gfx/display.h" 21 #include "ui/gfx/display.h"
20 #include "ui/gfx/screen.h" 22 #include "ui/gfx/screen.h"
21 23
22 namespace ash { 24 namespace ash {
23 namespace internal { 25 namespace internal {
26 namespace {
27 // The number of pixels to overlap between the primary and secondary displays,
28 // in case that the offset value is too large.
29 const int kMinimumOverlapForInvalidOffset = 50;
30 }
24 31
25 DisplayController::DisplayController() 32 DisplayController::DisplayController()
26 : secondary_display_layout_(RIGHT) { 33 : secondary_display_layout_(RIGHT),
34 secondary_display_offset_(0) {
27 aura::Env::GetInstance()->display_manager()->AddObserver(this); 35 aura::Env::GetInstance()->display_manager()->AddObserver(this);
28 } 36 }
29 37
30 DisplayController::~DisplayController() { 38 DisplayController::~DisplayController() {
31 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); 39 aura::Env::GetInstance()->display_manager()->RemoveObserver(this);
32 // Delete all root window controllers, which deletes root window 40 // Delete all root window controllers, which deletes root window
33 // from the last so that the primary root window gets deleted last. 41 // from the last so that the primary root window gets deleted last.
34 for (std::map<int, aura::RootWindow*>::const_reverse_iterator it = 42 for (std::map<int, aura::RootWindow*>::const_reverse_iterator it =
35 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { 43 root_windows_.rbegin(); it != root_windows_.rend(); ++it) {
36 internal::RootWindowController* controller = 44 internal::RootWindowController* controller =
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 121 }
114 return controllers; 122 return controllers;
115 } 123 }
116 124
117 void DisplayController::SetSecondaryDisplayLayout( 125 void DisplayController::SetSecondaryDisplayLayout(
118 SecondaryDisplayLayout layout) { 126 SecondaryDisplayLayout layout) {
119 secondary_display_layout_ = layout; 127 secondary_display_layout_ = layout;
120 UpdateDisplayBoundsForLayout(); 128 UpdateDisplayBoundsForLayout();
121 } 129 }
122 130
131 void DisplayController::SetSecondaryDisplayOffset(int offset) {
132 secondary_display_offset_ = offset;
133 UpdateDisplayBoundsForLayout();
134 }
135
123 bool DisplayController::WarpMouseCursorIfNecessary( 136 bool DisplayController::WarpMouseCursorIfNecessary(
124 aura::RootWindow* current_root, 137 aura::RootWindow* current_root,
125 const gfx::Point& point_in_root) { 138 const gfx::Point& point_in_root) {
126 if (root_windows_.size() < 2) 139 if (root_windows_.size() < 2)
127 return false; 140 return false;
128 141
129 gfx::Rect root_bounds = current_root->bounds(); 142 gfx::Rect root_bounds = current_root->bounds();
130 int offset_x = 0; 143 int offset_x = 0;
131 int offset_y = 0; 144 int offset_y = 0;
132 if (point_in_root.x() <= root_bounds.x()) { 145 if (point_in_root.x() <= root_bounds.x()) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 return; 240 return;
228 } 241 }
229 DCHECK_EQ(2, gfx::Screen::GetNumDisplays()); 242 DCHECK_EQ(2, gfx::Screen::GetNumDisplays());
230 aura::DisplayManager* display_manager = 243 aura::DisplayManager* display_manager =
231 aura::Env::GetInstance()->display_manager(); 244 aura::Env::GetInstance()->display_manager();
232 const gfx::Rect& primary_bounds = display_manager->GetDisplayAt(0)->bounds(); 245 const gfx::Rect& primary_bounds = display_manager->GetDisplayAt(0)->bounds();
233 gfx::Display* secondary_display = display_manager->GetDisplayAt(1); 246 gfx::Display* secondary_display = display_manager->GetDisplayAt(1);
234 const gfx::Rect& secondary_bounds = secondary_display->bounds(); 247 const gfx::Rect& secondary_bounds = secondary_display->bounds();
235 gfx::Point new_secondary_origin = primary_bounds.origin(); 248 gfx::Point new_secondary_origin = primary_bounds.origin();
236 249
237 // TODO(oshima|mukai): Implement more flexible layout. 250 // TODO(oshima|mukai): Implement more flexible layout.
oshima 2012/08/06 07:38:49 remove this comment.
251
252 // Ignore the offset in case that the secondary display doesn't share edges
253 // with the primary display.
254 int offset = secondary_display_layout_;
255 if (secondary_display_layout_ == TOP || secondary_display_layout_ == BOTTOM) {
256 offset = std::min(
257 offset, primary_bounds.width() - kMinimumOverlapForInvalidOffset);
258 offset = std::max(
259 offset, -secondary_bounds.width() + kMinimumOverlapForInvalidOffset);
260 } else {
261 offset = std::min(
262 offset, primary_bounds.height() - kMinimumOverlapForInvalidOffset);
263 offset = std::max(
264 offset, -secondary_bounds.height() + kMinimumOverlapForInvalidOffset);
265 }
238 switch (secondary_display_layout_) { 266 switch (secondary_display_layout_) {
239 case TOP: 267 case TOP:
240 new_secondary_origin.Offset(0, -secondary_bounds.height()); 268 new_secondary_origin.Offset(offset, -secondary_bounds.height());
241 break; 269 break;
242 case RIGHT: 270 case RIGHT:
243 new_secondary_origin.Offset(primary_bounds.width(), 0); 271 new_secondary_origin.Offset(primary_bounds.width(), offset);
244 break; 272 break;
245 case BOTTOM: 273 case BOTTOM:
246 new_secondary_origin.Offset(0, primary_bounds.height()); 274 new_secondary_origin.Offset(offset, primary_bounds.height());
247 break; 275 break;
248 case LEFT: 276 case LEFT:
249 new_secondary_origin.Offset(-secondary_bounds.width(), 0); 277 new_secondary_origin.Offset(-secondary_bounds.width(), offset);
250 break; 278 break;
251 } 279 }
252 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); 280 gfx::Insets insets = secondary_display->GetWorkAreaInsets();
253 secondary_display->set_bounds( 281 secondary_display->set_bounds(
254 gfx::Rect(new_secondary_origin, secondary_bounds.size())); 282 gfx::Rect(new_secondary_origin, secondary_bounds.size()));
255 secondary_display->UpdateWorkAreaFromInsets(insets); 283 secondary_display->UpdateWorkAreaFromInsets(insets);
256 } 284 }
257 285
258 } // namespace internal 286 } // namespace internal
259 } // namespace ash 287 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_controller.h ('k') | chrome/browser/chromeos/preferences.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698