| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/layout_manager.h" | 5 #include "ash/mus/layout_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "services/ui/public/cpp/property_type_converters.h" | 9 #include "services/ui/public/cpp/property_type_converters.h" |
| 10 #include "services/ui/public/cpp/window.h" | 10 #include "services/ui/public/cpp/window.h" |
| 11 #include "services/ui/public/cpp/window_property.h" | 11 #include "services/ui/public/cpp/window_property.h" |
| 12 | 12 |
| 13 namespace ash { | 13 namespace ash { |
| 14 namespace mus { | 14 namespace mus { |
| 15 | 15 |
| 16 LayoutManager::~LayoutManager() { | 16 LayoutManager::~LayoutManager() { |
| 17 Uninstall(); | 17 Uninstall(); |
| 18 } | 18 } |
| 19 | 19 |
| 20 LayoutManager::LayoutManager(::ui::Window* owner) : owner_(owner) { | 20 LayoutManager::LayoutManager(ui::Window* owner) : owner_(owner) { |
| 21 owner_->AddObserver(this); | 21 owner_->AddObserver(this); |
| 22 DCHECK(owner->children().empty()); | 22 DCHECK(owner->children().empty()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void LayoutManager::Uninstall() { | 25 void LayoutManager::Uninstall() { |
| 26 if (!owner_) | 26 if (!owner_) |
| 27 return; | 27 return; |
| 28 owner_->RemoveObserver(this); | 28 owner_->RemoveObserver(this); |
| 29 for (auto* child : owner_->children()) | 29 for (auto* child : owner_->children()) |
| 30 child->RemoveObserver(this); | 30 child->RemoveObserver(this); |
| 31 owner_ = nullptr; | 31 owner_ = nullptr; |
| 32 } | 32 } |
| 33 | 33 |
| 34 void LayoutManager::OnTreeChanged( | 34 void LayoutManager::OnTreeChanged( |
| 35 const ::ui::WindowObserver::TreeChangeParams& params) { | 35 const ui::WindowObserver::TreeChangeParams& params) { |
| 36 DCHECK(params.target); | 36 DCHECK(params.target); |
| 37 if (params.new_parent == owner_) { | 37 if (params.new_parent == owner_) { |
| 38 // params.target was added to the layout. | 38 // params.target was added to the layout. |
| 39 WindowAdded(params.target); | 39 WindowAdded(params.target); |
| 40 params.target->AddObserver(this); | 40 params.target->AddObserver(this); |
| 41 LayoutWindow(params.target); | 41 LayoutWindow(params.target); |
| 42 } else if (params.old_parent == owner_) { | 42 } else if (params.old_parent == owner_) { |
| 43 // params.target was removed from the layout. | 43 // params.target was removed from the layout. |
| 44 params.target->RemoveObserver(this); | 44 params.target->RemoveObserver(this); |
| 45 WindowRemoved(params.target); | 45 WindowRemoved(params.target); |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 void LayoutManager::OnWindowDestroying(::ui::Window* window) { | 49 void LayoutManager::OnWindowDestroying(ui::Window* window) { |
| 50 if (owner_ == window) | 50 if (owner_ == window) |
| 51 Uninstall(); | 51 Uninstall(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void LayoutManager::OnWindowBoundsChanged(::ui::Window* window, | 54 void LayoutManager::OnWindowBoundsChanged(ui::Window* window, |
| 55 const gfx::Rect& old_bounds, | 55 const gfx::Rect& old_bounds, |
| 56 const gfx::Rect& new_bounds) { | 56 const gfx::Rect& new_bounds) { |
| 57 if (window != owner_) | 57 if (window != owner_) |
| 58 return; | 58 return; |
| 59 | 59 |
| 60 // Changes to the container's bounds require all windows to be laid out. | 60 // Changes to the container's bounds require all windows to be laid out. |
| 61 for (auto* child : window->children()) | 61 for (auto* child : window->children()) |
| 62 LayoutWindow(child); | 62 LayoutWindow(child); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void LayoutManager::OnWindowSharedPropertyChanged( | 65 void LayoutManager::OnWindowSharedPropertyChanged( |
| 66 ::ui::Window* window, | 66 ui::Window* window, |
| 67 const std::string& name, | 67 const std::string& name, |
| 68 const std::vector<uint8_t>* old_data, | 68 const std::vector<uint8_t>* old_data, |
| 69 const std::vector<uint8_t>* new_data) { | 69 const std::vector<uint8_t>* new_data) { |
| 70 if (window == owner_) | 70 if (window == owner_) |
| 71 return; | 71 return; |
| 72 | 72 |
| 73 // Changes to the following properties require the window to be laid out. | 73 // Changes to the following properties require the window to be laid out. |
| 74 if (layout_properties_.count(name) > 0) | 74 if (layout_properties_.count(name) > 0) |
| 75 LayoutWindow(window); | 75 LayoutWindow(window); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void LayoutManager::WindowAdded(::ui::Window* window) {} | 78 void LayoutManager::WindowAdded(ui::Window* window) {} |
| 79 void LayoutManager::WindowRemoved(::ui::Window* window) {} | 79 void LayoutManager::WindowRemoved(ui::Window* window) {} |
| 80 | 80 |
| 81 void LayoutManager::AddLayoutProperty(const std::string& name) { | 81 void LayoutManager::AddLayoutProperty(const std::string& name) { |
| 82 layout_properties_.insert(name); | 82 layout_properties_.insert(name); |
| 83 } | 83 } |
| 84 | 84 |
| 85 } // namespace mus | 85 } // namespace mus |
| 86 } // namespace ash | 86 } // namespace ash |
| OLD | NEW |