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