Commit fe83284b authored by Allen Bauer's avatar Allen Bauer Committed by Commit Bot

Add std::unique_ptr<T> RemoveChildViewT().

Renamed to avoid all the fun-and-games of overload resolution with template functions.

Part of the overall effort to eliminate the need for and eventual removal of set_owned_by_client().

Bug: 1044687
Change-Id: I4f728af6e17b3c6c804db7eda58f0fb6d426d5f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2068878
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746505}
parent 59f29b79
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkPath.h"
#include "ui/accessibility/ax_enums.mojom-forward.h" #include "ui/accessibility/ax_enums.mojom-forward.h"
...@@ -434,6 +435,21 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, ...@@ -434,6 +435,21 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// Removes |view| from this view. The view's parent will change to null. // Removes |view| from this view. The view's parent will change to null.
void RemoveChildView(View* view); void RemoveChildView(View* view);
// Removes |view| from this view and transfers ownership back to the caller in
// the form of a std::unique_ptr<T>.
// TODO(kylixrd): Rename back to RemoveChildView() once the code is refactored
// to eliminate the uses of the old RemoveChildView().
template <typename T>
std::unique_ptr<T> RemoveChildViewT(T* view) {
DCHECK(!view->owned_by_client())
<< "This should only be called if the client doesn't already have "
"ownership of |view|.";
DCHECK(std::find(children_.cbegin(), children_.cend(), view) !=
children_.cend());
RemoveChildView(view);
return base::WrapUnique(view);
}
// Removes all the children from this view. If |delete_children| is true, // Removes all the children from this view. If |delete_children| is true,
// the views are deleted, unless marked as not parent owned. // the views are deleted, unless marked as not parent owned.
void RemoveAllChildViews(bool delete_children); void RemoveAllChildViews(bool delete_children);
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment