| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MASH_WM_BRIDGE_MUS_LAYOUT_MANAGER_ADAPTER_H_ |
| 6 #define MASH_WM_BRIDGE_MUS_LAYOUT_MANAGER_ADAPTER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "components/mus/public/cpp/window_observer.h" |
| 12 |
| 13 namespace ash { |
| 14 namespace wm { |
| 15 class WmLayoutManager; |
| 16 } |
| 17 } |
| 18 |
| 19 namespace mash { |
| 20 namespace wm { |
| 21 |
| 22 // Used to associate a mus::Window with an ash::wm::WmLayoutManager. This |
| 23 // attaches an observer to the mus::Window and calls the appropriate methods on |
| 24 // the WmLayoutManager at the appropriate time. |
| 25 // |
| 26 // NOTE: WmLayoutManager provides the function SetChildBounds(). This is |
| 27 // expected to be called to change the bounds of the Window. For aura this |
| 28 // function is called by way of aura exposing a hook (aura::LayoutManager). Mus |
| 29 // has no such hook. To ensure SetChildBounds() is called correctly all bounds |
| 30 // changes to mus::Windows must be routed through WmWindowMus. WmWindowMus |
| 31 // ensures WmLayoutManager::SetChildBounds() is called appropriately. |
| 32 class MusLayoutManagerAdapter : public mus::WindowObserver { |
| 33 public: |
| 34 MusLayoutManagerAdapter( |
| 35 mus::Window* window, |
| 36 std::unique_ptr<ash::wm::WmLayoutManager> layout_manager); |
| 37 ~MusLayoutManagerAdapter() override; |
| 38 |
| 39 ash::wm::WmLayoutManager* layout_manager() { return layout_manager_.get(); } |
| 40 |
| 41 private: |
| 42 // WindowObserver attached to child windows. A separate class is used to |
| 43 // easily differentiate WindowObserver calls on the mus::Window associated |
| 44 // with the MusLayoutManagerAdapter, vs children. |
| 45 class ChildWindowObserver : public mus::WindowObserver { |
| 46 public: |
| 47 explicit ChildWindowObserver(MusLayoutManagerAdapter* adapter); |
| 48 ~ChildWindowObserver() override; |
| 49 |
| 50 private: |
| 51 // mus::WindowObserver: |
| 52 void OnWindowVisibilityChanged(mus::Window* window) override; |
| 53 |
| 54 MusLayoutManagerAdapter* adapter_; |
| 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(ChildWindowObserver); |
| 57 }; |
| 58 |
| 59 // mus::WindowObserver: |
| 60 void OnTreeChanging(const TreeChangeParams& params) override; |
| 61 void OnTreeChanged(const TreeChangeParams& params) override; |
| 62 void OnWindowBoundsChanged(mus::Window* window, |
| 63 const gfx::Rect& old_bounds, |
| 64 const gfx::Rect& new_bounds) override; |
| 65 |
| 66 mus::Window* window_; |
| 67 ChildWindowObserver child_window_observer_; |
| 68 std::unique_ptr<ash::wm::WmLayoutManager> layout_manager_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(MusLayoutManagerAdapter); |
| 71 }; |
| 72 |
| 73 } // namespace wm |
| 74 } // namespace mash |
| 75 |
| 76 #endif // MASH_WM_BRIDGE_MUS_LAYOUT_MANAGER_ADAPTER_H_ |
| OLD | NEW |