Chromium Code Reviews| 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; | |
|
oshima
2014/06/05 17:09:05
nit: you're using both Window and aura::Window. pl
Nikita (slow)
2014/06/06 04:31:30
Done.
| |
| 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 wm::WindowState* window_state = LockWindowState::SetLockWindowState(child); | |
| 61 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); | |
| 62 window_state->OnWMEvent(&event); | |
| 63 } | |
| 64 | |
| 65 void LockLayoutManager::OnWillRemoveWindowFromLayout(Window* child) { | |
| 66 child->RemoveObserver(this); | |
| 67 } | |
| 68 | |
| 69 void LockLayoutManager::OnWindowRemovedFromLayout(Window* child) { | |
| 70 } | |
| 71 | |
| 72 void LockLayoutManager::OnChildWindowVisibilityChanged(Window* child, | |
| 73 bool visible) { | |
| 74 } | |
| 75 | |
| 76 void LockLayoutManager::SetChildBounds( | |
| 77 Window* child, | |
| 78 const gfx::Rect& requested_bounds) { | |
| 79 wm::WindowState* window_state = wm::GetWindowState(child); | |
| 80 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); | |
| 81 window_state->OnWMEvent(&event); | |
| 82 } | |
| 83 | |
| 84 void LockLayoutManager::OnWindowHierarchyChanged( | |
| 85 const WindowObserver::HierarchyChangeParams& params) { | |
| 86 } | |
| 87 | |
| 88 void LockLayoutManager::OnWindowPropertyChanged(Window* window, | |
| 89 const void* key, | |
| 90 intptr_t old) { | |
| 91 } | |
| 92 | |
| 93 void LockLayoutManager::OnWindowStackingChanged(aura::Window* window) { | |
| 94 } | |
| 95 | |
| 96 void LockLayoutManager::OnWindowDestroying(aura::Window* window) { | |
| 97 if (root_window_ == window) { | |
| 98 root_window_->RemoveObserver(this); | |
| 99 root_window_ = NULL; | |
| 100 } else { | |
| 101 ForgetWindow(window); | |
| 102 } | |
|
oshima
2014/06/05 17:09:04
can now this be just
window->RemoveObserver(this)
Nikita (slow)
2014/06/06 04:31:30
Done.
| |
| 103 } | |
| 104 | |
| 105 void LockLayoutManager::OnWindowBoundsChanged(aura::Window* window, | |
| 106 const gfx::Rect& old_bounds, | |
| 107 const gfx::Rect& new_bounds) { | |
| 108 if (root_window_ == window) { | |
| 109 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); | |
| 110 AdjustWindowsForWorkAreaChange(&wm_event); | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 void LockLayoutManager::OnVirtualKeyboardStateChanged(bool activated) { | |
| 115 if (keyboard::KeyboardController::GetInstance()) { | |
| 116 if (activated) { | |
| 117 if (!is_observing_keyboard_) { | |
| 118 keyboard::KeyboardController::GetInstance()->AddObserver(this); | |
| 119 is_observing_keyboard_ = true; | |
| 120 } | |
| 121 } else { | |
| 122 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); | |
| 123 is_observing_keyboard_ = false; | |
| 124 } | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 void LockLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | |
| 129 keyboard_bounds_ = new_bounds; | |
| 130 OnWindowResized(); | |
| 131 } | |
| 132 | |
| 133 void LockLayoutManager::AdjustWindowsForWorkAreaChange( | |
| 134 const wm::WMEvent* event) { | |
| 135 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || | |
| 136 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | |
| 137 | |
| 138 for (aura::Window::Windows::const_iterator it = window_->children().begin(); | |
| 139 it != window_->children().end(); | |
| 140 ++it) { | |
| 141 wm::GetWindowState(*it)->OnWMEvent(event); | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 void LockLayoutManager::ForgetWindow(aura::Window* window) { | |
| 146 window->RemoveObserver(this); | |
| 147 } | |
| 148 | |
| 149 } // namespace ash | |
| OLD | NEW |