Chromium Code Reviews| 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/shell.h" | 7 #include "ash/wm/common/wm_shell_window_ids.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/wm/common/wm_window.h" |
| 9 #include "ash/wm/common/wm_window_property.h" | |
| 9 #include "ash/wm/common/workspace/workspace_layout_manager_delegate.h" | 10 #include "ash/wm/common/workspace/workspace_layout_manager_delegate.h" |
| 10 #include "ash/wm/workspace/workspace_layout_manager.h" | 11 #include "ash/wm/workspace/workspace_layout_manager.h" |
| 11 #include "ui/aura/client/aura_constants.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "ui/aura/window.h" | |
| 13 | 13 |
| 14 namespace ash { | 14 namespace ash { |
| 15 | 15 |
| 16 AlwaysOnTopController::AlwaysOnTopController(aura::Window* viewport) | 16 AlwaysOnTopController::AlwaysOnTopController(wm::WmWindow* viewport) |
| 17 : always_on_top_container_(viewport) { | 17 : always_on_top_container_(viewport) { |
| 18 always_on_top_container_->SetLayoutManager( | 18 always_on_top_container_->SetLayoutManager( |
| 19 new WorkspaceLayoutManager(viewport, nullptr)); | 19 base::WrapUnique(new WorkspaceLayoutManager(viewport, nullptr))); |
| 20 // Container should be empty. | 20 // Container should be empty. |
| 21 DCHECK(always_on_top_container_->children().empty()); | 21 DCHECK(always_on_top_container_->GetChildren().empty()); |
| 22 always_on_top_container_->AddObserver(this); | 22 always_on_top_container_->AddObserver(this); |
| 23 } | 23 } |
| 24 | 24 |
| 25 AlwaysOnTopController::~AlwaysOnTopController() { | 25 AlwaysOnTopController::~AlwaysOnTopController() { |
| 26 if (always_on_top_container_) | 26 if (always_on_top_container_) |
| 27 always_on_top_container_->RemoveObserver(this); | 27 always_on_top_container_->RemoveObserver(this); |
| 28 } | 28 } |
| 29 | 29 |
| 30 aura::Window* AlwaysOnTopController::GetContainer(aura::Window* window) const { | 30 wm::WmWindow* AlwaysOnTopController::GetContainer(wm::WmWindow* window) const { |
| 31 DCHECK(always_on_top_container_); | 31 DCHECK(always_on_top_container_); |
| 32 if (window->GetProperty(aura::client::kAlwaysOnTopKey)) | 32 if (window->GetBoolProperty(wm::WmWindowProperty::ALWAYS_ON_TOP)) |
| 33 return always_on_top_container_; | 33 return always_on_top_container_; |
| 34 return Shell::GetContainer(always_on_top_container_->GetRootWindow(), | 34 return always_on_top_container_->GetRootWindow()->GetChildByShellWindowId( |
| 35 kShellWindowId_DefaultContainer); | 35 kShellWindowId_DefaultContainer); |
| 36 } | |
| 37 | |
| 38 void AlwaysOnTopController::OnWindowAdded(aura::Window* child) { | |
| 39 // Observe direct child of the containers. | |
| 40 if (child->parent() == always_on_top_container_) | |
| 41 child->AddObserver(this); | |
| 42 } | |
| 43 | |
| 44 void AlwaysOnTopController::SetLayoutManagerForTest( | |
| 45 WorkspaceLayoutManager* layout_manager) { | |
| 46 always_on_top_container_->SetLayoutManager(layout_manager); | |
| 47 } | 36 } |
| 48 | 37 |
| 49 // TODO(rsadam@): Refactor so that this cast is unneeded. | 38 // TODO(rsadam@): Refactor so that this cast is unneeded. |
| 50 WorkspaceLayoutManager* AlwaysOnTopController::GetLayoutManager() const { | 39 WorkspaceLayoutManager* AlwaysOnTopController::GetLayoutManager() const { |
| 51 return static_cast<WorkspaceLayoutManager*>( | 40 return static_cast<WorkspaceLayoutManager*>( |
| 52 always_on_top_container_->layout_manager()); | 41 always_on_top_container_->GetLayoutManager()); |
| 53 } | 42 } |
| 54 | 43 |
| 55 void AlwaysOnTopController::OnWillRemoveWindow(aura::Window* child) { | 44 void AlwaysOnTopController::SetLayoutManagerForTest( |
| 56 child->RemoveObserver(this); | 45 std::unique_ptr<WorkspaceLayoutManager> layout_manager) { |
| 46 always_on_top_container_->SetLayoutManager(std::move(layout_manager)); | |
| 57 } | 47 } |
| 58 | 48 |
| 59 void AlwaysOnTopController::OnWindowPropertyChanged(aura::Window* window, | 49 void AlwaysOnTopController::OnWindowTreeChanged( |
| 60 const void* key, | 50 wm::WmWindow* window, |
| 61 intptr_t old) { | 51 const TreeChangeParams& params) { |
| 62 if (key == aura::client::kAlwaysOnTopKey) { | 52 if (window != always_on_top_container_) |
| 63 DCHECK(window->type() == ui::wm::WINDOW_TYPE_NORMAL || | 53 return; |
| 64 window->type() == ui::wm::WINDOW_TYPE_POPUP); | 54 |
| 65 aura::Window* container = GetContainer(window); | 55 if (params.old_parent == always_on_top_container_) |
| 66 if (window->parent() != container) | 56 params.target->RemoveObserver(this); |
| 57 else if (params.new_parent == always_on_top_container_) | |
| 58 params.target->AddObserver(this); | |
| 59 } | |
| 60 | |
| 61 void AlwaysOnTopController::OnWindowPropertyChanged( | |
| 62 wm::WmWindow* window, | |
| 63 wm::WmWindowProperty property, | |
| 64 intptr_t old) { | |
| 65 if (window != always_on_top_container_ && | |
| 66 property == wm::WmWindowProperty::ALWAYS_ON_TOP) { | |
| 67 DCHECK(window->GetType() == ui::wm::WINDOW_TYPE_NORMAL || | |
| 68 window->GetType() == ui::wm::WINDOW_TYPE_POPUP); | |
| 69 wm::WmWindow* container = GetContainer(window); | |
| 70 if (window->GetParent() != container) | |
| 67 container->AddChild(window); | 71 container->AddChild(window); |
| 68 } | 72 } |
| 69 } | 73 } |
| 70 | 74 |
| 71 void AlwaysOnTopController::OnWindowDestroyed(aura::Window* window) { | 75 void AlwaysOnTopController::OnWindowDestroying(wm::WmWindow* window) { |
|
sky
2016/04/27 20:48:05
I'm hoping the order doesn't really matter here (b
James Cook
2016/04/27 23:24:24
Acknowledged.
| |
| 72 if (window == always_on_top_container_) | 76 if (window == always_on_top_container_) { |
| 73 always_on_top_container_ = NULL; | 77 always_on_top_container_->RemoveObserver(this); |
| 78 always_on_top_container_ = nullptr; | |
| 79 } | |
| 74 } | 80 } |
| 75 | 81 |
| 76 } // namespace ash | 82 } // namespace ash |
| OLD | NEW |