Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Side by Side Diff: ash/wm/lock_layout_manager.cc

Issue 2354533004: Ports LockLayoutManager/LockWindowState to ash/common (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/common/wm/window_state.h"
8 #include "ash/common/wm/wm_event.h"
9 #include "ash/common/wm_shell.h"
10 #include "ash/wm/lock_window_state.h"
11 #include "ash/wm/window_state_aura.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 namespace ash {
19
20 LockLayoutManager::LockLayoutManager(aura::Window* window)
21 : SnapToPixelLayoutManager(window),
22 window_(window),
23 root_window_(window->GetRootWindow()),
24 is_observing_keyboard_(false) {
25 WmShell::Get()->AddShellObserver(this);
26 root_window_->AddObserver(this);
27 if (keyboard::KeyboardController::GetInstance()) {
28 keyboard::KeyboardController::GetInstance()->AddObserver(this);
29 is_observing_keyboard_ = true;
30 }
31 }
32
33 LockLayoutManager::~LockLayoutManager() {
34 if (root_window_)
35 root_window_->RemoveObserver(this);
36
37 for (aura::Window::Windows::const_iterator it = window_->children().begin();
38 it != window_->children().end(); ++it) {
39 (*it)->RemoveObserver(this);
40 }
41
42 WmShell::Get()->RemoveShellObserver(this);
43
44 if (keyboard::KeyboardController::GetInstance() && is_observing_keyboard_) {
45 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
46 is_observing_keyboard_ = false;
47 }
48 }
49
50 void LockLayoutManager::OnWindowResized() {
51 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED);
52 AdjustWindowsForWorkAreaChange(&event);
53 }
54
55 void LockLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
56 child->AddObserver(this);
57
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);
62 }
63
64 void LockLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) {
65 child->RemoveObserver(this);
66 }
67
68 void LockLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) {}
69
70 void LockLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child,
71 bool visible) {}
72
73 void LockLayoutManager::SetChildBounds(aura::Window* child,
74 const gfx::Rect& requested_bounds) {
75 wm::WindowState* window_state = wm::GetWindowState(child);
76 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds);
77 window_state->OnWMEvent(&event);
78 }
79
80 void LockLayoutManager::OnWindowHierarchyChanged(
81 const WindowObserver::HierarchyChangeParams& params) {}
82
83 void LockLayoutManager::OnWindowPropertyChanged(aura::Window* window,
84 const void* key,
85 intptr_t old) {}
86
87 void LockLayoutManager::OnWindowStackingChanged(aura::Window* window) {}
88
89 void LockLayoutManager::OnWindowDestroying(aura::Window* window) {
90 window->RemoveObserver(this);
91 if (root_window_ == window)
92 root_window_ = NULL;
93 }
94
95 void LockLayoutManager::OnWindowBoundsChanged(aura::Window* window,
96 const gfx::Rect& old_bounds,
97 const gfx::Rect& new_bounds) {
98 if (root_window_ == window) {
99 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED);
100 AdjustWindowsForWorkAreaChange(&wm_event);
101 }
102 }
103
104 void LockLayoutManager::OnVirtualKeyboardStateChanged(bool activated) {
105 if (keyboard::KeyboardController::GetInstance()) {
106 if (activated) {
107 if (!is_observing_keyboard_) {
108 keyboard::KeyboardController::GetInstance()->AddObserver(this);
109 is_observing_keyboard_ = true;
110 }
111 } else {
112 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
113 is_observing_keyboard_ = false;
114 }
115 }
116 }
117
118 void LockLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) {
119 keyboard_bounds_ = new_bounds;
120 OnWindowResized();
121 }
122
123 void LockLayoutManager::OnKeyboardClosed() {}
124
125 void LockLayoutManager::AdjustWindowsForWorkAreaChange(
126 const wm::WMEvent* event) {
127 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED ||
128 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED);
129
130 for (aura::Window::Windows::const_iterator it = window_->children().begin();
131 it != window_->children().end(); ++it) {
132 wm::GetWindowState(*it)->OnWMEvent(event);
133 }
134 }
135
136 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698