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

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: 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/coordinate_conversion.h" 14 #include "ash/wm/coordinate_conversion.h"
13 #include "ash/wm/property_util.h" 15 #include "ash/wm/property_util.h"
14 #include "ash/wm/window_util.h" 16 #include "ash/wm/window_util.h"
15 #include "base/command_line.h" 17 #include "base/command_line.h"
16 #include "ui/aura/client/screen_position_client.h" 18 #include "ui/aura/client/screen_position_client.h"
17 #include "ui/aura/env.h" 19 #include "ui/aura/env.h"
18 #include "ui/aura/root_window.h" 20 #include "ui/aura/root_window.h"
19 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
20 #include "ui/gfx/display.h" 22 #include "ui/gfx/display.h"
21 #include "ui/gfx/screen.h" 23 #include "ui/gfx/screen.h"
22 24
23 namespace ash { 25 namespace ash {
24 namespace internal { 26 namespace internal {
27 namespace {
28
29 // The number of pixels to overlap between the primary and secondary displays,
30 // in case that the offset value is too large.
31 const int kMinimumOverlapForInvalidOffset = 50;
32
33 }
25 34
26 DisplayController::DisplayController() 35 DisplayController::DisplayController()
27 : secondary_display_layout_(RIGHT), 36 : secondary_display_layout_(RIGHT),
37 secondary_display_offset_(0),
28 dont_warp_mouse_(false) { 38 dont_warp_mouse_(false) {
29 aura::Env::GetInstance()->display_manager()->AddObserver(this); 39 aura::Env::GetInstance()->display_manager()->AddObserver(this);
30 } 40 }
31 41
32 DisplayController::~DisplayController() { 42 DisplayController::~DisplayController() {
33 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); 43 aura::Env::GetInstance()->display_manager()->RemoveObserver(this);
34 // Delete all root window controllers, which deletes root window 44 // Delete all root window controllers, which deletes root window
35 // 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.
36 for (std::map<int, aura::RootWindow*>::const_reverse_iterator it = 46 for (std::map<int, aura::RootWindow*>::const_reverse_iterator it =
37 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { 47 root_windows_.rbegin(); it != root_windows_.rend(); ++it) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 125 }
116 return controllers; 126 return controllers;
117 } 127 }
118 128
119 void DisplayController::SetSecondaryDisplayLayout( 129 void DisplayController::SetSecondaryDisplayLayout(
120 SecondaryDisplayLayout layout) { 130 SecondaryDisplayLayout layout) {
121 secondary_display_layout_ = layout; 131 secondary_display_layout_ = layout;
122 UpdateDisplayBoundsForLayout(); 132 UpdateDisplayBoundsForLayout();
123 } 133 }
124 134
135 void DisplayController::SetSecondaryDisplayOffset(int offset) {
136 secondary_display_offset_ = offset;
137 UpdateDisplayBoundsForLayout();
138 }
139
125 bool DisplayController::WarpMouseCursorIfNecessary( 140 bool DisplayController::WarpMouseCursorIfNecessary(
126 aura::RootWindow* current_root, 141 aura::RootWindow* current_root,
127 const gfx::Point& point_in_root) { 142 const gfx::Point& point_in_root) {
128 if (root_windows_.size() < 2 || dont_warp_mouse_) 143 if (root_windows_.size() < 2 || dont_warp_mouse_)
129 return false; 144 return false;
130 145
131 // The pointer might be outside the |current_root|. Get the root window where 146 // The pointer might be outside the |current_root|. Get the root window where
132 // the pointer is currently on. 147 // the pointer is currently on.
133 std::pair<aura::RootWindow*, gfx::Point> actual_location = 148 std::pair<aura::RootWindow*, gfx::Point> actual_location =
134 wm::GetRootWindowRelativeToWindow(current_root, point_in_root); 149 wm::GetRootWindowRelativeToWindow(current_root, point_in_root);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 251 }
237 DCHECK_EQ(2, gfx::Screen::GetNumDisplays()); 252 DCHECK_EQ(2, gfx::Screen::GetNumDisplays());
238 aura::DisplayManager* display_manager = 253 aura::DisplayManager* display_manager =
239 aura::Env::GetInstance()->display_manager(); 254 aura::Env::GetInstance()->display_manager();
240 const gfx::Rect& primary_bounds = display_manager->GetDisplayAt(0)->bounds(); 255 const gfx::Rect& primary_bounds = display_manager->GetDisplayAt(0)->bounds();
241 gfx::Display* secondary_display = display_manager->GetDisplayAt(1); 256 gfx::Display* secondary_display = display_manager->GetDisplayAt(1);
242 const gfx::Rect& secondary_bounds = secondary_display->bounds(); 257 const gfx::Rect& secondary_bounds = secondary_display->bounds();
243 gfx::Point new_secondary_origin = primary_bounds.origin(); 258 gfx::Point new_secondary_origin = primary_bounds.origin();
244 259
245 // TODO(oshima|mukai): Implement more flexible layout. 260 // TODO(oshima|mukai): Implement more flexible layout.
261
262 // Ignore the offset in case the secondary display doesn't share edges with
263 // the primary display.
264 int offset = secondary_display_offset_;
265 if (secondary_display_layout_ == TOP || secondary_display_layout_ == BOTTOM) {
266 offset = std::min(
267 offset, primary_bounds.width() - kMinimumOverlapForInvalidOffset);
268 offset = std::max(
269 offset, -secondary_bounds.width() + kMinimumOverlapForInvalidOffset);
270 } else {
271 offset = std::min(
272 offset, primary_bounds.height() - kMinimumOverlapForInvalidOffset);
273 offset = std::max(
274 offset, -secondary_bounds.height() + kMinimumOverlapForInvalidOffset);
275 }
246 switch (secondary_display_layout_) { 276 switch (secondary_display_layout_) {
247 case TOP: 277 case TOP:
248 new_secondary_origin.Offset(0, -secondary_bounds.height()); 278 new_secondary_origin.Offset(offset, -secondary_bounds.height());
249 break; 279 break;
250 case RIGHT: 280 case RIGHT:
251 new_secondary_origin.Offset(primary_bounds.width(), 0); 281 new_secondary_origin.Offset(primary_bounds.width(), offset);
252 break; 282 break;
253 case BOTTOM: 283 case BOTTOM:
254 new_secondary_origin.Offset(0, primary_bounds.height()); 284 new_secondary_origin.Offset(offset, primary_bounds.height());
255 break; 285 break;
256 case LEFT: 286 case LEFT:
257 new_secondary_origin.Offset(-secondary_bounds.width(), 0); 287 new_secondary_origin.Offset(-secondary_bounds.width(), offset);
258 break; 288 break;
259 } 289 }
260 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); 290 gfx::Insets insets = secondary_display->GetWorkAreaInsets();
261 secondary_display->set_bounds( 291 secondary_display->set_bounds(
262 gfx::Rect(new_secondary_origin, secondary_bounds.size())); 292 gfx::Rect(new_secondary_origin, secondary_bounds.size()));
263 secondary_display->UpdateWorkAreaFromInsets(insets); 293 secondary_display->UpdateWorkAreaFromInsets(insets);
264 } 294 }
265 295
266 } // namespace internal 296 } // namespace internal
267 } // namespace ash 297 } // 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