| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/libgtk2ui/native_theme_gtk2.h" | 5 #include "chrome/browser/ui/libgtk2ui/native_theme_gtk2.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "chrome/browser/ui/libgtk2ui/chrome_gtk_menu_subclasses.h" | 9 #include "chrome/browser/ui/libgtk2ui/chrome_gtk_menu_subclasses.h" |
| 10 #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" | 10 #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" |
| 11 #include "ui/gfx/color_utils.h" | 11 #include "ui/gfx/color_utils.h" |
| 12 #include "ui/gfx/path.h" | 12 #include "ui/gfx/path.h" |
| 13 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
| 14 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
| 15 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
| 16 #include "ui/native_theme/common_theme.h" | 16 #include "ui/native_theme/common_theme.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Theme colors returned by GetSystemColor(). | 20 // Theme colors returned by GetSystemColor(). |
| 21 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); | 21 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); |
| 22 | 22 |
| 23 const GdkColor kURLTextColor = GDK_COLOR_RGB(0x00, 0x88, 0x00); |
| 24 |
| 25 GdkColor GdkAlphaBlend(GdkColor foreground, |
| 26 GdkColor background, |
| 27 SkAlpha alpha) { |
| 28 return libgtk2ui::SkColorToGdkColor( |
| 29 color_utils::AlphaBlend(libgtk2ui::GdkColorToSkColor(foreground), |
| 30 libgtk2ui::GdkColorToSkColor(background), alpha)); |
| 31 } |
| 32 |
| 33 // Generates the normal URL color, a green color used in unhighlighted URL |
| 34 // text. It is a mix of |kURLTextColor| and the current text color. Unlike the |
| 35 // selected text color, it is more important to match the qualities of the |
| 36 // foreground typeface color instead of taking the background into account. |
| 37 GdkColor NormalURLColor(GdkColor foreground) { |
| 38 color_utils::HSL fg_hsl; |
| 39 color_utils::SkColorToHSL(libgtk2ui::GdkColorToSkColor(foreground), &fg_hsl); |
| 40 |
| 41 color_utils::HSL hue_hsl; |
| 42 color_utils::SkColorToHSL(libgtk2ui::GdkColorToSkColor(kURLTextColor), |
| 43 &hue_hsl); |
| 44 |
| 45 // Only allow colors that have a fair amount of saturation in them (color vs |
| 46 // white). This means that our output color will always be fairly green. |
| 47 double s = std::max(0.5, fg_hsl.s); |
| 48 |
| 49 // Make sure the luminance is at least as bright as the |kURLTextColor| green |
| 50 // would be if we were to use that. |
| 51 double l; |
| 52 if (fg_hsl.l < hue_hsl.l) |
| 53 l = hue_hsl.l; |
| 54 else |
| 55 l = (fg_hsl.l + hue_hsl.l) / 2; |
| 56 |
| 57 color_utils::HSL output = { hue_hsl.h, s, l }; |
| 58 return libgtk2ui::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255)); |
| 59 } |
| 60 |
| 61 // Generates the selected URL color, a green color used on URL text in the |
| 62 // currently highlighted entry in the autocomplete popup. It's a mix of |
| 63 // |kURLTextColor|, the current text color, and the background color (the |
| 64 // select highlight). It is more important to contrast with the background |
| 65 // saturation than to look exactly like the foreground color. |
| 66 GdkColor SelectedURLColor(GdkColor foreground, GdkColor background) { |
| 67 color_utils::HSL fg_hsl; |
| 68 color_utils::SkColorToHSL(libgtk2ui::GdkColorToSkColor(foreground), |
| 69 &fg_hsl); |
| 70 |
| 71 color_utils::HSL bg_hsl; |
| 72 color_utils::SkColorToHSL(libgtk2ui::GdkColorToSkColor(background), |
| 73 &bg_hsl); |
| 74 |
| 75 color_utils::HSL hue_hsl; |
| 76 color_utils::SkColorToHSL(libgtk2ui::GdkColorToSkColor(kURLTextColor), |
| 77 &hue_hsl); |
| 78 |
| 79 // The saturation of the text should be opposite of the background, clamped |
| 80 // to 0.2-0.8. We make sure it's greater than 0.2 so there's some color, but |
| 81 // less than 0.8 so it's not the oversaturated neon-color. |
| 82 double opposite_s = 1 - bg_hsl.s; |
| 83 double s = std::max(0.2, std::min(0.8, opposite_s)); |
| 84 |
| 85 // The luminance should match the luminance of the foreground text. Again, |
| 86 // we clamp so as to have at some amount of color (green) in the text. |
| 87 double opposite_l = fg_hsl.l; |
| 88 double l = std::max(0.1, std::min(0.9, opposite_l)); |
| 89 |
| 90 color_utils::HSL output = { hue_hsl.h, s, l }; |
| 91 return libgtk2ui::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255)); |
| 92 } |
| 93 |
| 23 } // namespace | 94 } // namespace |
| 24 | 95 |
| 25 | 96 |
| 26 namespace libgtk2ui { | 97 namespace libgtk2ui { |
| 27 | 98 |
| 28 // static | 99 // static |
| 29 NativeThemeGtk2* NativeThemeGtk2::instance() { | 100 NativeThemeGtk2* NativeThemeGtk2::instance() { |
| 30 CR_DEFINE_STATIC_LOCAL(NativeThemeGtk2, s_native_theme, ()); | 101 CR_DEFINE_STATIC_LOCAL(NativeThemeGtk2, s_native_theme, ()); |
| 31 return &s_native_theme; | 102 return &s_native_theme; |
| 32 } | 103 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 return GetEntryStyle()->base[GTK_STATE_NORMAL]; | 238 return GetEntryStyle()->base[GTK_STATE_NORMAL]; |
| 168 case kColorId_TextfieldReadOnlyColor: | 239 case kColorId_TextfieldReadOnlyColor: |
| 169 return GetEntryStyle()->text[GTK_STATE_INSENSITIVE]; | 240 return GetEntryStyle()->text[GTK_STATE_INSENSITIVE]; |
| 170 case kColorId_TextfieldReadOnlyBackground: | 241 case kColorId_TextfieldReadOnlyBackground: |
| 171 return GetEntryStyle()->base[GTK_STATE_INSENSITIVE]; | 242 return GetEntryStyle()->base[GTK_STATE_INSENSITIVE]; |
| 172 case kColorId_TextfieldSelectionColor: | 243 case kColorId_TextfieldSelectionColor: |
| 173 return GetEntryStyle()->text[GTK_STATE_SELECTED]; | 244 return GetEntryStyle()->text[GTK_STATE_SELECTED]; |
| 174 case kColorId_TextfieldSelectionBackgroundFocused: | 245 case kColorId_TextfieldSelectionBackgroundFocused: |
| 175 return GetEntryStyle()->base[GTK_STATE_SELECTED]; | 246 return GetEntryStyle()->base[GTK_STATE_SELECTED]; |
| 176 | 247 |
| 177 // Trees and Tables (implemented on GTK using the same class) | 248 // Trees and Tables (implemented on GTK using the same class) |
| 178 case kColorId_TableBackground: | 249 case kColorId_TableBackground: |
| 179 case kColorId_TreeBackground: | 250 case kColorId_TreeBackground: |
| 180 return GetTreeStyle()->bg[GTK_STATE_NORMAL]; | 251 return GetTreeStyle()->bg[GTK_STATE_NORMAL]; |
| 181 case kColorId_TableText: | 252 case kColorId_TableText: |
| 182 case kColorId_TreeText: | 253 case kColorId_TreeText: |
| 183 return GetTreeStyle()->text[GTK_STATE_NORMAL]; | 254 return GetTreeStyle()->text[GTK_STATE_NORMAL]; |
| 184 case kColorId_TableSelectedText: | 255 case kColorId_TableSelectedText: |
| 185 case kColorId_TableSelectedTextUnfocused: | 256 case kColorId_TableSelectedTextUnfocused: |
| 186 case kColorId_TreeSelectedText: | 257 case kColorId_TreeSelectedText: |
| 187 case kColorId_TreeSelectedTextUnfocused: | 258 case kColorId_TreeSelectedTextUnfocused: |
| 188 return GetTreeStyle()->text[GTK_STATE_SELECTED]; | 259 return GetTreeStyle()->text[GTK_STATE_SELECTED]; |
| 189 case kColorId_TableSelectionBackgroundFocused: | 260 case kColorId_TableSelectionBackgroundFocused: |
| 190 case kColorId_TableSelectionBackgroundUnfocused: | 261 case kColorId_TableSelectionBackgroundUnfocused: |
| 191 case kColorId_TreeSelectionBackgroundFocused: | 262 case kColorId_TreeSelectionBackgroundFocused: |
| 192 case kColorId_TreeSelectionBackgroundUnfocused: | 263 case kColorId_TreeSelectionBackgroundUnfocused: |
| 193 return GetTreeStyle()->bg[GTK_STATE_SELECTED]; | 264 return GetTreeStyle()->bg[GTK_STATE_SELECTED]; |
| 194 case kColorId_TreeArrow: | 265 case kColorId_TreeArrow: |
| 195 return GetTreeStyle()->fg[GTK_STATE_NORMAL]; | 266 return GetTreeStyle()->fg[GTK_STATE_NORMAL]; |
| 196 case kColorId_TableGroupingIndicatorColor: | 267 case kColorId_TableGroupingIndicatorColor: |
| 197 return GetTreeStyle()->text_aa[GTK_STATE_NORMAL]; | 268 return GetTreeStyle()->text_aa[GTK_STATE_NORMAL]; |
| 198 | 269 |
| 270 // Results Table |
| 271 case kColorId_ResultsTableNormalBackground: |
| 272 return GetEntryStyle()->base[GTK_STATE_NORMAL]; |
| 273 case kColorId_ResultsTableHoveredBackground: { |
| 274 GtkStyle* entry_style = GetEntryStyle(); |
| 275 return GdkAlphaBlend( |
| 276 entry_style->base[GTK_STATE_NORMAL], |
| 277 entry_style->base[GTK_STATE_SELECTED], 0x80); |
| 278 } |
| 279 case kColorId_ResultsTableSelectedBackground: |
| 280 return GetEntryStyle()->base[GTK_STATE_SELECTED]; |
| 281 case kColorId_ResultsTableNormalText: |
| 282 case kColorId_ResultsTableHoveredText: |
| 283 return GetEntryStyle()->text[GTK_STATE_NORMAL]; |
| 284 case kColorId_ResultsTableSelectedText: |
| 285 return GetEntryStyle()->text[GTK_STATE_SELECTED]; |
| 286 case kColorId_ResultsTableNormalDimmedText: |
| 287 case kColorId_ResultsTableHoveredDimmedText: { |
| 288 GtkStyle* entry_style = GetEntryStyle(); |
| 289 return GdkAlphaBlend( |
| 290 entry_style->text[GTK_STATE_NORMAL], |
| 291 entry_style->base[GTK_STATE_NORMAL], 0x80); |
| 292 } |
| 293 case kColorId_ResultsTableSelectedDimmedText: { |
| 294 GtkStyle* entry_style = GetEntryStyle(); |
| 295 return GdkAlphaBlend( |
| 296 entry_style->text[GTK_STATE_SELECTED], |
| 297 entry_style->base[GTK_STATE_NORMAL], 0x80); |
| 298 } |
| 299 case kColorId_ResultsTableNormalUrl: |
| 300 case kColorId_ResultsTableHoveredUrl: { |
| 301 return NormalURLColor(GetEntryStyle()->text[GTK_STATE_NORMAL]); |
| 302 } |
| 303 case kColorId_ResultsTableSelectedUrl: { |
| 304 GtkStyle* entry_style = GetEntryStyle(); |
| 305 return SelectedURLColor(entry_style->text[GTK_STATE_SELECTED], |
| 306 entry_style->base[GTK_STATE_SELECTED]); |
| 307 } |
| 308 case kColorId_ResultsTableNormalDivider: { |
| 309 GtkStyle* win_style = GetWindowStyle(); |
| 310 return GdkAlphaBlend(win_style->text[GTK_STATE_NORMAL], |
| 311 win_style->bg[GTK_STATE_NORMAL], 0x34); |
| 312 } |
| 313 case kColorId_ResultsTableHoveredDivider: { |
| 314 GtkStyle* win_style = GetWindowStyle(); |
| 315 return GdkAlphaBlend(win_style->text[GTK_STATE_PRELIGHT], |
| 316 win_style->bg[GTK_STATE_PRELIGHT], 0x34); |
| 317 } |
| 318 case kColorId_ResultsTableSelectedDivider: { |
| 319 GtkStyle* win_style = GetWindowStyle(); |
| 320 return GdkAlphaBlend(win_style->text[GTK_STATE_SELECTED], |
| 321 win_style->bg[GTK_STATE_SELECTED], 0x34); |
| 322 } |
| 199 default: | 323 default: |
| 200 // Fall through | 324 // Fall through |
| 201 break; | 325 break; |
| 202 } | 326 } |
| 203 | 327 |
| 204 return SkColorToGdkColor(kInvalidColorIdColor); | 328 return SkColorToGdkColor(kInvalidColorIdColor); |
| 205 } | 329 } |
| 206 | 330 |
| 207 GtkWidget* NativeThemeGtk2::GetRealizedWindow() const { | 331 GtkWidget* NativeThemeGtk2::GetRealizedWindow() const { |
| 208 if (!fake_window_) { | 332 if (!fake_window_) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 fake_menu_.Own(gtk_custom_menu_new()); | 386 fake_menu_.Own(gtk_custom_menu_new()); |
| 263 | 387 |
| 264 fake_menu_item_ = gtk_custom_menu_item_new(); | 388 fake_menu_item_ = gtk_custom_menu_item_new(); |
| 265 gtk_menu_shell_append(GTK_MENU_SHELL(fake_menu_.get()), fake_menu_item_); | 389 gtk_menu_shell_append(GTK_MENU_SHELL(fake_menu_.get()), fake_menu_item_); |
| 266 } | 390 } |
| 267 | 391 |
| 268 return gtk_rc_get_style(fake_menu_item_); | 392 return gtk_rc_get_style(fake_menu_item_); |
| 269 } | 393 } |
| 270 | 394 |
| 271 } // namespace libgtk2ui | 395 } // namespace libgtk2ui |
| OLD | NEW |