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

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

Issue 302313005: Show the Managed Bookmarks folder in the views UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased on model changes Created 6 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 18 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
19 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
19 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/chrome_notification_types.h" 21 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/defaults.h" 22 #include "chrome/browser/defaults.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/search/search.h" 24 #include "chrome/browser/search/search.h"
24 #include "chrome/browser/sync/profile_sync_service.h" 25 #include "chrome/browser/sync/profile_sync_service.h"
25 #include "chrome/browser/sync/profile_sync_service_factory.h" 26 #include "chrome/browser/sync/profile_sync_service_factory.h"
26 #include "chrome/browser/themes/theme_properties.h" 27 #include "chrome/browser/themes/theme_properties.h"
27 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" 28 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h"
28 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" 29 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 129
129 // Left-padding for the instructional text. 130 // Left-padding for the instructional text.
130 static const int kInstructionsPadding = 6; 131 static const int kInstructionsPadding = 6;
131 132
132 // Tag for the 'Other bookmarks' button. 133 // Tag for the 'Other bookmarks' button.
133 static const int kOtherFolderButtonTag = 1; 134 static const int kOtherFolderButtonTag = 1;
134 135
135 // Tag for the 'Apps Shortcut' button. 136 // Tag for the 'Apps Shortcut' button.
136 static const int kAppsShortcutButtonTag = 2; 137 static const int kAppsShortcutButtonTag = 2;
137 138
139 // Tag for the 'Managed bookmarks' button.
140 static const int kManagedFolderButtonTag = 3;
141
138 namespace { 142 namespace {
139 143
140 // To enable/disable BookmarkBar animations during testing. In production 144 // To enable/disable BookmarkBar animations during testing. In production
141 // animations are enabled by default. 145 // animations are enabled by default.
142 bool animations_enabled = true; 146 bool animations_enabled = true;
143 147
144 // BookmarkButtonBase ----------------------------------------------- 148 // BookmarkButtonBase -----------------------------------------------
145 149
146 // Base class for text buttons used on the bookmark bar. 150 // Base class for text buttons used on the bookmark bar.
147 151
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 if (!kFolderIcon) { 433 if (!kFolderIcon) {
430 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 434 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
431 kFolderIcon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER); 435 kFolderIcon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER);
432 } 436 }
433 return *kFolderIcon; 437 return *kFolderIcon;
434 } 438 }
435 439
436 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) 440 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view)
437 : page_navigator_(NULL), 441 : page_navigator_(NULL),
438 model_(NULL), 442 model_(NULL),
443 client_(NULL),
439 bookmark_menu_(NULL), 444 bookmark_menu_(NULL),
440 bookmark_drop_menu_(NULL), 445 bookmark_drop_menu_(NULL),
441 other_bookmarked_button_(NULL), 446 other_bookmarked_button_(NULL),
447 managed_bookmarks_button_(NULL),
442 apps_page_shortcut_(NULL), 448 apps_page_shortcut_(NULL),
443 show_folder_method_factory_(this), 449 show_folder_method_factory_(this),
444 overflow_button_(NULL), 450 overflow_button_(NULL),
445 instructions_(NULL), 451 instructions_(NULL),
446 bookmarks_separator_view_(NULL), 452 bookmarks_separator_view_(NULL),
447 browser_(browser), 453 browser_(browser),
448 browser_view_(browser_view), 454 browser_view_(browser_view),
449 infobar_visible_(false), 455 infobar_visible_(false),
450 throbbing_view_(NULL), 456 throbbing_view_(NULL),
451 bookmark_bar_state_(BookmarkBar::SHOW), 457 bookmark_bar_state_(BookmarkBar::SHOW),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex( 525 const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex(
520 const gfx::Point& loc, 526 const gfx::Point& loc,
521 int* model_start_index) { 527 int* model_start_index) {
522 *model_start_index = 0; 528 *model_start_index = 0;
523 529
524 if (loc.x() < 0 || loc.x() >= width() || loc.y() < 0 || loc.y() >= height()) 530 if (loc.x() < 0 || loc.x() >= width() || loc.y() < 0 || loc.y() >= height())
525 return NULL; 531 return NULL;
526 532
527 gfx::Point adjusted_loc(GetMirroredXInView(loc.x()), loc.y()); 533 gfx::Point adjusted_loc(GetMirroredXInView(loc.x()), loc.y());
528 534
535 // Check the managed button first.
536 if (managed_bookmarks_button_->visible() &&
537 managed_bookmarks_button_->bounds().Contains(adjusted_loc)) {
538 return client_->managed_node();
539 }
540
529 // Check the buttons first. 541 // Check the buttons first.
530 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { 542 for (int i = 0; i < GetBookmarkButtonCount(); ++i) {
531 views::View* child = child_at(i); 543 views::View* child = child_at(i);
532 if (!child->visible()) 544 if (!child->visible())
533 break; 545 break;
534 if (child->bounds().Contains(adjusted_loc)) 546 if (child->bounds().Contains(adjusted_loc))
535 return model_->bookmark_bar_node()->GetChild(i); 547 return model_->bookmark_bar_node()->GetChild(i);
536 } 548 }
537 549
538 // Then the overflow button. 550 // Then the overflow button.
539 if (overflow_button_->visible() && 551 if (overflow_button_->visible() &&
540 overflow_button_->bounds().Contains(adjusted_loc)) { 552 overflow_button_->bounds().Contains(adjusted_loc)) {
541 *model_start_index = GetFirstHiddenNodeIndex(); 553 *model_start_index = GetFirstHiddenNodeIndex();
542 return model_->bookmark_bar_node(); 554 return model_->bookmark_bar_node();
543 } 555 }
544 556
545 // And finally the other folder. 557 // And finally the other folder.
546 if (other_bookmarked_button_->visible() && 558 if (other_bookmarked_button_->visible() &&
547 other_bookmarked_button_->bounds().Contains(adjusted_loc)) { 559 other_bookmarked_button_->bounds().Contains(adjusted_loc)) {
548 return model_->other_node(); 560 return model_->other_node();
549 } 561 }
550 562
551 return NULL; 563 return NULL;
552 } 564 }
553 565
554 views::MenuButton* BookmarkBarView::GetMenuButtonForNode( 566 views::MenuButton* BookmarkBarView::GetMenuButtonForNode(
555 const BookmarkNode* node) { 567 const BookmarkNode* node) {
568 if (node == client_->managed_node())
569 return managed_bookmarks_button_;
556 if (node == model_->other_node()) 570 if (node == model_->other_node())
557 return other_bookmarked_button_; 571 return other_bookmarked_button_;
558 if (node == model_->bookmark_bar_node()) 572 if (node == model_->bookmark_bar_node())
559 return overflow_button_; 573 return overflow_button_;
560 int index = model_->bookmark_bar_node()->GetIndexOf(node); 574 int index = model_->bookmark_bar_node()->GetIndexOf(node);
561 if (index == -1 || !node->is_folder()) 575 if (index == -1 || !node->is_folder())
562 return NULL; 576 return NULL;
563 return static_cast<views::MenuButton*>(child_at(index)); 577 return static_cast<views::MenuButton*>(child_at(index));
564 } 578 }
565 579
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 popup_model()->IsOpen()) { 703 popup_model()->IsOpen()) {
690 return false; 704 return false;
691 } 705 }
692 return true; 706 return true;
693 } 707 }
694 708
695 gfx::Size BookmarkBarView::GetMinimumSize() const { 709 gfx::Size BookmarkBarView::GetMinimumSize() const {
696 // The minimum width of the bookmark bar should at least contain the overflow 710 // The minimum width of the bookmark bar should at least contain the overflow
697 // button, by which one can access all the Bookmark Bar items, and the "Other 711 // button, by which one can access all the Bookmark Bar items, and the "Other
698 // Bookmarks" folder, along with appropriate margins and button padding. 712 // Bookmarks" folder, along with appropriate margins and button padding.
713 // It should also contain the Managed Bookmarks folder, if it's visible.
699 int width = kLeftMargin; 714 int width = kLeftMargin;
700 715
701 int height = chrome::kBookmarkBarHeight; 716 int height = chrome::kBookmarkBarHeight;
702 if (IsDetached()) { 717 if (IsDetached()) {
703 double current_state = 1 - size_animation_->GetCurrentValue(); 718 double current_state = 1 - size_animation_->GetCurrentValue();
704 width += 2 * static_cast<int>(kNewtabHorizontalPadding * current_state); 719 width += 2 * static_cast<int>(kNewtabHorizontalPadding * current_state);
705 height += static_cast<int>( 720 height += static_cast<int>(
706 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * 721 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) *
707 current_state); 722 current_state);
708 } 723 }
709 724
710 gfx::Size other_bookmarked_pref; 725 gfx::Size size;
sky 2014/06/05 23:46:47 Make this local to each block.
Joao da Silva 2014/06/06 15:41:03 Done.
711 if (other_bookmarked_button_->visible()) 726 if (managed_bookmarks_button_->visible()) {
712 other_bookmarked_pref = other_bookmarked_button_->GetPreferredSize(); 727 size = managed_bookmarks_button_->GetPreferredSize();
713 gfx::Size overflow_pref; 728 width += size.width() + kButtonPadding;
714 if (overflow_button_->visible()) 729 }
715 overflow_pref = overflow_button_->GetPreferredSize(); 730 if (other_bookmarked_button_->visible()) {
716 gfx::Size bookmarks_separator_pref; 731 size = other_bookmarked_button_->GetPreferredSize();
717 if (bookmarks_separator_view_->visible()) 732 width += size.width() + kButtonPadding;
718 bookmarks_separator_pref = bookmarks_separator_view_->GetPreferredSize(); 733 }
719 734 if (overflow_button_->visible()) {
720 gfx::Size apps_page_shortcut_pref; 735 size = overflow_button_->GetPreferredSize();
721 if (apps_page_shortcut_->visible()) 736 width += size.width() + kButtonPadding;
722 apps_page_shortcut_pref = apps_page_shortcut_->GetPreferredSize(); 737 }
723 width += other_bookmarked_pref.width() + kButtonPadding + 738 if (bookmarks_separator_view_->visible()) {
724 apps_page_shortcut_pref.width() + kButtonPadding + 739 size = bookmarks_separator_view_->GetPreferredSize();
725 overflow_pref.width() + kButtonPadding + 740 width += size.width();
726 bookmarks_separator_pref.width(); 741 }
742 if (apps_page_shortcut_->visible()) {
743 size = apps_page_shortcut_->GetPreferredSize();
744 width += size.width() + kButtonPadding;
745 }
727 746
728 return gfx::Size(width, height); 747 return gfx::Size(width, height);
729 } 748 }
730 749
731 void BookmarkBarView::Layout() { 750 void BookmarkBarView::Layout() {
732 LayoutItems(); 751 LayoutItems();
733 } 752 }
734 753
735 void BookmarkBarView::ViewHierarchyChanged( 754 void BookmarkBarView::ViewHierarchyChanged(
736 const ViewHierarchyChangedDetails& details) { 755 const ViewHierarchyChangedDetails& details) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 parent_node = root; 930 parent_node = root;
912 index = parent_node->child_count(); 931 index = parent_node->child_count();
913 } else if (drop_info_->location.on) { 932 } else if (drop_info_->location.on) {
914 parent_node = root->GetChild(index); 933 parent_node = root->GetChild(index);
915 index = parent_node->child_count(); 934 index = parent_node->child_count();
916 } else { 935 } else {
917 parent_node = root; 936 parent_node = root;
918 } 937 }
919 const BookmarkNodeData data = drop_info_->data; 938 const BookmarkNodeData data = drop_info_->data;
920 DCHECK(data.is_valid()); 939 DCHECK(data.is_valid());
940 bool copy = drop_info_->location.operation == ui::DragDropTypes::DRAG_COPY;
921 drop_info_.reset(); 941 drop_info_.reset();
922 return chrome::DropBookmarks(browser_->profile(), data, parent_node, index); 942 return chrome::DropBookmarks(
943 browser_->profile(), data, parent_node, index, copy);
923 } 944 }
924 945
925 void BookmarkBarView::OnThemeChanged() { 946 void BookmarkBarView::OnThemeChanged() {
926 UpdateColors(); 947 UpdateColors();
927 } 948 }
928 949
929 const char* BookmarkBarView::GetClassName() const { 950 const char* BookmarkBarView::GetClassName() const {
930 return kViewClassName; 951 return kViewClassName;
931 } 952 }
932 953
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 } else if (bookmark_bar_state_ == BookmarkBar::DETACHED) { 988 } else if (bookmark_bar_state_ == BookmarkBar::DETACHED) {
968 UMA_HISTOGRAM_COUNTS("Import.ShowDialog.FromFloatingBookmarkBarView", 989 UMA_HISTOGRAM_COUNTS("Import.ShowDialog.FromFloatingBookmarkBarView",
969 time_from_install); 990 time_from_install);
970 } 991 }
971 992
972 chrome::ShowImportDialog(browser_); 993 chrome::ShowImportDialog(browser_);
973 } 994 }
974 995
975 void BookmarkBarView::OnBookmarkBubbleShown(const GURL& url) { 996 void BookmarkBarView::OnBookmarkBubbleShown(const GURL& url) {
976 StopThrobbing(true); 997 StopThrobbing(true);
977 const BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(url); 998 const BookmarkNode* node = model_->GetMostRecentlyAddedUserNodeForURL(url);
978 if (!node) 999 if (!node)
979 return; // Generally shouldn't happen. 1000 return; // Generally shouldn't happen.
980 StartThrobbing(node, false); 1001 StartThrobbing(node, false);
981 } 1002 }
982 1003
983 void BookmarkBarView::OnBookmarkBubbleHidden() { 1004 void BookmarkBarView::OnBookmarkBubbleHidden() {
984 StopThrobbing(false); 1005 StopThrobbing(false);
985 } 1006 }
986 1007
987 void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model, 1008 void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model,
988 bool ids_reassigned) { 1009 bool ids_reassigned) {
989 // There should be no buttons. If non-zero it means Load was invoked more than 1010 // There should be no buttons. If non-zero it means Load was invoked more than
990 // once, or we didn't properly clear things. Either of which shouldn't happen. 1011 // once, or we didn't properly clear things. Either of which shouldn't happen.
991 DCHECK_EQ(0, GetBookmarkButtonCount()); 1012 DCHECK_EQ(0, GetBookmarkButtonCount());
992 const BookmarkNode* node = model_->bookmark_bar_node(); 1013 const BookmarkNode* node = model_->bookmark_bar_node();
993 DCHECK(node); 1014 DCHECK(node);
994 // Create a button for each of the children on the bookmark bar. 1015 // Create a button for each of the children on the bookmark bar.
995 for (int i = 0, child_count = node->child_count(); i < child_count; ++i) 1016 for (int i = 0, child_count = node->child_count(); i < child_count; ++i)
996 AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i); 1017 AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i);
997 DCHECK(model_->other_node()); 1018 DCHECK(model_->other_node());
998 other_bookmarked_button_->SetAccessibleName(model_->other_node()->GetTitle()); 1019 other_bookmarked_button_->SetAccessibleName(model_->other_node()->GetTitle());
999 other_bookmarked_button_->SetText(model_->other_node()->GetTitle()); 1020 other_bookmarked_button_->SetText(model_->other_node()->GetTitle());
1021 managed_bookmarks_button_->SetAccessibleName(
1022 client_->managed_node()->GetTitle());
1023 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle());
1000 UpdateColors(); 1024 UpdateColors();
1001 UpdateOtherBookmarksVisibility(); 1025 UpdateButtonsVisibility();
1002 other_bookmarked_button_->SetEnabled(true); 1026 other_bookmarked_button_->SetEnabled(true);
1027 managed_bookmarks_button_->SetEnabled(true);
1003 1028
1004 Layout(); 1029 Layout();
1005 SchedulePaint(); 1030 SchedulePaint();
1006 } 1031 }
1007 1032
1008 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { 1033 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) {
1009 NOTREACHED(); 1034 NOTREACHED();
1010 // Do minimal cleanup, presumably we'll be deleted shortly. 1035 // Do minimal cleanup, presumably we'll be deleted shortly.
1011 model_->RemoveObserver(this); 1036 model_->RemoveObserver(this);
1012 model_ = NULL; 1037 model_ = NULL;
1038 client_ = NULL;
1013 } 1039 }
1014 1040
1015 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, 1041 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model,
1016 const BookmarkNode* old_parent, 1042 const BookmarkNode* old_parent,
1017 int old_index, 1043 int old_index,
1018 const BookmarkNode* new_parent, 1044 const BookmarkNode* new_parent,
1019 int new_index) { 1045 int new_index) {
1020 bool was_throbbing = throbbing_view_ && 1046 bool was_throbbing = throbbing_view_ &&
1021 throbbing_view_ == DetermineViewToThrobFromRemove(old_parent, old_index); 1047 throbbing_view_ == DetermineViewToThrobFromRemove(old_parent, old_index);
1022 if (was_throbbing) 1048 if (was_throbbing)
(...skipping 17 matching lines...) Expand all
1040 const std::set<GURL>& removed_urls) { 1066 const std::set<GURL>& removed_urls) {
1041 // Close the menu if the menu is showing for the deleted node. 1067 // Close the menu if the menu is showing for the deleted node.
1042 if (bookmark_menu_ && bookmark_menu_->node() == node) 1068 if (bookmark_menu_ && bookmark_menu_->node() == node)
1043 bookmark_menu_->Cancel(); 1069 bookmark_menu_->Cancel();
1044 BookmarkNodeRemovedImpl(model, parent, old_index); 1070 BookmarkNodeRemovedImpl(model, parent, old_index);
1045 } 1071 }
1046 1072
1047 void BookmarkBarView::BookmarkAllNodesRemoved( 1073 void BookmarkBarView::BookmarkAllNodesRemoved(
1048 BookmarkModel* model, 1074 BookmarkModel* model,
1049 const std::set<GURL>& removed_urls) { 1075 const std::set<GURL>& removed_urls) {
1050 UpdateOtherBookmarksVisibility(); 1076 UpdateButtonsVisibility();
1051 1077
1052 StopThrobbing(true); 1078 StopThrobbing(true);
1053 1079
1054 // Remove the existing buttons. 1080 // Remove the existing buttons.
1055 while (GetBookmarkButtonCount()) { 1081 while (GetBookmarkButtonCount()) {
1056 delete GetBookmarkButton(0); 1082 delete GetBookmarkButton(0);
1057 } 1083 }
1058 1084
1059 Layout(); 1085 Layout();
1060 SchedulePaint(); 1086 SchedulePaint();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 return true; 1185 return true;
1160 } 1186 }
1161 1187
1162 void BookmarkBarView::OnMenuButtonClicked(views::View* view, 1188 void BookmarkBarView::OnMenuButtonClicked(views::View* view,
1163 const gfx::Point& point) { 1189 const gfx::Point& point) {
1164 const BookmarkNode* node; 1190 const BookmarkNode* node;
1165 1191
1166 int start_index = 0; 1192 int start_index = 0;
1167 if (view == other_bookmarked_button_) { 1193 if (view == other_bookmarked_button_) {
1168 node = model_->other_node(); 1194 node = model_->other_node();
1195 } else if (view == managed_bookmarks_button_) {
1196 node = client_->managed_node();
1169 } else if (view == overflow_button_) { 1197 } else if (view == overflow_button_) {
1170 node = model_->bookmark_bar_node(); 1198 node = model_->bookmark_bar_node();
1171 start_index = GetFirstHiddenNodeIndex(); 1199 start_index = GetFirstHiddenNodeIndex();
1172 } else { 1200 } else {
1173 int button_index = GetIndexOf(view); 1201 int button_index = GetIndexOf(view);
1174 DCHECK_NE(-1, button_index); 1202 DCHECK_NE(-1, button_index);
1175 node = model_->bookmark_bar_node()->GetChild(button_index); 1203 node = model_->bookmark_bar_node()->GetChild(button_index);
1176 } 1204 }
1177 1205
1178 RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); 1206 RecordBookmarkFolderOpen(GetBookmarkLaunchLocation());
(...skipping 15 matching lines...) Expand all
1194 content::PAGE_TRANSITION_AUTO_BOOKMARK, 1222 content::PAGE_TRANSITION_AUTO_BOOKMARK,
1195 false); 1223 false);
1196 page_navigator_->OpenURL(params); 1224 page_navigator_->OpenURL(params);
1197 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation()); 1225 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation());
1198 return; 1226 return;
1199 } 1227 }
1200 1228
1201 const BookmarkNode* node; 1229 const BookmarkNode* node;
1202 if (sender->tag() == kOtherFolderButtonTag) { 1230 if (sender->tag() == kOtherFolderButtonTag) {
1203 node = model_->other_node(); 1231 node = model_->other_node();
1232 } else if (sender->tag() == kManagedFolderButtonTag) {
1233 node = client_->managed_node();
1204 } else { 1234 } else {
1205 int index = GetIndexOf(sender); 1235 int index = GetIndexOf(sender);
1206 DCHECK_NE(-1, index); 1236 DCHECK_NE(-1, index);
1207 node = model_->bookmark_bar_node()->GetChild(index); 1237 node = model_->bookmark_bar_node()->GetChild(index);
1208 } 1238 }
1209 DCHECK(page_navigator_); 1239 DCHECK(page_navigator_);
1210 1240
1211 if (node->is_url()) { 1241 if (node->is_url()) {
1212 RecordAppLaunch(browser_->profile(), node->url()); 1242 RecordAppLaunch(browser_->profile(), node->url());
1213 OpenURLParams params( 1243 OpenURLParams params(
(...skipping 16 matching lines...) Expand all
1230 return; 1260 return;
1231 } 1261 }
1232 1262
1233 const BookmarkNode* parent = NULL; 1263 const BookmarkNode* parent = NULL;
1234 std::vector<const BookmarkNode*> nodes; 1264 std::vector<const BookmarkNode*> nodes;
1235 if (source == other_bookmarked_button_) { 1265 if (source == other_bookmarked_button_) {
1236 parent = model_->other_node(); 1266 parent = model_->other_node();
1237 // Do this so the user can open all bookmarks. BookmarkContextMenu makes 1267 // Do this so the user can open all bookmarks. BookmarkContextMenu makes
1238 // sure the user can't edit/delete the node in this case. 1268 // sure the user can't edit/delete the node in this case.
1239 nodes.push_back(parent); 1269 nodes.push_back(parent);
1270 } else if (source == managed_bookmarks_button_) {
1271 parent = client_->managed_node();
1272 nodes.push_back(parent);
1240 } else if (source != this && source != apps_page_shortcut_) { 1273 } else if (source != this && source != apps_page_shortcut_) {
1241 // User clicked on one of the bookmark buttons, find which one they 1274 // User clicked on one of the bookmark buttons, find which one they
1242 // clicked on, except for the apps page shortcut, which must behave as if 1275 // clicked on, except for the apps page shortcut, which must behave as if
1243 // the user clicked on the bookmark bar background. 1276 // the user clicked on the bookmark bar background.
1244 int bookmark_button_index = GetIndexOf(source); 1277 int bookmark_button_index = GetIndexOf(source);
1245 DCHECK(bookmark_button_index != -1 && 1278 DCHECK(bookmark_button_index != -1 &&
1246 bookmark_button_index < GetBookmarkButtonCount()); 1279 bookmark_button_index < GetBookmarkButtonCount());
1247 const BookmarkNode* node = 1280 const BookmarkNode* node =
1248 model_->bookmark_bar_node()->GetChild(bookmark_button_index); 1281 model_->bookmark_bar_node()->GetChild(bookmark_button_index);
1249 nodes.push_back(node); 1282 nodes.push_back(node);
(...skipping 21 matching lines...) Expand all
1271 // Child views are traversed in the order they are added. Make sure the order 1304 // Child views are traversed in the order they are added. Make sure the order
1272 // they are added matches the visual order. 1305 // they are added matches the visual order.
1273 overflow_button_ = CreateOverflowButton(); 1306 overflow_button_ = CreateOverflowButton();
1274 AddChildView(overflow_button_); 1307 AddChildView(overflow_button_);
1275 1308
1276 other_bookmarked_button_ = CreateOtherBookmarkedButton(); 1309 other_bookmarked_button_ = CreateOtherBookmarkedButton();
1277 // We'll re-enable when the model is loaded. 1310 // We'll re-enable when the model is loaded.
1278 other_bookmarked_button_->SetEnabled(false); 1311 other_bookmarked_button_->SetEnabled(false);
1279 AddChildView(other_bookmarked_button_); 1312 AddChildView(other_bookmarked_button_);
1280 1313
1314 managed_bookmarks_button_ = CreateOtherBookmarkedButton();
1315 // Also re-enabled when the model is loaded.
1316 managed_bookmarks_button_->SetEnabled(false);
1317 AddChildView(managed_bookmarks_button_);
1318
1281 apps_page_shortcut_ = CreateAppsPageShortcutButton(); 1319 apps_page_shortcut_ = CreateAppsPageShortcutButton();
1282 AddChildView(apps_page_shortcut_); 1320 AddChildView(apps_page_shortcut_);
1283 profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); 1321 profile_pref_registrar_.Init(browser_->profile()->GetPrefs());
1284 profile_pref_registrar_.Add( 1322 profile_pref_registrar_.Add(
1285 prefs::kShowAppsShortcutInBookmarkBar, 1323 prefs::kShowAppsShortcutInBookmarkBar,
1286 base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityPrefChanged, 1324 base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityPrefChanged,
1287 base::Unretained(this))); 1325 base::Unretained(this)));
1288 apps_page_shortcut_->SetVisible( 1326 apps_page_shortcut_->SetVisible(
1289 chrome::ShouldShowAppsShortcutInBookmarkBar( 1327 chrome::ShouldShowAppsShortcutInBookmarkBar(
1290 browser_->profile(), browser_->host_desktop_type())); 1328 browser_->profile(), browser_->host_desktop_type()));
1291 1329
1292 bookmarks_separator_view_ = new ButtonSeparatorView(); 1330 bookmarks_separator_view_ = new ButtonSeparatorView();
1293 AddChildView(bookmarks_separator_view_); 1331 AddChildView(bookmarks_separator_view_);
1294 UpdateBookmarksSeparatorVisibility(); 1332 UpdateBookmarksSeparatorVisibility();
1295 1333
1296 instructions_ = new BookmarkBarInstructionsView(this); 1334 instructions_ = new BookmarkBarInstructionsView(this);
1297 AddChildView(instructions_); 1335 AddChildView(instructions_);
1298 1336
1299 set_context_menu_controller(this); 1337 set_context_menu_controller(this);
1300 1338
1301 size_animation_.reset(new gfx::SlideAnimation(this)); 1339 size_animation_.reset(new gfx::SlideAnimation(this));
1302 1340
1303 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); 1341 client_ = BookmarkModelFactory::GetChromeBookmarkClientForProfile(
1342 browser_->profile());
1343 model_ = client_->model();
1304 if (model_) { 1344 if (model_) {
1305 model_->AddObserver(this); 1345 model_->AddObserver(this);
1306 if (model_->loaded()) 1346 if (model_->loaded())
1307 BookmarkModelLoaded(model_, false); 1347 BookmarkModelLoaded(model_, false);
1308 // else case: we'll receive notification back from the BookmarkModel when 1348 // else case: we'll receive notification back from the BookmarkModel when
1309 // done loading, then we'll populate the bar. 1349 // done loading, then we'll populate the bar.
1310 } 1350 }
1311 } 1351 }
1312 1352
1313 int BookmarkBarView::GetBookmarkButtonCount() const { 1353 int BookmarkBarView::GetBookmarkButtonCount() const {
1314 // We contain four non-bookmark button views: other bookmarks, bookmarks 1354 // We contain six non-bookmark button views: managed bookmarks,
1315 // separator, chevrons (for overflow), apps page, and the instruction label. 1355 // other bookmarks, bookmarks separator, chevrons (for overflow), apps page,
1316 return child_count() - 5; 1356 // and the instruction label.
1357 return child_count() - 6;
1317 } 1358 }
1318 1359
1319 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { 1360 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) {
1320 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); 1361 DCHECK(index >= 0 && index < GetBookmarkButtonCount());
1321 return static_cast<views::TextButton*>(child_at(index)); 1362 return static_cast<views::TextButton*>(child_at(index));
1322 } 1363 }
1323 1364
1324 BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const { 1365 BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const {
1325 return IsDetached() ? BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR : 1366 return IsDetached() ? BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR :
1326 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR; 1367 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR;
(...skipping 12 matching lines...) Expand all
1339 // Title is set in Loaded. 1380 // Title is set in Loaded.
1340 MenuButton* button = 1381 MenuButton* button =
1341 new BookmarkFolderButton(this, base::string16(), this, false); 1382 new BookmarkFolderButton(this, base::string16(), this, false);
1342 button->set_id(VIEW_ID_OTHER_BOOKMARKS); 1383 button->set_id(VIEW_ID_OTHER_BOOKMARKS);
1343 button->SetIcon(GetFolderIcon()); 1384 button->SetIcon(GetFolderIcon());
1344 button->set_context_menu_controller(this); 1385 button->set_context_menu_controller(this);
1345 button->set_tag(kOtherFolderButtonTag); 1386 button->set_tag(kOtherFolderButtonTag);
1346 return button; 1387 return button;
1347 } 1388 }
1348 1389
1390 MenuButton* BookmarkBarView::CreateManagedBookmarksButton() {
1391 // Title is set in Loaded.
1392 MenuButton* button =
1393 new BookmarkFolderButton(this, base::string16(), this, false);
1394 button->set_id(VIEW_ID_MANAGED_BOOKMARKS);
1395 // TODO(joaodasilva): replace with a "managed folder" icon.
1396 // http://crbug.com/49598
1397 button->SetIcon(GetFolderIcon());
1398 button->set_context_menu_controller(this);
1399 button->set_tag(kManagedFolderButtonTag);
1400 return button;
1401 }
1402
1349 MenuButton* BookmarkBarView::CreateOverflowButton() { 1403 MenuButton* BookmarkBarView::CreateOverflowButton() {
1350 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1404 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1351 MenuButton* button = new OverFlowButton(this); 1405 MenuButton* button = new OverFlowButton(this);
1352 button->SetIcon(*rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS)); 1406 button->SetIcon(*rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS));
1353 1407
1354 // The overflow button's image contains an arrow and therefore it is a 1408 // The overflow button's image contains an arrow and therefore it is a
1355 // direction sensitive image and we need to flip it if the UI layout is 1409 // direction sensitive image and we need to flip it if the UI layout is
1356 // right-to-left. 1410 // right-to-left.
1357 // 1411 //
1358 // By default, menu buttons are not flipped because they generally contain 1412 // By default, menu buttons are not flipped because they generally contain
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 button->SetIcon(*favicon.ToImageSkia()); 1470 button->SetIcon(*favicon.ToImageSkia());
1417 else 1471 else
1418 button->SetIcon(GetDefaultFavicon()); 1472 button->SetIcon(GetDefaultFavicon());
1419 } 1473 }
1420 button->set_max_width(kMaxButtonWidth); 1474 button->set_max_width(kMaxButtonWidth);
1421 } 1475 }
1422 1476
1423 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, 1477 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model,
1424 const BookmarkNode* parent, 1478 const BookmarkNode* parent,
1425 int index) { 1479 int index) {
1426 UpdateOtherBookmarksVisibility(); 1480 UpdateButtonsVisibility();
1427 if (parent != model_->bookmark_bar_node()) { 1481 if (parent != model_->bookmark_bar_node()) {
1428 // We only care about nodes on the bookmark bar. 1482 // We only care about nodes on the bookmark bar.
1429 return; 1483 return;
1430 } 1484 }
1431 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); 1485 DCHECK(index >= 0 && index <= GetBookmarkButtonCount());
1432 const BookmarkNode* node = parent->GetChild(index); 1486 const BookmarkNode* node = parent->GetChild(index);
1433 ProfileSyncService* sync_service(ProfileSyncServiceFactory:: 1487 ProfileSyncService* sync_service(ProfileSyncServiceFactory::
1434 GetInstance()->GetForProfile(browser_->profile())); 1488 GetInstance()->GetForProfile(browser_->profile()));
1435 if (!throbbing_view_ && sync_service && sync_service->FirstSetupInProgress()) 1489 if (!throbbing_view_ && sync_service && sync_service->FirstSetupInProgress())
1436 StartThrobbing(node, true); 1490 StartThrobbing(node, true);
1437 AddChildViewAt(CreateBookmarkButton(node), index); 1491 AddChildViewAt(CreateBookmarkButton(node), index);
1438 UpdateColors(); 1492 UpdateColors();
1439 Layout(); 1493 Layout();
1440 SchedulePaint(); 1494 SchedulePaint();
1441 } 1495 }
1442 1496
1443 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, 1497 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model,
1444 const BookmarkNode* parent, 1498 const BookmarkNode* parent,
1445 int index) { 1499 int index) {
1446 UpdateOtherBookmarksVisibility(); 1500 UpdateButtonsVisibility();
1447 1501
1448 StopThrobbing(true); 1502 StopThrobbing(true);
1449 // No need to start throbbing again as the bookmark bubble can't be up at 1503 // No need to start throbbing again as the bookmark bubble can't be up at
1450 // the same time as the user reorders. 1504 // the same time as the user reorders.
1451 1505
1452 if (parent != model_->bookmark_bar_node()) { 1506 if (parent != model_->bookmark_bar_node()) {
1453 // We only care about nodes on the bookmark bar. 1507 // We only care about nodes on the bookmark bar.
1454 return; 1508 return;
1455 } 1509 }
1456 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); 1510 DCHECK(index >= 0 && index < GetBookmarkButtonCount());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 Profile* profile = browser_->profile(); 1600 Profile* profile = browser_->profile();
1547 if (other_bookmarked_button_->visible() && other_delta_x >= 0 && 1601 if (other_bookmarked_button_->visible() && other_delta_x >= 0 &&
1548 other_delta_x < other_bookmarked_button_->width()) { 1602 other_delta_x < other_bookmarked_button_->width()) {
1549 // Mouse is over 'other' folder. 1603 // Mouse is over 'other' folder.
1550 location->button_type = DROP_OTHER_FOLDER; 1604 location->button_type = DROP_OTHER_FOLDER;
1551 location->on = true; 1605 location->on = true;
1552 found = true; 1606 found = true;
1553 } else if (!GetBookmarkButtonCount()) { 1607 } else if (!GetBookmarkButtonCount()) {
1554 // No bookmarks, accept the drop. 1608 // No bookmarks, accept the drop.
1555 location->index = 0; 1609 location->index = 0;
1556 int ops = data.GetFirstNode(model_, profile->GetPath()) ? 1610 const BookmarkNode* node = data.GetFirstNode(model_, profile->GetPath());
1611 int ops = node && client_->CanBeEditedByUser(node) ?
1557 ui::DragDropTypes::DRAG_MOVE : 1612 ui::DragDropTypes::DRAG_MOVE :
1558 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; 1613 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK;
1559 location->operation = chrome::GetPreferredBookmarkDropOperation( 1614 location->operation = chrome::GetPreferredBookmarkDropOperation(
1560 event.source_operations(), ops); 1615 event.source_operations(), ops);
1561 return; 1616 return;
1562 } 1617 }
1563 1618
1564 for (int i = 0; i < GetBookmarkButtonCount() && 1619 for (int i = 0; i < GetBookmarkButtonCount() &&
1565 GetBookmarkButton(i)->visible() && !found; i++) { 1620 GetBookmarkButton(i)->visible() && !found; i++) {
1566 views::TextButton* button = GetBookmarkButton(i); 1621 views::TextButton* button = GetBookmarkButton(i);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 parent_on_bb = parent; 1707 parent_on_bb = parent;
1653 } 1708 }
1654 if (parent_on_bb) { 1709 if (parent_on_bb) {
1655 int index = bbn->GetIndexOf(parent_on_bb); 1710 int index = bbn->GetIndexOf(parent_on_bb);
1656 if (index >= GetFirstHiddenNodeIndex()) { 1711 if (index >= GetFirstHiddenNodeIndex()) {
1657 // Node is hidden, animate the overflow button. 1712 // Node is hidden, animate the overflow button.
1658 throbbing_view_ = overflow_button_; 1713 throbbing_view_ = overflow_button_;
1659 } else if (!overflow_only) { 1714 } else if (!overflow_only) {
1660 throbbing_view_ = static_cast<CustomButton*>(child_at(index)); 1715 throbbing_view_ = static_cast<CustomButton*>(child_at(index));
1661 } 1716 }
1717 } else if (client_->IsDescendantOfManagedNode(node)) {
1718 throbbing_view_ = managed_bookmarks_button_;
1662 } else if (!overflow_only) { 1719 } else if (!overflow_only) {
1663 throbbing_view_ = other_bookmarked_button_; 1720 throbbing_view_ = other_bookmarked_button_;
1664 } 1721 }
1665 1722
1666 // Use a large number so that the button continues to throb. 1723 // Use a large number so that the button continues to throb.
1667 if (throbbing_view_) 1724 if (throbbing_view_)
1668 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); 1725 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max());
1669 } 1726 }
1670 1727
1671 views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( 1728 views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove(
(...skipping 10 matching lines...) Expand all
1682 } 1739 }
1683 old_node = parent; 1740 old_node = parent;
1684 } 1741 }
1685 if (old_node) { 1742 if (old_node) {
1686 if (old_index_on_bb >= GetFirstHiddenNodeIndex()) { 1743 if (old_index_on_bb >= GetFirstHiddenNodeIndex()) {
1687 // Node is hidden, animate the overflow button. 1744 // Node is hidden, animate the overflow button.
1688 return overflow_button_; 1745 return overflow_button_;
1689 } 1746 }
1690 return static_cast<CustomButton*>(child_at(old_index_on_bb)); 1747 return static_cast<CustomButton*>(child_at(old_index_on_bb));
1691 } 1748 }
1749 if (client_->IsDescendantOfManagedNode(parent))
1750 return managed_bookmarks_button_;
1692 // Node wasn't on the bookmark bar, use the other bookmark button. 1751 // Node wasn't on the bookmark bar, use the other bookmark button.
1693 return other_bookmarked_button_; 1752 return other_bookmarked_button_;
1694 } 1753 }
1695 1754
1696 void BookmarkBarView::UpdateColors() { 1755 void BookmarkBarView::UpdateColors() {
1697 // We don't always have a theme provider (ui tests, for example). 1756 // We don't always have a theme provider (ui tests, for example).
1698 const ui::ThemeProvider* theme_provider = GetThemeProvider(); 1757 const ui::ThemeProvider* theme_provider = GetThemeProvider();
1699 if (!theme_provider) 1758 if (!theme_provider)
1700 return; 1759 return;
1701 SkColor text_color = 1760 SkColor text_color =
1702 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); 1761 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
1703 for (int i = 0; i < GetBookmarkButtonCount(); ++i) 1762 for (int i = 0; i < GetBookmarkButtonCount(); ++i)
1704 GetBookmarkButton(i)->SetEnabledColor(text_color); 1763 GetBookmarkButton(i)->SetEnabledColor(text_color);
1705 other_bookmarked_button()->SetEnabledColor(text_color); 1764 other_bookmarked_button_->SetEnabledColor(text_color);
1765 managed_bookmarks_button_->SetEnabledColor(text_color);
1706 if (apps_page_shortcut_->visible()) 1766 if (apps_page_shortcut_->visible())
1707 apps_page_shortcut_->SetEnabledColor(text_color); 1767 apps_page_shortcut_->SetEnabledColor(text_color);
1708 } 1768 }
1709 1769
1710 void BookmarkBarView::UpdateOtherBookmarksVisibility() { 1770 void BookmarkBarView::UpdateButtonsVisibility() {
1711 bool has_other_children = !model_->other_node()->empty(); 1771 bool has_other_children = !model_->other_node()->empty();
1712 if (has_other_children == other_bookmarked_button_->visible()) 1772 bool update_other = has_other_children != other_bookmarked_button_->visible();
1713 return; 1773 if (update_other) {
1714 other_bookmarked_button_->SetVisible(has_other_children); 1774 other_bookmarked_button_->SetVisible(has_other_children);
1715 UpdateBookmarksSeparatorVisibility(); 1775 UpdateBookmarksSeparatorVisibility();
1716 Layout(); 1776 }
1717 SchedulePaint(); 1777
1778 bool has_managed_children = !client_->managed_node()->empty();
1779 bool update_managed =
1780 has_managed_children != managed_bookmarks_button_->visible();
1781 if (update_managed)
1782 managed_bookmarks_button_->SetVisible(has_managed_children);
1783
1784 if (update_other || update_managed) {
1785 Layout();
1786 SchedulePaint();
1787 }
1718 } 1788 }
1719 1789
1720 void BookmarkBarView::UpdateBookmarksSeparatorVisibility() { 1790 void BookmarkBarView::UpdateBookmarksSeparatorVisibility() {
1721 // Ash does not paint the bookmarks separator line because it looks odd on 1791 // Ash does not paint the bookmarks separator line because it looks odd on
1722 // the flat background. We keep it present for layout, but don't draw it. 1792 // the flat background. We keep it present for layout, but don't draw it.
1723 bookmarks_separator_view_->SetVisible( 1793 bookmarks_separator_view_->SetVisible(
1724 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH && 1794 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH &&
1725 other_bookmarked_button_->visible()); 1795 other_bookmarked_button_->visible());
1726 } 1796 }
1727 1797
(...skipping 21 matching lines...) Expand all
1749 y += View::height() - chrome::kBookmarkBarHeight; 1819 y += View::height() - chrome::kBookmarkBarHeight;
1750 } 1820 }
1751 1821
1752 gfx::Size other_bookmarked_pref = other_bookmarked_button_->visible() ? 1822 gfx::Size other_bookmarked_pref = other_bookmarked_button_->visible() ?
1753 other_bookmarked_button_->GetPreferredSize() : gfx::Size(); 1823 other_bookmarked_button_->GetPreferredSize() : gfx::Size();
1754 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); 1824 gfx::Size overflow_pref = overflow_button_->GetPreferredSize();
1755 gfx::Size bookmarks_separator_pref = 1825 gfx::Size bookmarks_separator_pref =
1756 bookmarks_separator_view_->GetPreferredSize(); 1826 bookmarks_separator_view_->GetPreferredSize();
1757 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ? 1827 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ?
1758 apps_page_shortcut_->GetPreferredSize() : gfx::Size(); 1828 apps_page_shortcut_->GetPreferredSize() : gfx::Size();
1829 gfx::Size managed_bookmarks_pref = managed_bookmarks_button_->visible() ?
sky 2014/06/05 23:46:47 Move to 1848.
Joao da Silva 2014/06/06 15:41:03 Done.
1830 managed_bookmarks_button_->GetPreferredSize() : gfx::Size();
1759 1831
1760 int max_x = width - overflow_pref.width() - kButtonPadding - 1832 int max_x = width - overflow_pref.width() - kButtonPadding -
1761 bookmarks_separator_pref.width(); 1833 bookmarks_separator_pref.width();
1762 if (other_bookmarked_button_->visible()) 1834 if (other_bookmarked_button_->visible())
1763 max_x -= other_bookmarked_pref.width() + kButtonPadding; 1835 max_x -= other_bookmarked_pref.width() + kButtonPadding;
1764 1836
1765 // Next, layout out the buttons. Any buttons that are placed beyond the 1837 // Next, layout out the buttons. Any buttons that are placed beyond the
1766 // visible region and made invisible. 1838 // visible region are made invisible.
1767 1839
1768 // Start with the apps page shortcut button. 1840 // Start with the apps page shortcut button.
1769 if (apps_page_shortcut_->visible()) { 1841 if (apps_page_shortcut_->visible()) {
1770 apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(), 1842 apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(),
1771 height); 1843 height);
1772 x += apps_page_shortcut_pref.width() + kButtonPadding; 1844 x += apps_page_shortcut_pref.width() + kButtonPadding;
1773 } 1845 }
1774 1846
1847 // Then comes the managed bookmarks folder, if visible.
1848 if (managed_bookmarks_button_->visible()) {
1849 managed_bookmarks_button_->SetBounds(x, y, managed_bookmarks_pref.width(),
1850 height);
1851 x += managed_bookmarks_pref.width() + kButtonPadding;
1852 }
1853
1775 // Then go through the bookmark buttons. 1854 // Then go through the bookmark buttons.
1776 if (GetBookmarkButtonCount() == 0 && model_ && model_->loaded()) { 1855 if (GetBookmarkButtonCount() == 0 && model_ && model_->loaded()) {
1777 gfx::Size pref = instructions_->GetPreferredSize(); 1856 gfx::Size pref = instructions_->GetPreferredSize();
1778 instructions_->SetBounds( 1857 instructions_->SetBounds(
1779 x + kInstructionsPadding, y, 1858 x + kInstructionsPadding, y,
1780 std::min(static_cast<int>(pref.width()), 1859 std::min(static_cast<int>(pref.width()),
1781 max_x - x), 1860 max_x - x),
1782 height); 1861 height);
1783 instructions_->SetVisible(true); 1862 instructions_->SetVisible(true);
1784 } else { 1863 } else {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 DCHECK(apps_page_shortcut_); 1908 DCHECK(apps_page_shortcut_);
1830 // Only perform layout if required. 1909 // Only perform layout if required.
1831 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( 1910 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar(
1832 browser_->profile(), browser_->host_desktop_type()); 1911 browser_->profile(), browser_->host_desktop_type());
1833 if (apps_page_shortcut_->visible() == visible) 1912 if (apps_page_shortcut_->visible() == visible)
1834 return; 1913 return;
1835 apps_page_shortcut_->SetVisible(visible); 1914 apps_page_shortcut_->SetVisible(visible);
1836 UpdateBookmarksSeparatorVisibility(); 1915 UpdateBookmarksSeparatorVisibility();
1837 Layout(); 1916 Layout();
1838 } 1917 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698