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

Side by Side Diff: ash/common/wm/always_on_top_controller.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/always_on_top_controller.h" 5 #include "ash/common/wm/always_on_top_controller.h"
6 6
7 #include "ash/common/shell_window_ids.h" 7 #include "ash/common/shell_window_ids.h"
8 #include "ash/common/wm/workspace/workspace_layout_manager.h" 8 #include "ash/common/wm/workspace/workspace_layout_manager.h"
9 #include "ash/common/wm/workspace/workspace_layout_manager_delegate.h" 9 #include "ash/common/wm/workspace/workspace_layout_manager_delegate.h"
10 #include "ash/common/wm_shell.h"
10 #include "ash/common/wm_window.h" 11 #include "ash/common/wm_window.h"
11 #include "ash/common/wm_window_property.h" 12 #include "ash/common/wm_window_property.h"
12 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
13 14
14 namespace ash { 15 namespace ash {
15 16
16 AlwaysOnTopController::AlwaysOnTopController(WmWindow* viewport) 17 AlwaysOnTopController::AlwaysOnTopController(WmWindow* viewport)
17 : always_on_top_container_(viewport) { 18 : always_on_top_container_(viewport) {
18 always_on_top_container_->SetLayoutManager( 19 always_on_top_container_->SetLayoutManager(
19 base::WrapUnique(new WorkspaceLayoutManager(viewport, nullptr))); 20 base::WrapUnique(new WorkspaceLayoutManager(viewport, nullptr)));
21 WmShell::Get()->AddShellObserver(GetLayoutManager());
20 // Container should be empty. 22 // Container should be empty.
21 DCHECK(always_on_top_container_->GetChildren().empty()); 23 DCHECK(always_on_top_container_->GetChildren().empty());
22 always_on_top_container_->AddObserver(this); 24 always_on_top_container_->AddObserver(this);
23 } 25 }
24 26
25 AlwaysOnTopController::~AlwaysOnTopController() { 27 AlwaysOnTopController::~AlwaysOnTopController() {
26 if (always_on_top_container_) 28 if (always_on_top_container_) {
27 always_on_top_container_->RemoveObserver(this); 29 always_on_top_container_->RemoveObserver(this);
30 WmShell::Get()->RemoveShellObserver(GetLayoutManager());
31 }
28 } 32 }
29 33
30 WmWindow* AlwaysOnTopController::GetContainer(WmWindow* window) const { 34 WmWindow* AlwaysOnTopController::GetContainer(WmWindow* window) const {
31 DCHECK(always_on_top_container_); 35 DCHECK(always_on_top_container_);
32 if (window->GetBoolProperty(WmWindowProperty::ALWAYS_ON_TOP)) 36 if (window->GetBoolProperty(WmWindowProperty::ALWAYS_ON_TOP))
33 return always_on_top_container_; 37 return always_on_top_container_;
34 return always_on_top_container_->GetRootWindow()->GetChildByShellWindowId( 38 return always_on_top_container_->GetRootWindow()->GetChildByShellWindowId(
35 kShellWindowId_DefaultContainer); 39 kShellWindowId_DefaultContainer);
36 } 40 }
37 41
38 // TODO(rsadam@): Refactor so that this cast is unneeded. 42 // TODO(rsadam@): Refactor so that this cast is unneeded.
39 WorkspaceLayoutManager* AlwaysOnTopController::GetLayoutManager() const { 43 WorkspaceLayoutManager* AlwaysOnTopController::GetLayoutManager() const {
40 return static_cast<WorkspaceLayoutManager*>( 44 return static_cast<WorkspaceLayoutManager*>(
41 always_on_top_container_->GetLayoutManager()); 45 always_on_top_container_->GetLayoutManager());
42 } 46 }
43 47
44 void AlwaysOnTopController::SetLayoutManagerForTest( 48 void AlwaysOnTopController::SetLayoutManagerForTest(
45 std::unique_ptr<WorkspaceLayoutManager> layout_manager) { 49 std::unique_ptr<WorkspaceLayoutManager> layout_manager) {
50 WmShell::Get()->RemoveShellObserver(GetLayoutManager());
46 always_on_top_container_->SetLayoutManager(std::move(layout_manager)); 51 always_on_top_container_->SetLayoutManager(std::move(layout_manager));
52 WmShell::Get()->AddShellObserver(GetLayoutManager());
47 } 53 }
48 54
49 void AlwaysOnTopController::OnWindowTreeChanged( 55 void AlwaysOnTopController::OnWindowTreeChanged(
50 WmWindow* window, 56 WmWindow* window,
51 const TreeChangeParams& params) { 57 const TreeChangeParams& params) {
52 if (params.old_parent == always_on_top_container_) 58 if (params.old_parent == always_on_top_container_)
53 params.target->RemoveObserver(this); 59 params.target->RemoveObserver(this);
54 else if (params.new_parent == always_on_top_container_) 60 else if (params.new_parent == always_on_top_container_)
55 params.target->AddObserver(this); 61 params.target->AddObserver(this);
56 } 62 }
57 63
58 void AlwaysOnTopController::OnWindowPropertyChanged(WmWindow* window, 64 void AlwaysOnTopController::OnWindowPropertyChanged(WmWindow* window,
59 WmWindowProperty property) { 65 WmWindowProperty property) {
60 if (window != always_on_top_container_ && 66 if (window != always_on_top_container_ &&
61 property == WmWindowProperty::ALWAYS_ON_TOP) { 67 property == WmWindowProperty::ALWAYS_ON_TOP) {
62 DCHECK(window->GetType() == ui::wm::WINDOW_TYPE_NORMAL || 68 DCHECK(window->GetType() == ui::wm::WINDOW_TYPE_NORMAL ||
63 window->GetType() == ui::wm::WINDOW_TYPE_POPUP); 69 window->GetType() == ui::wm::WINDOW_TYPE_POPUP);
64 WmWindow* container = GetContainer(window); 70 WmWindow* container = GetContainer(window);
65 if (window->GetParent() != container) 71 if (window->GetParent() != container)
66 container->AddChild(window); 72 container->AddChild(window);
67 } 73 }
68 } 74 }
69 75
70 void AlwaysOnTopController::OnWindowDestroying(WmWindow* window) { 76 void AlwaysOnTopController::OnWindowDestroying(WmWindow* window) {
71 if (window == always_on_top_container_) { 77 if (window == always_on_top_container_) {
72 always_on_top_container_->RemoveObserver(this); 78 always_on_top_container_->RemoveObserver(this);
79 WmShell::Get()->RemoveShellObserver(GetLayoutManager());
73 always_on_top_container_ = nullptr; 80 always_on_top_container_ = nullptr;
74 } 81 }
75 } 82 }
76 83
77 } // namespace ash 84 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698