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

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: address comments 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
« no previous file with comments | « ash/common/wm/workspace/workspace_layout_manager.h ('k') | ash/common/wm_shell.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 (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 16 matching lines...) Expand all
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 shell_->AddShellObserver(this);
37 shell_->AddActivationObserver(this); 38 shell_->AddActivationObserver(this);
38 root_window_->AddObserver(this); 39 root_window_->AddObserver(this);
39 root_window_controller_->AddObserver(this); 40 root_window_controller_->AddObserver(this);
40 DCHECK(window->GetBoolProperty( 41 DCHECK(window->GetBoolProperty(
41 WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY)); 42 WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY));
42 } 43 }
43 44
44 WorkspaceLayoutManager::~WorkspaceLayoutManager() { 45 WorkspaceLayoutManager::~WorkspaceLayoutManager() {
45 if (root_window_) 46 if (root_window_)
46 root_window_->RemoveObserver(this); 47 root_window_->RemoveObserver(this);
47 for (WmWindow* window : windows_) 48 for (WmWindow* window : windows_) {
49 wm::WindowState* window_state = window->GetWindowState();
50 window_state->RemoveObserver(this);
48 window->RemoveObserver(this); 51 window->RemoveObserver(this);
52 }
49 root_window_->GetRootWindowController()->RemoveObserver(this); 53 root_window_->GetRootWindowController()->RemoveObserver(this);
50 shell_->RemoveActivationObserver(this); 54 shell_->RemoveActivationObserver(this);
55 shell_->RemoveShellObserver(this);
51 } 56 }
52 57
53 void WorkspaceLayoutManager::DeleteDelegate() { 58 void WorkspaceLayoutManager::DeleteDelegate() {
54 delegate_.reset(); 59 delegate_.reset();
55 } 60 }
56 61
57 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( 62 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate(
58 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { 63 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) {
59 backdrop_delegate_.reset(delegate.release()); 64 backdrop_delegate_.reset(delegate.release());
60 } 65 }
61 66
62 ////////////////////////////////////////////////////////////////////////////// 67 //////////////////////////////////////////////////////////////////////////////
63 // WorkspaceLayoutManager, aura::LayoutManager implementation: 68 // WorkspaceLayoutManager, aura::LayoutManager implementation:
64 69
65 void WorkspaceLayoutManager::OnWindowResized() {} 70 void WorkspaceLayoutManager::OnWindowResized() {}
66 71
67 void WorkspaceLayoutManager::OnWindowAddedToLayout(WmWindow* child) { 72 void WorkspaceLayoutManager::OnWindowAddedToLayout(WmWindow* child) {
68 wm::WindowState* window_state = child->GetWindowState(); 73 wm::WindowState* window_state = child->GetWindowState();
69 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); 74 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE);
70 window_state->OnWMEvent(&event); 75 window_state->OnWMEvent(&event);
71 windows_.insert(child); 76 windows_.insert(child);
72 child->AddObserver(this); 77 child->AddObserver(this);
73 window_state->AddObserver(this); 78 window_state->AddObserver(this);
74 UpdateShelfVisibility(); 79 UpdateShelfVisibility();
75 UpdateFullscreenState(); 80 UpdateFullscreenState();
76 if (backdrop_delegate_) 81 if (backdrop_delegate_)
77 backdrop_delegate_->OnWindowAddedToLayout(child); 82 backdrop_delegate_->OnWindowAddedToLayout(child);
78 WindowPositioner::RearrangeVisibleWindowOnShow(child); 83 WindowPositioner::RearrangeVisibleWindowOnShow(child);
84 if (WmShell::Get()->IsPinned())
85 child->GetWindowState()->DisableAlwaysOnTop(nullptr);
79 } 86 }
80 87
81 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(WmWindow* child) { 88 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(WmWindow* child) {
82 windows_.erase(child); 89 windows_.erase(child);
83 child->RemoveObserver(this); 90 child->RemoveObserver(this);
84 child->GetWindowState()->RemoveObserver(this); 91 child->GetWindowState()->RemoveObserver(this);
85 92
86 if (child->GetTargetVisibility()) 93 if (child->GetTargetVisibility())
87 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); 94 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child);
88 } 95 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 const gfx::Rect work_area(wm::GetDisplayWorkAreaBounds(window_)); 170 const gfx::Rect work_area(wm::GetDisplayWorkAreaBounds(window_));
164 if (work_area != work_area_in_parent_) { 171 if (work_area != work_area_in_parent_) {
165 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); 172 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED);
166 AdjustAllWindowsBoundsForWorkAreaChange(&event); 173 AdjustAllWindowsBoundsForWorkAreaChange(&event);
167 } 174 }
168 if (backdrop_delegate_) 175 if (backdrop_delegate_)
169 backdrop_delegate_->OnDisplayWorkAreaInsetsChanged(); 176 backdrop_delegate_->OnDisplayWorkAreaInsetsChanged();
170 } 177 }
171 178
172 void WorkspaceLayoutManager::OnFullscreenStateChanged(bool is_fullscreen) { 179 void WorkspaceLayoutManager::OnFullscreenStateChanged(bool is_fullscreen) {
173 if (is_fullscreen_ == is_fullscreen) 180 if (is_fullscreen_ == is_fullscreen) {
174 return; 181 return;
182 }
oshima 2016/06/18 08:41:39 nuke {}
hidehiko 2016/06/18 09:33:34 Done.
175 183
176 is_fullscreen_ = is_fullscreen; 184 is_fullscreen_ = is_fullscreen;
177 WmWindow* fullscreen_window = 185 if (WmShell::Get()->IsPinned()) {
178 is_fullscreen ? wm::GetWindowForFullscreenMode(window_) : nullptr; 186 // If this is in pinned mode, then this event does not trigger the
179 // Changing always on top state may change window's parent. Iterate on a copy 187 // always-on-top state change, because it is kept disabled regardless of
180 // of |windows_| to avoid invalidating an iterator. Since both workspace and 188 // the fullscreen state change.
181 // always_on_top containers' layouts are managed by this class all the 189 return;
182 // appropriate windows will be included in the iteration.
183 WindowSet windows(windows_);
184 for (auto window : windows) {
185 wm::WindowState* window_state = window->GetWindowState();
186 if (is_fullscreen)
187 window_state->DisableAlwaysOnTop(fullscreen_window);
188 else
189 window_state->RestoreAlwaysOnTop();
190 } 190 }
191
192 UpdateAlwaysOnTop(is_fullscreen_ ? wm::GetWindowForFullscreenMode(window_)
193 : nullptr);
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())
200 return; 203 return;
(...skipping 76 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 if (is_fullscreen_) {
294 // If in fullscreen mode, then this event does not affect to the
295 // always-on-top state, because it is kept disabled regardless of pinned
296 // window state change.
oshima 2016/06/18 08:41:39 new always-on-stop may be created during fullscree
hidehiko 2016/06/18 09:33:34 Done.
297 return;
298 }
299
300 UpdateAlwaysOnTop(WmShell::Get()->IsPinned() ? pinned_window : nullptr);
301 }
302
303 //////////////////////////////////////////////////////////////////////////////
287 // WorkspaceLayoutManager, private: 304 // WorkspaceLayoutManager, private:
288 305
289 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( 306 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange(
290 const wm::WMEvent* event) { 307 const wm::WMEvent* event) {
291 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || 308 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED ||
292 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); 309 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED);
293 310
294 work_area_in_parent_ = wm::GetDisplayWorkAreaBounds(window_); 311 work_area_in_parent_ = wm::GetDisplayWorkAreaBounds(window_);
295 312
296 // Don't do any adjustments of the insets while we are in screen locked mode. 313 // 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. 339 // technically any container could get a fullscreen window.
323 if (!delegate_) 340 if (!delegate_)
324 return; 341 return;
325 bool is_fullscreen = wm::GetWindowForFullscreenMode(window_) != nullptr; 342 bool is_fullscreen = wm::GetWindowForFullscreenMode(window_) != nullptr;
326 if (is_fullscreen != is_fullscreen_) { 343 if (is_fullscreen != is_fullscreen_) {
327 delegate_->OnFullscreenStateChanged(is_fullscreen); 344 delegate_->OnFullscreenStateChanged(is_fullscreen);
328 is_fullscreen_ = is_fullscreen; 345 is_fullscreen_ = is_fullscreen;
329 } 346 }
330 } 347 }
331 348
349 void WorkspaceLayoutManager::UpdateAlwaysOnTop(WmWindow* window_on_top) {
350 // Changing always on top state may change window's parent. Iterate on a copy
351 // of |windows_| to avoid invalidating an iterator. Since both workspace and
352 // always_on_top containers' layouts are managed by this class all the
353 // appropriate windows will be included in the iteration.
354 WindowSet windows(windows_);
355 for (auto window : windows) {
356 wm::WindowState* window_state = window->GetWindowState();
357 if (window_on_top)
358 window_state->DisableAlwaysOnTop(window_on_top);
359 else
360 window_state->RestoreAlwaysOnTop();
361 }
362 }
363
332 } // namespace ash 364 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/workspace/workspace_layout_manager.h ('k') | ash/common/wm_shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698