diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-17 00:28:55 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-17 00:28:55 +0000 |
commit | 40f84e57af704b0e6214308edef8f847339d7187 (patch) | |
tree | f2803af81b6f1788e94699c6acc83f442a72fbeb /chrome | |
parent | e46a877ad70fcf5cce428024456ae918ff780071 (diff) | |
download | chromium_src-40f84e57af704b0e6214308edef8f847339d7187.zip chromium_src-40f84e57af704b0e6214308edef8f847339d7187.tar.gz chromium_src-40f84e57af704b0e6214308edef8f847339d7187.tar.bz2 |
Linux: Make theme install bubble prettier (for compositing WMs)
BUG=none
TEST=screenshot
Review URL: http://codereview.chromium.org/289004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29362 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/theme_install_bubble_view_gtk.cc | 72 | ||||
-rw-r--r-- | chrome/browser/gtk/theme_install_bubble_view_gtk.h | 19 |
2 files changed, 68 insertions, 23 deletions
diff --git a/chrome/browser/gtk/theme_install_bubble_view_gtk.cc b/chrome/browser/gtk/theme_install_bubble_view_gtk.cc index 5114642..f3ea425 100644 --- a/chrome/browser/gtk/theme_install_bubble_view_gtk.cc +++ b/chrome/browser/gtk/theme_install_bubble_view_gtk.cc @@ -4,9 +4,12 @@ #include "chrome/browser/gtk/theme_install_bubble_view_gtk.h" +#include <math.h> + #include "app/gfx/gtk_util.h" #include "app/l10n_util.h" #include "chrome/browser/gtk/rounded_window.h" +#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" #include "grit/generated_resources.h" @@ -73,7 +76,6 @@ void ThemeInstallBubbleViewGtk::InitWidgets() { // Widgematically, the bubble is just a label in a popup window. widget_ = gtk_window_new(GTK_WINDOW_POPUP); gtk_container_set_border_width(GTK_CONTAINER(widget_), kTextPadding); - gtk_widget_modify_bg(widget_, GTK_STATE_NORMAL, &gfx::kGdkBlack); GtkWidget* label = gtk_label_new(NULL); // Need our own copy of the "Loading..." string: http://crbug.com/24177 @@ -86,22 +88,38 @@ void ThemeInstallBubbleViewGtk::InitWidgets() { gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &gfx::kGdkWhite); gtk_container_add(GTK_CONTAINER(widget_), label); - gtk_widget_realize(widget_); - GdkColor color; - gtk_util::ActAsRoundedWindow(widget_, color, kBubbleCornerRadius, - gtk_util::ROUNDED_ALL, gtk_util::BORDER_NONE); - gtk_window_set_opacity(GTK_WINDOW(widget_), kBubbleOpacity); + bool composited = false; + if (gtk_util::IsScreenComposited()) { + composited = true; + GdkScreen* screen = gtk_widget_get_screen(widget_); + GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen); + + if (colormap) + gtk_widget_set_colormap(widget_, colormap); + else + composited = false; + } + + if (composited) { + gtk_widget_set_app_paintable(widget_, TRUE); + g_signal_connect(widget_, "expose-event", + G_CALLBACK(HandleExposeEventThunk), this); + gtk_widget_realize(widget_); + } else { + gtk_widget_modify_bg(widget_, GTK_STATE_NORMAL, &gfx::kGdkBlack); + GdkColor color; + gtk_util::ActAsRoundedWindow(widget_, color, kBubbleCornerRadius, + gtk_util::ROUNDED_ALL, gtk_util::BORDER_NONE); + } + MoveWindow(); - g_signal_connect(widget_, "configure-event", - G_CALLBACK(&HandleParentConfigureThunk), this); g_signal_connect(widget_, "unmap-event", G_CALLBACK(&HandleParentUnmapThunk), this); gtk_widget_show_all(widget_); } - void ThemeInstallBubbleViewGtk::MoveWindow() { GtkRequisition req; gtk_widget_size_request(widget_, &req); @@ -117,13 +135,39 @@ void ThemeInstallBubbleViewGtk::MoveWindow() { gtk_window_move(GTK_WINDOW(widget_), x, y); } -gboolean ThemeInstallBubbleViewGtk::HandleParentConfigure( - GdkEventConfigure* event) { - MoveWindow(); +gboolean ThemeInstallBubbleViewGtk::HandleParentUnmap() { + delete this; return FALSE; } -gboolean ThemeInstallBubbleViewGtk::HandleParentUnmap() { - delete this; +gboolean ThemeInstallBubbleViewGtk::HandleExposeEvent( + GdkEventExpose* event) { + cairo_t* cr = gdk_cairo_create(event->window); + gdk_cairo_rectangle(cr, &event->area); + cairo_clip(cr); + + cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); + cairo_paint(cr); + cairo_set_operator(cr, CAIRO_OPERATOR_OVER); + + // |inner_rect| has its corners at the centerpoints of the corner arcs. + gfx::Rect inner_rect(widget_->allocation); + int inset = kBubbleCornerRadius; + inner_rect.Inset(inset, inset); + + // The positive y axis is down, so M_PI_2 is down. + cairo_arc(cr, inner_rect.x(), inner_rect.y(), inset, + M_PI, 3 * M_PI_2); + cairo_arc(cr, inner_rect.right(), inner_rect.y(), inset, + 3 * M_PI_2, 0); + cairo_arc(cr, inner_rect.right(), inner_rect.bottom(), inset, + 0, M_PI_2); + cairo_arc(cr, inner_rect.x(), inner_rect.bottom(), inset, + M_PI_2, M_PI); + + cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, kBubbleOpacity); + cairo_fill(cr); + cairo_destroy(cr); + return FALSE; } diff --git a/chrome/browser/gtk/theme_install_bubble_view_gtk.h b/chrome/browser/gtk/theme_install_bubble_view_gtk.h index 1885261..bffaae8 100644 --- a/chrome/browser/gtk/theme_install_bubble_view_gtk.h +++ b/chrome/browser/gtk/theme_install_bubble_view_gtk.h @@ -33,15 +33,6 @@ class ThemeInstallBubbleViewGtk : public NotificationObserver { // Reposition |widget_| to be centered over |parent_|. void MoveWindow(); - // Move with the parent window. - static gboolean HandleParentConfigureThunk(GtkWidget* widget, - GdkEventConfigure* event, - gpointer user_data) { - return reinterpret_cast<ThemeInstallBubbleViewGtk*>(user_data)-> - HandleParentConfigure(event); - } - gboolean HandleParentConfigure(GdkEventConfigure* event); - // Our parent is going down; self destruct. static gboolean HandleParentUnmapThunk(GtkWidget* widget, GdkEvent* event, @@ -51,6 +42,16 @@ class ThemeInstallBubbleViewGtk : public NotificationObserver { } gboolean HandleParentUnmap(); + // Draw the background. This is only signalled if we are using a compositing + // window manager, otherwise we just use ActAsRoundedWindow(). + static gboolean HandleExposeEventThunk(GtkWidget* widget, + GdkEventExpose* event, + gpointer user_data) { + return reinterpret_cast<ThemeInstallBubbleViewGtk*>(user_data)-> + HandleExposeEvent(event); + } + gboolean HandleExposeEvent(GdkEventExpose* event); + GtkWidget* widget_; // The parent browser window, over which we position ourselves. |