summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/bookmark_bar_view.cc
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-29 23:38:06 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-29 23:38:06 +0000
commit7f856bee73ffdccdbbbbbab4cb79185290d38359 (patch)
treea837328e08a113abdc70b2fc0ae2f2a4a3f804eb /chrome/browser/views/bookmark_bar_view.cc
parent281fe14063dd8fb81cea102f5abb7b82f407c3d1 (diff)
downloadchromium_src-7f856bee73ffdccdbbbbbab4cb79185290d38359.zip
chromium_src-7f856bee73ffdccdbbbbbab4cb79185290d38359.tar.gz
chromium_src-7f856bee73ffdccdbbbbbab4cb79185290d38359.tar.bz2
First cut at the bookmark manager. There are still a fair number of
rough edges, but I'm at a good point where I want to land what I have. Here's what is left: . Flicker on show, likely the result of restoring window placement. . tree flickers when dragging splitter. . table/tree need to autoscroll when drop cursor held at bottom of view. . prompts for deleting. . When you move an item the table snaps to the top, this is because I'm sending out model changed. need a better notification. . Operations in menu to add need to change selection. . Remember split location. I would have preferred to split this up into a couple of reviews, but everything is intertwined now. Sorry. BUG=674 TEST=don't test the bookmark manager yet, but make sure bookmark bar still works. Review URL: http://codereview.chromium.org/8197 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4191 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/bookmark_bar_view.cc')
-rw-r--r--chrome/browser/views/bookmark_bar_view.cc87
1 files changed, 51 insertions, 36 deletions
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc
index 70be891..8c08453 100644
--- a/chrome/browser/views/bookmark_bar_view.cc
+++ b/chrome/browser/views/bookmark_bar_view.cc
@@ -9,8 +9,8 @@
#include "base/base_drag_source.h"
#include "base/gfx/skia_utils.h"
#include "chrome/app/theme/theme_resources.h"
-#include "chrome/browser/bookmark_bar_context_menu_controller.h"
-#include "chrome/browser/bookmarks/bookmark_drag_utils.h"
+#include "chrome/browser/bookmarks/bookmark_context_menu.h"
+#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_process.h"
@@ -395,8 +395,6 @@ class MenuRunner : public views::MenuDelegate,
}
virtual void ModelChanged() {
- if (context_menu_.get())
- context_menu_->ModelChanged();
menu_.Cancel();
}
@@ -531,8 +529,16 @@ class MenuRunner : public views::MenuDelegate,
int y,
bool is_mouse_gesture) {
DCHECK(menu_id_to_node_map_.find(id) != menu_id_to_node_map_.end());
+ std::vector<BookmarkNode*> nodes;
+ nodes.push_back(menu_id_to_node_map_[id]);
context_menu_.reset(
- new BookmarkBarContextMenuController(view_, menu_id_to_node_map_[id]));
+ new BookmarkContextMenu(view_->GetContainer()->GetHWND(),
+ view_->GetProfile(),
+ view_->browser(),
+ view_->GetPageNavigator(),
+ nodes[0]->GetParent(),
+ nodes,
+ BookmarkContextMenu::BOOKMARK_BAR));
context_menu_->RunMenuAt(x, y);
context_menu_.reset(NULL);
return true;
@@ -581,7 +587,7 @@ class MenuRunner : public views::MenuDelegate,
// Data for the drop.
BookmarkDragData drop_data_;
- scoped_ptr<BookmarkBarContextMenuController> context_menu_;
+ scoped_ptr<BookmarkContextMenu> context_menu_;
DISALLOW_COPY_AND_ASSIGN(MenuRunner);
};
@@ -646,6 +652,22 @@ static const SkBitmap& GetGroupIcon() {
}
// static
+void BookmarkBarView::ToggleWhenVisible(Profile* profile) {
+ PrefService* prefs = profile->GetPrefs();
+ const bool always_show = !prefs->GetBoolean(prefs::kShowBookmarkBar);
+
+ // The user changed when the bookmark bar is shown, update the preferences.
+ prefs->SetBoolean(prefs::kShowBookmarkBar, always_show);
+ prefs->ScheduleSavePersistentPrefs(g_browser_process->file_thread());
+
+ // And notify the notification service.
+ Source<Profile> source(profile);
+ NotificationService::current()->Notify(
+ NOTIFY_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, source,
+ NotificationService::NoDetails());
+}
+
+// static
void BookmarkBarView::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kShowBookmarkBar, false);
}
@@ -1079,24 +1101,6 @@ int BookmarkBarView::OnPerformDrop(const DropTargetEvent& event) {
return PerformDropImpl(data, parent_node, index);
}
-void BookmarkBarView::ToggleWhenVisible() {
- PrefService* prefs = profile_->GetPrefs();
- const bool always_show = !prefs->GetBoolean(prefs::kShowBookmarkBar);
-
- // The user changed when the bookmark bar is shown, update the preferences.
- prefs->SetBoolean(prefs::kShowBookmarkBar, always_show);
- prefs->ScheduleSavePersistentPrefs(g_browser_process->file_thread());
-
- // And notify the notification service.
- Source<Profile> source(profile_);
- NotificationService::current()->Notify(
- NOTIFY_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, source,
- NotificationService::NoDetails());
-
- // May need to redraw the bar with a new style.
- SchedulePaint();
-}
-
bool BookmarkBarView::IsAlwaysShown() {
return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
}
@@ -1422,8 +1426,8 @@ void BookmarkBarView::ButtonPressed(views::BaseButton* sender) {
event_utils::DispositionFromEventFlags(sender->mouse_event_flags()),
PageTransition::AUTO_BOOKMARK);
} else {
- BookmarkBarContextMenuController::OpenAll(
- GetContainer()->GetHWND(), GetPageNavigator(), node,
+ bookmark_utils::OpenAll(
+ GetContainer()->GetHWND(), profile_, GetPageNavigator(), node,
event_utils::DispositionFromEventFlags(sender->mouse_event_flags()));
}
UserMetrics::RecordAction(L"ClickedBookmarkBarURLButton", profile_);
@@ -1438,18 +1442,30 @@ void BookmarkBarView::ShowContextMenu(View* source,
return;
}
- BookmarkNode* node = model_->GetBookmarkBarNode();
+ BookmarkNode* parent = NULL;
+ std::vector<BookmarkNode*> nodes;
if (source == other_bookmarked_button_) {
- node = model_->other_node();
+ parent = model_->other_node();
+ // Do this so the user can open all bookmarks. BookmarkContextMenu makes
+ // sure the user can edit/delete the node in this case.
+ nodes.push_back(parent);
} else if (source != this) {
// User clicked on one of the bookmark buttons, find which one they
// clicked on.
int bookmark_button_index = GetChildIndex(source);
DCHECK(bookmark_button_index != -1 &&
bookmark_button_index < GetBookmarkButtonCount());
- node = model_->GetBookmarkBarNode()->GetChild(bookmark_button_index);
+ BookmarkNode* node =
+ model_->GetBookmarkBarNode()->GetChild(bookmark_button_index);
+ nodes.push_back(node);
+ parent = node->GetParent();
+ } else {
+ parent = model_->GetBookmarkBarNode();
}
- BookmarkBarContextMenuController controller(this, node);
+ BookmarkContextMenu controller(GetContainer()->GetHWND(),
+ GetProfile(), browser(), GetPageNavigator(),
+ parent, nodes,
+ BookmarkContextMenu::BOOKMARK_BAR);
controller.RunMenuAt(x, y);
}
@@ -1492,7 +1508,7 @@ bool BookmarkBarView::IsItemChecked(int id) const {
}
void BookmarkBarView::ExecuteCommand(int id) {
- ToggleWhenVisible();
+ ToggleWhenVisible(profile_);
}
void BookmarkBarView::Observe(NotificationType type,
@@ -1652,7 +1668,7 @@ int BookmarkBarView::CalculateDropOperation(const DropTargetEvent& event,
int ops = data.GetFirstNode(profile_)
? DragDropTypes::DRAG_MOVE
: DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK;
- return bookmark_drag_utils::PreferredDropOperation(event, ops);
+ return bookmark_utils::PreferredDropOperation(event, ops);
}
for (int i = 0; i < GetBookmarkButtonCount() &&
@@ -1733,7 +1749,7 @@ int BookmarkBarView::CalculateDropOperation(const DropTargetEvent& event,
// Currently only accept one dragged node at a time.
return DragDropTypes::DRAG_NONE;
- if (!bookmark_drag_utils::IsValidDropLocation(profile_, data, parent, index))
+ if (!bookmark_utils::IsValidDropLocation(profile_, data, parent, index))
return DragDropTypes::DRAG_NONE;
if (data.GetFirstNode(profile_)) {
@@ -1741,7 +1757,7 @@ int BookmarkBarView::CalculateDropOperation(const DropTargetEvent& event,
return DragDropTypes::DRAG_MOVE;
} else {
// User is dragging from another app, copy.
- return bookmark_drag_utils::PreferredDropOperation(
+ return bookmark_utils::PreferredDropOperation(
event, DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK);
}
}
@@ -1767,8 +1783,7 @@ int BookmarkBarView::PerformDropImpl(const BookmarkDragData& data,
return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK;
} else {
// Dropping a group from different profile. Always accept.
- bookmark_drag_utils::CloneDragData(model_, data.elements, parent_node,
- index);
+ bookmark_utils::CloneDragData(model_, data.elements, parent_node, index);
return DragDropTypes::DRAG_COPY;
}
}