summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.cc29
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.h1
-rw-r--r--chrome/browser/gtk/gtk_chrome_button.cc43
-rw-r--r--chrome/browser/gtk/gtk_chrome_button.h9
4 files changed, 76 insertions, 6 deletions
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc
index 1d16a2f..72148b1 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_toolbar_gtk.cc
@@ -52,6 +52,8 @@ const int kMenuTimerDelay = 500;
} // namespace
+// BrowserToolbarGtk, public ---------------------------------------------------
+
BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser)
: toolbar_(NULL),
location_bar_(new LocationBarViewGtk(browser->command_updater(),
@@ -179,6 +181,8 @@ LocationBar* BrowserToolbarGtk::GetLocationBar() const {
return location_bar_.get();
}
+// CommandUpdater::CommandObserver ---------------------------------------------
+
void BrowserToolbarGtk::EnabledStateChangedForCommand(int id, bool enabled) {
GtkWidget* widget = NULL;
switch (id) {
@@ -206,6 +210,8 @@ void BrowserToolbarGtk::EnabledStateChangedForCommand(int id, bool enabled) {
gtk_widget_set_sensitive(widget, enabled);
}
+// MenuGtk::Delegate -----------------------------------------------------------
+
bool BrowserToolbarGtk::IsCommandEnabled(int command_id) const {
return browser_->command_updater()->IsCommandEnabled(command_id);
}
@@ -223,6 +229,15 @@ void BrowserToolbarGtk::ExecuteCommand(int id) {
browser_->ExecuteCommand(id);
}
+void BrowserToolbarGtk::StoppedShowing() {
+ gtk_chrome_button_unset_paint_state(
+ GTK_CHROME_BUTTON(page_menu_button_.get()));
+ gtk_chrome_button_unset_paint_state(
+ GTK_CHROME_BUTTON(app_menu_button_.get()));
+}
+
+// NotificationObserver --------------------------------------------------------
+
void BrowserToolbarGtk::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -235,6 +250,8 @@ void BrowserToolbarGtk::Observe(NotificationType type,
}
}
+// BrowserToolbarGtk, public ---------------------------------------------------
+
void BrowserToolbarGtk::SetProfile(Profile* profile) {
if (profile == profile_)
return;
@@ -267,6 +284,8 @@ gfx::Rect BrowserToolbarGtk::GetPopupBounds() const {
go_x - star_x - (2 * kPopupLeftRightMargin), 0);
}
+// BrowserToolbarGtk, private --------------------------------------------------
+
CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton(
int normal_id, int active_id, int highlight_id, int depressed_id,
const std::string& localized_tooltip) {
@@ -360,18 +379,20 @@ void BrowserToolbarGtk::OnButtonClick(GtkWidget* button,
gboolean BrowserToolbarGtk::OnMenuButtonPressEvent(GtkWidget* button,
GdkEvent* event,
BrowserToolbarGtk* toolbar) {
- // TODO(port): this never puts the button into the "active" state,
- // which means we never display the button-pressed-down graphics. I
- // suspect a better way to do it is just to use a real GtkMenuShell
- // with our custom drawing.
if (event->type == GDK_BUTTON_PRESS) {
GdkEventButton* event_button = reinterpret_cast<GdkEventButton*>(event);
if (event_button->button == 1) {
// We have a button press we should respond to.
if (button == toolbar->page_menu_button_.get()) {
+ gtk_chrome_button_set_paint_state(
+ GTK_CHROME_BUTTON(toolbar->page_menu_button_.get()),
+ GTK_STATE_ACTIVE);
toolbar->RunPageMenu(event);
return TRUE;
} else if (button == toolbar->app_menu_button_.get()) {
+ gtk_chrome_button_set_paint_state(
+ GTK_CHROME_BUTTON(toolbar->app_menu_button_.get()),
+ GTK_STATE_ACTIVE);
toolbar->RunAppMenu(event);
return TRUE;
}
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h
index c901a6d5..2cda352 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.h
+++ b/chrome/browser/gtk/browser_toolbar_gtk.h
@@ -58,6 +58,7 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver,
virtual bool IsCommandEnabled(int command_id) const;
virtual bool IsItemChecked(int id) const;
virtual void ExecuteCommand(int command_id);
+ virtual void StoppedShowing();
// NotificationObserver implementation.
void Observe(NotificationType type,
diff --git a/chrome/browser/gtk/gtk_chrome_button.cc b/chrome/browser/gtk/gtk_chrome_button.cc
index 93b0218..ceddef2 100644
--- a/chrome/browser/gtk/gtk_chrome_button.cc
+++ b/chrome/browser/gtk/gtk_chrome_button.cc
@@ -20,11 +20,22 @@ NineBox* g_nine_box_active;
G_BEGIN_DECLS
+#define GTK_CHROME_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o),\
+ GTK_TYPE_CHROME_BUTTON,\
+ GtkChromeButtonPrivate))
+typedef struct _GtkChromeButtonPrivate GtkChromeButtonPrivate;
+
+struct _GtkChromeButtonPrivate
+{
+ int paint_state;
+};
+
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;
widget_class->expose_event = gtk_chrome_button_expose;
@@ -49,18 +60,27 @@ static void gtk_chrome_button_class_init(GtkChromeButtonClass *button_class) {
IDR_TEXTBUTTON_BOTTOM_LEFT_P,
IDR_TEXTBUTTON_BOTTOM_P,
IDR_TEXTBUTTON_BOTTOM_RIGHT_P);
+
+ g_type_class_add_private(gobject_class, sizeof(GtkChromeButtonPrivate));
}
static void gtk_chrome_button_init(GtkChromeButton* button) {
+ GtkChromeButtonPrivate *priv = GTK_CHROME_BUTTON_GET_PRIVATE(button);
+ priv->paint_state = -1;
+
gtk_widget_set_app_paintable(GTK_WIDGET(button), TRUE);
}
static gboolean gtk_chrome_button_expose(GtkWidget* widget,
GdkEventExpose* event) {
+ GtkChromeButtonPrivate *priv = GTK_CHROME_BUTTON_GET_PRIVATE(widget);
+ int paint_state = priv->paint_state < 0 ?
+ GTK_WIDGET_STATE(widget) : priv->paint_state;
+
NineBox* nine_box = NULL;
- if (GTK_WIDGET_STATE(widget) == GTK_STATE_PRELIGHT)
+ if (paint_state == GTK_STATE_PRELIGHT)
nine_box = g_nine_box_prelight;
- else if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE)
+ else if (paint_state == GTK_STATE_ACTIVE)
nine_box = g_nine_box_active;
// Only draw theme graphics if we have some.
@@ -78,5 +98,24 @@ GtkWidget* gtk_chrome_button_new(void) {
return GTK_WIDGET(g_object_new(GTK_TYPE_CHROME_BUTTON, NULL));
}
+void gtk_chrome_button_set_paint_state(GtkChromeButton* button,
+ GtkStateType state) {
+ g_return_if_fail(GTK_IS_CHROME_BUTTON(button));
+
+ GtkChromeButtonPrivate *priv = GTK_CHROME_BUTTON_GET_PRIVATE(button);
+ priv->paint_state = state;
+
+ gtk_widget_queue_draw(GTK_WIDGET(button));
+}
+
+void gtk_chrome_button_unset_paint_state(GtkChromeButton* button) {
+ g_return_if_fail(GTK_IS_CHROME_BUTTON(button));
+
+ GtkChromeButtonPrivate *priv = GTK_CHROME_BUTTON_GET_PRIVATE(button);
+ priv->paint_state = -1;
+
+ gtk_widget_queue_draw(GTK_WIDGET(button));
+}
+
G_END_DECLS
diff --git a/chrome/browser/gtk/gtk_chrome_button.h b/chrome/browser/gtk/gtk_chrome_button.h
index 84d1490..c1437d4 100644
--- a/chrome/browser/gtk/gtk_chrome_button.h
+++ b/chrome/browser/gtk/gtk_chrome_button.h
@@ -36,6 +36,15 @@ struct _GtkChromeButtonClass {
GtkWidget* gtk_chrome_button_new();
+GType gtk_chrome_button_get_type();
+
+// Set the paint state to |state|. This overrides the widget's current state.
+void gtk_chrome_button_set_paint_state(GtkChromeButton* button,
+ GtkStateType state);
+
+// Revert to using the widget's current state for painting.
+void gtk_chrome_button_unset_paint_state(GtkChromeButton* button);
+
G_END_DECLS
#endif // CHROME_BROWSER_GTK_GTK_CHROME_BUTTON_H_