OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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. |
sky
2014/06/06 19:34:04
nit: update comment.
Joao da Silva
2014/06/06 20:06:11
Done.
| |
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 Loading... | |
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 if (managed_bookmarks_button_->visible()) { |
711 if (other_bookmarked_button_->visible()) | 726 gfx::Size size = managed_bookmarks_button_->GetPreferredSize(); |
712 other_bookmarked_pref = other_bookmarked_button_->GetPreferredSize(); | 727 width += size.width() + kButtonPadding; |
713 gfx::Size overflow_pref; | 728 } |
714 if (overflow_button_->visible()) | 729 if (other_bookmarked_button_->visible()) { |
715 overflow_pref = overflow_button_->GetPreferredSize(); | 730 gfx::Size size = other_bookmarked_button_->GetPreferredSize(); |
716 gfx::Size bookmarks_separator_pref; | 731 width += size.width() + kButtonPadding; |
717 if (bookmarks_separator_view_->visible()) | 732 } |
718 bookmarks_separator_pref = bookmarks_separator_view_->GetPreferredSize(); | 733 if (overflow_button_->visible()) { |
719 | 734 gfx::Size size = overflow_button_->GetPreferredSize(); |
720 gfx::Size apps_page_shortcut_pref; | 735 width += size.width() + kButtonPadding; |
721 if (apps_page_shortcut_->visible()) | 736 } |
722 apps_page_shortcut_pref = apps_page_shortcut_->GetPreferredSize(); | 737 if (bookmarks_separator_view_->visible()) { |
723 width += other_bookmarked_pref.width() + kButtonPadding + | 738 gfx::Size size = bookmarks_separator_view_->GetPreferredSize(); |
724 apps_page_shortcut_pref.width() + kButtonPadding + | 739 width += size.width(); |
725 overflow_pref.width() + kButtonPadding + | 740 } |
726 bookmarks_separator_pref.width(); | 741 if (apps_page_shortcut_->visible()) { |
742 gfx::Size size = apps_page_shortcut_->GetPreferredSize(); | |
743 width += size.width() + kButtonPadding; | |
744 } | |
727 | 745 |
728 return gfx::Size(width, height); | 746 return gfx::Size(width, height); |
729 } | 747 } |
730 | 748 |
731 void BookmarkBarView::Layout() { | 749 void BookmarkBarView::Layout() { |
732 LayoutItems(); | 750 LayoutItems(); |
733 } | 751 } |
734 | 752 |
735 void BookmarkBarView::ViewHierarchyChanged( | 753 void BookmarkBarView::ViewHierarchyChanged( |
736 const ViewHierarchyChangedDetails& details) { | 754 const ViewHierarchyChangedDetails& details) { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
911 parent_node = root; | 929 parent_node = root; |
912 index = parent_node->child_count(); | 930 index = parent_node->child_count(); |
913 } else if (drop_info_->location.on) { | 931 } else if (drop_info_->location.on) { |
914 parent_node = root->GetChild(index); | 932 parent_node = root->GetChild(index); |
915 index = parent_node->child_count(); | 933 index = parent_node->child_count(); |
916 } else { | 934 } else { |
917 parent_node = root; | 935 parent_node = root; |
918 } | 936 } |
919 const BookmarkNodeData data = drop_info_->data; | 937 const BookmarkNodeData data = drop_info_->data; |
920 DCHECK(data.is_valid()); | 938 DCHECK(data.is_valid()); |
939 bool copy = drop_info_->location.operation == ui::DragDropTypes::DRAG_COPY; | |
921 drop_info_.reset(); | 940 drop_info_.reset(); |
922 return chrome::DropBookmarks(browser_->profile(), data, parent_node, index); | 941 return chrome::DropBookmarks( |
942 browser_->profile(), data, parent_node, index, copy); | |
923 } | 943 } |
924 | 944 |
925 void BookmarkBarView::OnThemeChanged() { | 945 void BookmarkBarView::OnThemeChanged() { |
926 UpdateColors(); | 946 UpdateColors(); |
927 } | 947 } |
928 | 948 |
929 const char* BookmarkBarView::GetClassName() const { | 949 const char* BookmarkBarView::GetClassName() const { |
930 return kViewClassName; | 950 return kViewClassName; |
931 } | 951 } |
932 | 952 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
990 // once, or we didn't properly clear things. Either of which shouldn't happen. | 1010 // once, or we didn't properly clear things. Either of which shouldn't happen. |
991 DCHECK_EQ(0, GetBookmarkButtonCount()); | 1011 DCHECK_EQ(0, GetBookmarkButtonCount()); |
992 const BookmarkNode* node = model_->bookmark_bar_node(); | 1012 const BookmarkNode* node = model_->bookmark_bar_node(); |
993 DCHECK(node); | 1013 DCHECK(node); |
994 // Create a button for each of the children on the bookmark bar. | 1014 // 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) | 1015 for (int i = 0, child_count = node->child_count(); i < child_count; ++i) |
996 AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i); | 1016 AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i); |
997 DCHECK(model_->other_node()); | 1017 DCHECK(model_->other_node()); |
998 other_bookmarked_button_->SetAccessibleName(model_->other_node()->GetTitle()); | 1018 other_bookmarked_button_->SetAccessibleName(model_->other_node()->GetTitle()); |
999 other_bookmarked_button_->SetText(model_->other_node()->GetTitle()); | 1019 other_bookmarked_button_->SetText(model_->other_node()->GetTitle()); |
1020 managed_bookmarks_button_->SetAccessibleName( | |
1021 client_->managed_node()->GetTitle()); | |
1022 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); | |
1000 UpdateColors(); | 1023 UpdateColors(); |
1001 UpdateOtherBookmarksVisibility(); | 1024 UpdateButtonsVisibility(); |
1002 other_bookmarked_button_->SetEnabled(true); | 1025 other_bookmarked_button_->SetEnabled(true); |
1026 managed_bookmarks_button_->SetEnabled(true); | |
1003 | 1027 |
1004 Layout(); | 1028 Layout(); |
1005 SchedulePaint(); | 1029 SchedulePaint(); |
1006 } | 1030 } |
1007 | 1031 |
1008 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { | 1032 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { |
1009 NOTREACHED(); | 1033 NOTREACHED(); |
1010 // Do minimal cleanup, presumably we'll be deleted shortly. | 1034 // Do minimal cleanup, presumably we'll be deleted shortly. |
1011 model_->RemoveObserver(this); | 1035 model_->RemoveObserver(this); |
1012 model_ = NULL; | 1036 model_ = NULL; |
1037 client_ = NULL; | |
1013 } | 1038 } |
1014 | 1039 |
1015 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, | 1040 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, |
1016 const BookmarkNode* old_parent, | 1041 const BookmarkNode* old_parent, |
1017 int old_index, | 1042 int old_index, |
1018 const BookmarkNode* new_parent, | 1043 const BookmarkNode* new_parent, |
1019 int new_index) { | 1044 int new_index) { |
1020 bool was_throbbing = throbbing_view_ && | 1045 bool was_throbbing = throbbing_view_ && |
1021 throbbing_view_ == DetermineViewToThrobFromRemove(old_parent, old_index); | 1046 throbbing_view_ == DetermineViewToThrobFromRemove(old_parent, old_index); |
1022 if (was_throbbing) | 1047 if (was_throbbing) |
(...skipping 17 matching lines...) Expand all Loading... | |
1040 const std::set<GURL>& removed_urls) { | 1065 const std::set<GURL>& removed_urls) { |
1041 // Close the menu if the menu is showing for the deleted node. | 1066 // Close the menu if the menu is showing for the deleted node. |
1042 if (bookmark_menu_ && bookmark_menu_->node() == node) | 1067 if (bookmark_menu_ && bookmark_menu_->node() == node) |
1043 bookmark_menu_->Cancel(); | 1068 bookmark_menu_->Cancel(); |
1044 BookmarkNodeRemovedImpl(model, parent, old_index); | 1069 BookmarkNodeRemovedImpl(model, parent, old_index); |
1045 } | 1070 } |
1046 | 1071 |
1047 void BookmarkBarView::BookmarkAllNodesRemoved( | 1072 void BookmarkBarView::BookmarkAllNodesRemoved( |
1048 BookmarkModel* model, | 1073 BookmarkModel* model, |
1049 const std::set<GURL>& removed_urls) { | 1074 const std::set<GURL>& removed_urls) { |
1050 UpdateOtherBookmarksVisibility(); | 1075 UpdateButtonsVisibility(); |
1051 | 1076 |
1052 StopThrobbing(true); | 1077 StopThrobbing(true); |
1053 | 1078 |
1054 // Remove the existing buttons. | 1079 // Remove the existing buttons. |
1055 while (GetBookmarkButtonCount()) { | 1080 while (GetBookmarkButtonCount()) { |
1056 delete GetBookmarkButton(0); | 1081 delete GetBookmarkButton(0); |
1057 } | 1082 } |
1058 | 1083 |
1059 Layout(); | 1084 Layout(); |
1060 SchedulePaint(); | 1085 SchedulePaint(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1159 return true; | 1184 return true; |
1160 } | 1185 } |
1161 | 1186 |
1162 void BookmarkBarView::OnMenuButtonClicked(views::View* view, | 1187 void BookmarkBarView::OnMenuButtonClicked(views::View* view, |
1163 const gfx::Point& point) { | 1188 const gfx::Point& point) { |
1164 const BookmarkNode* node; | 1189 const BookmarkNode* node; |
1165 | 1190 |
1166 int start_index = 0; | 1191 int start_index = 0; |
1167 if (view == other_bookmarked_button_) { | 1192 if (view == other_bookmarked_button_) { |
1168 node = model_->other_node(); | 1193 node = model_->other_node(); |
1194 } else if (view == managed_bookmarks_button_) { | |
1195 node = client_->managed_node(); | |
1169 } else if (view == overflow_button_) { | 1196 } else if (view == overflow_button_) { |
1170 node = model_->bookmark_bar_node(); | 1197 node = model_->bookmark_bar_node(); |
1171 start_index = GetFirstHiddenNodeIndex(); | 1198 start_index = GetFirstHiddenNodeIndex(); |
1172 } else { | 1199 } else { |
1173 int button_index = GetIndexOf(view); | 1200 int button_index = GetIndexOf(view); |
1174 DCHECK_NE(-1, button_index); | 1201 DCHECK_NE(-1, button_index); |
1175 node = model_->bookmark_bar_node()->GetChild(button_index); | 1202 node = model_->bookmark_bar_node()->GetChild(button_index); |
1176 } | 1203 } |
1177 | 1204 |
1178 RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); | 1205 RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); |
(...skipping 15 matching lines...) Expand all Loading... | |
1194 content::PAGE_TRANSITION_AUTO_BOOKMARK, | 1221 content::PAGE_TRANSITION_AUTO_BOOKMARK, |
1195 false); | 1222 false); |
1196 page_navigator_->OpenURL(params); | 1223 page_navigator_->OpenURL(params); |
1197 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation()); | 1224 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation()); |
1198 return; | 1225 return; |
1199 } | 1226 } |
1200 | 1227 |
1201 const BookmarkNode* node; | 1228 const BookmarkNode* node; |
1202 if (sender->tag() == kOtherFolderButtonTag) { | 1229 if (sender->tag() == kOtherFolderButtonTag) { |
1203 node = model_->other_node(); | 1230 node = model_->other_node(); |
1231 } else if (sender->tag() == kManagedFolderButtonTag) { | |
1232 node = client_->managed_node(); | |
1204 } else { | 1233 } else { |
1205 int index = GetIndexOf(sender); | 1234 int index = GetIndexOf(sender); |
1206 DCHECK_NE(-1, index); | 1235 DCHECK_NE(-1, index); |
1207 node = model_->bookmark_bar_node()->GetChild(index); | 1236 node = model_->bookmark_bar_node()->GetChild(index); |
1208 } | 1237 } |
1209 DCHECK(page_navigator_); | 1238 DCHECK(page_navigator_); |
1210 | 1239 |
1211 if (node->is_url()) { | 1240 if (node->is_url()) { |
1212 RecordAppLaunch(browser_->profile(), node->url()); | 1241 RecordAppLaunch(browser_->profile(), node->url()); |
1213 OpenURLParams params( | 1242 OpenURLParams params( |
(...skipping 16 matching lines...) Expand all Loading... | |
1230 return; | 1259 return; |
1231 } | 1260 } |
1232 | 1261 |
1233 const BookmarkNode* parent = NULL; | 1262 const BookmarkNode* parent = NULL; |
1234 std::vector<const BookmarkNode*> nodes; | 1263 std::vector<const BookmarkNode*> nodes; |
1235 if (source == other_bookmarked_button_) { | 1264 if (source == other_bookmarked_button_) { |
1236 parent = model_->other_node(); | 1265 parent = model_->other_node(); |
1237 // Do this so the user can open all bookmarks. BookmarkContextMenu makes | 1266 // Do this so the user can open all bookmarks. BookmarkContextMenu makes |
1238 // sure the user can't edit/delete the node in this case. | 1267 // sure the user can't edit/delete the node in this case. |
1239 nodes.push_back(parent); | 1268 nodes.push_back(parent); |
1269 } else if (source == managed_bookmarks_button_) { | |
1270 parent = client_->managed_node(); | |
1271 nodes.push_back(parent); | |
1240 } else if (source != this && source != apps_page_shortcut_) { | 1272 } else if (source != this && source != apps_page_shortcut_) { |
1241 // User clicked on one of the bookmark buttons, find which one they | 1273 // 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 | 1274 // clicked on, except for the apps page shortcut, which must behave as if |
1243 // the user clicked on the bookmark bar background. | 1275 // the user clicked on the bookmark bar background. |
1244 int bookmark_button_index = GetIndexOf(source); | 1276 int bookmark_button_index = GetIndexOf(source); |
1245 DCHECK(bookmark_button_index != -1 && | 1277 DCHECK(bookmark_button_index != -1 && |
1246 bookmark_button_index < GetBookmarkButtonCount()); | 1278 bookmark_button_index < GetBookmarkButtonCount()); |
1247 const BookmarkNode* node = | 1279 const BookmarkNode* node = |
1248 model_->bookmark_bar_node()->GetChild(bookmark_button_index); | 1280 model_->bookmark_bar_node()->GetChild(bookmark_button_index); |
1249 nodes.push_back(node); | 1281 nodes.push_back(node); |
(...skipping 21 matching lines...) Expand all Loading... | |
1271 // Child views are traversed in the order they are added. Make sure the order | 1303 // Child views are traversed in the order they are added. Make sure the order |
1272 // they are added matches the visual order. | 1304 // they are added matches the visual order. |
1273 overflow_button_ = CreateOverflowButton(); | 1305 overflow_button_ = CreateOverflowButton(); |
1274 AddChildView(overflow_button_); | 1306 AddChildView(overflow_button_); |
1275 | 1307 |
1276 other_bookmarked_button_ = CreateOtherBookmarkedButton(); | 1308 other_bookmarked_button_ = CreateOtherBookmarkedButton(); |
1277 // We'll re-enable when the model is loaded. | 1309 // We'll re-enable when the model is loaded. |
1278 other_bookmarked_button_->SetEnabled(false); | 1310 other_bookmarked_button_->SetEnabled(false); |
1279 AddChildView(other_bookmarked_button_); | 1311 AddChildView(other_bookmarked_button_); |
1280 | 1312 |
1313 managed_bookmarks_button_ = CreateOtherBookmarkedButton(); | |
1314 // Also re-enabled when the model is loaded. | |
1315 managed_bookmarks_button_->SetEnabled(false); | |
1316 AddChildView(managed_bookmarks_button_); | |
1317 | |
1281 apps_page_shortcut_ = CreateAppsPageShortcutButton(); | 1318 apps_page_shortcut_ = CreateAppsPageShortcutButton(); |
1282 AddChildView(apps_page_shortcut_); | 1319 AddChildView(apps_page_shortcut_); |
1283 profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); | 1320 profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); |
1284 profile_pref_registrar_.Add( | 1321 profile_pref_registrar_.Add( |
1285 prefs::kShowAppsShortcutInBookmarkBar, | 1322 prefs::kShowAppsShortcutInBookmarkBar, |
1286 base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityPrefChanged, | 1323 base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityPrefChanged, |
1287 base::Unretained(this))); | 1324 base::Unretained(this))); |
1288 apps_page_shortcut_->SetVisible( | 1325 apps_page_shortcut_->SetVisible( |
1289 chrome::ShouldShowAppsShortcutInBookmarkBar( | 1326 chrome::ShouldShowAppsShortcutInBookmarkBar( |
1290 browser_->profile(), browser_->host_desktop_type())); | 1327 browser_->profile(), browser_->host_desktop_type())); |
1291 | 1328 |
1292 bookmarks_separator_view_ = new ButtonSeparatorView(); | 1329 bookmarks_separator_view_ = new ButtonSeparatorView(); |
1293 AddChildView(bookmarks_separator_view_); | 1330 AddChildView(bookmarks_separator_view_); |
1294 UpdateBookmarksSeparatorVisibility(); | 1331 UpdateBookmarksSeparatorVisibility(); |
1295 | 1332 |
1296 instructions_ = new BookmarkBarInstructionsView(this); | 1333 instructions_ = new BookmarkBarInstructionsView(this); |
1297 AddChildView(instructions_); | 1334 AddChildView(instructions_); |
1298 | 1335 |
1299 set_context_menu_controller(this); | 1336 set_context_menu_controller(this); |
1300 | 1337 |
1301 size_animation_.reset(new gfx::SlideAnimation(this)); | 1338 size_animation_.reset(new gfx::SlideAnimation(this)); |
1302 | 1339 |
1303 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); | 1340 client_ = BookmarkModelFactory::GetChromeBookmarkClientForProfile( |
1341 browser_->profile()); | |
1342 model_ = client_->model(); | |
1304 if (model_) { | 1343 if (model_) { |
1305 model_->AddObserver(this); | 1344 model_->AddObserver(this); |
1306 if (model_->loaded()) | 1345 if (model_->loaded()) |
1307 BookmarkModelLoaded(model_, false); | 1346 BookmarkModelLoaded(model_, false); |
1308 // else case: we'll receive notification back from the BookmarkModel when | 1347 // else case: we'll receive notification back from the BookmarkModel when |
1309 // done loading, then we'll populate the bar. | 1348 // done loading, then we'll populate the bar. |
1310 } | 1349 } |
1311 } | 1350 } |
1312 | 1351 |
1313 int BookmarkBarView::GetBookmarkButtonCount() const { | 1352 int BookmarkBarView::GetBookmarkButtonCount() const { |
1314 // We contain four non-bookmark button views: other bookmarks, bookmarks | 1353 // We contain six non-bookmark button views: managed bookmarks, |
1315 // separator, chevrons (for overflow), apps page, and the instruction label. | 1354 // other bookmarks, bookmarks separator, chevrons (for overflow), apps page, |
1316 return child_count() - 5; | 1355 // and the instruction label. |
1356 return child_count() - 6; | |
1317 } | 1357 } |
1318 | 1358 |
1319 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { | 1359 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { |
1320 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); | 1360 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); |
1321 return static_cast<views::TextButton*>(child_at(index)); | 1361 return static_cast<views::TextButton*>(child_at(index)); |
1322 } | 1362 } |
1323 | 1363 |
1324 BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const { | 1364 BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const { |
1325 return IsDetached() ? BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR : | 1365 return IsDetached() ? BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR : |
1326 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR; | 1366 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR; |
(...skipping 12 matching lines...) Expand all Loading... | |
1339 // Title is set in Loaded. | 1379 // Title is set in Loaded. |
1340 MenuButton* button = | 1380 MenuButton* button = |
1341 new BookmarkFolderButton(this, base::string16(), this, false); | 1381 new BookmarkFolderButton(this, base::string16(), this, false); |
1342 button->set_id(VIEW_ID_OTHER_BOOKMARKS); | 1382 button->set_id(VIEW_ID_OTHER_BOOKMARKS); |
1343 button->SetIcon(GetFolderIcon()); | 1383 button->SetIcon(GetFolderIcon()); |
1344 button->set_context_menu_controller(this); | 1384 button->set_context_menu_controller(this); |
1345 button->set_tag(kOtherFolderButtonTag); | 1385 button->set_tag(kOtherFolderButtonTag); |
1346 return button; | 1386 return button; |
1347 } | 1387 } |
1348 | 1388 |
1389 MenuButton* BookmarkBarView::CreateManagedBookmarksButton() { | |
1390 // Title is set in Loaded. | |
1391 MenuButton* button = | |
1392 new BookmarkFolderButton(this, base::string16(), this, false); | |
1393 button->set_id(VIEW_ID_MANAGED_BOOKMARKS); | |
1394 // TODO(joaodasilva): replace with a "managed folder" icon. | |
1395 // http://crbug.com/49598 | |
1396 button->SetIcon(GetFolderIcon()); | |
1397 button->set_context_menu_controller(this); | |
1398 button->set_tag(kManagedFolderButtonTag); | |
1399 return button; | |
1400 } | |
1401 | |
1349 MenuButton* BookmarkBarView::CreateOverflowButton() { | 1402 MenuButton* BookmarkBarView::CreateOverflowButton() { |
1350 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 1403 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
1351 MenuButton* button = new OverFlowButton(this); | 1404 MenuButton* button = new OverFlowButton(this); |
1352 button->SetIcon(*rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS)); | 1405 button->SetIcon(*rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS)); |
1353 | 1406 |
1354 // The overflow button's image contains an arrow and therefore it is a | 1407 // 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 | 1408 // direction sensitive image and we need to flip it if the UI layout is |
1356 // right-to-left. | 1409 // right-to-left. |
1357 // | 1410 // |
1358 // By default, menu buttons are not flipped because they generally contain | 1411 // By default, menu buttons are not flipped because they generally contain |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1416 button->SetIcon(*favicon.ToImageSkia()); | 1469 button->SetIcon(*favicon.ToImageSkia()); |
1417 else | 1470 else |
1418 button->SetIcon(GetDefaultFavicon()); | 1471 button->SetIcon(GetDefaultFavicon()); |
1419 } | 1472 } |
1420 button->set_max_width(kMaxButtonWidth); | 1473 button->set_max_width(kMaxButtonWidth); |
1421 } | 1474 } |
1422 | 1475 |
1423 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, | 1476 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, |
1424 const BookmarkNode* parent, | 1477 const BookmarkNode* parent, |
1425 int index) { | 1478 int index) { |
1426 UpdateOtherBookmarksVisibility(); | 1479 UpdateButtonsVisibility(); |
1427 if (parent != model_->bookmark_bar_node()) { | 1480 if (parent != model_->bookmark_bar_node()) { |
1428 // We only care about nodes on the bookmark bar. | 1481 // We only care about nodes on the bookmark bar. |
1429 return; | 1482 return; |
1430 } | 1483 } |
1431 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); | 1484 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); |
1432 const BookmarkNode* node = parent->GetChild(index); | 1485 const BookmarkNode* node = parent->GetChild(index); |
1433 ProfileSyncService* sync_service(ProfileSyncServiceFactory:: | 1486 ProfileSyncService* sync_service(ProfileSyncServiceFactory:: |
1434 GetInstance()->GetForProfile(browser_->profile())); | 1487 GetInstance()->GetForProfile(browser_->profile())); |
1435 if (!throbbing_view_ && sync_service && sync_service->FirstSetupInProgress()) | 1488 if (!throbbing_view_ && sync_service && sync_service->FirstSetupInProgress()) |
1436 StartThrobbing(node, true); | 1489 StartThrobbing(node, true); |
1437 AddChildViewAt(CreateBookmarkButton(node), index); | 1490 AddChildViewAt(CreateBookmarkButton(node), index); |
1438 UpdateColors(); | 1491 UpdateColors(); |
1439 Layout(); | 1492 Layout(); |
1440 SchedulePaint(); | 1493 SchedulePaint(); |
1441 } | 1494 } |
1442 | 1495 |
1443 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, | 1496 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, |
1444 const BookmarkNode* parent, | 1497 const BookmarkNode* parent, |
1445 int index) { | 1498 int index) { |
1446 UpdateOtherBookmarksVisibility(); | 1499 UpdateButtonsVisibility(); |
1447 | 1500 |
1448 StopThrobbing(true); | 1501 StopThrobbing(true); |
1449 // No need to start throbbing again as the bookmark bubble can't be up at | 1502 // No need to start throbbing again as the bookmark bubble can't be up at |
1450 // the same time as the user reorders. | 1503 // the same time as the user reorders. |
1451 | 1504 |
1452 if (parent != model_->bookmark_bar_node()) { | 1505 if (parent != model_->bookmark_bar_node()) { |
1453 // We only care about nodes on the bookmark bar. | 1506 // We only care about nodes on the bookmark bar. |
1454 return; | 1507 return; |
1455 } | 1508 } |
1456 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); | 1509 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1546 Profile* profile = browser_->profile(); | 1599 Profile* profile = browser_->profile(); |
1547 if (other_bookmarked_button_->visible() && other_delta_x >= 0 && | 1600 if (other_bookmarked_button_->visible() && other_delta_x >= 0 && |
1548 other_delta_x < other_bookmarked_button_->width()) { | 1601 other_delta_x < other_bookmarked_button_->width()) { |
1549 // Mouse is over 'other' folder. | 1602 // Mouse is over 'other' folder. |
1550 location->button_type = DROP_OTHER_FOLDER; | 1603 location->button_type = DROP_OTHER_FOLDER; |
1551 location->on = true; | 1604 location->on = true; |
1552 found = true; | 1605 found = true; |
1553 } else if (!GetBookmarkButtonCount()) { | 1606 } else if (!GetBookmarkButtonCount()) { |
1554 // No bookmarks, accept the drop. | 1607 // No bookmarks, accept the drop. |
1555 location->index = 0; | 1608 location->index = 0; |
1556 int ops = data.GetFirstNode(model_, profile->GetPath()) ? | 1609 const BookmarkNode* node = data.GetFirstNode(model_, profile->GetPath()); |
1610 int ops = node && client_->CanBeEditedByUser(node) ? | |
1557 ui::DragDropTypes::DRAG_MOVE : | 1611 ui::DragDropTypes::DRAG_MOVE : |
1558 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; | 1612 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; |
1559 location->operation = chrome::GetPreferredBookmarkDropOperation( | 1613 location->operation = chrome::GetPreferredBookmarkDropOperation( |
1560 event.source_operations(), ops); | 1614 event.source_operations(), ops); |
1561 return; | 1615 return; |
1562 } | 1616 } |
1563 | 1617 |
1564 for (int i = 0; i < GetBookmarkButtonCount() && | 1618 for (int i = 0; i < GetBookmarkButtonCount() && |
1565 GetBookmarkButton(i)->visible() && !found; i++) { | 1619 GetBookmarkButton(i)->visible() && !found; i++) { |
1566 views::TextButton* button = GetBookmarkButton(i); | 1620 views::TextButton* button = GetBookmarkButton(i); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1652 parent_on_bb = parent; | 1706 parent_on_bb = parent; |
1653 } | 1707 } |
1654 if (parent_on_bb) { | 1708 if (parent_on_bb) { |
1655 int index = bbn->GetIndexOf(parent_on_bb); | 1709 int index = bbn->GetIndexOf(parent_on_bb); |
1656 if (index >= GetFirstHiddenNodeIndex()) { | 1710 if (index >= GetFirstHiddenNodeIndex()) { |
1657 // Node is hidden, animate the overflow button. | 1711 // Node is hidden, animate the overflow button. |
1658 throbbing_view_ = overflow_button_; | 1712 throbbing_view_ = overflow_button_; |
1659 } else if (!overflow_only) { | 1713 } else if (!overflow_only) { |
1660 throbbing_view_ = static_cast<CustomButton*>(child_at(index)); | 1714 throbbing_view_ = static_cast<CustomButton*>(child_at(index)); |
1661 } | 1715 } |
1716 } else if (client_->IsDescendantOfManagedNode(node)) { | |
1717 throbbing_view_ = managed_bookmarks_button_; | |
1662 } else if (!overflow_only) { | 1718 } else if (!overflow_only) { |
1663 throbbing_view_ = other_bookmarked_button_; | 1719 throbbing_view_ = other_bookmarked_button_; |
1664 } | 1720 } |
1665 | 1721 |
1666 // Use a large number so that the button continues to throb. | 1722 // Use a large number so that the button continues to throb. |
1667 if (throbbing_view_) | 1723 if (throbbing_view_) |
1668 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); | 1724 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); |
1669 } | 1725 } |
1670 | 1726 |
1671 views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( | 1727 views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( |
(...skipping 10 matching lines...) Expand all Loading... | |
1682 } | 1738 } |
1683 old_node = parent; | 1739 old_node = parent; |
1684 } | 1740 } |
1685 if (old_node) { | 1741 if (old_node) { |
1686 if (old_index_on_bb >= GetFirstHiddenNodeIndex()) { | 1742 if (old_index_on_bb >= GetFirstHiddenNodeIndex()) { |
1687 // Node is hidden, animate the overflow button. | 1743 // Node is hidden, animate the overflow button. |
1688 return overflow_button_; | 1744 return overflow_button_; |
1689 } | 1745 } |
1690 return static_cast<CustomButton*>(child_at(old_index_on_bb)); | 1746 return static_cast<CustomButton*>(child_at(old_index_on_bb)); |
1691 } | 1747 } |
1748 if (client_->IsDescendantOfManagedNode(parent)) | |
1749 return managed_bookmarks_button_; | |
1692 // Node wasn't on the bookmark bar, use the other bookmark button. | 1750 // Node wasn't on the bookmark bar, use the other bookmark button. |
1693 return other_bookmarked_button_; | 1751 return other_bookmarked_button_; |
1694 } | 1752 } |
1695 | 1753 |
1696 void BookmarkBarView::UpdateColors() { | 1754 void BookmarkBarView::UpdateColors() { |
1697 // We don't always have a theme provider (ui tests, for example). | 1755 // We don't always have a theme provider (ui tests, for example). |
1698 const ui::ThemeProvider* theme_provider = GetThemeProvider(); | 1756 const ui::ThemeProvider* theme_provider = GetThemeProvider(); |
1699 if (!theme_provider) | 1757 if (!theme_provider) |
1700 return; | 1758 return; |
1701 SkColor text_color = | 1759 SkColor text_color = |
1702 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); | 1760 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); |
1703 for (int i = 0; i < GetBookmarkButtonCount(); ++i) | 1761 for (int i = 0; i < GetBookmarkButtonCount(); ++i) |
1704 GetBookmarkButton(i)->SetEnabledColor(text_color); | 1762 GetBookmarkButton(i)->SetEnabledColor(text_color); |
1705 other_bookmarked_button()->SetEnabledColor(text_color); | 1763 other_bookmarked_button_->SetEnabledColor(text_color); |
1764 managed_bookmarks_button_->SetEnabledColor(text_color); | |
1706 if (apps_page_shortcut_->visible()) | 1765 if (apps_page_shortcut_->visible()) |
1707 apps_page_shortcut_->SetEnabledColor(text_color); | 1766 apps_page_shortcut_->SetEnabledColor(text_color); |
1708 } | 1767 } |
1709 | 1768 |
1710 void BookmarkBarView::UpdateOtherBookmarksVisibility() { | 1769 void BookmarkBarView::UpdateButtonsVisibility() { |
1711 bool has_other_children = !model_->other_node()->empty(); | 1770 bool has_other_children = !model_->other_node()->empty(); |
1712 if (has_other_children == other_bookmarked_button_->visible()) | 1771 bool update_other = has_other_children != other_bookmarked_button_->visible(); |
1713 return; | 1772 if (update_other) { |
1714 other_bookmarked_button_->SetVisible(has_other_children); | 1773 other_bookmarked_button_->SetVisible(has_other_children); |
1715 UpdateBookmarksSeparatorVisibility(); | 1774 UpdateBookmarksSeparatorVisibility(); |
1716 Layout(); | 1775 } |
1717 SchedulePaint(); | 1776 |
1777 bool has_managed_children = !client_->managed_node()->empty(); | |
1778 bool update_managed = | |
1779 has_managed_children != managed_bookmarks_button_->visible(); | |
1780 if (update_managed) | |
1781 managed_bookmarks_button_->SetVisible(has_managed_children); | |
1782 | |
1783 if (update_other || update_managed) { | |
1784 Layout(); | |
1785 SchedulePaint(); | |
1786 } | |
1718 } | 1787 } |
1719 | 1788 |
1720 void BookmarkBarView::UpdateBookmarksSeparatorVisibility() { | 1789 void BookmarkBarView::UpdateBookmarksSeparatorVisibility() { |
1721 // Ash does not paint the bookmarks separator line because it looks odd on | 1790 // 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. | 1791 // the flat background. We keep it present for layout, but don't draw it. |
1723 bookmarks_separator_view_->SetVisible( | 1792 bookmarks_separator_view_->SetVisible( |
1724 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH && | 1793 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH && |
1725 other_bookmarked_button_->visible()); | 1794 other_bookmarked_button_->visible()); |
1726 } | 1795 } |
1727 | 1796 |
(...skipping 28 matching lines...) Expand all Loading... | |
1756 bookmarks_separator_view_->GetPreferredSize(); | 1825 bookmarks_separator_view_->GetPreferredSize(); |
1757 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ? | 1826 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ? |
1758 apps_page_shortcut_->GetPreferredSize() : gfx::Size(); | 1827 apps_page_shortcut_->GetPreferredSize() : gfx::Size(); |
1759 | 1828 |
1760 int max_x = width - overflow_pref.width() - kButtonPadding - | 1829 int max_x = width - overflow_pref.width() - kButtonPadding - |
1761 bookmarks_separator_pref.width(); | 1830 bookmarks_separator_pref.width(); |
1762 if (other_bookmarked_button_->visible()) | 1831 if (other_bookmarked_button_->visible()) |
1763 max_x -= other_bookmarked_pref.width() + kButtonPadding; | 1832 max_x -= other_bookmarked_pref.width() + kButtonPadding; |
1764 | 1833 |
1765 // Next, layout out the buttons. Any buttons that are placed beyond the | 1834 // Next, layout out the buttons. Any buttons that are placed beyond the |
1766 // visible region and made invisible. | 1835 // visible region are made invisible. |
1767 | 1836 |
1768 // Start with the apps page shortcut button. | 1837 // Start with the apps page shortcut button. |
1769 if (apps_page_shortcut_->visible()) { | 1838 if (apps_page_shortcut_->visible()) { |
1770 apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(), | 1839 apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(), |
1771 height); | 1840 height); |
1772 x += apps_page_shortcut_pref.width() + kButtonPadding; | 1841 x += apps_page_shortcut_pref.width() + kButtonPadding; |
1773 } | 1842 } |
1774 | 1843 |
1844 // Then comes the managed bookmarks folder, if visible. | |
1845 if (managed_bookmarks_button_->visible()) { | |
1846 gfx::Size managed_bookmarks_pref = managed_bookmarks_button_->visible() ? | |
1847 managed_bookmarks_button_->GetPreferredSize() : gfx::Size(); | |
1848 managed_bookmarks_button_->SetBounds(x, y, managed_bookmarks_pref.width(), | |
1849 height); | |
1850 x += managed_bookmarks_pref.width() + kButtonPadding; | |
1851 } | |
1852 | |
1775 // Then go through the bookmark buttons. | 1853 // Then go through the bookmark buttons. |
1776 if (GetBookmarkButtonCount() == 0 && model_ && model_->loaded()) { | 1854 if (GetBookmarkButtonCount() == 0 && model_ && model_->loaded()) { |
1777 gfx::Size pref = instructions_->GetPreferredSize(); | 1855 gfx::Size pref = instructions_->GetPreferredSize(); |
1778 instructions_->SetBounds( | 1856 instructions_->SetBounds( |
1779 x + kInstructionsPadding, y, | 1857 x + kInstructionsPadding, y, |
1780 std::min(static_cast<int>(pref.width()), | 1858 std::min(static_cast<int>(pref.width()), |
1781 max_x - x), | 1859 max_x - x), |
1782 height); | 1860 height); |
1783 instructions_->SetVisible(true); | 1861 instructions_->SetVisible(true); |
1784 } else { | 1862 } else { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1829 DCHECK(apps_page_shortcut_); | 1907 DCHECK(apps_page_shortcut_); |
1830 // Only perform layout if required. | 1908 // Only perform layout if required. |
1831 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( | 1909 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( |
1832 browser_->profile(), browser_->host_desktop_type()); | 1910 browser_->profile(), browser_->host_desktop_type()); |
1833 if (apps_page_shortcut_->visible() == visible) | 1911 if (apps_page_shortcut_->visible() == visible) |
1834 return; | 1912 return; |
1835 apps_page_shortcut_->SetVisible(visible); | 1913 apps_page_shortcut_->SetVisible(visible); |
1836 UpdateBookmarksSeparatorVisibility(); | 1914 UpdateBookmarksSeparatorVisibility(); |
1837 Layout(); | 1915 Layout(); |
1838 } | 1916 } |
OLD | NEW |