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

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

Issue 8115: Refactors some of the bookmark drag and drop code into a separate... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/bookmarks/bookmark_drag_utils.h"
6
7 #include "chrome/browser/bookmarks/bookmark_drag_data.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/common/drag_drop_types.h"
10 #include "chrome/views/event.h"
11
12 namespace {
13
14 void CloneDragDataImpl(BookmarkModel* model,
15 const BookmarkDragData::Element& element,
16 BookmarkNode* parent,
17 int index_to_add_at) {
18 if (element.is_url) {
19 model->AddURL(parent, index_to_add_at, element.title, element.url);
20 } else {
21 BookmarkNode* new_folder = model->AddGroup(parent, index_to_add_at,
22 element.title);
23 for (int i = 0; i < static_cast<int>(element.children.size()); ++i)
24 CloneDragDataImpl(model, element.children[i], new_folder, i);
25 }
26 }
27
28 } // namespace
29
30 namespace bookmark_drag_utils {
31
32 int PreferredDropOperation(const views::DropTargetEvent& event,
33 int operation) {
34 int common_ops = (event.GetSourceOperations() & operation);
35 if (!common_ops)
36 return 0;
37 if (DragDropTypes::DRAG_COPY & common_ops)
38 return DragDropTypes::DRAG_COPY;
39 if (DragDropTypes::DRAG_LINK & common_ops)
40 return DragDropTypes::DRAG_LINK;
41 if (DragDropTypes::DRAG_MOVE & common_ops)
42 return DragDropTypes::DRAG_MOVE;
43 return DragDropTypes::DRAG_NONE;
44 }
45
46 bool IsValidDropLocation(Profile* profile,
47 const BookmarkDragData& data,
48 BookmarkNode* drop_parent,
49 int index) {
50 if (!drop_parent->is_folder()) {
51 NOTREACHED();
52 return false;
53 }
54
55 if (!data.is_valid())
56 return false;
57
58 if (data.IsFromProfile(profile)) {
59 std::vector<BookmarkNode*> nodes = data.GetNodes(profile);
60 for (size_t i = 0; i < nodes.size(); ++i) {
61 // Don't allow the drop if the user is attempting to drop on one of the
62 // nodes being dragged.
63 BookmarkNode* node = nodes[i];
64 int node_index = (drop_parent == node->GetParent()) ?
65 drop_parent->IndexOfChild(nodes[i]) : -1;
66 if (node_index != -1 && (index == node_index || index == node_index + 1))
67 return false;
68
69 // drop_parent can't accept a child that is an ancestor.
70 if (drop_parent->HasAncestor(node))
71 return false;
72 }
73 return true;
74 }
75 // From the same profile, always accept.
76 return true;
77 }
78
79 void CloneDragData(BookmarkModel* model,
80 const std::vector<BookmarkDragData::Element>& elements,
81 BookmarkNode* parent,
82 int index_to_add_at) {
83 if (!parent->is_folder() || !model) {
84 NOTREACHED();
85 return;
86 }
87 for (size_t i = 0; i < elements.size(); ++i)
88 CloneDragDataImpl(model, elements[i], parent, index_to_add_at + i);
89 }
90
91 } // namespace bookmark_drag_utils
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_drag_utils.h ('k') | chrome/browser/views/bookmark_bar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698