OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_bar_gtk.h" | 5 #include "chrome/browser/gtk/bookmark_bar_gtk.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "app/gfx/text_elider.h" | 9 #include "app/gfx/text_elider.h" |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 reinterpret_cast<void*>(true)); | 433 reinterpret_cast<void*>(true)); |
434 | 434 |
435 GtkToolItem* item = gtk_tool_item_new(); | 435 GtkToolItem* item = gtk_tool_item_new(); |
436 gtk_container_add(GTK_CONTAINER(item), button); | 436 gtk_container_add(GTK_CONTAINER(item), button); |
437 gtk_widget_show_all(GTK_WIDGET(item)); | 437 gtk_widget_show_all(GTK_WIDGET(item)); |
438 | 438 |
439 return item; | 439 return item; |
440 } | 440 } |
441 | 441 |
442 void BookmarkBarGtk::ConnectFolderButtonEvents(GtkWidget* widget) { | 442 void BookmarkBarGtk::ConnectFolderButtonEvents(GtkWidget* widget) { |
| 443 gtk_drag_dest_set(widget, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_MOVE); |
| 444 GtkDndUtil::SetDestTargetListFromCodeMask(widget, |
| 445 GtkDndUtil::X_CHROME_BOOKMARK_ITEM); |
| 446 g_signal_connect(widget, "drag-data-received", |
| 447 G_CALLBACK(&OnFolderDragReceived), this); |
| 448 |
443 // Connect to 'button-release-event' instead of 'clicked' because we need | 449 // Connect to 'button-release-event' instead of 'clicked' because we need |
444 // access to the modifier keys and we do different things on each | 450 // access to the modifier keys and we do different things on each |
445 // button. | 451 // button. |
446 g_signal_connect(G_OBJECT(widget), "button-press-event", | 452 g_signal_connect(G_OBJECT(widget), "button-press-event", |
447 G_CALLBACK(OnButtonPressed), this); | 453 G_CALLBACK(OnButtonPressed), this); |
448 g_signal_connect(G_OBJECT(widget), "button-release-event", | 454 g_signal_connect(G_OBJECT(widget), "button-release-event", |
449 G_CALLBACK(OnFolderButtonReleased), this); | 455 G_CALLBACK(OnFolderButtonReleased), this); |
450 } | 456 } |
451 | 457 |
452 const BookmarkNode* BookmarkBarGtk::GetNodeForToolButton(GtkWidget* widget) { | 458 const BookmarkNode* BookmarkBarGtk::GetNodeForToolButton(GtkWidget* widget) { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 node, | 645 node, |
640 0, | 646 0, |
641 false)); | 647 false)); |
642 bar->current_menu_->Popup(sender, event->button, event->time); | 648 bar->current_menu_->Popup(sender, event->button, event->time); |
643 | 649 |
644 // Allow other handlers to run so the button state is updated correctly. | 650 // Allow other handlers to run so the button state is updated correctly. |
645 return FALSE; | 651 return FALSE; |
646 } | 652 } |
647 | 653 |
648 // static | 654 // static |
| 655 void BookmarkBarGtk::OnFolderDragReceived(GtkWidget* widget, |
| 656 GdkDragContext* context, gint x, gint y, GtkSelectionData* selection_data, |
| 657 guint target_type, guint time, BookmarkBarGtk* bar) { |
| 658 gboolean dnd_success = FALSE; |
| 659 gboolean delete_selection_data = FALSE; |
| 660 |
| 661 const BookmarkNode* dest_node = bar->GetNodeForToolButton(widget); |
| 662 DCHECK(dest_node->is_folder()); |
| 663 std::vector<const BookmarkNode*> nodes = |
| 664 bookmark_utils::GetNodesFromSelection(context, selection_data, |
| 665 target_type, |
| 666 bar->profile_, |
| 667 &delete_selection_data, |
| 668 &dnd_success); |
| 669 DCHECK(!nodes.empty()); |
| 670 |
| 671 for (std::vector<const BookmarkNode*>::iterator it = nodes.begin(); |
| 672 it != nodes.end(); ++it) { |
| 673 bar->model_->Move(*it, dest_node, dest_node->GetChildCount()); |
| 674 } |
| 675 |
| 676 gtk_drag_finish(context, dnd_success, delete_selection_data, time); |
| 677 } |
| 678 |
| 679 // static |
649 gboolean BookmarkBarGtk::OnToolbarExpose(GtkWidget* widget, | 680 gboolean BookmarkBarGtk::OnToolbarExpose(GtkWidget* widget, |
650 GdkEventExpose* event, | 681 GdkEventExpose* event, |
651 BookmarkBarGtk* bar) { | 682 BookmarkBarGtk* bar) { |
652 // A GtkToolbar's expose handler first draws a box. We don't want that so we | 683 // A GtkToolbar's expose handler first draws a box. We don't want that so we |
653 // need to propagate the expose event to all the container's children. | 684 // need to propagate the expose event to all the container's children. |
654 GList* children = gtk_container_get_children(GTK_CONTAINER(widget)); | 685 GList* children = gtk_container_get_children(GTK_CONTAINER(widget)); |
655 for (GList* item = children; item; item = item->next) { | 686 for (GList* item = children; item; item = item->next) { |
656 gtk_container_propagate_expose(GTK_CONTAINER(widget), | 687 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
657 GTK_WIDGET(item->data), | 688 GTK_WIDGET(item->data), |
658 event); | 689 event); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 bar->InitBackground(); | 806 bar->InitBackground(); |
776 gfx::Point tabstrip_origin = | 807 gfx::Point tabstrip_origin = |
777 bar->window_->tabstrip()->GetTabStripOriginForWidget(widget); | 808 bar->window_->tabstrip()->GetTabStripOriginForWidget(widget); |
778 bar->background_ninebox_->RenderTopCenterStrip( | 809 bar->background_ninebox_->RenderTopCenterStrip( |
779 cr, tabstrip_origin.x(), tabstrip_origin.y(), | 810 cr, tabstrip_origin.x(), tabstrip_origin.y(), |
780 event->area.x + event->area.width - tabstrip_origin.x()); | 811 event->area.x + event->area.width - tabstrip_origin.x()); |
781 cairo_destroy(cr); | 812 cairo_destroy(cr); |
782 | 813 |
783 return FALSE; // Propagate expose to children. | 814 return FALSE; // Propagate expose to children. |
784 } | 815 } |
OLD | NEW |