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