| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/workspace/workspace_layout_manager.h" | 5 #include "ash/common/wm/workspace/workspace_layout_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
| 10 #include "ash/common/shelf/wm_shelf.h" | 10 #include "ash/common/shelf/wm_shelf.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "ui/wm/public/activation_client.h" | 33 #include "ui/wm/public/activation_client.h" |
| 34 | 34 |
| 35 namespace ash { | 35 namespace ash { |
| 36 | 36 |
| 37 WorkspaceLayoutManager::WorkspaceLayoutManager(WmWindow* window) | 37 WorkspaceLayoutManager::WorkspaceLayoutManager(WmWindow* window) |
| 38 : window_(window), | 38 : window_(window), |
| 39 root_window_(window->GetRootWindow()), | 39 root_window_(window->GetRootWindow()), |
| 40 root_window_controller_(root_window_->GetRootWindowController()), | 40 root_window_controller_(root_window_->GetRootWindowController()), |
| 41 shell_(window_->GetShell()), | 41 shell_(window_->GetShell()), |
| 42 work_area_in_parent_(wm::GetDisplayWorkAreaBoundsInParent(window_)), | 42 work_area_in_parent_(wm::GetDisplayWorkAreaBoundsInParent(window_)), |
| 43 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr) { | 43 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr), |
| 44 keyboard_observer_(this) { |
| 44 Shell::GetInstance()->AddShellObserver(this); | 45 Shell::GetInstance()->AddShellObserver(this); |
| 45 Shell::GetInstance()->activation_client()->AddObserver(this); | 46 Shell::GetInstance()->activation_client()->AddObserver(this); |
| 46 root_window_->aura_window()->AddObserver(this); | 47 root_window_->aura_window()->AddObserver(this); |
| 47 display::Screen::GetScreen()->AddObserver(this); | 48 display::Screen::GetScreen()->AddObserver(this); |
| 48 DCHECK(window->aura_window()->GetProperty(kSnapChildrenToPixelBoundary)); | 49 DCHECK(window->aura_window()->GetProperty(kSnapChildrenToPixelBoundary)); |
| 49 } | 50 } |
| 50 | 51 |
| 51 WorkspaceLayoutManager::~WorkspaceLayoutManager() { | 52 WorkspaceLayoutManager::~WorkspaceLayoutManager() { |
| 52 if (root_window_) | 53 if (root_window_) |
| 53 root_window_->aura_window()->RemoveObserver(this); | 54 root_window_->aura_window()->RemoveObserver(this); |
| 54 for (WmWindow* window : windows_) { | 55 for (WmWindow* window : windows_) { |
| 55 wm::WindowState* window_state = window->GetWindowState(); | 56 wm::WindowState* window_state = window->GetWindowState(); |
| 56 window_state->RemoveObserver(this); | 57 window_state->RemoveObserver(this); |
| 57 window->aura_window()->RemoveObserver(this); | 58 window->aura_window()->RemoveObserver(this); |
| 58 } | 59 } |
| 59 display::Screen::GetScreen()->RemoveObserver(this); | 60 display::Screen::GetScreen()->RemoveObserver(this); |
| 60 Shell::GetInstance()->activation_client()->RemoveObserver(this); | 61 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| 61 Shell::GetInstance()->RemoveShellObserver(this); | 62 Shell::GetInstance()->RemoveShellObserver(this); |
| 62 } | 63 } |
| 63 | 64 |
| 64 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( | 65 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( |
| 65 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { | 66 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { |
| 66 backdrop_delegate_ = std::move(delegate); | 67 backdrop_delegate_ = std::move(delegate); |
| 67 } | 68 } |
| 68 | 69 |
| 70 void WorkspaceLayoutManager::StartObservingKeyboard( |
| 71 keyboard::KeyboardController* keyboard_controller) { |
| 72 DCHECK(!keyboard_observer_.IsObservingSources()); |
| 73 keyboard_observer_.Add(keyboard_controller); |
| 74 } |
| 75 |
| 76 void WorkspaceLayoutManager::StopObservingKeyboard( |
| 77 keyboard::KeyboardController* keyboard_controller) { |
| 78 if (keyboard_observer_.IsObserving(keyboard_controller)) |
| 79 keyboard_observer_.Remove(keyboard_controller); |
| 80 } |
| 81 |
| 69 ////////////////////////////////////////////////////////////////////////////// | 82 ////////////////////////////////////////////////////////////////////////////// |
| 70 // WorkspaceLayoutManager, aura::LayoutManager implementation: | 83 // WorkspaceLayoutManager, aura::LayoutManager implementation: |
| 71 | 84 |
| 72 void WorkspaceLayoutManager::OnWindowResized() {} | 85 void WorkspaceLayoutManager::OnWindowResized() {} |
| 73 | 86 |
| 74 void WorkspaceLayoutManager::OnWindowAddedToLayout(WmWindow* child) { | 87 void WorkspaceLayoutManager::OnWindowAddedToLayout(WmWindow* child) { |
| 75 wm::WindowState* window_state = child->GetWindowState(); | 88 wm::WindowState* window_state = child->GetWindowState(); |
| 76 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); | 89 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); |
| 77 window_state->OnWMEvent(&event); | 90 window_state->OnWMEvent(&event); |
| 78 windows_.insert(child); | 91 windows_.insert(child); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 184 } |
| 172 } else if (window_state->HasRestoreBounds()) { | 185 } else if (window_state->HasRestoreBounds()) { |
| 173 // Keyboard hidden, restore original bounds if they exist. If the user has | 186 // Keyboard hidden, restore original bounds if they exist. If the user has |
| 174 // resized or dragged the window in the meantime, WorkspaceWindowResizer | 187 // resized or dragged the window in the meantime, WorkspaceWindowResizer |
| 175 // will have cleared the restore bounds and this code will not accidentally | 188 // will have cleared the restore bounds and this code will not accidentally |
| 176 // override user intent. | 189 // override user intent. |
| 177 window_state->SetAndClearRestoreBounds(); | 190 window_state->SetAndClearRestoreBounds(); |
| 178 } | 191 } |
| 179 } | 192 } |
| 180 | 193 |
| 181 void WorkspaceLayoutManager::OnKeyboardClosed() {} | 194 void WorkspaceLayoutManager::OnKeyboardClosed() { |
| 195 keyboard_observer_.RemoveAll(); |
| 196 } |
| 182 | 197 |
| 183 ////////////////////////////////////////////////////////////////////////////// | 198 ////////////////////////////////////////////////////////////////////////////// |
| 184 // WorkspaceLayoutManager, aura::WindowObserver implementation: | 199 // WorkspaceLayoutManager, aura::WindowObserver implementation: |
| 185 | 200 |
| 186 void WorkspaceLayoutManager::OnWindowHierarchyChanged( | 201 void WorkspaceLayoutManager::OnWindowHierarchyChanged( |
| 187 const HierarchyChangeParams& params) { | 202 const HierarchyChangeParams& params) { |
| 188 if (!wm::GetWindowState(params.target)->IsActive()) | 203 if (!wm::GetWindowState(params.target)->IsActive()) |
| 189 return; | 204 return; |
| 190 // If the window is already tracked by the workspace this update would be | 205 // If the window is already tracked by the workspace this update would be |
| 191 // redundant as the fullscreen and shelf state would have been handled in | 206 // redundant as the fullscreen and shelf state would have been handled in |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 for (auto* window : windows) { | 398 for (auto* window : windows) { |
| 384 wm::WindowState* window_state = window->GetWindowState(); | 399 wm::WindowState* window_state = window->GetWindowState(); |
| 385 if (window_on_top) | 400 if (window_on_top) |
| 386 window_state->DisableAlwaysOnTop(window_on_top); | 401 window_state->DisableAlwaysOnTop(window_on_top); |
| 387 else | 402 else |
| 388 window_state->RestoreAlwaysOnTop(); | 403 window_state->RestoreAlwaysOnTop(); |
| 389 } | 404 } |
| 390 } | 405 } |
| 391 | 406 |
| 392 } // namespace ash | 407 } // namespace ash |
| OLD | NEW |