 Chromium Code Reviews
 Chromium Code Reviews Issue 2713643002:
  Add View::AddedToWidget and RemovedFromWidget.  (Closed)
    
  
    Issue 2713643002:
  Add View::AddedToWidget and RemovedFromWidget.  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 
| 6 | 6 | 
| 7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" | 
| 8 | 8 | 
| 9 #include <algorithm> | 9 #include <algorithm> | 
| 10 #include <cmath> | 10 #include <cmath> | 
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 } | 189 } | 
| 190 | 190 | 
| 191 void View::AddChildViewAt(View* view, int index) { | 191 void View::AddChildViewAt(View* view, int index) { | 
| 192 CHECK_NE(view, this) << "You cannot add a view as its own child"; | 192 CHECK_NE(view, this) << "You cannot add a view as its own child"; | 
| 193 DCHECK_GE(index, 0); | 193 DCHECK_GE(index, 0); | 
| 194 DCHECK_LE(index, child_count()); | 194 DCHECK_LE(index, child_count()); | 
| 195 | 195 | 
| 196 // If |view| has a parent, remove it from its parent. | 196 // If |view| has a parent, remove it from its parent. | 
| 197 View* parent = view->parent_; | 197 View* parent = view->parent_; | 
| 198 ui::NativeTheme* old_theme = NULL; | 198 ui::NativeTheme* old_theme = NULL; | 
| 199 Widget* old_widget = NULL; | |
| 199 if (parent) { | 200 if (parent) { | 
| 200 old_theme = view->GetNativeTheme(); | 201 old_theme = view->GetNativeTheme(); | 
| 202 old_widget = view->GetWidget(); | |
| 201 if (parent == this) { | 203 if (parent == this) { | 
| 202 ReorderChildView(view, index); | 204 ReorderChildView(view, index); | 
| 203 return; | 205 return; | 
| 204 } | 206 } | 
| 205 parent->DoRemoveChildView(view, true, true, false, this); | 207 parent->DoRemoveChildView(view, true, true, false, this); | 
| 206 } | 208 } | 
| 207 | 209 | 
| 208 // Sets the prev/next focus views. | 210 // Sets the prev/next focus views. | 
| 209 InitFocusSiblings(view, index); | 211 InitFocusSiblings(view, index); | 
| 210 | 212 | 
| (...skipping 30 matching lines...) Expand all Loading... | |
| 241 for (View* v = this; v; v = v->parent_) | 243 for (View* v = this; v; v = v->parent_) | 
| 242 v->ViewHierarchyChangedImpl(false, details); | 244 v->ViewHierarchyChangedImpl(false, details); | 
| 243 | 245 | 
| 244 view->PropagateAddNotifications(details); | 246 view->PropagateAddNotifications(details); | 
| 245 | 247 | 
| 246 UpdateTooltip(); | 248 UpdateTooltip(); | 
| 247 | 249 | 
| 248 if (widget) { | 250 if (widget) { | 
| 249 RegisterChildrenForVisibleBoundsNotification(view); | 251 RegisterChildrenForVisibleBoundsNotification(view); | 
| 250 | 252 | 
| 253 if (widget != old_widget) | |
| 254 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.
 | |
| 255 | |
| 251 if (view->visible()) | 256 if (view->visible()) | 
| 252 view->SchedulePaint(); | 257 view->SchedulePaint(); | 
| 253 } | 258 } | 
| 254 | 259 | 
| 255 if (layout_manager_.get()) | 260 if (layout_manager_.get()) | 
| 256 layout_manager_->ViewAdded(this, view); | 261 layout_manager_->ViewAdded(this, view); | 
| 257 | 262 | 
| 258 for (ViewObserver& observer : observers_) | 263 for (ViewObserver& observer : observers_) | 
| 259 observer.OnChildViewAdded(view); | 264 observer.OnChildViewAdded(view); | 
| 260 } | 265 } | 
| (...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1509 void View::NativeViewHierarchyChanged() { | 1514 void View::NativeViewHierarchyChanged() { | 
| 1510 FocusManager* focus_manager = GetFocusManager(); | 1515 FocusManager* focus_manager = GetFocusManager(); | 
| 1511 if (accelerator_focus_manager_ != focus_manager) { | 1516 if (accelerator_focus_manager_ != focus_manager) { | 
| 1512 UnregisterAccelerators(true); | 1517 UnregisterAccelerators(true); | 
| 1513 | 1518 | 
| 1514 if (focus_manager) | 1519 if (focus_manager) | 
| 1515 RegisterPendingAccelerators(); | 1520 RegisterPendingAccelerators(); | 
| 1516 } | 1521 } | 
| 1517 } | 1522 } | 
| 1518 | 1523 | 
| 1524 void View::AddedToWidget() {} | |
| 1525 | |
| 1526 void View::RemovedFromWidget() {} | |
| 1527 | |
| 1519 // Painting -------------------------------------------------------------------- | 1528 // Painting -------------------------------------------------------------------- | 
| 1520 | 1529 | 
| 1521 void View::PaintChildren(const ui::PaintContext& context) { | 1530 void View::PaintChildren(const ui::PaintContext& context) { | 
| 1522 TRACE_EVENT1("views", "View::PaintChildren", "class", GetClassName()); | 1531 TRACE_EVENT1("views", "View::PaintChildren", "class", GetClassName()); | 
| 1523 View::Views children = GetChildrenInZOrder(); | 1532 View::Views children = GetChildrenInZOrder(); | 
| 1524 DCHECK_EQ(child_count(), static_cast<int>(children.size())); | 1533 DCHECK_EQ(child_count(), static_cast<int>(children.size())); | 
| 1525 for (auto* child : children) { | 1534 for (auto* child : children) { | 
| 1526 if (!child->layer()) | 1535 if (!child->layer()) | 
| 1527 child->Paint(context); | 1536 child->Paint(context); | 
| 1528 } | 1537 } | 
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1927 if (next_focusable) | 1936 if (next_focusable) | 
| 1928 next_focusable->previous_focusable_view_ = prev_focusable; | 1937 next_focusable->previous_focusable_view_ = prev_focusable; | 
| 1929 } | 1938 } | 
| 1930 | 1939 | 
| 1931 Widget* widget = GetWidget(); | 1940 Widget* widget = GetWidget(); | 
| 1932 if (widget) { | 1941 if (widget) { | 
| 1933 UnregisterChildrenForVisibleBoundsNotification(view); | 1942 UnregisterChildrenForVisibleBoundsNotification(view); | 
| 1934 if (view->visible()) | 1943 if (view->visible()) | 
| 1935 view->SchedulePaint(); | 1944 view->SchedulePaint(); | 
| 1936 | 1945 | 
| 1937 if (!new_parent || new_parent->GetWidget() != widget) | 1946 if (!new_parent || new_parent->GetWidget() != widget) { | 
| 1938 widget->NotifyWillRemoveView(view); | 1947 widget->NotifyWillRemoveView(view); | 
| 1948 view->PropagateRemovedFromWidget(); | |
| 1949 } | |
| 1939 } | 1950 } | 
| 1940 | 1951 | 
| 1941 // Make sure the layers belonging to the subtree rooted at |view| get | 1952 // Make sure the layers belonging to the subtree rooted at |view| get | 
| 1942 // removed. | 1953 // removed. | 
| 1943 view->OrphanLayers(); | 1954 view->OrphanLayers(); | 
| 1944 if (widget) | 1955 if (widget) | 
| 1945 widget->LayerTreeChanged(); | 1956 widget->LayerTreeChanged(); | 
| 1946 | 1957 | 
| 1947 view->PropagateRemoveNotifications(this, new_parent); | 1958 view->PropagateRemoveNotifications(this, new_parent); | 
| 1948 view->parent_ = nullptr; | 1959 view->parent_ = nullptr; | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2020 return; | 2031 return; | 
| 2021 | 2032 | 
| 2022 { | 2033 { | 
| 2023 internal::ScopedChildrenLock lock(this); | 2034 internal::ScopedChildrenLock lock(this); | 
| 2024 for (auto* child : children_) | 2035 for (auto* child : children_) | 
| 2025 child->PropagateNativeThemeChanged(theme); | 2036 child->PropagateNativeThemeChanged(theme); | 
| 2026 } | 2037 } | 
| 2027 OnNativeThemeChanged(theme); | 2038 OnNativeThemeChanged(theme); | 
| 2028 } | 2039 } | 
| 2029 | 2040 | 
| 2041 void View::PropagateAddedToWidget() { | |
| 2042 { | |
| 2043 internal::ScopedChildrenLock lock(this); | |
| 2044 for (auto* child : children_) | |
| 2045 child->PropagateAddedToWidget(); | |
| 2046 } | |
| 2047 AddedToWidget(); | |
| 2048 } | |
| 2049 | |
| 2050 void View::PropagateRemovedFromWidget() { | |
| 2051 { | |
| 2052 internal::ScopedChildrenLock lock(this); | |
| 2053 for (auto* child : children_) | |
| 2054 child->PropagateRemovedFromWidget(); | |
| 2055 } | |
| 2056 RemovedFromWidget(); | |
| 2057 } | |
| 2058 | |
| 2030 // Size and disposition -------------------------------------------------------- | 2059 // Size and disposition -------------------------------------------------------- | 
| 2031 | 2060 | 
| 2032 void View::PropagateVisibilityNotifications(View* start, bool is_visible) { | 2061 void View::PropagateVisibilityNotifications(View* start, bool is_visible) { | 
| 2033 { | 2062 { | 
| 2034 internal::ScopedChildrenLock lock(this); | 2063 internal::ScopedChildrenLock lock(this); | 
| 2035 for (auto* child : children_) | 2064 for (auto* child : children_) | 
| 2036 child->PropagateVisibilityNotifications(start, is_visible); | 2065 child->PropagateVisibilityNotifications(start, is_visible); | 
| 2037 } | 2066 } | 
| 2038 VisibilityChangedImpl(start, is_visible); | 2067 VisibilityChangedImpl(start, is_visible); | 
| 2039 } | 2068 } | 
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2551 // Message the RootView to do the drag and drop. That way if we're removed | 2580 // Message the RootView to do the drag and drop. That way if we're removed | 
| 2552 // the RootView can detect it and avoid calling us back. | 2581 // the RootView can detect it and avoid calling us back. | 
| 2553 gfx::Point widget_location(event.location()); | 2582 gfx::Point widget_location(event.location()); | 
| 2554 ConvertPointToWidget(this, &widget_location); | 2583 ConvertPointToWidget(this, &widget_location); | 
| 2555 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2584 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 
| 2556 // WARNING: we may have been deleted. | 2585 // WARNING: we may have been deleted. | 
| 2557 return true; | 2586 return true; | 
| 2558 } | 2587 } | 
| 2559 | 2588 | 
| 2560 } // namespace views | 2589 } // namespace views | 
| OLD | NEW |