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 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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()) |
sky
2011/06/09 17:06:34
move the std::find into the DCHECK, eg:
DCHECK(std
tfarina
2011/06/09 17:17:06
Done.
| |
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()) { |
887 if (!accelerators_.get() || | |
888 ((iter = std::find(accelerators_->begin(), accelerators_->end(), | |
889 accelerator)) == accelerators_->end())) { | |
890 NOTREACHED() << "Removing non-existing accelerator"; | 887 NOTREACHED() << "Removing non-existing accelerator"; |
891 return; | 888 return; |
892 } | 889 } |
893 | 890 |
894 size_t index = iter - accelerators_->begin(); | 891 std::vector<Accelerator>::iterator i( |
895 accelerators_->erase(iter); | 892 std::find(accelerators_->begin(), accelerators_->end(), accelerator)); |
893 if (i == accelerators_->end()) { | |
894 NOTREACHED() << "Removing non-existing accelerator"; | |
895 return; | |
896 } | |
897 | |
898 size_t index = i - accelerators_->begin(); | |
899 accelerators_->erase(i); | |
896 if (index >= registered_accelerator_count_) { | 900 if (index >= registered_accelerator_count_) { |
897 // The accelerator is not registered to FocusManager. | 901 // The accelerator is not registered to FocusManager. |
898 return; | 902 return; |
899 } | 903 } |
900 --registered_accelerator_count_; | 904 --registered_accelerator_count_; |
901 | 905 |
902 // Providing we are attached to a Widget and registered with a focus manager, | 906 // Providing we are attached to a Widget and registered with a focus manager, |
903 // we should de-register from that focus manager now. | 907 // we should de-register from that focus manager now. |
904 if (GetWidget() && accelerator_focus_manager_) | 908 if (GetWidget() && accelerator_focus_manager_) |
905 accelerator_focus_manager_->UnregisterAccelerator(accelerator, this); | 909 accelerator_focus_manager_->UnregisterAccelerator(accelerator, this); |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1335 start_pt = p; | 1339 start_pt = p; |
1336 } | 1340 } |
1337 | 1341 |
1338 // Tree operations ------------------------------------------------------------- | 1342 // Tree operations ------------------------------------------------------------- |
1339 | 1343 |
1340 void View::DoRemoveChildView(View* view, | 1344 void View::DoRemoveChildView(View* view, |
1341 bool update_focus_cycle, | 1345 bool update_focus_cycle, |
1342 bool update_tool_tip, | 1346 bool update_tool_tip, |
1343 bool delete_removed_view) { | 1347 bool delete_removed_view) { |
1344 DCHECK(view); | 1348 DCHECK(view); |
1345 const Views::iterator i = std::find(children_.begin(), children_.end(), view); | 1349 const Views::iterator i(std::find(children_.begin(), children_.end(), view)); |
1346 scoped_ptr<View> view_to_be_deleted; | 1350 scoped_ptr<View> view_to_be_deleted; |
1347 if (i != children_.end()) { | 1351 if (i != children_.end()) { |
1348 if (update_focus_cycle) { | 1352 if (update_focus_cycle) { |
1349 // Let's remove the view from the focus traversal. | 1353 // Let's remove the view from the focus traversal. |
1350 View* next_focusable = view->next_focusable_view_; | 1354 View* next_focusable = view->next_focusable_view_; |
1351 View* prev_focusable = view->previous_focusable_view_; | 1355 View* prev_focusable = view->previous_focusable_view_; |
1352 if (prev_focusable) | 1356 if (prev_focusable) |
1353 prev_focusable->next_focusable_view_ = next_focusable; | 1357 prev_focusable->next_focusable_view_ = next_focusable; |
1354 if (next_focusable) | 1358 if (next_focusable) |
1355 next_focusable->previous_focusable_view_ = prev_focusable; | 1359 next_focusable->previous_focusable_view_ = prev_focusable; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1472 Layout(); | 1476 Layout(); |
1473 } | 1477 } |
1474 | 1478 |
1475 if (NeedsNotificationWhenVisibleBoundsChange()) { | 1479 if (NeedsNotificationWhenVisibleBoundsChange()) { |
1476 OnVisibleBoundsChanged(); | 1480 OnVisibleBoundsChanged(); |
1477 } | 1481 } |
1478 | 1482 |
1479 // Notify interested Views that visible bounds within the root view may have | 1483 // Notify interested Views that visible bounds within the root view may have |
1480 // changed. | 1484 // changed. |
1481 if (descendants_to_notify_.get()) { | 1485 if (descendants_to_notify_.get()) { |
1482 for (Views::iterator i = descendants_to_notify_->begin(); | 1486 for (Views::iterator i(descendants_to_notify_->begin()); |
1483 i != descendants_to_notify_->end(); ++i) { | 1487 i != descendants_to_notify_->end(); ++i) { |
1484 (*i)->OnVisibleBoundsChanged(); | 1488 (*i)->OnVisibleBoundsChanged(); |
1485 } | 1489 } |
1486 } | 1490 } |
1487 } | 1491 } |
1488 | 1492 |
1489 // static | 1493 // static |
1490 void View::RegisterChildrenForVisibleBoundsNotification(View* view) { | 1494 void View::RegisterChildrenForVisibleBoundsNotification(View* view) { |
1491 if (view->NeedsNotificationWhenVisibleBoundsChange()) | 1495 if (view->NeedsNotificationWhenVisibleBoundsChange()) |
1492 view->RegisterForVisibleBoundsNotification(); | 1496 view->RegisterForVisibleBoundsNotification(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1527 | 1531 |
1528 void View::AddDescendantToNotify(View* view) { | 1532 void View::AddDescendantToNotify(View* view) { |
1529 DCHECK(view); | 1533 DCHECK(view); |
1530 if (!descendants_to_notify_.get()) | 1534 if (!descendants_to_notify_.get()) |
1531 descendants_to_notify_.reset(new Views); | 1535 descendants_to_notify_.reset(new Views); |
1532 descendants_to_notify_->push_back(view); | 1536 descendants_to_notify_->push_back(view); |
1533 } | 1537 } |
1534 | 1538 |
1535 void View::RemoveDescendantToNotify(View* view) { | 1539 void View::RemoveDescendantToNotify(View* view) { |
1536 DCHECK(view && descendants_to_notify_.get()); | 1540 DCHECK(view && descendants_to_notify_.get()); |
1537 Views::iterator i = std::find(descendants_to_notify_->begin(), | 1541 Views::iterator i(std::find( |
1538 descendants_to_notify_->end(), | 1542 descendants_to_notify_->begin(), descendants_to_notify_->end(), view)); |
1539 view); | |
1540 DCHECK(i != descendants_to_notify_->end()); | 1543 DCHECK(i != descendants_to_notify_->end()); |
1541 descendants_to_notify_->erase(i); | 1544 descendants_to_notify_->erase(i); |
1542 if (descendants_to_notify_->empty()) | 1545 if (descendants_to_notify_->empty()) |
1543 descendants_to_notify_.reset(); | 1546 descendants_to_notify_.reset(); |
1544 } | 1547 } |
1545 | 1548 |
1546 // Transformations ------------------------------------------------------------- | 1549 // Transformations ------------------------------------------------------------- |
1547 | 1550 |
1548 bool View::GetTransformRelativeTo(const View* ancestor, | 1551 bool View::GetTransformRelativeTo(const View* ancestor, |
1549 ui::Transform* transform) const { | 1552 ui::Transform* transform) const { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1721 // NOTREACHED assertion and verify accelerators works as | 1724 // NOTREACHED assertion and verify accelerators works as |
1722 // expected. | 1725 // expected. |
1723 #if defined(OS_WIN) | 1726 #if defined(OS_WIN) |
1724 NOTREACHED(); | 1727 NOTREACHED(); |
1725 #endif | 1728 #endif |
1726 return; | 1729 return; |
1727 } | 1730 } |
1728 // Only register accelerators if we are visible. | 1731 // Only register accelerators if we are visible. |
1729 if (!IsVisibleInRootView()) | 1732 if (!IsVisibleInRootView()) |
1730 return; | 1733 return; |
1731 std::vector<Accelerator>::const_iterator iter; | 1734 for (std::vector<Accelerator>::const_iterator i( |
1732 for (iter = accelerators_->begin() + registered_accelerator_count_; | 1735 accelerators_->begin() + registered_accelerator_count_); |
1733 iter != accelerators_->end(); ++iter) { | 1736 i != accelerators_->end(); ++i) { |
1734 accelerator_focus_manager_->RegisterAccelerator(*iter, this); | 1737 accelerator_focus_manager_->RegisterAccelerator(*i, this); |
1735 } | 1738 } |
1736 registered_accelerator_count_ = accelerators_->size(); | 1739 registered_accelerator_count_ = accelerators_->size(); |
1737 } | 1740 } |
1738 | 1741 |
1739 void View::UnregisterAccelerators(bool leave_data_intact) { | 1742 void View::UnregisterAccelerators(bool leave_data_intact) { |
1740 if (!accelerators_.get()) | 1743 if (!accelerators_.get()) |
1741 return; | 1744 return; |
1742 | 1745 |
1743 if (GetWidget()) { | 1746 if (GetWidget()) { |
1744 if (accelerator_focus_manager_) { | 1747 if (accelerator_focus_manager_) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1895 result.append(GetChildViewAt(i)->PrintViewGraph(false)); | 1898 result.append(GetChildViewAt(i)->PrintViewGraph(false)); |
1896 | 1899 |
1897 if (first) | 1900 if (first) |
1898 result.append("}\n"); | 1901 result.append("}\n"); |
1899 | 1902 |
1900 return result; | 1903 return result; |
1901 } | 1904 } |
1902 #endif | 1905 #endif |
1903 | 1906 |
1904 } // namespace views | 1907 } // namespace views |
OLD | NEW |