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/wm/lock_layout_manager.h" |
| 6 |
| 7 #include "ash/shell.h" |
| 8 #include "ash/shell_delegate.h" |
| 9 #include "ash/wm/lock_window_state.h" |
| 10 #include "ash/wm/window_state.h" |
| 11 #include "ash/wm/wm_event.h" |
| 12 #include "ui/aura/window.h" |
| 13 #include "ui/aura/window_observer.h" |
| 14 #include "ui/events/event.h" |
| 15 #include "ui/keyboard/keyboard_controller.h" |
| 16 #include "ui/keyboard/keyboard_util.h" |
| 17 |
| 18 using aura::Window; |
| 19 |
| 20 namespace ash { |
| 21 |
| 22 LockLayoutManager::LockLayoutManager(aura::Window* window) |
| 23 : window_(window), |
| 24 root_window_(window->GetRootWindow()), |
| 25 is_observing_keyboard_(false) { |
| 26 Shell::GetInstance()->delegate()->AddVirtualKeyboardStateObserver(this); |
| 27 root_window_->AddObserver(this); |
| 28 if (keyboard::KeyboardController::GetInstance()) { |
| 29 keyboard::KeyboardController::GetInstance()->AddObserver(this); |
| 30 is_observing_keyboard_ = true; |
| 31 } |
| 32 } |
| 33 |
| 34 LockLayoutManager::~LockLayoutManager() { |
| 35 if (root_window_) |
| 36 root_window_->RemoveObserver(this); |
| 37 |
| 38 for (aura::Window::Windows::const_iterator it = window_->children().begin(); |
| 39 it != window_->children().end(); ++it) { |
| 40 (*it)->RemoveObserver(this); |
| 41 } |
| 42 |
| 43 Shell::GetInstance()->delegate()->RemoveVirtualKeyboardStateObserver(this); |
| 44 |
| 45 if (keyboard::KeyboardController::GetInstance() && is_observing_keyboard_) { |
| 46 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); |
| 47 is_observing_keyboard_ = false; |
| 48 } |
| 49 } |
| 50 |
| 51 void LockLayoutManager::OnWindowResized() { |
| 52 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); |
| 53 AdjustWindowsForWorkAreaChange(&event); |
| 54 } |
| 55 |
| 56 void LockLayoutManager::OnWindowAddedToLayout(Window* child) { |
| 57 child->AddObserver(this); |
| 58 |
| 59 // LockWindowState replaces default WindowState of a child. |
| 60 new LockWindowState(child); |
| 61 wm::WindowState* window_state = wm::GetWindowState(child); |
| 62 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); |
| 63 window_state->OnWMEvent(&event); |
| 64 } |
| 65 |
| 66 void LockLayoutManager::OnWillRemoveWindowFromLayout(Window* child) { |
| 67 child->RemoveObserver(this); |
| 68 } |
| 69 |
| 70 void LockLayoutManager::OnWindowRemovedFromLayout(Window* child) { |
| 71 } |
| 72 |
| 73 void LockLayoutManager::OnChildWindowVisibilityChanged(Window* child, |
| 74 bool visible) { |
| 75 } |
| 76 |
| 77 void LockLayoutManager::SetChildBounds( |
| 78 Window* child, |
| 79 const gfx::Rect& requested_bounds) { |
| 80 wm::WindowState* window_state = wm::GetWindowState(child); |
| 81 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); |
| 82 window_state->OnWMEvent(&event); |
| 83 } |
| 84 |
| 85 void LockLayoutManager::OnWindowHierarchyChanged( |
| 86 const WindowObserver::HierarchyChangeParams& params) { |
| 87 } |
| 88 |
| 89 void LockLayoutManager::OnWindowPropertyChanged(Window* window, |
| 90 const void* key, |
| 91 intptr_t old) { |
| 92 } |
| 93 |
| 94 void LockLayoutManager::OnWindowStackingChanged(aura::Window* window) { |
| 95 } |
| 96 |
| 97 void LockLayoutManager::OnWindowDestroying(aura::Window* window) { |
| 98 if (root_window_ == window) { |
| 99 root_window_->RemoveObserver(this); |
| 100 root_window_ = NULL; |
| 101 } else { |
| 102 ForgetWindow(window); |
| 103 } |
| 104 } |
| 105 |
| 106 void LockLayoutManager::OnWindowBoundsChanged(aura::Window* window, |
| 107 const gfx::Rect& old_bounds, |
| 108 const gfx::Rect& new_bounds) { |
| 109 if (root_window_ == window) { |
| 110 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); |
| 111 AdjustWindowsForWorkAreaChange(&wm_event); |
| 112 } |
| 113 } |
| 114 |
| 115 void LockLayoutManager::OnVirtualKeyboardStateChanged(bool activated) { |
| 116 if (keyboard::KeyboardController::GetInstance()) { |
| 117 if (activated) { |
| 118 if (!is_observing_keyboard_) { |
| 119 keyboard::KeyboardController::GetInstance()->AddObserver(this); |
| 120 is_observing_keyboard_ = true; |
| 121 } |
| 122 } else { |
| 123 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); |
| 124 is_observing_keyboard_ = false; |
| 125 } |
| 126 } |
| 127 } |
| 128 |
| 129 void LockLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
| 130 keyboard_bounds_ = new_bounds; |
| 131 OnWindowResized(); |
| 132 } |
| 133 |
| 134 void LockLayoutManager::AdjustWindowsForWorkAreaChange( |
| 135 const wm::WMEvent* event) { |
| 136 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || |
| 137 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); |
| 138 |
| 139 for (aura::Window::Windows::const_iterator it = window_->children().begin(); |
| 140 it != window_->children().end(); |
| 141 ++it) { |
| 142 wm::GetWindowState(*it)->OnWMEvent(event); |
| 143 } |
| 144 } |
| 145 |
| 146 void LockLayoutManager::ForgetWindow(aura::Window* window) { |
| 147 window->RemoveObserver(this); |
| 148 } |
| 149 |
| 150 } // namespace ash |
OLD | NEW |