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

Side by Side Diff: chrome/browser/gtk/bookmark_manager_gtk.cc

Issue 1118005: GTK: More transitions to thunk definition macros. (Closed)
Patch Set: Created 10 years, 9 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
OLDNEW
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_manager_gtk.h" 5 #include "chrome/browser/gtk/bookmark_manager_gtk.h"
6 6
7 #include <gdk/gdkkeysyms.h> 7 #include <gdk/gdkkeysyms.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "app/gtk_dnd_util.h" 10 #include "app/gtk_dnd_util.h"
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 window_bounds_.SetRect(x, y, width, height); 374 window_bounds_.SetRect(x, y, width, height);
375 375
376 // Build the organize and tools menus. 376 // Build the organize and tools menus.
377 organize_ = gtk_menu_item_new_with_label( 377 organize_ = gtk_menu_item_new_with_label(
378 l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_ORGANIZE_MENU).c_str()); 378 l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_ORGANIZE_MENU).c_str());
379 379
380 GtkWidget* import_item = gtk_menu_item_new_with_mnemonic( 380 GtkWidget* import_item = gtk_menu_item_new_with_mnemonic(
381 gtk_util::ConvertAcceleratorsFromWindowsStyle( 381 gtk_util::ConvertAcceleratorsFromWindowsStyle(
382 l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_IMPORT_MENU)).c_str()); 382 l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_IMPORT_MENU)).c_str());
383 g_signal_connect(import_item, "activate", 383 g_signal_connect(import_item, "activate",
384 G_CALLBACK(OnImportItemActivated), this); 384 G_CALLBACK(OnImportItemActivatedThunk), this);
385 385
386 GtkWidget* export_item = gtk_menu_item_new_with_mnemonic( 386 GtkWidget* export_item = gtk_menu_item_new_with_mnemonic(
387 gtk_util::ConvertAcceleratorsFromWindowsStyle( 387 gtk_util::ConvertAcceleratorsFromWindowsStyle(
388 l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_EXPORT_MENU)).c_str()); 388 l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_EXPORT_MENU)).c_str());
389 g_signal_connect(export_item, "activate", 389 g_signal_connect(export_item, "activate",
390 G_CALLBACK(OnExportItemActivated), this); 390 G_CALLBACK(OnExportItemActivatedThunk), this);
391 391
392 GtkWidget* tools_menu = gtk_menu_new(); 392 GtkWidget* tools_menu = gtk_menu_new();
393 gtk_menu_shell_append(GTK_MENU_SHELL(tools_menu), import_item); 393 gtk_menu_shell_append(GTK_MENU_SHELL(tools_menu), import_item);
394 gtk_menu_shell_append(GTK_MENU_SHELL(tools_menu), export_item); 394 gtk_menu_shell_append(GTK_MENU_SHELL(tools_menu), export_item);
395 395
396 GtkWidget* tools = gtk_menu_item_new_with_label( 396 GtkWidget* tools = gtk_menu_item_new_with_label(
397 l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_TOOLS_MENU).c_str()); 397 l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_TOOLS_MENU).c_str());
398 gtk_menu_item_set_submenu(GTK_MENU_ITEM(tools), tools_menu); 398 gtk_menu_item_set_submenu(GTK_MENU_ITEM(tools), tools_menu);
399 399
400 // Build the sync status menu item. 400 // Build the sync status menu item.
401 sync_status_menu_ = gtk_menu_item_new_with_label(""); 401 sync_status_menu_ = gtk_menu_item_new_with_label("");
402 g_signal_connect(sync_status_menu_, "activate", 402 g_signal_connect(sync_status_menu_, "activate",
403 G_CALLBACK(OnSyncStatusMenuActivated), this); 403 G_CALLBACK(OnSyncStatusMenuActivatedThunk), this);
404 404
405 GtkWidget* menu_bar = gtk_menu_bar_new(); 405 GtkWidget* menu_bar = gtk_menu_bar_new();
406 gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), organize_); 406 gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), organize_);
407 gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), tools); 407 gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), tools);
408 gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), sync_status_menu_); 408 gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), sync_status_menu_);
409 SetMenuBarStyle(); 409 SetMenuBarStyle();
410 gtk_widget_set_name(menu_bar, "chrome-bm-menubar"); 410 gtk_widget_set_name(menu_bar, "chrome-bm-menubar");
411 411
412 GtkWidget* search_label = gtk_label_new( 412 GtkWidget* search_label = gtk_label_new(
413 l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_SEARCH_TITLE).c_str()); 413 l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_SEARCH_TITLE).c_str());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 this, NULL)); 456 this, NULL));
457 } 457 }
458 458
459 GtkWidget* BookmarkManagerGtk::MakeLeftPane() { 459 GtkWidget* BookmarkManagerGtk::MakeLeftPane() {
460 left_store_ = bookmark_utils::MakeFolderTreeStore(); 460 left_store_ = bookmark_utils::MakeFolderTreeStore();
461 left_tree_view_ = bookmark_utils::MakeTreeViewForStore(left_store_); 461 left_tree_view_ = bookmark_utils::MakeTreeViewForStore(left_store_);
462 462
463 // When a row is collapsed that contained the selected node, we want to select 463 // When a row is collapsed that contained the selected node, we want to select
464 // it. 464 // it.
465 g_signal_connect(left_tree_view_, "row-collapsed", 465 g_signal_connect(left_tree_view_, "row-collapsed",
466 G_CALLBACK(OnLeftTreeViewRowCollapsed), this); 466 G_CALLBACK(OnLeftTreeViewRowCollapsedThunk), this);
467 g_signal_connect(left_tree_view_, "focus-in-event", 467 g_signal_connect(left_tree_view_, "focus-in-event",
468 G_CALLBACK(OnLeftTreeViewFocusIn), this); 468 G_CALLBACK(OnLeftTreeViewFocusInThunk), this);
469 g_signal_connect(left_tree_view_, "button-press-event", 469 g_signal_connect(left_tree_view_, "button-press-event",
470 G_CALLBACK(OnTreeViewButtonPress), this); 470 G_CALLBACK(OnTreeViewButtonPressThunk), this);
471 g_signal_connect(left_tree_view_, "button-release-event", 471 g_signal_connect(left_tree_view_, "button-release-event",
472 G_CALLBACK(OnTreeViewButtonRelease), this); 472 G_CALLBACK(OnTreeViewButtonReleaseThunk), this);
473 g_signal_connect(left_tree_view_, "key-press-event", 473 g_signal_connect(left_tree_view_, "key-press-event",
474 G_CALLBACK(OnTreeViewKeyPress), this); 474 G_CALLBACK(OnTreeViewKeyPressThunk), this);
475 475
476 GtkCellRenderer* cell_renderer_text = bookmark_utils::GetCellRendererText( 476 GtkCellRenderer* cell_renderer_text = bookmark_utils::GetCellRendererText(
477 GTK_TREE_VIEW(left_tree_view_)); 477 GTK_TREE_VIEW(left_tree_view_));
478 g_signal_connect(cell_renderer_text, "edited", 478 g_signal_connect(cell_renderer_text, "edited",
479 G_CALLBACK(OnFolderNameEdited), this); 479 G_CALLBACK(OnFolderNameEdited), this);
480 480
481 // The left side is only a drag destination (not a source). 481 // The left side is only a drag destination (not a source).
482 gtk_drag_dest_set(left_tree_view_, GTK_DEST_DEFAULT_DROP, 482 gtk_drag_dest_set(left_tree_view_, GTK_DEST_DEFAULT_DROP,
483 NULL, 0, GDK_ACTION_MOVE); 483 NULL, 0, GDK_ACTION_MOVE);
484 gtk_dnd_util::SetDestTargetList(left_tree_view_, kDestTargetList); 484 gtk_dnd_util::SetDestTargetList(left_tree_view_, kDestTargetList);
485 485
486 g_signal_connect(left_tree_view_, "drag-data-received", 486 g_signal_connect(left_tree_view_, "drag-data-received",
487 G_CALLBACK(&OnLeftTreeViewDragReceived), this); 487 G_CALLBACK(&OnLeftTreeViewDragReceivedThunk), this);
488 g_signal_connect(left_tree_view_, "drag-motion", 488 g_signal_connect(left_tree_view_, "drag-motion",
489 G_CALLBACK(&OnLeftTreeViewDragMotion), this); 489 G_CALLBACK(&OnLeftTreeViewDragMotionThunk), this);
490 490
491 GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL); 491 GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL);
492 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), 492 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
493 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); 493 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
494 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), 494 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
495 GTK_SHADOW_ETCHED_IN); 495 GTK_SHADOW_ETCHED_IN);
496 gtk_container_add(GTK_CONTAINER(scrolled), left_tree_view_); 496 gtk_container_add(GTK_CONTAINER(scrolled), left_tree_view_);
497 497
498 return scrolled; 498 return scrolled;
499 } 499 }
(...skipping 28 matching lines...) Expand all
528 528
529 right_tree_view_ = gtk_tree_view_new_with_model(GTK_TREE_MODEL(right_store_)); 529 right_tree_view_ = gtk_tree_view_new_with_model(GTK_TREE_MODEL(right_store_));
530 // Let |tree_view| own the store. 530 // Let |tree_view| own the store.
531 g_object_unref(right_store_); 531 g_object_unref(right_store_);
532 gtk_tree_view_append_column(GTK_TREE_VIEW(right_tree_view_), title_column_); 532 gtk_tree_view_append_column(GTK_TREE_VIEW(right_tree_view_), title_column_);
533 gtk_tree_view_append_column(GTK_TREE_VIEW(right_tree_view_), url_column_); 533 gtk_tree_view_append_column(GTK_TREE_VIEW(right_tree_view_), url_column_);
534 gtk_tree_view_append_column(GTK_TREE_VIEW(right_tree_view_), path_column_); 534 gtk_tree_view_append_column(GTK_TREE_VIEW(right_tree_view_), path_column_);
535 gtk_tree_selection_set_mode(right_selection(), GTK_SELECTION_MULTIPLE); 535 gtk_tree_selection_set_mode(right_selection(), GTK_SELECTION_MULTIPLE);
536 536
537 g_signal_connect(right_tree_view_, "row-activated", 537 g_signal_connect(right_tree_view_, "row-activated",
538 G_CALLBACK(OnRightTreeViewRowActivated), this); 538 G_CALLBACK(OnRightTreeViewRowActivatedThunk), this);
539 g_signal_connect(right_selection(), "changed", 539 g_signal_connect(right_selection(), "changed",
540 G_CALLBACK(OnRightSelectionChanged), this); 540 G_CALLBACK(OnRightSelectionChanged), this);
541 g_signal_connect(right_tree_view_, "focus-in-event", 541 g_signal_connect(right_tree_view_, "focus-in-event",
542 G_CALLBACK(OnRightTreeViewFocusIn), this); 542 G_CALLBACK(OnRightTreeViewFocusInThunk), this);
543 g_signal_connect(right_tree_view_, "button-press-event", 543 g_signal_connect(right_tree_view_, "button-press-event",
544 G_CALLBACK(OnRightTreeViewButtonPress), this); 544 G_CALLBACK(OnRightTreeViewButtonPressThunk), this);
545 g_signal_connect(right_tree_view_, "motion-notify-event", 545 g_signal_connect(right_tree_view_, "motion-notify-event",
546 G_CALLBACK(OnRightTreeViewMotion), this); 546 G_CALLBACK(OnRightTreeViewMotionThunk), this);
547 // This handler just controls showing the context menu. 547 // This handler just controls showing the context menu.
548 g_signal_connect(right_tree_view_, "button-press-event", 548 g_signal_connect(right_tree_view_, "button-press-event",
549 G_CALLBACK(OnTreeViewButtonPress), this); 549 G_CALLBACK(OnTreeViewButtonPressThunk), this);
550 g_signal_connect(right_tree_view_, "button-release-event", 550 g_signal_connect(right_tree_view_, "button-release-event",
551 G_CALLBACK(OnTreeViewButtonRelease), this); 551 G_CALLBACK(OnTreeViewButtonReleaseThunk), this);
552 g_signal_connect(right_tree_view_, "key-press-event", 552 g_signal_connect(right_tree_view_, "key-press-event",
553 G_CALLBACK(OnTreeViewKeyPress), this); 553 G_CALLBACK(OnTreeViewKeyPressThunk), this);
554 554
555 // GDK_ACTION_MOVE is necessary to reorder bookmarks within the 555 // GDK_ACTION_MOVE is necessary to reorder bookmarks within the
556 // right tree. COPY and LINK are necessary for drags to the 556 // right tree. COPY and LINK are necessary for drags to the
557 // Gnome desktop (nautilus). 557 // Gnome desktop (nautilus).
558 gtk_drag_source_set(right_tree_view_, GDK_BUTTON1_MASK, NULL, 0, 558 gtk_drag_source_set(right_tree_view_, GDK_BUTTON1_MASK, NULL, 0,
559 static_cast<GdkDragAction>(GDK_ACTION_MOVE | GDK_ACTION_COPY | 559 static_cast<GdkDragAction>(GDK_ACTION_MOVE | GDK_ACTION_COPY |
560 GDK_ACTION_LINK)); 560 GDK_ACTION_LINK));
561 gtk_dnd_util::SetSourceTargetListFromCodeMask( 561 gtk_dnd_util::SetSourceTargetListFromCodeMask(
562 right_tree_view_, kSourceTargetMask); 562 right_tree_view_, kSourceTargetMask);
563 563
564 // We connect to drag dest signals, but we don't actually enable the widget 564 // We connect to drag dest signals, but we don't actually enable the widget
565 // as a drag destination unless it corresponds to the contents of a folder. 565 // as a drag destination unless it corresponds to the contents of a folder.
566 // See BuildRightStore(). 566 // See BuildRightStore().
567 g_signal_connect(right_tree_view_, "drag-data-get", 567 g_signal_connect(right_tree_view_, "drag-data-get",
568 G_CALLBACK(&OnRightTreeViewDragGet), this); 568 G_CALLBACK(OnRightTreeViewDragGetThunk), this);
569 g_signal_connect(right_tree_view_, "drag-data-received", 569 g_signal_connect(right_tree_view_, "drag-data-received",
570 G_CALLBACK(&OnRightTreeViewDragReceived), this); 570 G_CALLBACK(&OnRightTreeViewDragReceivedThunk), this);
571 g_signal_connect(right_tree_view_, "drag-motion", 571 g_signal_connect(right_tree_view_, "drag-motion",
572 G_CALLBACK(&OnRightTreeViewDragMotion), this); 572 G_CALLBACK(&OnRightTreeViewDragMotionThunk), this);
573 g_signal_connect(right_tree_view_, "drag-begin", 573 g_signal_connect(right_tree_view_, "drag-begin",
574 G_CALLBACK(&OnRightTreeViewDragBegin), this); 574 G_CALLBACK(&OnRightTreeViewDragBeginThunk), this);
575 575
576 GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL); 576 GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL);
577 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), 577 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
578 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); 578 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
579 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), 579 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
580 GTK_SHADOW_ETCHED_IN); 580 GTK_SHADOW_ETCHED_IN);
581 gtk_container_add(GTK_CONTAINER(scrolled), right_tree_view_); 581 gtk_container_add(GTK_CONTAINER(scrolled), right_tree_view_);
582 582
583 return scrolled; 583 return scrolled;
584 } 584 }
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 gtk_tree_model_iter_n_children(GTK_TREE_MODEL(left_store_), NULL) - 1; 896 gtk_tree_model_iter_n_children(GTK_TREE_MODEL(left_store_), NULL) - 1;
897 GtkTreeIter iter; 897 GtkTreeIter iter;
898 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(left_store_), &iter, NULL, 898 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(left_store_), &iter, NULL,
899 index); 899 index);
900 gtk_tree_selection_select_iter(left_selection(), &iter); 900 gtk_tree_selection_select_iter(left_selection(), &iter);
901 } else { 901 } else {
902 BuildRightStore(); 902 BuildRightStore();
903 } 903 }
904 } 904 }
905 905
906 void BookmarkManagerGtk::OnSearchTextChanged() { 906 void BookmarkManagerGtk::OnSearchTextChanged(GtkWidget* widget) {
907 search_factory_.RevokeAll(); 907 search_factory_.RevokeAll();
908 MessageLoop::current()->PostDelayedTask(FROM_HERE, 908 MessageLoop::current()->PostDelayedTask(FROM_HERE,
909 search_factory_.NewRunnableMethod(&BookmarkManagerGtk::PerformSearch), 909 search_factory_.NewRunnableMethod(&BookmarkManagerGtk::PerformSearch),
910 kSearchDelayMS); 910 kSearchDelayMS);
911 } 911 }
912 912
913 // static 913 // static
914 void BookmarkManagerGtk::OnLeftSelectionChanged(GtkTreeSelection* selection, 914 void BookmarkManagerGtk::OnLeftSelectionChanged(GtkTreeSelection* selection,
915 BookmarkManagerGtk* bm) { 915 BookmarkManagerGtk* bm) {
916 // If the selection is (newly) empty, then make the right tree view take 916 // If the selection is (newly) empty, then make the right tree view take
(...skipping 13 matching lines...) Expand all
930 // If the selection is (newly) empty, then make the left tree view take 930 // If the selection is (newly) empty, then make the left tree view take
931 // over the organize menu. 931 // over the organize menu.
932 if (gtk_tree_selection_count_selected_rows(selection) == 0) { 932 if (gtk_tree_selection_count_selected_rows(selection) == 0) {
933 bm->ResetOrganizeMenu(true); 933 bm->ResetOrganizeMenu(true);
934 return; 934 return;
935 } 935 }
936 936
937 bm->ResetOrganizeMenu(false); 937 bm->ResetOrganizeMenu(false);
938 } 938 }
939 939
940 // static
941 void BookmarkManagerGtk::OnLeftTreeViewDragReceived( 940 void BookmarkManagerGtk::OnLeftTreeViewDragReceived(
942 GtkWidget* tree_view, 941 GtkWidget* tree_view,
943 GdkDragContext* context, 942 GdkDragContext* context,
944 gint x, 943 gint x,
945 gint y, 944 gint y,
946 GtkSelectionData* selection_data, 945 GtkSelectionData* selection_data,
947 guint target_type, 946 guint target_type,
948 guint time, 947 guint time) {
949 BookmarkManagerGtk* bm) {
950 gboolean get_nodes_success = FALSE; 948 gboolean get_nodes_success = FALSE;
951 gboolean delete_selection_data = FALSE; 949 gboolean delete_selection_data = FALSE;
952 950
953 std::vector<const BookmarkNode*> nodes = 951 std::vector<const BookmarkNode*> nodes =
954 bookmark_utils::GetNodesFromSelection(context, selection_data, 952 bookmark_utils::GetNodesFromSelection(context, selection_data,
955 target_type, 953 target_type,
956 bm->profile_, 954 profile_,
957 &delete_selection_data, 955 &delete_selection_data,
958 &get_nodes_success); 956 &get_nodes_success);
959 957
960 if (nodes.empty() || !get_nodes_success) { 958 if (nodes.empty() || !get_nodes_success) {
961 gtk_drag_finish(context, FALSE, delete_selection_data, time); 959 gtk_drag_finish(context, FALSE, delete_selection_data, time);
962 return; 960 return;
963 } 961 }
964 962
965 GtkTreePath* path; 963 GtkTreePath* path;
966 GtkTreeViewDropPosition pos; 964 GtkTreeViewDropPosition pos;
967 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, 965 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y,
968 &path, &pos); 966 &path, &pos);
969 if (!path) { 967 if (!path) {
970 gtk_drag_finish(context, FALSE, delete_selection_data, time); 968 gtk_drag_finish(context, FALSE, delete_selection_data, time);
971 return; 969 return;
972 } 970 }
973 971
974 GtkTreeIter iter; 972 GtkTreeIter iter;
975 gtk_tree_model_get_iter(GTK_TREE_MODEL(bm->left_store_), &iter, path); 973 gtk_tree_model_get_iter(GTK_TREE_MODEL(left_store_), &iter, path);
976 const BookmarkNode* folder = 974 const BookmarkNode* folder = GetNodeAt(GTK_TREE_MODEL(left_store_), &iter);
977 bm->GetNodeAt(GTK_TREE_MODEL(bm->left_store_), &iter);
978 gboolean dnd_success = FALSE; 975 gboolean dnd_success = FALSE;
979 976
980 if (folder) { 977 if (folder) {
981 for (std::vector<const BookmarkNode*>::iterator it = nodes.begin(); 978 for (std::vector<const BookmarkNode*>::iterator it = nodes.begin();
982 it != nodes.end(); ++it) { 979 it != nodes.end(); ++it) {
983 // Don't try to drop a node into one of its descendants. 980 // Don't try to drop a node into one of its descendants.
984 if (!folder->HasAncestor(*it)) { 981 if (!folder->HasAncestor(*it)) {
985 bm->model_->Move(*it, folder, folder->GetChildCount()); 982 model_->Move(*it, folder, folder->GetChildCount());
986 dnd_success = TRUE; 983 dnd_success = TRUE;
987 } 984 }
988 } 985 }
989 } 986 }
990 987
991 gtk_tree_path_free(path); 988 gtk_tree_path_free(path);
992 gtk_drag_finish(context, dnd_success, delete_selection_data && dnd_success, 989 gtk_drag_finish(context, dnd_success, delete_selection_data && dnd_success,
993 time); 990 time);
994 } 991 }
995 992
996 // static
997 gboolean BookmarkManagerGtk::OnLeftTreeViewDragMotion( 993 gboolean BookmarkManagerGtk::OnLeftTreeViewDragMotion(
998 GtkWidget* tree_view, 994 GtkWidget* tree_view,
999 GdkDragContext* context, 995 GdkDragContext* context,
1000 gint x, 996 gint x,
1001 gint y, 997 gint y,
1002 guint time, 998 guint time) {
1003 BookmarkManagerGtk* bm) {
1004 GtkTreePath* path; 999 GtkTreePath* path;
1005 GtkTreeViewDropPosition pos; 1000 GtkTreeViewDropPosition pos;
1006 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, 1001 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y,
1007 &path, &pos); 1002 &path, &pos);
1008 1003
1009 if (path) { 1004 if (path) {
1010 // Don't accept drops over the "Search" or "Recently added" folders. 1005 // Don't accept drops over the "Search" or "Recently added" folders.
1011 GtkTreeIter iter; 1006 GtkTreeIter iter;
1012 GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)); 1007 GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view));
1013 gtk_tree_model_get_iter(model, &iter, path); 1008 gtk_tree_model_get_iter(model, &iter, path);
1014 if (bm->GetNodeAt(model, &iter) == NULL) 1009 if (GetNodeAt(model, &iter) == NULL)
1015 return FALSE; 1010 return FALSE;
1016 1011
1017 // Only allow INTO. 1012 // Only allow INTO.
1018 if (pos == GTK_TREE_VIEW_DROP_BEFORE) 1013 if (pos == GTK_TREE_VIEW_DROP_BEFORE)
1019 pos = GTK_TREE_VIEW_DROP_INTO_OR_BEFORE; 1014 pos = GTK_TREE_VIEW_DROP_INTO_OR_BEFORE;
1020 else if (pos == GTK_TREE_VIEW_DROP_AFTER) 1015 else if (pos == GTK_TREE_VIEW_DROP_AFTER)
1021 pos = GTK_TREE_VIEW_DROP_INTO_OR_AFTER; 1016 pos = GTK_TREE_VIEW_DROP_INTO_OR_AFTER;
1022 gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), path, pos); 1017 gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), path, pos);
1023 } else { 1018 } else {
1024 return FALSE; 1019 return FALSE;
1025 } 1020 }
1026 1021
1027 gdk_drag_status(context, GDK_ACTION_MOVE, time); 1022 gdk_drag_status(context, GDK_ACTION_MOVE, time);
1028 gtk_tree_path_free(path); 1023 gtk_tree_path_free(path);
1029 return TRUE; 1024 return TRUE;
1030 } 1025 }
1031 1026
1032 // static
1033 void BookmarkManagerGtk::OnLeftTreeViewRowCollapsed( 1027 void BookmarkManagerGtk::OnLeftTreeViewRowCollapsed(
1034 GtkTreeView *tree_view, 1028 GtkWidget* tree_view,
1035 GtkTreeIter* iter, 1029 GtkTreeIter* iter,
1036 GtkTreePath* path, 1030 GtkTreePath* path) {
1037 BookmarkManagerGtk* bm) {
1038 // If a selection still exists, do nothing. 1031 // If a selection still exists, do nothing.
1039 if (gtk_tree_selection_get_selected(bm->left_selection(), NULL, NULL)) 1032 if (gtk_tree_selection_get_selected(left_selection(), NULL, NULL))
1040 return; 1033 return;
1041 1034
1042 gtk_tree_selection_select_path(bm->left_selection(), path); 1035 gtk_tree_selection_select_path(left_selection(), path);
1043 } 1036 }
1044 1037
1045 // static
1046 void BookmarkManagerGtk::OnRightTreeViewDragGet( 1038 void BookmarkManagerGtk::OnRightTreeViewDragGet(
1047 GtkWidget* tree_view, 1039 GtkWidget* tree_view,
1048 GdkDragContext* context, 1040 GdkDragContext* context,
1049 GtkSelectionData* selection_data, 1041 GtkSelectionData* selection_data,
1050 guint target_type, 1042 guint target_type,
1051 guint time, 1043 guint time) {
1052 BookmarkManagerGtk* bm) {
1053 // No selection, do nothing. This shouldn't get hit, but if it does an early 1044 // No selection, do nothing. This shouldn't get hit, but if it does an early
1054 // return avoids a crash. 1045 // return avoids a crash.
1055 if (gtk_tree_selection_count_selected_rows(bm->right_selection()) == 0) { 1046 if (gtk_tree_selection_count_selected_rows(right_selection()) == 0) {
1056 NOTREACHED(); 1047 NOTREACHED();
1057 return; 1048 return;
1058 } 1049 }
1059 1050
1060 bookmark_utils::WriteBookmarksToSelection(bm->GetRightSelection(), 1051 bookmark_utils::WriteBookmarksToSelection(GetRightSelection(),
1061 selection_data, 1052 selection_data,
1062 target_type, 1053 target_type,
1063 bm->profile_); 1054 profile_);
1064 } 1055 }
1065 1056
1066 // static
1067 void BookmarkManagerGtk::OnRightTreeViewDragReceived( 1057 void BookmarkManagerGtk::OnRightTreeViewDragReceived(
1068 GtkWidget* tree_view, 1058 GtkWidget* tree_view,
1069 GdkDragContext* context, 1059 GdkDragContext* context,
1070 gint x, 1060 gint x,
1071 gint y, 1061 gint y,
1072 GtkSelectionData* selection_data, 1062 GtkSelectionData* selection_data,
1073 guint target_type, 1063 guint target_type,
1074 guint time, 1064 guint time) {
1075 BookmarkManagerGtk* bm) {
1076 gboolean dnd_success = FALSE; 1065 gboolean dnd_success = FALSE;
1077 gboolean delete_selection_data = FALSE; 1066 gboolean delete_selection_data = FALSE;
1078 1067
1079 std::vector<const BookmarkNode*> nodes = 1068 std::vector<const BookmarkNode*> nodes =
1080 bookmark_utils::GetNodesFromSelection(context, selection_data, 1069 bookmark_utils::GetNodesFromSelection(context, selection_data,
1081 target_type, 1070 target_type,
1082 bm->profile_, 1071 profile_,
1083 &delete_selection_data, 1072 &delete_selection_data,
1084 &dnd_success); 1073 &dnd_success);
1085 1074
1086 if (nodes.empty()) { 1075 if (nodes.empty()) {
1087 gtk_drag_finish(context, dnd_success, delete_selection_data, time); 1076 gtk_drag_finish(context, dnd_success, delete_selection_data, time);
1088 return; 1077 return;
1089 } 1078 }
1090 1079
1091 GtkTreePath* path; 1080 GtkTreePath* path;
1092 GtkTreeViewDropPosition pos; 1081 GtkTreeViewDropPosition pos;
1093 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, 1082 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y,
1094 &path, &pos); 1083 &path, &pos);
1095 1084
1096 bool drop_before = pos == GTK_TREE_VIEW_DROP_BEFORE; 1085 bool drop_before = pos == GTK_TREE_VIEW_DROP_BEFORE;
1097 bool drop_after = pos == GTK_TREE_VIEW_DROP_AFTER; 1086 bool drop_after = pos == GTK_TREE_VIEW_DROP_AFTER;
1098 1087
1099 // The parent folder and index therein to drop the nodes. 1088 // The parent folder and index therein to drop the nodes.
1100 const BookmarkNode* parent = NULL; 1089 const BookmarkNode* parent = NULL;
1101 int idx = -1; 1090 int idx = -1;
1102 1091
1103 // |path| will be null when we are looking at an empty folder. 1092 // |path| will be null when we are looking at an empty folder.
1104 if (!drop_before && !drop_after && path) { 1093 if (!drop_before && !drop_after && path) {
1105 GtkTreeIter iter; 1094 GtkTreeIter iter;
1106 GtkTreeModel* model = GTK_TREE_MODEL(bm->right_store_); 1095 GtkTreeModel* model = GTK_TREE_MODEL(right_store_);
1107 gtk_tree_model_get_iter(model, &iter, path); 1096 gtk_tree_model_get_iter(model, &iter, path);
1108 const BookmarkNode* node = bm->GetNodeAt(model, &iter); 1097 const BookmarkNode* node = GetNodeAt(model, &iter);
1109 if (node && node->is_folder()) { 1098 if (node && node->is_folder()) {
1110 parent = node; 1099 parent = node;
1111 idx = parent->GetChildCount(); 1100 idx = parent->GetChildCount();
1112 } else { 1101 } else {
1113 drop_before = pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE; 1102 drop_before = pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE;
1114 drop_after = pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER; 1103 drop_after = pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER;
1115 } 1104 }
1116 } 1105 }
1117 1106
1118 if (drop_before || drop_after || !path) { 1107 if (drop_before || drop_after || !path) {
1119 if (path && drop_after) 1108 if (path && drop_after)
1120 gtk_tree_path_next(path); 1109 gtk_tree_path_next(path);
1121 // We will get a null path when the drop is below the lowest row. 1110 // We will get a null path when the drop is below the lowest row.
1122 parent = bm->GetFolder(); 1111 parent = GetFolder();
1123 idx = !path ? parent->GetChildCount() : gtk_tree_path_get_indices(path)[0]; 1112 idx = !path ? parent->GetChildCount() : gtk_tree_path_get_indices(path)[0];
1124 } 1113 }
1125 1114
1126 for (std::vector<const BookmarkNode*>::iterator it = nodes.begin(); 1115 for (std::vector<const BookmarkNode*>::iterator it = nodes.begin();
1127 it != nodes.end(); ++it) { 1116 it != nodes.end(); ++it) {
1128 // Don't try to drop a node into one of its descendants. 1117 // Don't try to drop a node into one of its descendants.
1129 if (!parent->HasAncestor(*it)) { 1118 if (!parent->HasAncestor(*it)) {
1130 bm->model_->Move(*it, parent, idx); 1119 model_->Move(*it, parent, idx);
1131 idx = parent->IndexOfChild(*it) + 1; 1120 idx = parent->IndexOfChild(*it) + 1;
1132 } 1121 }
1133 } 1122 }
1134 1123
1135 gtk_tree_path_free(path); 1124 gtk_tree_path_free(path);
1136 gtk_drag_finish(context, dnd_success, delete_selection_data, time); 1125 gtk_drag_finish(context, dnd_success, delete_selection_data, time);
1137 } 1126 }
1138 1127
1139 // static
1140 void BookmarkManagerGtk::OnRightTreeViewDragBegin( 1128 void BookmarkManagerGtk::OnRightTreeViewDragBegin(
1141 GtkWidget* tree_view, 1129 GtkWidget* tree_view,
1142 GdkDragContext* drag_context, 1130 GdkDragContext* drag_context) {
1143 BookmarkManagerGtk* bm) {
1144 gtk_drag_set_icon_stock(drag_context, GTK_STOCK_DND, 0, 0); 1131 gtk_drag_set_icon_stock(drag_context, GTK_STOCK_DND, 0, 0);
1145 } 1132 }
1146 1133
1147 // static
1148 gboolean BookmarkManagerGtk::OnRightTreeViewDragMotion( 1134 gboolean BookmarkManagerGtk::OnRightTreeViewDragMotion(
1149 GtkWidget* tree_view, 1135 GtkWidget* tree_view,
1150 GdkDragContext* context, 1136 GdkDragContext* context,
1151 gint x, 1137 gint x,
1152 gint y, 1138 gint y,
1153 guint time, 1139 guint time) {
1154 BookmarkManagerGtk* bm) {
1155 GtkTreePath* path; 1140 GtkTreePath* path;
1156 GtkTreeViewDropPosition pos; 1141 GtkTreeViewDropPosition pos;
1157 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, 1142 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y,
1158 &path, &pos); 1143 &path, &pos);
1159 1144
1160 const BookmarkNode* parent = bm->GetFolder(); 1145 const BookmarkNode* parent = GetFolder();
1161 if (path) { 1146 if (path) {
1162 int idx = 1147 int idx =
1163 gtk_tree_path_get_indices(path)[gtk_tree_path_get_depth(path) - 1]; 1148 gtk_tree_path_get_indices(path)[gtk_tree_path_get_depth(path) - 1];
1164 // Only allow INTO if the node is a folder. 1149 // Only allow INTO if the node is a folder.
1165 if (parent->GetChild(idx)->is_url()) { 1150 if (parent->GetChild(idx)->is_url()) {
1166 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE) 1151 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
1167 pos = GTK_TREE_VIEW_DROP_BEFORE; 1152 pos = GTK_TREE_VIEW_DROP_BEFORE;
1168 else if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) 1153 else if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
1169 pos = GTK_TREE_VIEW_DROP_AFTER; 1154 pos = GTK_TREE_VIEW_DROP_AFTER;
1170 } 1155 }
1171 gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), path, pos); 1156 gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), path, pos);
1172 } else { 1157 } else {
1173 // We allow a drop if the drag is over the bottom of the tree view, 1158 // We allow a drop if the drag is over the bottom of the tree view,
1174 // but we don't draw any indication. 1159 // but we don't draw any indication.
1175 } 1160 }
1176 1161
1177 gdk_drag_status(context, GDK_ACTION_MOVE, time); 1162 gdk_drag_status(context, GDK_ACTION_MOVE, time);
1178 return TRUE; 1163 return TRUE;
1179 } 1164 }
1180 1165
1181 // static
1182 void BookmarkManagerGtk::OnRightTreeViewRowActivated( 1166 void BookmarkManagerGtk::OnRightTreeViewRowActivated(
1183 GtkTreeView* tree_view, 1167 GtkWidget* tree_view,
1184 GtkTreePath* path, 1168 GtkTreePath* path,
1185 GtkTreeViewColumn* column, 1169 GtkTreeViewColumn* column) {
1186 BookmarkManagerGtk* bm) { 1170 std::vector<const BookmarkNode*> nodes = GetRightSelection();
1187 std::vector<const BookmarkNode*> nodes = bm->GetRightSelection();
1188 if (nodes.empty()) 1171 if (nodes.empty())
1189 return; 1172 return;
1190 if (nodes.size() == 1 && nodes[0]->is_folder()) { 1173 if (nodes.size() == 1 && nodes[0]->is_folder()) {
1191 // Double click on a folder descends into the folder. 1174 // Double click on a folder descends into the folder.
1192 bm->SelectInTree(nodes[0], false); 1175 SelectInTree(nodes[0], false);
1193 return; 1176 return;
1194 } 1177 }
1195 bookmark_utils::OpenAll(GTK_WINDOW(bm->window_), bm->profile_, NULL, nodes, 1178 bookmark_utils::OpenAll(GTK_WINDOW(window_), profile_, NULL, nodes,
1196 CURRENT_TAB); 1179 CURRENT_TAB);
1197 } 1180 }
1198 1181
1199 // static 1182 void BookmarkManagerGtk::OnLeftTreeViewFocusIn(GtkWidget* tree_view,
1200 void BookmarkManagerGtk::OnLeftTreeViewFocusIn( 1183 GdkEventFocus* event) {
1201 GtkTreeView* tree_view, 1184 if (!organize_is_for_left_)
1202 GdkEventFocus* event, 1185 ResetOrganizeMenu(true);
1203 BookmarkManagerGtk* bm) {
1204 if (!bm->organize_is_for_left_)
1205 bm->ResetOrganizeMenu(true);
1206 } 1186 }
1207 1187
1208 // static 1188 void BookmarkManagerGtk::OnRightTreeViewFocusIn(GtkWidget* tree_view,
1209 void BookmarkManagerGtk::OnRightTreeViewFocusIn( 1189 GdkEventFocus* event) {
1210 GtkTreeView* tree_view, 1190 if (organize_is_for_left_)
1211 GdkEventFocus* event, 1191 ResetOrganizeMenu(false);
1212 BookmarkManagerGtk* bm) {
1213 if (bm->organize_is_for_left_)
1214 bm->ResetOrganizeMenu(false);
1215 } 1192 }
1216 1193
1217 // We do a couple things in this handler. 1194 // We do a couple things in this handler.
1218 // 1195 //
1219 // 1. On left clicks that occur below the lowest row, unselect all selected 1196 // 1. On left clicks that occur below the lowest row, unselect all selected
1220 // rows. This is not a native GtkTreeView behavior, but it is added by libegg 1197 // rows. This is not a native GtkTreeView behavior, but it is added by libegg
1221 // and is thus present in Nautilus. This is the path == NULL path. 1198 // and is thus present in Nautilus. This is the path == NULL path.
1222 // 2. Cache left clicks that occur on an already active selection. If the user 1199 // 2. Cache left clicks that occur on an already active selection. If the user
1223 // begins a drag, then we will throw away this event and initiate a drag on the 1200 // begins a drag, then we will throw away this event and initiate a drag on the
1224 // tree view manually. If the user doesn't begin a drag (e.g. just releases the 1201 // tree view manually. If the user doesn't begin a drag (e.g. just releases the
1225 // button), send both events to the tree view. This is a workaround for 1202 // button), send both events to the tree view. This is a workaround for
1226 // http://crbug.com/15240. If we don't do this, when the user tries to drag 1203 // http://crbug.com/15240. If we don't do this, when the user tries to drag
1227 // a group of selected rows, the click at the start of the drag will deselect 1204 // a group of selected rows, the click at the start of the drag will deselect
1228 // all rows except the one the cursor is over. 1205 // all rows except the one the cursor is over.
1229 // 1206 //
1230 // We return TRUE for when we want to ignore events (i.e., stop the default 1207 // We return TRUE for when we want to ignore events (i.e., stop the default
1231 // handler from handling them), and FALSE for when we want to continue 1208 // handler from handling them), and FALSE for when we want to continue
1232 // propagation. 1209 // propagation.
1233 //
1234 // static
1235 gboolean BookmarkManagerGtk::OnRightTreeViewButtonPress( 1210 gboolean BookmarkManagerGtk::OnRightTreeViewButtonPress(
1236 GtkWidget* tree_view, GdkEventButton* event, BookmarkManagerGtk* bm) { 1211 GtkWidget* tree_view, GdkEventButton* event) {
1237 // Always let cached mousedown events through. 1212 // Always let cached mousedown events through.
1238 if (bm->sending_delayed_mousedown_) 1213 if (sending_delayed_mousedown_)
1239 return FALSE; 1214 return FALSE;
1240 1215
1241 if (event->button != 1) 1216 if (event->button != 1)
1242 return FALSE; 1217 return FALSE;
1243 1218
1244 // If a user double clicks, we will get two button presses in a row without 1219 // If a user double clicks, we will get two button presses in a row without
1245 // any intervening mouse up, hence we must flush delayed mousedowns here as 1220 // any intervening mouse up, hence we must flush delayed mousedowns here as
1246 // well as in the button release handler. 1221 // well as in the button release handler.
1247 if (bm->delaying_mousedown_) { 1222 if (delaying_mousedown_) {
1248 bm->SendDelayedMousedown(); 1223 SendDelayedMousedown();
1249 return FALSE; 1224 return FALSE;
1250 } 1225 }
1251 1226
1252 if (event->window != gtk_tree_view_get_bin_window(GTK_TREE_VIEW(tree_view))) 1227 if (event->window != gtk_tree_view_get_bin_window(GTK_TREE_VIEW(tree_view)))
1253 return FALSE; 1228 return FALSE;
1254 1229
1255 gint tree_x, tree_y; 1230 gint tree_x, tree_y;
1256 gtk_tree_view_convert_bin_window_to_widget_coords( 1231 gtk_tree_view_convert_bin_window_to_widget_coords(
1257 GTK_TREE_VIEW(tree_view), 1232 GTK_TREE_VIEW(tree_view),
1258 static_cast<gint>(event->x), 1233 static_cast<gint>(event->x),
1259 static_cast<gint>(event->y), 1234 static_cast<gint>(event->y),
1260 &tree_x, &tree_y); 1235 &tree_x, &tree_y);
1261 1236
1262 GtkTreePath* path; 1237 GtkTreePath* path;
1263 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tree_view), 1238 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tree_view),
1264 tree_x, tree_y, 1239 tree_x, tree_y,
1265 &path, NULL, NULL, NULL); 1240 &path, NULL, NULL, NULL);
1266 1241
1267 if (path == NULL) { 1242 if (path == NULL) {
1268 // Checking that the widget already has focus matches libegg behavior. 1243 // Checking that the widget already has focus matches libegg behavior.
1269 if (GTK_WIDGET_HAS_FOCUS(tree_view)) 1244 if (GTK_WIDGET_HAS_FOCUS(tree_view))
1270 gtk_tree_selection_unselect_all(bm->right_selection()); 1245 gtk_tree_selection_unselect_all(right_selection());
1271 return FALSE; 1246 return FALSE;
1272 } 1247 }
1273 1248
1274 if (gtk_tree_selection_path_is_selected(bm->right_selection(), path)) { 1249 if (gtk_tree_selection_path_is_selected(right_selection(), path)) {
1275 bm->mousedown_event_ = *event; 1250 mousedown_event_ = *event;
1276 bm->delaying_mousedown_ = true; 1251 delaying_mousedown_ = true;
1277 gtk_tree_path_free(path); 1252 gtk_tree_path_free(path);
1278 return TRUE; 1253 return TRUE;
1279 } 1254 }
1280 1255
1281 gtk_tree_path_free(path); 1256 gtk_tree_path_free(path);
1282 return FALSE; 1257 return FALSE;
1283 } 1258 }
1284 1259
1285 // static
1286 gboolean BookmarkManagerGtk::OnRightTreeViewMotion( 1260 gboolean BookmarkManagerGtk::OnRightTreeViewMotion(
1287 GtkWidget* tree_view, GdkEventMotion* event, BookmarkManagerGtk* bm) { 1261 GtkWidget* tree_view, GdkEventMotion* event) {
1288 // Swallow motion events when no row is selected. This prevents the initiation 1262 // Swallow motion events when no row is selected. This prevents the initiation
1289 // of empty drags. 1263 // of empty drags.
1290 if (gtk_tree_selection_count_selected_rows(bm->right_selection()) == 0) 1264 if (gtk_tree_selection_count_selected_rows(right_selection()) == 0)
1291 return TRUE; 1265 return TRUE;
1292 1266
1293 // Otherwise this handler is only used for the multi-drag workaround. 1267 // Otherwise this handler is only used for the multi-drag workaround.
1294 if (!bm->delaying_mousedown_) 1268 if (!delaying_mousedown_)
1295 return FALSE; 1269 return FALSE;
1296 1270
1297 if (gtk_drag_check_threshold(tree_view, 1271 if (gtk_drag_check_threshold(tree_view,
1298 static_cast<gint>(bm->mousedown_event_.x), 1272 static_cast<gint>(mousedown_event_.x),
1299 static_cast<gint>(bm->mousedown_event_.y), 1273 static_cast<gint>(mousedown_event_.y),
1300 static_cast<gint>(event->x), 1274 static_cast<gint>(event->x),
1301 static_cast<gint>(event->y))) { 1275 static_cast<gint>(event->y))) {
1302 bm->delaying_mousedown_ = false; 1276 delaying_mousedown_ = false;
1303 GtkTargetList* targets = gtk_dnd_util::GetTargetListFromCodeMask( 1277 GtkTargetList* targets = gtk_dnd_util::GetTargetListFromCodeMask(
1304 kSourceTargetMask); 1278 kSourceTargetMask);
1305 gtk_drag_begin(tree_view, targets, GDK_ACTION_MOVE, 1279 gtk_drag_begin(tree_view, targets, GDK_ACTION_MOVE,
1306 1, reinterpret_cast<GdkEvent*>(event)); 1280 1, reinterpret_cast<GdkEvent*>(event));
1307 // The drag adds a ref; let it own the list. 1281 // The drag adds a ref; let it own the list.
1308 gtk_target_list_unref(targets); 1282 gtk_target_list_unref(targets);
1309 } 1283 }
1310 1284
1311 return FALSE; 1285 return FALSE;
1312 } 1286 }
1313 1287
1314 // static
1315 gboolean BookmarkManagerGtk::OnTreeViewButtonPress( 1288 gboolean BookmarkManagerGtk::OnTreeViewButtonPress(
1316 GtkWidget* tree_view, GdkEventButton* button, BookmarkManagerGtk* bm) { 1289 GtkWidget* tree_view, GdkEventButton* button) {
1317 if (button->button != 3) 1290 if (button->button != 3)
1318 return FALSE; 1291 return FALSE;
1319 1292
1320 if (bm->ignore_rightclicks_) 1293 if (ignore_rightclicks_)
1321 return FALSE; 1294 return FALSE;
1322 1295
1323 // If the cursor is not hovering over a selected row, let it propagate 1296 // If the cursor is not hovering over a selected row, let it propagate
1324 // to the default handler so that a selection change may occur. 1297 // to the default handler so that a selection change may occur.
1325 if (!CursorIsOverSelection(GTK_TREE_VIEW(tree_view))) { 1298 if (!CursorIsOverSelection(GTK_TREE_VIEW(tree_view))) {
1326 bm->ignore_rightclicks_ = true; 1299 ignore_rightclicks_ = true;
1327 gtk_propagate_event(tree_view, reinterpret_cast<GdkEvent*>(button)); 1300 gtk_propagate_event(tree_view, reinterpret_cast<GdkEvent*>(button));
1328 bm->ignore_rightclicks_ = false; 1301 ignore_rightclicks_ = false;
1329 } 1302 }
1330 1303
1331 bm->context_menu_->PopupAsContext(button->time); 1304 context_menu_->PopupAsContext(button->time);
1332 return TRUE; 1305 return TRUE;
1333 } 1306 }
1334 1307
1335 // static
1336 gboolean BookmarkManagerGtk::OnTreeViewButtonRelease( 1308 gboolean BookmarkManagerGtk::OnTreeViewButtonRelease(
1337 GtkWidget* tree_view, GdkEventButton* button, BookmarkManagerGtk* bm) { 1309 GtkWidget* tree_view, GdkEventButton* button) {
1338 if (bm->delaying_mousedown_ && (tree_view == bm->right_tree_view_)) 1310 if (delaying_mousedown_ && (tree_view == right_tree_view_))
1339 bm->SendDelayedMousedown(); 1311 SendDelayedMousedown();
1340 1312
1341 return FALSE; 1313 return FALSE;
1342 } 1314 }
1343 1315
1344 // static 1316 gboolean BookmarkManagerGtk::OnTreeViewKeyPress(GtkWidget* tree_view,
1345 gboolean BookmarkManagerGtk::OnTreeViewKeyPress( 1317 GdkEventKey* key) {
1346 GtkWidget* tree_view, GdkEventKey* key, BookmarkManagerGtk* bm) {
1347 int command = -1; 1318 int command = -1;
1348 1319
1349 if ((key->state & gtk_accelerator_get_default_mod_mask()) == 1320 if ((key->state & gtk_accelerator_get_default_mod_mask()) ==
1350 GDK_SHIFT_MASK) { 1321 GDK_SHIFT_MASK) {
1351 if (key->keyval == GDK_Delete) 1322 if (key->keyval == GDK_Delete)
1352 command = IDS_CUT; 1323 command = IDS_CUT;
1353 else if (key->keyval == GDK_Insert) 1324 else if (key->keyval == GDK_Insert)
1354 command = IDS_PASTE; 1325 command = IDS_PASTE;
1355 } else if ((key->state & gtk_accelerator_get_default_mod_mask()) == 1326 } else if ((key->state & gtk_accelerator_get_default_mod_mask()) ==
1356 GDK_CONTROL_MASK) { 1327 GDK_CONTROL_MASK) {
(...skipping 11 matching lines...) Expand all
1368 default: 1339 default:
1369 break; 1340 break;
1370 } 1341 }
1371 } else if (key->keyval == GDK_Delete) { 1342 } else if (key->keyval == GDK_Delete) {
1372 command = IDS_BOOKMARK_BAR_REMOVE; 1343 command = IDS_BOOKMARK_BAR_REMOVE;
1373 } 1344 }
1374 1345
1375 if (command == -1) 1346 if (command == -1)
1376 return FALSE; 1347 return FALSE;
1377 1348
1378 if (bm->organize_menu_controller_.get() && 1349 if (organize_menu_controller_.get() &&
1379 bm->organize_menu_controller_->IsCommandIdEnabled(command)) { 1350 organize_menu_controller_->IsCommandIdEnabled(command)) {
1380 bm->organize_menu_controller_->ExecuteCommand(command); 1351 organize_menu_controller_->ExecuteCommand(command);
1381 return TRUE; 1352 return TRUE;
1382 } 1353 }
1383 1354
1384 return FALSE; 1355 return FALSE;
1385 } 1356 }
1386 1357
1387 // static 1358 // static
1388 void BookmarkManagerGtk::OnFolderNameEdited(GtkCellRendererText* render, 1359 void BookmarkManagerGtk::OnFolderNameEdited(GtkCellRendererText* render,
1389 gchar* path, gchar* new_folder_name, BookmarkManagerGtk* bm) { 1360 gchar* path, gchar* new_folder_name, BookmarkManagerGtk* bm) {
1390 // A folder named was edited in place. Sync the change to the bookmark 1361 // A folder named was edited in place. Sync the change to the bookmark
1391 // model. 1362 // model.
1392 GtkTreeIter iter; 1363 GtkTreeIter iter;
1393 GtkTreePath* tree_path = gtk_tree_path_new_from_string(path); 1364 GtkTreePath* tree_path = gtk_tree_path_new_from_string(path);
1394 gboolean rv = gtk_tree_model_get_iter(GTK_TREE_MODEL(bm->left_store_), 1365 gboolean rv = gtk_tree_model_get_iter(GTK_TREE_MODEL(bm->left_store_),
1395 &iter, tree_path); 1366 &iter, tree_path);
1396 DCHECK(rv); 1367 DCHECK(rv);
1397 bm->model_->SetTitle(bm->GetNodeAt(GTK_TREE_MODEL(bm->left_store_), &iter), 1368 bm->model_->SetTitle(bm->GetNodeAt(GTK_TREE_MODEL(bm->left_store_), &iter),
1398 UTF8ToWide(new_folder_name)); 1369 UTF8ToWide(new_folder_name));
1399 } 1370 }
1400 1371
1401 // static 1372 void BookmarkManagerGtk::OnImportItemActivated(GtkWidget* menuitem) {
1402 void BookmarkManagerGtk::OnImportItemActivated(
1403 GtkMenuItem* menuitem, BookmarkManagerGtk* bm) {
1404 SelectFileDialog::FileTypeInfo file_type_info; 1373 SelectFileDialog::FileTypeInfo file_type_info;
1405 file_type_info.extensions.resize(1); 1374 file_type_info.extensions.resize(1);
1406 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html")); 1375 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html"));
1407 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("htm")); 1376 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("htm"));
1408 file_type_info.include_all_files = true; 1377 file_type_info.include_all_files = true;
1409 bm->select_file_dialog_->SelectFile( 1378 select_file_dialog_->SelectFile(
1410 SelectFileDialog::SELECT_OPEN_FILE, string16(), 1379 SelectFileDialog::SELECT_OPEN_FILE, string16(),
1411 FilePath(""), &file_type_info, 0, 1380 FilePath(""), &file_type_info, 0,
1412 std::string(), GTK_WINDOW(bm->window_), 1381 std::string(), GTK_WINDOW(window_),
1413 reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_IMPORT_MENU)); 1382 reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_IMPORT_MENU));
1414 } 1383 }
1415 1384
1416 // static 1385 void BookmarkManagerGtk::OnExportItemActivated(GtkWidget* menuitem) {
1417 void BookmarkManagerGtk::OnExportItemActivated(
1418 GtkMenuItem* menuitem, BookmarkManagerGtk* bm) {
1419 SelectFileDialog::FileTypeInfo file_type_info; 1386 SelectFileDialog::FileTypeInfo file_type_info;
1420 file_type_info.extensions.resize(1); 1387 file_type_info.extensions.resize(1);
1421 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html")); 1388 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html"));
1422 file_type_info.include_all_files = true; 1389 file_type_info.include_all_files = true;
1423 // TODO(estade): If a user exports a bookmark file then we will remember the 1390 // TODO(estade): If a user exports a bookmark file then we will remember the
1424 // download location. If the user subsequently downloads a file, we will 1391 // download location. If the user subsequently downloads a file, we will
1425 // suggest this cached download location. This is bad! We ought to remember 1392 // suggest this cached download location. This is bad! We ought to remember
1426 // save locations differently for different user tasks. 1393 // save locations differently for different user tasks.
1427 FilePath suggested_path; 1394 FilePath suggested_path;
1428 PathService::Get(chrome::DIR_USER_DATA, &suggested_path); 1395 PathService::Get(chrome::DIR_USER_DATA, &suggested_path);
1429 bm->select_file_dialog_->SelectFile( 1396 select_file_dialog_->SelectFile(
1430 SelectFileDialog::SELECT_SAVEAS_FILE, string16(), 1397 SelectFileDialog::SELECT_SAVEAS_FILE, string16(),
1431 suggested_path.Append("bookmarks.html"), &file_type_info, 0, 1398 suggested_path.Append("bookmarks.html"), &file_type_info, 0,
1432 "html", GTK_WINDOW(bm->window_), 1399 "html", GTK_WINDOW(window_),
1433 reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_EXPORT_MENU)); 1400 reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_EXPORT_MENU));
1434 } 1401 }
1435 1402
1436 // static 1403 void BookmarkManagerGtk::OnSyncStatusMenuActivated(GtkWidget* menu_item) {
1437 void BookmarkManagerGtk::OnSyncStatusMenuActivated(GtkMenuItem* menu_item, 1404 if (sync_relogin_required_) {
1438 BookmarkManagerGtk* bm) { 1405 DCHECK(sync_service_);
1439 if (bm->sync_relogin_required_) { 1406 sync_service_->ShowLoginDialog();
1440 DCHECK(bm->sync_service_);
1441 bm->sync_service_->ShowLoginDialog();
1442 } else { 1407 } else {
1443 sync_ui_util::OpenSyncMyBookmarksDialog( 1408 sync_ui_util::OpenSyncMyBookmarksDialog(
1444 bm->profile_, ProfileSyncService::START_FROM_BOOKMARK_MANAGER); 1409 profile_, ProfileSyncService::START_FROM_BOOKMARK_MANAGER);
1445 } 1410 }
1446 } 1411 }
1447 1412
1448 gboolean BookmarkManagerGtk::OnWindowDestroyed(GtkWidget* window) { 1413 gboolean BookmarkManagerGtk::OnWindowDestroyed(GtkWidget* window) {
1449 DCHECK_EQ(this, manager); 1414 DCHECK_EQ(this, manager);
1450 1415
1451 if (g_browser_process->local_state()) { 1416 if (g_browser_process->local_state()) {
1452 DictionaryValue* placement_pref = 1417 DictionaryValue* placement_pref =
1453 g_browser_process->local_state()->GetMutableDictionary( 1418 g_browser_process->local_state()->GetMutableDictionary(
1454 prefs::kBookmarkManagerPlacement); 1419 prefs::kBookmarkManagerPlacement);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 username); 1520 username);
1556 } else if (sync_service_->SetupInProgress()) { 1521 } else if (sync_service_->SetupInProgress()) {
1557 status_label = l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS); 1522 status_label = l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS);
1558 } else { 1523 } else {
1559 status_label = l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL); 1524 status_label = l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL);
1560 } 1525 }
1561 GtkWidget* sync_status_label = gtk_bin_get_child(GTK_BIN(sync_status_menu_)); 1526 GtkWidget* sync_status_label = gtk_bin_get_child(GTK_BIN(sync_status_menu_));
1562 gtk_label_set_label(GTK_LABEL(sync_status_label), 1527 gtk_label_set_label(GTK_LABEL(sync_status_label),
1563 UTF16ToUTF8(status_label).c_str()); 1528 UTF16ToUTF8(status_label).c_str());
1564 } 1529 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/bookmark_manager_gtk.h ('k') | chrome/browser/gtk/bookmark_menu_controller_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698