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 && gtk_selection_data_get_length(selection_data) > 0) { |
James Hawkins
2012/01/10 22:26:26
Refactor the gtk_selection_data_get_length call in
| |
398 if (context && delete_selection_data && context->action == GDK_ACTION_MOVE) | 399 if (context && delete_selection_data && context->action == GDK_ACTION_MOVE) |
399 *delete_selection_data = TRUE; | 400 *delete_selection_data = TRUE; |
400 | 401 |
401 switch (target_type) { | 402 switch (target_type) { |
402 case ui::CHROME_BOOKMARK_ITEM: { | 403 case ui::CHROME_BOOKMARK_ITEM: { |
403 if (dnd_success) | 404 if (dnd_success) |
404 *dnd_success = TRUE; | 405 *dnd_success = TRUE; |
405 Pickle pickle(reinterpret_cast<char*>(selection_data->data), | 406 Pickle pickle(reinterpret_cast<const char*>( |
406 selection_data->length); | 407 gtk_selection_data_get_data(selection_data)), |
408 gtk_selection_data_get_length(selection_data)); | |
407 BookmarkNodeData drag_data; | 409 BookmarkNodeData drag_data; |
408 drag_data.ReadFromPickle(&pickle); | 410 drag_data.ReadFromPickle(&pickle); |
409 return drag_data.GetNodes(profile); | 411 return drag_data.GetNodes(profile); |
410 } | 412 } |
411 default: { | 413 default: { |
412 DLOG(ERROR) << "Unsupported drag received type: " << target_type; | 414 DLOG(ERROR) << "Unsupported drag received type: " << target_type; |
413 } | 415 } |
414 } | 416 } |
415 } | 417 } |
416 | 418 |
(...skipping 27 matching lines...) Expand all Loading... | |
444 GURL url; | 446 GURL url; |
445 string16 title; | 447 string16 title; |
446 if (!ui::ExtractNetscapeURL(selection_data, &url, &title)) | 448 if (!ui::ExtractNetscapeURL(selection_data, &url, &title)) |
447 return false; | 449 return false; |
448 | 450 |
449 model->AddURL(parent, idx, title, url); | 451 model->AddURL(parent, idx, title, url); |
450 return true; | 452 return true; |
451 } | 453 } |
452 | 454 |
453 } // namespace bookmark_utils | 455 } // namespace bookmark_utils |
OLD | NEW |