| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/views/bookmark_bar_view.h" | 5 #include "chrome/browser/views/bookmark_bar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 // Make visible as necessary. | 946 // Make visible as necessary. |
| 947 button->SetVisible(false); | 947 button->SetVisible(false); |
| 948 // Set accessibility name. | 948 // Set accessibility name. |
| 949 button->SetAccessibleName( | 949 button->SetAccessibleName( |
| 950 l10n_util::GetString(IDS_ACCNAME_BOOKMARKS_CHEVRON)); | 950 l10n_util::GetString(IDS_ACCNAME_BOOKMARKS_CHEVRON)); |
| 951 return button; | 951 return button; |
| 952 } | 952 } |
| 953 | 953 |
| 954 void BookmarkBarView::Loaded(BookmarkModel* model) { | 954 void BookmarkBarView::Loaded(BookmarkModel* model) { |
| 955 volatile int button_count = GetBookmarkButtonCount(); | 955 volatile int button_count = GetBookmarkButtonCount(); |
| 956 CHECK(button_count == 0); // If non-zero it means Load was invoked more than | 956 DCHECK(button_count == 0); // If non-zero it means Load was invoked more than |
| 957 // once, or we didn't properly clear things. Either | 957 // once, or we didn't properly clear things. |
| 958 // of which shouldn't happen | 958 // Either of which shouldn't happen |
| 959 const BookmarkNode* node = model_->GetBookmarkBarNode(); | 959 const BookmarkNode* node = model_->GetBookmarkBarNode(); |
| 960 DCHECK(node && model_->other_node()); | 960 DCHECK(node && model_->other_node()); |
| 961 // Create a button for each of the children on the bookmark bar. | 961 // Create a button for each of the children on the bookmark bar. |
| 962 for (int i = 0, child_count = node->GetChildCount(); i < child_count; ++i) | 962 for (int i = 0, child_count = node->GetChildCount(); i < child_count; ++i) |
| 963 AddChildView(i, CreateBookmarkButton(node->GetChild(i))); | 963 AddChildView(i, CreateBookmarkButton(node->GetChild(i))); |
| 964 UpdateColors(); | 964 UpdateColors(); |
| 965 other_bookmarked_button_->SetEnabled(true); | 965 other_bookmarked_button_->SetEnabled(true); |
| 966 | 966 |
| 967 Layout(); | 967 Layout(); |
| 968 SchedulePaint(); | 968 SchedulePaint(); |
| 969 | |
| 970 CheckIntegrity(); | |
| 971 } | 969 } |
| 972 | 970 |
| 973 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { | 971 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { |
| 974 // The bookmark model should never be deleted before us. This code exists | 972 // The bookmark model should never be deleted before us. This code exists |
| 975 // to check for regressions in shutdown code and not crash. | 973 // to check for regressions in shutdown code and not crash. |
| 976 NOTREACHED(); | 974 NOTREACHED(); |
| 977 | 975 |
| 978 // Do minimal cleanup, presumably we'll be deleted shortly. | 976 // Do minimal cleanup, presumably we'll be deleted shortly. |
| 979 NotifyModelChanged(); | 977 NotifyModelChanged(); |
| 980 model_->RemoveObserver(this); | 978 model_->RemoveObserver(this); |
| 981 model_ = NULL; | 979 model_ = NULL; |
| 982 } | 980 } |
| 983 | 981 |
| 984 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, | 982 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, |
| 985 const BookmarkNode* old_parent, | 983 const BookmarkNode* old_parent, |
| 986 int old_index, | 984 int old_index, |
| 987 const BookmarkNode* new_parent, | 985 const BookmarkNode* new_parent, |
| 988 int new_index) { | 986 int new_index) { |
| 989 BookmarkNodeRemovedImpl(model, old_parent, old_index); | 987 BookmarkNodeRemovedImpl(model, old_parent, old_index); |
| 990 BookmarkNodeAddedImpl(model, new_parent, new_index); | 988 BookmarkNodeAddedImpl(model, new_parent, new_index); |
| 991 CheckIntegrity(); | |
| 992 } | 989 } |
| 993 | 990 |
| 994 void BookmarkBarView::BookmarkNodeAdded(BookmarkModel* model, | 991 void BookmarkBarView::BookmarkNodeAdded(BookmarkModel* model, |
| 995 const BookmarkNode* parent, | 992 const BookmarkNode* parent, |
| 996 int index) { | 993 int index) { |
| 997 BookmarkNodeAddedImpl(model, parent, index); | 994 BookmarkNodeAddedImpl(model, parent, index); |
| 998 CheckIntegrity(); | |
| 999 } | 995 } |
| 1000 | 996 |
| 1001 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, | 997 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, |
| 1002 const BookmarkNode* parent, | 998 const BookmarkNode* parent, |
| 1003 int index) { | 999 int index) { |
| 1004 NotifyModelChanged(); | 1000 NotifyModelChanged(); |
| 1005 if (parent != model_->GetBookmarkBarNode()) { | 1001 if (parent != model_->GetBookmarkBarNode()) { |
| 1006 // We only care about nodes on the bookmark bar. | 1002 // We only care about nodes on the bookmark bar. |
| 1007 return; | 1003 return; |
| 1008 } | 1004 } |
| 1009 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); | 1005 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); |
| 1010 const BookmarkNode* node = parent->GetChild(index); | 1006 const BookmarkNode* node = parent->GetChild(index); |
| 1011 if (!throbbing_view_ && sync_service_ && sync_service_->SetupInProgress()) { | 1007 if (!throbbing_view_ && sync_service_ && sync_service_->SetupInProgress()) { |
| 1012 StartThrobbing(node, true); | 1008 StartThrobbing(node, true); |
| 1013 } | 1009 } |
| 1014 AddChildView(index, CreateBookmarkButton(node)); | 1010 AddChildView(index, CreateBookmarkButton(node)); |
| 1015 UpdateColors(); | 1011 UpdateColors(); |
| 1016 Layout(); | 1012 Layout(); |
| 1017 SchedulePaint(); | 1013 SchedulePaint(); |
| 1018 } | 1014 } |
| 1019 | 1015 |
| 1020 void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model, | 1016 void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model, |
| 1021 const BookmarkNode* parent, | 1017 const BookmarkNode* parent, |
| 1022 int old_index, | 1018 int old_index, |
| 1023 const BookmarkNode* node) { | 1019 const BookmarkNode* node) { |
| 1024 BookmarkNodeRemovedImpl(model, parent, old_index); | 1020 BookmarkNodeRemovedImpl(model, parent, old_index); |
| 1025 CheckIntegrity(); | |
| 1026 } | 1021 } |
| 1027 | 1022 |
| 1028 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, | 1023 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, |
| 1029 const BookmarkNode* parent, | 1024 const BookmarkNode* parent, |
| 1030 int index) { | 1025 int index) { |
| 1031 StopThrobbing(true); | 1026 StopThrobbing(true); |
| 1032 // No need to start throbbing again as the bookmark bubble can't be up at | 1027 // No need to start throbbing again as the bookmark bubble can't be up at |
| 1033 // the same time as the user reorders. | 1028 // the same time as the user reorders. |
| 1034 | 1029 |
| 1035 NotifyModelChanged(); | 1030 NotifyModelChanged(); |
| 1036 if (parent != model_->GetBookmarkBarNode()) { | 1031 if (parent != model_->GetBookmarkBarNode()) { |
| 1037 // We only care about nodes on the bookmark bar. | 1032 // We only care about nodes on the bookmark bar. |
| 1038 return; | 1033 return; |
| 1039 } | 1034 } |
| 1040 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); | 1035 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); |
| 1041 views::View* button = GetChildViewAt(index); | 1036 views::View* button = GetChildViewAt(index); |
| 1042 RemoveChildView(button); | 1037 RemoveChildView(button); |
| 1043 MessageLoop::current()->DeleteSoon(FROM_HERE, button); | 1038 MessageLoop::current()->DeleteSoon(FROM_HERE, button); |
| 1044 Layout(); | 1039 Layout(); |
| 1045 SchedulePaint(); | 1040 SchedulePaint(); |
| 1046 } | 1041 } |
| 1047 | 1042 |
| 1048 void BookmarkBarView::BookmarkNodeChanged(BookmarkModel* model, | 1043 void BookmarkBarView::BookmarkNodeChanged(BookmarkModel* model, |
| 1049 const BookmarkNode* node) { | 1044 const BookmarkNode* node) { |
| 1050 NotifyModelChanged(); | 1045 NotifyModelChanged(); |
| 1051 BookmarkNodeChangedImpl(model, node); | 1046 BookmarkNodeChangedImpl(model, node); |
| 1052 CheckIntegrity(); | |
| 1053 } | 1047 } |
| 1054 | 1048 |
| 1055 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, | 1049 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, |
| 1056 const BookmarkNode* node) { | 1050 const BookmarkNode* node) { |
| 1057 if (node->GetParent() != model_->GetBookmarkBarNode()) { | 1051 if (node->GetParent() != model_->GetBookmarkBarNode()) { |
| 1058 // We only care about nodes on the bookmark bar. | 1052 // We only care about nodes on the bookmark bar. |
| 1059 return; | 1053 return; |
| 1060 } | 1054 } |
| 1061 int index = model_->GetBookmarkBarNode()->IndexOfChild(node); | 1055 int index = model_->GetBookmarkBarNode()->IndexOfChild(node); |
| 1062 DCHECK_NE(-1, index); | 1056 DCHECK_NE(-1, index); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1085 MessageLoop::current()->DeleteSoon(FROM_HERE, button); | 1079 MessageLoop::current()->DeleteSoon(FROM_HERE, button); |
| 1086 } | 1080 } |
| 1087 | 1081 |
| 1088 // Create the new buttons. | 1082 // Create the new buttons. |
| 1089 for (int i = 0, child_count = node->GetChildCount(); i < child_count; ++i) | 1083 for (int i = 0, child_count = node->GetChildCount(); i < child_count; ++i) |
| 1090 AddChildView(i, CreateBookmarkButton(node->GetChild(i))); | 1084 AddChildView(i, CreateBookmarkButton(node->GetChild(i))); |
| 1091 UpdateColors(); | 1085 UpdateColors(); |
| 1092 | 1086 |
| 1093 Layout(); | 1087 Layout(); |
| 1094 SchedulePaint(); | 1088 SchedulePaint(); |
| 1095 | |
| 1096 CheckIntegrity(); | |
| 1097 } | 1089 } |
| 1098 | 1090 |
| 1099 void BookmarkBarView::BookmarkNodeFavIconLoaded(BookmarkModel* model, | 1091 void BookmarkBarView::BookmarkNodeFavIconLoaded(BookmarkModel* model, |
| 1100 const BookmarkNode* node) { | 1092 const BookmarkNode* node) { |
| 1101 BookmarkNodeChangedImpl(model, node); | 1093 BookmarkNodeChangedImpl(model, node); |
| 1102 } | 1094 } |
| 1103 | 1095 |
| 1104 void BookmarkBarView::WriteDragData(View* sender, | 1096 void BookmarkBarView::WriteDragData(View* sender, |
| 1105 const gfx::Point& press_pt, | 1097 const gfx::Point& press_pt, |
| 1106 OSExchangeData* data) { | 1098 OSExchangeData* data) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1124 int BookmarkBarView::GetDragOperations(View* sender, const gfx::Point& p) { | 1116 int BookmarkBarView::GetDragOperations(View* sender, const gfx::Point& p) { |
| 1125 if (size_animation_->is_animating() || | 1117 if (size_animation_->is_animating() || |
| 1126 (size_animation_->GetCurrentValue() == 0 && !OnNewTabPage())) { | 1118 (size_animation_->GetCurrentValue() == 0 && !OnNewTabPage())) { |
| 1127 // Don't let the user drag while animating open or we're closed (and not on | 1119 // Don't let the user drag while animating open or we're closed (and not on |
| 1128 // the new tab page, on the new tab page size_animation_ is always 0). This | 1120 // the new tab page, on the new tab page size_animation_ is always 0). This |
| 1129 // typically is only hit if the user does something to inadvertanty trigger | 1121 // typically is only hit if the user does something to inadvertanty trigger |
| 1130 // dnd, such as pressing the mouse and hitting control-b. | 1122 // dnd, such as pressing the mouse and hitting control-b. |
| 1131 return DragDropTypes::DRAG_NONE; | 1123 return DragDropTypes::DRAG_NONE; |
| 1132 } | 1124 } |
| 1133 | 1125 |
| 1134 CheckIntegrity(); | |
| 1135 | |
| 1136 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 1126 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
| 1137 if (sender == GetBookmarkButton(i)) { | 1127 if (sender == GetBookmarkButton(i)) { |
| 1138 return bookmark_utils::BookmarkDragOperation( | 1128 return bookmark_utils::BookmarkDragOperation( |
| 1139 model_->GetBookmarkBarNode()->GetChild(i)); | 1129 model_->GetBookmarkBarNode()->GetChild(i)); |
| 1140 } | 1130 } |
| 1141 } | 1131 } |
| 1142 NOTREACHED(); | 1132 NOTREACHED(); |
| 1143 return DragDropTypes::DRAG_NONE; | 1133 return DragDropTypes::DRAG_NONE; |
| 1144 } | 1134 } |
| 1145 | 1135 |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1733 // The tooltip is the only way we have to display text explaining the error | 1723 // The tooltip is the only way we have to display text explaining the error |
| 1734 // to the user. | 1724 // to the user. |
| 1735 sync_error_button->SetTooltipText( | 1725 sync_error_button->SetTooltipText( |
| 1736 l10n_util::GetString(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC)); | 1726 l10n_util::GetString(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC)); |
| 1737 sync_error_button->SetAccessibleName( | 1727 sync_error_button->SetAccessibleName( |
| 1738 l10n_util::GetString(IDS_ACCNAME_SYNC_ERROR_BUTTON)); | 1728 l10n_util::GetString(IDS_ACCNAME_SYNC_ERROR_BUTTON)); |
| 1739 sync_error_button->SetIcon( | 1729 sync_error_button->SetIcon( |
| 1740 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); | 1730 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); |
| 1741 return sync_error_button; | 1731 return sync_error_button; |
| 1742 } | 1732 } |
| 1743 | |
| 1744 void BookmarkBarView::CheckIntegrity() { | |
| 1745 // We better be on the ui thread. | |
| 1746 CHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | |
| 1747 | |
| 1748 // And the number of views on the bookmark bar better match that of the model. | |
| 1749 volatile int model_count = model_->GetBookmarkBarNode()->GetChildCount(); | |
| 1750 volatile int view_count = GetBookmarkButtonCount(); | |
| 1751 CHECK_EQ(model_count, view_count); | |
| 1752 } | |
| OLD | NEW |