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

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

Issue 8391034: Remove sync error button from bookmark bar (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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/bookmarks/bookmark_bar_view.h" 5 #include "chrome/browser/ui/views/bookmarks/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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/i18n/rtl.h" 13 #include "base/i18n/rtl.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "chrome/browser/bookmarks/bookmark_model.h" 17 #include "chrome/browser/bookmarks/bookmark_model.h"
18 #include "chrome/browser/bookmarks/bookmark_utils.h" 18 #include "chrome/browser/bookmarks/bookmark_utils.h"
19 #include "chrome/browser/browser_shutdown.h" 19 #include "chrome/browser/browser_shutdown.h"
20 #include "chrome/browser/defaults.h" 20 #include "chrome/browser/defaults.h"
21 #include "chrome/browser/extensions/extension_service.h" 21 #include "chrome/browser/extensions/extension_service.h"
22 #include "chrome/browser/prefs/pref_service.h" 22 #include "chrome/browser/prefs/pref_service.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/sync/sync_ui_util.h" 24 #include "chrome/browser/sync/profile_sync_service.h"
25 #include "chrome/browser/themes/theme_service.h" 25 #include "chrome/browser/themes/theme_service.h"
26 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" 26 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
27 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
29 #include "chrome/browser/ui/view_ids.h" 29 #include "chrome/browser/ui/view_ids.h"
30 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" 30 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h"
31 #include "chrome/browser/ui/views/event_utils.h" 31 #include "chrome/browser/ui/views/event_utils.h"
32 #include "chrome/browser/ui/views/frame/browser_view.h" 32 #include "chrome/browser/ui/views/frame/browser_view.h"
33 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 33 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
34 #include "chrome/common/chrome_notification_types.h" 34 #include "chrome/common/chrome_notification_types.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 // Starting x-coordinate of the separator line within a separator. 112 // Starting x-coordinate of the separator line within a separator.
113 static const int kSeparatorStartX = 2; 113 static const int kSeparatorStartX = 2;
114 114
115 // Left-padding for the instructional text. 115 // Left-padding for the instructional text.
116 static const int kInstructionsPadding = 6; 116 static const int kInstructionsPadding = 6;
117 117
118 // Tag for the 'Other bookmarks' button. 118 // Tag for the 'Other bookmarks' button.
119 static const int kOtherFolderButtonTag = 1; 119 static const int kOtherFolderButtonTag = 1;
120 120
121 // Tag for the sync error button.
122 static const int kSyncErrorButtonTag = 2;
123
124 namespace { 121 namespace {
125 122
126 // BookmarkButton ------------------------------------------------------------- 123 // BookmarkButton -------------------------------------------------------------
127 124
128 // Buttons used for the bookmarks on the bookmark bar. 125 // Buttons used for the bookmarks on the bookmark bar.
129 126
130 class BookmarkButton : public views::TextButton { 127 class BookmarkButton : public views::TextButton {
131 public: 128 public:
132 // The internal view class name. 129 // The internal view class name.
133 static const char kViewClassName[]; 130 static const char kViewClassName[];
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 return *kFolderIcon; 361 return *kFolderIcon;
365 } 362 }
366 363
367 BookmarkBarView::BookmarkBarView(Browser* browser) 364 BookmarkBarView::BookmarkBarView(Browser* browser)
368 : page_navigator_(NULL), 365 : page_navigator_(NULL),
369 model_(NULL), 366 model_(NULL),
370 bookmark_menu_(NULL), 367 bookmark_menu_(NULL),
371 bookmark_drop_menu_(NULL), 368 bookmark_drop_menu_(NULL),
372 other_bookmarked_button_(NULL), 369 other_bookmarked_button_(NULL),
373 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)), 370 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)),
374 sync_error_button_(NULL),
375 sync_service_(browser->profile()->GetProfileSyncService()),
376 overflow_button_(NULL), 371 overflow_button_(NULL),
377 instructions_(NULL), 372 instructions_(NULL),
378 bookmarks_separator_view_(NULL), 373 bookmarks_separator_view_(NULL),
379 browser_(browser), 374 browser_(browser),
380 infobar_visible_(false), 375 infobar_visible_(false),
381 throbbing_view_(NULL), 376 throbbing_view_(NULL),
382 bookmark_bar_state_(BookmarkBar::SHOW), 377 bookmark_bar_state_(BookmarkBar::SHOW),
383 animating_detached_(false) { 378 animating_detached_(false) {
384 if (sync_service_)
385 sync_service_->AddObserver(this);
386
387 set_id(VIEW_ID_BOOKMARK_BAR); 379 set_id(VIEW_ID_BOOKMARK_BAR);
388 Init(); 380 Init();
389 381
390 size_animation_->Reset(1); 382 size_animation_->Reset(1);
391 } 383 }
392 384
393 BookmarkBarView::~BookmarkBarView() { 385 BookmarkBarView::~BookmarkBarView() {
394 if (model_) 386 if (model_)
395 model_->RemoveObserver(this); 387 model_->RemoveObserver(this);
396 388
397 // It's possible for the menu to outlive us, reset the observer to make sure 389 // It's possible for the menu to outlive us, reset the observer to make sure
398 // it doesn't have a reference to us. 390 // it doesn't have a reference to us.
399 if (bookmark_menu_) { 391 if (bookmark_menu_) {
400 bookmark_menu_->set_observer(NULL); 392 bookmark_menu_->set_observer(NULL);
401 bookmark_menu_->SetPageNavigator(NULL); 393 bookmark_menu_->SetPageNavigator(NULL);
402 } 394 }
403 if (context_menu_.get()) 395 if (context_menu_.get())
404 context_menu_->SetPageNavigator(NULL); 396 context_menu_->SetPageNavigator(NULL);
405 397
406 StopShowFolderDropMenuTimer(); 398 StopShowFolderDropMenuTimer();
407
408 if (sync_service_)
409 sync_service_->RemoveObserver(this);
410 } 399 }
411 400
412 void BookmarkBarView::SetPageNavigator(PageNavigator* navigator) { 401 void BookmarkBarView::SetPageNavigator(PageNavigator* navigator) {
413 page_navigator_ = navigator; 402 page_navigator_ = navigator;
414 if (bookmark_menu_) 403 if (bookmark_menu_)
415 bookmark_menu_->SetPageNavigator(navigator); 404 bookmark_menu_->SetPageNavigator(navigator);
416 if (context_menu_.get()) 405 if (context_menu_.get())
417 context_menu_->SetPageNavigator(navigator); 406 context_menu_->SetPageNavigator(navigator);
418 } 407 }
419 408
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 // The minimum width of the bookmark bar should at least contain the overflow 576 // The minimum width of the bookmark bar should at least contain the overflow
588 // button, by which one can access all the Bookmark Bar items, and the "Other 577 // button, by which one can access all the Bookmark Bar items, and the "Other
589 // Bookmarks" folder, along with appropriate margins and button padding. 578 // Bookmarks" folder, along with appropriate margins and button padding.
590 int width = kLeftMargin; 579 int width = kLeftMargin;
591 580
592 if (bookmark_bar_state_ == BookmarkBar::DETACHED) { 581 if (bookmark_bar_state_ == BookmarkBar::DETACHED) {
593 double current_state = 1 - size_animation_->GetCurrentValue(); 582 double current_state = 1 - size_animation_->GetCurrentValue();
594 width += 2 * static_cast<int>(kNewtabHorizontalPadding * current_state); 583 width += 2 * static_cast<int>(kNewtabHorizontalPadding * current_state);
595 } 584 }
596 585
597 int sync_error_total_width = 0;
598 gfx::Size sync_error_button_pref = sync_error_button_->GetPreferredSize();
599 if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_))
600 sync_error_total_width += kButtonPadding + sync_error_button_pref.width();
601
602 gfx::Size other_bookmarked_pref = 586 gfx::Size other_bookmarked_pref =
603 other_bookmarked_button_->GetPreferredSize(); 587 other_bookmarked_button_->GetPreferredSize();
604 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); 588 gfx::Size overflow_pref = overflow_button_->GetPreferredSize();
605 gfx::Size bookmarks_separator_pref = 589 gfx::Size bookmarks_separator_pref =
606 bookmarks_separator_view_->GetPreferredSize(); 590 bookmarks_separator_view_->GetPreferredSize();
607 591
608 width += (other_bookmarked_pref.width() + kButtonPadding + 592 width += (other_bookmarked_pref.width() + kButtonPadding +
Peter Kasting 2011/10/26 18:12:01 Nit: No parens needed
sail 2011/10/27 00:45:54 Done.
609 overflow_pref.width() + kButtonPadding + 593 overflow_pref.width() + kButtonPadding +
610 bookmarks_separator_pref.width() + sync_error_total_width); 594 bookmarks_separator_pref.width());
611 595
612 return gfx::Size(width, browser_defaults::kBookmarkBarHeight); 596 return gfx::Size(width, browser_defaults::kBookmarkBarHeight);
613 } 597 }
614 598
615 void BookmarkBarView::Layout() { 599 void BookmarkBarView::Layout() {
616 LayoutItems(false); 600 LayoutItems(false);
617 } 601 }
618 602
619 void BookmarkBarView::ViewHierarchyChanged(bool is_add, 603 void BookmarkBarView::ViewHierarchyChanged(bool is_add,
620 View* parent, 604 View* parent,
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 804
821 std::string BookmarkBarView::GetClassName() const { 805 std::string BookmarkBarView::GetClassName() const {
822 return kViewClassName; 806 return kViewClassName;
823 } 807 }
824 808
825 void BookmarkBarView::GetAccessibleState(ui::AccessibleViewState* state) { 809 void BookmarkBarView::GetAccessibleState(ui::AccessibleViewState* state) {
826 state->role = ui::AccessibilityTypes::ROLE_TOOLBAR; 810 state->role = ui::AccessibilityTypes::ROLE_TOOLBAR;
827 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS); 811 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS);
828 } 812 }
829 813
830 void BookmarkBarView::OnStateChanged() {
831 // When the sync state changes, it is sufficient to invoke View::Layout since
832 // during layout we query the profile sync service and determine whether the
833 // new state requires showing the sync error button so that the user can
834 // re-enter her password. If extension shelf appears along with the bookmark
835 // shelf, it too needs to be layed out. Since both have the same parent, it is
836 // enough to let the parent layout both of these children.
837 // TODO(sky): This should not require Layout() and SchedulePaint(). Needs
838 // some cleanup.
839 PreferredSizeChanged();
840 Layout();
841 SchedulePaint();
842 }
843
844 void BookmarkBarView::AnimationProgressed(const ui::Animation* animation) { 814 void BookmarkBarView::AnimationProgressed(const ui::Animation* animation) {
845 if (browser_) 815 if (browser_)
846 browser_->BookmarkBarSizeChanged(true); 816 browser_->BookmarkBarSizeChanged(true);
847 } 817 }
848 818
849 void BookmarkBarView::AnimationEnded(const ui::Animation* animation) { 819 void BookmarkBarView::AnimationEnded(const ui::Animation* animation) {
850 if (browser_) 820 if (browser_)
851 browser_->BookmarkBarSizeChanged(false); 821 browser_->BookmarkBarSizeChanged(false);
852 822
853 SchedulePaint(); 823 SchedulePaint();
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 } 1004 }
1035 1005
1036 bookmark_menu_ = new BookmarkMenuController(browser_->profile(), 1006 bookmark_menu_ = new BookmarkMenuController(browser_->profile(),
1037 page_navigator_, GetWidget(), node, start_index); 1007 page_navigator_, GetWidget(), node, start_index);
1038 bookmark_menu_->set_observer(this); 1008 bookmark_menu_->set_observer(this);
1039 bookmark_menu_->RunMenuAt(this, false); 1009 bookmark_menu_->RunMenuAt(this, false);
1040 } 1010 }
1041 1011
1042 void BookmarkBarView::ButtonPressed(views::Button* sender, 1012 void BookmarkBarView::ButtonPressed(views::Button* sender,
1043 const views::Event& event) { 1013 const views::Event& event) {
1044 // Show the login wizard if the user clicked the re-login button.
1045 if (sender->tag() == kSyncErrorButtonTag) {
1046 DCHECK(sender == sync_error_button_);
1047 DCHECK(sync_service_ && !sync_service_->IsManaged());
1048 sync_service_->ShowErrorUI();
1049 return;
1050 }
1051
1052 const BookmarkNode* node; 1014 const BookmarkNode* node;
1053 if (sender->tag() == kOtherFolderButtonTag) { 1015 if (sender->tag() == kOtherFolderButtonTag) {
1054 node = model_->other_node(); 1016 node = model_->other_node();
1055 } else { 1017 } else {
1056 int index = GetIndexOf(sender); 1018 int index = GetIndexOf(sender);
1057 DCHECK_NE(-1, index); 1019 DCHECK_NE(-1, index);
1058 node = model_->bookmark_bar_node()->GetChild(index); 1020 node = model_->bookmark_bar_node()->GetChild(index);
1059 } 1021 }
1060 DCHECK(page_navigator_); 1022 DCHECK(page_navigator_);
1061 1023
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 // UpdateColors(), which will set the appropriate colors for all the objects 1108 // UpdateColors(), which will set the appropriate colors for all the objects
1147 // added in this function. 1109 // added in this function.
1148 1110
1149 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1111 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1150 1112
1151 if (!kDefaultFavicon) 1113 if (!kDefaultFavicon)
1152 kDefaultFavicon = rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); 1114 kDefaultFavicon = rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
1153 1115
1154 // Child views are traversed in the order they are added. Make sure the order 1116 // Child views are traversed in the order they are added. Make sure the order
1155 // they are added matches the visual order. 1117 // they are added matches the visual order.
1156 sync_error_button_ = CreateSyncErrorButton();
1157 AddChildView(sync_error_button_);
1158
1159 overflow_button_ = CreateOverflowButton(); 1118 overflow_button_ = CreateOverflowButton();
1160 AddChildView(overflow_button_); 1119 AddChildView(overflow_button_);
1161 1120
1162 other_bookmarked_button_ = CreateOtherBookmarkedButton(); 1121 other_bookmarked_button_ = CreateOtherBookmarkedButton();
1163 // We'll re-enable when the model is loaded. 1122 // We'll re-enable when the model is loaded.
1164 other_bookmarked_button_->SetEnabled(false); 1123 other_bookmarked_button_->SetEnabled(false);
1165 AddChildView(other_bookmarked_button_); 1124 AddChildView(other_bookmarked_button_);
1166 1125
1167 bookmarks_separator_view_ = new ButtonSeparatorView(); 1126 bookmarks_separator_view_ = new ButtonSeparatorView();
1168 AddChildView(bookmarks_separator_view_); 1127 AddChildView(bookmarks_separator_view_);
(...skipping 14 matching lines...) Expand all
1183 if (model_) { 1142 if (model_) {
1184 model_->AddObserver(this); 1143 model_->AddObserver(this);
1185 if (model_->IsLoaded()) 1144 if (model_->IsLoaded())
1186 Loaded(model_, false); 1145 Loaded(model_, false);
1187 // else case: we'll receive notification back from the BookmarkModel when 1146 // else case: we'll receive notification back from the BookmarkModel when
1188 // done loading, then we'll populate the bar. 1147 // done loading, then we'll populate the bar.
1189 } 1148 }
1190 } 1149 }
1191 1150
1192 int BookmarkBarView::GetBookmarkButtonCount() { 1151 int BookmarkBarView::GetBookmarkButtonCount() {
1193 // We contain five non-bookmark button views: other bookmarks, bookmarks 1152 // We contain four non-bookmark button views: other bookmarks, bookmarks
1194 // separator, chevrons (for overflow), the instruction label and the sync 1153 // separator, chevrons (for overflow), and the instruction label.
1195 // error button. 1154 return child_count() - 4;
1196 return child_count() - 5;
1197 } 1155 }
1198 1156
1199 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { 1157 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) {
1200 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); 1158 DCHECK(index >= 0 && index < GetBookmarkButtonCount());
1201 return static_cast<views::TextButton*>(child_at(index)); 1159 return static_cast<views::TextButton*>(child_at(index));
1202 } 1160 }
1203 1161
1204 int BookmarkBarView::GetFirstHiddenNodeIndex() { 1162 int BookmarkBarView::GetFirstHiddenNodeIndex() {
1205 const int bb_count = GetBookmarkButtonCount(); 1163 const int bb_count = GetBookmarkButtonCount();
1206 for (int i = 0; i < bb_count; ++i) { 1164 for (int i = 0; i < bb_count; ++i) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 button->EnableCanvasFlippingForRTLUI(true); 1198 button->EnableCanvasFlippingForRTLUI(true);
1241 1199
1242 // Make visible as necessary. 1200 // Make visible as necessary.
1243 button->SetVisible(false); 1201 button->SetVisible(false);
1244 // Set accessibility name. 1202 // Set accessibility name.
1245 button->SetAccessibleName( 1203 button->SetAccessibleName(
1246 l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS_CHEVRON)); 1204 l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS_CHEVRON));
1247 return button; 1205 return button;
1248 } 1206 }
1249 1207
1250 views::TextButton* BookmarkBarView::CreateSyncErrorButton() {
1251 views::TextButton* sync_error_button = new views::TextButton(
1252 this, l10n_util::GetStringUTF16(IDS_SYNC_BOOKMARK_BAR_ERROR));
1253 sync_error_button->set_tag(kSyncErrorButtonTag);
1254
1255 // The tooltip is the only way we have to display text explaining the error
1256 // to the user.
1257 sync_error_button->SetTooltipText(
1258 l10n_util::GetStringUTF16(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC));
1259 sync_error_button->SetAccessibleName(
1260 l10n_util::GetStringUTF16(IDS_ACCNAME_SYNC_ERROR_BUTTON));
1261 sync_error_button->SetIcon(
1262 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING));
1263 return sync_error_button;
1264 }
1265
1266 views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) { 1208 views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) {
1267 if (node->is_url()) { 1209 if (node->is_url()) {
1268 BookmarkButton* button = new BookmarkButton( 1210 BookmarkButton* button = new BookmarkButton(
1269 this, node->url(), node->GetTitle(), browser_->profile()); 1211 this, node->url(), node->GetTitle(), browser_->profile());
1270 ConfigureButton(node, button); 1212 ConfigureButton(node, button);
1271 return button; 1213 return button;
1272 } else { 1214 } else {
1273 views::MenuButton* button = new BookmarkFolderButton( 1215 views::MenuButton* button = new BookmarkFolderButton(
1274 this, node->GetTitle(), this, false); 1216 this, node->GetTitle(), this, false);
1275 button->SetIcon(GetFolderIcon()); 1217 button->SetIcon(GetFolderIcon());
(...skipping 28 matching lines...) Expand all
1304 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, 1246 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model,
1305 const BookmarkNode* parent, 1247 const BookmarkNode* parent,
1306 int index) { 1248 int index) {
1307 UpdateOtherBookmarksVisibility(); 1249 UpdateOtherBookmarksVisibility();
1308 if (parent != model_->bookmark_bar_node()) { 1250 if (parent != model_->bookmark_bar_node()) {
1309 // We only care about nodes on the bookmark bar. 1251 // We only care about nodes on the bookmark bar.
1310 return; 1252 return;
1311 } 1253 }
1312 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); 1254 DCHECK(index >= 0 && index <= GetBookmarkButtonCount());
1313 const BookmarkNode* node = parent->GetChild(index); 1255 const BookmarkNode* node = parent->GetChild(index);
1314 if (!throbbing_view_ && sync_service_ && sync_service_->SetupInProgress()) { 1256 ProfileSyncService* sync_service =
1257 browser_->profile()->GetProfileSyncService();
1258 if (!throbbing_view_ && sync_service && sync_service->SetupInProgress())
1315 StartThrobbing(node, true); 1259 StartThrobbing(node, true);
1316 }
1317 AddChildViewAt(CreateBookmarkButton(node), index); 1260 AddChildViewAt(CreateBookmarkButton(node), index);
1318 UpdateColors(); 1261 UpdateColors();
1319 Layout(); 1262 Layout();
1320 SchedulePaint(); 1263 SchedulePaint();
1321 } 1264 }
1322 1265
1323 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, 1266 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model,
1324 const BookmarkNode* parent, 1267 const BookmarkNode* parent,
1325 int index) { 1268 int index) {
1326 UpdateOtherBookmarksVisibility(); 1269 UpdateOtherBookmarksVisibility();
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 height += browser_defaults::kBookmarkBarHeight; 1566 height += browser_defaults::kBookmarkBarHeight;
1624 } 1567 }
1625 1568
1626 gfx::Size other_bookmarked_pref = 1569 gfx::Size other_bookmarked_pref =
1627 other_bookmarked_button_->IsVisible() ? 1570 other_bookmarked_button_->IsVisible() ?
1628 other_bookmarked_button_->GetPreferredSize() : gfx::Size(); 1571 other_bookmarked_button_->GetPreferredSize() : gfx::Size();
1629 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); 1572 gfx::Size overflow_pref = overflow_button_->GetPreferredSize();
1630 gfx::Size bookmarks_separator_pref = 1573 gfx::Size bookmarks_separator_pref =
1631 bookmarks_separator_view_->GetPreferredSize(); 1574 bookmarks_separator_view_->GetPreferredSize();
1632 1575
1633 int sync_error_total_width = 0;
1634 gfx::Size sync_error_button_pref = sync_error_button_->GetPreferredSize();
1635 if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) {
1636 sync_error_total_width += kButtonPadding + sync_error_button_pref.width();
1637 }
1638 int max_x = width - overflow_pref.width() - kButtonPadding - 1576 int max_x = width - overflow_pref.width() - kButtonPadding -
1639 bookmarks_separator_pref.width() - sync_error_total_width; 1577 bookmarks_separator_pref.width();
1640 if (other_bookmarked_button_->IsVisible()) 1578 if (other_bookmarked_button_->IsVisible())
1641 max_x -= other_bookmarked_pref.width() + kButtonPadding; 1579 max_x -= other_bookmarked_pref.width() + kButtonPadding;
1642 1580
1643 // Next, layout out the buttons. Any buttons that are placed beyond the 1581 // Next, layout out the buttons. Any buttons that are placed beyond the
1644 // visible region and made invisible. 1582 // visible region and made invisible.
1645 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) { 1583 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) {
1646 gfx::Size pref = instructions_->GetPreferredSize(); 1584 gfx::Size pref = instructions_->GetPreferredSize();
1647 if (!compute_bounds_only) { 1585 if (!compute_bounds_only) {
1648 instructions_->SetBounds( 1586 instructions_->SetBounds(
1649 x + kInstructionsPadding, y, 1587 x + kInstructionsPadding, y,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 1639
1702 // The other bookmarks button. 1640 // The other bookmarks button.
1703 if (other_bookmarked_button_->IsVisible()) { 1641 if (other_bookmarked_button_->IsVisible()) {
1704 if (!compute_bounds_only) { 1642 if (!compute_bounds_only) {
1705 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(), 1643 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(),
1706 height); 1644 height);
1707 } 1645 }
1708 x += other_bookmarked_pref.width() + kButtonPadding; 1646 x += other_bookmarked_pref.width() + kButtonPadding;
1709 } 1647 }
1710 1648
1711 // Set the real bounds of the sync error button only if it needs to appear on
1712 // the bookmarks bar.
1713 if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) {
1714 x += kButtonPadding;
1715 if (!compute_bounds_only) {
1716 sync_error_button_->SetBounds(
1717 x, y, sync_error_button_pref.width(), height);
1718 sync_error_button_->SetVisible(true);
1719 }
1720 x += sync_error_button_pref.width();
1721 } else if (!compute_bounds_only) {
1722 sync_error_button_->SetBounds(x, y, 0, height);
1723 sync_error_button_->SetVisible(false);
1724 }
1725
1726 // Set the preferred size computed so far. 1649 // Set the preferred size computed so far.
1727 if (compute_bounds_only) { 1650 if (compute_bounds_only) {
1728 x += kRightMargin; 1651 x += kRightMargin;
1729 prefsize.set_width(x); 1652 prefsize.set_width(x);
1730 if (IsDetached()) { 1653 if (IsDetached()) {
1731 x += static_cast<int>( 1654 x += static_cast<int>(
1732 kNewtabHorizontalPadding * (1 - size_animation_->GetCurrentValue())); 1655 kNewtabHorizontalPadding * (1 - size_animation_->GetCurrentValue()));
1733 prefsize.set_height( 1656 prefsize.set_height(
1734 browser_defaults::kBookmarkBarHeight + 1657 browser_defaults::kBookmarkBarHeight +
1735 static_cast<int>( 1658 static_cast<int>(
1736 (browser_defaults::kNewtabBookmarkBarHeight - 1659 (browser_defaults::kNewtabBookmarkBarHeight -
1737 browser_defaults::kBookmarkBarHeight) * 1660 browser_defaults::kBookmarkBarHeight) *
1738 (1 - size_animation_->GetCurrentValue()))); 1661 (1 - size_animation_->GetCurrentValue())));
1739 } else { 1662 } else {
1740 prefsize.set_height( 1663 prefsize.set_height(
1741 static_cast<int>( 1664 static_cast<int>(
1742 browser_defaults::kBookmarkBarHeight * 1665 browser_defaults::kBookmarkBarHeight *
1743 size_animation_->GetCurrentValue())); 1666 size_animation_->GetCurrentValue()));
1744 } 1667 }
1745 } 1668 }
1746 return prefsize; 1669 return prefsize;
1747 } 1670 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698