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

Unified Diff: chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc

Issue 769153007: Managed bookmarks for supervised users (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 d8b0f7db408fa0993f4ee0a1aa76b59f31d4cedc..a2b3d028b3bfddd917815b4d2a1cbe8d259eb4fb 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
@@ -155,6 +155,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;
@@ -499,6 +501,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),
@@ -600,6 +603,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);
@@ -629,6 +638,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())
@@ -772,7 +783,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;
@@ -788,6 +800,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;
@@ -855,13 +871,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()) {
+ 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;
@@ -1205,10 +1230,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();
}
@@ -1383,6 +1412,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();
@@ -1420,6 +1451,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);
@@ -1459,6 +1492,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
@@ -1505,6 +1541,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());
@@ -1543,10 +1584,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) {
@@ -1593,6 +1634,20 @@ 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);
+ ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
+ gfx::ImageSkia* image =
+ rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER_SUPERVISED);
+ button->SetImage(views::Button::STATE_NORMAL, *image);
Pam (message me for reviews) 2015/01/14 14:03:37 This pattern is different in all the rest of the m
Marc Treib 2015/01/14 16:40:50 Probably, yeah - thanks, done.
+ 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,
@@ -1713,6 +1768,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.
@@ -1910,6 +1973,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_;
}
@@ -1942,6 +2007,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_;
}
@@ -1957,6 +2024,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);
}
@@ -1976,7 +2045,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() {

Powered by Google App Engine
This is Rietveld 408576698