| OLD | NEW |
| (Empty) |
| 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 | |
| 5 #include "ash/common/wm/lock_layout_manager.h" | |
| 6 | |
| 7 #include "ash/common/wm/lock_window_state.h" | |
| 8 #include "ash/common/wm/window_state.h" | |
| 9 #include "ash/common/wm/wm_event.h" | |
| 10 #include "ash/common/wm_shell.h" | |
| 11 #include "ash/common/wm_window.h" | |
| 12 #include "ui/events/event.h" | |
| 13 #include "ui/keyboard/keyboard_controller.h" | |
| 14 #include "ui/keyboard/keyboard_util.h" | |
| 15 | |
| 16 namespace ash { | |
| 17 | |
| 18 LockLayoutManager::LockLayoutManager(WmWindow* window) | |
| 19 : wm::WmSnapToPixelLayoutManager(), | |
| 20 window_(window), | |
| 21 root_window_(window->GetRootWindow()), | |
| 22 is_observing_keyboard_(false) { | |
| 23 WmShell::Get()->AddShellObserver(this); | |
| 24 root_window_->aura_window()->AddObserver(this); | |
| 25 if (keyboard::KeyboardController::GetInstance()) { | |
| 26 keyboard::KeyboardController::GetInstance()->AddObserver(this); | |
| 27 is_observing_keyboard_ = true; | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 LockLayoutManager::~LockLayoutManager() { | |
| 32 if (root_window_) | |
| 33 root_window_->aura_window()->RemoveObserver(this); | |
| 34 | |
| 35 for (WmWindow* child : window_->GetChildren()) | |
| 36 child->aura_window()->RemoveObserver(this); | |
| 37 | |
| 38 WmShell::Get()->RemoveShellObserver(this); | |
| 39 | |
| 40 if (keyboard::KeyboardController::GetInstance() && is_observing_keyboard_) { | |
| 41 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); | |
| 42 is_observing_keyboard_ = false; | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 void LockLayoutManager::OnWindowResized() { | |
| 47 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | |
| 48 AdjustWindowsForWorkAreaChange(&event); | |
| 49 } | |
| 50 | |
| 51 void LockLayoutManager::OnWindowAddedToLayout(WmWindow* child) { | |
| 52 child->aura_window()->AddObserver(this); | |
| 53 | |
| 54 // LockWindowState replaces default WindowState of a child. | |
| 55 wm::WindowState* window_state = LockWindowState::SetLockWindowState(child); | |
| 56 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); | |
| 57 window_state->OnWMEvent(&event); | |
| 58 } | |
| 59 | |
| 60 void LockLayoutManager::OnWillRemoveWindowFromLayout(WmWindow* child) { | |
| 61 child->aura_window()->RemoveObserver(this); | |
| 62 } | |
| 63 | |
| 64 void LockLayoutManager::OnWindowRemovedFromLayout(WmWindow* child) {} | |
| 65 | |
| 66 void LockLayoutManager::OnChildWindowVisibilityChanged(WmWindow* child, | |
| 67 bool visible) {} | |
| 68 | |
| 69 void LockLayoutManager::SetChildBounds(WmWindow* child, | |
| 70 const gfx::Rect& requested_bounds) { | |
| 71 wm::WindowState* window_state = child->GetWindowState(); | |
| 72 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); | |
| 73 window_state->OnWMEvent(&event); | |
| 74 } | |
| 75 | |
| 76 void LockLayoutManager::OnWindowDestroying(aura::Window* window) { | |
| 77 window->RemoveObserver(this); | |
| 78 if (root_window_ == WmWindow::Get(window)) | |
| 79 root_window_ = nullptr; | |
| 80 } | |
| 81 | |
| 82 void LockLayoutManager::OnWindowBoundsChanged(aura::Window* window, | |
| 83 const gfx::Rect& old_bounds, | |
| 84 const gfx::Rect& new_bounds) { | |
| 85 if (root_window_ == WmWindow::Get(window)) { | |
| 86 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); | |
| 87 AdjustWindowsForWorkAreaChange(&wm_event); | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 void LockLayoutManager::OnVirtualKeyboardStateChanged(bool activated) { | |
| 92 if (keyboard::KeyboardController::GetInstance()) { | |
| 93 if (activated) { | |
| 94 if (!is_observing_keyboard_) { | |
| 95 keyboard::KeyboardController::GetInstance()->AddObserver(this); | |
| 96 is_observing_keyboard_ = true; | |
| 97 } | |
| 98 } else { | |
| 99 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); | |
| 100 is_observing_keyboard_ = false; | |
| 101 } | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 void LockLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | |
| 106 keyboard_bounds_ = new_bounds; | |
| 107 OnWindowResized(); | |
| 108 } | |
| 109 | |
| 110 void LockLayoutManager::OnKeyboardClosed() {} | |
| 111 | |
| 112 void LockLayoutManager::AdjustWindowsForWorkAreaChange( | |
| 113 const wm::WMEvent* event) { | |
| 114 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || | |
| 115 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | |
| 116 | |
| 117 for (WmWindow* child : window_->GetChildren()) | |
| 118 child->GetWindowState()->OnWMEvent(event); | |
| 119 } | |
| 120 | |
| 121 } // namespace ash | |
| OLD | NEW |