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

Side by Side Diff: chrome/browser/bookmarks/bookmark_utils.cc

Issue 596105: Bookmark Manager Drag and Drop backend.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/bookmarks/bookmark_utils.h" 5 #include "chrome/browser/bookmarks/bookmark_utils.h"
6 6
7 #include "app/clipboard/clipboard.h" 7 #include "app/clipboard/clipboard.h"
8 #include "app/drag_drop_types.h" 8 #include "app/drag_drop_types.h"
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/tree_node_iterator.h" 10 #include "app/tree_node_iterator.h"
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/tab_contents/page_navigator.h" 25 #include "chrome/browser/tab_contents/page_navigator.h"
26 #include "chrome/browser/tab_contents/tab_contents.h" 26 #include "chrome/browser/tab_contents/tab_contents.h"
27 #include "chrome/common/notification_service.h" 27 #include "chrome/common/notification_service.h"
28 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
29 #include "grit/app_strings.h" 29 #include "grit/app_strings.h"
30 #include "grit/chromium_strings.h" 30 #include "grit/chromium_strings.h"
31 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
32 #include "net/base/net_util.h" 32 #include "net/base/net_util.h"
33 #include "views/event.h" 33 #include "views/event.h"
34 34
35 #if defined(TOOLKIT_VIEWS)
36 #include "app/os_exchange_data.h"
37 #include "views/drag_utils.h"
38 #include "views/widget/root_view.h"
39 #include "views/widget/widget.h"
40 #endif
41
35 using base::Time; 42 using base::Time;
36 43
37 namespace { 44 namespace {
38 45
39 // A PageNavigator implementation that creates a new Browser. This is used when 46 // A PageNavigator implementation that creates a new Browser. This is used when
40 // opening a url and there is no Browser open. The Browser is created the first 47 // opening a url and there is no Browser open. The Browser is created the first
41 // time the PageNavigator method is invoked. 48 // time the PageNavigator method is invoked.
42 class NewBrowserPageNavigator : public PageNavigator { 49 class NewBrowserPageNavigator : public PageNavigator {
43 public: 50 public:
44 explicit NewBrowserPageNavigator(Profile* profile) 51 explicit NewBrowserPageNavigator(Profile* profile)
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 245 }
239 // User is dragging from another app, copy. 246 // User is dragging from another app, copy.
240 return PreferredDropOperation(event.GetSourceOperations(), 247 return PreferredDropOperation(event.GetSourceOperations(),
241 DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK); 248 DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK);
242 } 249 }
243 250
244 int PerformBookmarkDrop(Profile* profile, 251 int PerformBookmarkDrop(Profile* profile,
245 const BookmarkDragData& data, 252 const BookmarkDragData& data,
246 const BookmarkNode* parent_node, 253 const BookmarkNode* parent_node,
247 int index) { 254 int index) {
248 const BookmarkNode* dragged_node = data.GetFirstNode(profile); 255 const std::vector<const BookmarkNode*> dragged_nodes = data.GetNodes(profile);
249 BookmarkModel* model = profile->GetBookmarkModel(); 256 BookmarkModel* model = profile->GetBookmarkModel();
250 if (dragged_node) { 257 if (!dragged_nodes.empty()) {
251 // Drag from same profile, do a move. 258 // Drag from same profile. Move nodes.
252 model->Move(dragged_node, parent_node, index); 259 for (size_t i = 0; i < dragged_nodes.size(); ++i) {
260 model->Move(dragged_nodes[i], parent_node, index);
261 index = parent_node->IndexOfChild(dragged_nodes[i]) + 1;
262 }
253 return DragDropTypes::DRAG_MOVE; 263 return DragDropTypes::DRAG_MOVE;
254 } else if (data.has_single_url()) { 264 } else if (data.has_single_url()) {
255 // New URL, add it at the specified location. 265 // New URL, add it at the specified location.
256 string16 title = data.elements[0].title; 266 string16 title = data.elements[0].title;
257 if (title.empty()) { 267 if (title.empty()) {
258 // No title, use the host. 268 // No title, use the host.
259 title = UTF8ToUTF16(data.elements[0].url.host()); 269 title = UTF8ToUTF16(data.elements[0].url.host());
260 if (title.empty()) 270 if (title.empty())
261 title = TabContents::GetDefaultTitle(); 271 title = TabContents::GetDefaultTitle();
262 } 272 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 const BookmarkNode* parent, 317 const BookmarkNode* parent,
308 int index_to_add_at) { 318 int index_to_add_at) {
309 if (!parent->is_folder() || !model) { 319 if (!parent->is_folder() || !model) {
310 NOTREACHED(); 320 NOTREACHED();
311 return; 321 return;
312 } 322 }
313 for (size_t i = 0; i < elements.size(); ++i) 323 for (size_t i = 0; i < elements.size(); ++i)
314 CloneDragDataImpl(model, elements[i], parent, index_to_add_at + i); 324 CloneDragDataImpl(model, elements[i], parent, index_to_add_at + i);
315 } 325 }
316 326
327
328 // Bookmark dragging
329 void DragBookmarks(Profile* profile,
330 const std::vector<const BookmarkNode*>& nodes,
331 gfx::NativeView view) {
332 DCHECK(!nodes.empty());
333
334 #if defined(TOOLKIT_VIEWS)
335 // Set up our OLE machinery
336 OSExchangeData data;
337 BookmarkDragData drag_data(nodes);
338 drag_data.Write(profile, &data);
339
340 views::RootView* root_view = views::Widget::GetWidgetFromNativeView(view)->Get RootView();
341
342 // Allow nested message loop so we get DnD events as we drag this around.
343 bool was_nested = MessageLoop::current()->IsNested();
344 MessageLoop::current()->SetNestableTasksAllowed(true);
345
346 root_view->StartDragForViewFromMouseEvent(NULL, data,
347 DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_MOVE |
348 DragDropTypes::DRAG_LINK);
349
350 MessageLoop::current()->SetNestableTasksAllowed(was_nested);
351 #else
352 // TODO(arv): Implement for GTK and Cocoa.
353 NOTIMPLEMENTED();
354 #endif
355 }
356
317 void OpenAll(gfx::NativeWindow parent, 357 void OpenAll(gfx::NativeWindow parent,
318 Profile* profile, 358 Profile* profile,
319 PageNavigator* navigator, 359 PageNavigator* navigator,
320 const std::vector<const BookmarkNode*>& nodes, 360 const std::vector<const BookmarkNode*>& nodes,
321 WindowOpenDisposition initial_disposition) { 361 WindowOpenDisposition initial_disposition) {
322 if (!ShouldOpenAll(parent, nodes)) 362 if (!ShouldOpenAll(parent, nodes))
323 return; 363 return;
324 364
325 NewBrowserPageNavigator navigator_impl(profile); 365 NewBrowserPageNavigator navigator_impl(profile);
326 if (!navigator) { 366 if (!navigator) {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 std::vector<std::pair<GURL, std::wstring> >* urls) { 644 std::vector<std::pair<GURL, std::wstring> >* urls) {
605 for (int i = 0; i < browser->tab_count(); ++i) { 645 for (int i = 0; i < browser->tab_count(); ++i) {
606 std::pair<GURL, std::wstring> entry; 646 std::pair<GURL, std::wstring> entry;
607 GetURLAndTitleToBookmark(browser->GetTabContentsAt(i), &(entry.first), 647 GetURLAndTitleToBookmark(browser->GetTabContentsAt(i), &(entry.first),
608 &(entry.second)); 648 &(entry.second));
609 urls->push_back(entry); 649 urls->push_back(entry);
610 } 650 }
611 } 651 }
612 652
613 } // namespace bookmark_utils 653 } // namespace bookmark_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698