OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "views/view.h" | 5 #include "views/view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 context_menu_controller_(NULL), | 119 context_menu_controller_(NULL), |
120 drag_controller_(NULL) { | 120 drag_controller_(NULL) { |
121 } | 121 } |
122 | 122 |
123 View::~View() { | 123 View::~View() { |
124 if (parent_) | 124 if (parent_) |
125 parent_->RemoveChildView(this); | 125 parent_->RemoveChildView(this); |
126 | 126 |
127 int c = static_cast<int>(children_.size()); | 127 int c = static_cast<int>(children_.size()); |
128 while (--c >= 0) { | 128 while (--c >= 0) { |
129 children_[c]->SetParent(NULL); | 129 children_[c]->parent_ = NULL; |
130 if (children_[c]->IsParentOwned()) | 130 if (children_[c]->IsParentOwned()) |
131 delete children_[c]; | 131 delete children_[c]; |
132 } | 132 } |
133 | 133 |
134 #if defined(OS_WIN) | 134 #if defined(OS_WIN) |
135 if (native_view_accessibility_win_.get()) | 135 if (native_view_accessibility_win_.get()) |
136 native_view_accessibility_win_->set_view(NULL); | 136 native_view_accessibility_win_->set_view(NULL); |
137 #endif | 137 #endif |
138 } | 138 } |
139 | 139 |
(...skipping 17 matching lines...) Expand all Loading... |
157 | 157 |
158 // Remove the view from its current parent if any. | 158 // Remove the view from its current parent if any. |
159 if (view->parent()) | 159 if (view->parent()) |
160 view->parent()->RemoveChildView(view); | 160 view->parent()->RemoveChildView(view); |
161 | 161 |
162 // Sets the prev/next focus views. | 162 // Sets the prev/next focus views. |
163 InitFocusSiblings(view, index); | 163 InitFocusSiblings(view, index); |
164 | 164 |
165 // Let's insert the view. | 165 // Let's insert the view. |
166 children_.insert(children_.begin() + index, view); | 166 children_.insert(children_.begin() + index, view); |
167 view->SetParent(this); | 167 view->parent_ = this; |
168 | 168 |
169 for (View* p = this; p; p = p->parent()) | 169 for (View* p = this; p; p = p->parent()) |
170 p->ViewHierarchyChangedImpl(false, true, this, view); | 170 p->ViewHierarchyChangedImpl(false, true, this, view); |
171 | 171 |
172 view->PropagateAddNotifications(this, view); | 172 view->PropagateAddNotifications(this, view); |
173 UpdateTooltip(); | 173 UpdateTooltip(); |
174 if (GetWidget()) | 174 if (GetWidget()) |
175 RegisterChildrenForVisibleBoundsNotification(view); | 175 RegisterChildrenForVisibleBoundsNotification(view); |
176 | 176 |
177 if (layout_manager_.get()) | 177 if (layout_manager_.get()) |
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 if (prev_focusable) | 1336 if (prev_focusable) |
1337 prev_focusable->next_focusable_view_ = next_focusable; | 1337 prev_focusable->next_focusable_view_ = next_focusable; |
1338 if (next_focusable) | 1338 if (next_focusable) |
1339 next_focusable->previous_focusable_view_ = prev_focusable; | 1339 next_focusable->previous_focusable_view_ = prev_focusable; |
1340 } | 1340 } |
1341 | 1341 |
1342 if (GetWidget()) | 1342 if (GetWidget()) |
1343 UnregisterChildrenForVisibleBoundsNotification(view); | 1343 UnregisterChildrenForVisibleBoundsNotification(view); |
1344 view->ResetTexture(); | 1344 view->ResetTexture(); |
1345 view->PropagateRemoveNotifications(this); | 1345 view->PropagateRemoveNotifications(this); |
1346 view->SetParent(NULL); | 1346 view->parent_ = NULL; |
1347 | 1347 |
1348 if (delete_removed_view && view->IsParentOwned()) | 1348 if (delete_removed_view && view->IsParentOwned()) |
1349 view_to_be_deleted.reset(view); | 1349 view_to_be_deleted.reset(view); |
1350 | 1350 |
1351 children_.erase(i); | 1351 children_.erase(i); |
1352 } | 1352 } |
1353 | 1353 |
1354 if (update_tool_tip) | 1354 if (update_tool_tip) |
1355 UpdateTooltip(); | 1355 UpdateTooltip(); |
1356 | 1356 |
1357 if (layout_manager_.get()) | 1357 if (layout_manager_.get()) |
1358 layout_manager_->ViewRemoved(this, view); | 1358 layout_manager_->ViewRemoved(this, view); |
1359 } | 1359 } |
1360 | 1360 |
1361 void View::SetParent(View* parent) { | |
1362 if (parent != parent_) | |
1363 parent_ = parent; | |
1364 } | |
1365 | |
1366 void View::PropagateRemoveNotifications(View* parent) { | 1361 void View::PropagateRemoveNotifications(View* parent) { |
1367 for (int i = 0, count = child_count(); i < count; ++i) | 1362 for (int i = 0, count = child_count(); i < count; ++i) |
1368 GetChildViewAt(i)->PropagateRemoveNotifications(parent); | 1363 GetChildViewAt(i)->PropagateRemoveNotifications(parent); |
1369 | 1364 |
1370 for (View* v = this; v; v = v->parent()) | 1365 for (View* v = this; v; v = v->parent()) |
1371 v->ViewHierarchyChangedImpl(true, false, parent, this); | 1366 v->ViewHierarchyChangedImpl(true, false, parent, this); |
1372 } | 1367 } |
1373 | 1368 |
1374 void View::PropagateAddNotifications(View* parent, View* child) { | 1369 void View::PropagateAddNotifications(View* parent, View* child) { |
1375 for (int i = 0, count = child_count(); i < count; ++i) | 1370 for (int i = 0, count = child_count(); i < count; ++i) |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1875 result.append(GetChildViewAt(i)->PrintViewGraph(false)); | 1870 result.append(GetChildViewAt(i)->PrintViewGraph(false)); |
1876 | 1871 |
1877 if (first) | 1872 if (first) |
1878 result.append("}\n"); | 1873 result.append("}\n"); |
1879 | 1874 |
1880 return result; | 1875 return result; |
1881 } | 1876 } |
1882 #endif | 1877 #endif |
1883 | 1878 |
1884 } // namespace views | 1879 } // namespace views |
OLD | NEW |