| 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 #ifndef SERVICES_UI_PUBLIC_CPP_SCOPED_WINDOW_PTR_H_ | 5 #ifndef SERVICES_UI_PUBLIC_CPP_SCOPED_WINDOW_PTR_H_ |
| 6 #define SERVICES_UI_PUBLIC_CPP_SCOPED_WINDOW_PTR_H_ | 6 #define SERVICES_UI_PUBLIC_CPP_SCOPED_WINDOW_PTR_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "services/ui/public/cpp/ui_export.h" |
| 9 #include "services/ui/public/cpp/window_observer.h" | 10 #include "services/ui/public/cpp/window_observer.h" |
| 10 | 11 |
| 11 namespace ui { | 12 namespace ui { |
| 12 | 13 |
| 13 // Wraps a Window, taking overship of the Window. Also deals with Window being | 14 // Wraps a Window, taking overship of the Window. Also deals with Window being |
| 14 // destroyed while ScopedWindowPtr still exists. | 15 // destroyed while ScopedWindowPtr still exists. |
| 15 class ScopedWindowPtr : public WindowObserver { | 16 class UI_EXPORT ScopedWindowPtr : public WindowObserver { |
| 16 public: | 17 public: |
| 17 explicit ScopedWindowPtr(Window* window); | 18 explicit ScopedWindowPtr(Window* window); |
| 18 ~ScopedWindowPtr() override; | 19 ~ScopedWindowPtr() override; |
| 19 | 20 |
| 20 // Destroys |window|. If |window| is a root of the WindowManager than the | 21 // Destroys |window|. If |window| is a root of the WindowManager than the |
| 21 // WindowManager is destroyed (which in turn destroys |window|). | 22 // WindowManager is destroyed (which in turn destroys |window|). |
| 22 // | 23 // |
| 23 // NOTE: this function (and class) are only useful for clients that only | 24 // NOTE: this function (and class) are only useful for clients that only |
| 24 // ever have a single root. | 25 // ever have a single root. |
| 25 static void DeleteWindowOrWindowManager(Window* window); | 26 static void DeleteWindowOrWindowManager(Window* window); |
| 26 | 27 |
| 27 Window* window() { return window_; } | 28 Window* window() { return window_; } |
| 28 const Window* window() const { return window_; } | 29 const Window* window() const { return window_; } |
| 29 | 30 |
| 30 private: | 31 private: |
| 31 void DetachFromWindow(); | 32 void DetachFromWindow(); |
| 32 | 33 |
| 33 void OnWindowDestroying(Window* window) override; | 34 void OnWindowDestroying(Window* window) override; |
| 34 | 35 |
| 35 Window* window_; | 36 Window* window_; |
| 36 | 37 |
| 37 DISALLOW_COPY_AND_ASSIGN(ScopedWindowPtr); | 38 DISALLOW_COPY_AND_ASSIGN(ScopedWindowPtr); |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 } // namespace ui | 41 } // namespace ui |
| 41 | 42 |
| 42 #endif // SERVICES_UI_PUBLIC_CPP_SCOPED_WINDOW_PTR_H_ | 43 #endif // SERVICES_UI_PUBLIC_CPP_SCOPED_WINDOW_PTR_H_ |
| OLD | NEW |