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