Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(593)

Unified Diff: ui/views/view.cc

Issue 2713643002: Add View::AddedToWidget and RemovedFromWidget. (Closed)
Patch Set: Review fixes. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/view.h ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/view.cc
diff --git a/ui/views/view.cc b/ui/views/view.cc
index 04c5f2fae25957c3ca3b706654e263fc8b3c6638..897dacd1b3f7228e410a521a018f4c70d9758491 100644
--- a/ui/views/view.cc
+++ b/ui/views/view.cc
@@ -195,9 +195,11 @@ void View::AddChildViewAt(View* view, int index) {
// If |view| has a parent, remove it from its parent.
View* parent = view->parent_;
- ui::NativeTheme* old_theme = NULL;
+ ui::NativeTheme* old_theme = nullptr;
+ Widget* old_widget = nullptr;
if (parent) {
old_theme = view->GetNativeTheme();
+ old_widget = view->GetWidget();
if (parent == this) {
ReorderChildView(view, index);
return;
@@ -241,7 +243,7 @@ void View::AddChildViewAt(View* view, int index) {
for (View* v = this; v; v = v->parent_)
v->ViewHierarchyChangedImpl(false, details);
- view->PropagateAddNotifications(details);
+ view->PropagateAddNotifications(details, widget && widget != old_widget);
UpdateTooltip();
@@ -1516,6 +1518,10 @@ void View::NativeViewHierarchyChanged() {
}
}
+void View::AddedToWidget() {}
+
+void View::RemovedFromWidget() {}
+
// Painting --------------------------------------------------------------------
void View::PaintChildren(const ui::PaintContext& context) {
@@ -1929,12 +1935,14 @@ void View::DoRemoveChildView(View* view,
}
Widget* widget = GetWidget();
+ bool is_removed_from_widget = false;
if (widget) {
UnregisterChildrenForVisibleBoundsNotification(view);
if (view->visible())
view->SchedulePaint();
- if (!new_parent || new_parent->GetWidget() != widget)
+ is_removed_from_widget = !new_parent || new_parent->GetWidget() != widget;
+ if (is_removed_from_widget)
widget->NotifyWillRemoveView(view);
}
@@ -1944,7 +1952,7 @@ void View::DoRemoveChildView(View* view,
if (widget)
widget->LayerTreeChanged();
- view->PropagateRemoveNotifications(this, new_parent);
+ view->PropagateRemoveNotifications(this, new_parent, is_removed_from_widget);
view->parent_ = nullptr;
if (delete_removed_view && !view->owned_by_client_)
@@ -1965,26 +1973,35 @@ void View::DoRemoveChildView(View* view,
observer.OnChildViewRemoved(view, this);
}
-void View::PropagateRemoveNotifications(View* old_parent, View* new_parent) {
+void View::PropagateRemoveNotifications(View* old_parent,
+ View* new_parent,
+ bool is_removed_from_widget) {
{
internal::ScopedChildrenLock lock(this);
- for (auto* child : children_)
- child->PropagateRemoveNotifications(old_parent, new_parent);
+ for (auto* child : children_) {
+ child->PropagateRemoveNotifications(old_parent, new_parent,
+ is_removed_from_widget);
+ }
}
ViewHierarchyChangedDetails details(false, old_parent, this, new_parent);
for (View* v = this; v; v = v->parent_)
v->ViewHierarchyChangedImpl(true, details);
+
+ if (is_removed_from_widget)
+ RemovedFromWidget();
}
-void View::PropagateAddNotifications(
- const ViewHierarchyChangedDetails& details) {
+void View::PropagateAddNotifications(const ViewHierarchyChangedDetails& details,
+ bool is_added_to_widget) {
{
internal::ScopedChildrenLock lock(this);
for (auto* child : children_)
- child->PropagateAddNotifications(details);
+ child->PropagateAddNotifications(details, is_added_to_widget);
}
ViewHierarchyChangedImpl(true, details);
+ if (is_added_to_widget)
+ AddedToWidget();
}
void View::PropagateNativeViewHierarchyChanged() {
« no previous file with comments | « ui/views/view.h ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698