Index: chrome/browser/ui/libgtkui/native_theme_gtk3.cc |
diff --git a/chrome/browser/ui/libgtkui/native_theme_gtk.cc b/chrome/browser/ui/libgtkui/native_theme_gtk3.cc |
similarity index 62% |
rename from chrome/browser/ui/libgtkui/native_theme_gtk.cc |
rename to chrome/browser/ui/libgtkui/native_theme_gtk3.cc |
index 67af85048fbeb260523c9099aaeca31ab8239168..b7528c9256f2615b18813375aafcb7cef22e9360 100644 |
--- a/chrome/browser/ui/libgtkui/native_theme_gtk.cc |
+++ b/chrome/browser/ui/libgtkui/native_theme_gtk3.cc |
@@ -1,86 +1,22 @@ |
-// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/libgtkui/native_theme_gtk.h" |
+#include "chrome/browser/ui/libgtkui/native_theme_gtk3.h" |
#include <gtk/gtk.h> |
#include "chrome/browser/ui/libgtkui/chrome_gtk_frame.h" |
#include "chrome/browser/ui/libgtkui/chrome_gtk_menu_subclasses.h" |
-#include "chrome/browser/ui/libgtkui/gtk_ui.h" |
#include "chrome/browser/ui/libgtkui/gtk_util.h" |
#include "chrome/browser/ui/libgtkui/skia_utils_gtk.h" |
-#include "third_party/skia/include/core/SkColor.h" |
-#include "ui/gfx/color_palette.h" |
#include "ui/gfx/color_utils.h" |
-#include "ui/gfx/geometry/rect.h" |
-#include "ui/gfx/geometry/size.h" |
-#include "ui/gfx/path.h" |
-#include "ui/gfx/skia_util.h" |
-#include "ui/native_theme/common_theme.h" |
-#include "ui/native_theme/native_theme_aura.h" |
#include "ui/native_theme/native_theme_dark_aura.h" |
namespace libgtkui { |
namespace { |
-// Theme colors returned by GetSystemColor(). |
-const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); |
-const SkColor kURLTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); |
- |
-// Generates the normal URL color, a green color used in unhighlighted URL |
-// text. It is a mix of |kURLTextColor| and the current text color. Unlike the |
-// selected text color, it is more important to match the qualities of the |
-// foreground typeface color instead of taking the background into account. |
-SkColor NormalURLColor(SkColor foreground) { |
- color_utils::HSL fg_hsl, hue_hsl; |
- color_utils::SkColorToHSL(foreground, &fg_hsl); |
- color_utils::SkColorToHSL(kURLTextColor, &hue_hsl); |
- |
- // Only allow colors that have a fair amount of saturation in them (color vs |
- // white). This means that our output color will always be fairly green. |
- double s = std::max(0.5, fg_hsl.s); |
- |
- // Make sure the luminance is at least as bright as the |kURLTextColor| green |
- // would be if we were to use that. |
- double l; |
- if (fg_hsl.l < hue_hsl.l) |
- l = hue_hsl.l; |
- else |
- l = (fg_hsl.l + hue_hsl.l) / 2; |
- |
- color_utils::HSL output = {hue_hsl.h, s, l}; |
- return color_utils::HSLToSkColor(output, 255); |
-} |
- |
-// Generates the selected URL color, a green color used on URL text in the |
-// currently highlighted entry in the autocomplete popup. It's a mix of |
-// |kURLTextColor|, the current text color, and the background color (the |
-// select highlight). It is more important to contrast with the background |
-// saturation than to look exactly like the foreground color. |
-SkColor SelectedURLColor(SkColor foreground, SkColor background) { |
- color_utils::HSL fg_hsl, bg_hsl, hue_hsl; |
- color_utils::SkColorToHSL(foreground, &fg_hsl); |
- color_utils::SkColorToHSL(background, &bg_hsl); |
- color_utils::SkColorToHSL(kURLTextColor, &hue_hsl); |
- |
- // The saturation of the text should be opposite of the background, clamped |
- // to 0.2-0.8. We make sure it's greater than 0.2 so there's some color, but |
- // less than 0.8 so it's not the oversaturated neon-color. |
- double opposite_s = 1 - bg_hsl.s; |
- double s = std::max(0.2, std::min(0.8, opposite_s)); |
- |
- // The luminance should match the luminance of the foreground text. Again, |
- // we clamp so as to have at some amount of color (green) in the text. |
- double opposite_l = fg_hsl.l; |
- double l = std::max(0.1, std::min(0.9, opposite_l)); |
- |
- color_utils::HSL output = {hue_hsl.h, s, l}; |
- return color_utils::HSLToSkColor(output, 255); |
-} |
- |
enum WidgetState { |
NORMAL = 0, |
ACTIVE = 1, |
@@ -89,34 +25,6 @@ enum WidgetState { |
INSENSITIVE = 4, |
}; |
-#if GTK_MAJOR_VERSION == 2 |
-// Same order as enum WidgetState above |
-const GtkStateType stateMap[] = { |
- GTK_STATE_NORMAL, |
- GTK_STATE_ACTIVE, |
- GTK_STATE_PRELIGHT, |
- GTK_STATE_SELECTED, |
- GTK_STATE_INSENSITIVE, |
-}; |
- |
-SkColor GetFGColor(GtkWidget* widget, WidgetState state) { |
- return GdkColorToSkColor(gtk_rc_get_style(widget)->fg[stateMap[state]]); |
-} |
-SkColor GetBGColor(GtkWidget* widget, WidgetState state) { |
- return GdkColorToSkColor(gtk_rc_get_style(widget)->bg[stateMap[state]]); |
-} |
- |
-SkColor GetTextColor(GtkWidget* widget, WidgetState state) { |
- return GdkColorToSkColor(gtk_rc_get_style(widget)->text[stateMap[state]]); |
-} |
-SkColor GetTextAAColor(GtkWidget* widget, WidgetState state) { |
- return GdkColorToSkColor(gtk_rc_get_style(widget)->text_aa[stateMap[state]]); |
-} |
-SkColor GetBaseColor(GtkWidget* widget, WidgetState state) { |
- return GdkColorToSkColor(gtk_rc_get_style(widget)->base[stateMap[state]]); |
-} |
- |
-#else |
// Same order as enum WidgetState above |
const GtkStateFlags stateMap[] = { |
GTK_STATE_FLAG_NORMAL, GTK_STATE_FLAG_ACTIVE, |
@@ -155,77 +63,20 @@ SkColor GetBaseColor(GtkWidget* widget, WidgetState state) { |
return GetBGColor(widget, state); |
} |
-#endif |
- |
} // namespace |
// static |
-NativeThemeGtk2* NativeThemeGtk2::instance() { |
- CR_DEFINE_STATIC_LOCAL(NativeThemeGtk2, s_native_theme, ()); |
+NativeThemeGtk3* NativeThemeGtk3::instance() { |
+ CR_DEFINE_STATIC_LOCAL(NativeThemeGtk3, s_native_theme, ()); |
return &s_native_theme; |
} |
// Constructors automatically called |
-NativeThemeGtk2::NativeThemeGtk2() {} |
+NativeThemeGtk3::NativeThemeGtk3() {} |
// This doesn't actually get called |
-NativeThemeGtk2::~NativeThemeGtk2() {} |
+NativeThemeGtk3::~NativeThemeGtk3() {} |
-void NativeThemeGtk2::PaintMenuPopupBackground( |
- SkCanvas* canvas, |
- const gfx::Size& size, |
- const MenuBackgroundExtraParams& menu_background) const { |
- if (menu_background.corner_radius > 0) { |
- SkPaint paint; |
- paint.setStyle(SkPaint::kFill_Style); |
- paint.setFlags(SkPaint::kAntiAlias_Flag); |
- paint.setColor(GetSystemColor(kColorId_MenuBackgroundColor)); |
- |
- gfx::Path path; |
- SkRect rect = SkRect::MakeWH(SkIntToScalar(size.width()), |
- SkIntToScalar(size.height())); |
- SkScalar radius = SkIntToScalar(menu_background.corner_radius); |
- SkScalar radii[8] = {radius, radius, radius, radius, |
- radius, radius, radius, radius}; |
- path.addRoundRect(rect, radii); |
- |
- canvas->drawPath(path, paint); |
- } else { |
- canvas->drawColor(GetSystemColor(kColorId_MenuBackgroundColor), |
- SkBlendMode::kSrc); |
- } |
-} |
- |
-void NativeThemeGtk2::PaintMenuItemBackground( |
- SkCanvas* canvas, |
- State state, |
- const gfx::Rect& rect, |
- const MenuItemExtraParams& menu_item) const { |
- SkColor color; |
- SkPaint paint; |
- switch (state) { |
- case NativeTheme::kNormal: |
- case NativeTheme::kDisabled: |
- color = GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor); |
- paint.setColor(color); |
- break; |
- case NativeTheme::kHovered: |
- color = |
- GetSystemColor(NativeTheme::kColorId_FocusedMenuItemBackgroundColor); |
- paint.setColor(color); |
- break; |
- default: |
- NOTREACHED() << "Invalid state " << state; |
- break; |
- } |
- if (menu_item.corner_radius > 0) { |
- const SkScalar radius = SkIntToScalar(menu_item.corner_radius); |
- canvas->drawRoundRect(gfx::RectToSkRect(rect), radius, radius, paint); |
- return; |
- } |
- canvas->drawRect(gfx::RectToSkRect(rect), paint); |
-} |
- |
-SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const { |
+SkColor NativeThemeGtk3::GetSystemColor(ColorId color_id) const { |
const SkColor kPositiveTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); |
const SkColor kNegativeTextColor = SkColorSetRGB(0xc5, 0x39, 0x29); |
@@ -282,7 +133,12 @@ SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const { |
return SkColorSetA(GetSystemColor(kColorId_LinkEnabled), 0xBB); |
case kColorId_LinkEnabled: { |
SkColor link_color = SK_ColorTRANSPARENT; |
- GetChromeStyleColor("link-color", &link_color); |
+ GdkColor* style_color = nullptr; |
+ gtk_widget_style_get(GetWindow(), "link-color", &style_color, nullptr); |
+ if (style_color) { |
+ link_color = GdkColorToSkColor(*style_color); |
+ gdk_color_free(style_color); |
+ } |
if (link_color != SK_ColorTRANSPARENT) |
return link_color; |
// Default color comes from gtklinkbutton.c. |
@@ -321,16 +177,6 @@ SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const { |
case kColorId_TextfieldDefaultBackground: |
return GetBaseColor(GetEntry(), NORMAL); |
-#if GTK_MAJOR_VERSION == 2 |
- case kColorId_TextfieldReadOnlyColor: |
- return GetTextColor(GetEntry(), ACTIVE); |
- case kColorId_TextfieldReadOnlyBackground: |
- return GetBaseColor(GetEntry(), ACTIVE); |
- case kColorId_TextfieldSelectionColor: |
- return GetTextColor(GetEntry(), SELECTED); |
- case kColorId_TextfieldSelectionBackgroundFocused: |
- return GetBaseColor(GetEntry(), SELECTED); |
-#else |
case kColorId_TextfieldReadOnlyColor: |
return GetTextColor(GetEntry(), SELECTED); |
case kColorId_TextfieldReadOnlyBackground: |
@@ -339,7 +185,6 @@ SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const { |
return GetTextColor(GetLabel(), SELECTED); |
case kColorId_TextfieldSelectionBackgroundFocused: |
return GetBaseColor(GetLabel(), SELECTED); |
-#endif |
// Tooltips |
case kColorId_TooltipBackground: |
@@ -456,23 +301,7 @@ 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 { |
+GtkWidget* NativeThemeGtk3::GetWindow() const { |
static GtkWidget* fake_window = NULL; |
if (!fake_window) { |
@@ -483,7 +312,7 @@ GtkWidget* NativeThemeGtk2::GetWindow() const { |
return fake_window; |
} |
-GtkWidget* NativeThemeGtk2::GetEntry() const { |
+GtkWidget* NativeThemeGtk3::GetEntry() const { |
static GtkWidget* fake_entry = NULL; |
if (!fake_entry) { |
@@ -498,7 +327,7 @@ GtkWidget* NativeThemeGtk2::GetEntry() const { |
return fake_entry; |
} |
-GtkWidget* NativeThemeGtk2::GetLabel() const { |
+GtkWidget* NativeThemeGtk3::GetLabel() const { |
static GtkWidget* fake_label = NULL; |
if (!fake_label) |
@@ -507,7 +336,7 @@ GtkWidget* NativeThemeGtk2::GetLabel() const { |
return fake_label; |
} |
-GtkWidget* NativeThemeGtk2::GetButton() const { |
+GtkWidget* NativeThemeGtk3::GetButton() const { |
static GtkWidget* fake_button = NULL; |
if (!fake_button) |
@@ -516,7 +345,7 @@ GtkWidget* NativeThemeGtk2::GetButton() const { |
return fake_button; |
} |
-GtkWidget* NativeThemeGtk2::GetBlueButton() const { |
+GtkWidget* NativeThemeGtk3::GetBlueButton() const { |
static GtkWidget* fake_bluebutton = NULL; |
if (!fake_bluebutton) { |
@@ -527,7 +356,7 @@ GtkWidget* NativeThemeGtk2::GetBlueButton() const { |
return fake_bluebutton; |
} |
-GtkWidget* NativeThemeGtk2::GetTree() const { |
+GtkWidget* NativeThemeGtk3::GetTree() const { |
static GtkWidget* fake_tree = NULL; |
if (!fake_tree) |
@@ -536,7 +365,7 @@ GtkWidget* NativeThemeGtk2::GetTree() const { |
return fake_tree; |
} |
-GtkWidget* NativeThemeGtk2::GetTooltip() const { |
+GtkWidget* NativeThemeGtk3::GetTooltip() const { |
static GtkWidget* fake_tooltip = NULL; |
if (!fake_tooltip) { |
@@ -548,7 +377,7 @@ GtkWidget* NativeThemeGtk2::GetTooltip() const { |
return fake_tooltip; |
} |
-GtkWidget* NativeThemeGtk2::GetMenu() const { |
+GtkWidget* NativeThemeGtk3::GetMenu() const { |
static GtkWidget* fake_menu = NULL; |
if (!fake_menu) |
@@ -557,7 +386,7 @@ GtkWidget* NativeThemeGtk2::GetMenu() const { |
return fake_menu; |
} |
-GtkWidget* NativeThemeGtk2::GetMenuItem() const { |
+GtkWidget* NativeThemeGtk3::GetMenuItem() const { |
static GtkWidget* fake_menu_item = NULL; |
if (!fake_menu_item) { |