summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/bookmark_bar_gtk.cc
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-16 18:19:17 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-16 18:19:17 +0000
commit2b2d1697cd3cd6303b372949565bb8ac87741589 (patch)
tree2c4ca63f7e4854c1be423d74896ec71d4c80a858 /chrome/browser/gtk/bookmark_bar_gtk.cc
parent54e1d52455272e0af32b4c6080f1914f6f2c4f95 (diff)
downloadchromium_src-2b2d1697cd3cd6303b372949565bb8ac87741589.zip
chromium_src-2b2d1697cd3cd6303b372949565bb8ac87741589.tar.gz
chromium_src-2b2d1697cd3cd6303b372949565bb8ac87741589.tar.bz2
Recommit previous change with GYP files fixed.
Implement BookmarkContextMenuGtk and hook it up to most bookmark bar elements. Also: - Fixes window dispositions (shift-click works on bookmark bar items). - Reorganizes gtk_utils Original Review URL: http://codereview.chromium.org/76002 Review URL: http://codereview.chromium.org/67223 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13857 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/bookmark_bar_gtk.cc')
-rw-r--r--chrome/browser/gtk/bookmark_bar_gtk.cc79
1 files changed, 60 insertions, 19 deletions
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc
index 4c8abea..7819ad4 100644
--- a/chrome/browser/gtk/bookmark_bar_gtk.cc
+++ b/chrome/browser/gtk/bookmark_bar_gtk.cc
@@ -5,12 +5,15 @@
#include "chrome/browser/gtk/bookmark_bar_gtk.h"
#include "base/gfx/gtk_util.h"
+#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/browser.h"
+#include "chrome/browser/gtk/bookmark_context_menu_gtk.h"
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/gtk_chrome_button.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
#include "chrome/common/gfx/text_elider.h"
+#include "chrome/common/gtk_util.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
@@ -115,16 +118,20 @@ void BookmarkBarGtk::Init(Profile* profile) {
G_CALLBACK(&OnToolbarDragLeave), this);
g_signal_connect(bookmark_toolbar_.get(), "drag-drop",
G_CALLBACK(&OnToolbarDragDrop), this);
+ g_signal_connect(bookmark_toolbar_.get(), "button-press-event",
+ G_CALLBACK(&OnButtonPressed), this);
gtk_box_pack_start(GTK_BOX(bookmark_hbox_), gtk_vseparator_new(),
FALSE, FALSE, 0);
other_bookmarks_button_ = gtk_chrome_button_new();
+ g_signal_connect(other_bookmarks_button_, "button-press-event",
+ G_CALLBACK(&OnButtonPressed), this);
gtk_button_set_label(GTK_BUTTON(other_bookmarks_button_),
"Other bookmarks");
gtk_button_set_image(GTK_BUTTON(other_bookmarks_button_),
gtk_image_new_from_pixbuf(folder_icon));
- // TODO(erg): Hook up a popup menu to |other_bookmarks_button_|.
+
gtk_box_pack_start(GTK_BOX(bookmark_hbox_), other_bookmarks_button_,
FALSE, FALSE, 0);
}
@@ -343,8 +350,16 @@ std::string BookmarkBarGtk::BuildTooltip(BookmarkNode* node) {
return node->GetURL().possibly_invalid_spec();
}
-BookmarkNode* BookmarkBarGtk::GetNodeForToolButton(GtkWidget* button) {
- GtkWidget* item_to_find = gtk_widget_get_parent(button);
+BookmarkNode* BookmarkBarGtk::GetNodeForToolButton(GtkWidget* widget) {
+ // First check to see if |button| is the special cased.
+ if (widget == other_bookmarks_button_)
+ return model_->other_node();
+ else if (widget == bookmark_toolbar_.get())
+ return model_->GetBookmarkBarNode();
+
+ // Search the contents of |bookmark_toolbar_| for the corresponding widget
+ // and find its index.
+ GtkWidget* item_to_find = gtk_widget_get_parent(widget);
int index_to_use = -1;
int index = 0;
GList* children = gtk_container_get_children(
@@ -363,20 +378,49 @@ BookmarkNode* BookmarkBarGtk::GetNodeForToolButton(GtkWidget* button) {
return NULL;
}
-void BookmarkBarGtk::PopupMenuForNode(BookmarkNode* node,
+void BookmarkBarGtk::PopupMenuForNode(GtkWidget* sender, BookmarkNode* node,
GdkEventButton* event) {
- GtkWidget* menu = gtk_menu_new();
- gtk_menu_shell_append(GTK_MENU_SHELL(menu),
- gtk_menu_item_new_with_label("TODO(erg): Write menus"));
- gtk_widget_show_all(menu);
- gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button,
- event->time);
+ if (!model_->IsLoaded()) {
+ // Don't do anything if the model isn't loaded.
+ return;
+ }
+
+ BookmarkNode* parent = NULL;
+ std::vector<BookmarkNode*> nodes;
+ if (sender == other_bookmarks_button_) {
+ parent = model_->GetBookmarkBarNode();
+ nodes.push_back(parent);
+ } else if (sender != bookmark_toolbar_.get()) {
+ nodes.push_back(node);
+ parent = node->GetParent();
+ } else {
+ parent = model_->GetBookmarkBarNode();
+ nodes.push_back(parent);
+ }
+
+ current_context_menu_.reset(new BookmarkContextMenuGtk(
+ GTK_WINDOW(gtk_widget_get_toplevel(sender)),
+ profile_, browser_, page_navigator_,
+ parent, nodes,
+ BookmarkContextMenuGtk::BOOKMARK_BAR));
+ current_context_menu_->PopupAsContext(event->time);
}
+// static
gboolean BookmarkBarGtk::OnButtonPressed(GtkWidget* sender,
GdkEventButton* event,
BookmarkBarGtk* bar) {
- bar->ignore_button_release_ = false;
+ if (sender != bar->other_bookmarks_button_ &&
+ sender != bar->bookmark_toolbar_.get())
+ bar->ignore_button_release_ = false;
+
+ if (event->button == 3) {
+ BookmarkNode* node = bar->GetNodeForToolButton(sender);
+ DCHECK(node);
+ DCHECK(bar->page_navigator_);
+ bar->PopupMenuForNode(sender, node, event);
+ }
+
return FALSE;
}
@@ -393,19 +437,16 @@ gboolean BookmarkBarGtk::OnButtonReleased(GtkWidget* sender,
DCHECK(node);
DCHECK(bar->page_navigator_);
- if (event->button == 3) {
- bar->PopupMenuForNode(node, event);
- return FALSE;
- }
-
if (node->is_url()) {
bar->page_navigator_->OpenURL(
node->GetURL(), GURL(),
- // TODO(erg): Detect the disposition based on the click type.
- CURRENT_TAB,
+ event_utils::DispositionFromEventFlags(event->state),
PageTransition::AUTO_BOOKMARK);
} else {
- // TODO(erg): Handle folders and extensions.
+ bookmark_utils::OpenAll(
+ GTK_WINDOW(gtk_widget_get_toplevel(sender)), bar->profile_,
+ bar->page_navigator_, node,
+ event_utils::DispositionFromEventFlags(event->state));
}
UserMetrics::RecordAction(L"ClickedBookmarkBarURLButton", bar->profile_);