Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / wm / lock_layout_manager.cc
blob590b949b383ca0dacb4adc1448fe950758f0008e
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"
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"
18 namespace ash {
20 LockLayoutManager::LockLayoutManager(aura::Window* window)
21 : SnapToPixelLayoutManager(window),
22 window_(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() {
34 if (root_window_)
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,
72 bool visible) {
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,
87 const void* key,
88 intptr_t old) {
91 void LockLayoutManager::OnWindowStackingChanged(aura::Window* window) {
94 void LockLayoutManager::OnWindowDestroying(aura::Window* window) {
95 window->RemoveObserver(this);
96 if (root_window_ == window)
97 root_window_ = NULL;
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()) {
111 if (activated) {
112 if (!is_observing_keyboard_) {
113 keyboard::KeyboardController::GetInstance()->AddObserver(this);
114 is_observing_keyboard_ = true;
116 } else {
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;
125 OnWindowResized();
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();
135 ++it) {
136 wm::GetWindowState(*it)->OnWMEvent(event);
140 } // namespace ash