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

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

Issue 6250014: Move more dnd related files to ui/base (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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 <utility> 7 #include <utility>
8 8
9 #include "app/drag_drop_types.h"
10 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
11 #include "base/basictypes.h" 10 #include "base/basictypes.h"
12 #include "base/file_path.h" 11 #include "base/file_path.h"
13 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
14 #include "base/string16.h" 13 #include "base/string16.h"
15 #include "base/time.h" 14 #include "base/time.h"
16 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
17 #include "chrome/browser/bookmarks/bookmark_node_data.h" 16 #include "chrome/browser/bookmarks/bookmark_node_data.h"
18 #include "chrome/browser/bookmarks/bookmark_model.h" 17 #include "chrome/browser/bookmarks/bookmark_model.h"
19 #if defined(OS_MACOSX) 18 #if defined(OS_MACOSX)
20 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h" 19 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h"
21 #endif 20 #endif
22 #include "chrome/browser/browser_list.h" 21 #include "chrome/browser/browser_list.h"
23 #include "chrome/browser/browser_window.h" 22 #include "chrome/browser/browser_window.h"
24 #include "chrome/browser/history/query_parser.h" 23 #include "chrome/browser/history/query_parser.h"
25 #include "chrome/browser/platform_util.h" 24 #include "chrome/browser/platform_util.h"
26 #include "chrome/browser/prefs/pref_service.h" 25 #include "chrome/browser/prefs/pref_service.h"
27 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/tab_contents/page_navigator.h" 27 #include "chrome/browser/tab_contents/page_navigator.h"
29 #include "chrome/browser/tab_contents/tab_contents.h" 28 #include "chrome/browser/tab_contents/tab_contents.h"
30 #include "chrome/browser/ui/browser.h" 29 #include "chrome/browser/ui/browser.h"
31 #include "chrome/common/notification_service.h" 30 #include "chrome/common/notification_service.h"
32 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
33 #include "grit/app_strings.h" 32 #include "grit/app_strings.h"
34 #include "grit/chromium_strings.h" 33 #include "grit/chromium_strings.h"
35 #include "grit/generated_resources.h" 34 #include "grit/generated_resources.h"
36 #include "net/base/net_util.h" 35 #include "net/base/net_util.h"
36 #include "ui/base/dragdrop/drag_drop_types.h"
37 #include "ui/base/models/tree_node_iterator.h"
37 #include "views/event.h" 38 #include "views/event.h"
38 #include "ui/base/models/tree_node_iterator.h"
39 39
40 #if defined(TOOLKIT_VIEWS) 40 #if defined(TOOLKIT_VIEWS)
41 #include "ui/base/dragdrop/os_exchange_data.h" 41 #include "ui/base/dragdrop/os_exchange_data.h"
42 #include "views/drag_utils.h" 42 #include "views/drag_utils.h"
43 #include "views/widget/root_view.h" 43 #include "views/widget/root_view.h"
44 #include "views/widget/widget.h" 44 #include "views/widget/widget.h"
45 #elif defined(TOOLKIT_GTK) 45 #elif defined(TOOLKIT_GTK)
46 #include "chrome/browser/gtk/custom_drag.h" 46 #include "chrome/browser/gtk/custom_drag.h"
47 #endif 47 #endif
48 48
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } // namespace 203 } // namespace
204 204
205 namespace bookmark_utils { 205 namespace bookmark_utils {
206 206
207 int num_urls_before_prompting = 15; 207 int num_urls_before_prompting = 15;
208 208
209 int PreferredDropOperation(int source_operations, int operations) { 209 int PreferredDropOperation(int source_operations, int operations) {
210 int common_ops = (source_operations & operations); 210 int common_ops = (source_operations & operations);
211 if (!common_ops) 211 if (!common_ops)
212 return 0; 212 return 0;
213 if (DragDropTypes::DRAG_COPY & common_ops) 213 if (ui::DragDropTypes::DRAG_COPY & common_ops)
214 return DragDropTypes::DRAG_COPY; 214 return ui::DragDropTypes::DRAG_COPY;
215 if (DragDropTypes::DRAG_LINK & common_ops) 215 if (ui::DragDropTypes::DRAG_LINK & common_ops)
216 return DragDropTypes::DRAG_LINK; 216 return ui::DragDropTypes::DRAG_LINK;
217 if (DragDropTypes::DRAG_MOVE & common_ops) 217 if (ui::DragDropTypes::DRAG_MOVE & common_ops)
218 return DragDropTypes::DRAG_MOVE; 218 return ui::DragDropTypes::DRAG_MOVE;
219 return DragDropTypes::DRAG_NONE; 219 return ui::DragDropTypes::DRAG_NONE;
220 } 220 }
221 221
222 int BookmarkDragOperation(const BookmarkNode* node) { 222 int BookmarkDragOperation(const BookmarkNode* node) {
223 if (node->is_url()) { 223 if (node->is_url()) {
224 return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_MOVE | 224 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE |
225 DragDropTypes::DRAG_LINK; 225 ui::DragDropTypes::DRAG_LINK;
226 } 226 }
227 return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_MOVE; 227 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE;
228 } 228 }
229 229
230 int BookmarkDropOperation(Profile* profile, 230 int BookmarkDropOperation(Profile* profile,
231 const views::DropTargetEvent& event, 231 const views::DropTargetEvent& event,
232 const BookmarkNodeData& data, 232 const BookmarkNodeData& data,
233 const BookmarkNode* parent, 233 const BookmarkNode* parent,
234 int index) { 234 int index) {
235 if (data.IsFromProfile(profile) && data.size() > 1) 235 if (data.IsFromProfile(profile) && data.size() > 1)
236 // Currently only accept one dragged node at a time. 236 // Currently only accept one dragged node at a time.
237 return DragDropTypes::DRAG_NONE; 237 return ui::DragDropTypes::DRAG_NONE;
238 238
239 if (!bookmark_utils::IsValidDropLocation(profile, data, parent, index)) 239 if (!bookmark_utils::IsValidDropLocation(profile, data, parent, index))
240 return DragDropTypes::DRAG_NONE; 240 return ui::DragDropTypes::DRAG_NONE;
241 241
242 if (data.GetFirstNode(profile)) { 242 if (data.GetFirstNode(profile)) {
243 // User is dragging from this profile: move. 243 // User is dragging from this profile: move.
244 return DragDropTypes::DRAG_MOVE; 244 return ui::DragDropTypes::DRAG_MOVE;
245 } 245 }
246 // User is dragging from another app, copy. 246 // User is dragging from another app, copy.
247 return PreferredDropOperation(event.GetSourceOperations(), 247 return PreferredDropOperation(event.GetSourceOperations(),
248 DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK); 248 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK);
249 } 249 }
250 250
251 int PerformBookmarkDrop(Profile* profile, 251 int PerformBookmarkDrop(Profile* profile,
252 const BookmarkNodeData& data, 252 const BookmarkNodeData& data,
253 const BookmarkNode* parent_node, 253 const BookmarkNode* parent_node,
254 int index) { 254 int index) {
255 BookmarkModel* model = profile->GetBookmarkModel(); 255 BookmarkModel* model = profile->GetBookmarkModel();
256 if (data.IsFromProfile(profile)) { 256 if (data.IsFromProfile(profile)) {
257 const std::vector<const BookmarkNode*> dragged_nodes = 257 const std::vector<const BookmarkNode*> dragged_nodes =
258 data.GetNodes(profile); 258 data.GetNodes(profile);
259 if (!dragged_nodes.empty()) { 259 if (!dragged_nodes.empty()) {
260 // Drag from same profile. Move nodes. 260 // Drag from same profile. Move nodes.
261 for (size_t i = 0; i < dragged_nodes.size(); ++i) { 261 for (size_t i = 0; i < dragged_nodes.size(); ++i) {
262 model->Move(dragged_nodes[i], parent_node, index); 262 model->Move(dragged_nodes[i], parent_node, index);
263 index = parent_node->IndexOfChild(dragged_nodes[i]) + 1; 263 index = parent_node->IndexOfChild(dragged_nodes[i]) + 1;
264 } 264 }
265 return DragDropTypes::DRAG_MOVE; 265 return ui::DragDropTypes::DRAG_MOVE;
266 } 266 }
267 return DragDropTypes::DRAG_NONE; 267 return ui::DragDropTypes::DRAG_NONE;
268 } 268 }
269 // Dropping a group from different profile. Always accept. 269 // Dropping a group from different profile. Always accept.
270 bookmark_utils::CloneBookmarkNode(model, data.elements, parent_node, index); 270 bookmark_utils::CloneBookmarkNode(model, data.elements, parent_node, index);
271 return DragDropTypes::DRAG_COPY; 271 return ui::DragDropTypes::DRAG_COPY;
272 } 272 }
273 273
274 bool IsValidDropLocation(Profile* profile, 274 bool IsValidDropLocation(Profile* profile,
275 const BookmarkNodeData& data, 275 const BookmarkNodeData& data,
276 const BookmarkNode* drop_parent, 276 const BookmarkNode* drop_parent,
277 int index) { 277 int index) {
278 if (!drop_parent->is_folder()) { 278 if (!drop_parent->is_folder()) {
279 NOTREACHED(); 279 NOTREACHED();
280 return false; 280 return false;
281 } 281 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 drag_data.Write(profile, &data); 330 drag_data.Write(profile, &data);
331 331
332 views::RootView* root_view = 332 views::RootView* root_view =
333 views::Widget::GetWidgetFromNativeView(view)->GetRootView(); 333 views::Widget::GetWidgetFromNativeView(view)->GetRootView();
334 334
335 // Allow nested message loop so we get DnD events as we drag this around. 335 // Allow nested message loop so we get DnD events as we drag this around.
336 bool was_nested = MessageLoop::current()->IsNested(); 336 bool was_nested = MessageLoop::current()->IsNested();
337 MessageLoop::current()->SetNestableTasksAllowed(true); 337 MessageLoop::current()->SetNestableTasksAllowed(true);
338 338
339 root_view->StartDragForViewFromMouseEvent(NULL, data, 339 root_view->StartDragForViewFromMouseEvent(NULL, data,
340 DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_MOVE | 340 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE |
341 DragDropTypes::DRAG_LINK); 341 ui::DragDropTypes::DRAG_LINK);
342 342
343 MessageLoop::current()->SetNestableTasksAllowed(was_nested); 343 MessageLoop::current()->SetNestableTasksAllowed(was_nested);
344 #elif defined(OS_MACOSX) 344 #elif defined(OS_MACOSX)
345 // Allow nested message loop so we get DnD events as we drag this around. 345 // Allow nested message loop so we get DnD events as we drag this around.
346 bool was_nested = MessageLoop::current()->IsNested(); 346 bool was_nested = MessageLoop::current()->IsNested();
347 MessageLoop::current()->SetNestableTasksAllowed(true); 347 MessageLoop::current()->SetNestableTasksAllowed(true);
348 bookmark_pasteboard_helper_mac::StartDrag(profile, nodes, view); 348 bookmark_pasteboard_helper_mac::StartDrag(profile, nodes, view);
349 MessageLoop::current()->SetNestableTasksAllowed(was_nested); 349 MessageLoop::current()->SetNestableTasksAllowed(was_nested);
350 #elif defined(TOOLKIT_GTK) 350 #elif defined(TOOLKIT_GTK)
351 BookmarkDrag::BeginDrag(profile, nodes); 351 BookmarkDrag::BeginDrag(profile, nodes);
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 return true; 662 return true;
663 663
664 for (int i = 0; i < node->GetChildCount(); ++i) { 664 for (int i = 0; i < node->GetChildCount(); ++i) {
665 if (NodeHasURLs(node->GetChild(i))) 665 if (NodeHasURLs(node->GetChild(i)))
666 return true; 666 return true;
667 } 667 }
668 return false; 668 return false;
669 } 669 }
670 670
671 } // namespace bookmark_utils 671 } // namespace bookmark_utils
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_win.cc ('k') | chrome/browser/chromeos/dom_ui/imageburner_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698