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

Side by Side Diff: chrome/browser/ui/views/bookmark_bar_view.cc

Issue 6452011: Rework tree APIs to reflect Google style and more const-correctness.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 10 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
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 "chrome/browser/ui/views/bookmark_bar_view.h" 5 #include "chrome/browser/ui/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 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 } 919 }
920 920
921 void BookmarkBarView::Loaded(BookmarkModel* model) { 921 void BookmarkBarView::Loaded(BookmarkModel* model) {
922 volatile int button_count = GetBookmarkButtonCount(); 922 volatile int button_count = GetBookmarkButtonCount();
923 DCHECK(button_count == 0); // If non-zero it means Load was invoked more than 923 DCHECK(button_count == 0); // If non-zero it means Load was invoked more than
924 // once, or we didn't properly clear things. 924 // once, or we didn't properly clear things.
925 // Either of which shouldn't happen 925 // Either of which shouldn't happen
926 const BookmarkNode* node = model_->GetBookmarkBarNode(); 926 const BookmarkNode* node = model_->GetBookmarkBarNode();
927 DCHECK(node && model_->other_node()); 927 DCHECK(node && model_->other_node());
928 // Create a button for each of the children on the bookmark bar. 928 // Create a button for each of the children on the bookmark bar.
929 for (int i = 0, child_count = node->GetChildCount(); i < child_count; ++i) 929 for (size_t i = 0, child_count = node->GetChildCount();
930 AddChildView(i, CreateBookmarkButton(node->GetChild(i))); 930 static_cast<int>(i) < child_count; ++i) {
931 AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i);
932 }
931 UpdateColors(); 933 UpdateColors();
932 other_bookmarked_button_->SetVisible( 934 other_bookmarked_button_->SetVisible(
933 model->other_node()->GetChildCount() > 0); 935 model->other_node()->GetChildCount() > 0);
934 other_bookmarked_button_->SetEnabled(true); 936 other_bookmarked_button_->SetEnabled(true);
935 937
936 Layout(); 938 Layout();
937 SchedulePaint(); 939 SchedulePaint();
938 } 940 }
939 941
940 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { 942 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 NotifyModelChanged(); 975 NotifyModelChanged();
974 if (parent != model_->GetBookmarkBarNode()) { 976 if (parent != model_->GetBookmarkBarNode()) {
975 // We only care about nodes on the bookmark bar. 977 // We only care about nodes on the bookmark bar.
976 return; 978 return;
977 } 979 }
978 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); 980 DCHECK(index >= 0 && index <= GetBookmarkButtonCount());
979 const BookmarkNode* node = parent->GetChild(index); 981 const BookmarkNode* node = parent->GetChild(index);
980 if (!throbbing_view_ && sync_service_ && sync_service_->SetupInProgress()) { 982 if (!throbbing_view_ && sync_service_ && sync_service_->SetupInProgress()) {
981 StartThrobbing(node, true); 983 StartThrobbing(node, true);
982 } 984 }
983 AddChildView(index, CreateBookmarkButton(node)); 985 AddChildViewAt(CreateBookmarkButton(node), index);
984 UpdateColors(); 986 UpdateColors();
985 Layout(); 987 Layout();
986 SchedulePaint(); 988 SchedulePaint();
987 } 989 }
988 990
989 void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model, 991 void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model,
990 const BookmarkNode* parent, 992 const BookmarkNode* parent,
991 int old_index, 993 int old_index,
992 const BookmarkNode* node) { 994 const BookmarkNode* node) {
993 BookmarkNodeRemovedImpl(model, parent, old_index); 995 BookmarkNodeRemovedImpl(model, parent, old_index);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 return; // We only care about reordering of the bookmark bar node. 1051 return; // We only care about reordering of the bookmark bar node.
1050 1052
1051 // Remove the existing buttons. 1053 // Remove the existing buttons.
1052 while (GetBookmarkButtonCount()) { 1054 while (GetBookmarkButtonCount()) {
1053 views::View* button = GetChildViewAt(0); 1055 views::View* button = GetChildViewAt(0);
1054 RemoveChildView(button); 1056 RemoveChildView(button);
1055 MessageLoop::current()->DeleteSoon(FROM_HERE, button); 1057 MessageLoop::current()->DeleteSoon(FROM_HERE, button);
1056 } 1058 }
1057 1059
1058 // Create the new buttons. 1060 // Create the new buttons.
1059 for (int i = 0, child_count = node->GetChildCount(); i < child_count; ++i) 1061 for (size_t i = 0, child_count = node->GetChildCount();
1060 AddChildView(i, CreateBookmarkButton(node->GetChild(i))); 1062 static_cast<int>(i) < child_count; ++i) {
1063 AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i);
1064 }
1061 UpdateColors(); 1065 UpdateColors();
1062 1066
1063 Layout(); 1067 Layout();
1064 SchedulePaint(); 1068 SchedulePaint();
1065 } 1069 }
1066 1070
1067 void BookmarkBarView::BookmarkNodeFavIconLoaded(BookmarkModel* model, 1071 void BookmarkBarView::BookmarkNodeFavIconLoaded(BookmarkModel* model,
1068 const BookmarkNode* node) { 1072 const BookmarkNode* node) {
1069 BookmarkNodeChangedImpl(model, node); 1073 BookmarkNodeChangedImpl(model, node);
1070 } 1074 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 void BookmarkBarView::RunMenu(views::View* view, const gfx::Point& pt) { 1147 void BookmarkBarView::RunMenu(views::View* view, const gfx::Point& pt) {
1144 const BookmarkNode* node; 1148 const BookmarkNode* node;
1145 1149
1146 int start_index = 0; 1150 int start_index = 0;
1147 if (view == other_bookmarked_button_) { 1151 if (view == other_bookmarked_button_) {
1148 node = model_->other_node(); 1152 node = model_->other_node();
1149 } else if (view == overflow_button_) { 1153 } else if (view == overflow_button_) {
1150 node = model_->GetBookmarkBarNode(); 1154 node = model_->GetBookmarkBarNode();
1151 start_index = GetFirstHiddenNodeIndex(); 1155 start_index = GetFirstHiddenNodeIndex();
1152 } else { 1156 } else {
1153 int button_index = GetChildIndex(view); 1157 int button_index = GetIndexOf(view);
1154 DCHECK_NE(-1, button_index); 1158 DCHECK_NE(-1, button_index);
1155 node = model_->GetBookmarkBarNode()->GetChild(button_index); 1159 node = model_->GetBookmarkBarNode()->GetChild(button_index);
1156 } 1160 }
1157 1161
1158 bookmark_menu_ = new BookmarkMenuController(browser_, profile_, 1162 bookmark_menu_ = new BookmarkMenuController(browser_, profile_,
1159 page_navigator_, GetWindow()->GetNativeWindow(), node, start_index); 1163 page_navigator_, GetWindow()->GetNativeWindow(), node, start_index);
1160 bookmark_menu_->set_observer(this); 1164 bookmark_menu_->set_observer(this);
1161 bookmark_menu_->RunMenuAt(this, false); 1165 bookmark_menu_->RunMenuAt(this, false);
1162 } 1166 }
1163 1167
1164 void BookmarkBarView::ButtonPressed(views::Button* sender, 1168 void BookmarkBarView::ButtonPressed(views::Button* sender,
1165 const views::Event& event) { 1169 const views::Event& event) {
1166 // Show the login wizard if the user clicked the re-login button. 1170 // Show the login wizard if the user clicked the re-login button.
1167 if (sender->tag() == kSyncErrorButtonTag) { 1171 if (sender->tag() == kSyncErrorButtonTag) {
1168 DCHECK(sender == sync_error_button_); 1172 DCHECK(sender == sync_error_button_);
1169 DCHECK(sync_service_ && !sync_service_->IsManaged()); 1173 DCHECK(sync_service_ && !sync_service_->IsManaged());
1170 sync_service_->ShowErrorUI(GetWindow()->GetNativeWindow()); 1174 sync_service_->ShowErrorUI(GetWindow()->GetNativeWindow());
1171 return; 1175 return;
1172 } 1176 }
1173 1177
1174 const BookmarkNode* node; 1178 const BookmarkNode* node;
1175 if (sender->tag() == kOtherFolderButtonTag) { 1179 if (sender->tag() == kOtherFolderButtonTag) {
1176 node = model_->other_node(); 1180 node = model_->other_node();
1177 } else { 1181 } else {
1178 int index = GetChildIndex(sender); 1182 int index = GetIndexOf(sender);
1179 DCHECK_NE(-1, index); 1183 DCHECK_NE(-1, index);
1180 node = model_->GetBookmarkBarNode()->GetChild(index); 1184 node = model_->GetBookmarkBarNode()->GetChild(index);
1181 } 1185 }
1182 DCHECK(page_navigator_); 1186 DCHECK(page_navigator_);
1183 1187
1184 WindowOpenDisposition disposition_from_event_flags = 1188 WindowOpenDisposition disposition_from_event_flags =
1185 event_utils::DispositionFromEventFlags(sender->mouse_event_flags()); 1189 event_utils::DispositionFromEventFlags(sender->mouse_event_flags());
1186 1190
1187 if (node->is_url()) { 1191 if (node->is_url()) {
1188 page_navigator_->OpenURL(node->GetURL(), GURL(), 1192 page_navigator_->OpenURL(node->GetURL(), GURL(),
(...skipping 17 matching lines...) Expand all
1206 const BookmarkNode* parent = NULL; 1210 const BookmarkNode* parent = NULL;
1207 std::vector<const BookmarkNode*> nodes; 1211 std::vector<const BookmarkNode*> nodes;
1208 if (source == other_bookmarked_button_) { 1212 if (source == other_bookmarked_button_) {
1209 parent = model_->other_node(); 1213 parent = model_->other_node();
1210 // Do this so the user can open all bookmarks. BookmarkContextMenu makes 1214 // Do this so the user can open all bookmarks. BookmarkContextMenu makes
1211 // sure the user can edit/delete the node in this case. 1215 // sure the user can edit/delete the node in this case.
1212 nodes.push_back(parent); 1216 nodes.push_back(parent);
1213 } else if (source != this) { 1217 } else if (source != this) {
1214 // User clicked on one of the bookmark buttons, find which one they 1218 // User clicked on one of the bookmark buttons, find which one they
1215 // clicked on. 1219 // clicked on.
1216 int bookmark_button_index = GetChildIndex(source); 1220 int bookmark_button_index = GetIndexOf(source);
1217 DCHECK(bookmark_button_index != -1 && 1221 DCHECK(bookmark_button_index != -1 &&
1218 bookmark_button_index < GetBookmarkButtonCount()); 1222 bookmark_button_index < GetBookmarkButtonCount());
1219 const BookmarkNode* node = 1223 const BookmarkNode* node =
1220 model_->GetBookmarkBarNode()->GetChild(bookmark_button_index); 1224 model_->GetBookmarkBarNode()->GetChild(bookmark_button_index);
1221 nodes.push_back(node); 1225 nodes.push_back(node);
1222 parent = node->GetParent(); 1226 parent = node->GetParent();
1223 } else { 1227 } else {
1224 parent = model_->GetBookmarkBarNode(); 1228 parent = model_->GetBookmarkBarNode();
1225 nodes.push_back(parent); 1229 nodes.push_back(parent);
1226 } 1230 }
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 1522
1519 // Use a large number so that the button continues to throb. 1523 // Use a large number so that the button continues to throb.
1520 if (throbbing_view_) 1524 if (throbbing_view_)
1521 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); 1525 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max());
1522 } 1526 }
1523 1527
1524 int BookmarkBarView::GetBookmarkButtonCount() { 1528 int BookmarkBarView::GetBookmarkButtonCount() {
1525 // We contain five non-bookmark button views: other bookmarks, bookmarks 1529 // We contain five non-bookmark button views: other bookmarks, bookmarks
1526 // separator, chevrons (for overflow), the instruction label and the sync 1530 // separator, chevrons (for overflow), the instruction label and the sync
1527 // error button. 1531 // error button.
1528 return GetChildViewCount() - 5; 1532 return child_count() - 5;
1529 } 1533 }
1530 1534
1531 void BookmarkBarView::StopThrobbing(bool immediate) { 1535 void BookmarkBarView::StopThrobbing(bool immediate) {
1532 if (!throbbing_view_) 1536 if (!throbbing_view_)
1533 return; 1537 return;
1534 1538
1535 // If not immediate, cycle through 2 more complete cycles. 1539 // If not immediate, cycle through 2 more complete cycles.
1536 throbbing_view_->StartThrobbing(immediate ? 0 : 4); 1540 throbbing_view_->StartThrobbing(immediate ? 0 : 4);
1537 throbbing_view_ = NULL; 1541 throbbing_view_ = NULL;
1538 } 1542 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 return; 1587 return;
1584 SkColor text_color = 1588 SkColor text_color =
1585 theme_provider->GetColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT); 1589 theme_provider->GetColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT);
1586 for (int i = 0; i < GetBookmarkButtonCount(); ++i) 1590 for (int i = 0; i < GetBookmarkButtonCount(); ++i)
1587 GetBookmarkButton(i)->SetEnabledColor(text_color); 1591 GetBookmarkButton(i)->SetEnabledColor(text_color);
1588 other_bookmarked_button()->SetEnabledColor(text_color); 1592 other_bookmarked_button()->SetEnabledColor(text_color);
1589 } 1593 }
1590 1594
1591 gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { 1595 gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) {
1592 gfx::Size prefsize; 1596 gfx::Size prefsize;
1593 if (!GetParent() && !compute_bounds_only) 1597 if (!parent() && !compute_bounds_only)
1594 return prefsize; 1598 return prefsize;
1595 1599
1596 int x = kLeftMargin; 1600 int x = kLeftMargin;
1597 int top_margin = IsDetached() ? kDetachedTopMargin : 0; 1601 int top_margin = IsDetached() ? kDetachedTopMargin : 0;
1598 int y = top_margin; 1602 int y = top_margin;
1599 int width = View::width() - kRightMargin - kLeftMargin; 1603 int width = View::width() - kRightMargin - kLeftMargin;
1600 int height = View::height() - top_margin - kBottomMargin; 1604 int height = View::height() - top_margin - kBottomMargin;
1601 int separator_margin = kSeparatorMargin; 1605 int separator_margin = kSeparatorMargin;
1602 1606
1603 if (OnNewTabPage()) { 1607 if (OnNewTabPage()) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 // The tooltip is the only way we have to display text explaining the error 1743 // The tooltip is the only way we have to display text explaining the error
1740 // to the user. 1744 // to the user.
1741 sync_error_button->SetTooltipText( 1745 sync_error_button->SetTooltipText(
1742 UTF16ToWide(l10n_util::GetStringUTF16(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC))); 1746 UTF16ToWide(l10n_util::GetStringUTF16(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC)));
1743 sync_error_button->SetAccessibleName( 1747 sync_error_button->SetAccessibleName(
1744 l10n_util::GetStringUTF16(IDS_ACCNAME_SYNC_ERROR_BUTTON)); 1748 l10n_util::GetStringUTF16(IDS_ACCNAME_SYNC_ERROR_BUTTON));
1745 sync_error_button->SetIcon( 1749 sync_error_button->SetIcon(
1746 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); 1750 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING));
1747 return sync_error_button; 1751 return sync_error_button;
1748 } 1752 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698