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

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: move the std::find into the DCHECK 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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 Widget* widget = GetWidget(); 871 Widget* widget = GetWidget();
872 return widget ? widget->GetInputMethod() : NULL; 872 return widget ? widget->GetInputMethod() : NULL;
873 } 873 }
874 874
875 // Accelerators ---------------------------------------------------------------- 875 // Accelerators ----------------------------------------------------------------
876 876
877 void View::AddAccelerator(const Accelerator& accelerator) { 877 void View::AddAccelerator(const Accelerator& accelerator) {
878 if (!accelerators_.get()) 878 if (!accelerators_.get())
879 accelerators_.reset(new std::vector<Accelerator>()); 879 accelerators_.reset(new std::vector<Accelerator>());
880 880
881 std::vector<Accelerator>::iterator iter = 881 DCHECK(std::find(accelerators_->begin(), accelerators_->end(), accelerator) ==
882 std::find(accelerators_->begin(), accelerators_->end(), accelerator); 882 accelerators_->end())
883 DCHECK(iter == accelerators_->end())
884 << "Registering the same accelerator multiple times"; 883 << "Registering the same accelerator multiple times";
885 884
886 accelerators_->push_back(accelerator); 885 accelerators_->push_back(accelerator);
887 RegisterPendingAccelerators(); 886 RegisterPendingAccelerators();
888 } 887 }
889 888
890 void View::RemoveAccelerator(const Accelerator& accelerator) { 889 void View::RemoveAccelerator(const Accelerator& accelerator) {
891 std::vector<Accelerator>::iterator iter; 890 if (!accelerators_.get()) {
892 if (!accelerators_.get() ||
893 ((iter = std::find(accelerators_->begin(), accelerators_->end(),
894 accelerator)) == accelerators_->end())) {
895 NOTREACHED() << "Removing non-existing accelerator"; 891 NOTREACHED() << "Removing non-existing accelerator";
896 return; 892 return;
897 } 893 }
898 894
899 size_t index = iter - accelerators_->begin(); 895 std::vector<Accelerator>::iterator i(
900 accelerators_->erase(iter); 896 std::find(accelerators_->begin(), accelerators_->end(), accelerator));
897 if (i == accelerators_->end()) {
898 NOTREACHED() << "Removing non-existing accelerator";
899 return;
900 }
901
902 size_t index = i - accelerators_->begin();
903 accelerators_->erase(i);
901 if (index >= registered_accelerator_count_) { 904 if (index >= registered_accelerator_count_) {
902 // The accelerator is not registered to FocusManager. 905 // The accelerator is not registered to FocusManager.
903 return; 906 return;
904 } 907 }
905 --registered_accelerator_count_; 908 --registered_accelerator_count_;
906 909
907 // Providing we are attached to a Widget and registered with a focus manager, 910 // Providing we are attached to a Widget and registered with a focus manager,
908 // we should de-register from that focus manager now. 911 // we should de-register from that focus manager now.
909 if (GetWidget() && accelerator_focus_manager_) 912 if (GetWidget() && accelerator_focus_manager_)
910 accelerator_focus_manager_->UnregisterAccelerator(accelerator, this); 913 accelerator_focus_manager_->UnregisterAccelerator(accelerator, this);
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 start_pt = p; 1343 start_pt = p;
1341 } 1344 }
1342 1345
1343 // Tree operations ------------------------------------------------------------- 1346 // Tree operations -------------------------------------------------------------
1344 1347
1345 void View::DoRemoveChildView(View* view, 1348 void View::DoRemoveChildView(View* view,
1346 bool update_focus_cycle, 1349 bool update_focus_cycle,
1347 bool update_tool_tip, 1350 bool update_tool_tip,
1348 bool delete_removed_view) { 1351 bool delete_removed_view) {
1349 DCHECK(view); 1352 DCHECK(view);
1350 const Views::iterator i = std::find(children_.begin(), children_.end(), view); 1353 const Views::iterator i(std::find(children_.begin(), children_.end(), view));
1351 scoped_ptr<View> view_to_be_deleted; 1354 scoped_ptr<View> view_to_be_deleted;
1352 if (i != children_.end()) { 1355 if (i != children_.end()) {
1353 if (update_focus_cycle) { 1356 if (update_focus_cycle) {
1354 // Let's remove the view from the focus traversal. 1357 // Let's remove the view from the focus traversal.
1355 View* next_focusable = view->next_focusable_view_; 1358 View* next_focusable = view->next_focusable_view_;
1356 View* prev_focusable = view->previous_focusable_view_; 1359 View* prev_focusable = view->previous_focusable_view_;
1357 if (prev_focusable) 1360 if (prev_focusable)
1358 prev_focusable->next_focusable_view_ = next_focusable; 1361 prev_focusable->next_focusable_view_ = next_focusable;
1359 if (next_focusable) 1362 if (next_focusable)
1360 next_focusable->previous_focusable_view_ = prev_focusable; 1363 next_focusable->previous_focusable_view_ = prev_focusable;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 Layout(); 1480 Layout();
1478 } 1481 }
1479 1482
1480 if (NeedsNotificationWhenVisibleBoundsChange()) { 1483 if (NeedsNotificationWhenVisibleBoundsChange()) {
1481 OnVisibleBoundsChanged(); 1484 OnVisibleBoundsChanged();
1482 } 1485 }
1483 1486
1484 // Notify interested Views that visible bounds within the root view may have 1487 // Notify interested Views that visible bounds within the root view may have
1485 // changed. 1488 // changed.
1486 if (descendants_to_notify_.get()) { 1489 if (descendants_to_notify_.get()) {
1487 for (Views::iterator i = descendants_to_notify_->begin(); 1490 for (Views::iterator i(descendants_to_notify_->begin());
1488 i != descendants_to_notify_->end(); ++i) { 1491 i != descendants_to_notify_->end(); ++i) {
1489 (*i)->OnVisibleBoundsChanged(); 1492 (*i)->OnVisibleBoundsChanged();
1490 } 1493 }
1491 } 1494 }
1492 } 1495 }
1493 1496
1494 // static 1497 // static
1495 void View::RegisterChildrenForVisibleBoundsNotification(View* view) { 1498 void View::RegisterChildrenForVisibleBoundsNotification(View* view) {
1496 if (view->NeedsNotificationWhenVisibleBoundsChange()) 1499 if (view->NeedsNotificationWhenVisibleBoundsChange())
1497 view->RegisterForVisibleBoundsNotification(); 1500 view->RegisterForVisibleBoundsNotification();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 1535
1533 void View::AddDescendantToNotify(View* view) { 1536 void View::AddDescendantToNotify(View* view) {
1534 DCHECK(view); 1537 DCHECK(view);
1535 if (!descendants_to_notify_.get()) 1538 if (!descendants_to_notify_.get())
1536 descendants_to_notify_.reset(new Views); 1539 descendants_to_notify_.reset(new Views);
1537 descendants_to_notify_->push_back(view); 1540 descendants_to_notify_->push_back(view);
1538 } 1541 }
1539 1542
1540 void View::RemoveDescendantToNotify(View* view) { 1543 void View::RemoveDescendantToNotify(View* view) {
1541 DCHECK(view && descendants_to_notify_.get()); 1544 DCHECK(view && descendants_to_notify_.get());
1542 Views::iterator i = std::find(descendants_to_notify_->begin(), 1545 Views::iterator i(std::find(
1543 descendants_to_notify_->end(), 1546 descendants_to_notify_->begin(), descendants_to_notify_->end(), view));
1544 view);
1545 DCHECK(i != descendants_to_notify_->end()); 1547 DCHECK(i != descendants_to_notify_->end());
1546 descendants_to_notify_->erase(i); 1548 descendants_to_notify_->erase(i);
1547 if (descendants_to_notify_->empty()) 1549 if (descendants_to_notify_->empty())
1548 descendants_to_notify_.reset(); 1550 descendants_to_notify_.reset();
1549 } 1551 }
1550 1552
1551 // Transformations ------------------------------------------------------------- 1553 // Transformations -------------------------------------------------------------
1552 1554
1553 bool View::GetTransformRelativeTo(const View* ancestor, 1555 bool View::GetTransformRelativeTo(const View* ancestor,
1554 ui::Transform* transform) const { 1556 ui::Transform* transform) const {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 // NOTREACHED assertion and verify accelerators works as 1728 // NOTREACHED assertion and verify accelerators works as
1727 // expected. 1729 // expected.
1728 #if defined(OS_WIN) 1730 #if defined(OS_WIN)
1729 NOTREACHED(); 1731 NOTREACHED();
1730 #endif 1732 #endif
1731 return; 1733 return;
1732 } 1734 }
1733 // Only register accelerators if we are visible. 1735 // Only register accelerators if we are visible.
1734 if (!IsVisibleInRootView()) 1736 if (!IsVisibleInRootView())
1735 return; 1737 return;
1736 std::vector<Accelerator>::const_iterator iter; 1738 for (std::vector<Accelerator>::const_iterator i(
1737 for (iter = accelerators_->begin() + registered_accelerator_count_; 1739 accelerators_->begin() + registered_accelerator_count_);
1738 iter != accelerators_->end(); ++iter) { 1740 i != accelerators_->end(); ++i) {
1739 accelerator_focus_manager_->RegisterAccelerator(*iter, this); 1741 accelerator_focus_manager_->RegisterAccelerator(*i, this);
1740 } 1742 }
1741 registered_accelerator_count_ = accelerators_->size(); 1743 registered_accelerator_count_ = accelerators_->size();
1742 } 1744 }
1743 1745
1744 void View::UnregisterAccelerators(bool leave_data_intact) { 1746 void View::UnregisterAccelerators(bool leave_data_intact) {
1745 if (!accelerators_.get()) 1747 if (!accelerators_.get())
1746 return; 1748 return;
1747 1749
1748 if (GetWidget()) { 1750 if (GetWidget()) {
1749 if (accelerator_focus_manager_) { 1751 if (accelerator_focus_manager_) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 result.append(GetChildViewAt(i)->PrintViewGraph(false)); 1902 result.append(GetChildViewAt(i)->PrintViewGraph(false));
1901 1903
1902 if (first) 1904 if (first)
1903 result.append("}\n"); 1905 result.append("}\n");
1904 1906
1905 return result; 1907 return result;
1906 } 1908 }
1907 #endif 1909 #endif
1908 1910
1909 } // namespace views 1911 } // 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