| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/mus/bridge/mus_layout_manager_adapter.h" | 5 #include "ash/mus/bridge/mus_layout_manager_adapter.h" |
| 6 | 6 |
| 7 #include "ash/common/wm_layout_manager.h" | 7 #include "ash/common/wm_layout_manager.h" |
| 8 #include "ash/mus/bridge/wm_window_mus.h" | 8 #include "ash/mus/bridge/wm_window_mus.h" |
| 9 #include "services/ui/public/cpp/window.h" | 9 #include "services/ui/public/cpp/window.h" |
| 10 | 10 |
| 11 namespace ash { | 11 namespace ash { |
| 12 namespace mus { | 12 namespace mus { |
| 13 | 13 |
| 14 MusLayoutManagerAdapter::ChildWindowObserver::ChildWindowObserver( | 14 MusLayoutManagerAdapter::ChildWindowObserver::ChildWindowObserver( |
| 15 MusLayoutManagerAdapter* adapter) | 15 MusLayoutManagerAdapter* adapter) |
| 16 : adapter_(adapter) {} | 16 : adapter_(adapter) {} |
| 17 | 17 |
| 18 MusLayoutManagerAdapter::ChildWindowObserver::~ChildWindowObserver() {} | 18 MusLayoutManagerAdapter::ChildWindowObserver::~ChildWindowObserver() {} |
| 19 | 19 |
| 20 void MusLayoutManagerAdapter::ChildWindowObserver::OnWindowVisibilityChanged( | 20 void MusLayoutManagerAdapter::ChildWindowObserver::OnWindowVisibilityChanged( |
| 21 ::ui::Window* window) { | 21 ui::Window* window) { |
| 22 adapter_->layout_manager_->OnChildWindowVisibilityChanged( | 22 adapter_->layout_manager_->OnChildWindowVisibilityChanged( |
| 23 WmWindowMus::Get(window), window->visible()); | 23 WmWindowMus::Get(window), window->visible()); |
| 24 } | 24 } |
| 25 | 25 |
| 26 MusLayoutManagerAdapter::MusLayoutManagerAdapter( | 26 MusLayoutManagerAdapter::MusLayoutManagerAdapter( |
| 27 ::ui::Window* window, | 27 ui::Window* window, |
| 28 std::unique_ptr<WmLayoutManager> layout_manager) | 28 std::unique_ptr<WmLayoutManager> layout_manager) |
| 29 : window_(window), | 29 : window_(window), |
| 30 child_window_observer_(this), | 30 child_window_observer_(this), |
| 31 layout_manager_(std::move(layout_manager)) { | 31 layout_manager_(std::move(layout_manager)) { |
| 32 window_->AddObserver(this); | 32 window_->AddObserver(this); |
| 33 for (::ui::Window* child : window_->children()) | 33 for (ui::Window* child : window_->children()) |
| 34 child->AddObserver(&child_window_observer_); | 34 child->AddObserver(&child_window_observer_); |
| 35 } | 35 } |
| 36 | 36 |
| 37 MusLayoutManagerAdapter::~MusLayoutManagerAdapter() { | 37 MusLayoutManagerAdapter::~MusLayoutManagerAdapter() { |
| 38 for (::ui::Window* child : window_->children()) | 38 for (ui::Window* child : window_->children()) |
| 39 child->RemoveObserver(&child_window_observer_); | 39 child->RemoveObserver(&child_window_observer_); |
| 40 | 40 |
| 41 window_->RemoveObserver(this); | 41 window_->RemoveObserver(this); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void MusLayoutManagerAdapter::OnTreeChanging(const TreeChangeParams& params) { | 44 void MusLayoutManagerAdapter::OnTreeChanging(const TreeChangeParams& params) { |
| 45 if (params.old_parent == window_) { | 45 if (params.old_parent == window_) { |
| 46 layout_manager_->OnWillRemoveWindowFromLayout( | 46 layout_manager_->OnWillRemoveWindowFromLayout( |
| 47 WmWindowMus::Get(params.target)); | 47 WmWindowMus::Get(params.target)); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 void MusLayoutManagerAdapter::OnTreeChanged(const TreeChangeParams& params) { | 51 void MusLayoutManagerAdapter::OnTreeChanged(const TreeChangeParams& params) { |
| 52 if (params.new_parent == window_) { | 52 if (params.new_parent == window_) { |
| 53 layout_manager_->OnWindowAddedToLayout(WmWindowMus::Get(params.target)); | 53 layout_manager_->OnWindowAddedToLayout(WmWindowMus::Get(params.target)); |
| 54 params.target->AddObserver(&child_window_observer_); | 54 params.target->AddObserver(&child_window_observer_); |
| 55 } else if (params.old_parent == window_) { | 55 } else if (params.old_parent == window_) { |
| 56 params.target->RemoveObserver(&child_window_observer_); | 56 params.target->RemoveObserver(&child_window_observer_); |
| 57 layout_manager_->OnWindowRemovedFromLayout(WmWindowMus::Get(params.target)); | 57 layout_manager_->OnWindowRemovedFromLayout(WmWindowMus::Get(params.target)); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 void MusLayoutManagerAdapter::OnWindowBoundsChanged( | 61 void MusLayoutManagerAdapter::OnWindowBoundsChanged( |
| 62 ::ui::Window* window, | 62 ui::Window* window, |
| 63 const gfx::Rect& old_bounds, | 63 const gfx::Rect& old_bounds, |
| 64 const gfx::Rect& new_bounds) { | 64 const gfx::Rect& new_bounds) { |
| 65 layout_manager_->OnWindowResized(); | 65 layout_manager_->OnWindowResized(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace mus | 68 } // namespace mus |
| 69 } // namespace ash | 69 } // namespace ash |
| OLD | NEW |