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