| 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> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 11 #include "ash/display/display_manager.h" | 11 #include "ash/display/display_manager.h" |
| 12 #include "ash/host/root_window_host_factory.h" | 12 #include "ash/host/root_window_host_factory.h" |
| 13 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
| 14 #include "ash/screen_ash.h" | 14 #include "ash/screen_ash.h" |
| 15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/wm/coordinate_conversion.h" | 16 #include "ash/wm/coordinate_conversion.h" |
| 17 #include "ash/wm/property_util.h" | 17 #include "ash/wm/property_util.h" |
| 18 #include "ash/wm/window_util.h" | 18 #include "ash/wm/window_util.h" |
| 19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 20 #include "base/json/json_value_converter.h" | 20 #include "base/json/json_value_converter.h" |
| 21 #include "base/string_piece.h" | 21 #include "base/string_piece.h" |
| 22 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
| 23 #include "base/values.h" | 23 #include "base/values.h" |
| 24 #include "third_party/skia/include/utils/SkMatrix44.h" | 24 #include "third_party/skia/include/utils/SkMatrix44.h" |
| 25 #include "ui/aura/client/activation_client.h" | |
| 26 #include "ui/aura/client/capture_client.h" | |
| 27 #include "ui/aura/client/cursor_client.h" | |
| 28 #include "ui/aura/client/focus_client.h" | |
| 29 #include "ui/aura/client/screen_position_client.h" | 25 #include "ui/aura/client/screen_position_client.h" |
| 30 #include "ui/aura/env.h" | 26 #include "ui/aura/env.h" |
| 31 #include "ui/aura/root_window.h" | 27 #include "ui/aura/root_window.h" |
| 32 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
| 33 #include "ui/aura/window_property.h" | 29 #include "ui/aura/window_property.h" |
| 34 #include "ui/aura/window_tracker.h" | |
| 35 #include "ui/compositor/compositor.h" | 30 #include "ui/compositor/compositor.h" |
| 36 #include "ui/compositor/dip_util.h" | 31 #include "ui/compositor/dip_util.h" |
| 37 #include "ui/gfx/display.h" | 32 #include "ui/gfx/display.h" |
| 38 #include "ui/gfx/screen.h" | 33 #include "ui/gfx/screen.h" |
| 39 | 34 |
| 40 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
| 41 #include "ash/display/output_configurator_animation.h" | 36 #include "ash/display/output_configurator_animation.h" |
| 42 #include "base/chromeos/chromeos_version.h" | 37 #include "base/chromeos/chromeos_version.h" |
| 43 #include "base/string_number_conversions.h" | 38 #include "base/string_number_conversions.h" |
| 44 #include "base/time.h" | 39 #include "base/time.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 ui::SetIntProperty(xwindow, | 214 ui::SetIntProperty(xwindow, |
| 220 kScaleFactorProp, | 215 kScaleFactorProp, |
| 221 kCARDINAL, | 216 kCARDINAL, |
| 222 100 * display.device_scale_factor()); | 217 100 * display.device_scale_factor()); |
| 223 #endif | 218 #endif |
| 224 RotateRootWindow(root, display, info); | 219 RotateRootWindow(root, display, info); |
| 225 } | 220 } |
| 226 | 221 |
| 227 } // namespace | 222 } // namespace |
| 228 | 223 |
| 229 namespace internal { | |
| 230 | |
| 231 // A utility class to store/restore focused/active window | |
| 232 // when the display configuration has changed. | |
| 233 class FocusActivationStore { | |
| 234 public: | |
| 235 FocusActivationStore() | |
| 236 : activation_client_(NULL), | |
| 237 capture_client_(NULL), | |
| 238 focus_client_(NULL), | |
| 239 focused_(NULL), | |
| 240 active_(NULL) { | |
| 241 } | |
| 242 | |
| 243 void Store() { | |
| 244 if (!activation_client_) { | |
| 245 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); | |
| 246 activation_client_ = aura::client::GetActivationClient(root); | |
| 247 capture_client_ = aura::client::GetCaptureClient(root); | |
| 248 focus_client_ = aura::client::GetFocusClient(root); | |
| 249 } | |
| 250 focused_ = focus_client_->GetFocusedWindow(); | |
| 251 if (focused_) | |
| 252 tracker_.Add(focused_); | |
| 253 active_ = activation_client_->GetActiveWindow(); | |
| 254 if (active_ && focused_ != active_) | |
| 255 tracker_.Add(active_); | |
| 256 | |
| 257 // Deactivate the window to close menu / bubble windows. | |
| 258 activation_client_->DeactivateWindow(active_); | |
| 259 // Release capture if any. | |
| 260 capture_client_->SetCapture(NULL); | |
| 261 // Clear the focused window if any. This is necessary because a | |
| 262 // window may be deleted when losing focus (fullscreen flash for | |
| 263 // example). If the focused window is still alive after move, it'll | |
| 264 // be re-focused below. | |
| 265 focus_client_->FocusWindow(NULL); | |
| 266 } | |
| 267 | |
| 268 void Restore() { | |
| 269 // Restore focused or active window if it's still alive. | |
| 270 if (focused_ && tracker_.Contains(focused_)) { | |
| 271 focus_client_->FocusWindow(focused_); | |
| 272 } else if (active_ && tracker_.Contains(active_)) { | |
| 273 activation_client_->ActivateWindow(active_); | |
| 274 } | |
| 275 if (focused_) | |
| 276 tracker_.Remove(focused_); | |
| 277 if (active_) | |
| 278 tracker_.Remove(active_); | |
| 279 focused_ = NULL; | |
| 280 active_ = NULL; | |
| 281 } | |
| 282 | |
| 283 private: | |
| 284 aura::client::ActivationClient* activation_client_; | |
| 285 aura::client::CaptureClient* capture_client_; | |
| 286 aura::client::FocusClient* focus_client_; | |
| 287 aura::WindowTracker tracker_; | |
| 288 aura::Window* focused_; | |
| 289 aura::Window* active_; | |
| 290 | |
| 291 DISALLOW_COPY_AND_ASSIGN(FocusActivationStore); | |
| 292 }; | |
| 293 | |
| 294 } // namespace internal | |
| 295 | |
| 296 //////////////////////////////////////////////////////////////////////////////// | 224 //////////////////////////////////////////////////////////////////////////////// |
| 297 // DisplayLayout | 225 // DisplayLayout |
| 298 | 226 |
| 299 // static | 227 // static |
| 300 DisplayLayout DisplayLayout::FromInts(int position, int offsets) { | 228 DisplayLayout DisplayLayout::FromInts(int position, int offsets) { |
| 301 return DisplayLayout(static_cast<Position>(position), offsets); | 229 return DisplayLayout(static_cast<Position>(position), offsets); |
| 302 } | 230 } |
| 303 | 231 |
| 304 DisplayLayout::DisplayLayout() | 232 DisplayLayout::DisplayLayout() |
| 305 : position(RIGHT), | 233 : position(RIGHT), |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 320 |
| 393 bool DisplayController::DisplayChangeLimiter::IsThrottled() const { | 321 bool DisplayController::DisplayChangeLimiter::IsThrottled() const { |
| 394 return base::Time::Now() < throttle_timeout_; | 322 return base::Time::Now() < throttle_timeout_; |
| 395 } | 323 } |
| 396 | 324 |
| 397 //////////////////////////////////////////////////////////////////////////////// | 325 //////////////////////////////////////////////////////////////////////////////// |
| 398 // DisplayController | 326 // DisplayController |
| 399 | 327 |
| 400 DisplayController::DisplayController() | 328 DisplayController::DisplayController() |
| 401 : desired_primary_display_id_(gfx::Display::kInvalidDisplayID), | 329 : desired_primary_display_id_(gfx::Display::kInvalidDisplayID), |
| 402 primary_root_window_for_replace_(NULL), | 330 primary_root_window_for_replace_(NULL) { |
| 403 focus_activation_store_(new internal::FocusActivationStore()) { | |
| 404 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 331 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 405 #if defined(OS_CHROMEOS) | 332 #if defined(OS_CHROMEOS) |
| 406 if (!command_line->HasSwitch(switches::kAshDisableDisplayChangeLimiter) && | 333 if (!command_line->HasSwitch(switches::kAshDisableDisplayChangeLimiter) && |
| 407 base::chromeos::IsRunningOnChromeOS()) | 334 base::chromeos::IsRunningOnChromeOS()) |
| 408 limiter_.reset(new DisplayChangeLimiter); | 335 limiter_.reset(new DisplayChangeLimiter); |
| 409 #endif | 336 #endif |
| 410 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) { | 337 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) { |
| 411 std::string value = command_line->GetSwitchValueASCII( | 338 std::string value = command_line->GetSwitchValueASCII( |
| 412 switches::kAshSecondaryDisplayLayout); | 339 switches::kAshSecondaryDisplayLayout); |
| 413 char layout; | 340 char layout; |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 break; | 893 break; |
| 967 } | 894 } |
| 968 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 895 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
| 969 secondary_display->set_bounds( | 896 secondary_display->set_bounds( |
| 970 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 897 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
| 971 secondary_display->UpdateWorkAreaFromInsets(insets); | 898 secondary_display->UpdateWorkAreaFromInsets(insets); |
| 972 } | 899 } |
| 973 | 900 |
| 974 void DisplayController::NotifyDisplayConfigurationChanging() { | 901 void DisplayController::NotifyDisplayConfigurationChanging() { |
| 975 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 902 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
| 976 focus_activation_store_->Store(); | |
| 977 } | 903 } |
| 978 | 904 |
| 979 void DisplayController::NotifyDisplayConfigurationChanged() { | 905 void DisplayController::NotifyDisplayConfigurationChanged() { |
| 980 focus_activation_store_->Restore(); | |
| 981 | |
| 982 internal::DisplayManager* display_manager = GetDisplayManager(); | 906 internal::DisplayManager* display_manager = GetDisplayManager(); |
| 983 if (display_manager->num_connected_displays() > 1) { | 907 if (display_manager->num_connected_displays() > 1) { |
| 984 DisplayIdPair pair = GetCurrentDisplayIdPair(); | 908 DisplayIdPair pair = GetCurrentDisplayIdPair(); |
| 985 bool exists = paired_layouts_.find(pair) != paired_layouts_.end(); | 909 bool exists = paired_layouts_.find(pair) != paired_layouts_.end(); |
| 986 if (exists || display_manager->IsMirrored()) { | 910 if (exists || display_manager->IsMirrored()) { |
| 987 if (!exists) | 911 if (!exists) |
| 988 paired_layouts_[pair] = default_display_layout_; | 912 paired_layouts_[pair] = default_display_layout_; |
| 989 paired_layouts_[pair].mirrored = display_manager->IsMirrored(); | 913 paired_layouts_[pair].mirrored = display_manager->IsMirrored(); |
| 990 } | 914 } |
| 991 } | 915 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1003 } | 927 } |
| 1004 | 928 |
| 1005 void DisplayController::OnFadeOutForSwapDisplayFinished() { | 929 void DisplayController::OnFadeOutForSwapDisplayFinished() { |
| 1006 #if defined(OS_CHROMEOS) | 930 #if defined(OS_CHROMEOS) |
| 1007 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); | 931 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); |
| 1008 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); | 932 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); |
| 1009 #endif | 933 #endif |
| 1010 } | 934 } |
| 1011 | 935 |
| 1012 } // namespace ash | 936 } // namespace ash |
| OLD | NEW |