lock_layout_manager.cc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/wm/lock_layout_manager.h"
  5. #include "ash/keyboard/ui/keyboard_ui_controller.h"
  6. #include "ash/wm/lock_window_state.h"
  7. #include "ash/wm/window_state.h"
  8. #include "ash/wm/wm_event.h"
  9. #include "ui/aura/env.h"
  10. #include "ui/events/event.h"
  11. #include "ui/events/gestures/gesture_recognizer.h"
  12. namespace ash {
  13. LockLayoutManager::LockLayoutManager(aura::Window* window, Shelf* shelf)
  14. : WmDefaultLayoutManager(),
  15. window_(window),
  16. root_window_(window->GetRootWindow()) {
  17. root_window_->AddObserver(this);
  18. keyboard::KeyboardUIController::Get()->AddObserver(this);
  19. shelf_observation_.Observe(shelf);
  20. }
  21. LockLayoutManager::~LockLayoutManager() {
  22. keyboard::KeyboardUIController::Get()->RemoveObserver(this);
  23. if (root_window_)
  24. root_window_->RemoveObserver(this);
  25. for (aura::Window* child : window_->children())
  26. child->RemoveObserver(this);
  27. }
  28. void LockLayoutManager::OnWindowResized() {
  29. const WMEvent event(WM_EVENT_WORKAREA_BOUNDS_CHANGED);
  30. AdjustWindowsForWorkAreaChange(&event);
  31. }
  32. void LockLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
  33. child->AddObserver(this);
  34. // LockWindowState replaces default WindowState of a child.
  35. WindowState* window_state = LockWindowState::SetLockWindowState(child);
  36. WMEvent event(WM_EVENT_ADDED_TO_WORKSPACE);
  37. window_state->OnWMEvent(&event);
  38. aura::Env::GetInstance()->gesture_recognizer()->CancelActiveTouchesExcept(
  39. nullptr);
  40. // Disable virtual keyboard overscroll because it interferes with scrolling
  41. // login/lock content. See crbug.com/363635.
  42. keyboard::KeyboardConfig config =
  43. keyboard::KeyboardUIController::Get()->keyboard_config();
  44. config.overscroll_behavior = keyboard::KeyboardOverscrollBehavior::kDisabled;
  45. keyboard::KeyboardUIController::Get()->UpdateKeyboardConfig(config);
  46. }
  47. void LockLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) {
  48. child->RemoveObserver(this);
  49. }
  50. void LockLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) {
  51. keyboard::KeyboardConfig config =
  52. keyboard::KeyboardUIController::Get()->keyboard_config();
  53. config.overscroll_behavior = keyboard::KeyboardOverscrollBehavior::kDefault;
  54. keyboard::KeyboardUIController::Get()->UpdateKeyboardConfig(config);
  55. }
  56. void LockLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child,
  57. bool visible) {}
  58. void LockLayoutManager::SetChildBounds(aura::Window* child,
  59. const gfx::Rect& requested_bounds) {
  60. WindowState* window_state = WindowState::Get(child);
  61. SetBoundsWMEvent event(requested_bounds);
  62. window_state->OnWMEvent(&event);
  63. }
  64. void LockLayoutManager::OnWindowDestroying(aura::Window* window) {
  65. window->RemoveObserver(this);
  66. if (root_window_ == window)
  67. root_window_ = nullptr;
  68. }
  69. void LockLayoutManager::OnWindowBoundsChanged(aura::Window* window,
  70. const gfx::Rect& old_bounds,
  71. const gfx::Rect& new_bounds,
  72. ui::PropertyChangeReason reason) {
  73. if (root_window_ == window) {
  74. const DisplayMetricsChangedWMEvent wm_event(
  75. display::DisplayObserver::DISPLAY_METRIC_BOUNDS);
  76. AdjustWindowsForWorkAreaChange(&wm_event);
  77. }
  78. }
  79. void LockLayoutManager::WillChangeVisibilityState(
  80. ShelfVisibilityState visibility) {
  81. // This will be called when shelf work area changes.
  82. // * LockLayoutManager windows depend on changes to the accessibility panel
  83. // height.
  84. // * LockActionHandlerLayoutManager windows bounds depend on the work area
  85. // bound defined by the shelf layout (see
  86. // screen_util::GetDisplayWorkAreaBoundsInParentForLockScreen).
  87. // In short, when shelf bounds change, the windows in this layout manager
  88. // should be updated, too.
  89. const WMEvent event(WM_EVENT_WORKAREA_BOUNDS_CHANGED);
  90. AdjustWindowsForWorkAreaChange(&event);
  91. }
  92. void LockLayoutManager::OnKeyboardOccludedBoundsChanged(
  93. const gfx::Rect& new_bounds_in_screen) {
  94. OnWindowResized();
  95. }
  96. void LockLayoutManager::AdjustWindowsForWorkAreaChange(const WMEvent* event) {
  97. DCHECK(event->type() == WM_EVENT_DISPLAY_BOUNDS_CHANGED ||
  98. event->type() == WM_EVENT_WORKAREA_BOUNDS_CHANGED);
  99. for (aura::Window* child : window_->children())
  100. WindowState::Get(child)->OnWMEvent(event);
  101. }
  102. } // namespace ash