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/wm/always_on_top_controller.h" | 5 #include "ash/wm/always_on_top_controller.h" |
6 | 6 |
7 #include "ash/public/cpp/shell_window_ids.h" | 7 #include "ash/public/cpp/shell_window_ids.h" |
8 #include "ash/wm/workspace/workspace_layout_manager.h" | 8 #include "ash/wm/workspace/workspace_layout_manager.h" |
9 #include "ash/wm_window.h" | |
10 #include "ui/aura/client/aura_constants.h" | 9 #include "ui/aura/client/aura_constants.h" |
11 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
12 | 11 |
13 namespace ash { | 12 namespace ash { |
14 | 13 |
15 AlwaysOnTopController::AlwaysOnTopController(WmWindow* viewport) | 14 AlwaysOnTopController::AlwaysOnTopController(aura::Window* viewport) |
16 : always_on_top_container_(viewport) { | 15 : always_on_top_container_(viewport) { |
17 DCHECK_NE(kShellWindowId_DefaultContainer, viewport->aura_window()->id()); | 16 DCHECK_NE(kShellWindowId_DefaultContainer, viewport->id()); |
18 always_on_top_container_->aura_window()->SetLayoutManager( | 17 always_on_top_container_->SetLayoutManager( |
19 new WorkspaceLayoutManager(viewport->aura_window())); | 18 new WorkspaceLayoutManager(viewport)); |
20 // Container should be empty. | 19 // Container should be empty. |
21 DCHECK(always_on_top_container_->GetChildren().empty()); | 20 DCHECK(always_on_top_container_->children().empty()); |
22 always_on_top_container_->aura_window()->AddObserver(this); | 21 always_on_top_container_->AddObserver(this); |
23 } | 22 } |
24 | 23 |
25 AlwaysOnTopController::~AlwaysOnTopController() { | 24 AlwaysOnTopController::~AlwaysOnTopController() { |
26 if (always_on_top_container_) | 25 if (always_on_top_container_) |
27 always_on_top_container_->aura_window()->RemoveObserver(this); | 26 always_on_top_container_->RemoveObserver(this); |
28 } | 27 } |
29 | 28 |
30 WmWindow* AlwaysOnTopController::GetContainer(WmWindow* window) const { | 29 aura::Window* AlwaysOnTopController::GetContainer(aura::Window* window) const { |
31 DCHECK(always_on_top_container_); | 30 DCHECK(always_on_top_container_); |
32 if (window->aura_window()->GetProperty(aura::client::kAlwaysOnTopKey)) | 31 if (window->GetProperty(aura::client::kAlwaysOnTopKey)) |
33 return always_on_top_container_; | 32 return always_on_top_container_; |
34 return always_on_top_container_->GetRootWindow()->GetChildByShellWindowId( | 33 return always_on_top_container_->GetRootWindow()->GetChildById( |
35 kShellWindowId_DefaultContainer); | 34 kShellWindowId_DefaultContainer); |
36 } | 35 } |
37 | 36 |
38 // TODO(rsadam@): Refactor so that this cast is unneeded. | 37 // TODO(rsadam@): Refactor so that this cast is unneeded. |
39 WorkspaceLayoutManager* AlwaysOnTopController::GetLayoutManager() const { | 38 WorkspaceLayoutManager* AlwaysOnTopController::GetLayoutManager() const { |
40 return static_cast<WorkspaceLayoutManager*>( | 39 return static_cast<WorkspaceLayoutManager*>( |
41 always_on_top_container_->aura_window()->layout_manager()); | 40 always_on_top_container_->layout_manager()); |
42 } | 41 } |
43 | 42 |
44 void AlwaysOnTopController::SetLayoutManagerForTest( | 43 void AlwaysOnTopController::SetLayoutManagerForTest( |
45 std::unique_ptr<WorkspaceLayoutManager> layout_manager) { | 44 std::unique_ptr<WorkspaceLayoutManager> layout_manager) { |
46 always_on_top_container_->aura_window()->SetLayoutManager( | 45 always_on_top_container_->SetLayoutManager(layout_manager.release()); |
47 layout_manager.release()); | |
48 } | 46 } |
49 | 47 |
50 void AlwaysOnTopController::OnWindowHierarchyChanged( | 48 void AlwaysOnTopController::OnWindowHierarchyChanged( |
51 const HierarchyChangeParams& params) { | 49 const HierarchyChangeParams& params) { |
52 if (WmWindow::Get(params.old_parent) == always_on_top_container_) | 50 if (params.old_parent == always_on_top_container_) |
53 params.target->RemoveObserver(this); | 51 params.target->RemoveObserver(this); |
54 else if (WmWindow::Get(params.new_parent) == always_on_top_container_) | 52 else if (params.new_parent == always_on_top_container_) |
55 params.target->AddObserver(this); | 53 params.target->AddObserver(this); |
56 } | 54 } |
57 | 55 |
58 void AlwaysOnTopController::OnWindowPropertyChanged(aura::Window* window, | 56 void AlwaysOnTopController::OnWindowPropertyChanged(aura::Window* window, |
59 const void* key, | 57 const void* key, |
60 intptr_t old) { | 58 intptr_t old) { |
61 if (WmWindow::Get(window) != always_on_top_container_ && | 59 if (window != always_on_top_container_ && |
62 key == aura::client::kAlwaysOnTopKey) { | 60 key == aura::client::kAlwaysOnTopKey) { |
63 DCHECK(window->type() == ui::wm::WINDOW_TYPE_NORMAL || | 61 DCHECK(window->type() == ui::wm::WINDOW_TYPE_NORMAL || |
64 window->type() == ui::wm::WINDOW_TYPE_POPUP); | 62 window->type() == ui::wm::WINDOW_TYPE_POPUP); |
65 WmWindow* container = GetContainer(WmWindow::Get(window)); | 63 aura::Window* container = GetContainer(window); |
66 if (WmWindow::Get(window->parent()) != container) | 64 if (window->parent() != container) |
67 container->AddChild(WmWindow::Get(window)); | 65 container->AddChild(window); |
68 } | 66 } |
69 } | 67 } |
70 | 68 |
71 void AlwaysOnTopController::OnWindowDestroying(aura::Window* window) { | 69 void AlwaysOnTopController::OnWindowDestroying(aura::Window* window) { |
72 if (WmWindow::Get(window) == always_on_top_container_) { | 70 if (window == always_on_top_container_) { |
73 always_on_top_container_->aura_window()->RemoveObserver(this); | 71 always_on_top_container_->RemoveObserver(this); |
74 always_on_top_container_ = nullptr; | 72 always_on_top_container_ = nullptr; |
75 } | 73 } |
76 } | 74 } |
77 | 75 |
78 } // namespace ash | 76 } // namespace ash |
OLD | NEW |