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

Side by Side Diff: ash/common/wm/workspace/workspace_layout_manager.cc

Issue 2072853002: Implement "pinned" mode in ash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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
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/wm/always_on_top_controller.h" 10 #include "ash/common/wm/always_on_top_controller.h"
(...skipping 15 matching lines...) Expand all
26 26
27 WorkspaceLayoutManager::WorkspaceLayoutManager( 27 WorkspaceLayoutManager::WorkspaceLayoutManager(
28 WmWindow* window, 28 WmWindow* window,
29 std::unique_ptr<wm::WorkspaceLayoutManagerDelegate> delegate) 29 std::unique_ptr<wm::WorkspaceLayoutManagerDelegate> delegate)
30 : window_(window), 30 : window_(window),
31 root_window_(window->GetRootWindow()), 31 root_window_(window->GetRootWindow()),
32 root_window_controller_(root_window_->GetRootWindowController()), 32 root_window_controller_(root_window_->GetRootWindowController()),
33 shell_(window_->GetShell()), 33 shell_(window_->GetShell()),
34 delegate_(std::move(delegate)), 34 delegate_(std::move(delegate)),
35 work_area_in_parent_(wm::GetDisplayWorkAreaBounds(window_)), 35 work_area_in_parent_(wm::GetDisplayWorkAreaBounds(window_)),
36 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr) { 36 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr),
37 is_pinned_(WmShell::Get()->IsPinned()) {
38 shell_->AddShellObserver(this);
37 shell_->AddActivationObserver(this); 39 shell_->AddActivationObserver(this);
38 root_window_->AddObserver(this); 40 root_window_->AddObserver(this);
39 root_window_controller_->AddObserver(this); 41 root_window_controller_->AddObserver(this);
40 DCHECK(window->GetBoolProperty( 42 DCHECK(window->GetBoolProperty(
41 WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY)); 43 WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY));
42 } 44 }
43 45
44 WorkspaceLayoutManager::~WorkspaceLayoutManager() { 46 WorkspaceLayoutManager::~WorkspaceLayoutManager() {
45 if (root_window_) 47 if (root_window_)
46 root_window_->RemoveObserver(this); 48 root_window_->RemoveObserver(this);
47 for (WmWindow* window : windows_) 49 for (WmWindow* window : windows_) {
50 wm::WindowState* window_state = window->GetWindowState();
51 window_state->RemoveObserver(this);
48 window->RemoveObserver(this); 52 window->RemoveObserver(this);
53 }
49 root_window_->GetRootWindowController()->RemoveObserver(this); 54 root_window_->GetRootWindowController()->RemoveObserver(this);
50 shell_->RemoveActivationObserver(this); 55 shell_->RemoveActivationObserver(this);
56 shell_->RemoveShellObserver(this);
51 } 57 }
52 58
53 void WorkspaceLayoutManager::DeleteDelegate() { 59 void WorkspaceLayoutManager::DeleteDelegate() {
54 delegate_.reset(); 60 delegate_.reset();
55 } 61 }
56 62
57 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( 63 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate(
58 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { 64 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) {
59 backdrop_delegate_.reset(delegate.release()); 65 backdrop_delegate_.reset(delegate.release());
60 } 66 }
61 67
62 ////////////////////////////////////////////////////////////////////////////// 68 //////////////////////////////////////////////////////////////////////////////
63 // WorkspaceLayoutManager, aura::LayoutManager implementation: 69 // WorkspaceLayoutManager, aura::LayoutManager implementation:
64 70
65 void WorkspaceLayoutManager::OnWindowResized() {} 71 void WorkspaceLayoutManager::OnWindowResized() {}
66 72
67 void WorkspaceLayoutManager::OnWindowAddedToLayout(WmWindow* child) { 73 void WorkspaceLayoutManager::OnWindowAddedToLayout(WmWindow* child) {
68 wm::WindowState* window_state = child->GetWindowState(); 74 wm::WindowState* window_state = child->GetWindowState();
69 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); 75 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE);
70 window_state->OnWMEvent(&event); 76 window_state->OnWMEvent(&event);
71 windows_.insert(child); 77 windows_.insert(child);
72 child->AddObserver(this); 78 child->AddObserver(this);
73 window_state->AddObserver(this); 79 window_state->AddObserver(this);
74 UpdateShelfVisibility(); 80 UpdateShelfVisibility();
75 UpdateFullscreenState(); 81 UpdateFullscreenState();
76 if (backdrop_delegate_) 82 if (backdrop_delegate_)
77 backdrop_delegate_->OnWindowAddedToLayout(child); 83 backdrop_delegate_->OnWindowAddedToLayout(child);
78 WindowPositioner::RearrangeVisibleWindowOnShow(child); 84 WindowPositioner::RearrangeVisibleWindowOnShow(child);
oshima 2016/06/18 06:36:10 I think you also need to update here.
hidehiko 2016/06/18 08:32:13 Done.
79 } 85 }
80 86
81 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(WmWindow* child) { 87 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(WmWindow* child) {
82 windows_.erase(child); 88 windows_.erase(child);
83 child->RemoveObserver(this); 89 child->RemoveObserver(this);
84 child->GetWindowState()->RemoveObserver(this); 90 child->GetWindowState()->RemoveObserver(this);
85 91
86 if (child->GetTargetVisibility()) 92 if (child->GetTargetVisibility())
87 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); 93 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child);
88 } 94 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 AdjustAllWindowsBoundsForWorkAreaChange(&event); 172 AdjustAllWindowsBoundsForWorkAreaChange(&event);
167 } 173 }
168 if (backdrop_delegate_) 174 if (backdrop_delegate_)
169 backdrop_delegate_->OnDisplayWorkAreaInsetsChanged(); 175 backdrop_delegate_->OnDisplayWorkAreaInsetsChanged();
170 } 176 }
171 177
172 void WorkspaceLayoutManager::OnFullscreenStateChanged(bool is_fullscreen) { 178 void WorkspaceLayoutManager::OnFullscreenStateChanged(bool is_fullscreen) {
173 if (is_fullscreen_ == is_fullscreen) 179 if (is_fullscreen_ == is_fullscreen)
174 return; 180 return;
175 181
182 bool was_always_on_top_allowed = !is_fullscreen_ && !is_pinned_;
176 is_fullscreen_ = is_fullscreen; 183 is_fullscreen_ = is_fullscreen;
177 WmWindow* fullscreen_window = 184 bool is_always_on_top_allowed = !is_fullscreen_ && !is_pinned_;
178 is_fullscreen ? wm::GetWindowForFullscreenMode(window_) : nullptr; 185 if (is_always_on_top_allowed != was_always_on_top_allowed) {
179 // Changing always on top state may change window's parent. Iterate on a copy 186 // In this pass, if is_always_on_top_allowed is false, then fullscreen
180 // of |windows_| to avoid invalidating an iterator. Since both workspace and 187 // window should be found. It is because; the situation only happens
181 // always_on_top containers' layouts are managed by this class all the 188 // when was_always_on_top_allowed is true, so (is_fullscreen, is_pinned)
182 // appropriate windows will be included in the iteration. 189 // is changed from (false, false) to (true, false).
183 WindowSet windows(windows_); 190 UpdateAlwaysOnTop(is_always_on_top_allowed
184 for (auto window : windows) { 191 ? nullptr
185 wm::WindowState* window_state = window->GetWindowState(); 192 : wm::GetWindowForFullscreenMode(window_));
186 if (is_fullscreen)
187 window_state->DisableAlwaysOnTop(fullscreen_window);
188 else
189 window_state->RestoreAlwaysOnTop();
190 } 193 }
191 } 194 }
192 195
193 ////////////////////////////////////////////////////////////////////////////// 196 //////////////////////////////////////////////////////////////////////////////
194 // WorkspaceLayoutManager, aura::WindowObserver implementation: 197 // WorkspaceLayoutManager, aura::WindowObserver implementation:
195 198
196 void WorkspaceLayoutManager::OnWindowTreeChanged( 199 void WorkspaceLayoutManager::OnWindowTreeChanged(
197 WmWindow* window, 200 WmWindow* window,
198 const WmWindowObserver::TreeChangeParams& params) { 201 const WmWindowObserver::TreeChangeParams& params) {
199 if (!params.target->GetWindowState()->IsActive()) 202 if (!params.target->GetWindowState()->IsActive())
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) { 280 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) {
278 UpdateFullscreenState(); 281 UpdateFullscreenState();
279 } 282 }
280 283
281 UpdateShelfVisibility(); 284 UpdateShelfVisibility();
282 if (backdrop_delegate_) 285 if (backdrop_delegate_)
283 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type); 286 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type);
284 } 287 }
285 288
286 ////////////////////////////////////////////////////////////////////////////// 289 //////////////////////////////////////////////////////////////////////////////
290 // WorkspaceLayoutManager, ShellObserver implementation:
291
292 void WorkspaceLayoutManager::OnPinnedStateChanged(WmWindow* pinned_window) {
293 bool is_pinned = pinned_window->GetWindowState()->IsPinned();
294 if (is_pinned_ == is_pinned)
295 return;
296
297 bool was_always_on_top_allowed = !is_fullscreen_ && !is_pinned_;
298 is_pinned_ = is_pinned;
299 bool is_always_on_top_allowed = !is_fullscreen_ && !is_pinned_;
300 if (is_always_on_top_allowed != was_always_on_top_allowed) {
301 UpdateAlwaysOnTop(is_always_on_top_allowed ? nullptr : pinned_window);
302 }
303 }
304
305 //////////////////////////////////////////////////////////////////////////////
287 // WorkspaceLayoutManager, private: 306 // WorkspaceLayoutManager, private:
288 307
289 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( 308 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange(
290 const wm::WMEvent* event) { 309 const wm::WMEvent* event) {
291 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || 310 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED ||
292 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); 311 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED);
293 312
294 work_area_in_parent_ = wm::GetDisplayWorkAreaBounds(window_); 313 work_area_in_parent_ = wm::GetDisplayWorkAreaBounds(window_);
295 314
296 // Don't do any adjustments of the insets while we are in screen locked mode. 315 // Don't do any adjustments of the insets while we are in screen locked mode.
(...skipping 25 matching lines...) Expand all
322 // technically any container could get a fullscreen window. 341 // technically any container could get a fullscreen window.
323 if (!delegate_) 342 if (!delegate_)
324 return; 343 return;
325 bool is_fullscreen = wm::GetWindowForFullscreenMode(window_) != nullptr; 344 bool is_fullscreen = wm::GetWindowForFullscreenMode(window_) != nullptr;
326 if (is_fullscreen != is_fullscreen_) { 345 if (is_fullscreen != is_fullscreen_) {
327 delegate_->OnFullscreenStateChanged(is_fullscreen); 346 delegate_->OnFullscreenStateChanged(is_fullscreen);
328 is_fullscreen_ = is_fullscreen; 347 is_fullscreen_ = is_fullscreen;
329 } 348 }
330 } 349 }
331 350
351 void WorkspaceLayoutManager::UpdateAlwaysOnTop(WmWindow* window_on_top) {
352 // Changing always on top state may change window's parent. Iterate on a copy
353 // of |windows_| to avoid invalidating an iterator. Since both workspace and
354 // always_on_top containers' layouts are managed by this class all the
355 // appropriate windows will be included in the iteration.
356 WindowSet windows(windows_);
357 for (auto window : windows) {
358 wm::WindowState* window_state = window->GetWindowState();
359 if (window_on_top)
360 window_state->DisableAlwaysOnTop(window_on_top);
361 else
362 window_state->RestoreAlwaysOnTop();
363 }
364 }
365
332 } // namespace ash 366 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698