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