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 f9ce890766ce94e9069bcf1ad20e63e448979600..d63ed808bb27c898f692cdfa56b08e8583151b7f 100644 |
--- a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc |
+++ b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc |
@@ -110,12 +110,7 @@ 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 }; |
+const color_utils::HSL kGtkFrameShift = { -1, -1, 0.8 }; |
// Values used as the new luminance and saturation values in the inactive tab |
// text color. |
@@ -124,12 +119,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. |
@@ -184,21 +173,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, GTK_STOCK_GO_BACK, true }, |
+ { IDR_BACK_D, GTK_STOCK_GO_BACK, false }, |
- { IDR_FORWARD, GTK_STOCK_GO_FORWARD, GTK_STATE_NORMAL }, |
- { IDR_FORWARD_D, GTK_STOCK_GO_FORWARD, GTK_STATE_INSENSITIVE }, |
+ { IDR_FORWARD, GTK_STOCK_GO_FORWARD, true }, |
+ { IDR_FORWARD_D, GTK_STOCK_GO_FORWARD, false }, |
- { IDR_HOME, GTK_STOCK_HOME, GTK_STATE_NORMAL }, |
+ { IDR_HOME, GTK_STOCK_HOME, true }, |
- { IDR_RELOAD, GTK_STOCK_REFRESH, GTK_STATE_NORMAL }, |
- { IDR_RELOAD_D, GTK_STOCK_REFRESH, GTK_STATE_INSENSITIVE }, |
+ { IDR_RELOAD, GTK_STOCK_REFRESH, true }, |
+ { IDR_RELOAD_D, GTK_STOCK_REFRESH, false }, |
- { IDR_STOP, GTK_STOCK_STOP, GTK_STATE_NORMAL }, |
- { IDR_STOP_D, GTK_STOCK_STOP, GTK_STATE_INSENSITIVE }, |
+ { IDR_STOP, GTK_STOCK_STOP, true }, |
+ { IDR_STOP_D, GTK_STOCK_STOP, false }, |
}; |
// The image resources that will be tinted by the 'button' tint value. |
@@ -233,27 +222,20 @@ bool IsOverridableImage(int id) { |
} |
// 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, |
@@ -300,17 +282,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) { |
@@ -456,18 +427,13 @@ Gtk2UI::Gtk2UI() |
void Gtk2UI::Initialize() { |
signals_.reset(new Gtk2SignalRegistrar); |
- // Create our fake widgets. |
- fake_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
+ // Create fake frame. |
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_); |
- |
signals_->Connect(fake_frame_, "style-set", |
G_CALLBACK(&OnStyleSetThunk), this); |
@@ -490,11 +456,7 @@ void Gtk2UI::Initialize() { |
} |
Gtk2UI::~Gtk2UI() { |
- gtk_widget_destroy(fake_window_); |
gtk_widget_destroy(fake_frame_); |
- fake_label_.Destroy(); |
- fake_entry_.Destroy(); |
- |
ClearAllThemeData(); |
} |
@@ -766,9 +728,7 @@ 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) { |
+void Gtk2UI::SetScrollbarColors() { |
GdkColor* theme_thumb_active = NULL; |
GdkColor* theme_thumb_inactive = NULL; |
GdkColor* theme_trough_color = NULL; |
@@ -781,99 +741,15 @@ void Gtk2UI::GetScrollbarColors(GdkColor* thumb_active_color, |
// 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; |
+ thumb_active_color_ = GdkColorToSkColor(*theme_thumb_active); |
+ thumb_inactive_color_ = GdkColorToSkColor(*theme_thumb_inactive); |
+ track_color_ = GdkColorToSkColor(*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); |
- } |
- |
- if (theme_trough_color) { |
- *track_color = *theme_trough_color; |
- gdk_color_free(theme_trough_color); |
- } |
} |
void Gtk2UI::LoadGtkValues() { |
@@ -882,31 +758,29 @@ 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_); |
- |
- GtkStyle* window_style = gtk_rc_get_style(fake_window_); |
- SetThemeColorFromGtk(ThemeProperties::COLOR_CONTROL_BACKGROUND, |
- &window_style->bg[GTK_STATE_NORMAL]); |
+ SkColor toolbar_color = |
+ GET_BG_COLOR(NativeThemeGtk2::instance()->GetWindow(), NORMAL); |
+ SkColor button_color = |
+ GET_BG_COLOR(NativeThemeGtk2::instance()->GetWindow(), SELECTED); |
+ SkColor label_color = |
+ GET_FG_COLOR(NativeThemeGtk2::instance()->GetWindow(), NORMAL); |
- 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 |
@@ -933,70 +807,56 @@ 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 = |
+ GET_BASE_COLOR(NativeThemeGtk2::instance()->GetEntry(), NORMAL); |
+ SkColor ntp_foreground = |
+ GET_TEXT_COLOR(NativeThemeGtk2::instance()->GetEntry(), NORMAL); |
+ |
+ 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); |
+ |
+ GdkColor* theme_link_color = NULL; |
+ gtk_widget_style_get(NativeThemeGtk2::instance()->GetWindow(), |
+ "link-color", &theme_link_color, NULL); |
+ if (theme_link_color) { |
+ link_color = GdkColorToSkColor(*theme_link_color); |
+ gdk_color_free(theme_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]); |
+ GET_BASE_COLOR(NativeThemeGtk2::instance()->GetEntry(), SELECTED); |
active_selection_fg_color_ = |
- GdkColorToSkColor(entry_style->text[GTK_STATE_SELECTED]); |
+ GET_TEXT_COLOR(NativeThemeGtk2::instance()->GetEntry(), SELECTED); |
inactive_selection_bg_color_ = |
- GdkColorToSkColor(entry_style->base[GTK_STATE_ACTIVE]); |
+ GET_BASE_COLOR(NativeThemeGtk2::instance()->GetEntry(), ACTIVE); |
inactive_selection_fg_color_ = |
- GdkColorToSkColor(entry_style->text[GTK_STATE_ACTIVE]); |
+ GET_TEXT_COLOR(NativeThemeGtk2::instance()->GetEntry(), ACTIVE); |
colors_[ThemeProperties::COLOR_THROBBER_SPINNING] = |
NativeThemeGtk2::instance()->GetSystemColor( |
@@ -1006,11 +866,12 @@ void Gtk2UI::LoadGtkValues() { |
ui::NativeTheme::kColorId_ThrobberWaitingColor); |
} |
-GdkColor Gtk2UI::BuildFrameColors(GtkStyle* frame_style) { |
+SkColor Gtk2UI::BuildFrameColors() { |
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, |
@@ -1019,54 +880,62 @@ GdkColor Gtk2UI::BuildFrameColors(GtkStyle* frame_style) { |
&theme_incognito_inactive_frame, |
NULL); |
- GdkColor frame_color = BuildAndSetFrameColor( |
- &frame_style->bg[GTK_STATE_SELECTED], |
- theme_frame, |
- kDefaultFrameShift, |
- ThemeProperties::COLOR_FRAME, |
- ThemeProperties::TINT_FRAME); |
- if (theme_frame) |
+ SkColor frame_color = GET_BG_COLOR(fake_frame_, NORMAL); |
+ SkColor temp_color; |
+ SetThemeTint(ThemeProperties::TINT_BACKGROUND_TAB, frame_color); |
+ |
+ |
+ temp_color = color_utils::HSLShift( |
+ frame_color, |
+ GetDefaultTint(ThemeProperties::TINT_FRAME)); |
+ if (theme_frame) { |
+ temp_color = GdkColorToSkColor(*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) |
+ } |
+ colors_[ThemeProperties::COLOR_FRAME] = temp_color; |
+ SetThemeTint(ThemeProperties::TINT_FRAME, temp_color); |
+ |
+ |
+ temp_color = color_utils::HSLShift( |
+ frame_color, |
+ GetDefaultTint(ThemeProperties::TINT_FRAME_INACTIVE)); |
+ if (theme_inactive_frame) { |
+ temp_color = GdkColorToSkColor(*theme_inactive_frame); |
gdk_color_free(theme_inactive_frame); |
+ } |
+ colors_[ThemeProperties::COLOR_FRAME_INACTIVE] = temp_color; |
+ SetThemeTint(ThemeProperties::TINT_FRAME_INACTIVE, temp_color); |
+ |
- BuildAndSetFrameColor( |
- &frame_color, |
- theme_incognito_frame, |
- GetDefaultTint(ThemeProperties::TINT_FRAME_INCOGNITO), |
- ThemeProperties::COLOR_FRAME_INCOGNITO, |
- ThemeProperties::TINT_FRAME_INCOGNITO); |
- if (theme_incognito_frame) |
+ temp_color = color_utils::HSLShift( |
+ frame_color, |
+ GetDefaultTint(ThemeProperties::TINT_FRAME_INCOGNITO)); |
+ if (theme_incognito_frame) { |
+ temp_color = GdkColorToSkColor(*theme_incognito_frame); |
gdk_color_free(theme_incognito_frame); |
+ } |
+ colors_[ThemeProperties::COLOR_FRAME_INCOGNITO] = temp_color; |
+ SetThemeTint(ThemeProperties::TINT_FRAME_INCOGNITO, temp_color); |
- 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) |
+ |
+ temp_color = color_utils::HSLShift( |
+ frame_color, |
+ GetDefaultTint(ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE)); |
+ if (theme_incognito_inactive_frame) { |
+ temp_color = GdkColorToSkColor(*theme_incognito_inactive_frame); |
gdk_color_free(theme_incognito_inactive_frame); |
+ } |
+ colors_[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = temp_color; |
+ SetThemeTint(ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE, temp_color); |
- return frame_color; |
-} |
-void Gtk2UI::SetThemeColorFromGtk(int id, const GdkColor* color) { |
- colors_[id] = GdkColorToSkColor(*color); |
+ return frame_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; |
@@ -1077,35 +946,13 @@ 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(GET_BG_COLOR(NativeThemeGtk2::instance()->GetWindow(), |
+ NORMAL)); |
return bitmap; |
} |
case IDR_THEME_TAB_BACKGROUND: |
@@ -1168,9 +1015,9 @@ 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_); |
} |
@@ -1238,11 +1085,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; |
} |
} |
@@ -1262,7 +1109,7 @@ SkBitmap Gtk2UI::GenerateGTKIcon(int base_id) const { |
icon_set, |
style, |
base::i18n::IsRTL() ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR, |
- gtk_state, |
+ enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, |
GTK_ICON_SIZE_SMALL_TOOLBAR, |
fake_frame_, |
NULL); |
@@ -1283,15 +1130,6 @@ SkBitmap Gtk2UI::GenerateGTKIcon(int base_id) const { |
SkCanvas canvas(retval); |
- 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); |
- } |
- |
canvas.drawBitmap(icon, |
(default_bitmap.width() / 2) - (icon.width() / 2), |
(default_bitmap.height() / 2) - (icon.height() / 2)); |
@@ -1299,108 +1137,101 @@ SkBitmap Gtk2UI::GenerateGTKIcon(int base_id) const { |
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( |
+ 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]; |
+ SkColor accent_color = |
+ GET_BG_COLOR(NativeThemeGtk2::instance()->GetWindow(), SELECTED); |
+ SkColor text_color = |
+ GET_FG_COLOR(NativeThemeGtk2::instance()->GetLabel(), NORMAL); |
+ SkColor base_color = |
+ GET_BASE_COLOR(NativeThemeGtk2::instance()->GetWindow(), NORMAL); |
- GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); |
- const GdkColor text_color = label_style->fg[GTK_STATE_NORMAL]; |
- |
- 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]; |
- |
- 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 = |
+ GET_BG_COLOR(NativeThemeGtk2::instance()->GetWindow(), SELECTED); |
+ SkColor text_color = |
+ GET_TEXT_COLOR(NativeThemeGtk2::instance()->GetEntry(), NORMAL); |
+ SkColor base_color = |
+ GET_BASE_COLOR(NativeThemeGtk2::instance()->GetEntry(), NORMAL); |
- 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 = |
+ GET_TEXT_COLOR(NativeThemeGtk2::instance()->GetEntry(), SELECTED); |
+ |
+ color_utils::SkColorToHSL(color, tint); |
} |
-SkBitmap Gtk2UI::DrawGtkButtonBorder(int gtk_state, |
- bool focused, |
- bool call_to_action, |
+SkBitmap Gtk2UI::DrawGtkButtonBorder(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); |
- } |
+ gtk_widget_show_all(window); |
- gtk_widget_set_state(button, static_cast<GtkStateType>(gtk_state)); |
+ 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); |
- GdkPixmap* pixmap; |
- { |
- // http://crbug.com/346740 |
- ANNOTATE_SCOPED_MEMORY_LEAK; |
- pixmap = gtk_widget_get_snapshot(button, NULL); |
- } |
+#if GTK_MAJOR_VERSION == 2 |
int w, h; |
+ GdkPixmap* pixmap = gtk_widget_get_snapshot(button, NULL); |
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. |
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; |
@@ -1410,7 +1241,10 @@ void Gtk2UI::ClearAllThemeData() { |
gtk_images_.clear(); |
} |
-void Gtk2UI::UpdateDefaultFont(const PangoFontDescription* desc) { |
+void Gtk2UI::UpdateDefaultFont() { |
+ GtkStyle* style = gtk_rc_get_style(NativeThemeGtk2::instance()->GetLabel()); |
+ const PangoFontDescription* desc = style->font_desc; |
+ |
// Use gfx::FontRenderParams to select a family and determine the rendering |
// settings. |
gfx::FontRenderParamsQuery query; |
@@ -1455,8 +1289,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 { |