summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-03 10:00:57 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-03 10:00:57 +0000
commitce29eeeb501db818f8f91158fd0f740a9673db61 (patch)
tree482be176eebfa02b76b775efc7122a4785fadac4
parente918f175a6293932fc4c682108cf3c9945671f60 (diff)
downloadchromium_src-ce29eeeb501db818f8f91158fd0f740a9673db61.zip
chromium_src-ce29eeeb501db818f8f91158fd0f740a9673db61.tar.gz
chromium_src-ce29eeeb501db818f8f91158fd0f740a9673db61.tar.bz2
Implement the base for the BookmarkBubble UI.
Additionally set the transient on the InfoBubble dialog window. BUG=11738 Review URL: http://codereview.chromium.org/119042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17472 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/bookmark_bubble_gtk.cc84
-rw-r--r--chrome/browser/gtk/bookmark_bubble_gtk.h6
-rw-r--r--chrome/browser/gtk/info_bubble_gtk.cc12
-rw-r--r--chrome/browser/gtk/info_bubble_gtk.h7
-rw-r--r--chrome/browser/gtk/toolbar_star_toggle_gtk.cc7
5 files changed, 94 insertions, 22 deletions
diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.cc b/chrome/browser/gtk/bookmark_bubble_gtk.cc
index 91b4c8d..310f00b 100644
--- a/chrome/browser/gtk/bookmark_bubble_gtk.cc
+++ b/chrome/browser/gtk/bookmark_bubble_gtk.cc
@@ -6,9 +6,13 @@
#include <gtk/gtk.h>
+#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
#include "base/basictypes.h"
#include "base/logging.h"
+#include "chrome/browser/gtk/gtk_chrome_link_button.h"
#include "chrome/browser/gtk/info_bubble_gtk.h"
+#include "grit/generated_resources.h"
namespace {
@@ -21,10 +25,16 @@ BookmarkBubbleGtk* g_bubble = NULL;
// saving the state.
gint g_last_active = 0;
+void HandleCloseButton(GtkWidget* widget,
+ gpointer user_data) {
+ reinterpret_cast<InfoBubbleGtk*>(user_data)->Close();
+}
+
} // namespace
// static
-void BookmarkBubbleGtk::Show(const gfx::Rect& rect,
+void BookmarkBubbleGtk::Show(GtkWindow* transient_toplevel,
+ const gfx::Rect& rect,
Profile* profile,
const GURL& url,
bool newly_bookmarked) {
@@ -34,7 +44,8 @@ void BookmarkBubbleGtk::Show(const gfx::Rect& rect,
// think that closing the previous bubble and opening the new one would make
// more sense, but I guess then you would commit the bubble's changes.
DCHECK(!g_bubble);
- g_bubble = new BookmarkBubbleGtk(rect, profile, url, newly_bookmarked);
+ g_bubble = new BookmarkBubbleGtk(transient_toplevel, rect, profile,
+ url, newly_bookmarked);
}
void BookmarkBubbleGtk::InfoBubbleClosing(InfoBubbleGtk* info_bubble,
@@ -43,7 +54,8 @@ void BookmarkBubbleGtk::InfoBubbleClosing(InfoBubbleGtk* info_bubble,
g_last_active = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_));
}
-BookmarkBubbleGtk::BookmarkBubbleGtk(const gfx::Rect& rect,
+BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel,
+ const gfx::Rect& rect,
Profile* profile,
const GURL& url,
bool newly_bookmarked)
@@ -51,11 +63,29 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(const gfx::Rect& rect,
newly_bookmarked_(newly_bookmarked),
content_(NULL),
combo_(NULL) {
- // TODO(deanm): Implement the real bookmark bubble. For now we just have
- // a placeholder for testing that input and focus works correctly.
+ GtkWidget* label = gtk_label_new(l10n_util::GetStringUTF8(
+ newly_bookmarked_ ? IDS_BOOMARK_BUBBLE_PAGE_BOOKMARKED :
+ IDS_BOOMARK_BUBBLE_PAGE_BOOKMARK).c_str());
+ GtkWidget* remove_button = gtk_chrome_link_button_new(
+ l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_REMOVE_BOOKMARK).c_str());
+ GtkWidget* name_label = gtk_label_new(
+ l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_TITLE_TEXT).c_str());
+ GtkWidget* folder_label = gtk_label_new(
+ l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_FOLDER_TEXT).c_str());
+ GtkWidget* edit_button = gtk_button_new_with_label(
+ l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_OPTIONS).c_str());
+ GtkWidget* close_button = gtk_button_new_with_label(
+ l10n_util::GetStringUTF8(IDS_CLOSE).c_str());
+
GtkWidget* content = gtk_vbox_new(FALSE, 5);
- gtk_box_pack_start(GTK_BOX(content), gtk_label_new("Hej!"), TRUE, TRUE, 0);
- gtk_box_pack_start(GTK_BOX(content), gtk_entry_new(), TRUE, TRUE, 0);
+ GtkWidget* top = gtk_hbox_new(FALSE, 0);
+
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 1);
+ gtk_box_pack_start(GTK_BOX(top), label,
+ TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(top), remove_button,
+ FALSE, FALSE, 0);
+
// Use a combo box just to make sure popup windows work in the bubble content
// and we're not fighting with the bubble for the grab.
combo_ = gtk_combo_box_new_text();
@@ -63,16 +93,52 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(const gfx::Rect& rect,
gtk_combo_box_append_text(GTK_COMBO_BOX(combo_), "entry 2");
gtk_combo_box_append_text(GTK_COMBO_BOX(combo_), "entry 3");
gtk_combo_box_set_active(GTK_COMBO_BOX(combo_), g_last_active);
- gtk_box_pack_start(GTK_BOX(content), combo_, TRUE, TRUE, 0);
+
+ GtkWidget* name_entry = gtk_entry_new();
+
+ GtkWidget* table = gtk_table_new(2, 2, FALSE);
+ gtk_table_set_row_spacings(GTK_TABLE(table), 5);
+ gtk_table_set_col_spacings(GTK_TABLE(table), 10);
+ gtk_table_attach_defaults(GTK_TABLE(table),
+ name_label,
+ 0, 1, 0, 1);
+ gtk_table_attach_defaults(GTK_TABLE(table),
+ name_entry,
+ 1, 2, 0, 1);
+ gtk_table_attach_defaults(GTK_TABLE(table),
+ folder_label,
+ 0, 1, 1, 2);
+ gtk_table_attach_defaults(GTK_TABLE(table),
+ combo_,
+ 1, 2, 1, 2);
+
+ GtkWidget* bottom = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(bottom), gtk_label_new(""),
+ TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(bottom), edit_button,
+ FALSE, FALSE, 4);
+ gtk_box_pack_start(GTK_BOX(bottom), close_button,
+ FALSE, FALSE, 0);
+
+ gtk_box_pack_start(GTK_BOX(content), top, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(content), table, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(content), bottom, TRUE, TRUE, 0);
+ // We want the focus to start on the entry, not on the remove button.
+ gtk_container_set_focus_child(GTK_CONTAINER(content), table);
g_signal_connect(content, "destroy",
G_CALLBACK(&HandleDestroyThunk), this);
// TODO(deanm): In the future we might want to hang on to the returned
// InfoBubble so that we can call Close() on it.
- if (!InfoBubbleGtk::Show(rect, content, this)) {
+ InfoBubbleGtk* bubble = InfoBubbleGtk::Show(transient_toplevel,
+ rect, content, this);
+ if (!bubble) {
NOTREACHED();
}
+
+ g_signal_connect(close_button, "clicked",
+ G_CALLBACK(&HandleCloseButton), bubble);
}
BookmarkBubbleGtk::~BookmarkBubbleGtk() {
diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.h b/chrome/browser/gtk/bookmark_bubble_gtk.h
index 123ff81..5192413 100644
--- a/chrome/browser/gtk/bookmark_bubble_gtk.h
+++ b/chrome/browser/gtk/bookmark_bubble_gtk.h
@@ -26,7 +26,8 @@ class Rect;
class BookmarkBubbleGtk : public InfoBubbleGtkDelegate {
public:
// Shows the bookmark bubble, pointing at |rect|.
- static void Show(const gfx::Rect& rect,
+ static void Show(GtkWindow* transient_toplevel,
+ const gfx::Rect& rect,
Profile* profile,
const GURL& url,
bool newly_bookmarked);
@@ -38,7 +39,8 @@ class BookmarkBubbleGtk : public InfoBubbleGtkDelegate {
bool closed_by_escape);
private:
- BookmarkBubbleGtk(const gfx::Rect& rect,
+ BookmarkBubbleGtk(GtkWindow* transient_toplevel,
+ const gfx::Rect& rect,
Profile* profile,
const GURL& url,
bool newly_bookmarked);
diff --git a/chrome/browser/gtk/info_bubble_gtk.cc b/chrome/browser/gtk/info_bubble_gtk.cc
index cff694b..e171e3b 100644
--- a/chrome/browser/gtk/info_bubble_gtk.cc
+++ b/chrome/browser/gtk/info_bubble_gtk.cc
@@ -116,11 +116,12 @@ gboolean HandleExpose(GtkWidget* widget,
} // namespace
// static
-InfoBubbleGtk* InfoBubbleGtk::Show(const gfx::Rect& rect,
+InfoBubbleGtk* InfoBubbleGtk::Show(GtkWindow* transient_toplevel,
+ const gfx::Rect& rect,
GtkWidget* content,
InfoBubbleGtkDelegate* delegate) {
InfoBubbleGtk* bubble = new InfoBubbleGtk();
- bubble->Init(rect, content);
+ bubble->Init(transient_toplevel, rect, content);
bubble->set_delegate(delegate);
return bubble;
}
@@ -130,18 +131,21 @@ InfoBubbleGtk::InfoBubbleGtk()
window_(NULL),
screen_x_(0),
screen_y_(0) {
-
+
}
InfoBubbleGtk::~InfoBubbleGtk() {
}
-void InfoBubbleGtk::Init(const gfx::Rect& rect, GtkWidget* content) {
+void InfoBubbleGtk::Init(GtkWindow* transient_toplevel,
+ const gfx::Rect& rect,
+ GtkWidget* content) {
DCHECK(!window_);
screen_x_ = rect.x() + (rect.width() / 2) - kArrowX;
screen_y_ = rect.y() + rect.height() + kArrowToContentPadding;
window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_transient_for(GTK_WINDOW(window_), transient_toplevel);
gtk_window_set_decorated(GTK_WINDOW(window_), FALSE);
gtk_window_set_resizable(GTK_WINDOW(window_), FALSE);
gtk_widget_set_app_paintable(window_, TRUE);
diff --git a/chrome/browser/gtk/info_bubble_gtk.h b/chrome/browser/gtk/info_bubble_gtk.h
index e88946c..0ea6c05 100644
--- a/chrome/browser/gtk/info_bubble_gtk.h
+++ b/chrome/browser/gtk/info_bubble_gtk.h
@@ -39,7 +39,8 @@ class InfoBubbleGtk {
// An infobubble will try to fit on the screen, so it can point to any edge
// of |rect|. The bubble will host the |content| widget. The |delegate|
// will be notified when things like closing are happening.
- static InfoBubbleGtk* Show(const gfx::Rect& rect,
+ static InfoBubbleGtk* Show(GtkWindow* transient_toplevel,
+ const gfx::Rect& rect,
GtkWidget* content,
InfoBubbleGtkDelegate* delegate);
@@ -52,7 +53,9 @@ class InfoBubbleGtk {
virtual ~InfoBubbleGtk();
// Creates the InfoBubble.
- void Init(const gfx::Rect& rect, GtkWidget* content);
+ void Init(GtkWindow* transient_toplevel,
+ const gfx::Rect& rect,
+ GtkWidget* content);
// Sets the delegate.
void set_delegate(InfoBubbleGtkDelegate* delegate) { delegate_ = delegate; }
diff --git a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc
index 012b478..4e03454 100644
--- a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc
+++ b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc
@@ -32,9 +32,6 @@ ToolbarStarToggleGtk::~ToolbarStarToggleGtk() {
void ToolbarStarToggleGtk::ShowStarBubble(const GURL& url,
bool newly_bookmarked) {
-// TODO(erg): Temporarily disabling the implementation of the bookmark bubble.
-// http://crbug.com/12259
-#if 0
GtkWidget* widget = widget_.get();
gint x, y;
gdk_window_get_origin(widget->window, &x, &y);
@@ -43,11 +40,11 @@ void ToolbarStarToggleGtk::ShowStarBubble(const GURL& url,
gint width = widget->allocation.width;
gint height = widget->allocation.height;
- BookmarkBubbleGtk::Show(gfx::Rect(x, y, width, height),
+ BookmarkBubbleGtk::Show(GTK_WINDOW(gtk_widget_get_toplevel(widget)),
+ gfx::Rect(x, y, width, height),
NULL,
url,
newly_bookmarked);
-#endif
}
void ToolbarStarToggleGtk::SetStarred(bool starred) {