Skip to content

Commit

Permalink
GTK native theme: use link color from theme throughout native UI
Browse files Browse the repository at this point in the history
You can see this, e.g., in the translate bubble

BUG=none

Review URL: https://codereview.chromium.org/1405993003

Cr-Commit-Position: refs/heads/master@{#355928}
  • Loading branch information
estade authored and Commit bot committed Oct 23, 2015
1 parent dce41e5 commit 88eb158
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 34 deletions.
47 changes: 17 additions & 30 deletions chrome/browser/ui/libgtk2ui/gtk2_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,24 +340,6 @@ const color_utils::HSL kDefaultTintFrameIncognito = { -1, 0.2f, 0.35f };
const color_utils::HSL kDefaultTintFrameIncognitoInactive = { -1, 0.3f, 0.6f };
const color_utils::HSL kDefaultTintBackgroundTab = { -1, 0.5, 0.75 };



// 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_color| will usually be the same color through a theme, this
// function will get called with the normal GtkLabel |text_color|/GtkWindow
Expand Down Expand Up @@ -908,9 +890,12 @@ void Gtk2UI::SetScrollbarColors() {
thumb_inactive_color_ = SkColorSetRGB(234, 234, 234);
track_color_ = SkColorSetRGB(211, 211, 211);

GetChromeStyleColor("scrollbar-slider-prelight-color", &thumb_active_color_);
GetChromeStyleColor("scrollbar-slider-normal-color", &thumb_inactive_color_);
GetChromeStyleColor("scrollbar-trough-color", &track_color_);
NativeThemeGtk2::instance()->GetChromeStyleColor(
"scrollbar-slider-prelight-color", &thumb_active_color_);
NativeThemeGtk2::instance()->GetChromeStyleColor(
"scrollbar-slider-normal-color", &thumb_inactive_color_);
NativeThemeGtk2::instance()->GetChromeStyleColor("scrollbar-trough-color",
&track_color_);
}

void Gtk2UI::LoadGtkValues() {
Expand Down Expand Up @@ -991,10 +976,8 @@ void Gtk2UI::LoadGtkValues() {
colors_[ThemeProperties::COLOR_NTP_SECTION] = toolbar_color;
colors_[ThemeProperties::COLOR_NTP_SECTION_TEXT] = label_color;

// Default link color, taken from gtklinkbutton.c.
SkColor link_color = SkColorSetRGB(0, 0, 0xee);
GetChromeStyleColor("link-color", &link_color);

SkColor link_color =
theme->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled);
colors_[ThemeProperties::COLOR_NTP_LINK] = link_color;
colors_[ThemeProperties::COLOR_NTP_LINK_UNDERLINE] = link_color;
colors_[ThemeProperties::COLOR_NTP_SECTION_LINK] = link_color;
Expand Down Expand Up @@ -1039,7 +1022,7 @@ SkColor Gtk2UI::BuildFrameColors() {
GtkStyle* style = gtk_rc_get_style(NativeThemeGtk2::instance()->GetWindow());

frame_color = color_utils::HSLShift(frame_color, kDefaultFrameShift);
GetChromeStyleColor("frame-color", &frame_color);
NativeThemeGtk2::instance()->GetChromeStyleColor("frame-color", &frame_color);

temp_color = frame_color;
colors_[ThemeProperties::COLOR_FRAME] = temp_color;
Expand All @@ -1048,21 +1031,24 @@ SkColor Gtk2UI::BuildFrameColors() {
temp_color = color_utils::HSLShift(
GdkColorToSkColor(style->bg[GTK_STATE_INSENSITIVE]),
kDefaultFrameShift);
GetChromeStyleColor("inactive-frame-color", &temp_color);
NativeThemeGtk2::instance()->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);
NativeThemeGtk2::instance()->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);
NativeThemeGtk2::instance()->GetChromeStyleColor(
"incognito-inactive-frame-color", &temp_color);
colors_[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = temp_color;
SetThemeTint(ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE, temp_color);
#else
Expand Down Expand Up @@ -1262,7 +1248,8 @@ SkBitmap Gtk2UI::GenerateFrameImage(
SkColor gradient_top_color = color_utils::HSLShift(base, kGtkFrameShift);
int gradient_size;

GetChromeStyleColor(gradient_name, &gradient_top_color);
NativeThemeGtk2::instance()->GetChromeStyleColor(gradient_name,
&gradient_top_color);
gtk_widget_style_get(NativeThemeGtk2::instance()->GetWindow(),
"frame-gradient-size", &gradient_size,
NULL);
Expand Down
29 changes: 25 additions & 4 deletions chrome/browser/ui/libgtk2ui/native_theme_gtk2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,16 @@ SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const {
return GetBGColor(GetWindow(), NORMAL);

// Link
// TODO(estade): get these from the gtk theme instead of hardcoding.
case kColorId_LinkDisabled:
return SK_ColorBLACK;
case kColorId_LinkEnabled:
return SkColorSetRGB(0x33, 0x67, 0xD6);
return SkColorSetA(GetSystemColor(kColorId_LinkEnabled), 0xBB);
case kColorId_LinkEnabled: {
SkColor link_color = SK_ColorTRANSPARENT;
GetChromeStyleColor("link-color", &link_color);
if (link_color != SK_ColorTRANSPARENT)
return link_color;
// Default color comes from gtklinkbutton.c.
return SkColorSetRGB(0x00, 0x00, 0xEE);
}
case kColorId_LinkPressed:
return SK_ColorRED;

Expand Down Expand Up @@ -441,6 +446,22 @@ SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const {
return kInvalidColorIdColor;
}

// Get ChromeGtkFrame theme colors. No-op in GTK3.
bool NativeThemeGtk2::GetChromeStyleColor(const char* style_property,
SkColor* ret_color) const {
#if GTK_MAJOR_VERSION == 2
GdkColor* style_color = nullptr;
gtk_widget_style_get(GetWindow(), style_property, &style_color, nullptr);
if (style_color) {
*ret_color = GdkColorToSkColor(*style_color);
gdk_color_free(style_color);
return true;
}
#endif

return false;
}

GtkWidget* NativeThemeGtk2::GetWindow() const {
static GtkWidget* fake_window = NULL;

Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/ui/libgtk2ui/native_theme_gtk2.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class NativeThemeGtk2 : public ui::NativeThemeBase {
const gfx::Rect& rect,
const MenuListExtraParams& menu_list) const override;

// Gets a ChromeGtkFrame theme color; returns true on success. Always returns
// false in GTK3.
bool GetChromeStyleColor(const char* style_property,
SkColor* ret_color) const;

// Returns various widgets for theming use.
GtkWidget* GetWindow() const;
GtkWidget* GetEntry() const;
Expand Down

0 comments on commit 88eb158

Please sign in to comment.