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