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 "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/display/multi_display_manager.h" | 8 #include "ash/display/multi_display_manager.h" |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ash/wm/property_util.h" | 12 #include "ash/wm/property_util.h" |
13 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "ui/aura/client/screen_position_client.h" | 15 #include "ui/aura/client/screen_position_client.h" |
16 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
17 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
18 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
19 #include "ui/gfx/display.h" | 19 #include "ui/gfx/display.h" |
20 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
21 | 21 |
22 namespace ash { | 22 namespace ash { |
23 namespace internal { | 23 namespace internal { |
24 | 24 |
25 DisplayController::DisplayController() | 25 DisplayController::DisplayController() |
26 : secondary_display_layout_(RIGHT) { | 26 : secondary_display_layout_(RIGHT), |
27 secondary_display_offset_(0) { | |
27 aura::Env::GetInstance()->display_manager()->AddObserver(this); | 28 aura::Env::GetInstance()->display_manager()->AddObserver(this); |
28 } | 29 } |
29 | 30 |
30 DisplayController::~DisplayController() { | 31 DisplayController::~DisplayController() { |
31 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); | 32 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); |
32 // Delete all root window controllers, which deletes root window | 33 // Delete all root window controllers, which deletes root window |
33 // from the last so that the primary root window gets deleted last. | 34 // from the last so that the primary root window gets deleted last. |
34 for (std::map<int, aura::RootWindow*>::const_reverse_iterator it = | 35 for (std::map<int, aura::RootWindow*>::const_reverse_iterator it = |
35 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { | 36 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { |
36 internal::RootWindowController* controller = | 37 internal::RootWindowController* controller = |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 } | 114 } |
114 return controllers; | 115 return controllers; |
115 } | 116 } |
116 | 117 |
117 void DisplayController::SetSecondaryDisplayLayout( | 118 void DisplayController::SetSecondaryDisplayLayout( |
118 SecondaryDisplayLayout layout) { | 119 SecondaryDisplayLayout layout) { |
119 secondary_display_layout_ = layout; | 120 secondary_display_layout_ = layout; |
120 UpdateDisplayBoundsForLayout(); | 121 UpdateDisplayBoundsForLayout(); |
121 } | 122 } |
122 | 123 |
124 void DisplayController::SetSecondaryDisplayOffset(int offset) { | |
125 secondary_display_offset_ = offset; | |
126 UpdateDisplayBoundsForLayout(); | |
127 } | |
128 | |
123 bool DisplayController::WarpMouseCursorIfNecessary( | 129 bool DisplayController::WarpMouseCursorIfNecessary( |
124 aura::RootWindow* current_root, | 130 aura::RootWindow* current_root, |
125 const gfx::Point& point_in_root) { | 131 const gfx::Point& point_in_root) { |
126 if (root_windows_.size() < 2) | 132 if (root_windows_.size() < 2) |
127 return false; | 133 return false; |
128 | 134 |
129 gfx::Rect root_bounds = current_root->bounds(); | 135 gfx::Rect root_bounds = current_root->bounds(); |
130 int offset_x = 0; | 136 int offset_x = 0; |
131 int offset_y = 0; | 137 int offset_y = 0; |
132 if (point_in_root.x() <= root_bounds.x()) { | 138 if (point_in_root.x() <= root_bounds.x()) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 } | 234 } |
229 DCHECK_EQ(2, gfx::Screen::GetNumDisplays()); | 235 DCHECK_EQ(2, gfx::Screen::GetNumDisplays()); |
230 aura::DisplayManager* display_manager = | 236 aura::DisplayManager* display_manager = |
231 aura::Env::GetInstance()->display_manager(); | 237 aura::Env::GetInstance()->display_manager(); |
232 const gfx::Rect& primary_bounds = display_manager->GetDisplayAt(0)->bounds(); | 238 const gfx::Rect& primary_bounds = display_manager->GetDisplayAt(0)->bounds(); |
233 gfx::Display* secondary_display = display_manager->GetDisplayAt(1); | 239 gfx::Display* secondary_display = display_manager->GetDisplayAt(1); |
234 const gfx::Rect& secondary_bounds = secondary_display->bounds(); | 240 const gfx::Rect& secondary_bounds = secondary_display->bounds(); |
235 gfx::Point new_secondary_origin = primary_bounds.origin(); | 241 gfx::Point new_secondary_origin = primary_bounds.origin(); |
236 | 242 |
237 // TODO(oshima|mukai): Implement more flexible layout. | 243 // TODO(oshima|mukai): Implement more flexible layout. |
244 | |
245 // Ignore the offset in case that the secondary display doesn't share edges | |
246 // with the primary display. | |
247 int offset = secondary_display_layout_; | |
248 if (secondary_display_layout_ == TOP || secondary_display_layout_ == BOTTOM) { | |
249 if (offset > primary_bounds.width() || offset < -secondary_bounds.width()) | |
250 offset = 0; | |
oshima_google
2012/08/06 05:44:37
I think it's better to adjust the offset (just kee
Jun Mukai
2012/08/06 06:58:35
Done.
| |
251 } else { | |
252 if (offset > primary_bounds.height() || offset < -secondary_bounds.height()) | |
253 offset = 0; | |
254 } | |
238 switch (secondary_display_layout_) { | 255 switch (secondary_display_layout_) { |
239 case TOP: | 256 case TOP: |
240 new_secondary_origin.Offset(0, -secondary_bounds.height()); | 257 new_secondary_origin.Offset(offset, -secondary_bounds.height()); |
241 break; | 258 break; |
242 case RIGHT: | 259 case RIGHT: |
243 new_secondary_origin.Offset(primary_bounds.width(), 0); | 260 new_secondary_origin.Offset(primary_bounds.width(), offset); |
244 break; | 261 break; |
245 case BOTTOM: | 262 case BOTTOM: |
246 new_secondary_origin.Offset(0, primary_bounds.height()); | 263 new_secondary_origin.Offset(offset, primary_bounds.height()); |
247 break; | 264 break; |
248 case LEFT: | 265 case LEFT: |
249 new_secondary_origin.Offset(-secondary_bounds.width(), 0); | 266 new_secondary_origin.Offset(-secondary_bounds.width(), offset); |
250 break; | 267 break; |
251 } | 268 } |
252 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 269 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
253 secondary_display->set_bounds( | 270 secondary_display->set_bounds( |
254 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 271 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
255 secondary_display->UpdateWorkAreaFromInsets(insets); | 272 secondary_display->UpdateWorkAreaFromInsets(insets); |
256 } | 273 } |
257 | 274 |
258 } // namespace internal | 275 } // namespace internal |
259 } // namespace ash | 276 } // namespace ash |
OLD | NEW |