| 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_bar_gtk.h" | 5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 gtk_drag_dest_set(bookmark_toolbar_.get(), GTK_DEST_DEFAULT_DROP, | 257 gtk_drag_dest_set(bookmark_toolbar_.get(), GTK_DEST_DEFAULT_DROP, |
| 258 NULL, 0, kDragAction); | 258 NULL, 0, kDragAction); |
| 259 ui::SetDestTargetList(bookmark_toolbar_.get(), kDestTargetList); | 259 ui::SetDestTargetList(bookmark_toolbar_.get(), kDestTargetList); |
| 260 g_signal_connect(bookmark_toolbar_.get(), "drag-motion", | 260 g_signal_connect(bookmark_toolbar_.get(), "drag-motion", |
| 261 G_CALLBACK(&OnToolbarDragMotionThunk), this); | 261 G_CALLBACK(&OnToolbarDragMotionThunk), this); |
| 262 g_signal_connect(bookmark_toolbar_.get(), "drag-leave", | 262 g_signal_connect(bookmark_toolbar_.get(), "drag-leave", |
| 263 G_CALLBACK(&OnDragLeaveThunk), this); | 263 G_CALLBACK(&OnDragLeaveThunk), this); |
| 264 g_signal_connect(bookmark_toolbar_.get(), "drag-data-received", | 264 g_signal_connect(bookmark_toolbar_.get(), "drag-data-received", |
| 265 G_CALLBACK(&OnDragReceivedThunk), this); | 265 G_CALLBACK(&OnDragReceivedThunk), this); |
| 266 | 266 |
| 267 GtkWidget* vseparator = theme_service_->CreateToolbarSeparator(); | 267 other_bookmarks_separator_ = theme_service_->CreateToolbarSeparator(); |
| 268 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), vseparator, | 268 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), other_bookmarks_separator_, |
| 269 FALSE, FALSE, 0); | 269 FALSE, FALSE, 0); |
| 270 | 270 |
| 271 // We pack the button manually (rather than using gtk_button_set_*) so that | 271 // We pack the button manually (rather than using gtk_button_set_*) so that |
| 272 // we can have finer control over its label. | 272 // we can have finer control over its label. |
| 273 other_bookmarks_button_ = theme_service_->BuildChromeButton(); | 273 other_bookmarks_button_ = theme_service_->BuildChromeButton(); |
| 274 ConnectFolderButtonEvents(other_bookmarks_button_, false); | 274 ConnectFolderButtonEvents(other_bookmarks_button_, false); |
| 275 GtkWidget* other_padding = gtk_alignment_new(0, 0, 1, 1); | 275 GtkWidget* other_padding = gtk_alignment_new(0, 0, 1, 1); |
| 276 gtk_alignment_set_padding(GTK_ALIGNMENT(other_padding), | 276 gtk_alignment_set_padding(GTK_ALIGNMENT(other_padding), |
| 277 kOtherBookmarksPaddingVertical, | 277 kOtherBookmarksPaddingVertical, |
| 278 kOtherBookmarksPaddingVertical, | 278 kOtherBookmarksPaddingVertical, |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 if (GTK_WIDGET_VISIBLE(overflow_button_)) | 532 if (GTK_WIDGET_VISIBLE(overflow_button_)) |
| 533 extra_space = overflow_button_->allocation.width; | 533 extra_space = overflow_button_->allocation.width; |
| 534 | 534 |
| 535 int overflow_idx = GetFirstHiddenBookmark(extra_space, NULL); | 535 int overflow_idx = GetFirstHiddenBookmark(extra_space, NULL); |
| 536 if (overflow_idx == -1) | 536 if (overflow_idx == -1) |
| 537 gtk_widget_hide(overflow_button_); | 537 gtk_widget_hide(overflow_button_); |
| 538 else | 538 else |
| 539 gtk_widget_show_all(overflow_button_); | 539 gtk_widget_show_all(overflow_button_); |
| 540 } | 540 } |
| 541 | 541 |
| 542 void BookmarkBarGtk::UpdateOtherBookmarksVisibility() { |
| 543 bool has_other_children = !model_->other_node()->empty(); |
| 544 if (has_other_children == gtk_widget_get_visible(other_bookmarks_button_)) |
| 545 return; |
| 546 |
| 547 gtk_widget_set_visible(other_bookmarks_button_, has_other_children); |
| 548 gtk_widget_set_visible(other_bookmarks_separator_, has_other_children); |
| 549 } |
| 550 |
| 542 void BookmarkBarGtk::RemoveAllBookmarkButtons() { | 551 void BookmarkBarGtk::RemoveAllBookmarkButtons() { |
| 543 gtk_util::RemoveAllChildren(bookmark_toolbar_.get()); | 552 gtk_util::RemoveAllChildren(bookmark_toolbar_.get()); |
| 544 menu_bar_helper_.Clear(); | 553 menu_bar_helper_.Clear(); |
| 545 menu_bar_helper_.Add(other_bookmarks_button_); | 554 menu_bar_helper_.Add(other_bookmarks_button_); |
| 546 menu_bar_helper_.Add(overflow_button_); | 555 menu_bar_helper_.Add(overflow_button_); |
| 547 } | 556 } |
| 548 | 557 |
| 549 int BookmarkBarGtk::GetBookmarkButtonCount() { | 558 int BookmarkBarGtk::GetBookmarkButtonCount() { |
| 550 GList* children = gtk_container_get_children( | 559 GList* children = gtk_container_get_children( |
| 551 GTK_CONTAINER(bookmark_toolbar_.get())); | 560 GTK_CONTAINER(bookmark_toolbar_.get())); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 gtk_toolbar_set_drop_highlight_item(GTK_TOOLBAR(bookmark_toolbar_.get()), | 830 gtk_toolbar_set_drop_highlight_item(GTK_TOOLBAR(bookmark_toolbar_.get()), |
| 822 NULL, 0); | 831 NULL, 0); |
| 823 } | 832 } |
| 824 | 833 |
| 825 void BookmarkBarGtk::Loaded(BookmarkModel* model) { | 834 void BookmarkBarGtk::Loaded(BookmarkModel* model) { |
| 826 // If |instructions_| has been nulled, we are in the middle of browser | 835 // If |instructions_| has been nulled, we are in the middle of browser |
| 827 // shutdown. Do nothing. | 836 // shutdown. Do nothing. |
| 828 if (!instructions_) | 837 if (!instructions_) |
| 829 return; | 838 return; |
| 830 | 839 |
| 840 UpdateOtherBookmarksVisibility(); |
| 831 RemoveAllBookmarkButtons(); | 841 RemoveAllBookmarkButtons(); |
| 832 CreateAllBookmarkButtons(); | 842 CreateAllBookmarkButtons(); |
| 833 } | 843 } |
| 834 | 844 |
| 835 void BookmarkBarGtk::BookmarkModelBeingDeleted(BookmarkModel* model) { | 845 void BookmarkBarGtk::BookmarkModelBeingDeleted(BookmarkModel* model) { |
| 836 // The bookmark model should never be deleted before us. This code exists | 846 // The bookmark model should never be deleted before us. This code exists |
| 837 // to check for regressions in shutdown code and not crash. | 847 // to check for regressions in shutdown code and not crash. |
| 838 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) | 848 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) |
| 839 NOTREACHED(); | 849 NOTREACHED(); |
| 840 | 850 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 862 return; | 872 return; |
| 863 } | 873 } |
| 864 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); | 874 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); |
| 865 | 875 |
| 866 GtkToolItem* item = CreateBookmarkToolItem(node); | 876 GtkToolItem* item = CreateBookmarkToolItem(node); |
| 867 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()), | 877 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()), |
| 868 item, index); | 878 item, index); |
| 869 if (node->is_folder()) | 879 if (node->is_folder()) |
| 870 menu_bar_helper_.Add(gtk_bin_get_child(GTK_BIN(item))); | 880 menu_bar_helper_.Add(gtk_bin_get_child(GTK_BIN(item))); |
| 871 | 881 |
| 882 UpdateOtherBookmarksVisibility(); |
| 872 SetInstructionState(); | 883 SetInstructionState(); |
| 873 SetChevronState(); | 884 SetChevronState(); |
| 874 | 885 |
| 875 StartThrobbingAfterAllocation(GTK_WIDGET(item)); | 886 StartThrobbingAfterAllocation(GTK_WIDGET(item)); |
| 876 } | 887 } |
| 877 | 888 |
| 878 void BookmarkBarGtk::BookmarkNodeRemoved(BookmarkModel* model, | 889 void BookmarkBarGtk::BookmarkNodeRemoved(BookmarkModel* model, |
| 879 const BookmarkNode* parent, | 890 const BookmarkNode* parent, |
| 880 int old_index, | 891 int old_index, |
| 881 const BookmarkNode* node) { | 892 const BookmarkNode* node) { |
| 882 if (parent != model_->GetBookmarkBarNode()) { | 893 if (parent != model_->GetBookmarkBarNode()) { |
| 883 // We only care about nodes on the bookmark bar. | 894 // We only care about nodes on the bookmark bar. |
| 884 return; | 895 return; |
| 885 } | 896 } |
| 886 DCHECK(old_index >= 0 && old_index < GetBookmarkButtonCount()); | 897 DCHECK(old_index >= 0 && old_index < GetBookmarkButtonCount()); |
| 887 | 898 |
| 888 GtkWidget* to_remove = GTK_WIDGET(gtk_toolbar_get_nth_item( | 899 GtkWidget* to_remove = GTK_WIDGET(gtk_toolbar_get_nth_item( |
| 889 GTK_TOOLBAR(bookmark_toolbar_.get()), old_index)); | 900 GTK_TOOLBAR(bookmark_toolbar_.get()), old_index)); |
| 890 if (node->is_folder()) | 901 if (node->is_folder()) |
| 891 menu_bar_helper_.Remove(gtk_bin_get_child(GTK_BIN(to_remove))); | 902 menu_bar_helper_.Remove(gtk_bin_get_child(GTK_BIN(to_remove))); |
| 892 gtk_container_remove(GTK_CONTAINER(bookmark_toolbar_.get()), | 903 gtk_container_remove(GTK_CONTAINER(bookmark_toolbar_.get()), |
| 893 to_remove); | 904 to_remove); |
| 894 | 905 |
| 906 UpdateOtherBookmarksVisibility(); |
| 895 SetInstructionState(); | 907 SetInstructionState(); |
| 896 SetChevronState(); | 908 SetChevronState(); |
| 897 } | 909 } |
| 898 | 910 |
| 899 void BookmarkBarGtk::BookmarkNodeChanged(BookmarkModel* model, | 911 void BookmarkBarGtk::BookmarkNodeChanged(BookmarkModel* model, |
| 900 const BookmarkNode* node) { | 912 const BookmarkNode* node) { |
| 901 if (node->parent() != model_->GetBookmarkBarNode()) { | 913 if (node->parent() != model_->GetBookmarkBarNode()) { |
| 902 // We only care about nodes on the bookmark bar. | 914 // We only care about nodes on the bookmark bar. |
| 903 return; | 915 return; |
| 904 } | 916 } |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1444 void BookmarkBarGtk::OnEditBookmarksEnabledChanged() { | 1456 void BookmarkBarGtk::OnEditBookmarksEnabledChanged() { |
| 1445 GtkDestDefaults dest_defaults = | 1457 GtkDestDefaults dest_defaults = |
| 1446 *edit_bookmarks_enabled_ ? GTK_DEST_DEFAULT_ALL : | 1458 *edit_bookmarks_enabled_ ? GTK_DEST_DEFAULT_ALL : |
| 1447 GTK_DEST_DEFAULT_DROP; | 1459 GTK_DEST_DEFAULT_DROP; |
| 1448 gtk_drag_dest_set(overflow_button_, dest_defaults, NULL, 0, kDragAction); | 1460 gtk_drag_dest_set(overflow_button_, dest_defaults, NULL, 0, kDragAction); |
| 1449 gtk_drag_dest_set(other_bookmarks_button_, dest_defaults, | 1461 gtk_drag_dest_set(other_bookmarks_button_, dest_defaults, |
| 1450 NULL, 0, kDragAction); | 1462 NULL, 0, kDragAction); |
| 1451 ui::SetDestTargetList(overflow_button_, kDestTargetList); | 1463 ui::SetDestTargetList(overflow_button_, kDestTargetList); |
| 1452 ui::SetDestTargetList(other_bookmarks_button_, kDestTargetList); | 1464 ui::SetDestTargetList(other_bookmarks_button_, kDestTargetList); |
| 1453 } | 1465 } |
| OLD | NEW |