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

Unified Diff: chrome/browser/ui/libgtk2ui/gtk2_ui.cc

Issue 1234223005: Initial gtk3 support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Silence gtk memory leak Created 5 years, 3 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
« no previous file with comments | « chrome/browser/ui/libgtk2ui/gtk2_ui.h ('k') | chrome/browser/ui/libgtk2ui/gtk2_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/libgtk2ui/gtk2_ui.cc
diff --git a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
index 21e7ce31e942bf51bac8b875fe5febf76ec7592b..43f7954b83f703e75497080f9e8853fef4336f2f 100644
--- a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
+++ b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
@@ -21,7 +21,6 @@
#include "base/strings/stringprintf.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/libgtk2ui/app_indicator_icon.h"
-#include "chrome/browser/ui/libgtk2ui/chrome_gtk_frame.h"
#include "chrome/browser/ui/libgtk2ui/gtk2_border.h"
#include "chrome/browser/ui/libgtk2ui/gtk2_event_loop.h"
#include "chrome/browser/ui/libgtk2ui/gtk2_key_bindings_handler.h"
@@ -52,6 +51,7 @@
#include "ui/gfx/skia_util.h"
#include "ui/native_theme/native_theme.h"
#include "ui/resources/grit/ui_resources.h"
+#include "ui/views/controls/button/blue_button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/label_button_border.h"
#include "ui/views/linux_ui/window_button_order_observer.h"
@@ -87,7 +87,9 @@ struct GObjectDeleter {
};
struct GtkIconInfoDeleter {
void operator()(GtkIconInfo* ptr) {
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_icon_info_free(ptr);
+ G_GNUC_END_IGNORE_DEPRECATIONS
}
};
typedef scoped_ptr<GIcon, GObjectDeleter> ScopedGIcon;
@@ -107,13 +109,6 @@ const char* kUnknownContentType = "application/octet-stream";
const int kToolbarImageWidth = 64;
const int kToolbarImageHeight = 128;
-// How much to tint the GTK+ color lighter at the top of the window.
-const color_utils::HSL kGtkFrameShift = { -1, -1, 0.58 };
-
-// How much to tint the GTK+ color when an explicit frame color hasn't been
-// specified.
-const color_utils::HSL kDefaultFrameShift = { -1, -1, 0.4 };
-
// Values used as the new luminance and saturation values in the inactive tab
// text color.
const double kDarkInactiveLuminance = 0.85;
@@ -121,12 +116,6 @@ const double kLightInactiveLuminance = 0.15;
const double kHeavyInactiveSaturation = 0.7;
const double kLightInactiveSaturation = 0.3;
-// Default color for links on the NTP when the GTK+ theme doesn't define a
-// link color. Constant taken from gtklinkbutton.c.
-const GdkColor kDefaultLinkColor = { 0, 0, 0, 0xeeee };
-
-const int kSkiaToGDKMultiplier = 257;
-
// TODO(erg): ThemeService has a whole interface just for reading default
// constants. Figure out what to do with that more long term; for now, just
// copy the constants themselves here.
@@ -181,21 +170,21 @@ const int kAutocompleteImages[] = {
struct IDRGtkMapping {
int idr;
const char* stock_id;
- GtkStateType gtk_state;
+ bool enabled;
} const kGtkIcons[] = {
- { IDR_BACK, GTK_STOCK_GO_BACK, GTK_STATE_NORMAL },
- { IDR_BACK_D, GTK_STOCK_GO_BACK, GTK_STATE_INSENSITIVE },
+ { IDR_BACK, "go-previous", true },
+ { IDR_BACK_D, "go-previous", false },
- { IDR_FORWARD, GTK_STOCK_GO_FORWARD, GTK_STATE_NORMAL },
- { IDR_FORWARD_D, GTK_STOCK_GO_FORWARD, GTK_STATE_INSENSITIVE },
+ { IDR_FORWARD, "go-next", true },
+ { IDR_FORWARD_D, "go-next", false },
- { IDR_HOME, GTK_STOCK_HOME, GTK_STATE_NORMAL },
+ { IDR_HOME, "go-home", true },
- { IDR_RELOAD, GTK_STOCK_REFRESH, GTK_STATE_NORMAL },
- { IDR_RELOAD_D, GTK_STOCK_REFRESH, GTK_STATE_INSENSITIVE },
+ { IDR_RELOAD, "view-refresh", true },
+ { IDR_RELOAD_D, "view-refresh", false },
- { IDR_STOP, GTK_STOCK_STOP, GTK_STATE_NORMAL },
- { IDR_STOP_D, GTK_STOCK_STOP, GTK_STATE_INSENSITIVE },
+ { IDR_STOP, "process-stop", true },
+ { IDR_STOP_D, "process-stop", false },
};
// The image resources that will be tinted by the 'button' tint value.
@@ -229,28 +218,37 @@ bool IsOverridableImage(int id) {
return images.count(id) > 0;
}
+// Get ChromeGtkFrame theme colors. No-op in GTK3.
+void GetChromeStyleColor(const char* style_property, SkColor* ret_color) {
+#if GTK_MAJOR_VERSION == 2
+ GdkColor* style_color = NULL;
+
+ gtk_widget_style_get(NativeThemeGtk2::instance()->GetWindow(),
+ style_property, &style_color,
+ NULL);
+
+ if (style_color) {
+ *ret_color = GdkColorToSkColor(*style_color);
+ gdk_color_free(style_color);
+ }
+#endif
+}
+
// Picks a button tint from a set of background colors. While
-// |accent_gdk_color| will usually be the same color through a theme, this
+// |accent_color| will usually be the same color through a theme, this
// function will get called with the normal GtkLabel |text_color|/GtkWindow
// |background_color| pair and the GtkEntry |text_color|/|background_color|
// pair. While 3/4 of the time the resulting tint will be the same, themes that
// have a dark window background (with light text) and a light text entry (with
// dark text) will get better icons with this separated out.
-void PickButtonTintFromColors(const GdkColor& accent_gdk_color,
- const GdkColor& text_color,
- const GdkColor& background_color,
+void PickButtonTintFromColors(SkColor accent_color,
+ SkColor text_color,
+ SkColor background_color,
color_utils::HSL* tint) {
- SkColor accent_color = GdkColorToSkColor(accent_gdk_color);
- color_utils::HSL accent_tint;
+ color_utils::HSL accent_tint, text_tint, background_tint;
color_utils::SkColorToHSL(accent_color, &accent_tint);
-
- color_utils::HSL text_tint;
- color_utils::SkColorToHSL(GdkColorToSkColor(text_color),
- &text_tint);
-
- color_utils::HSL background_tint;
- color_utils::SkColorToHSL(GdkColorToSkColor(background_color),
- &background_tint);
+ color_utils::SkColorToHSL(text_color, &text_tint);
+ color_utils::SkColorToHSL(background_color, &background_tint);
// If the accent color is gray, then our normal HSL tomfoolery will bring out
// whatever color is oddly dominant (for example, in rgb space [125, 128,
@@ -297,17 +295,6 @@ void PickButtonTintFromColors(const GdkColor& accent_gdk_color,
}
}
-// Applies an HSL shift to a GdkColor (instead of an SkColor)
-void GdkColorHSLShift(const color_utils::HSL& shift, GdkColor* frame_color) {
- SkColor shifted = color_utils::HSLShift(
- GdkColorToSkColor(*frame_color), shift);
-
- frame_color->pixel = 0;
- frame_color->red = SkColorGetR(shifted) * kSkiaToGDKMultiplier;
- frame_color->green = SkColorGetG(shifted) * kSkiaToGDKMultiplier;
- frame_color->blue = SkColorGetB(shifted) * kSkiaToGDKMultiplier;
-}
-
// Copied Default blah sections from ThemeService.
color_utils::HSL GetDefaultTint(int id) {
switch (id) {
@@ -428,23 +415,23 @@ Gtk2UI::Gtk2UI()
GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess());
}
-void Gtk2UI::Initialize() {
- signals_.reset(new Gtk2SignalRegistrar);
- // Create our fake widgets.
- fake_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- fake_frame_ = chrome_gtk_frame_new();
- fake_label_.Own(gtk_label_new(""));
- fake_entry_.Own(gtk_entry_new());
- // Only realized widgets receive style-set notifications, which we need to
- // broadcast new theme images and colors. Only realized widgets have style
- // properties, too, which we query for some colors.
- gtk_widget_realize(fake_frame_);
- gtk_widget_realize(fake_window_);
+void OnThemeChanged(GObject* obj, GParamSpec* param, Gtk2UI* gtkui) {
+ gtkui->ResetStyle();
+}
+
+void Gtk2UI::Initialize() {
+ GtkSettings* settings = gtk_settings_get_default();
+ g_signal_connect_after(settings,
+ "notify::gtk-theme-name",
+ G_CALLBACK(OnThemeChanged),
+ this);
+ g_signal_connect_after(settings,
+ "notify::gtk-icon-theme-name",
+ G_CALLBACK(OnThemeChanged),
+ this);
- signals_->Connect(fake_frame_, "style-set",
- G_CALLBACK(&OnStyleSetThunk), this);
LoadGtkValues();
@@ -465,11 +452,6 @@ void Gtk2UI::Initialize() {
}
Gtk2UI::~Gtk2UI() {
- gtk_widget_destroy(fake_window_);
- gtk_widget_destroy(fake_frame_);
- fake_label_.Destroy();
- fake_entry_.Destroy();
-
ClearAllThemeData();
}
@@ -741,114 +723,14 @@ bool Gtk2UI::MatchEvent(const ui::Event& event,
return key_bindings_handler_->MatchEvent(event, commands);
}
-void Gtk2UI::GetScrollbarColors(GdkColor* thumb_active_color,
- GdkColor* thumb_inactive_color,
- GdkColor* track_color) {
- GdkColor* theme_thumb_active = NULL;
- GdkColor* theme_thumb_inactive = NULL;
- GdkColor* theme_trough_color = NULL;
- gtk_widget_style_get(GTK_WIDGET(fake_frame_),
- "scrollbar-slider-prelight-color", &theme_thumb_active,
- "scrollbar-slider-normal-color", &theme_thumb_inactive,
- "scrollbar-trough-color", &theme_trough_color,
- NULL);
-
- // Ask the theme if the theme specifies all the scrollbar colors and short
- // circuit the expensive painting/compositing if we have all of them.
- if (theme_thumb_active && theme_thumb_inactive && theme_trough_color) {
- *thumb_active_color = *theme_thumb_active;
- *thumb_inactive_color = *theme_thumb_inactive;
- *track_color = *theme_trough_color;
-
- gdk_color_free(theme_thumb_active);
- gdk_color_free(theme_thumb_inactive);
- gdk_color_free(theme_trough_color);
- return;
- }
-
- // Create window containing scrollbar elements
- GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP);
- GtkWidget* fixed = gtk_fixed_new();
- GtkWidget* scrollbar = gtk_hscrollbar_new(NULL);
- gtk_container_add(GTK_CONTAINER(window), fixed);
- gtk_container_add(GTK_CONTAINER(fixed), scrollbar);
- gtk_widget_realize(window);
- gtk_widget_realize(scrollbar);
-
- // Draw scrollbar thumb part and track into offscreen image
- const int kWidth = 100;
- const int kHeight = 20;
- GtkStyle* style = gtk_rc_get_style(scrollbar);
- GdkWindow* gdk_window = gtk_widget_get_window(window);
- GdkPixmap* pm = gdk_pixmap_new(gdk_window, kWidth, kHeight, -1);
- GdkRectangle rect = { 0, 0, kWidth, kHeight };
- unsigned char data[3 * kWidth * kHeight];
- for (int i = 0; i < 3; ++i) {
- if (i < 2) {
- // Thumb part
- gtk_paint_slider(style, pm,
- i == 0 ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
- GTK_SHADOW_OUT, &rect, scrollbar, "slider", 0, 0,
- kWidth, kHeight, GTK_ORIENTATION_HORIZONTAL);
- } else {
- // Track
- gtk_paint_box(style, pm, GTK_STATE_ACTIVE, GTK_SHADOW_IN, &rect,
- scrollbar, "trough-upper", 0, 0, kWidth, kHeight);
- }
- GdkPixbuf* pb = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB,
- FALSE, 8, kWidth, kHeight,
- 3 * kWidth, 0, 0);
- gdk_pixbuf_get_from_drawable(pb, pm, NULL, 0, 0, 0, 0, kWidth, kHeight);
-
- // Sample pixels
- int components[3] = { 0 };
- for (int y = 2; y < kHeight - 2; ++y) {
- for (int c = 0; c < 3; ++c) {
- // Sample a vertical slice of pixels at about one-thirds from the
- // left edge. This allows us to avoid any fixed graphics that might be
- // located at the edges or in the center of the scrollbar.
- // Each pixel is made up of a red, green, and blue component; taking up
- // a total of three bytes.
- components[c] += data[3 * (kWidth / 3 + y * kWidth) + c];
- }
- }
- GdkColor* color = i == 0 ? thumb_active_color :
- i == 1 ? thumb_inactive_color :
- track_color;
- color->pixel = 0;
- // We sampled pixels across the full height of the image, ignoring a two
- // pixel border. In some themes, the border has a completely different
- // color which we do not want to factor into our average color computation.
- //
- // We now need to scale the colors from the 0..255 range, to the wider
- // 0..65535 range, and we need to actually compute the average color; so,
- // we divide by the total number of pixels in the sample.
- color->red = components[0] * 65535 / (255 * (kHeight - 4));
- color->green = components[1] * 65535 / (255 * (kHeight - 4));
- color->blue = components[2] * 65535 / (255 * (kHeight - 4));
-
- g_object_unref(pb);
- }
- g_object_unref(pm);
-
- gtk_widget_destroy(window);
-
- // Override any of the default colors with ones that were specified by the
- // theme.
- if (theme_thumb_active) {
- *thumb_active_color = *theme_thumb_active;
- gdk_color_free(theme_thumb_active);
- }
-
- if (theme_thumb_inactive) {
- *thumb_inactive_color = *theme_thumb_inactive;
- gdk_color_free(theme_thumb_inactive);
- }
+void Gtk2UI::SetScrollbarColors() {
+ thumb_active_color_ = SkColorSetRGB(244, 244, 244);
+ thumb_inactive_color_ = SkColorSetRGB(234, 234, 234);
+ track_color_ = SkColorSetRGB(211, 211, 211);
- if (theme_trough_color) {
- *track_color = *theme_trough_color;
- gdk_color_free(theme_trough_color);
- }
+ GetChromeStyleColor("scrollbar-slider-prelight-color", &thumb_active_color_);
+ GetChromeStyleColor("scrollbar-slider-normal-color", &thumb_inactive_color_);
+ GetChromeStyleColor("scrollbar-trough-color", &track_color_);
}
void Gtk2UI::LoadGtkValues() {
@@ -857,31 +739,31 @@ void Gtk2UI::LoadGtkValues() {
// regress startup time. Figure out how to do that when we can't access the
// prefs system from here.
- GtkStyle* frame_style = gtk_rc_get_style(fake_frame_);
+ NativeThemeGtk2* theme = NativeThemeGtk2::instance();
- GtkStyle* window_style = gtk_rc_get_style(fake_window_);
- SetThemeColorFromGtk(ThemeProperties::COLOR_CONTROL_BACKGROUND,
- &window_style->bg[GTK_STATE_NORMAL]);
+ SkColor toolbar_color =
+ theme->GetSystemColor(ui::NativeTheme::kColorId_LabelBackgroundColor);
+ SkColor button_color =
+ theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHighlightColor);
+ SkColor label_color =
+ theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor);
- GdkColor toolbar_color = window_style->bg[GTK_STATE_NORMAL];
- SetThemeColorFromGtk(ThemeProperties::COLOR_TOOLBAR, &toolbar_color);
+ colors_[ThemeProperties::COLOR_CONTROL_BACKGROUND] = toolbar_color;
+ colors_[ThemeProperties::COLOR_TOOLBAR] = toolbar_color;
- GdkColor button_color = window_style->bg[GTK_STATE_SELECTED];
- SetThemeTintFromGtk(ThemeProperties::TINT_BUTTONS, &button_color);
+ SetThemeTint(ThemeProperties::TINT_BUTTONS, button_color);
- GtkStyle* label_style = gtk_rc_get_style(fake_label_.get());
- GdkColor label_color = label_style->fg[GTK_STATE_NORMAL];
- SetThemeColorFromGtk(ThemeProperties::COLOR_TAB_TEXT, &label_color);
- SetThemeColorFromGtk(ThemeProperties::COLOR_BOOKMARK_TEXT, &label_color);
- SetThemeColorFromGtk(ThemeProperties::COLOR_STATUS_BAR_TEXT, &label_color);
+ colors_[ThemeProperties::COLOR_TAB_TEXT] = label_color;
+ colors_[ThemeProperties::COLOR_BOOKMARK_TEXT] = label_color;
+ colors_[ThemeProperties::COLOR_STATUS_BAR_TEXT] = label_color;
- UpdateDefaultFont(label_style->font_desc);
+ UpdateDefaultFont();
// Build the various icon tints.
GetNormalButtonTintHSL(&button_tint_);
GetNormalEntryForegroundHSL(&entry_tint_);
GetSelectedEntryForegroundHSL(&selected_entry_tint_);
- GdkColor frame_color = BuildFrameColors(frame_style);
+ SkColor frame_color = BuildFrameColors();
// The inactive frame color never occurs naturally in the theme, as it is a
// tinted version of |frame_color|. We generate another color based on the
@@ -908,140 +790,136 @@ void Gtk2UI::LoadGtkValues() {
// as |toolbar_color|, is usually a white, and when it isn't a white,
// provides sufficient contrast to |toolbar_color|. Try this out with
// Darklooks, HighContrastInverse or ThinIce.
- GtkStyle* entry_style = gtk_rc_get_style(fake_entry_.get());
- GdkColor ntp_background = entry_style->base[GTK_STATE_NORMAL];
- GdkColor ntp_foreground = entry_style->text[GTK_STATE_NORMAL];
- SetThemeColorFromGtk(ThemeProperties::COLOR_NTP_BACKGROUND,
- &ntp_background);
- SetThemeColorFromGtk(ThemeProperties::COLOR_NTP_TEXT,
- &ntp_foreground);
+
+ SkColor ntp_background =
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldDefaultBackground);
+ SkColor ntp_foreground =
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldDefaultColor);
+
+ colors_[ThemeProperties::COLOR_NTP_BACKGROUND] = ntp_background;
+ colors_[ThemeProperties::COLOR_NTP_TEXT] = ntp_foreground;
// The NTP header is the color that surrounds the current active thumbnail on
// the NTP, and acts as the border of the "Recent Links" box. It would be
// awesome if they were separated so we could use GetBorderColor() for the
// border around the "Recent Links" section, but matching the frame color is
// more important.
- SetThemeColorFromGtk(ThemeProperties::COLOR_NTP_HEADER,
- &frame_color);
- SetThemeColorFromGtk(ThemeProperties::COLOR_NTP_SECTION,
- &toolbar_color);
- SetThemeColorFromGtk(ThemeProperties::COLOR_NTP_SECTION_TEXT,
- &label_color);
-
- // Override the link color if the theme provides it.
- const GdkColor* link_color = NULL;
- gtk_widget_style_get(GTK_WIDGET(fake_window_),
- "link-color", &link_color, NULL);
-
- bool is_default_link_color = false;
- if (!link_color) {
- link_color = &kDefaultLinkColor;
- is_default_link_color = true;
- }
- SetThemeColorFromGtk(ThemeProperties::COLOR_NTP_LINK,
- link_color);
- SetThemeColorFromGtk(ThemeProperties::COLOR_NTP_LINK_UNDERLINE,
- link_color);
- SetThemeColorFromGtk(ThemeProperties::COLOR_NTP_SECTION_LINK,
- link_color);
- SetThemeColorFromGtk(ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE,
- link_color);
+ colors_[ThemeProperties::COLOR_NTP_HEADER] = frame_color;
+ colors_[ThemeProperties::COLOR_NTP_SECTION] = toolbar_color;
+ colors_[ThemeProperties::COLOR_NTP_SECTION_TEXT] = label_color;
- if (!is_default_link_color)
- gdk_color_free(const_cast<GdkColor*>(link_color));
+ // Default link color, taken from gtklinkbutton.c.
+ SkColor link_color = SkColorSetRGB(0, 0, 0xee);
+ GetChromeStyleColor("link-color", &link_color);
+
+ colors_[ThemeProperties::COLOR_NTP_LINK] = link_color;
+ colors_[ThemeProperties::COLOR_NTP_LINK_UNDERLINE] = link_color;
+ colors_[ThemeProperties::COLOR_NTP_SECTION_LINK] = link_color;
+ colors_[ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE] = link_color;
// Generate the colors that we pass to WebKit.
- focus_ring_color_ = GdkColorToSkColor(frame_color);
+ focus_ring_color_ = frame_color;
- GdkColor thumb_active_color, thumb_inactive_color, track_color;
- Gtk2UI::GetScrollbarColors(&thumb_active_color,
- &thumb_inactive_color,
- &track_color);
- thumb_active_color_ = GdkColorToSkColor(thumb_active_color);
- thumb_inactive_color_ = GdkColorToSkColor(thumb_inactive_color);
- track_color_ = GdkColorToSkColor(track_color);
+ SetScrollbarColors();
// Some GTK themes only define the text selection colors on the GtkEntry
// class, so we need to use that for getting selection colors.
active_selection_bg_color_ =
- GdkColorToSkColor(entry_style->base[GTK_STATE_SELECTED]);
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused);
active_selection_fg_color_ =
- GdkColorToSkColor(entry_style->text[GTK_STATE_SELECTED]);
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldSelectionColor);
inactive_selection_bg_color_ =
- GdkColorToSkColor(entry_style->base[GTK_STATE_ACTIVE]);
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldReadOnlyBackground);
inactive_selection_fg_color_ =
- GdkColorToSkColor(entry_style->text[GTK_STATE_ACTIVE]);
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldReadOnlyColor);
colors_[ThemeProperties::COLOR_THROBBER_SPINNING] =
- NativeThemeGtk2::instance()->GetSystemColor(
- ui::NativeTheme::kColorId_ThrobberSpinningColor);
+ theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberSpinningColor);
colors_[ThemeProperties::COLOR_THROBBER_WAITING] =
- NativeThemeGtk2::instance()->GetSystemColor(
- ui::NativeTheme::kColorId_ThrobberWaitingColor);
-}
-
-GdkColor Gtk2UI::BuildFrameColors(GtkStyle* frame_style) {
- GdkColor* theme_frame = NULL;
- GdkColor* theme_inactive_frame = NULL;
- GdkColor* theme_incognito_frame = NULL;
- GdkColor* theme_incognito_inactive_frame = NULL;
- gtk_widget_style_get(GTK_WIDGET(fake_frame_),
- "frame-color", &theme_frame,
- "inactive-frame-color", &theme_inactive_frame,
- "incognito-frame-color", &theme_incognito_frame,
- "incognito-inactive-frame-color",
- &theme_incognito_inactive_frame,
- NULL);
+ theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberWaitingColor);
+}
- GdkColor frame_color = BuildAndSetFrameColor(
- &frame_style->bg[GTK_STATE_SELECTED],
- theme_frame,
- kDefaultFrameShift,
- ThemeProperties::COLOR_FRAME,
- ThemeProperties::TINT_FRAME);
- if (theme_frame)
- gdk_color_free(theme_frame);
- SetThemeTintFromGtk(ThemeProperties::TINT_BACKGROUND_TAB, &frame_color);
-
- BuildAndSetFrameColor(
- &frame_style->bg[GTK_STATE_INSENSITIVE],
- theme_inactive_frame,
- kDefaultFrameShift,
- ThemeProperties::COLOR_FRAME_INACTIVE,
- ThemeProperties::TINT_FRAME_INACTIVE);
- if (theme_inactive_frame)
- gdk_color_free(theme_inactive_frame);
-
- BuildAndSetFrameColor(
- &frame_color,
- theme_incognito_frame,
- GetDefaultTint(ThemeProperties::TINT_FRAME_INCOGNITO),
- ThemeProperties::COLOR_FRAME_INCOGNITO,
- ThemeProperties::TINT_FRAME_INCOGNITO);
- if (theme_incognito_frame)
- gdk_color_free(theme_incognito_frame);
-
- BuildAndSetFrameColor(
- &frame_color,
- theme_incognito_inactive_frame,
- GetDefaultTint(ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE),
- ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE,
- ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE);
- if (theme_incognito_inactive_frame)
- gdk_color_free(theme_incognito_inactive_frame);
+SkColor Gtk2UI::BuildFrameColors() {
+ SkColor frame_color =
+ NativeThemeGtk2::instance()->GetSystemColor(
+ ui::NativeTheme::kColorId_WindowBackground);
+ SkColor temp_color;
+ SetThemeTint(ThemeProperties::TINT_BACKGROUND_TAB, frame_color);
+
+
+#if GTK_MAJOR_VERSION == 2
+ color_utils::HSL kDefaultFrameShift = { -1, -1, 0.4 };
+ GtkStyle* style = gtk_rc_get_style(NativeThemeGtk2::instance()->GetWindow());
+
+ frame_color = color_utils::HSLShift(frame_color, kDefaultFrameShift);
+ GetChromeStyleColor("frame-color", &frame_color);
+
+ temp_color = frame_color;
+ colors_[ThemeProperties::COLOR_FRAME] = temp_color;
+ SetThemeTint(ThemeProperties::TINT_FRAME, temp_color);
+
+ temp_color = color_utils::HSLShift(
+ GdkColorToSkColor(style->bg[GTK_STATE_INSENSITIVE]),
+ kDefaultFrameShift);
+ GetChromeStyleColor("inactive-frame-color", &temp_color);
+ colors_[ThemeProperties::COLOR_FRAME_INACTIVE] = temp_color;
+ SetThemeTint(ThemeProperties::TINT_FRAME_INACTIVE, temp_color);
+
+ temp_color = color_utils::HSLShift(
+ frame_color,
+ GetDefaultTint(ThemeProperties::TINT_FRAME_INCOGNITO));
+ GetChromeStyleColor("incognito-frame-color", &temp_color);
+ colors_[ThemeProperties::COLOR_FRAME_INCOGNITO] = temp_color;
+ SetThemeTint(ThemeProperties::TINT_FRAME_INCOGNITO, temp_color);
+
+ temp_color = color_utils::HSLShift(
+ frame_color,
+ GetDefaultTint(ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE));
+ GetChromeStyleColor("incognito-inactive-frame-color", &temp_color);
+ colors_[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = temp_color;
+ SetThemeTint(ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE, temp_color);
+#else
+ const SkBitmap* bitmap;
+
+ bitmap = GetThemeImageNamed(IDR_THEME_FRAME).ToSkBitmap();
+ bitmap->lockPixels();
+ temp_color = bitmap->getColor(bitmap->width() / 2, bitmap->height() - 1);
+ bitmap->unlockPixels();
+ colors_[ThemeProperties::COLOR_FRAME] = temp_color;
+
+ bitmap = GetThemeImageNamed(IDR_THEME_FRAME_INACTIVE).ToSkBitmap();
+ bitmap->lockPixels();
+ temp_color = bitmap->getColor(bitmap->width() / 2, bitmap->height() - 1);
+ bitmap->unlockPixels();
+ colors_[ThemeProperties::COLOR_FRAME_INACTIVE] = temp_color;
+
+ bitmap = GetThemeImageNamed(IDR_THEME_FRAME_INCOGNITO).ToSkBitmap();
+ bitmap->lockPixels();
+ temp_color = bitmap->getColor(bitmap->width() / 2, bitmap->height() - 1);
+ bitmap->unlockPixels();
+ colors_[ThemeProperties::COLOR_FRAME_INCOGNITO] = temp_color;
+
+ bitmap = GetThemeImageNamed(IDR_THEME_FRAME_INCOGNITO_INACTIVE).ToSkBitmap();
+ bitmap->lockPixels();
+ temp_color = bitmap->getColor(bitmap->width() / 2, bitmap->height() - 1);
+ bitmap->unlockPixels();
+ colors_[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = temp_color;
+#endif
return frame_color;
}
-void Gtk2UI::SetThemeColorFromGtk(int id, const GdkColor* color) {
- colors_[id] = GdkColorToSkColor(*color);
-}
-
-void Gtk2UI::SetThemeTintFromGtk(int id, const GdkColor* color) {
+void Gtk2UI::SetThemeTint(int id, SkColor color) {
color_utils::HSL default_tint = GetDefaultTint(id);
color_utils::HSL hsl;
- color_utils::SkColorToHSL(GdkColorToSkColor(*color), &hsl);
+ color_utils::SkColorToHSL(color, &hsl);
if (default_tint.s != -1)
hsl.s = default_tint.s;
@@ -1052,35 +930,14 @@ void Gtk2UI::SetThemeTintFromGtk(int id, const GdkColor* color) {
tints_[id] = hsl;
}
-GdkColor Gtk2UI::BuildAndSetFrameColor(const GdkColor* base,
- const GdkColor* gtk_base,
- const color_utils::HSL& tint,
- int color_id,
- int tint_id) {
- GdkColor out_color = *base;
- if (gtk_base) {
- // The theme author specified a color to use, use it without modification.
- out_color = *gtk_base;
- } else {
- // Tint the basic color since this is a heuristic color instead of one
- // specified by the theme author.
- GdkColorHSLShift(tint, &out_color);
- }
- SetThemeColorFromGtk(color_id, &out_color);
- SetThemeTintFromGtk(tint_id, &out_color);
-
- return out_color;
-}
-
SkBitmap Gtk2UI::GenerateGtkThemeBitmap(int id) const {
switch (id) {
case IDR_THEME_TOOLBAR: {
- GtkStyle* style = gtk_rc_get_style(fake_window_);
- GdkColor* color = &style->bg[GTK_STATE_NORMAL];
SkBitmap bitmap;
bitmap.allocN32Pixels(kToolbarImageWidth, kToolbarImageHeight);
- bitmap.eraseARGB(0xff, color->red >> 8, color->green >> 8,
- color->blue >> 8);
+ bitmap.eraseColor(
+ NativeThemeGtk2::instance()->GetSystemColor(
+ ui::NativeTheme::kColorId_LabelBackgroundColor));
return bitmap;
}
case IDR_THEME_TAB_BACKGROUND:
@@ -1143,9 +1000,11 @@ SkBitmap Gtk2UI::GenerateGtkThemeBitmap(int id) const {
return GenerateGTKIcon(id);
}
case IDR_TOOLBAR_BEZEL_HOVER:
- return GenerateToolbarBezel(GTK_STATE_PRELIGHT, IDR_TOOLBAR_BEZEL_HOVER);
+ return GenerateToolbarBezel(
+ ui::NativeTheme::kHovered, IDR_TOOLBAR_BEZEL_HOVER);
case IDR_TOOLBAR_BEZEL_PRESSED:
- return GenerateToolbarBezel(GTK_STATE_ACTIVE, IDR_TOOLBAR_BEZEL_PRESSED);
+ return GenerateToolbarBezel(
+ ui::NativeTheme::kPressed, IDR_TOOLBAR_BEZEL_PRESSED);
default: {
return GenerateTintedIcon(id, button_tint_);
}
@@ -1157,28 +1016,29 @@ SkBitmap Gtk2UI::GenerateGtkThemeBitmap(int id) const {
SkBitmap Gtk2UI::GenerateFrameImage(
int color_id,
const char* gradient_name) const {
- // We use two colors: the main color (passed in) and a lightened version of
- // that color (which is supposed to match the light gradient at the top of
- // several GTK+ themes, such as Ambiance, Clearlooks or Bluebird).
+#if GTK_MAJOR_VERSION == 2
ColorMap::const_iterator it = colors_.find(color_id);
DCHECK(it != colors_.end());
SkColor base = it->second;
+ // We use two colors: the main color (passed in) and a lightened version of
+ // that color (which is supposed to match the light gradient at the top of
+ // several GTK+ themes, such as Ambiance, Clearlooks or Bluebird).
+ const color_utils::HSL kGtkFrameShift = { -1, -1, 0.58 };
gfx::Canvas canvas(gfx::Size(kToolbarImageWidth, kToolbarImageHeight),
1.0f, true);
+ SkColor gradient_top_color = color_utils::HSLShift(base, kGtkFrameShift);
int gradient_size;
- GdkColor* gradient_top_color = NULL;
- gtk_widget_style_get(GTK_WIDGET(fake_frame_),
+
+ GetChromeStyleColor(gradient_name, &gradient_top_color);
+ gtk_widget_style_get(NativeThemeGtk2::instance()->GetWindow(),
"frame-gradient-size", &gradient_size,
- gradient_name, &gradient_top_color,
NULL);
+
if (gradient_size) {
- SkColor lighter = gradient_top_color ?
- GdkColorToSkColor(*gradient_top_color) :
- color_utils::HSLShift(base, kGtkFrameShift);
skia::RefPtr<SkShader> shader = gfx::CreateGradientShader(
- 0, gradient_size, lighter, base);
+ 0, gradient_size, gradient_top_color, base);
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setAntiAlias(true);
@@ -1187,12 +1047,54 @@ SkBitmap Gtk2UI::GenerateFrameImage(
canvas.DrawRect(gfx::Rect(0, 0, kToolbarImageWidth, gradient_size), paint);
}
- if (gradient_top_color)
- gdk_color_free(gradient_top_color);
-
canvas.FillRect(gfx::Rect(0, gradient_size, kToolbarImageWidth,
kToolbarImageHeight - gradient_size), base);
return canvas.ExtractImageRep().sk_bitmap();
+
+#else
+ // Render a GtkHeaderBar as our title bar, cropping out any curved edges on
+ // the left and right sides. Also remove the bottom border for good measure.
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(kToolbarImageWidth, 40);
+ bitmap.eraseColor(0);
+
+
+ static GtkWidget* title = NULL;
+ if (!title) {
+ title = gtk_header_bar_new();
+ gtk_widget_set_size_request(title, kToolbarImageWidth * 2, 48);
+
+ GtkWidget* window = gtk_offscreen_window_new();
+ gtk_container_add(GTK_CONTAINER(window), title);
+
+ gtk_widget_show_all(window);
+ }
+
+ cairo_surface_t* surface = cairo_image_surface_create_for_data(
+ static_cast<unsigned char*>(bitmap.getAddr(0, 0)),
+ CAIRO_FORMAT_ARGB32,
+ bitmap.width(), bitmap.height(),
+ bitmap.width() * 4);
+ cairo_t* cr = cairo_create(surface);
+ cairo_translate(cr, kToolbarImageWidth / -2, 0);
+ gtk_widget_draw(title, cr);
+ cairo_destroy(cr);
+ cairo_surface_destroy(surface);
+
+ switch (color_id) {
+ case ThemeProperties::COLOR_FRAME_INACTIVE:
+ return SkBitmapOperations::CreateHSLShiftedBitmap(bitmap,
+ kDefaultTintFrameInactive);
+ case ThemeProperties::COLOR_FRAME_INCOGNITO:
+ return SkBitmapOperations::CreateHSLShiftedBitmap(bitmap,
+ kDefaultTintFrameIncognito);
+ case ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE:
+ return SkBitmapOperations::CreateHSLShiftedBitmap(bitmap,
+ kDefaultTintFrameIncognitoInactive);
+ }
+
+ return bitmap;
+#endif
}
SkBitmap Gtk2UI::GenerateTabImage(int base_id) const {
@@ -1213,11 +1115,11 @@ SkBitmap Gtk2UI::GenerateTintedIcon(
SkBitmap Gtk2UI::GenerateGTKIcon(int base_id) const {
const char* stock_id = NULL;
- GtkStateType gtk_state = GTK_STATE_NORMAL;
+ bool enabled = true;
for (unsigned int i = 0; i < arraysize(kGtkIcons); ++i) {
if (kGtkIcons[i].idr == base_id) {
stock_id = kGtkIcons[i].stock_id;
- gtk_state = kGtkIcons[i].gtk_state;
+ enabled = kGtkIcons[i].enabled;
break;
}
}
@@ -1226,20 +1128,13 @@ SkBitmap Gtk2UI::GenerateGTKIcon(int base_id) const {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
SkBitmap default_bitmap = rb.GetImageNamed(base_id).AsBitmap();
- gtk_widget_ensure_style(fake_frame_);
- GtkStyle* style = gtk_widget_get_style(fake_frame_);
- GtkIconSet* icon_set = gtk_style_lookup_icon_set(style, stock_id);
- if (!icon_set)
- return default_bitmap;
-
// Ask GTK to render the icon to a buffer, which we will steal from.
- GdkPixbuf* gdk_icon = gtk_icon_set_render_icon(
- icon_set,
- style,
- base::i18n::IsRTL() ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR,
- gtk_state,
- GTK_ICON_SIZE_SMALL_TOOLBAR,
- fake_frame_,
+ GtkIconTheme* icon_theme = gtk_icon_theme_get_default();
+ GdkPixbuf* gdk_icon = gtk_icon_theme_load_icon(
+ icon_theme,
+ stock_id,
+ 20,
+ (GtkIconLookupFlags)0,
NULL);
if (!gdk_icon) {
@@ -1249,6 +1144,25 @@ SkBitmap Gtk2UI::GenerateGTKIcon(int base_id) const {
return default_bitmap;
}
+#if GTK_MAJOR_VERSION == 2
+ GtkIconSource* icon_source = gtk_icon_source_new();
+ gtk_icon_source_set_pixbuf(icon_source, gdk_icon);
+
+ GdkPixbuf* temp = gtk_style_render_icon(
+ gtk_rc_get_style(NativeThemeGtk2::instance()->GetButton()),
+ icon_source,
+ GTK_TEXT_DIR_NONE,
+ enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
+ (GtkIconSize)-1,
+ NativeThemeGtk2::instance()->GetButton(),
+ NULL);
+
+ gtk_icon_source_free(icon_source);
+ g_object_unref(gdk_icon);
+
+ gdk_icon = temp;
+#endif
+
SkBitmap retval;
retval.allocN32Pixels(default_bitmap.width(), default_bitmap.height());
retval.eraseColor(0);
@@ -1257,125 +1171,143 @@ SkBitmap Gtk2UI::GenerateGTKIcon(int base_id) const {
g_object_unref(gdk_icon);
SkCanvas canvas(retval);
+ SkPaint paint;
- if (gtk_state == GTK_STATE_ACTIVE || gtk_state == GTK_STATE_PRELIGHT) {
- SkBitmap border = DrawGtkButtonBorder(gtk_state,
- false,
- false,
- default_bitmap.width(),
- default_bitmap.height());
- canvas.drawBitmap(border, 0, 0);
- }
+#if GTK_MAJOR_VERSION > 2
+ if (!enabled)
+ paint.setAlpha(128);
+#endif
canvas.drawBitmap(icon,
(default_bitmap.width() / 2) - (icon.width() / 2),
- (default_bitmap.height() / 2) - (icon.height() / 2));
+ (default_bitmap.height() / 2) - (icon.height() / 2),
+ &paint);
return retval;
}
-SkBitmap Gtk2UI::GenerateToolbarBezel(int gtk_state, int sizing_idr) const {
+SkBitmap Gtk2UI::GenerateToolbarBezel(
+ ui::NativeTheme::State state,
+ int sizing_idr) const {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
SkBitmap default_bitmap =
rb.GetImageNamed(sizing_idr).AsBitmap();
- SkBitmap retval;
- retval.allocN32Pixels(default_bitmap.width(), default_bitmap.height());
- retval.eraseColor(0);
-
- SkCanvas canvas(retval);
- SkBitmap border = DrawGtkButtonBorder(
- gtk_state,
- false,
- false,
+ return DrawGtkButtonBorder(
+ NULL,
+ state,
default_bitmap.width(),
default_bitmap.height());
- canvas.drawBitmap(border, 0, 0);
-
- return retval;
}
void Gtk2UI::GetNormalButtonTintHSL(color_utils::HSL* tint) const {
- GtkStyle* window_style = gtk_rc_get_style(fake_window_);
- const GdkColor accent_gdk_color = window_style->bg[GTK_STATE_SELECTED];
- const GdkColor base_color = window_style->base[GTK_STATE_NORMAL];
+ NativeThemeGtk2* theme = NativeThemeGtk2::instance();
- GtkStyle* label_style = gtk_rc_get_style(fake_label_.get());
- const GdkColor text_color = label_style->fg[GTK_STATE_NORMAL];
+ SkColor accent_color =
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_ButtonHighlightColor);
+ SkColor text_color =
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_LabelEnabledColor);
+ SkColor base_color =
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_LabelBackgroundColor);
- PickButtonTintFromColors(accent_gdk_color, text_color, base_color, tint);
+ PickButtonTintFromColors(accent_color, text_color, base_color, tint);
}
void Gtk2UI::GetNormalEntryForegroundHSL(color_utils::HSL* tint) const {
- GtkStyle* window_style = gtk_rc_get_style(fake_window_);
- const GdkColor accent_gdk_color = window_style->bg[GTK_STATE_SELECTED];
+ NativeThemeGtk2* theme = NativeThemeGtk2::instance();
- GtkStyle* style = gtk_rc_get_style(fake_entry_.get());
- const GdkColor text_color = style->text[GTK_STATE_NORMAL];
- const GdkColor base_color = style->base[GTK_STATE_NORMAL];
+ SkColor accent_color =
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_ButtonHighlightColor);
+ SkColor text_color =
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldDefaultColor);
+ SkColor base_color =
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldDefaultBackground);
- PickButtonTintFromColors(accent_gdk_color, text_color, base_color, tint);
+ PickButtonTintFromColors(accent_color, text_color, base_color, tint);
}
void Gtk2UI::GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const {
// The simplest of all the tints. We just use the selected text in the entry
// since the icons tinted this way will only be displayed against
// base[GTK_STATE_SELECTED].
- GtkStyle* style = gtk_rc_get_style(fake_entry_.get());
- const GdkColor color = style->text[GTK_STATE_SELECTED];
- color_utils::SkColorToHSL(GdkColorToSkColor(color), tint);
+ SkColor color =
+ NativeThemeGtk2::instance()->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldSelectionColor);
+
+ color_utils::SkColorToHSL(color, tint);
}
-SkBitmap Gtk2UI::DrawGtkButtonBorder(int gtk_state,
- bool focused,
- bool call_to_action,
+SkBitmap Gtk2UI::DrawGtkButtonBorder(const char* class_name,
+ ui::NativeTheme::State state,
int width,
int height) const {
+ SkBitmap border;
+ border.allocN32Pixels(width, height);
+ border.eraseColor(0);
+
// Create a temporary GTK button to snapshot
GtkWidget* window = gtk_offscreen_window_new();
- GtkWidget* button = gtk_button_new();
+ GtkWidget* button = gtk_toggle_button_new();
+
+ if (state == ui::NativeTheme::kPressed)
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), true);
+ else if (state == ui::NativeTheme::kDisabled)
+ gtk_widget_set_sensitive(button, false);
+
gtk_widget_set_size_request(button, width, height);
gtk_container_add(GTK_CONTAINER(window), button);
- gtk_widget_realize(window);
- gtk_widget_realize(button);
- gtk_widget_show(button);
- gtk_widget_show(window);
-
- if (call_to_action)
- GTK_WIDGET_SET_FLAGS(button, GTK_HAS_DEFAULT);
-
- if (focused) {
- // We can't just use gtk_widget_grab_focus() here because that sets
- // gtk_widget_is_focus(), but not gtk_widget_has_focus(), which is what the
- // GtkButton's paint checks.
- GTK_WIDGET_SET_FLAGS(button, GTK_HAS_FOCUS);
+
+ if (class_name == views::BlueButton::kViewClassName) {
+ gtk_widget_set_can_default(button, true);
+ gtk_widget_grab_default(button);
}
- gtk_widget_set_state(button, static_cast<GtkStateType>(gtk_state));
+ gtk_widget_show_all(window);
+
+ cairo_surface_t* surface = cairo_image_surface_create_for_data(
+ static_cast<unsigned char*>(border.getAddr(0, 0)),
+ CAIRO_FORMAT_ARGB32,
+ width, height,
+ width * 4);
+ cairo_t* cr = cairo_create(surface);
+
+#if GTK_MAJOR_VERSION == 2
+ int w, h;
GdkPixmap* pixmap;
+
{
// http://crbug.com/346740
ANNOTATE_SCOPED_MEMORY_LEAK;
pixmap = gtk_widget_get_snapshot(button, NULL);
}
- int w, h;
- gdk_drawable_get_size(GDK_DRAWABLE(pixmap), &w, &h);
- DCHECK_EQ(w, width);
- DCHECK_EQ(h, height);
- // We render the Pixmap to a Pixbuf. This can be slow, as we're scrapping
- // bits from X.
+ gdk_drawable_get_size(GDK_DRAWABLE(pixmap), &w, &h);
GdkColormap* colormap = gdk_drawable_get_colormap(pixmap);
GdkPixbuf* pixbuf = gdk_pixbuf_get_from_drawable(NULL,
GDK_DRAWABLE(pixmap),
colormap,
0, 0, 0, 0, w, h);
- // Finally, we convert our pixbuf into a type we can use.
- SkBitmap border = GdkPixbufToImageSkia(pixbuf);
+ gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
+ cairo_paint(cr);
+
g_object_unref(pixbuf);
g_object_unref(pixmap);
+#else
+ gtk_widget_draw(button, cr);
+#endif
+
+ cairo_destroy(cr);
+ cairo_surface_destroy(surface);
+
+
gtk_widget_destroy(window);
return border;
@@ -1385,7 +1317,11 @@ void Gtk2UI::ClearAllThemeData() {
gtk_images_.clear();
}
-void Gtk2UI::UpdateDefaultFont(const PangoFontDescription* desc) {
+void Gtk2UI::UpdateDefaultFont() {
+ PangoContext* pc = gtk_widget_get_pango_context(
+ NativeThemeGtk2::instance()->GetLabel());
+ const PangoFontDescription* desc = pango_context_get_font_description(pc);
+
// Use gfx::FontRenderParams to select a family and determine the rendering
// settings.
gfx::FontRenderParamsQuery query;
@@ -1422,7 +1358,7 @@ void Gtk2UI::UpdateDefaultFont(const PangoFontDescription* desc) {
default_font_style_ = query.style;
}
-void Gtk2UI::OnStyleSet(GtkWidget* widget, GtkStyle* previous_style) {
+void Gtk2UI::ResetStyle() {
ClearAllThemeData();
LoadGtkValues();
NativeThemeGtk2::instance()->NotifyObservers();
@@ -1430,8 +1366,7 @@ void Gtk2UI::OnStyleSet(GtkWidget* widget, GtkStyle* previous_style) {
void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) {
device_scale_factor_ = device_scale_factor;
- GtkStyle* label_style = gtk_rc_get_style(fake_label_.get());
- UpdateDefaultFont(label_style->font_desc);
+ UpdateDefaultFont();
}
float Gtk2UI::GetDeviceScaleFactor() const {
« no previous file with comments | « chrome/browser/ui/libgtk2ui/gtk2_ui.h ('k') | chrome/browser/ui/libgtk2ui/gtk2_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698