Show the Managed Bookmarks folder in the views UI.

This change makes the Managed Bookmarks folder visible in the bookmarks
bar if it contains at least one bookmark:

- this folder is always shown floating to the left, next to the Apps button;
- this folder also appears in the bookmarks menu from the hotdog menu, as if
  it were part of the bookmarks bar;
- bookmarks can't be dragged into this folder or any of its subfolders;
- dragging bookmarks out of this folder always creates a new copy and never
  moves (the mouse cursor is decorated with the + "copy" indicator);
- the bookmark editor can't select managed folders for new bookmarks;
- bookmarks a page that already has a managed bookmarks creates a new
  bookmark instead.

BUG=49598
R=sky@chromium.org

Review URL: https://codereview.chromium.org/302313005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275676 0039d316-1c4b-4281-b951-d872f2087c98
parent eab49a65
...@@ -594,7 +594,9 @@ bool BookmarkManagerPrivateDropFunction::RunOnReady() { ...@@ -594,7 +594,9 @@ bool BookmarkManagerPrivateDropFunction::RunOnReady() {
NOTREACHED() <<"Somehow we're dropping null bookmark data"; NOTREACHED() <<"Somehow we're dropping null bookmark data";
return false; return false;
} }
chrome::DropBookmarks(GetProfile(), *drag_data, drop_parent, drop_index); const bool copy = false;
chrome::DropBookmarks(
GetProfile(), *drag_data, drop_parent, drop_index, copy);
router->ClearBookmarkNodeData(); router->ClearBookmarkNodeData();
return true; return true;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/undo/bookmark_undo_service.h" #include "chrome/browser/undo/bookmark_undo_service.h"
#include "chrome/browser/undo/bookmark_undo_service_factory.h" #include "chrome/browser/undo/bookmark_undo_service_factory.h"
#include "components/bookmarks/browser/bookmark_client.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_node_data.h" #include "components/bookmarks/browser/bookmark_node_data.h"
#include "components/bookmarks/browser/bookmark_utils.h" #include "components/bookmarks/browser/bookmark_utils.h"
...@@ -19,7 +20,8 @@ namespace chrome { ...@@ -19,7 +20,8 @@ namespace chrome {
int DropBookmarks(Profile* profile, int DropBookmarks(Profile* profile,
const BookmarkNodeData& data, const BookmarkNodeData& data,
const BookmarkNode* parent_node, const BookmarkNode* parent_node,
int index) { int index,
bool copy) {
BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
bookmarks::ScopedGroupBookmarkActions group_drops(model); bookmarks::ScopedGroupBookmarkActions group_drops(model);
...@@ -27,13 +29,20 @@ int DropBookmarks(Profile* profile, ...@@ -27,13 +29,20 @@ int DropBookmarks(Profile* profile,
if (data.IsFromProfilePath(profile->GetPath())) { if (data.IsFromProfilePath(profile->GetPath())) {
const std::vector<const BookmarkNode*> dragged_nodes = const std::vector<const BookmarkNode*> dragged_nodes =
data.GetNodes(model, profile->GetPath()); data.GetNodes(model, profile->GetPath());
DCHECK(model->client()->CanBeEditedByUser(parent_node));
DCHECK(copy || bookmark_utils::CanAllBeEditedByUser(model->client(),
dragged_nodes));
if (!dragged_nodes.empty()) { if (!dragged_nodes.empty()) {
// Drag from same profile. Move nodes. // Drag from same profile. Copy or move nodes.
for (size_t i = 0; i < dragged_nodes.size(); ++i) { for (size_t i = 0; i < dragged_nodes.size(); ++i) {
model->Move(dragged_nodes[i], parent_node, index); if (copy) {
model->Copy(dragged_nodes[i], parent_node, index);
} else {
model->Move(dragged_nodes[i], parent_node, index);
}
index = parent_node->GetIndexOf(dragged_nodes[i]) + 1; index = parent_node->GetIndexOf(dragged_nodes[i]) + 1;
} }
return ui::DragDropTypes::DRAG_MOVE; return copy ? ui::DragDropTypes::DRAG_COPY : ui::DragDropTypes::DRAG_MOVE;
} }
return ui::DragDropTypes::DRAG_NONE; return ui::DragDropTypes::DRAG_NONE;
} }
......
...@@ -23,11 +23,14 @@ void DragBookmarks(Profile* profile, ...@@ -23,11 +23,14 @@ void DragBookmarks(Profile* profile,
ui::DragDropTypes::DragEventSource source); ui::DragDropTypes::DragEventSource source);
// Drops the bookmark nodes that are in |data| onto |parent_node| at |index|. // Drops the bookmark nodes that are in |data| onto |parent_node| at |index|.
// |copy| indicates the source operation: if true then the bookmarks in |data|
// are copied, otherwise they are moved if they belong to the same |profile|.
// Returns the drop type used. // Returns the drop type used.
int DropBookmarks(Profile* profile, int DropBookmarks(Profile* profile,
const BookmarkNodeData& data, const BookmarkNodeData& data,
const BookmarkNode* parent_node, const BookmarkNode* parent_node,
int index); int index,
bool copy);
} // namespace chrome } // namespace chrome
......
...@@ -174,19 +174,22 @@ void BookmarkCurrentPageInternal(Browser* browser) { ...@@ -174,19 +174,22 @@ void BookmarkCurrentPageInternal(Browser* browser) {
WebContents* web_contents = WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents(); browser->tab_strip_model()->GetActiveWebContents();
GetURLAndTitleToBookmark(web_contents, &url, &title); GetURLAndTitleToBookmark(web_contents, &url, &title);
bool was_bookmarked = model->IsBookmarked(url); bool is_bookmarked_by_any = model->IsBookmarked(url);
if (!was_bookmarked && web_contents->GetBrowserContext()->IsOffTheRecord()) { if (!is_bookmarked_by_any &&
web_contents->GetBrowserContext()->IsOffTheRecord()) {
// If we're incognito the favicon may not have been saved. Save it now // If we're incognito the favicon may not have been saved. Save it now
// so that bookmarks have an icon for the page. // so that bookmarks have an icon for the page.
FaviconTabHelper::FromWebContents(web_contents)->SaveFavicon(); FaviconTabHelper::FromWebContents(web_contents)->SaveFavicon();
} }
bool was_bookmarked_by_user = bookmark_utils::IsBookmarkedByUser(model, url);
bookmark_utils::AddIfNotBookmarked(model, url, title); bookmark_utils::AddIfNotBookmarked(model, url, title);
bool is_bookmarked_by_user = bookmark_utils::IsBookmarkedByUser(model, url);
// Make sure the model actually added a bookmark before showing the star. A // Make sure the model actually added a bookmark before showing the star. A
// bookmark isn't created if the url is invalid. // bookmark isn't created if the url is invalid.
if (browser->window()->IsActive() && model->IsBookmarked(url)) { if (browser->window()->IsActive() && is_bookmarked_by_user) {
// Only show the bubble if the window is active, otherwise we may get into // Only show the bubble if the window is active, otherwise we may get into
// weird situations where the bubble is deleted as soon as it is shown. // weird situations where the bubble is deleted as soon as it is shown.
browser->window()->ShowBookmarkBubble(url, was_bookmarked); browser->window()->ShowBookmarkBubble(url, was_bookmarked_by_user);
} }
} }
......
...@@ -72,6 +72,7 @@ class ViewIDTest : public InProcessBrowserTest { ...@@ -72,6 +72,7 @@ class ViewIDTest : public InProcessBrowserTest {
i == VIEW_ID_FEEDBACK_BUTTON || i == VIEW_ID_FEEDBACK_BUTTON ||
i == VIEW_ID_SCRIPT_BUBBLE || i == VIEW_ID_SCRIPT_BUBBLE ||
i == VIEW_ID_MIC_SEARCH_BUTTON || i == VIEW_ID_MIC_SEARCH_BUTTON ||
i == VIEW_ID_MANAGED_BOOKMARKS ||
i == VIEW_ID_TRANSLATE_BUTTON) { i == VIEW_ID_TRANSLATE_BUTTON) {
continue; continue;
} }
......
...@@ -62,6 +62,7 @@ enum ViewID { ...@@ -62,6 +62,7 @@ enum ViewID {
// The Bookmark Bar. // The Bookmark Bar.
VIEW_ID_BOOKMARK_BAR, VIEW_ID_BOOKMARK_BAR,
VIEW_ID_OTHER_BOOKMARKS, VIEW_ID_OTHER_BOOKMARKS,
VIEW_ID_MANAGED_BOOKMARKS,
// Used for bookmarks/folders on the bookmark bar. // Used for bookmarks/folders on the bookmark bar.
VIEW_ID_BOOKMARK_BAR_ELEMENT, VIEW_ID_BOOKMARK_BAR_ELEMENT,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/chrome_bookmark_client.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/defaults.h" #include "chrome/browser/defaults.h"
...@@ -135,6 +136,9 @@ static const int kOtherFolderButtonTag = 1; ...@@ -135,6 +136,9 @@ static const int kOtherFolderButtonTag = 1;
// Tag for the 'Apps Shortcut' button. // Tag for the 'Apps Shortcut' button.
static const int kAppsShortcutButtonTag = 2; static const int kAppsShortcutButtonTag = 2;
// Tag for the 'Managed bookmarks' button.
static const int kManagedFolderButtonTag = 3;
namespace { namespace {
// To enable/disable BookmarkBar animations during testing. In production // To enable/disable BookmarkBar animations during testing. In production
...@@ -436,9 +440,11 @@ static const gfx::ImageSkia& GetFolderIcon() { ...@@ -436,9 +440,11 @@ static const gfx::ImageSkia& GetFolderIcon() {
BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view)
: page_navigator_(NULL), : page_navigator_(NULL),
model_(NULL), model_(NULL),
client_(NULL),
bookmark_menu_(NULL), bookmark_menu_(NULL),
bookmark_drop_menu_(NULL), bookmark_drop_menu_(NULL),
other_bookmarked_button_(NULL), other_bookmarked_button_(NULL),
managed_bookmarks_button_(NULL),
apps_page_shortcut_(NULL), apps_page_shortcut_(NULL),
show_folder_method_factory_(this), show_folder_method_factory_(this),
overflow_button_(NULL), overflow_button_(NULL),
...@@ -526,7 +532,13 @@ const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex( ...@@ -526,7 +532,13 @@ const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex(
gfx::Point adjusted_loc(GetMirroredXInView(loc.x()), loc.y()); gfx::Point adjusted_loc(GetMirroredXInView(loc.x()), loc.y());
// Check the buttons first. // Check the managed button first.
if (managed_bookmarks_button_->visible() &&
managed_bookmarks_button_->bounds().Contains(adjusted_loc)) {
return client_->managed_node();
}
// Then check the bookmark buttons.
for (int i = 0; i < GetBookmarkButtonCount(); ++i) { for (int i = 0; i < GetBookmarkButtonCount(); ++i) {
views::View* child = child_at(i); views::View* child = child_at(i);
if (!child->visible()) if (!child->visible())
...@@ -553,6 +565,8 @@ const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex( ...@@ -553,6 +565,8 @@ const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex(
views::MenuButton* BookmarkBarView::GetMenuButtonForNode( views::MenuButton* BookmarkBarView::GetMenuButtonForNode(
const BookmarkNode* node) { const BookmarkNode* node) {
if (node == client_->managed_node())
return managed_bookmarks_button_;
if (node == model_->other_node()) if (node == model_->other_node())
return other_bookmarked_button_; return other_bookmarked_button_;
if (node == model_->bookmark_bar_node()) if (node == model_->bookmark_bar_node())
...@@ -696,6 +710,7 @@ gfx::Size BookmarkBarView::GetMinimumSize() const { ...@@ -696,6 +710,7 @@ gfx::Size BookmarkBarView::GetMinimumSize() const {
// The minimum width of the bookmark bar should at least contain the overflow // 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 // button, by which one can access all the Bookmark Bar items, and the "Other
// Bookmarks" folder, along with appropriate margins and button padding. // Bookmarks" folder, along with appropriate margins and button padding.
// It should also contain the Managed Bookmarks folder, if it's visible.
int width = kLeftMargin; int width = kLeftMargin;
int height = chrome::kBookmarkBarHeight; int height = chrome::kBookmarkBarHeight;
...@@ -707,23 +722,26 @@ gfx::Size BookmarkBarView::GetMinimumSize() const { ...@@ -707,23 +722,26 @@ gfx::Size BookmarkBarView::GetMinimumSize() const {
current_state); current_state);
} }
gfx::Size other_bookmarked_pref; if (managed_bookmarks_button_->visible()) {
if (other_bookmarked_button_->visible()) gfx::Size size = managed_bookmarks_button_->GetPreferredSize();
other_bookmarked_pref = other_bookmarked_button_->GetPreferredSize(); width += size.width() + kButtonPadding;
gfx::Size overflow_pref; }
if (overflow_button_->visible()) if (other_bookmarked_button_->visible()) {
overflow_pref = overflow_button_->GetPreferredSize(); gfx::Size size = other_bookmarked_button_->GetPreferredSize();
gfx::Size bookmarks_separator_pref; width += size.width() + kButtonPadding;
if (bookmarks_separator_view_->visible()) }
bookmarks_separator_pref = bookmarks_separator_view_->GetPreferredSize(); if (overflow_button_->visible()) {
gfx::Size size = overflow_button_->GetPreferredSize();
gfx::Size apps_page_shortcut_pref; width += size.width() + kButtonPadding;
if (apps_page_shortcut_->visible()) }
apps_page_shortcut_pref = apps_page_shortcut_->GetPreferredSize(); if (bookmarks_separator_view_->visible()) {
width += other_bookmarked_pref.width() + kButtonPadding + gfx::Size size = bookmarks_separator_view_->GetPreferredSize();
apps_page_shortcut_pref.width() + kButtonPadding + width += size.width();
overflow_pref.width() + kButtonPadding + }
bookmarks_separator_pref.width(); if (apps_page_shortcut_->visible()) {
gfx::Size size = apps_page_shortcut_->GetPreferredSize();
width += size.width() + kButtonPadding;
}
return gfx::Size(width, height); return gfx::Size(width, height);
} }
...@@ -918,8 +936,10 @@ int BookmarkBarView::OnPerformDrop(const DropTargetEvent& event) { ...@@ -918,8 +936,10 @@ int BookmarkBarView::OnPerformDrop(const DropTargetEvent& event) {
} }
const BookmarkNodeData data = drop_info_->data; const BookmarkNodeData data = drop_info_->data;
DCHECK(data.is_valid()); DCHECK(data.is_valid());
bool copy = drop_info_->location.operation == ui::DragDropTypes::DRAG_COPY;
drop_info_.reset(); drop_info_.reset();
return chrome::DropBookmarks(browser_->profile(), data, parent_node, index); return chrome::DropBookmarks(
browser_->profile(), data, parent_node, index, copy);
} }
void BookmarkBarView::OnThemeChanged() { void BookmarkBarView::OnThemeChanged() {
...@@ -997,9 +1017,13 @@ void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model, ...@@ -997,9 +1017,13 @@ void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model,
DCHECK(model_->other_node()); DCHECK(model_->other_node());
other_bookmarked_button_->SetAccessibleName(model_->other_node()->GetTitle()); other_bookmarked_button_->SetAccessibleName(model_->other_node()->GetTitle());
other_bookmarked_button_->SetText(model_->other_node()->GetTitle()); other_bookmarked_button_->SetText(model_->other_node()->GetTitle());
managed_bookmarks_button_->SetAccessibleName(
client_->managed_node()->GetTitle());
managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle());
UpdateColors(); UpdateColors();
UpdateOtherBookmarksVisibility(); UpdateButtonsVisibility();
other_bookmarked_button_->SetEnabled(true); other_bookmarked_button_->SetEnabled(true);
managed_bookmarks_button_->SetEnabled(true);
Layout(); Layout();
SchedulePaint(); SchedulePaint();
...@@ -1010,6 +1034,7 @@ void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { ...@@ -1010,6 +1034,7 @@ void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) {
// Do minimal cleanup, presumably we'll be deleted shortly. // Do minimal cleanup, presumably we'll be deleted shortly.
model_->RemoveObserver(this); model_->RemoveObserver(this);
model_ = NULL; model_ = NULL;
client_ = NULL;
} }
void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model,
...@@ -1047,7 +1072,7 @@ void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model, ...@@ -1047,7 +1072,7 @@ void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model,
void BookmarkBarView::BookmarkAllNodesRemoved( void BookmarkBarView::BookmarkAllNodesRemoved(
BookmarkModel* model, BookmarkModel* model,
const std::set<GURL>& removed_urls) { const std::set<GURL>& removed_urls) {
UpdateOtherBookmarksVisibility(); UpdateButtonsVisibility();
StopThrobbing(true); StopThrobbing(true);
...@@ -1166,6 +1191,8 @@ void BookmarkBarView::OnMenuButtonClicked(views::View* view, ...@@ -1166,6 +1191,8 @@ void BookmarkBarView::OnMenuButtonClicked(views::View* view,
int start_index = 0; int start_index = 0;
if (view == other_bookmarked_button_) { if (view == other_bookmarked_button_) {
node = model_->other_node(); node = model_->other_node();
} else if (view == managed_bookmarks_button_) {
node = client_->managed_node();
} else if (view == overflow_button_) { } else if (view == overflow_button_) {
node = model_->bookmark_bar_node(); node = model_->bookmark_bar_node();
start_index = GetFirstHiddenNodeIndex(); start_index = GetFirstHiddenNodeIndex();
...@@ -1201,6 +1228,8 @@ void BookmarkBarView::ButtonPressed(views::Button* sender, ...@@ -1201,6 +1228,8 @@ void BookmarkBarView::ButtonPressed(views::Button* sender,
const BookmarkNode* node; const BookmarkNode* node;
if (sender->tag() == kOtherFolderButtonTag) { if (sender->tag() == kOtherFolderButtonTag) {
node = model_->other_node(); node = model_->other_node();
} else if (sender->tag() == kManagedFolderButtonTag) {
node = client_->managed_node();
} else { } else {
int index = GetIndexOf(sender); int index = GetIndexOf(sender);
DCHECK_NE(-1, index); DCHECK_NE(-1, index);
...@@ -1237,6 +1266,9 @@ void BookmarkBarView::ShowContextMenuForView(views::View* source, ...@@ -1237,6 +1266,9 @@ void BookmarkBarView::ShowContextMenuForView(views::View* source,
// Do this so the user can open all bookmarks. BookmarkContextMenu makes // Do this so the user can open all bookmarks. BookmarkContextMenu makes
// sure the user can't edit/delete the node in this case. // sure the user can't edit/delete the node in this case.
nodes.push_back(parent); nodes.push_back(parent);
} else if (source == managed_bookmarks_button_) {
parent = client_->managed_node();
nodes.push_back(parent);
} else if (source != this && source != apps_page_shortcut_) { } else if (source != this && source != apps_page_shortcut_) {
// User clicked on one of the bookmark buttons, find which one they // 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 // clicked on, except for the apps page shortcut, which must behave as if
...@@ -1278,6 +1310,11 @@ void BookmarkBarView::Init() { ...@@ -1278,6 +1310,11 @@ void BookmarkBarView::Init() {
other_bookmarked_button_->SetEnabled(false); other_bookmarked_button_->SetEnabled(false);
AddChildView(other_bookmarked_button_); AddChildView(other_bookmarked_button_);
managed_bookmarks_button_ = CreateOtherBookmarkedButton();
// Also re-enabled when the model is loaded.
managed_bookmarks_button_->SetEnabled(false);
AddChildView(managed_bookmarks_button_);
apps_page_shortcut_ = CreateAppsPageShortcutButton(); apps_page_shortcut_ = CreateAppsPageShortcutButton();
AddChildView(apps_page_shortcut_); AddChildView(apps_page_shortcut_);
profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); profile_pref_registrar_.Init(browser_->profile()->GetPrefs());
...@@ -1300,8 +1337,10 @@ void BookmarkBarView::Init() { ...@@ -1300,8 +1337,10 @@ void BookmarkBarView::Init() {
size_animation_.reset(new gfx::SlideAnimation(this)); size_animation_.reset(new gfx::SlideAnimation(this));
model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); client_ = BookmarkModelFactory::GetChromeBookmarkClientForProfile(
if (model_) { browser_->profile());
if (client_) {
model_ = client_->model();
model_->AddObserver(this); model_->AddObserver(this);
if (model_->loaded()) if (model_->loaded())
BookmarkModelLoaded(model_, false); BookmarkModelLoaded(model_, false);
...@@ -1311,9 +1350,10 @@ void BookmarkBarView::Init() { ...@@ -1311,9 +1350,10 @@ void BookmarkBarView::Init() {
} }
int BookmarkBarView::GetBookmarkButtonCount() const { int BookmarkBarView::GetBookmarkButtonCount() const {
// We contain four non-bookmark button views: other bookmarks, bookmarks // We contain six non-bookmark button views: managed bookmarks,
// separator, chevrons (for overflow), apps page, and the instruction label. // other bookmarks, bookmarks separator, chevrons (for overflow), apps page,
return child_count() - 5; // and the instruction label.
return child_count() - 6;
} }
views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { views::TextButton* BookmarkBarView::GetBookmarkButton(int index) {
...@@ -1346,6 +1386,19 @@ MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { ...@@ -1346,6 +1386,19 @@ MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() {
return button; return button;
} }
MenuButton* BookmarkBarView::CreateManagedBookmarksButton() {
// Title is set in Loaded.
MenuButton* button =
new BookmarkFolderButton(this, base::string16(), this, false);
button->set_id(VIEW_ID_MANAGED_BOOKMARKS);
// TODO(joaodasilva): replace with a "managed folder" icon.
// http://crbug.com/49598
button->SetIcon(GetFolderIcon());
button->set_context_menu_controller(this);
button->set_tag(kManagedFolderButtonTag);
return button;
}
MenuButton* BookmarkBarView::CreateOverflowButton() { MenuButton* BookmarkBarView::CreateOverflowButton() {
ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
MenuButton* button = new OverFlowButton(this); MenuButton* button = new OverFlowButton(this);
...@@ -1423,7 +1476,7 @@ void BookmarkBarView::ConfigureButton(const BookmarkNode* node, ...@@ -1423,7 +1476,7 @@ void BookmarkBarView::ConfigureButton(const BookmarkNode* node,
void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model,
const BookmarkNode* parent, const BookmarkNode* parent,
int index) { int index) {
UpdateOtherBookmarksVisibility(); UpdateButtonsVisibility();
if (parent != model_->bookmark_bar_node()) { if (parent != model_->bookmark_bar_node()) {
// We only care about nodes on the bookmark bar. // We only care about nodes on the bookmark bar.
return; return;
...@@ -1443,7 +1496,7 @@ void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, ...@@ -1443,7 +1496,7 @@ void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model,
void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model,
const BookmarkNode* parent, const BookmarkNode* parent,
int index) { int index) {
UpdateOtherBookmarksVisibility(); UpdateButtonsVisibility();
StopThrobbing(true); StopThrobbing(true);
// No need to start throbbing again as the bookmark bubble can't be up at // No need to start throbbing again as the bookmark bubble can't be up at
...@@ -1553,7 +1606,8 @@ void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event, ...@@ -1553,7 +1606,8 @@ void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event,
} else if (!GetBookmarkButtonCount()) { } else if (!GetBookmarkButtonCount()) {
// No bookmarks, accept the drop. // No bookmarks, accept the drop.
location->index = 0; location->index = 0;
int ops = data.GetFirstNode(model_, profile->GetPath()) ? const BookmarkNode* node = data.GetFirstNode(model_, profile->GetPath());
int ops = node && client_->CanBeEditedByUser(node) ?
ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_MOVE :
ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK;
location->operation = chrome::GetPreferredBookmarkDropOperation( location->operation = chrome::GetPreferredBookmarkDropOperation(
...@@ -1659,6 +1713,8 @@ void BookmarkBarView::StartThrobbing(const BookmarkNode* node, ...@@ -1659,6 +1713,8 @@ void BookmarkBarView::StartThrobbing(const BookmarkNode* node,
} else if (!overflow_only) { } else if (!overflow_only) {
throbbing_view_ = static_cast<CustomButton*>(child_at(index)); throbbing_view_ = static_cast<CustomButton*>(child_at(index));
} }
} else if (client_->IsDescendantOfManagedNode(node)) {
throbbing_view_ = managed_bookmarks_button_;
} else if (!overflow_only) { } else if (!overflow_only) {
throbbing_view_ = other_bookmarked_button_; throbbing_view_ = other_bookmarked_button_;
} }
...@@ -1689,6 +1745,8 @@ views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( ...@@ -1689,6 +1745,8 @@ views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove(
} }
return static_cast<CustomButton*>(child_at(old_index_on_bb)); return static_cast<CustomButton*>(child_at(old_index_on_bb));
} }
if (client_->IsDescendantOfManagedNode(parent))
return managed_bookmarks_button_;
// Node wasn't on the bookmark bar, use the other bookmark button. // Node wasn't on the bookmark bar, use the other bookmark button.
return other_bookmarked_button_; return other_bookmarked_button_;
} }
...@@ -1702,19 +1760,30 @@ void BookmarkBarView::UpdateColors() { ...@@ -1702,19 +1760,30 @@ void BookmarkBarView::UpdateColors() {
theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
for (int i = 0; i < GetBookmarkButtonCount(); ++i) for (int i = 0; i < GetBookmarkButtonCount(); ++i)
GetBookmarkButton(i)->SetEnabledColor(text_color); GetBookmarkButton(i)->SetEnabledColor(text_color);
other_bookmarked_button()->SetEnabledColor(text_color); other_bookmarked_button_->SetEnabledColor(text_color);
managed_bookmarks_button_->SetEnabledColor(text_color);
if (apps_page_shortcut_->visible()) if (apps_page_shortcut_->visible())
apps_page_shortcut_->SetEnabledColor(text_color); apps_page_shortcut_->SetEnabledColor(text_color);
} }
void BookmarkBarView::UpdateOtherBookmarksVisibility() { void BookmarkBarView::UpdateButtonsVisibility() {
bool has_other_children = !model_->other_node()->empty(); bool has_other_children = !model_->other_node()->empty();
if (has_other_children == other_bookmarked_button_->visible()) bool update_other = has_other_children != other_bookmarked_button_->visible();
return; if (update_other) {
other_bookmarked_button_->SetVisible(has_other_children); other_bookmarked_button_->SetVisible(has_other_children);
UpdateBookmarksSeparatorVisibility(); UpdateBookmarksSeparatorVisibility();
Layout(); }
SchedulePaint();
bool has_managed_children = !client_->managed_node()->empty();
bool update_managed =
has_managed_children != managed_bookmarks_button_->visible();
if (update_managed)
managed_bookmarks_button_->SetVisible(has_managed_children);
if (update_other || update_managed) {
Layout();
SchedulePaint();
}
} }
void BookmarkBarView::UpdateBookmarksSeparatorVisibility() { void BookmarkBarView::UpdateBookmarksSeparatorVisibility() {
...@@ -1763,7 +1832,7 @@ void BookmarkBarView::LayoutItems() { ...@@ -1763,7 +1832,7 @@ void BookmarkBarView::LayoutItems() {
max_x -= other_bookmarked_pref.width() + kButtonPadding; max_x -= other_bookmarked_pref.width() + kButtonPadding;
// Next, layout out the buttons. Any buttons that are placed beyond the // Next, layout out the buttons. Any buttons that are placed beyond the
// visible region and made invisible. // visible region are made invisible.
// Start with the apps page shortcut button. // Start with the apps page shortcut button.
if (apps_page_shortcut_->visible()) { if (apps_page_shortcut_->visible()) {
...@@ -1772,6 +1841,15 @@ void BookmarkBarView::LayoutItems() { ...@@ -1772,6 +1841,15 @@ void BookmarkBarView::LayoutItems() {
x += apps_page_shortcut_pref.width() + kButtonPadding; x += apps_page_shortcut_pref.width() + kButtonPadding;
} }
// 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();
managed_bookmarks_button_->SetBounds(x, y, managed_bookmarks_pref.width(),
height);
x += managed_bookmarks_pref.width() + kButtonPadding;
}
// Then go through the bookmark buttons. // Then go through the bookmark buttons.
if (GetBookmarkButtonCount() == 0 && model_ && model_->loaded()) { if (GetBookmarkButtonCount() == 0 && model_ && model_->loaded()) {
gfx::Size pref = instructions_->GetPreferredSize(); gfx::Size pref = instructions_->GetPreferredSize();
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
class BookmarkContextMenu; class BookmarkContextMenu;
class Browser; class Browser;
class BrowserView; class BrowserView;
class ChromeBookmarkClient;
class Profile; class Profile;
namespace content { namespace content {
...@@ -301,6 +302,9 @@ class BookmarkBarView : public DetachableToolbarView, ...@@ -301,6 +302,9 @@ class BookmarkBarView : public DetachableToolbarView,
// Creates the button showing the other bookmarked items. // Creates the button showing the other bookmarked items.
views::MenuButton* CreateOtherBookmarkedButton(); views::MenuButton* CreateOtherBookmarkedButton();
// Creates the button showing the managed bookmarks items.
views::MenuButton* CreateManagedBookmarksButton();
// Creates the button used when not all bookmark buttons fit. // Creates the button used when not all bookmark buttons fit.
views::MenuButton* CreateOverflowButton(); views::MenuButton* CreateOverflowButton();
...@@ -362,9 +366,9 @@ class BookmarkBarView : public DetachableToolbarView, ...@@ -362,9 +366,9 @@ class BookmarkBarView : public DetachableToolbarView,
// Updates the colors for all the child objects in the bookmarks bar. // Updates the colors for all the child objects in the bookmarks bar.
void UpdateColors(); void UpdateColors();
// Updates the visibility of |other_bookmarked_button_|. Also shows or hide // Updates the visibility of |other_bookmarked_button_| and
// the separator if required. // |managed_bookmarks_button_|. Also shows or hides the separator if required.
void UpdateOtherBookmarksVisibility(); void UpdateButtonsVisibility();
// Updates the visibility of |bookmarks_separator_view_|. // Updates the visibility of |bookmarks_separator_view_|.
void UpdateBookmarksSeparatorVisibility(); void UpdateBookmarksSeparatorVisibility();
...@@ -385,6 +389,9 @@ class BookmarkBarView : public DetachableToolbarView, ...@@ -385,6 +389,9 @@ class BookmarkBarView : public DetachableToolbarView,
// shown. This is owned by the Profile. // shown. This is owned by the Profile.
BookmarkModel* model_; BookmarkModel* model_;
// The ChromeBookmarkClient that owns the |model_|.
ChromeBookmarkClient* client_;
// Used to manage showing a Menu, either for the most recently bookmarked // Used to manage showing a Menu, either for the most recently bookmarked
// entries, or for the starred folder. // entries, or for the starred folder.
BookmarkMenuController* bookmark_menu_; BookmarkMenuController* bookmark_menu_;
...@@ -401,6 +408,9 @@ class BookmarkBarView : public DetachableToolbarView, ...@@ -401,6 +408,9 @@ class BookmarkBarView : public DetachableToolbarView,
// Shows the other bookmark entries. // Shows the other bookmark entries.
views::MenuButton* other_bookmarked_button_; views::MenuButton* other_bookmarked_button_;
// Shows the managed bookmarks entries.
views::MenuButton* managed_bookmarks_button_;
// Shows the Apps page shortcut. // Shows the Apps page shortcut.
views::TextButton* apps_page_shortcut_; views::TextButton* apps_page_shortcut_;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_node_data.h" #include "components/bookmarks/browser/bookmark_node_data.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/user_prefs/user_prefs.h" #include "components/user_prefs/user_prefs.h"
#include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/dragdrop/os_exchange_data.h"
...@@ -27,7 +28,7 @@ void DragBookmarks(Profile* profile, ...@@ -27,7 +28,7 @@ void DragBookmarks(Profile* profile,
ui::DragDropTypes::DragEventSource source) { ui::DragDropTypes::DragEventSource source) {
DCHECK(!nodes.empty()); DCHECK(!nodes.empty());
// Set up our OLE machinery // Set up our OLE machinery.
ui::OSExchangeData data; ui::OSExchangeData data;
BookmarkNodeData drag_data(nodes); BookmarkNodeData drag_data(nodes);
drag_data.Write(profile->GetPath(), &data); drag_data.Write(profile->GetPath(), &data);
...@@ -36,9 +37,11 @@ void DragBookmarks(Profile* profile, ...@@ -36,9 +37,11 @@ void DragBookmarks(Profile* profile,
bool was_nested = base::MessageLoop::current()->IsNested(); bool was_nested = base::MessageLoop::current()->IsNested();
base::MessageLoop::current()->SetNestableTasksAllowed(true); base::MessageLoop::current()->SetNestableTasksAllowed(true);
int operation = ui::DragDropTypes::DRAG_COPY | int operation = ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK;
ui::DragDropTypes::DRAG_MOVE | BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
ui::DragDropTypes::DRAG_LINK; if (bookmark_utils::CanAllBeEditedByUser(model->client(), nodes))
operation |= ui::DragDropTypes::DRAG_MOVE;
views::Widget* widget = views::Widget::GetWidgetForNativeView(view); views::Widget* widget = views::Widget::GetWidgetForNativeView(view);
if (widget) { if (widget) {
...@@ -55,10 +58,14 @@ void DragBookmarks(Profile* profile, ...@@ -55,10 +58,14 @@ void DragBookmarks(Profile* profile,
int GetBookmarkDragOperation(content::BrowserContext* browser_context, int GetBookmarkDragOperation(content::BrowserContext* browser_context,
const BookmarkNode* node) { const BookmarkNode* node) {
PrefService* prefs = user_prefs::UserPrefs::Get(browser_context); PrefService* prefs = user_prefs::UserPrefs::Get(browser_context);
Profile* profile = Profile::FromBrowserContext(browser_context);
BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
int move = ui::DragDropTypes::DRAG_MOVE; int move = ui::DragDropTypes::DRAG_MOVE;
if (!prefs->GetBoolean(prefs::kEditBookmarksEnabled)) if (!prefs->GetBoolean(prefs::kEditBookmarksEnabled) ||
!model->client()->CanBeEditedByUser(node)) {
move = ui::DragDropTypes::DRAG_NONE; move = ui::DragDropTypes::DRAG_NONE;
}
if (node->is_url()) if (node->is_url())
return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK | move; return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK | move;
return ui::DragDropTypes::DRAG_COPY | move; return ui::DragDropTypes::DRAG_COPY | move;
...@@ -91,10 +98,21 @@ int GetBookmarkDropOperation(Profile* profile, ...@@ -91,10 +98,21 @@ int GetBookmarkDropOperation(Profile* profile,
if (!IsValidBookmarkDropLocation(profile, data, parent, index)) if (!IsValidBookmarkDropLocation(profile, data, parent, index))
return ui::DragDropTypes::DRAG_NONE; return ui::DragDropTypes::DRAG_NONE;
if (data.GetFirstNode(BookmarkModelFactory::GetForProfile(profile), BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
profile_path)) if (!model->client()->CanBeEditedByUser(parent))
// User is dragging from this profile: move. return ui::DragDropTypes::DRAG_NONE;
const BookmarkNode* dragged_node =
data.GetFirstNode(model, profile->GetPath());
if (dragged_node) {
// User is dragging from this profile.
if (!model->client()->CanBeEditedByUser(dragged_node)) {
// Do a copy instead of a move when dragging bookmarks that the user can't
// modify.
return ui::DragDropTypes::DRAG_COPY;
}
return ui::DragDropTypes::DRAG_MOVE; return ui::DragDropTypes::DRAG_MOVE;
}
// User is dragging from another app, copy. // User is dragging from another app, copy.
return GetPreferredBookmarkDropOperation(event.source_operations(), return GetPreferredBookmarkDropOperation(event.source_operations(),
...@@ -113,10 +131,13 @@ bool IsValidBookmarkDropLocation(Profile* profile, ...@@ -113,10 +131,13 @@ bool IsValidBookmarkDropLocation(Profile* profile,
if (!data.is_valid()) if (!data.is_valid())
return false; return false;
BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
if (!model->client()->CanBeEditedByUser(drop_parent))
return false;
const base::FilePath& profile_path = profile->GetPath(); const base::FilePath& profile_path = profile->GetPath();
if (data.IsFromProfilePath(profile_path)) { if (data.IsFromProfilePath(profile_path)) {
std::vector<const BookmarkNode*> nodes = data.GetNodes( std::vector<const BookmarkNode*> nodes = data.GetNodes(model, profile_path);
BookmarkModelFactory::GetForProfile(profile), profile_path);
for (size_t i = 0; i < nodes.size(); ++i) { for (size_t i = 0; i < nodes.size(); ++i) {
// Don't allow the drop if the user is attempting to drop on one of the // Don't allow the drop if the user is attempting to drop on one of the
// nodes being dragged. // nodes being dragged.
...@@ -132,7 +153,7 @@ bool IsValidBookmarkDropLocation(Profile* profile, ...@@ -132,7 +153,7 @@ bool IsValidBookmarkDropLocation(Profile* profile,
} }
return true; return true;
} }
// From the same profile, always accept. // From another profile, always accept.
return true; return true;
} }
......
...@@ -72,9 +72,12 @@ BookmarkEditorView::BookmarkEditorView( ...@@ -72,9 +72,12 @@ BookmarkEditorView::BookmarkEditorView(
title_tf_(NULL), title_tf_(NULL),
parent_(parent), parent_(parent),
details_(details), details_(details),
bb_model_(BookmarkModelFactory::GetForProfile(profile)),
running_menu_for_root_(false), running_menu_for_root_(false),
show_tree_(configuration == SHOW_TREE) { show_tree_(configuration == SHOW_TREE) {
DCHECK(profile); DCHECK(profile);
DCHECK(bb_model_);
DCHECK(bb_model_->client()->CanBeEditedByUser(parent));
Init(); Init();
} }
...@@ -262,8 +265,6 @@ void BookmarkEditorView::ShowContextMenuForView( ...@@ -262,8 +265,6 @@ void BookmarkEditorView::ShowContextMenuForView(
} }
void BookmarkEditorView::Init() { void BookmarkEditorView::Init() {
bb_model_ = BookmarkModelFactory::GetForProfile(profile_);
DCHECK(bb_model_);
bb_model_->AddObserver(this); bb_model_->AddObserver(this);
title_label_ = new views::Label( title_label_ = new views::Label(
...@@ -507,7 +508,8 @@ void BookmarkEditorView::CreateNodes(const BookmarkNode* bb_node, ...@@ -507,7 +508,8 @@ void BookmarkEditorView::CreateNodes(const BookmarkNode* bb_node,
BookmarkEditorView::EditorNode* b_node) { BookmarkEditorView::EditorNode* b_node) {
for (int i = 0; i < bb_node->child_count(); ++i) { for (int i = 0; i < bb_node->child_count(); ++i) {
const BookmarkNode* child_bb_node = bb_node->GetChild(i); const BookmarkNode* child_bb_node = bb_node->GetChild(i);
if (child_bb_node->IsVisible() && child_bb_node->is_folder()) { if (child_bb_node->IsVisible() && child_bb_node->is_folder() &&
bb_model_->client()->CanBeEditedByUser(child_bb_node)) {
EditorNode* new_b_node = new EditorNode(child_bb_node->GetTitle(), EditorNode* new_b_node = new EditorNode(child_bb_node->GetTitle(),
child_bb_node->id()); child_bb_node->id());
b_node->Add(new_b_node, b_node->child_count()); b_node->Add(new_b_node, b_node->child_count());
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/chrome_bookmark_client.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h"
#include "chrome/browser/ui/bookmarks/bookmark_utils.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
...@@ -71,12 +72,23 @@ void BookmarkMenuDelegate::Init(views::MenuDelegate* real_delegate, ...@@ -71,12 +72,23 @@ void BookmarkMenuDelegate::Init(views::MenuDelegate* real_delegate,
location_ = location; location_ = location;
if (parent) { if (parent) {
parent_menu_item_ = parent; parent_menu_item_ = parent;
// Add a separator if there are existing items in the menu, and if the
// current node has children. If |node| is the bookmark bar then the
// managed node is shown as its first child, if it's not empty.
BookmarkModel* model = GetBookmarkModel();
ChromeBookmarkClient* client = GetChromeBookmarkClient();
bool show_managed = show_options == SHOW_PERMANENT_FOLDERS &&
node == model->bookmark_bar_node() &&
!client->managed_node()->empty();
bool has_children =
(start_child_index < node->child_count()) || show_managed;
int initial_count = parent->GetSubmenu() ? int initial_count = parent->GetSubmenu() ?
parent->GetSubmenu()->GetMenuItemCount() : 0; parent->GetSubmenu()->GetMenuItemCount() : 0;
if ((start_child_index < node->child_count()) && if (has_children && initial_count > 0)
(initial_count > 0)) {
parent->AppendSeparator(); parent->AppendSeparator();
} if (show_managed)
BuildMenuForManagedNode(parent, &next_menu_id_);
BuildMenu(node, start_child_index, parent, &next_menu_id_); BuildMenu(node, start_child_index, parent, &next_menu_id_);
if (show_options == SHOW_PERMANENT_FOLDERS) if (show_options == SHOW_PERMANENT_FOLDERS)
BuildMenusForPermanentNodes(parent, &next_menu_id_); BuildMenusForPermanentNodes(parent, &next_menu_id_);
...@@ -95,6 +107,10 @@ BookmarkModel* BookmarkMenuDelegate::GetBookmarkModel() { ...@@ -95,6 +107,10 @@ BookmarkModel* BookmarkMenuDelegate::GetBookmarkModel() {
return BookmarkModelFactory::GetForProfile(profile_); return BookmarkModelFactory::GetForProfile(profile_);
} }
ChromeBookmarkClient* BookmarkMenuDelegate::GetChromeBookmarkClient() {
return BookmarkModelFactory::GetChromeBookmarkClientForProfile(profile_);
}
void BookmarkMenuDelegate::SetActiveMenu(const BookmarkNode* node, void BookmarkMenuDelegate::SetActiveMenu(const BookmarkNode* node,
int start_index) { int start_index) {
DCHECK(!parent_menu_item_); DCHECK(!parent_menu_item_);
...@@ -270,8 +286,9 @@ int BookmarkMenuDelegate::OnPerformDrop( ...@@ -270,8 +286,9 @@ int BookmarkMenuDelegate::OnPerformDrop(
break; break;
} }
bool copy = event.source_operations() == ui::DragDropTypes::DRAG_COPY;
return chrome::DropBookmarks(profile_, drop_data_, return chrome::DropBookmarks(profile_, drop_data_,
drop_parent, index_to_drop_at); drop_parent, index_to_drop_at, copy);
} }
bool BookmarkMenuDelegate::ShowContextMenu(MenuItemView* source, bool BookmarkMenuDelegate::ShowContextMenu(MenuItemView* source,
...@@ -409,8 +426,11 @@ MenuItemView* BookmarkMenuDelegate::CreateMenu(const BookmarkNode* parent, ...@@ -409,8 +426,11 @@ MenuItemView* BookmarkMenuDelegate::CreateMenu(const BookmarkNode* parent,
menu->SetCommand(next_menu_id_++); menu->SetCommand(next_menu_id_++);
menu_id_to_node_map_[menu->GetCommand()] = parent; menu_id_to_node_map_[menu->GetCommand()] = parent;
menu->set_has_icons(true); menu->set_has_icons(true);
bool show_permanent = show_options == SHOW_PERMANENT_FOLDERS;
if (show_permanent && parent == GetBookmarkModel()->bookmark_bar_node())
BuildMenuForManagedNode(menu, &next_menu_id_);
BuildMenu(parent, start_child_index, menu, &next_menu_id_); BuildMenu(parent, start_child_index, menu, &next_menu_id_);
if (show_options == SHOW_PERMANENT_FOLDERS) if (show_permanent)
BuildMenusForPermanentNodes(menu, &next_menu_id_); BuildMenusForPermanentNodes(menu, &next_menu_id_);
return menu; return menu;
} }
...@@ -453,6 +473,17 @@ void BookmarkMenuDelegate::BuildMenuForPermanentNode( ...@@ -453,6 +473,17 @@ void BookmarkMenuDelegate::BuildMenuForPermanentNode(
menu_id_to_node_map_[id] = node; menu_id_to_node_map_[id] = node;
} }
void BookmarkMenuDelegate::BuildMenuForManagedNode(
MenuItemView* menu,
int* next_menu_id) {
// Don't add a separator for this menu.
bool added_separator = true;
const BookmarkNode* node = GetChromeBookmarkClient()->managed_node();
// TODO(joaodasilva): use the "managed bookmark folder" icon here.
// http://crbug.com/49598
BuildMenuForPermanentNode(node, menu, next_menu_id, &added_separator);
}
void BookmarkMenuDelegate::BuildMenu(const BookmarkNode* parent, void BookmarkMenuDelegate::BuildMenu(const BookmarkNode* parent,
int start_child_index, int start_child_index,
MenuItemView* menu, MenuItemView* menu,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
class BookmarkNode; class BookmarkNode;
class Browser; class Browser;
class ChromeBookmarkClient;
class Profile; class Profile;
namespace content { namespace content {
...@@ -76,6 +77,7 @@ class BookmarkMenuDelegate : public BaseBookmarkModelObserver, ...@@ -76,6 +77,7 @@ class BookmarkMenuDelegate : public BaseBookmarkModelObserver,
void SetActiveMenu(const BookmarkNode* node, int start_index); void SetActiveMenu(const BookmarkNode* node, int start_index);
BookmarkModel* GetBookmarkModel(); BookmarkModel* GetBookmarkModel();
ChromeBookmarkClient* GetChromeBookmarkClient();
// Returns the menu. // Returns the menu.
views::MenuItemView* menu() { return menu_; } views::MenuItemView* menu() { return menu_; }
...@@ -152,6 +154,9 @@ class BookmarkMenuDelegate : public BaseBookmarkModelObserver, ...@@ -152,6 +154,9 @@ class BookmarkMenuDelegate : public BaseBookmarkModelObserver,
int* next_menu_id, int* next_menu_id,
bool* added_separator); bool* added_separator);
void BuildMenuForManagedNode(views::MenuItemView* menu,
int* next_menu_id);
// Creates an entry in menu for each child node of |parent| starting at // Creates an entry in menu for each child node of |parent| starting at
// |start_child_index|. // |start_child_index|.
void BuildMenu(const BookmarkNode* parent, void BuildMenu(const BookmarkNode* parent,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment