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.
5 #include "ash/wm/lock_layout_manager.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"
20 LockLayoutManager::LockLayoutManager(aura::Window
* window
)
21 : SnapToPixelLayoutManager(window
),
23 root_window_(window
->GetRootWindow()),
24 is_observing_keyboard_(false) {
25 Shell::GetInstance()->delegate()->AddVirtualKeyboardStateObserver(this);
26 root_window_
->AddObserver(this);
27 if (keyboard::KeyboardController::GetInstance()) {
28 keyboard::KeyboardController::GetInstance()->AddObserver(this);
29 is_observing_keyboard_
= true;
33 LockLayoutManager::~LockLayoutManager() {
35 root_window_
->RemoveObserver(this);
37 for (aura::Window::Windows::const_iterator it
= window_
->children().begin();
38 it
!= window_
->children().end(); ++it
) {
39 (*it
)->RemoveObserver(this);
42 Shell::GetInstance()->delegate()->RemoveVirtualKeyboardStateObserver(this);
44 if (keyboard::KeyboardController::GetInstance() && is_observing_keyboard_
) {
45 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
46 is_observing_keyboard_
= false;
50 void LockLayoutManager::OnWindowResized() {
51 const wm::WMEvent
event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED
);
52 AdjustWindowsForWorkAreaChange(&event
);
55 void LockLayoutManager::OnWindowAddedToLayout(aura::Window
* child
) {
56 child
->AddObserver(this);
58 // LockWindowState replaces default WindowState of a child.
59 wm::WindowState
* window_state
= LockWindowState::SetLockWindowState(child
);
60 wm::WMEvent
event(wm::WM_EVENT_ADDED_TO_WORKSPACE
);
61 window_state
->OnWMEvent(&event
);
64 void LockLayoutManager::OnWillRemoveWindowFromLayout(aura::Window
* child
) {
65 child
->RemoveObserver(this);
68 void LockLayoutManager::OnWindowRemovedFromLayout(aura::Window
* child
) {
71 void LockLayoutManager::OnChildWindowVisibilityChanged(aura::Window
* child
,
75 void LockLayoutManager::SetChildBounds(aura::Window
* child
,
76 const gfx::Rect
& requested_bounds
) {
77 wm::WindowState
* window_state
= wm::GetWindowState(child
);
78 wm::SetBoundsEvent
event(wm::WM_EVENT_SET_BOUNDS
, requested_bounds
);
79 window_state
->OnWMEvent(&event
);
82 void LockLayoutManager::OnWindowHierarchyChanged(
83 const WindowObserver::HierarchyChangeParams
& params
) {
86 void LockLayoutManager::OnWindowPropertyChanged(aura::Window
* window
,
91 void LockLayoutManager::OnWindowStackingChanged(aura::Window
* window
) {
94 void LockLayoutManager::OnWindowDestroying(aura::Window
* window
) {
95 window
->RemoveObserver(this);
96 if (root_window_
== window
)
100 void LockLayoutManager::OnWindowBoundsChanged(aura::Window
* window
,
101 const gfx::Rect
& old_bounds
,
102 const gfx::Rect
& new_bounds
) {
103 if (root_window_
== window
) {
104 const wm::WMEvent
wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED
);
105 AdjustWindowsForWorkAreaChange(&wm_event
);
109 void LockLayoutManager::OnVirtualKeyboardStateChanged(bool activated
) {
110 if (keyboard::KeyboardController::GetInstance()) {
112 if (!is_observing_keyboard_
) {
113 keyboard::KeyboardController::GetInstance()->AddObserver(this);
114 is_observing_keyboard_
= true;
117 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
118 is_observing_keyboard_
= false;
123 void LockLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect
& new_bounds
) {
124 keyboard_bounds_
= new_bounds
;
128 void LockLayoutManager::AdjustWindowsForWorkAreaChange(
129 const wm::WMEvent
* event
) {
130 DCHECK(event
->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED
||
131 event
->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED
);
133 for (aura::Window::Windows::const_iterator it
= window_
->children().begin();
134 it
!= window_
->children().end();
136 wm::GetWindowState(*it
)->OnWMEvent(event
);