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

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

Issue 2747543002: ash: Start/stop observing KeyboardController via ShellObserver (Closed)
Patch Set: update LockLayoutManager to use similar logic Created 3 years, 9 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
« no previous file with comments | « ash/common/wm/lock_layout_manager.h ('k') | ash/common/wm/panels/panel_layout_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/wm/lock_layout_manager.h" 5 #include "ash/common/wm/lock_layout_manager.h"
6 6
7 #include "ash/common/keyboard/keyboard_observer_register.h"
7 #include "ash/common/wm/lock_window_state.h" 8 #include "ash/common/wm/lock_window_state.h"
8 #include "ash/common/wm/window_state.h" 9 #include "ash/common/wm/window_state.h"
9 #include "ash/common/wm/wm_event.h" 10 #include "ash/common/wm/wm_event.h"
10 #include "ash/common/wm_window.h" 11 #include "ash/common/wm_window.h"
11 #include "ash/shell.h" 12 #include "ash/shell.h"
12 #include "ui/events/event.h" 13 #include "ui/events/event.h"
13 #include "ui/keyboard/keyboard_controller.h" 14 #include "ui/keyboard/keyboard_controller.h"
14 #include "ui/keyboard/keyboard_util.h" 15 #include "ui/keyboard/keyboard_util.h"
15 16
16 namespace ash { 17 namespace ash {
17 18
18 LockLayoutManager::LockLayoutManager(WmWindow* window) 19 LockLayoutManager::LockLayoutManager(WmWindow* window)
19 : wm::WmSnapToPixelLayoutManager(), 20 : wm::WmSnapToPixelLayoutManager(),
20 window_(window), 21 window_(window),
21 root_window_(window->GetRootWindow()), 22 root_window_(window->GetRootWindow()),
22 is_observing_keyboard_(false) { 23 keyboard_observer_(this) {
23 Shell::GetInstance()->AddShellObserver(this); 24 Shell::GetInstance()->AddShellObserver(this);
24 root_window_->aura_window()->AddObserver(this); 25 root_window_->aura_window()->AddObserver(this);
25 if (keyboard::KeyboardController::GetInstance()) { 26 if (keyboard::KeyboardController::GetInstance())
26 keyboard::KeyboardController::GetInstance()->AddObserver(this); 27 keyboard_observer_.Add(keyboard::KeyboardController::GetInstance());
27 is_observing_keyboard_ = true;
28 }
29 } 28 }
30 29
31 LockLayoutManager::~LockLayoutManager() { 30 LockLayoutManager::~LockLayoutManager() {
32 if (root_window_) 31 if (root_window_)
33 root_window_->aura_window()->RemoveObserver(this); 32 root_window_->aura_window()->RemoveObserver(this);
34 33
35 for (WmWindow* child : window_->GetChildren()) 34 for (WmWindow* child : window_->GetChildren())
36 child->aura_window()->RemoveObserver(this); 35 child->aura_window()->RemoveObserver(this);
37 36
38 Shell::GetInstance()->RemoveShellObserver(this); 37 Shell::GetInstance()->RemoveShellObserver(this);
39
40 if (keyboard::KeyboardController::GetInstance() && is_observing_keyboard_) {
41 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
42 is_observing_keyboard_ = false;
43 }
44 } 38 }
45 39
46 void LockLayoutManager::OnWindowResized() { 40 void LockLayoutManager::OnWindowResized() {
47 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); 41 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED);
48 AdjustWindowsForWorkAreaChange(&event); 42 AdjustWindowsForWorkAreaChange(&event);
49 } 43 }
50 44
51 void LockLayoutManager::OnWindowAddedToLayout(WmWindow* child) { 45 void LockLayoutManager::OnWindowAddedToLayout(WmWindow* child) {
52 child->aura_window()->AddObserver(this); 46 child->aura_window()->AddObserver(this);
53 47
(...skipping 27 matching lines...) Expand all
81 75
82 void LockLayoutManager::OnWindowBoundsChanged(aura::Window* window, 76 void LockLayoutManager::OnWindowBoundsChanged(aura::Window* window,
83 const gfx::Rect& old_bounds, 77 const gfx::Rect& old_bounds,
84 const gfx::Rect& new_bounds) { 78 const gfx::Rect& new_bounds) {
85 if (root_window_ == WmWindow::Get(window)) { 79 if (root_window_ == WmWindow::Get(window)) {
86 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); 80 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED);
87 AdjustWindowsForWorkAreaChange(&wm_event); 81 AdjustWindowsForWorkAreaChange(&wm_event);
88 } 82 }
89 } 83 }
90 84
91 void LockLayoutManager::OnVirtualKeyboardStateChanged(bool activated) { 85 void LockLayoutManager::OnVirtualKeyboardStateChanged(bool activated,
92 if (keyboard::KeyboardController::GetInstance()) { 86 WmWindow* root_window) {
93 if (activated) { 87 UpdateKeyboardObserverFromStateChanged(activated, root_window, root_window_,
94 if (!is_observing_keyboard_) { 88 &keyboard_observer_);
95 keyboard::KeyboardController::GetInstance()->AddObserver(this);
96 is_observing_keyboard_ = true;
97 }
98 } else {
99 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
100 is_observing_keyboard_ = false;
101 }
102 }
103 } 89 }
104 90
105 void LockLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { 91 void LockLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) {
106 keyboard_bounds_ = new_bounds; 92 keyboard_bounds_ = new_bounds;
107 OnWindowResized(); 93 OnWindowResized();
108 } 94 }
109 95
110 void LockLayoutManager::OnKeyboardClosed() {} 96 void LockLayoutManager::OnKeyboardClosed() {
97 keyboard_observer_.RemoveAll();
98 }
111 99
112 void LockLayoutManager::AdjustWindowsForWorkAreaChange( 100 void LockLayoutManager::AdjustWindowsForWorkAreaChange(
113 const wm::WMEvent* event) { 101 const wm::WMEvent* event) {
114 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || 102 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED ||
115 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); 103 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED);
116 104
117 for (WmWindow* child : window_->GetChildren()) 105 for (WmWindow* child : window_->GetChildren())
118 child->GetWindowState()->OnWMEvent(event); 106 child->GetWindowState()->OnWMEvent(event);
119 } 107 }
120 108
121 } // namespace ash 109 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/lock_layout_manager.h ('k') | ash/common/wm/panels/panel_layout_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698