| 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..44f93f0752ffbea9a5034aa79bf6529889c3b706 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,27 @@ 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 in attention mode.
|
| +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 +56,41 @@ PanelBrowserTitlebarGtk::PanelBrowserTitlebarGtk(
|
| PanelBrowserTitlebarGtk::~PanelBrowserTitlebarGtk() {
|
| }
|
|
|
| +SkColor PanelBrowserTitlebarGtk::GetTextColor() const {
|
| + PanelBrowserWindowGtk::PaintState paint_state =
|
| + browser_window_->GetPaintState();
|
| + if (paint_state == PanelBrowserWindowGtk::PAINT_FOR_ATTENTION)
|
| + return kAttentionTitleTextDefaultColor;
|
| +
|
| + return paint_state == PanelBrowserWindowGtk::PAINT_AS_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) {
|
| + // Don't need to update background since we're using transparent background.
|
| +}
|
| +
|
| +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 +156,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(GetTextColor());
|
| + 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);
|
| +}
|
|
|