Chromium Code Reviews| Index: chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| index 0e878190707b30146f89945f43110f66e0395b93..9c538b6b55b1a7a967748966c2cccd761eb8fd13 100644 |
| --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| @@ -156,6 +156,8 @@ static const int kButtonPaddingVertical = 4; |
| // Tag for the 'Managed bookmarks' button. |
| static const int kManagedFolderButtonTag = 3; |
| +// Tag for the 'Supervised bookmarks' button. |
| +static const int kSupervisedFolderButtonTag = 4; |
| #if !defined(OS_WIN) |
| static const gfx::ElideBehavior kElideBehavior = gfx::FADE_TAIL; |
| @@ -500,6 +502,7 @@ BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) |
| bookmark_drop_menu_(NULL), |
| other_bookmarks_button_(NULL), |
| managed_bookmarks_button_(NULL), |
| + supervised_bookmarks_button_(NULL), |
| apps_page_shortcut_(NULL), |
| overflow_button_(NULL), |
| instructions_(NULL), |
| @@ -601,6 +604,12 @@ const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex( |
| return client_->managed_node(); |
| } |
| + // Then check the supervised button. |
| + if (supervised_bookmarks_button_->visible() && |
| + supervised_bookmarks_button_->bounds().Contains(adjusted_loc)) { |
| + return client_->supervised_node(); |
| + } |
| + |
| // Then check the bookmark buttons. |
| for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
| views::View* child = child_at(i); |
| @@ -630,6 +639,8 @@ views::MenuButton* BookmarkBarView::GetMenuButtonForNode( |
| const BookmarkNode* node) { |
| if (node == client_->managed_node()) |
| return managed_bookmarks_button_; |
| + if (node == client_->supervised_node()) |
| + return supervised_bookmarks_button_; |
| if (node == model_->other_node()) |
| return other_bookmarks_button_; |
| if (node == model_->bookmark_bar_node()) |
| @@ -773,7 +784,8 @@ gfx::Size BookmarkBarView::GetMinimumSize() const { |
| // The minimum width of the bookmark bar should at least contain the overflow |
| // button, by which one can access all the Bookmark Bar items, and the "Other |
| // Bookmarks" folder, along with appropriate margins and button padding. |
| - // It should also contain the Managed Bookmarks folder, if it's visible. |
| + // It should also contain the Managed and/or Supervised Bookmarks folders, |
| + // if they are visible. |
| int width = kLeftMargin; |
| int height = chrome::kBookmarkBarHeight; |
| @@ -789,6 +801,10 @@ gfx::Size BookmarkBarView::GetMinimumSize() const { |
| gfx::Size size = managed_bookmarks_button_->GetPreferredSize(); |
| width += size.width() + kButtonPadding; |
| } |
| + if (supervised_bookmarks_button_->visible()) { |
| + gfx::Size size = supervised_bookmarks_button_->GetPreferredSize(); |
| + width += size.width() + kButtonPadding; |
| + } |
| if (other_bookmarks_button_->visible()) { |
| gfx::Size size = other_bookmarks_button_->GetPreferredSize(); |
| width += size.width() + kButtonPadding; |
| @@ -856,13 +872,22 @@ void BookmarkBarView::Layout() { |
| // Then comes the managed bookmarks folder, if visible. |
| if (managed_bookmarks_button_->visible()) { |
| - gfx::Size managed_bookmarks_pref = managed_bookmarks_button_->visible() ? |
| - managed_bookmarks_button_->GetPreferredSize() : gfx::Size(); |
| + gfx::Size managed_bookmarks_pref = |
| + managed_bookmarks_button_->GetPreferredSize(); |
| managed_bookmarks_button_->SetBounds(x, y, managed_bookmarks_pref.width(), |
| height); |
| x += managed_bookmarks_pref.width() + kButtonPadding; |
| } |
| + // Then the supervised bookmarks folder, if visible. |
| + if (supervised_bookmarks_button_->visible()) { |
|
sky
2015/02/04 18:36:58
What happens when the supervised, managed and apps
Marc Treib
2015/02/05 12:57:06
We're only exposing the supervised bookmarks for c
sky
2015/02/05 17:57:11
Ok.
|
| + gfx::Size supervised_bookmarks_pref = |
| + supervised_bookmarks_button_->GetPreferredSize(); |
| + supervised_bookmarks_button_->SetBounds( |
| + x, y, supervised_bookmarks_pref.width(), height); |
| + x += supervised_bookmarks_pref.width() + kButtonPadding; |
| + } |
| + |
| const bool show_instructions = |
| model_ && model_->loaded() && |
| model_->bookmark_bar_node()->child_count() == 0; |
| @@ -1206,10 +1231,14 @@ void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model, |
| managed_bookmarks_button_->SetAccessibleName( |
| client_->managed_node()->GetTitle()); |
| managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); |
| + supervised_bookmarks_button_->SetAccessibleName( |
| + client_->supervised_node()->GetTitle()); |
| + supervised_bookmarks_button_->SetText(client_->supervised_node()->GetTitle()); |
| UpdateColors(); |
| UpdateOtherAndManagedButtonsVisibility(); |
| other_bookmarks_button_->SetEnabled(true); |
| managed_bookmarks_button_->SetEnabled(true); |
| + supervised_bookmarks_button_->SetEnabled(true); |
| LayoutAndPaint(); |
| } |
| @@ -1384,6 +1413,8 @@ void BookmarkBarView::OnMenuButtonClicked(views::View* view, |
| node = model_->other_node(); |
| } else if (view == managed_bookmarks_button_) { |
| node = client_->managed_node(); |
| + } else if (view == supervised_bookmarks_button_) { |
| + node = client_->supervised_node(); |
| } else if (view == overflow_button_) { |
| node = model_->bookmark_bar_node(); |
| start_index = GetFirstHiddenNodeIndex(); |
| @@ -1421,6 +1452,8 @@ void BookmarkBarView::ButtonPressed(views::Button* sender, |
| node = model_->other_node(); |
| } else if (sender->tag() == kManagedFolderButtonTag) { |
| node = client_->managed_node(); |
| + } else if (sender->tag() == kSupervisedFolderButtonTag) { |
| + node = client_->supervised_node(); |
| } else { |
| int index = GetIndexOf(sender); |
| DCHECK_NE(-1, index); |
| @@ -1460,6 +1493,9 @@ void BookmarkBarView::ShowContextMenuForView(views::View* source, |
| } else if (source == managed_bookmarks_button_) { |
| parent = client_->managed_node(); |
| nodes.push_back(parent); |
| + } else if (source == supervised_bookmarks_button_) { |
| + parent = client_->supervised_node(); |
| + nodes.push_back(parent); |
| } else if (source != this && source != apps_page_shortcut_) { |
| // User clicked on one of the bookmark buttons, find which one they |
| // clicked on, except for the apps page shortcut, which must behave as if |
| @@ -1506,6 +1542,11 @@ void BookmarkBarView::Init() { |
| managed_bookmarks_button_->SetEnabled(false); |
| AddChildView(managed_bookmarks_button_); |
| + supervised_bookmarks_button_ = CreateSupervisedBookmarksButton(); |
| + // Also re-enabled when the model is loaded. |
| + supervised_bookmarks_button_->SetEnabled(false); |
| + AddChildView(supervised_bookmarks_button_); |
| + |
| apps_page_shortcut_ = CreateAppsPageShortcutButton(); |
| AddChildView(apps_page_shortcut_); |
| profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); |
| @@ -1544,10 +1585,10 @@ void BookmarkBarView::Init() { |
| } |
| int BookmarkBarView::GetBookmarkButtonCount() const { |
| - // We contain six non-bookmark button views: managed bookmarks, |
| - // other bookmarks, bookmarks separator, chevrons (for overflow), apps page, |
| - // and the instruction label. |
| - return child_count() - 6; |
| + // We contain seven non-bookmark button views: managed bookmarks, supervised |
| + // bookmarks, other bookmarks, bookmarks separator, chevrons (for overflow), |
| + // apps page, and the instruction label. |
| + return child_count() - 7; |
| } |
| views::LabelButton* BookmarkBarView::GetBookmarkButton(int index) { |
| @@ -1594,6 +1635,18 @@ MenuButton* BookmarkBarView::CreateManagedBookmarksButton() { |
| return button; |
| } |
| +MenuButton* BookmarkBarView::CreateSupervisedBookmarksButton() { |
| + // Title is set in Loaded. |
| + MenuButton* button = |
| + new BookmarkFolderButton(this, base::string16(), this, false); |
| + button->set_id(VIEW_ID_SUPERVISED_BOOKMARKS); |
| + button->SetImage(views::Button::STATE_NORMAL, |
| + *GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER_SUPERVISED)); |
| + button->set_context_menu_controller(this); |
| + button->set_tag(kSupervisedFolderButtonTag); |
| + return button; |
| +} |
| + |
| MenuButton* BookmarkBarView::CreateOverflowButton() { |
| MenuButton* button = new OverFlowButton(this); |
| button->SetImage(views::Button::STATE_NORMAL, |
| @@ -1714,6 +1767,14 @@ void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, |
| managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); |
| return; |
| } |
| + if (node == client_->supervised_node()) { |
| + // The supervised node may have its title updated. |
| + supervised_bookmarks_button_->SetAccessibleName( |
| + client_->supervised_node()->GetTitle()); |
| + supervised_bookmarks_button_->SetText( |
| + client_->supervised_node()->GetTitle()); |
| + return; |
| + } |
| if (node->parent() != model->bookmark_bar_node()) { |
| // We only care about nodes on the bookmark bar. |
| @@ -1911,6 +1972,8 @@ void BookmarkBarView::StartThrobbing(const BookmarkNode* node, |
| } |
| } else if (client_->IsDescendantOfManagedNode(node)) { |
| throbbing_view_ = managed_bookmarks_button_; |
| + } else if (client_->IsDescendantOfSupervisedNode(node)) { |
| + throbbing_view_ = supervised_bookmarks_button_; |
| } else if (!overflow_only) { |
| throbbing_view_ = other_bookmarks_button_; |
| } |
| @@ -1943,6 +2006,8 @@ views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( |
| } |
| if (client_->IsDescendantOfManagedNode(parent)) |
| return managed_bookmarks_button_; |
| + if (client_->IsDescendantOfSupervisedNode(parent)) |
| + return supervised_bookmarks_button_; |
| // Node wasn't on the bookmark bar, use the "Other Bookmarks" button. |
| return other_bookmarks_button_; |
| } |
| @@ -1958,6 +2023,8 @@ void BookmarkBarView::UpdateColors() { |
| GetBookmarkButton(i)->SetTextColor(views::Button::STATE_NORMAL, color); |
| other_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, color); |
| managed_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, color); |
| + supervised_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, |
| + color); |
| if (apps_page_shortcut_->visible()) |
| apps_page_shortcut_->SetTextColor(views::Button::STATE_NORMAL, color); |
| } |
| @@ -1977,7 +2044,13 @@ bool BookmarkBarView::UpdateOtherAndManagedButtonsVisibility() { |
| if (update_managed) |
| managed_bookmarks_button_->SetVisible(show_managed); |
| - return update_other || update_managed; |
| + bool show_supervised = !client_->supervised_node()->empty(); |
| + bool update_supervised = |
| + show_supervised != supervised_bookmarks_button_->visible(); |
| + if (update_supervised) |
| + supervised_bookmarks_button_->SetVisible(show_supervised); |
| + |
| + return update_other || update_managed || update_supervised; |
| } |
| void BookmarkBarView::UpdateBookmarksSeparatorVisibility() { |