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

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: fix build (Android & unit_tests) Created 5 years, 10 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 6672c13e4e9517312406086a6008490aca00c876..506ee3e28241024b67b14be201cc1d0bfcd7dd54 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
@@ -51,6 +51,7 @@
#include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "components/bookmarks/browser/bookmark_model.h"
+#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/metrics/metrics_service.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
@@ -157,6 +158,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;
@@ -501,6 +504,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),
@@ -602,6 +606,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);
@@ -631,6 +641,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())
@@ -774,7 +786,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;
@@ -790,6 +803,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;
@@ -857,13 +874,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;
@@ -1207,10 +1233,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();
}
@@ -1385,6 +1415,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();
@@ -1422,6 +1454,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);
@@ -1461,6 +1495,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
@@ -1507,6 +1544,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());
@@ -1545,10 +1587,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) {
@@ -1595,6 +1637,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,
@@ -1715,6 +1769,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,8 +1972,10 @@ void BookmarkBarView::StartThrobbing(const BookmarkNode* node,
} else if (!overflow_only) {
throbbing_view_ = static_cast<CustomButton*>(child_at(index));
}
- } else if (client_->IsDescendantOfManagedNode(node)) {
+ } else if (bookmarks::IsDescendantOf(node, client_->managed_node())) {
throbbing_view_ = managed_bookmarks_button_;
+ } else if (bookmarks::IsDescendantOf(node, client_->supervised_node())) {
+ throbbing_view_ = supervised_bookmarks_button_;
} else if (!overflow_only) {
throbbing_view_ = other_bookmarks_button_;
}
@@ -1942,8 +2006,10 @@ views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove(
}
return static_cast<CustomButton*>(child_at(old_index_on_bb));
}
- if (client_->IsDescendantOfManagedNode(parent))
+ if (bookmarks::IsDescendantOf(parent, client_->managed_node()))
return managed_bookmarks_button_;
+ if (bookmarks::IsDescendantOf(parent, client_->supervised_node()))
+ return supervised_bookmarks_button_;
// Node wasn't on the bookmark bar, use the "Other Bookmarks" button.
return other_bookmarks_button_;
}
@@ -1959,6 +2025,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);
}
@@ -1978,7 +2046,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() {
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view.h ('k') | chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698