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

Side by Side Diff: views/view.cc

Issue 7129028: views: STL iterator cleanups in View class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: peter review Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 Widget* widget = GetWidget(); 866 Widget* widget = GetWidget();
867 return widget ? widget->GetInputMethod() : NULL; 867 return widget ? widget->GetInputMethod() : NULL;
868 } 868 }
869 869
870 // Accelerators ---------------------------------------------------------------- 870 // Accelerators ----------------------------------------------------------------
871 871
872 void View::AddAccelerator(const Accelerator& accelerator) { 872 void View::AddAccelerator(const Accelerator& accelerator) {
873 if (!accelerators_.get()) 873 if (!accelerators_.get())
874 accelerators_.reset(new std::vector<Accelerator>()); 874 accelerators_.reset(new std::vector<Accelerator>());
875 875
876 std::vector<Accelerator>::iterator iter = 876 std::vector<Accelerator>::iterator i(
877 std::find(accelerators_->begin(), accelerators_->end(), accelerator); 877 std::find(accelerators_->begin(), accelerators_->end(), accelerator));
878 DCHECK(iter == accelerators_->end()) 878 DCHECK(i == accelerators_->end())
879 << "Registering the same accelerator multiple times"; 879 << "Registering the same accelerator multiple times";
880 880
881 accelerators_->push_back(accelerator); 881 accelerators_->push_back(accelerator);
882 RegisterPendingAccelerators(); 882 RegisterPendingAccelerators();
883 } 883 }
884 884
885 void View::RemoveAccelerator(const Accelerator& accelerator) { 885 void View::RemoveAccelerator(const Accelerator& accelerator) {
886 std::vector<Accelerator>::iterator iter; 886 if (!accelerators_.get())
Peter Kasting 2011/06/09 00:59:38 This doesn't NOTREACHED() the way the old code doe
tfarina 2011/06/09 01:08:17 Done.
887 if (!accelerators_.get() || 887 return;
888 ((iter = std::find(accelerators_->begin(), accelerators_->end(), 888
889 accelerator)) == accelerators_->end())) { 889 std::vector<Accelerator>::iterator i(
890 std::find(accelerators_->begin(), accelerators_->end(), accelerator));
891 if (i == accelerators_->end()) {
890 NOTREACHED() << "Removing non-existing accelerator"; 892 NOTREACHED() << "Removing non-existing accelerator";
891 return; 893 return;
892 } 894 }
893 895
894 size_t index = iter - accelerators_->begin(); 896 size_t index = i - accelerators_->begin();
895 accelerators_->erase(iter); 897 accelerators_->erase(i);
896 if (index >= registered_accelerator_count_) { 898 if (index >= registered_accelerator_count_) {
897 // The accelerator is not registered to FocusManager. 899 // The accelerator is not registered to FocusManager.
898 return; 900 return;
899 } 901 }
900 --registered_accelerator_count_; 902 --registered_accelerator_count_;
901 903
902 // Providing we are attached to a Widget and registered with a focus manager, 904 // Providing we are attached to a Widget and registered with a focus manager,
903 // we should de-register from that focus manager now. 905 // we should de-register from that focus manager now.
904 if (GetWidget() && accelerator_focus_manager_) 906 if (GetWidget() && accelerator_focus_manager_)
905 accelerator_focus_manager_->UnregisterAccelerator(accelerator, this); 907 accelerator_focus_manager_->UnregisterAccelerator(accelerator, this);
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 start_pt = p; 1337 start_pt = p;
1336 } 1338 }
1337 1339
1338 // Tree operations ------------------------------------------------------------- 1340 // Tree operations -------------------------------------------------------------
1339 1341
1340 void View::DoRemoveChildView(View* view, 1342 void View::DoRemoveChildView(View* view,
1341 bool update_focus_cycle, 1343 bool update_focus_cycle,
1342 bool update_tool_tip, 1344 bool update_tool_tip,
1343 bool delete_removed_view) { 1345 bool delete_removed_view) {
1344 DCHECK(view); 1346 DCHECK(view);
1345 const Views::iterator i = std::find(children_.begin(), children_.end(), view); 1347 const Views::iterator i(std::find(children_.begin(), children_.end(), view));
1346 scoped_ptr<View> view_to_be_deleted; 1348 scoped_ptr<View> view_to_be_deleted;
1347 if (i != children_.end()) { 1349 if (i != children_.end()) {
1348 if (update_focus_cycle) { 1350 if (update_focus_cycle) {
1349 // Let's remove the view from the focus traversal. 1351 // Let's remove the view from the focus traversal.
1350 View* next_focusable = view->next_focusable_view_; 1352 View* next_focusable = view->next_focusable_view_;
1351 View* prev_focusable = view->previous_focusable_view_; 1353 View* prev_focusable = view->previous_focusable_view_;
1352 if (prev_focusable) 1354 if (prev_focusable)
1353 prev_focusable->next_focusable_view_ = next_focusable; 1355 prev_focusable->next_focusable_view_ = next_focusable;
1354 if (next_focusable) 1356 if (next_focusable)
1355 next_focusable->previous_focusable_view_ = prev_focusable; 1357 next_focusable->previous_focusable_view_ = prev_focusable;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 Layout(); 1474 Layout();
1473 } 1475 }
1474 1476
1475 if (NeedsNotificationWhenVisibleBoundsChange()) { 1477 if (NeedsNotificationWhenVisibleBoundsChange()) {
1476 OnVisibleBoundsChanged(); 1478 OnVisibleBoundsChanged();
1477 } 1479 }
1478 1480
1479 // Notify interested Views that visible bounds within the root view may have 1481 // Notify interested Views that visible bounds within the root view may have
1480 // changed. 1482 // changed.
1481 if (descendants_to_notify_.get()) { 1483 if (descendants_to_notify_.get()) {
1482 for (Views::iterator i = descendants_to_notify_->begin(); 1484 for (Views::iterator i(descendants_to_notify_->begin());
1483 i != descendants_to_notify_->end(); ++i) { 1485 i != descendants_to_notify_->end(); ++i) {
1484 (*i)->OnVisibleBoundsChanged(); 1486 (*i)->OnVisibleBoundsChanged();
1485 } 1487 }
1486 } 1488 }
1487 } 1489 }
1488 1490
1489 // static 1491 // static
1490 void View::RegisterChildrenForVisibleBoundsNotification(View* view) { 1492 void View::RegisterChildrenForVisibleBoundsNotification(View* view) {
1491 if (view->NeedsNotificationWhenVisibleBoundsChange()) 1493 if (view->NeedsNotificationWhenVisibleBoundsChange())
1492 view->RegisterForVisibleBoundsNotification(); 1494 view->RegisterForVisibleBoundsNotification();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 1529
1528 void View::AddDescendantToNotify(View* view) { 1530 void View::AddDescendantToNotify(View* view) {
1529 DCHECK(view); 1531 DCHECK(view);
1530 if (!descendants_to_notify_.get()) 1532 if (!descendants_to_notify_.get())
1531 descendants_to_notify_.reset(new Views); 1533 descendants_to_notify_.reset(new Views);
1532 descendants_to_notify_->push_back(view); 1534 descendants_to_notify_->push_back(view);
1533 } 1535 }
1534 1536
1535 void View::RemoveDescendantToNotify(View* view) { 1537 void View::RemoveDescendantToNotify(View* view) {
1536 DCHECK(view && descendants_to_notify_.get()); 1538 DCHECK(view && descendants_to_notify_.get());
1537 Views::iterator i = std::find(descendants_to_notify_->begin(), 1539 Views::iterator i(std::find(descendants_to_notify_->begin(),
1538 descendants_to_notify_->end(), 1540 descendants_to_notify_->end(),
1539 view); 1541 view));
1540 DCHECK(i != descendants_to_notify_->end()); 1542 DCHECK(i != descendants_to_notify_->end());
1541 descendants_to_notify_->erase(i); 1543 descendants_to_notify_->erase(i);
1542 if (descendants_to_notify_->empty()) 1544 if (descendants_to_notify_->empty())
1543 descendants_to_notify_.reset(); 1545 descendants_to_notify_.reset();
1544 } 1546 }
1545 1547
1546 // Transformations ------------------------------------------------------------- 1548 // Transformations -------------------------------------------------------------
1547 1549
1548 bool View::GetTransformRelativeTo(const View* ancestor, 1550 bool View::GetTransformRelativeTo(const View* ancestor,
1549 ui::Transform* transform) const { 1551 ui::Transform* transform) const {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 // NOTREACHED assertion and verify accelerators works as 1723 // NOTREACHED assertion and verify accelerators works as
1722 // expected. 1724 // expected.
1723 #if defined(OS_WIN) 1725 #if defined(OS_WIN)
1724 NOTREACHED(); 1726 NOTREACHED();
1725 #endif 1727 #endif
1726 return; 1728 return;
1727 } 1729 }
1728 // Only register accelerators if we are visible. 1730 // Only register accelerators if we are visible.
1729 if (!IsVisibleInRootView()) 1731 if (!IsVisibleInRootView())
1730 return; 1732 return;
1731 std::vector<Accelerator>::const_iterator iter; 1733 for (std::vector<Accelerator>::const_iterator i(
1732 for (iter = accelerators_->begin() + registered_accelerator_count_; 1734 accelerators_->begin() + registered_accelerator_count_);
1733 iter != accelerators_->end(); ++iter) { 1735 i != accelerators_->end(); ++i) {
1734 accelerator_focus_manager_->RegisterAccelerator(*iter, this); 1736 accelerator_focus_manager_->RegisterAccelerator(*i, this);
1735 } 1737 }
1736 registered_accelerator_count_ = accelerators_->size(); 1738 registered_accelerator_count_ = accelerators_->size();
1737 } 1739 }
1738 1740
1739 void View::UnregisterAccelerators(bool leave_data_intact) { 1741 void View::UnregisterAccelerators(bool leave_data_intact) {
1740 if (!accelerators_.get()) 1742 if (!accelerators_.get())
1741 return; 1743 return;
1742 1744
1743 if (GetWidget()) { 1745 if (GetWidget()) {
1744 if (accelerator_focus_manager_) { 1746 if (accelerator_focus_manager_) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1895 result.append(GetChildViewAt(i)->PrintViewGraph(false)); 1897 result.append(GetChildViewAt(i)->PrintViewGraph(false));
1896 1898
1897 if (first) 1899 if (first)
1898 result.append("}\n"); 1900 result.append("}\n");
1899 1901
1900 return result; 1902 return result;
1901 } 1903 }
1902 #endif 1904 #endif
1903 1905
1904 } // namespace views 1906 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698