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