Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: chrome/browser/ui/panels/panel_browser_titlebar_gtk.cc

Issue 10180011: Support painting panels with chromium themes on GTK. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/panels/panel_browser_titlebar_gtk.cc
diff --git a/chrome/browser/ui/panels/panel_browser_titlebar_gtk.cc b/chrome/browser/ui/panels/panel_browser_titlebar_gtk.cc
index d1d80dc45a58f66b0b2c1dfecd9890131a07081c..47a43e0a30e9bef689a0c421de679ae50a4ad5e9 100644
--- a/chrome/browser/ui/panels/panel_browser_titlebar_gtk.cc
+++ b/chrome/browser/ui/panels/panel_browser_titlebar_gtk.cc
@@ -4,11 +4,17 @@
#include "chrome/browser/ui/panels/panel_browser_titlebar_gtk.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/gtk/custom_button.h"
+#include "chrome/browser/ui/gtk/gtk_util.h"
+#include "chrome/browser/ui/gtk/theme_service_gtk.h"
#include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_browser_window_gtk.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
+#include "ui/base/gtk/gtk_compat.h"
+#include "ui/gfx/skia_utils_gtk.h"
namespace {
@@ -18,6 +24,29 @@ const int kPanelButtonSpacing = 7;
// Spacing around outside of panel's titlebar buttons.
const int kPanelButtonOuterPadding = 7;
+// Markup for painting title as bold.
+const char* const kTitleMarkupPrefix = "<span font_weight='bold'>";
+const char* const kTitleMarkupSuffix = "</span>";
+
+// Colors used to draw title.
+const SkColor kActiveTitleTextDefaultColor = SK_ColorBLACK;
+const SkColor kInactiveTitleTextDefaultColor = 0x80888888;
dcheng 2012/04/27 01:18:39 Consider using SkColorSetARGB. It makes it clear w
jianli 2012/04/27 20:22:34 Done.
+const SkColor kAttentionTitleTextDefaultColor = SK_ColorWHITE;
+
+// Alpha value used in drawing inactive titlebar under non-default theme.
+const U8CPU kInactiveAlphaBlending = 0x80;
+
+SkColor BlendSkColorWithAlpha(SkColor fg_color, SkColor bg_color, U8CPU alpha) {
+ if (alpha == 255)
+ return fg_color;
+ double fg_ratio = alpha / 255.0;
+ double bg_ratio = 1.0 - fg_ratio;
+ return SkColorSetRGB(
+ (SkColorGetR(fg_color) * fg_ratio + SkColorGetR(bg_color) * bg_ratio),
+ (SkColorGetG(fg_color) * fg_ratio + SkColorGetG(bg_color) * bg_ratio),
+ (SkColorGetB(fg_color) * fg_ratio + SkColorGetB(bg_color) * bg_ratio));
+}
+
} // namespace
PanelBrowserTitlebarGtk::PanelBrowserTitlebarGtk(
@@ -29,6 +58,44 @@ PanelBrowserTitlebarGtk::PanelBrowserTitlebarGtk(
PanelBrowserTitlebarGtk::~PanelBrowserTitlebarGtk() {
}
+SkColor PanelBrowserTitlebarGtk::GetTitleColor() const {
+ if (browser_window_->IsDrawingAttention())
jennb 2012/04/27 18:36:13 browser_window_->panel()->IsDrawingAttention()
jianli 2012/04/27 20:22:34 Changed to query about paint state, per discussion
+ return kAttentionTitleTextDefaultColor;
+
+ bool is_active = browser_window_->IsActive();
+ if (theme_service()->UsingDefaultTheme()) {
+ return is_active ? kActiveTitleTextDefaultColor
+ : kInactiveTitleTextDefaultColor;
+ } else {
+ return is_active ? theme_service()->GetColor(ThemeService::COLOR_TAB_TEXT) :
+ BlendSkColorWithAlpha(
+ theme_service()->GetColor(ThemeService::COLOR_BACKGROUND_TAB_TEXT),
+ theme_service()->GetColor(ThemeService::COLOR_TOOLBAR),
+ kInactiveAlphaBlending);
+ }
+}
+
+void PanelBrowserTitlebarGtk::UpdateButtonBackground(CustomDrawButton* button) {
+ button->SetBackground(GetTitleColor(), NULL, NULL);
jennb 2012/04/27 18:36:13 The button's background is the same as the title t
jianli 2012/04/27 20:22:34 Changed per discussion.
+}
+
+void PanelBrowserTitlebarGtk::UpdateTitleAndIcon() {
+ DCHECK(app_mode_title());
+
+ std::string title =
+ UTF16ToUTF8(browser_window_->browser()->GetWindowTitleForCurrentTab());
+
+ // Add the markup to show the title as bold.
+ gchar* escaped_title = g_markup_escape_text(title.c_str(), -1);
+ gchar* title_with_markup = g_strconcat(kTitleMarkupPrefix,
+ escaped_title,
+ kTitleMarkupSuffix,
+ NULL);
+ gtk_label_set_markup(GTK_LABEL(app_mode_title()), title_with_markup);
+ g_free(escaped_title);
+ g_free(title_with_markup);
+}
+
bool PanelBrowserTitlebarGtk::BuildButton(const std::string& button_token,
bool left_side) {
// Panel only shows close and minimize/restore buttons.
@@ -94,3 +161,51 @@ void PanelBrowserTitlebarGtk::HandleButtonClick(GtkWidget* button) {
void PanelBrowserTitlebarGtk::ShowFaviconMenu(GdkEventButton* event) {
// Favicon menu is not supported in panels.
}
+
+void PanelBrowserTitlebarGtk::UpdateTextColor() {
+ DCHECK(app_mode_title());
+
+ GdkColor text_color = gfx::SkColorToGdkColor(GetTitleColor());
+ gtk_util::SetLabelColor(app_mode_title(), &text_color);
+}
+
+void PanelBrowserTitlebarGtk::SendEnterNotifyToCloseButtonIfUnderMouse() {
+ if (!close_button())
+ return;
+
+ gint x;
+ gint y;
+ GtkAllocation widget_allocation = close_button()->WidgetAllocation();
+ gtk_widget_get_pointer(GTK_WIDGET(close_button()->widget()), &x, &y);
+
+ gfx::Rect button_rect(0, 0, widget_allocation.width,
+ widget_allocation.height);
+ if (!button_rect.Contains(x, y)) {
+ // Mouse is not over the close button.
+ return;
+ }
+
+ // Create and emit an enter-notify-event on close button.
+ GValue return_value;
+ return_value.g_type = G_TYPE_BOOLEAN;
+ g_value_set_boolean(&return_value, false);
+
+ GdkEvent* event = gdk_event_new(GDK_ENTER_NOTIFY);
+ event->crossing.window =
+ gtk_button_get_event_window(GTK_BUTTON(close_button()->widget()));
+ event->crossing.send_event = FALSE;
+ event->crossing.subwindow = gtk_widget_get_window(close_button()->widget());
+ event->crossing.time = gtk_util::XTimeNow();
+ event->crossing.x = x;
+ event->crossing.y = y;
+ event->crossing.x_root = widget_allocation.x;
+ event->crossing.y_root = widget_allocation.y;
+ event->crossing.mode = GDK_CROSSING_NORMAL;
+ event->crossing.detail = GDK_NOTIFY_ANCESTOR;
+ event->crossing.focus = true;
+ event->crossing.state = 0;
+
+ g_signal_emit_by_name(GTK_OBJECT(close_button()->widget()),
+ "enter-notify-event", event,
+ &return_value);
+}

Powered by Google App Engine
This is Rietveld 408576698