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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 AddChildViewAt(view, child_count()); | 188 AddChildViewAt(view, child_count()); |
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 = nullptr; |
| 199 Widget* old_widget = nullptr; |
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 23 matching lines...) Expand all Loading... |
234 const ui::NativeTheme* new_theme = view->GetNativeTheme(); | 236 const ui::NativeTheme* new_theme = view->GetNativeTheme(); |
235 if (new_theme != old_theme) | 237 if (new_theme != old_theme) |
236 view->PropagateNativeThemeChanged(new_theme); | 238 view->PropagateNativeThemeChanged(new_theme); |
237 } | 239 } |
238 | 240 |
239 ViewHierarchyChangedDetails details(true, this, view, parent); | 241 ViewHierarchyChangedDetails details(true, this, view, parent); |
240 | 242 |
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, widget && widget != old_widget); |
245 | 247 |
246 UpdateTooltip(); | 248 UpdateTooltip(); |
247 | 249 |
248 if (widget) { | 250 if (widget) { |
249 RegisterChildrenForVisibleBoundsNotification(view); | 251 RegisterChildrenForVisibleBoundsNotification(view); |
250 | 252 |
251 if (view->visible()) | 253 if (view->visible()) |
252 view->SchedulePaint(); | 254 view->SchedulePaint(); |
253 } | 255 } |
254 | 256 |
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1509 void View::NativeViewHierarchyChanged() { | 1511 void View::NativeViewHierarchyChanged() { |
1510 FocusManager* focus_manager = GetFocusManager(); | 1512 FocusManager* focus_manager = GetFocusManager(); |
1511 if (accelerator_focus_manager_ != focus_manager) { | 1513 if (accelerator_focus_manager_ != focus_manager) { |
1512 UnregisterAccelerators(true); | 1514 UnregisterAccelerators(true); |
1513 | 1515 |
1514 if (focus_manager) | 1516 if (focus_manager) |
1515 RegisterPendingAccelerators(); | 1517 RegisterPendingAccelerators(); |
1516 } | 1518 } |
1517 } | 1519 } |
1518 | 1520 |
| 1521 void View::AddedToWidget() {} |
| 1522 |
| 1523 void View::RemovedFromWidget() {} |
| 1524 |
1519 // Painting -------------------------------------------------------------------- | 1525 // Painting -------------------------------------------------------------------- |
1520 | 1526 |
1521 void View::PaintChildren(const ui::PaintContext& context) { | 1527 void View::PaintChildren(const ui::PaintContext& context) { |
1522 TRACE_EVENT1("views", "View::PaintChildren", "class", GetClassName()); | 1528 TRACE_EVENT1("views", "View::PaintChildren", "class", GetClassName()); |
1523 View::Views children = GetChildrenInZOrder(); | 1529 View::Views children = GetChildrenInZOrder(); |
1524 DCHECK_EQ(child_count(), static_cast<int>(children.size())); | 1530 DCHECK_EQ(child_count(), static_cast<int>(children.size())); |
1525 for (auto* child : children) { | 1531 for (auto* child : children) { |
1526 if (!child->layer()) | 1532 if (!child->layer()) |
1527 child->Paint(context); | 1533 child->Paint(context); |
1528 } | 1534 } |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 if (update_focus_cycle) { | 1928 if (update_focus_cycle) { |
1923 View* next_focusable = view->next_focusable_view_; | 1929 View* next_focusable = view->next_focusable_view_; |
1924 View* prev_focusable = view->previous_focusable_view_; | 1930 View* prev_focusable = view->previous_focusable_view_; |
1925 if (prev_focusable) | 1931 if (prev_focusable) |
1926 prev_focusable->next_focusable_view_ = next_focusable; | 1932 prev_focusable->next_focusable_view_ = next_focusable; |
1927 if (next_focusable) | 1933 if (next_focusable) |
1928 next_focusable->previous_focusable_view_ = prev_focusable; | 1934 next_focusable->previous_focusable_view_ = prev_focusable; |
1929 } | 1935 } |
1930 | 1936 |
1931 Widget* widget = GetWidget(); | 1937 Widget* widget = GetWidget(); |
| 1938 bool is_removed_from_widget = false; |
1932 if (widget) { | 1939 if (widget) { |
1933 UnregisterChildrenForVisibleBoundsNotification(view); | 1940 UnregisterChildrenForVisibleBoundsNotification(view); |
1934 if (view->visible()) | 1941 if (view->visible()) |
1935 view->SchedulePaint(); | 1942 view->SchedulePaint(); |
1936 | 1943 |
1937 if (!new_parent || new_parent->GetWidget() != widget) | 1944 is_removed_from_widget = !new_parent || new_parent->GetWidget() != widget; |
| 1945 if (is_removed_from_widget) |
1938 widget->NotifyWillRemoveView(view); | 1946 widget->NotifyWillRemoveView(view); |
1939 } | 1947 } |
1940 | 1948 |
1941 // Make sure the layers belonging to the subtree rooted at |view| get | 1949 // Make sure the layers belonging to the subtree rooted at |view| get |
1942 // removed. | 1950 // removed. |
1943 view->OrphanLayers(); | 1951 view->OrphanLayers(); |
1944 if (widget) | 1952 if (widget) |
1945 widget->LayerTreeChanged(); | 1953 widget->LayerTreeChanged(); |
1946 | 1954 |
1947 view->PropagateRemoveNotifications(this, new_parent); | 1955 view->PropagateRemoveNotifications(this, new_parent, is_removed_from_widget); |
1948 view->parent_ = nullptr; | 1956 view->parent_ = nullptr; |
1949 | 1957 |
1950 if (delete_removed_view && !view->owned_by_client_) | 1958 if (delete_removed_view && !view->owned_by_client_) |
1951 view_to_be_deleted.reset(view); | 1959 view_to_be_deleted.reset(view); |
1952 | 1960 |
1953 #if DCHECK_IS_ON() | 1961 #if DCHECK_IS_ON() |
1954 DCHECK(!iterating_); | 1962 DCHECK(!iterating_); |
1955 #endif | 1963 #endif |
1956 children_.erase(i); | 1964 children_.erase(i); |
1957 | 1965 |
1958 if (update_tool_tip) | 1966 if (update_tool_tip) |
1959 UpdateTooltip(); | 1967 UpdateTooltip(); |
1960 | 1968 |
1961 if (layout_manager_) | 1969 if (layout_manager_) |
1962 layout_manager_->ViewRemoved(this, view); | 1970 layout_manager_->ViewRemoved(this, view); |
1963 | 1971 |
1964 for (ViewObserver& observer : observers_) | 1972 for (ViewObserver& observer : observers_) |
1965 observer.OnChildViewRemoved(view, this); | 1973 observer.OnChildViewRemoved(view, this); |
1966 } | 1974 } |
1967 | 1975 |
1968 void View::PropagateRemoveNotifications(View* old_parent, View* new_parent) { | 1976 void View::PropagateRemoveNotifications(View* old_parent, |
| 1977 View* new_parent, |
| 1978 bool is_removed_from_widget) { |
1969 { | 1979 { |
1970 internal::ScopedChildrenLock lock(this); | 1980 internal::ScopedChildrenLock lock(this); |
1971 for (auto* child : children_) | 1981 for (auto* child : children_) { |
1972 child->PropagateRemoveNotifications(old_parent, new_parent); | 1982 child->PropagateRemoveNotifications(old_parent, new_parent, |
| 1983 is_removed_from_widget); |
| 1984 } |
1973 } | 1985 } |
1974 | 1986 |
1975 ViewHierarchyChangedDetails details(false, old_parent, this, new_parent); | 1987 ViewHierarchyChangedDetails details(false, old_parent, this, new_parent); |
1976 for (View* v = this; v; v = v->parent_) | 1988 for (View* v = this; v; v = v->parent_) |
1977 v->ViewHierarchyChangedImpl(true, details); | 1989 v->ViewHierarchyChangedImpl(true, details); |
| 1990 |
| 1991 if (is_removed_from_widget) |
| 1992 RemovedFromWidget(); |
1978 } | 1993 } |
1979 | 1994 |
1980 void View::PropagateAddNotifications( | 1995 void View::PropagateAddNotifications(const ViewHierarchyChangedDetails& details, |
1981 const ViewHierarchyChangedDetails& details) { | 1996 bool is_added_to_widget) { |
1982 { | 1997 { |
1983 internal::ScopedChildrenLock lock(this); | 1998 internal::ScopedChildrenLock lock(this); |
1984 for (auto* child : children_) | 1999 for (auto* child : children_) |
1985 child->PropagateAddNotifications(details); | 2000 child->PropagateAddNotifications(details, is_added_to_widget); |
1986 } | 2001 } |
1987 ViewHierarchyChangedImpl(true, details); | 2002 ViewHierarchyChangedImpl(true, details); |
| 2003 if (is_added_to_widget) |
| 2004 AddedToWidget(); |
1988 } | 2005 } |
1989 | 2006 |
1990 void View::PropagateNativeViewHierarchyChanged() { | 2007 void View::PropagateNativeViewHierarchyChanged() { |
1991 { | 2008 { |
1992 internal::ScopedChildrenLock lock(this); | 2009 internal::ScopedChildrenLock lock(this); |
1993 for (auto* child : children_) | 2010 for (auto* child : children_) |
1994 child->PropagateNativeViewHierarchyChanged(); | 2011 child->PropagateNativeViewHierarchyChanged(); |
1995 } | 2012 } |
1996 NativeViewHierarchyChanged(); | 2013 NativeViewHierarchyChanged(); |
1997 } | 2014 } |
(...skipping 553 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 | 2568 // 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. | 2569 // the RootView can detect it and avoid calling us back. |
2553 gfx::Point widget_location(event.location()); | 2570 gfx::Point widget_location(event.location()); |
2554 ConvertPointToWidget(this, &widget_location); | 2571 ConvertPointToWidget(this, &widget_location); |
2555 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2572 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2556 // WARNING: we may have been deleted. | 2573 // WARNING: we may have been deleted. |
2557 return true; | 2574 return true; |
2558 } | 2575 } |
2559 | 2576 |
2560 } // namespace views | 2577 } // namespace views |
OLD | NEW |