OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/gtk/bookmarks/bookmark_utils_gtk.h" | 5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" |
6 | 6 |
7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 void WriteBookmarksToSelection(const std::vector<const BookmarkNode*>& nodes, | 317 void WriteBookmarksToSelection(const std::vector<const BookmarkNode*>& nodes, |
318 GtkSelectionData* selection_data, | 318 GtkSelectionData* selection_data, |
319 guint target_type, | 319 guint target_type, |
320 Profile* profile) { | 320 Profile* profile) { |
321 switch (target_type) { | 321 switch (target_type) { |
322 case ui::CHROME_BOOKMARK_ITEM: { | 322 case ui::CHROME_BOOKMARK_ITEM: { |
323 BookmarkNodeData data(nodes); | 323 BookmarkNodeData data(nodes); |
324 Pickle pickle; | 324 Pickle pickle; |
325 data.WriteToPickle(profile, &pickle); | 325 data.WriteToPickle(profile, &pickle); |
326 | 326 |
327 gtk_selection_data_set(selection_data, selection_data->target, | 327 gtk_selection_data_set(selection_data, |
| 328 gtk_selection_data_get_target(selection_data), |
328 kBitsInAByte, | 329 kBitsInAByte, |
329 static_cast<const guchar*>(pickle.data()), | 330 static_cast<const guchar*>(pickle.data()), |
330 pickle.size()); | 331 pickle.size()); |
331 break; | 332 break; |
332 } | 333 } |
333 case ui::NETSCAPE_URL: { | 334 case ui::NETSCAPE_URL: { |
334 // _NETSCAPE_URL format is URL + \n + title. | 335 // _NETSCAPE_URL format is URL + \n + title. |
335 std::string utf8_text = nodes[0]->url().spec() + "\n" + | 336 std::string utf8_text = nodes[0]->url().spec() + "\n" + |
336 UTF16ToUTF8(nodes[0]->GetTitle()); | 337 UTF16ToUTF8(nodes[0]->GetTitle()); |
337 gtk_selection_data_set(selection_data, | 338 gtk_selection_data_set(selection_data, |
338 selection_data->target, | 339 gtk_selection_data_get_target(selection_data), |
339 kBitsInAByte, | 340 kBitsInAByte, |
340 reinterpret_cast<const guchar*>(utf8_text.c_str()), | 341 reinterpret_cast<const guchar*>(utf8_text.c_str()), |
341 utf8_text.length()); | 342 utf8_text.length()); |
342 break; | 343 break; |
343 } | 344 } |
344 case ui::TEXT_URI_LIST: { | 345 case ui::TEXT_URI_LIST: { |
345 gchar** uris = reinterpret_cast<gchar**>(malloc(sizeof(gchar*) * | 346 gchar** uris = reinterpret_cast<gchar**>(malloc(sizeof(gchar*) * |
346 (nodes.size() + 1))); | 347 (nodes.size() + 1))); |
347 for (size_t i = 0; i < nodes.size(); ++i) { | 348 for (size_t i = 0; i < nodes.size(); ++i) { |
348 // If the node is a folder, this will be empty. TODO(estade): figure out | 349 // If the node is a folder, this will be empty. TODO(estade): figure out |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 GtkSelectionData* selection_data, | 388 GtkSelectionData* selection_data, |
388 guint target_type, | 389 guint target_type, |
389 Profile* profile, | 390 Profile* profile, |
390 gboolean* delete_selection_data, | 391 gboolean* delete_selection_data, |
391 gboolean* dnd_success) { | 392 gboolean* dnd_success) { |
392 if (delete_selection_data) | 393 if (delete_selection_data) |
393 *delete_selection_data = FALSE; | 394 *delete_selection_data = FALSE; |
394 if (dnd_success) | 395 if (dnd_success) |
395 *dnd_success = FALSE; | 396 *dnd_success = FALSE; |
396 | 397 |
397 if (selection_data && selection_data->length > 0) { | 398 if (selection_data) { |
398 if (context && delete_selection_data && context->action == GDK_ACTION_MOVE) | 399 gint length = gtk_selection_data_get_length(selection_data); |
399 *delete_selection_data = TRUE; | 400 if (length > 0) { |
| 401 if (context && delete_selection_data && |
| 402 context->action == GDK_ACTION_MOVE) |
| 403 *delete_selection_data = TRUE; |
400 | 404 |
401 switch (target_type) { | 405 switch (target_type) { |
402 case ui::CHROME_BOOKMARK_ITEM: { | 406 case ui::CHROME_BOOKMARK_ITEM: { |
403 if (dnd_success) | 407 if (dnd_success) |
404 *dnd_success = TRUE; | 408 *dnd_success = TRUE; |
405 Pickle pickle(reinterpret_cast<char*>(selection_data->data), | 409 Pickle pickle(reinterpret_cast<const char*>( |
406 selection_data->length); | 410 gtk_selection_data_get_data(selection_data)), length); |
407 BookmarkNodeData drag_data; | 411 BookmarkNodeData drag_data; |
408 drag_data.ReadFromPickle(&pickle); | 412 drag_data.ReadFromPickle(&pickle); |
409 return drag_data.GetNodes(profile); | 413 return drag_data.GetNodes(profile); |
410 } | 414 } |
411 default: { | 415 default: { |
412 DLOG(ERROR) << "Unsupported drag received type: " << target_type; | 416 DLOG(ERROR) << "Unsupported drag received type: " << target_type; |
| 417 } |
413 } | 418 } |
414 } | 419 } |
415 } | 420 } |
416 | 421 |
417 return std::vector<const BookmarkNode*>(); | 422 return std::vector<const BookmarkNode*>(); |
418 } | 423 } |
419 | 424 |
420 bool CreateNewBookmarkFromNamedUrl(GtkSelectionData* selection_data, | 425 bool CreateNewBookmarkFromNamedUrl(GtkSelectionData* selection_data, |
421 BookmarkModel* model, const BookmarkNode* parent, int idx) { | 426 BookmarkModel* model, const BookmarkNode* parent, int idx) { |
422 GURL url; | 427 GURL url; |
(...skipping 21 matching lines...) Expand all Loading... |
444 GURL url; | 449 GURL url; |
445 string16 title; | 450 string16 title; |
446 if (!ui::ExtractNetscapeURL(selection_data, &url, &title)) | 451 if (!ui::ExtractNetscapeURL(selection_data, &url, &title)) |
447 return false; | 452 return false; |
448 | 453 |
449 model->AddURL(parent, idx, title, url); | 454 model->AddURL(parent, idx, title, url); |
450 return true; | 455 return true; |
451 } | 456 } |
452 | 457 |
453 } // namespace bookmark_utils | 458 } // namespace bookmark_utils |
OLD | NEW |