summaryrefslogtreecommitdiffstats
path: root/chrome/browser/bookmarks
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-20 02:06:16 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-20 02:06:16 +0000
commitced90ae1159e8967837cd13b9155956467a811f9 (patch)
treeb052ff281b583fdcc12f6bea883f83db663ae92f /chrome/browser/bookmarks
parentddf796cffe2f905a36764bc2e46cc8325a560c51 (diff)
downloadchromium_src-ced90ae1159e8967837cd13b9155956467a811f9.zip
chromium_src-ced90ae1159e8967837cd13b9155956467a811f9.tar.gz
chromium_src-ced90ae1159e8967837cd13b9155956467a811f9.tar.bz2
Bookmark Manager Drag and Drop backend.
This adds the following methods to chrome.experimental.bookmarkManager: startDrag(idList) drop(parentId, opt_index) as well as the following events: onDragEnter(function(BookmarkDragData)) onDragLeave(function(BookmarkDragData)) onDrop(function(BookmarkDragData)) BUG=32194 TEST=None Review URL: http://codereview.chromium.org/596105 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39540 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks')
-rw-r--r--chrome/browser/bookmarks/bookmark_drag_data.cc5
-rw-r--r--chrome/browser/bookmarks/bookmark_drag_data.h3
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.cc48
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.h5
4 files changed, 57 insertions, 4 deletions
diff --git a/chrome/browser/bookmarks/bookmark_drag_data.cc b/chrome/browser/bookmarks/bookmark_drag_data.cc
index 1b4b7de..5a5340b 100644
--- a/chrome/browser/bookmarks/bookmark_drag_data.cc
+++ b/chrome/browser/bookmarks/bookmark_drag_data.cc
@@ -261,6 +261,11 @@ const BookmarkNode* BookmarkDragData::GetFirstNode(Profile* profile) const {
return nodes.size() == 1 ? nodes[0] : NULL;
}
+void BookmarkDragData::Clear() {
+ profile_path_.clear();
+ elements.clear();
+}
+
bool BookmarkDragData::IsFromProfile(Profile* profile) const {
// An empty path means the data is not associated with any profile.
return (!profile_path_.empty() &&
diff --git a/chrome/browser/bookmarks/bookmark_drag_data.h b/chrome/browser/bookmarks/bookmark_drag_data.h
index 486d144..9d033ae 100644
--- a/chrome/browser/bookmarks/bookmark_drag_data.h
+++ b/chrome/browser/bookmarks/bookmark_drag_data.h
@@ -124,6 +124,9 @@ struct BookmarkDragData {
// Number of elements.
size_t size() const { return elements.size(); }
+ // Clears the data.
+ void Clear();
+
// Returns true if this data is from the specified profile.
bool IsFromProfile(Profile* profile) const;
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
index fe4ae6e..4aa14eb 100644
--- a/chrome/browser/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_utils.cc
@@ -32,6 +32,13 @@
#include "net/base/net_util.h"
#include "views/event.h"
+#if defined(TOOLKIT_VIEWS)
+#include "app/os_exchange_data.h"
+#include "views/drag_utils.h"
+#include "views/widget/root_view.h"
+#include "views/widget/widget.h"
+#endif
+
using base::Time;
namespace {
@@ -245,11 +252,14 @@ int PerformBookmarkDrop(Profile* profile,
const BookmarkDragData& data,
const BookmarkNode* parent_node,
int index) {
- const BookmarkNode* dragged_node = data.GetFirstNode(profile);
+ const std::vector<const BookmarkNode*> dragged_nodes = data.GetNodes(profile);
BookmarkModel* model = profile->GetBookmarkModel();
- if (dragged_node) {
- // Drag from same profile, do a move.
- model->Move(dragged_node, parent_node, index);
+ if (!dragged_nodes.empty()) {
+ // Drag from same profile. Move nodes.
+ for (size_t i = 0; i < dragged_nodes.size(); ++i) {
+ model->Move(dragged_nodes[i], parent_node, index);
+ index = parent_node->IndexOfChild(dragged_nodes[i]) + 1;
+ }
return DragDropTypes::DRAG_MOVE;
} else if (data.has_single_url()) {
// New URL, add it at the specified location.
@@ -314,6 +324,36 @@ void CloneDragData(BookmarkModel* model,
CloneDragDataImpl(model, elements[i], parent, index_to_add_at + i);
}
+
+// Bookmark dragging
+void DragBookmarks(Profile* profile,
+ const std::vector<const BookmarkNode*>& nodes,
+ gfx::NativeView view) {
+ DCHECK(!nodes.empty());
+
+#if defined(TOOLKIT_VIEWS)
+ // Set up our OLE machinery
+ OSExchangeData data;
+ BookmarkDragData drag_data(nodes);
+ drag_data.Write(profile, &data);
+
+ views::RootView* root_view = views::Widget::GetWidgetFromNativeView(view)->GetRootView();
+
+ // Allow nested message loop so we get DnD events as we drag this around.
+ bool was_nested = MessageLoop::current()->IsNested();
+ MessageLoop::current()->SetNestableTasksAllowed(true);
+
+ root_view->StartDragForViewFromMouseEvent(NULL, data,
+ DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_MOVE |
+ DragDropTypes::DRAG_LINK);
+
+ MessageLoop::current()->SetNestableTasksAllowed(was_nested);
+#else
+ // TODO(arv): Implement for GTK and Cocoa.
+ NOTIMPLEMENTED();
+#endif
+}
+
void OpenAll(gfx::NativeWindow parent,
Profile* profile,
PageNavigator* navigator,
diff --git a/chrome/browser/bookmarks/bookmark_utils.h b/chrome/browser/bookmarks/bookmark_utils.h
index 0bea122..b63c848 100644
--- a/chrome/browser/bookmarks/bookmark_utils.h
+++ b/chrome/browser/bookmarks/bookmark_utils.h
@@ -71,6 +71,11 @@ void CloneDragData(BookmarkModel* model,
const BookmarkNode* parent,
int index_to_add_at);
+// Begins dragging a group of bookmarks.
+void DragBookmarks(Profile* profile,
+ const std::vector<const BookmarkNode*>& nodes,
+ gfx::NativeView view);
+
// Recursively opens all bookmarks. |initial_disposition| dictates how the
// first URL is opened, all subsequent URLs are opened as background tabs.
// |navigator| is used to open the URLs. If |navigator| is NULL the last