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

Side by Side Diff: chrome/browser/ui/libgtkui/native_theme_gtk.cc

Issue 2453243002: Gtk3 UI: Rename files in libgtkui containing gtk2 in their name (Closed)
Patch Set: Fix git cl format mistake Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
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/libgtkui/native_theme_gtk2.h" 5 #include "chrome/browser/ui/libgtkui/native_theme_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "chrome/browser/ui/libgtkui/chrome_gtk_frame.h" 9 #include "chrome/browser/ui/libgtkui/chrome_gtk_frame.h"
10 #include "chrome/browser/ui/libgtkui/chrome_gtk_menu_subclasses.h" 10 #include "chrome/browser/ui/libgtkui/chrome_gtk_menu_subclasses.h"
11 #include "chrome/browser/ui/libgtkui/gtk2_ui.h" 11 #include "chrome/browser/ui/libgtkui/gtk_ui.h"
12 #include "chrome/browser/ui/libgtkui/gtk2_util.h" 12 #include "chrome/browser/ui/libgtkui/gtk_util.h"
13 #include "chrome/browser/ui/libgtkui/skia_utils_gtk2.h" 13 #include "chrome/browser/ui/libgtkui/skia_utils_gtk.h"
14 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/gfx/color_palette.h" 15 #include "ui/gfx/color_palette.h"
16 #include "ui/gfx/color_utils.h" 16 #include "ui/gfx/color_utils.h"
17 #include "ui/gfx/geometry/rect.h" 17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/size.h" 18 #include "ui/gfx/geometry/size.h"
19 #include "ui/gfx/path.h" 19 #include "ui/gfx/path.h"
20 #include "ui/gfx/skia_util.h" 20 #include "ui/gfx/skia_util.h"
21 #include "ui/native_theme/common_theme.h" 21 #include "ui/native_theme/common_theme.h"
22 #include "ui/native_theme/native_theme_aura.h" 22 #include "ui/native_theme/native_theme_aura.h"
23 #include "ui/native_theme/native_theme_dark_aura.h" 23 #include "ui/native_theme/native_theme_dark_aura.h"
(...skipping 20 matching lines...) Expand all
44 double s = std::max(0.5, fg_hsl.s); 44 double s = std::max(0.5, fg_hsl.s);
45 45
46 // Make sure the luminance is at least as bright as the |kURLTextColor| green 46 // Make sure the luminance is at least as bright as the |kURLTextColor| green
47 // would be if we were to use that. 47 // would be if we were to use that.
48 double l; 48 double l;
49 if (fg_hsl.l < hue_hsl.l) 49 if (fg_hsl.l < hue_hsl.l)
50 l = hue_hsl.l; 50 l = hue_hsl.l;
51 else 51 else
52 l = (fg_hsl.l + hue_hsl.l) / 2; 52 l = (fg_hsl.l + hue_hsl.l) / 2;
53 53
54 color_utils::HSL output = { hue_hsl.h, s, l }; 54 color_utils::HSL output = {hue_hsl.h, s, l};
55 return color_utils::HSLToSkColor(output, 255); 55 return color_utils::HSLToSkColor(output, 255);
56 } 56 }
57 57
58 // Generates the selected URL color, a green color used on URL text in the 58 // Generates the selected URL color, a green color used on URL text in the
59 // currently highlighted entry in the autocomplete popup. It's a mix of 59 // currently highlighted entry in the autocomplete popup. It's a mix of
60 // |kURLTextColor|, the current text color, and the background color (the 60 // |kURLTextColor|, the current text color, and the background color (the
61 // select highlight). It is more important to contrast with the background 61 // select highlight). It is more important to contrast with the background
62 // saturation than to look exactly like the foreground color. 62 // saturation than to look exactly like the foreground color.
63 SkColor SelectedURLColor(SkColor foreground, SkColor background) { 63 SkColor SelectedURLColor(SkColor foreground, SkColor background) {
64 color_utils::HSL fg_hsl, bg_hsl, hue_hsl; 64 color_utils::HSL fg_hsl, bg_hsl, hue_hsl;
65 color_utils::SkColorToHSL(foreground, &fg_hsl); 65 color_utils::SkColorToHSL(foreground, &fg_hsl);
66 color_utils::SkColorToHSL(background, &bg_hsl); 66 color_utils::SkColorToHSL(background, &bg_hsl);
67 color_utils::SkColorToHSL(kURLTextColor, &hue_hsl); 67 color_utils::SkColorToHSL(kURLTextColor, &hue_hsl);
68 68
69 // The saturation of the text should be opposite of the background, clamped 69 // The saturation of the text should be opposite of the background, clamped
70 // to 0.2-0.8. We make sure it's greater than 0.2 so there's some color, but 70 // to 0.2-0.8. We make sure it's greater than 0.2 so there's some color, but
71 // less than 0.8 so it's not the oversaturated neon-color. 71 // less than 0.8 so it's not the oversaturated neon-color.
72 double opposite_s = 1 - bg_hsl.s; 72 double opposite_s = 1 - bg_hsl.s;
73 double s = std::max(0.2, std::min(0.8, opposite_s)); 73 double s = std::max(0.2, std::min(0.8, opposite_s));
74 74
75 // The luminance should match the luminance of the foreground text. Again, 75 // The luminance should match the luminance of the foreground text. Again,
76 // we clamp so as to have at some amount of color (green) in the text. 76 // we clamp so as to have at some amount of color (green) in the text.
77 double opposite_l = fg_hsl.l; 77 double opposite_l = fg_hsl.l;
78 double l = std::max(0.1, std::min(0.9, opposite_l)); 78 double l = std::max(0.1, std::min(0.9, opposite_l));
79 79
80 color_utils::HSL output = { hue_hsl.h, s, l }; 80 color_utils::HSL output = {hue_hsl.h, s, l};
81 return color_utils::HSLToSkColor(output, 255); 81 return color_utils::HSLToSkColor(output, 255);
82 } 82 }
83 83
84 enum WidgetState { 84 enum WidgetState {
85 NORMAL = 0, 85 NORMAL = 0,
86 ACTIVE = 1, 86 ACTIVE = 1,
87 PRELIGHT = 2, 87 PRELIGHT = 2,
88 SELECTED = 3, 88 SELECTED = 3,
89 INSENSITIVE = 4, 89 INSENSITIVE = 4,
90 }; 90 };
(...skipping 21 matching lines...) Expand all
112 SkColor GetTextAAColor(GtkWidget* widget, WidgetState state) { 112 SkColor GetTextAAColor(GtkWidget* widget, WidgetState state) {
113 return GdkColorToSkColor(gtk_rc_get_style(widget)->text_aa[stateMap[state]]); 113 return GdkColorToSkColor(gtk_rc_get_style(widget)->text_aa[stateMap[state]]);
114 } 114 }
115 SkColor GetBaseColor(GtkWidget* widget, WidgetState state) { 115 SkColor GetBaseColor(GtkWidget* widget, WidgetState state) {
116 return GdkColorToSkColor(gtk_rc_get_style(widget)->base[stateMap[state]]); 116 return GdkColorToSkColor(gtk_rc_get_style(widget)->base[stateMap[state]]);
117 } 117 }
118 118
119 #else 119 #else
120 // Same order as enum WidgetState above 120 // Same order as enum WidgetState above
121 const GtkStateFlags stateMap[] = { 121 const GtkStateFlags stateMap[] = {
122 GTK_STATE_FLAG_NORMAL, 122 GTK_STATE_FLAG_NORMAL, GTK_STATE_FLAG_ACTIVE,
123 GTK_STATE_FLAG_ACTIVE, 123 GTK_STATE_FLAG_PRELIGHT, GTK_STATE_FLAG_SELECTED,
124 GTK_STATE_FLAG_PRELIGHT, 124 GTK_STATE_FLAG_INSENSITIVE,
125 GTK_STATE_FLAG_SELECTED,
126 GTK_STATE_FLAG_INSENSITIVE,
127 }; 125 };
128 126
129 SkColor GetFGColor(GtkWidget* widget, WidgetState state) { 127 SkColor GetFGColor(GtkWidget* widget, WidgetState state) {
130 GdkRGBA color; 128 GdkRGBA color;
131 gtk_style_context_get_color( 129 gtk_style_context_get_color(gtk_widget_get_style_context(widget),
132 gtk_widget_get_style_context(widget), stateMap[state], &color); 130 stateMap[state], &color);
133 return SkColorSetRGB(color.red * 255, color.green * 255, color.blue * 255); 131 return SkColorSetRGB(color.red * 255, color.green * 255, color.blue * 255);
134 } 132 }
135 SkColor GetBGColor(GtkWidget* widget, WidgetState state) { 133 SkColor GetBGColor(GtkWidget* widget, WidgetState state) {
136 GdkRGBA color; 134 GdkRGBA color;
137 135
138 G_GNUC_BEGIN_IGNORE_DEPRECATIONS 136 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
139 gtk_style_context_get_background_color( 137 gtk_style_context_get_background_color(gtk_widget_get_style_context(widget),
140 gtk_widget_get_style_context(widget), stateMap[state], &color); 138 stateMap[state], &color);
141 G_GNUC_END_IGNORE_DEPRECATIONS 139 G_GNUC_END_IGNORE_DEPRECATIONS
142 140
143 // Hack for default color 141 // Hack for default color
144 if (color.alpha == 0.0) 142 if (color.alpha == 0.0)
145 color = {1, 1, 1, 1}; 143 color = {1, 1, 1, 1};
146 144
147 return SkColorSetRGB(color.red * 255, color.green * 255, color.blue * 255); 145 return SkColorSetRGB(color.red * 255, color.green * 255, color.blue * 255);
148 } 146 }
149 147
150 SkColor GetTextColor(GtkWidget* widget, WidgetState state) { 148 SkColor GetTextColor(GtkWidget* widget, WidgetState state) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 const MenuItemExtraParams& menu_item) const { 202 const MenuItemExtraParams& menu_item) const {
205 SkColor color; 203 SkColor color;
206 SkPaint paint; 204 SkPaint paint;
207 switch (state) { 205 switch (state) {
208 case NativeTheme::kNormal: 206 case NativeTheme::kNormal:
209 case NativeTheme::kDisabled: 207 case NativeTheme::kDisabled:
210 color = GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor); 208 color = GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor);
211 paint.setColor(color); 209 paint.setColor(color);
212 break; 210 break;
213 case NativeTheme::kHovered: 211 case NativeTheme::kHovered:
214 color = GetSystemColor( 212 color =
215 NativeTheme::kColorId_FocusedMenuItemBackgroundColor); 213 GetSystemColor(NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
216 paint.setColor(color); 214 paint.setColor(color);
217 break; 215 break;
218 default: 216 default:
219 NOTREACHED() << "Invalid state " << state; 217 NOTREACHED() << "Invalid state " << state;
220 break; 218 break;
221 } 219 }
222 if (menu_item.corner_radius > 0) { 220 if (menu_item.corner_radius > 0) {
223 const SkScalar radius = SkIntToScalar(menu_item.corner_radius); 221 const SkScalar radius = SkIntToScalar(menu_item.corner_radius);
224 canvas->drawRoundRect(gfx::RectToSkRect(rect), radius, radius, paint); 222 canvas->drawRoundRect(gfx::RectToSkRect(rect), radius, radius, paint);
225 return; 223 return;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 case kColorId_TextfieldReadOnlyColor: 330 case kColorId_TextfieldReadOnlyColor:
333 return GetTextColor(GetEntry(), SELECTED); 331 return GetTextColor(GetEntry(), SELECTED);
334 case kColorId_TextfieldReadOnlyBackground: 332 case kColorId_TextfieldReadOnlyBackground:
335 return GetBaseColor(GetEntry(), SELECTED); 333 return GetBaseColor(GetEntry(), SELECTED);
336 case kColorId_TextfieldSelectionColor: 334 case kColorId_TextfieldSelectionColor:
337 return GetTextColor(GetLabel(), SELECTED); 335 return GetTextColor(GetLabel(), SELECTED);
338 case kColorId_TextfieldSelectionBackgroundFocused: 336 case kColorId_TextfieldSelectionBackgroundFocused:
339 return GetBaseColor(GetLabel(), SELECTED); 337 return GetBaseColor(GetLabel(), SELECTED);
340 #endif 338 #endif
341 339
342
343 // Tooltips 340 // Tooltips
344 case kColorId_TooltipBackground: 341 case kColorId_TooltipBackground:
345 return GetBGColor(GetTooltip(), NORMAL); 342 return GetBGColor(GetTooltip(), NORMAL);
346 case kColorId_TooltipText: 343 case kColorId_TooltipText:
347 return GetFGColor(GetTooltip(), NORMAL); 344 return GetFGColor(GetTooltip(), NORMAL);
348 345
349 // Trees and Tables (implemented on GTK using the same class) 346 // Trees and Tables (implemented on GTK using the same class)
350 case kColorId_TableBackground: 347 case kColorId_TableBackground:
351 case kColorId_TreeBackground: 348 case kColorId_TreeBackground:
352 return GetBGColor(GetTree(), NORMAL); 349 return GetBGColor(GetTree(), NORMAL);
353 case kColorId_TableText: 350 case kColorId_TableText:
354 case kColorId_TreeText: 351 case kColorId_TreeText:
355 return GetTextColor(GetTree(), NORMAL); 352 return GetTextColor(GetTree(), NORMAL);
356 case kColorId_TableSelectedText: 353 case kColorId_TableSelectedText:
357 case kColorId_TableSelectedTextUnfocused: 354 case kColorId_TableSelectedTextUnfocused:
358 case kColorId_TreeSelectedText: 355 case kColorId_TreeSelectedText:
359 case kColorId_TreeSelectedTextUnfocused: 356 case kColorId_TreeSelectedTextUnfocused:
360 return GetTextColor(GetTree(), SELECTED); 357 return GetTextColor(GetTree(), SELECTED);
361 case kColorId_TableSelectionBackgroundFocused: 358 case kColorId_TableSelectionBackgroundFocused:
362 case kColorId_TableSelectionBackgroundUnfocused: 359 case kColorId_TableSelectionBackgroundUnfocused:
363 case kColorId_TreeSelectionBackgroundFocused: 360 case kColorId_TreeSelectionBackgroundFocused:
364 case kColorId_TreeSelectionBackgroundUnfocused: 361 case kColorId_TreeSelectionBackgroundUnfocused:
365 return GetBGColor(GetTree(), SELECTED); 362 return GetBGColor(GetTree(), SELECTED);
366 case kColorId_TreeArrow: 363 case kColorId_TreeArrow:
367 return GetFGColor(GetTree(), NORMAL); 364 return GetFGColor(GetTree(), NORMAL);
368 case kColorId_TableGroupingIndicatorColor: 365 case kColorId_TableGroupingIndicatorColor:
369 return GetTextAAColor(GetTree(), NORMAL); 366 return GetTextAAColor(GetTree(), NORMAL);
370 367
371 // Results Table 368 // Results Table
372 case kColorId_ResultsTableNormalBackground: 369 case kColorId_ResultsTableNormalBackground:
373 return GetSystemColor(kColorId_TextfieldDefaultBackground); 370 return GetSystemColor(kColorId_TextfieldDefaultBackground);
374 case kColorId_ResultsTableHoveredBackground: 371 case kColorId_ResultsTableHoveredBackground:
375 return color_utils::AlphaBlend( 372 return color_utils::AlphaBlend(
376 GetSystemColor(kColorId_TextfieldDefaultBackground), 373 GetSystemColor(kColorId_TextfieldDefaultBackground),
377 GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused), 374 GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused), 0x80);
378 0x80);
379 case kColorId_ResultsTableSelectedBackground: 375 case kColorId_ResultsTableSelectedBackground:
380 return GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused); 376 return GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused);
381 case kColorId_ResultsTableNormalText: 377 case kColorId_ResultsTableNormalText:
382 case kColorId_ResultsTableHoveredText: 378 case kColorId_ResultsTableHoveredText:
383 return GetSystemColor(kColorId_TextfieldDefaultColor); 379 return GetSystemColor(kColorId_TextfieldDefaultColor);
384 case kColorId_ResultsTableSelectedText: 380 case kColorId_ResultsTableSelectedText:
385 return GetSystemColor(kColorId_TextfieldSelectionColor); 381 return GetSystemColor(kColorId_TextfieldSelectionColor);
386 case kColorId_ResultsTableNormalDimmedText: 382 case kColorId_ResultsTableNormalDimmedText:
387 case kColorId_ResultsTableHoveredDimmedText: 383 case kColorId_ResultsTableHoveredDimmedText:
388 return color_utils::AlphaBlend( 384 return color_utils::AlphaBlend(
389 GetSystemColor(kColorId_TextfieldDefaultColor), 385 GetSystemColor(kColorId_TextfieldDefaultColor),
390 GetSystemColor(kColorId_TextfieldDefaultBackground), 386 GetSystemColor(kColorId_TextfieldDefaultBackground), 0x80);
391 0x80);
392 case kColorId_ResultsTableSelectedDimmedText: 387 case kColorId_ResultsTableSelectedDimmedText:
393 return color_utils::AlphaBlend( 388 return color_utils::AlphaBlend(
394 GetSystemColor(kColorId_TextfieldSelectionColor), 389 GetSystemColor(kColorId_TextfieldSelectionColor),
395 GetSystemColor(kColorId_TextfieldDefaultBackground), 390 GetSystemColor(kColorId_TextfieldDefaultBackground), 0x80);
396 0x80);
397 case kColorId_ResultsTableNormalUrl: 391 case kColorId_ResultsTableNormalUrl:
398 case kColorId_ResultsTableHoveredUrl: 392 case kColorId_ResultsTableHoveredUrl:
399 return NormalURLColor(GetSystemColor(kColorId_TextfieldDefaultColor)); 393 return NormalURLColor(GetSystemColor(kColorId_TextfieldDefaultColor));
400 394
401 case kColorId_ResultsTableSelectedUrl: 395 case kColorId_ResultsTableSelectedUrl:
402 return SelectedURLColor( 396 return SelectedURLColor(
403 GetSystemColor(kColorId_TextfieldSelectionColor), 397 GetSystemColor(kColorId_TextfieldSelectionColor),
404 GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused)); 398 GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused));
405 399
406 case kColorId_ResultsTablePositiveText: { 400 case kColorId_ResultsTablePositiveText: {
(...skipping 22 matching lines...) Expand all
429 } 423 }
430 424
431 // Throbber 425 // Throbber
432 case kColorId_ThrobberSpinningColor: 426 case kColorId_ThrobberSpinningColor:
433 case kColorId_ThrobberLightColor: 427 case kColorId_ThrobberLightColor:
434 return GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused); 428 return GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused);
435 429
436 case kColorId_ThrobberWaitingColor: 430 case kColorId_ThrobberWaitingColor:
437 return color_utils::AlphaBlend( 431 return color_utils::AlphaBlend(
438 GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused), 432 GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused),
439 GetBGColor(GetWindow(), NORMAL), 433 GetBGColor(GetWindow(), NORMAL), 0x80);
440 0x80);
441 434
442 // Alert icons 435 // Alert icons
443 // Just fall back to the same colors as Aura. 436 // Just fall back to the same colors as Aura.
444 case kColorId_AlertSeverityLow: 437 case kColorId_AlertSeverityLow:
445 case kColorId_AlertSeverityMedium: 438 case kColorId_AlertSeverityMedium:
446 case kColorId_AlertSeverityHigh: { 439 case kColorId_AlertSeverityHigh: {
447 ui::NativeTheme* fallback_theme = 440 ui::NativeTheme* fallback_theme =
448 color_utils::IsDark(GetTextColor(GetEntry(), NORMAL)) 441 color_utils::IsDark(GetTextColor(GetEntry(), NORMAL))
449 ? ui::NativeThemeAura::instance() 442 ? ui::NativeThemeAura::instance()
450 : ui::NativeThemeDarkAura::instance(); 443 : ui::NativeThemeDarkAura::instance();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 558
566 if (!fake_menu_item) { 559 if (!fake_menu_item) {
567 fake_menu_item = gtk_custom_menu_item_new(); 560 fake_menu_item = gtk_custom_menu_item_new();
568 gtk_menu_shell_append(GTK_MENU_SHELL(GetMenu()), fake_menu_item); 561 gtk_menu_shell_append(GTK_MENU_SHELL(GetMenu()), fake_menu_item);
569 } 562 }
570 563
571 return fake_menu_item; 564 return fake_menu_item;
572 } 565 }
573 566
574 } // namespace libgtkui 567 } // namespace libgtkui
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtkui/native_theme_gtk.h ('k') | chrome/browser/ui/libgtkui/native_theme_gtk2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698