summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-03 09:50:52 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-03 09:50:52 +0000
commite918f175a6293932fc4c682108cf3c9945671f60 (patch)
tree3ddf091b7186228813357a87928b099e9372edc8 /chrome/browser/gtk
parentce560f84a2640482e7880cee4d9e4b1661fed3bc (diff)
downloadchromium_src-e918f175a6293932fc4c682108cf3c9945671f60.zip
chromium_src-e918f175a6293932fc4c682108cf3c9945671f60.tar.gz
chromium_src-e918f175a6293932fc4c682108cf3c9945671f60.tar.bz2
Make LinkButtonGtk into a real widget (GtkChromeLinkButton).
This means there are no longer two objects to keep around, the widget and the wrapper C++ object. This simplifies ownership in hierarchies. Review URL: http://codereview.chromium.org/118116 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17471 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.cc11
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.h4
-rw-r--r--chrome/browser/gtk/gtk_chrome_button.cc14
-rw-r--r--chrome/browser/gtk/gtk_chrome_link_button.cc141
-rw-r--r--chrome/browser/gtk/gtk_chrome_link_button.h56
-rw-r--r--chrome/browser/gtk/infobar_gtk.cc14
-rw-r--r--chrome/browser/gtk/link_button_gtk.cc111
-rw-r--r--chrome/browser/gtk/link_button_gtk.h52
8 files changed, 215 insertions, 188 deletions
diff --git a/chrome/browser/gtk/download_shelf_gtk.cc b/chrome/browser/gtk/download_shelf_gtk.cc
index 97a142a..005536e 100644
--- a/chrome/browser/gtk/download_shelf_gtk.cc
+++ b/chrome/browser/gtk/download_shelf_gtk.cc
@@ -11,7 +11,7 @@
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/download_item_gtk.h"
-#include "chrome/browser/gtk/link_button_gtk.h"
+#include "chrome/browser/gtk/gtk_chrome_link_button.h"
#include "chrome/browser/gtk/slide_animator_gtk.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/gtk_util.h"
@@ -95,12 +95,13 @@ DownloadShelfGtk::DownloadShelfGtk(TabContents* tab_contents)
// Create the "Show all downloads..." link and connect to the click event.
std::string link_text =
l10n_util::GetStringUTF8(IDS_SHOW_ALL_DOWNLOADS);
- link_button_.reset(new LinkButtonGtk(link_text.c_str()));
- g_signal_connect(link_button_->widget(), "clicked",
+ GtkWidget* link_button = gtk_chrome_link_button_new(link_text.c_str());
+ g_signal_connect(link_button, "clicked",
G_CALLBACK(OnButtonClick), this);
// Until we switch to vector graphics, force the font size.
// 13.4px == 10pt @ 96dpi
- gtk_util::ForceFontSizePixels(link_button_->label(), 13.4);
+ gtk_util::ForceFontSizePixels(GTK_CHROME_LINK_BUTTON(link_button)->label,
+ 13.4);
// Make the download arrow icon.
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
@@ -110,7 +111,7 @@ DownloadShelfGtk::DownloadShelfGtk(TabContents* tab_contents)
// Pack the link and the icon in an hbox.
link_hbox_ = gtk_hbox_new(FALSE, 5);
gtk_util::CenterWidgetInHBox(link_hbox_, download_image, false, 0);
- gtk_util::CenterWidgetInHBox(link_hbox_, link_button_->widget(), false, 0);
+ gtk_util::CenterWidgetInHBox(link_hbox_, link_button, false, 0);
gtk_box_pack_end(GTK_BOX(hbox_), link_hbox_, FALSE, FALSE, 0);
slide_widget_.reset(new SlideAnimatorGtk(shelf_.get(),
diff --git a/chrome/browser/gtk/download_shelf_gtk.h b/chrome/browser/gtk/download_shelf_gtk.h
index bc41647..4ed81b7 100644
--- a/chrome/browser/gtk/download_shelf_gtk.h
+++ b/chrome/browser/gtk/download_shelf_gtk.h
@@ -16,7 +16,6 @@
class BaseDownloadItemModel;
class CustomDrawButton;
class DownloadItemGtk;
-class LinkButtonGtk;
class SlideAnimatorGtk;
class DownloadShelfGtk : public DownloadShelf {
@@ -56,9 +55,6 @@ class DownloadShelfGtk : public DownloadShelf {
// distinction of being the leftmost non-download item widget on the shelf.
GtkWidget* link_hbox_;
- // The clickable "Show all downloads..." link text.
- scoped_ptr<LinkButtonGtk> link_button_;
-
// The 'x' that the user can press to hide the download shelf.
scoped_ptr<CustomDrawButton> close_button_;
diff --git a/chrome/browser/gtk/gtk_chrome_button.cc b/chrome/browser/gtk/gtk_chrome_button.cc
index 8c076c1..558e610 100644
--- a/chrome/browser/gtk/gtk_chrome_button.cc
+++ b/chrome/browser/gtk/gtk_chrome_button.cc
@@ -25,18 +25,17 @@ G_BEGIN_DECLS
GtkChromeButtonPrivate))
typedef struct _GtkChromeButtonPrivate GtkChromeButtonPrivate;
-struct _GtkChromeButtonPrivate
-{
+struct _GtkChromeButtonPrivate {
int paint_state;
};
-G_DEFINE_TYPE (GtkChromeButton, gtk_chrome_button, GTK_TYPE_BUTTON)
+G_DEFINE_TYPE(GtkChromeButton, gtk_chrome_button, GTK_TYPE_BUTTON)
static gboolean gtk_chrome_button_expose(GtkWidget* widget,
GdkEventExpose* event);
-static void gtk_chrome_button_class_init(GtkChromeButtonClass *button_class) {
- GObjectClass *gobject_class = G_OBJECT_CLASS(button_class);
- GtkWidgetClass* widget_class = (GtkWidgetClass*)button_class;
+static void gtk_chrome_button_class_init(GtkChromeButtonClass* button_class) {
+ GObjectClass* gobject_class = G_OBJECT_CLASS(button_class);
+ GtkWidgetClass* widget_class = reinterpret_cast<GtkWidgetClass*>(button_class);
widget_class->expose_event = gtk_chrome_button_expose;
g_nine_box_prelight = new NineBox(
@@ -65,7 +64,7 @@ static void gtk_chrome_button_class_init(GtkChromeButtonClass *button_class) {
}
static void gtk_chrome_button_init(GtkChromeButton* button) {
- GtkChromeButtonPrivate *priv = GTK_CHROME_BUTTON_GET_PRIVATE(button);
+ GtkChromeButtonPrivate* priv = GTK_CHROME_BUTTON_GET_PRIVATE(button);
priv->paint_state = -1;
gtk_widget_set_app_paintable(GTK_WIDGET(button), TRUE);
@@ -120,4 +119,3 @@ void gtk_chrome_button_unset_paint_state(GtkChromeButton* button) {
}
G_END_DECLS
-
diff --git a/chrome/browser/gtk/gtk_chrome_link_button.cc b/chrome/browser/gtk/gtk_chrome_link_button.cc
new file mode 100644
index 0000000..3fbb7e5
--- /dev/null
+++ b/chrome/browser/gtk/gtk_chrome_link_button.cc
@@ -0,0 +1,141 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/gtk/gtk_chrome_link_button.h"
+
+#include "base/logging.h"
+
+static const char* kLinkMarkup = "<u><span color=\"%s\">%s</span></u>";
+
+namespace {
+
+// Set the GTK style on our custom link button. We don't want any border around
+// the link text.
+void SetLinkButtonStyle() {
+ static bool style_was_set = false;
+
+ if (style_was_set)
+ return;
+ style_was_set = true;
+
+ gtk_rc_parse_string(
+ "style \"chrome-link-button\" {"
+ " GtkButton::inner-border = {0, 0, 0, 0}"
+ " xthickness = 0"
+ " ythickness = 0"
+ "}"
+ "widget \"*chrome-link-button\" style \"chrome-link-button\"");
+}
+
+} // namespace
+
+G_BEGIN_DECLS
+G_DEFINE_TYPE(GtkChromeLinkButton, gtk_chrome_link_button, GTK_TYPE_BUTTON)
+
+static gboolean gtk_chrome_link_button_expose(GtkWidget* widget,
+ GdkEventExpose* event) {
+ GtkChromeLinkButton* button = GTK_CHROME_LINK_BUTTON(widget);
+ GtkWidget* label = button->label;
+
+ if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE && button->is_blue) {
+ gtk_label_set_markup(GTK_LABEL(label), button->red_markup);
+ button->is_blue = FALSE;
+ } else if (GTK_WIDGET_STATE(widget) != GTK_STATE_ACTIVE && !button->is_blue) {
+ gtk_label_set_markup(GTK_LABEL(label), button->blue_markup);
+ button->is_blue = TRUE;
+ }
+
+ // Draw the link inside the button.
+ gtk_container_propagate_expose(GTK_CONTAINER(widget), label, event);
+
+ // Draw the focus rectangle.
+ if (GTK_WIDGET_HAS_FOCUS(widget)) {
+ gtk_paint_focus(widget->style, widget->window,
+ static_cast<GtkStateType>(GTK_WIDGET_STATE(widget)),
+ &event->area, widget, NULL,
+ widget->allocation.x, widget->allocation.y,
+ widget->allocation.width, widget->allocation.height);
+ }
+
+ return TRUE;
+}
+
+static void gtk_chrome_link_button_enter(GtkButton* button) {
+ GtkWidget* widget = GTK_WIDGET(button);
+ GtkChromeLinkButton* link_button = GTK_CHROME_LINK_BUTTON(button);
+ gdk_window_set_cursor(widget->window, link_button->hand_cursor);
+}
+
+static void gtk_chrome_link_button_leave(GtkButton* button) {
+ GtkWidget* widget = GTK_WIDGET(button);
+ gdk_window_set_cursor(widget->window, NULL);
+}
+
+static void gtk_chrome_link_button_destroy(GtkObject* object) {
+ GtkChromeLinkButton* button = GTK_CHROME_LINK_BUTTON(object);
+ if (button->blue_markup) {
+ g_free(button->blue_markup);
+ button->blue_markup = NULL;
+ }
+ if (button->red_markup) {
+ g_free(button->red_markup);
+ button->red_markup = NULL;
+ }
+ if (button->hand_cursor) {
+ gdk_cursor_unref(button->hand_cursor);
+ button->hand_cursor = NULL;
+ }
+
+ GTK_OBJECT_CLASS(gtk_chrome_link_button_parent_class)->destroy(object);
+}
+
+static void gtk_chrome_link_button_class_init(
+ GtkChromeLinkButtonClass* link_button_class) {
+ GtkWidgetClass* widget_class =
+ reinterpret_cast<GtkWidgetClass*>(link_button_class);
+ GtkButtonClass* button_class =
+ reinterpret_cast<GtkButtonClass*>(link_button_class);
+ GtkObjectClass* object_class =
+ reinterpret_cast<GtkObjectClass*>(link_button_class);
+ widget_class->expose_event = &gtk_chrome_link_button_expose;
+ button_class->enter = &gtk_chrome_link_button_enter;
+ button_class->leave = &gtk_chrome_link_button_leave;
+ object_class->destroy = &gtk_chrome_link_button_destroy;
+}
+
+static void gtk_chrome_link_button_init(GtkChromeLinkButton* button) {
+ SetLinkButtonStyle();
+
+ // We put a label in a button so we can connect to the click event. We don't
+ // let the button draw itself; catch all expose events to the button and pass
+ // them through to the label.
+ button->label = gtk_label_new(NULL);
+ button->blue_markup = NULL;
+ button->red_markup = NULL;
+ button->is_blue = TRUE;
+ button->hand_cursor = gdk_cursor_new(GDK_HAND2);
+
+ gtk_container_add(GTK_CONTAINER(button), button->label);
+ gtk_widget_set_name(GTK_WIDGET(button), "chrome-link-button");
+ gtk_widget_set_app_paintable(GTK_WIDGET(button), TRUE);
+}
+
+static void gtk_chrome_link_button_set_text(GtkChromeLinkButton* button,
+ const char* text) {
+ // We should have only been called once or we'd leak the markups.
+ DCHECK(!button->blue_markup && !button->red_markup);
+
+ button->blue_markup = g_markup_printf_escaped(kLinkMarkup, "blue", text);
+ button->red_markup = g_markup_printf_escaped(kLinkMarkup, "red", text);
+ gtk_label_set_markup(GTK_LABEL(button->label), button->blue_markup);
+ button->is_blue = TRUE;
+}
+
+GtkWidget* gtk_chrome_link_button_new(const char* text) {
+ GtkWidget* lb = GTK_WIDGET(g_object_new(GTK_TYPE_CHROME_LINK_BUTTON, NULL));
+ gtk_chrome_link_button_set_text(GTK_CHROME_LINK_BUTTON(lb), text);
+ return lb;
+}
+
+G_END_DECLS
diff --git a/chrome/browser/gtk/gtk_chrome_link_button.h b/chrome/browser/gtk/gtk_chrome_link_button.h
new file mode 100644
index 0000000..214b142
--- /dev/null
+++ b/chrome/browser/gtk/gtk_chrome_link_button.h
@@ -0,0 +1,56 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Creates a link button that shows |text| in blue and underlined. The cursor
+// changes to a hand when over the link. This is like the GTK LinkButton, but
+// it doesn't call the global URI link handler, etc. It is a button subclass,
+// so you can just handle the clicked signal.
+
+#ifndef CHROME_BROWSER_GTK_GTK_CHROME_LINK_BUTTON_H_
+#define CHROME_BROWSER_GTK_GTK_CHROME_LINK_BUTTON_H_
+
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_CHROME_LINK_BUTTON (gtk_chrome_link_button_get_type ())
+#define GTK_CHROME_LINK_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GTK_TYPE_CHROME_LINK_BUTTON, \
+ GtkChromeLinkButton))
+#define GTK_CHROME_LINK_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GTK_TYPE_CHROME_LINK_BUTTON, \
+ GtkChromeLinkButtonClass))
+#define GTK_IS_CHROME_LINK_BUTTON(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CHROME_LINK_BUTTON))
+#define GTK_IS_CHROME_LINK_BUTTON_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CHROME_LINK_BUTTON))
+#define GTK_CHROME_LINK_BUTTON_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ GTK_TYPE_CHROME_LINK_BUTTON, \
+ GtkChromeLinkButton))
+
+typedef struct _GtkChromeLinkButton GtkChromeLinkButton;
+typedef struct _GtkChromeLinkButtonClass GtkChromeLinkButtonClass;
+
+struct _GtkChromeLinkButton {
+ GtkButton button;
+ GtkWidget* label;
+ char* blue_markup;
+ char* red_markup;
+ gboolean is_blue;
+ GdkCursor* hand_cursor;
+};
+
+struct _GtkChromeLinkButtonClass {
+ GtkButtonClass parent_class;
+};
+
+GtkWidget* gtk_chrome_link_button_new(const char* text);
+
+GType gtk_chrome_link_button_get_type();
+
+G_END_DECLS
+
+#endif // CHROME_BROWSER_GTK_GTK_CHROME_LINK_BUTTON_H_
diff --git a/chrome/browser/gtk/infobar_gtk.cc b/chrome/browser/gtk/infobar_gtk.cc
index 6ec2686..1b8734b 100644
--- a/chrome/browser/gtk/infobar_gtk.cc
+++ b/chrome/browser/gtk/infobar_gtk.cc
@@ -10,8 +10,8 @@
#include "base/gfx/gtk_util.h"
#include "base/string_util.h"
#include "chrome/browser/gtk/custom_button.h"
+#include "chrome/browser/gtk/gtk_chrome_link_button.h"
#include "chrome/browser/gtk/infobar_container_gtk.h"
-#include "chrome/browser/gtk/link_button_gtk.h"
#include "chrome/common/gtk_util.h"
namespace {
@@ -148,14 +148,15 @@ class LinkInfoBar : public InfoBar {
std::wstring link_text = delegate->GetLinkText();
// Create the link button.
- link_button_.reset(new LinkButtonGtk(WideToUTF8(link_text).c_str()));
- g_signal_connect(link_button_->widget(), "clicked",
+ GtkWidget* link_button =
+ gtk_chrome_link_button_new(WideToUTF8(link_text).c_str());
+ g_signal_connect(link_button, "clicked",
G_CALLBACK(OnLinkClick), this);
// If link_offset is npos, we right-align the link instead of embedding it
// in the text.
if (link_offset == std::wstring::npos) {
- gtk_box_pack_end(GTK_BOX(hbox_), link_button_->widget(), FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(hbox_), link_button, FALSE, FALSE, 0);
GtkWidget* label = gtk_label_new(WideToUTF8(display_text).c_str());
gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &gfx::kGdkBlack);
gtk_box_pack_start(GTK_BOX(hbox_), label, FALSE, FALSE, 0);
@@ -172,7 +173,7 @@ class LinkInfoBar : public InfoBar {
// this hbox that doesn't use kElementPadding.
GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), initial_label, FALSE, FALSE, 0);
- gtk_util::CenterWidgetInHBox(hbox, link_button_->widget(), false, 0);
+ gtk_util::CenterWidgetInHBox(hbox, link_button, false, 0);
gtk_box_pack_start(GTK_BOX(hbox), trailing_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox_), hbox, FALSE, FALSE, 0);
}
@@ -188,9 +189,6 @@ class LinkInfoBar : public InfoBar {
link_info_bar->RemoveInfoBar();
}
}
-
- // The clickable link text.
- scoped_ptr<LinkButtonGtk> link_button_;
};
// ConfirmInfoBar --------------------------------------------------------------
diff --git a/chrome/browser/gtk/link_button_gtk.cc b/chrome/browser/gtk/link_button_gtk.cc
deleted file mode 100644
index 66c85bd..0000000
--- a/chrome/browser/gtk/link_button_gtk.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/gtk/link_button_gtk.h"
-
-static const char* kLinkMarkup = "<u><span color=\"%s\">%s</span></u>";
-
-namespace {
-
-// Set the GTK style on our custom link button. We don't want any border around
-// the link text.
-void SetLinkButtonStyle() {
- static bool style_was_set = false;
-
- if (style_was_set)
- return;
- style_was_set = true;
-
- gtk_rc_parse_string(
- "style \"chrome-link-button\" {"
- " GtkButton::inner-border = {0, 0, 0, 0}"
- " xthickness = 0"
- " ythickness = 0"
- "}"
- "widget \"*chrome-link-button\" style \"chrome-link-button\"");
-}
-
-} // namespace
-
-LinkButtonGtk::LinkButtonGtk(const char* text)
- : hand_cursor_(gdk_cursor_new(GDK_HAND2)),
- is_blue_(true) {
- SetLinkButtonStyle();
-
- // We put a label in a button so we can connect to the click event. We don't
- // let the button draw itself; catch all expose events to the button and pass
- // them through to the label.
- label_ = gtk_label_new(NULL);
- blue_markup = g_markup_printf_escaped(kLinkMarkup, "blue", text);
- red_markup = g_markup_printf_escaped(kLinkMarkup, "red", text);
- gtk_label_set_markup(GTK_LABEL(label_), blue_markup);
-
- widget_.Own(gtk_button_new());
- gtk_container_add(GTK_CONTAINER(widget_.get()), label_);
- gtk_widget_set_name(widget_.get(), "chrome-link-button");
- gtk_widget_set_app_paintable(widget_.get(), TRUE);
- g_signal_connect(widget_.get(), "expose-event",
- G_CALLBACK(OnExpose), this);
- // We connect to these signals so we can set the cursor appropriately. We
- // could give the link button its own GdkWindow (e.g. by placing it in a
- // GtkEventBox), but that would wreak havok with painting of the parent
- // widget. We can't use the enter- and leave- notify events as they operate
- // on the widget's GdkWindow, and |label| nor |button| has its own GdkWindow.
- g_signal_connect(widget_.get(), "enter",
- G_CALLBACK(OnEnter), this);
- g_signal_connect(widget_.get(), "leave",
- G_CALLBACK(OnLeave), this);
-}
-
-LinkButtonGtk::~LinkButtonGtk() {
- g_free(red_markup);
- g_free(blue_markup);
- gdk_cursor_unref(hand_cursor_);
- widget_.Destroy();
-}
-
-// static
-gboolean LinkButtonGtk::OnEnter(GtkWidget* widget,
- LinkButtonGtk* link_button) {
- gdk_window_set_cursor(widget->window, link_button->hand_cursor_);
- return FALSE;
-}
-
-// static
-gboolean LinkButtonGtk::OnLeave(GtkWidget* widget,
- LinkButtonGtk* link_button) {
- gdk_window_set_cursor(widget->window, NULL);
- return FALSE;
-}
-
-// static
-gboolean LinkButtonGtk::OnExpose(GtkWidget* widget,
- GdkEventExpose* event,
- LinkButtonGtk* link_button) {
- GtkWidget* label = link_button->label_;
-
- if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE && link_button->is_blue_) {
- gtk_label_set_markup(GTK_LABEL(label), link_button->red_markup);
- link_button->is_blue_ = false;
- } else if (GTK_WIDGET_STATE(widget) != GTK_STATE_ACTIVE &&
- !link_button->is_blue_) {
- gtk_label_set_markup(GTK_LABEL(label), link_button->blue_markup);
- link_button->is_blue_ = true;
- }
-
- // Draw the link inside the button.
- gtk_container_propagate_expose(GTK_CONTAINER(widget), label, event);
-
- // Draw the focus rectangle.
- if (GTK_WIDGET_HAS_FOCUS(widget)) {
- gtk_paint_focus(widget->style, widget->window,
- static_cast<GtkStateType>(GTK_WIDGET_STATE(widget)),
- &event->area, widget, NULL,
- widget->allocation.x, widget->allocation.y,
- widget->allocation.width, widget->allocation.height);
- }
-
- // Don't let the button draw itself, ever.
- return TRUE;
-}
diff --git a/chrome/browser/gtk/link_button_gtk.h b/chrome/browser/gtk/link_button_gtk.h
deleted file mode 100644
index dc4b809..0000000
--- a/chrome/browser/gtk/link_button_gtk.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <gdk/gdk.h>
-#include <gtk/gtk.h>
-
-#include "chrome/common/owned_widget_gtk.h"
-
-// Creates a link button that shows |text| in blue and underlined. The cursor
-// changes to a hand when over the link.
-class LinkButtonGtk {
- public:
- explicit LinkButtonGtk(const char* text);
- virtual ~LinkButtonGtk();
-
- GtkWidget* widget() { return widget_.get(); }
-
- GtkWidget* label() { return label_; }
-
- private:
- // Called when the pointer enters or leaves the button.
- static gboolean OnEnter(GtkWidget* widget, LinkButtonGtk* link_button);
- static gboolean OnLeave(GtkWidget* widget, LinkButtonGtk* link_button);
-
- // Called when the pointer moves over the link button's gdk window.
- static gboolean OnMotionNotify(GtkWidget* widget,
- GdkEventMotion* event,
- LinkButtonGtk* link_button);
-
- // Called when the widget is exposed.
- static gboolean OnExpose(GtkWidget* widget,
- GdkEventExpose* event,
- LinkButtonGtk* link_button);
-
- // The button widget.
- OwnedWidgetGtk widget_;
-
- // The text widget.
- GtkWidget* label_;
-
- // We keep this hand cursor so we don't have to recreate it every time the
- // user mouses over the link.
- GdkCursor* hand_cursor_;
-
- // Text markup for the link. We use the red one when the link is being
- // clicked.
- gchar* blue_markup;
- gchar* red_markup;
- // The current state of the text.
- bool is_blue_;
-};