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

Side by Side Diff: chrome/browser/ui/gtk/bookmark_utils_gtk.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) 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/gtk/bookmark_utils_gtk.h" 5 #include "chrome/browser/gtk/bookmark_utils_gtk.h"
6 6
7 #include "app/gtk_dnd_util.h"
8 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
9 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
10 #include "base/pickle.h" 9 #include "base/pickle.h"
11 #include "base/string16.h" 10 #include "base/string16.h"
12 #include "base/string_util.h" 11 #include "base/string_util.h"
13 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/bookmarks/bookmark_node_data.h" 13 #include "chrome/browser/bookmarks/bookmark_node_data.h"
15 #include "chrome/browser/bookmarks/bookmark_model.h" 14 #include "chrome/browser/bookmarks/bookmark_model.h"
16 #include "chrome/browser/bookmarks/bookmark_utils.h" 15 #include "chrome/browser/bookmarks/bookmark_utils.h"
17 #include "chrome/browser/gtk/gtk_chrome_button.h" 16 #include "chrome/browser/gtk/gtk_chrome_button.h"
18 #include "chrome/browser/gtk/gtk_theme_provider.h" 17 #include "chrome/browser/gtk/gtk_theme_provider.h"
19 #include "chrome/browser/gtk/gtk_util.h" 18 #include "chrome/browser/gtk/gtk_util.h"
20 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
21 #include "gfx/canvas_skia_paint.h" 20 #include "gfx/canvas_skia_paint.h"
22 #include "gfx/font.h" 21 #include "gfx/font.h"
23 #include "gfx/gtk_util.h" 22 #include "gfx/gtk_util.h"
23 #include "ui/base/dragdrop/gtk_dnd_util.h"
24 24
25 namespace { 25 namespace {
26 26
27 // Spacing between the favicon and the text. 27 // Spacing between the favicon and the text.
28 const int kBarButtonPadding = 4; 28 const int kBarButtonPadding = 4;
29 29
30 // Used in gtk_selection_data_set(). (I assume from this parameter that gtk has 30 // Used in gtk_selection_data_set(). (I assume from this parameter that gtk has
31 // to some really exotic hardware...) 31 // to some really exotic hardware...)
32 const int kBitsInAByte = 8; 32 const int kBitsInAByte = 8;
33 33
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // Because the prelight state is a white image that doesn't change by the 287 // Because the prelight state is a white image that doesn't change by the
288 // theme, force the text color to black when it would be used. 288 // theme, force the text color to black when it would be used.
289 gtk_widget_modify_fg(label, GTK_STATE_ACTIVE, &gtk_util::kGdkBlack); 289 gtk_widget_modify_fg(label, GTK_STATE_ACTIVE, &gtk_util::kGdkBlack);
290 gtk_widget_modify_fg(label, GTK_STATE_PRELIGHT, &gtk_util::kGdkBlack); 290 gtk_widget_modify_fg(label, GTK_STATE_PRELIGHT, &gtk_util::kGdkBlack);
291 } 291 }
292 } 292 }
293 293
294 // DnD-related ----------------------------------------------------------------- 294 // DnD-related -----------------------------------------------------------------
295 295
296 int GetCodeMask(bool folder) { 296 int GetCodeMask(bool folder) {
297 int rv = gtk_dnd_util::CHROME_BOOKMARK_ITEM; 297 int rv = ui::CHROME_BOOKMARK_ITEM;
298 if (!folder) { 298 if (!folder) {
299 rv |= gtk_dnd_util::TEXT_URI_LIST | 299 rv |= ui::TEXT_URI_LIST |
300 gtk_dnd_util::TEXT_PLAIN | 300 ui::TEXT_PLAIN |
301 gtk_dnd_util::NETSCAPE_URL; 301 ui::NETSCAPE_URL;
302 } 302 }
303 return rv; 303 return rv;
304 } 304 }
305 305
306 void WriteBookmarkToSelection(const BookmarkNode* node, 306 void WriteBookmarkToSelection(const BookmarkNode* node,
307 GtkSelectionData* selection_data, 307 GtkSelectionData* selection_data,
308 guint target_type, 308 guint target_type,
309 Profile* profile) { 309 Profile* profile) {
310 DCHECK(node); 310 DCHECK(node);
311 std::vector<const BookmarkNode*> nodes; 311 std::vector<const BookmarkNode*> nodes;
312 nodes.push_back(node); 312 nodes.push_back(node);
313 WriteBookmarksToSelection(nodes, selection_data, target_type, profile); 313 WriteBookmarksToSelection(nodes, selection_data, target_type, profile);
314 } 314 }
315 315
316 void WriteBookmarksToSelection(const std::vector<const BookmarkNode*>& nodes, 316 void WriteBookmarksToSelection(const std::vector<const BookmarkNode*>& nodes,
317 GtkSelectionData* selection_data, 317 GtkSelectionData* selection_data,
318 guint target_type, 318 guint target_type,
319 Profile* profile) { 319 Profile* profile) {
320 switch (target_type) { 320 switch (target_type) {
321 case gtk_dnd_util::CHROME_BOOKMARK_ITEM: { 321 case ui::CHROME_BOOKMARK_ITEM: {
322 BookmarkNodeData data(nodes); 322 BookmarkNodeData data(nodes);
323 Pickle pickle; 323 Pickle pickle;
324 data.WriteToPickle(profile, &pickle); 324 data.WriteToPickle(profile, &pickle);
325 325
326 gtk_selection_data_set(selection_data, selection_data->target, 326 gtk_selection_data_set(selection_data, selection_data->target,
327 kBitsInAByte, 327 kBitsInAByte,
328 static_cast<const guchar*>(pickle.data()), 328 static_cast<const guchar*>(pickle.data()),
329 pickle.size()); 329 pickle.size());
330 break; 330 break;
331 } 331 }
332 case gtk_dnd_util::NETSCAPE_URL: { 332 case ui::NETSCAPE_URL: {
333 // _NETSCAPE_URL format is URL + \n + title. 333 // _NETSCAPE_URL format is URL + \n + title.
334 std::string utf8_text = nodes[0]->GetURL().spec() + "\n" + 334 std::string utf8_text = nodes[0]->GetURL().spec() + "\n" +
335 UTF16ToUTF8(nodes[0]->GetTitle()); 335 UTF16ToUTF8(nodes[0]->GetTitle());
336 gtk_selection_data_set(selection_data, 336 gtk_selection_data_set(selection_data,
337 selection_data->target, 337 selection_data->target,
338 kBitsInAByte, 338 kBitsInAByte,
339 reinterpret_cast<const guchar*>(utf8_text.c_str()), 339 reinterpret_cast<const guchar*>(utf8_text.c_str()),
340 utf8_text.length()); 340 utf8_text.length());
341 break; 341 break;
342 } 342 }
343 case gtk_dnd_util::TEXT_URI_LIST: { 343 case ui::TEXT_URI_LIST: {
344 gchar** uris = reinterpret_cast<gchar**>(malloc(sizeof(gchar*) * 344 gchar** uris = reinterpret_cast<gchar**>(malloc(sizeof(gchar*) *
345 (nodes.size() + 1))); 345 (nodes.size() + 1)));
346 for (size_t i = 0; i < nodes.size(); ++i) { 346 for (size_t i = 0; i < nodes.size(); ++i) {
347 // If the node is a folder, this will be empty. TODO(estade): figure out 347 // If the node is a folder, this will be empty. TODO(estade): figure out
348 // if there are any ramifications to passing an empty URI. After a 348 // if there are any ramifications to passing an empty URI. After a
349 // little testing, it seems fine. 349 // little testing, it seems fine.
350 const GURL& url = nodes[i]->GetURL(); 350 const GURL& url = nodes[i]->GetURL();
351 // This const cast should be safe as gtk_selection_data_set_uris() 351 // This const cast should be safe as gtk_selection_data_set_uris()
352 // makes copies. 352 // makes copies.
353 uris[i] = const_cast<gchar*>(url.spec().c_str()); 353 uris[i] = const_cast<gchar*>(url.spec().c_str());
354 } 354 }
355 uris[nodes.size()] = NULL; 355 uris[nodes.size()] = NULL;
356 356
357 gtk_selection_data_set_uris(selection_data, uris); 357 gtk_selection_data_set_uris(selection_data, uris);
358 free(uris); 358 free(uris);
359 break; 359 break;
360 } 360 }
361 case gtk_dnd_util::TEXT_PLAIN: { 361 case ui::TEXT_PLAIN: {
362 gtk_selection_data_set_text(selection_data, 362 gtk_selection_data_set_text(selection_data,
363 nodes[0]->GetURL().spec().c_str(), -1); 363 nodes[0]->GetURL().spec().c_str(), -1);
364 break; 364 break;
365 } 365 }
366 default: { 366 default: {
367 DLOG(ERROR) << "Unsupported drag get type!"; 367 DLOG(ERROR) << "Unsupported drag get type!";
368 } 368 }
369 } 369 }
370 } 370 }
371 371
372 std::vector<const BookmarkNode*> GetNodesFromSelection( 372 std::vector<const BookmarkNode*> GetNodesFromSelection(
373 GdkDragContext* context, 373 GdkDragContext* context,
374 GtkSelectionData* selection_data, 374 GtkSelectionData* selection_data,
375 guint target_type, 375 guint target_type,
376 Profile* profile, 376 Profile* profile,
377 gboolean* delete_selection_data, 377 gboolean* delete_selection_data,
378 gboolean* dnd_success) { 378 gboolean* dnd_success) {
379 if (delete_selection_data) 379 if (delete_selection_data)
380 *delete_selection_data = FALSE; 380 *delete_selection_data = FALSE;
381 if (dnd_success) 381 if (dnd_success)
382 *dnd_success = FALSE; 382 *dnd_success = FALSE;
383 383
384 if (selection_data && selection_data->length > 0) { 384 if (selection_data && selection_data->length > 0) {
385 if (context && delete_selection_data && context->action == GDK_ACTION_MOVE) 385 if (context && delete_selection_data && context->action == GDK_ACTION_MOVE)
386 *delete_selection_data = TRUE; 386 *delete_selection_data = TRUE;
387 387
388 switch (target_type) { 388 switch (target_type) {
389 case gtk_dnd_util::CHROME_BOOKMARK_ITEM: { 389 case ui::CHROME_BOOKMARK_ITEM: {
390 if (dnd_success) 390 if (dnd_success)
391 *dnd_success = TRUE; 391 *dnd_success = TRUE;
392 Pickle pickle(reinterpret_cast<char*>(selection_data->data), 392 Pickle pickle(reinterpret_cast<char*>(selection_data->data),
393 selection_data->length); 393 selection_data->length);
394 BookmarkNodeData drag_data; 394 BookmarkNodeData drag_data;
395 drag_data.ReadFromPickle(&pickle); 395 drag_data.ReadFromPickle(&pickle);
396 return drag_data.GetNodes(profile); 396 return drag_data.GetNodes(profile);
397 } 397 }
398 default: { 398 default: {
399 DLOG(ERROR) << "Unsupported drag received type: " << target_type; 399 DLOG(ERROR) << "Unsupported drag received type: " << target_type;
400 } 400 }
401 } 401 }
402 } 402 }
403 403
404 return std::vector<const BookmarkNode*>(); 404 return std::vector<const BookmarkNode*>();
405 } 405 }
406 406
407 bool CreateNewBookmarkFromNamedUrl(GtkSelectionData* selection_data, 407 bool CreateNewBookmarkFromNamedUrl(GtkSelectionData* selection_data,
408 BookmarkModel* model, const BookmarkNode* parent, int idx) { 408 BookmarkModel* model, const BookmarkNode* parent, int idx) {
409 GURL url; 409 GURL url;
410 string16 title; 410 string16 title;
411 if (!gtk_dnd_util::ExtractNamedURL(selection_data, &url, &title)) 411 if (!ui::ExtractNamedURL(selection_data, &url, &title))
412 return false; 412 return false;
413 413
414 model->AddURL(parent, idx, title, url); 414 model->AddURL(parent, idx, title, url);
415 return true; 415 return true;
416 } 416 }
417 417
418 bool CreateNewBookmarksFromURIList(GtkSelectionData* selection_data, 418 bool CreateNewBookmarksFromURIList(GtkSelectionData* selection_data,
419 BookmarkModel* model, const BookmarkNode* parent, int idx) { 419 BookmarkModel* model, const BookmarkNode* parent, int idx) {
420 std::vector<GURL> urls; 420 std::vector<GURL> urls;
421 gtk_dnd_util::ExtractURIList(selection_data, &urls); 421 ui::ExtractURIList(selection_data, &urls);
422 for (size_t i = 0; i < urls.size(); ++i) { 422 for (size_t i = 0; i < urls.size(); ++i) {
423 std::string title = GetNameForURL(urls[i]); 423 std::string title = GetNameForURL(urls[i]);
424 model->AddURL(parent, idx++, UTF8ToUTF16(title), urls[i]); 424 model->AddURL(parent, idx++, UTF8ToUTF16(title), urls[i]);
425 } 425 }
426 return true; 426 return true;
427 } 427 }
428 428
429 bool CreateNewBookmarkFromNetscapeURL(GtkSelectionData* selection_data, 429 bool CreateNewBookmarkFromNetscapeURL(GtkSelectionData* selection_data,
430 BookmarkModel* model, const BookmarkNode* parent, int idx) { 430 BookmarkModel* model, const BookmarkNode* parent, int idx) {
431 GURL url; 431 GURL url;
432 string16 title; 432 string16 title;
433 if (!gtk_dnd_util::ExtractNetscapeURL(selection_data, &url, &title)) 433 if (!ui::ExtractNetscapeURL(selection_data, &url, &title))
434 return false; 434 return false;
435 435
436 model->AddURL(parent, idx, title, url); 436 model->AddURL(parent, idx, title, url);
437 return true; 437 return true;
438 } 438 }
439 439
440 } // namespace bookmark_utils 440 } // namespace bookmark_utils
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/bookmark_menu_controller_gtk.cc ('k') | chrome/browser/ui/gtk/bookmark_utils_gtk_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698