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

Unified Diff: ui/views/view.cc

Issue 2713643002: Add View::AddedToWidget and RemovedFromWidget. (Closed)
Patch Set: Reimplement without using the additional member View::attached_widget_. 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..1a173b8760e1448c638325907cd0983f28aebee1 100644
--- a/ui/views/view.cc
+++ b/ui/views/view.cc
@@ -196,8 +196,10 @@ 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;
+ Widget* old_widget = NULL;
if (parent) {
old_theme = view->GetNativeTheme();
+ old_widget = view->GetWidget();
if (parent == this) {
ReorderChildView(view, index);
return;
@@ -248,6 +250,9 @@ void View::AddChildViewAt(View* view, int index) {
if (widget) {
RegisterChildrenForVisibleBoundsNotification(view);
+ if (widget != old_widget)
+ view->PropagateAddedToWidget();
sky 2017/02/27 16:46:54 I would like to avoid more tree walking. Can't you
msimonides 2017/02/28 10:07:27 Ok. I will merge PropagateAddedToWidget into Propa
sky 2017/02/28 17:35:33 That's fine. These are implementation details of V
msimonides 2017/03/01 10:31:52 Done.
+
if (view->visible())
view->SchedulePaint();
}
@@ -1516,6 +1521,10 @@ void View::NativeViewHierarchyChanged() {
}
}
+void View::AddedToWidget() {}
+
+void View::RemovedFromWidget() {}
+
// Painting --------------------------------------------------------------------
void View::PaintChildren(const ui::PaintContext& context) {
@@ -1934,8 +1943,10 @@ void View::DoRemoveChildView(View* view,
if (view->visible())
view->SchedulePaint();
- if (!new_parent || new_parent->GetWidget() != widget)
+ if (!new_parent || new_parent->GetWidget() != widget) {
widget->NotifyWillRemoveView(view);
+ view->PropagateRemovedFromWidget();
+ }
}
// Make sure the layers belonging to the subtree rooted at |view| get
@@ -2027,6 +2038,24 @@ void View::PropagateNativeThemeChanged(const ui::NativeTheme* theme) {
OnNativeThemeChanged(theme);
}
+void View::PropagateAddedToWidget() {
+ {
+ internal::ScopedChildrenLock lock(this);
+ for (auto* child : children_)
+ child->PropagateAddedToWidget();
+ }
+ AddedToWidget();
+}
+
+void View::PropagateRemovedFromWidget() {
+ {
+ internal::ScopedChildrenLock lock(this);
+ for (auto* child : children_)
+ child->PropagateRemovedFromWidget();
+ }
+ RemovedFromWidget();
+}
+
// Size and disposition --------------------------------------------------------
void View::PropagateVisibilityNotifications(View* start, bool is_visible) {
« 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