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

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

Issue 6264011: Makes the other bookmark button on the bookmark bar visible only if it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment Created 9 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 956 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 volatile int button_count = GetBookmarkButtonCount(); 967 volatile int button_count = GetBookmarkButtonCount();
968 DCHECK(button_count == 0); // If non-zero it means Load was invoked more than 968 DCHECK(button_count == 0); // If non-zero it means Load was invoked more than
969 // once, or we didn't properly clear things. 969 // once, or we didn't properly clear things.
970 // Either of which shouldn't happen 970 // Either of which shouldn't happen
971 const BookmarkNode* node = model_->GetBookmarkBarNode(); 971 const BookmarkNode* node = model_->GetBookmarkBarNode();
972 DCHECK(node && model_->other_node()); 972 DCHECK(node && model_->other_node());
973 // Create a button for each of the children on the bookmark bar. 973 // Create a button for each of the children on the bookmark bar.
974 for (int i = 0, child_count = node->GetChildCount(); i < child_count; ++i) 974 for (int i = 0, child_count = node->GetChildCount(); i < child_count; ++i)
975 AddChildView(i, CreateBookmarkButton(node->GetChild(i))); 975 AddChildView(i, CreateBookmarkButton(node->GetChild(i)));
976 UpdateColors(); 976 UpdateColors();
977 other_bookmarked_button_->SetVisible(
978 model->other_node()->GetChildCount() > 0);
977 other_bookmarked_button_->SetEnabled(true); 979 other_bookmarked_button_->SetEnabled(true);
978 980
979 Layout(); 981 Layout();
980 SchedulePaint(); 982 SchedulePaint();
981 } 983 }
982 984
983 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { 985 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) {
984 // In normal shutdown The bookmark model should never be deleted before us. 986 // In normal shutdown The bookmark model should never be deleted before us.
985 // When X exits suddenly though, it can happen, This code exists 987 // When X exits suddenly though, it can happen, This code exists
986 // to check for regressions in shutdown code and not crash. 988 // to check for regressions in shutdown code and not crash.
(...skipping 17 matching lines...) Expand all
1004 1006
1005 void BookmarkBarView::BookmarkNodeAdded(BookmarkModel* model, 1007 void BookmarkBarView::BookmarkNodeAdded(BookmarkModel* model,
1006 const BookmarkNode* parent, 1008 const BookmarkNode* parent,
1007 int index) { 1009 int index) {
1008 BookmarkNodeAddedImpl(model, parent, index); 1010 BookmarkNodeAddedImpl(model, parent, index);
1009 } 1011 }
1010 1012
1011 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, 1013 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model,
1012 const BookmarkNode* parent, 1014 const BookmarkNode* parent,
1013 int index) { 1015 int index) {
1016 other_bookmarked_button_->SetVisible(
1017 model->other_node()->GetChildCount() > 0);
1014 NotifyModelChanged(); 1018 NotifyModelChanged();
1015 if (parent != model_->GetBookmarkBarNode()) { 1019 if (parent != model_->GetBookmarkBarNode()) {
1016 // We only care about nodes on the bookmark bar. 1020 // We only care about nodes on the bookmark bar.
1017 return; 1021 return;
1018 } 1022 }
1019 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); 1023 DCHECK(index >= 0 && index <= GetBookmarkButtonCount());
1020 const BookmarkNode* node = parent->GetChild(index); 1024 const BookmarkNode* node = parent->GetChild(index);
1021 if (!throbbing_view_ && sync_service_ && sync_service_->SetupInProgress()) { 1025 if (!throbbing_view_ && sync_service_ && sync_service_->SetupInProgress()) {
1022 StartThrobbing(node, true); 1026 StartThrobbing(node, true);
1023 } 1027 }
1024 AddChildView(index, CreateBookmarkButton(node)); 1028 AddChildView(index, CreateBookmarkButton(node));
1025 UpdateColors(); 1029 UpdateColors();
1026 Layout(); 1030 Layout();
1027 SchedulePaint(); 1031 SchedulePaint();
1028 } 1032 }
1029 1033
1030 void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model, 1034 void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model,
1031 const BookmarkNode* parent, 1035 const BookmarkNode* parent,
1032 int old_index, 1036 int old_index,
1033 const BookmarkNode* node) { 1037 const BookmarkNode* node) {
1034 BookmarkNodeRemovedImpl(model, parent, old_index); 1038 BookmarkNodeRemovedImpl(model, parent, old_index);
1035 } 1039 }
1036 1040
1037 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, 1041 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model,
1038 const BookmarkNode* parent, 1042 const BookmarkNode* parent,
1039 int index) { 1043 int index) {
1044 other_bookmarked_button_->SetVisible(
1045 model->other_node()->GetChildCount() > 0);
1046
1040 StopThrobbing(true); 1047 StopThrobbing(true);
1041 // No need to start throbbing again as the bookmark bubble can't be up at 1048 // No need to start throbbing again as the bookmark bubble can't be up at
1042 // the same time as the user reorders. 1049 // the same time as the user reorders.
1043 1050
1044 NotifyModelChanged(); 1051 NotifyModelChanged();
1045 if (parent != model_->GetBookmarkBarNode()) { 1052 if (parent != model_->GetBookmarkBarNode()) {
1046 // We only care about nodes on the bookmark bar. 1053 // We only care about nodes on the bookmark bar.
1047 return; 1054 return;
1048 } 1055 }
1049 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); 1056 DCHECK(index >= 0 && index < GetBookmarkButtonCount());
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 } else if (!overflow_only) { 1560 } else if (!overflow_only) {
1554 throbbing_view_ = other_bookmarked_button_; 1561 throbbing_view_ = other_bookmarked_button_;
1555 } 1562 }
1556 1563
1557 // Use a large number so that the button continues to throb. 1564 // Use a large number so that the button continues to throb.
1558 if (throbbing_view_) 1565 if (throbbing_view_)
1559 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); 1566 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max());
1560 } 1567 }
1561 1568
1562 int BookmarkBarView::GetBookmarkButtonCount() { 1569 int BookmarkBarView::GetBookmarkButtonCount() {
1563 // We contain at least four non-bookmark button views: other bookmarks, 1570 // We contain five non-bookmark button views: other bookmarks, bookmarks
1564 // bookmarks separator, chevrons (for overflow), the instruction label and 1571 // separator, chevrons (for overflow), the instruction label and the sync
1565 // the sync error button. 1572 // error button.
1566 return GetChildViewCount() - 5; 1573 return GetChildViewCount() - 5;
1567 } 1574 }
1568 1575
1569 void BookmarkBarView::StopThrobbing(bool immediate) { 1576 void BookmarkBarView::StopThrobbing(bool immediate) {
1570 if (!throbbing_view_) 1577 if (!throbbing_view_)
1571 return; 1578 return;
1572 1579
1573 // If not immediate, cycle through 2 more complete cycles. 1580 // If not immediate, cycle through 2 more complete cycles.
1574 throbbing_view_->StartThrobbing(immediate ? 0 : 4); 1581 throbbing_view_->StartThrobbing(immediate ? 0 : 4);
1575 throbbing_view_ = NULL; 1582 throbbing_view_ = NULL;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 (kNewtabVerticalPadding) * current_state); 1614 (kNewtabVerticalPadding) * current_state);
1608 width -= static_cast<int>(static_cast<double> 1615 width -= static_cast<int>(static_cast<double>
1609 (kNewtabHorizontalPadding) * current_state); 1616 (kNewtabHorizontalPadding) * current_state);
1610 height -= static_cast<int>(static_cast<double> 1617 height -= static_cast<int>(static_cast<double>
1611 (kNewtabVerticalPadding * 2) * current_state); 1618 (kNewtabVerticalPadding * 2) * current_state);
1612 separator_margin -= static_cast<int>(static_cast<double> 1619 separator_margin -= static_cast<int>(static_cast<double>
1613 (kSeparatorMargin) * current_state); 1620 (kSeparatorMargin) * current_state);
1614 } 1621 }
1615 1622
1616 gfx::Size other_bookmarked_pref = 1623 gfx::Size other_bookmarked_pref =
1617 other_bookmarked_button_->GetPreferredSize(); 1624 other_bookmarked_button_->IsVisible() ?
1625 other_bookmarked_button_->GetPreferredSize() : gfx::Size();
1618 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); 1626 gfx::Size overflow_pref = overflow_button_->GetPreferredSize();
1619 gfx::Size bookmarks_separator_pref = 1627 gfx::Size bookmarks_separator_pref =
1620 bookmarks_separator_view_->GetPreferredSize(); 1628 bookmarks_separator_view_->GetPreferredSize();
1621 1629
1622 int sync_error_total_width = 0; 1630 int sync_error_total_width = 0;
1623 gfx::Size sync_error_button_pref = sync_error_button_->GetPreferredSize(); 1631 gfx::Size sync_error_button_pref = sync_error_button_->GetPreferredSize();
1624 if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) { 1632 if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) {
1625 sync_error_total_width += kButtonPadding + sync_error_button_pref.width(); 1633 sync_error_total_width += kButtonPadding + sync_error_button_pref.width();
1626 } 1634 }
1627 const int max_x = width - other_bookmarked_pref.width() - kButtonPadding - 1635 int max_x = width - overflow_pref.width() - kButtonPadding -
1628 overflow_pref.width() - kButtonPadding -
1629 bookmarks_separator_pref.width() - sync_error_total_width; 1636 bookmarks_separator_pref.width() - sync_error_total_width;
1637 if (other_bookmarked_button_->IsVisible())
1638 max_x -= other_bookmarked_pref.width() + kButtonPadding;
1630 1639
1631 // Next, layout out the buttons. Any buttons that are placed beyond the 1640 // Next, layout out the buttons. Any buttons that are placed beyond the
1632 // visible region and made invisible. 1641 // visible region and made invisible.
1633 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) { 1642 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) {
1634 gfx::Size pref = instructions_->GetPreferredSize(); 1643 gfx::Size pref = instructions_->GetPreferredSize();
1635 if (!compute_bounds_only) { 1644 if (!compute_bounds_only) {
1636 instructions_->SetBounds( 1645 instructions_->SetBounds(
1637 x + kInstructionsPadding, y, 1646 x + kInstructionsPadding, y,
1638 std::min(static_cast<int>(pref.width()), 1647 std::min(static_cast<int>(pref.width()),
1639 max_x - x), 1648 max_x - x),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 bookmarks_separator_view_->SetBounds(x, 1688 bookmarks_separator_view_->SetBounds(x,
1680 y - top_margin, 1689 y - top_margin,
1681 bookmarks_separator_pref.width(), 1690 bookmarks_separator_pref.width(),
1682 height + top_margin + kBottomMargin - 1691 height + top_margin + kBottomMargin -
1683 separator_margin); 1692 separator_margin);
1684 } 1693 }
1685 1694
1686 x += bookmarks_separator_pref.width(); 1695 x += bookmarks_separator_pref.width();
1687 1696
1688 // The other bookmarks button. 1697 // The other bookmarks button.
1689 if (!compute_bounds_only) { 1698 if (other_bookmarked_button_->IsVisible()) {
1690 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(), 1699 if (!compute_bounds_only) {
1691 height); 1700 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(),
1701 height);
1702 }
1703 x += other_bookmarked_pref.width() + kButtonPadding;
1692 } 1704 }
1693 x += other_bookmarked_pref.width() + kButtonPadding;
1694 1705
1695 // Set the real bounds of the sync error button only if it needs to appear on 1706 // Set the real bounds of the sync error button only if it needs to appear on
1696 // the bookmarks bar. 1707 // the bookmarks bar.
1697 if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) { 1708 if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) {
1698 x += kButtonPadding; 1709 x += kButtonPadding;
1699 if (!compute_bounds_only) { 1710 if (!compute_bounds_only) {
1700 sync_error_button_->SetBounds( 1711 sync_error_button_->SetBounds(
1701 x, y, sync_error_button_pref.width(), height); 1712 x, y, sync_error_button_pref.width(), height);
1702 sync_error_button_->SetVisible(true); 1713 sync_error_button_->SetVisible(true);
1703 } 1714 }
(...skipping 30 matching lines...) Expand all
1734 // The tooltip is the only way we have to display text explaining the error 1745 // The tooltip is the only way we have to display text explaining the error
1735 // to the user. 1746 // to the user.
1736 sync_error_button->SetTooltipText( 1747 sync_error_button->SetTooltipText(
1737 UTF16ToWide(l10n_util::GetStringUTF16(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC))); 1748 UTF16ToWide(l10n_util::GetStringUTF16(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC)));
1738 sync_error_button->SetAccessibleName( 1749 sync_error_button->SetAccessibleName(
1739 l10n_util::GetStringUTF16(IDS_ACCNAME_SYNC_ERROR_BUTTON)); 1750 l10n_util::GetStringUTF16(IDS_ACCNAME_SYNC_ERROR_BUTTON));
1740 sync_error_button->SetIcon( 1751 sync_error_button->SetIcon(
1741 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); 1752 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING));
1742 return sync_error_button; 1753 return sync_error_button;
1743 } 1754 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698