| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/libgtkui/native_theme_gtk.h" | |
| 6 | |
| 7 #include <gtk/gtk.h> | |
| 8 | |
| 9 #include "chrome/browser/ui/libgtkui/chrome_gtk_frame.h" | |
| 10 #include "chrome/browser/ui/libgtkui/chrome_gtk_menu_subclasses.h" | |
| 11 #include "chrome/browser/ui/libgtkui/gtk_ui.h" | |
| 12 #include "chrome/browser/ui/libgtkui/gtk_util.h" | |
| 13 #include "chrome/browser/ui/libgtkui/skia_utils_gtk.h" | |
| 14 #include "third_party/skia/include/core/SkColor.h" | |
| 15 #include "ui/gfx/color_palette.h" | |
| 16 #include "ui/gfx/color_utils.h" | |
| 17 #include "ui/gfx/geometry/rect.h" | |
| 18 #include "ui/gfx/geometry/size.h" | |
| 19 #include "ui/gfx/path.h" | |
| 20 #include "ui/gfx/skia_util.h" | |
| 21 #include "ui/native_theme/common_theme.h" | |
| 22 #include "ui/native_theme/native_theme_aura.h" | |
| 23 #include "ui/native_theme/native_theme_dark_aura.h" | |
| 24 | |
| 25 namespace libgtkui { | |
| 26 | |
| 27 namespace { | |
| 28 | |
| 29 // Theme colors returned by GetSystemColor(). | |
| 30 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); | |
| 31 const SkColor kURLTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); | |
| 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 SkColor NormalURLColor(SkColor foreground) { | |
| 38 color_utils::HSL fg_hsl, hue_hsl; | |
| 39 color_utils::SkColorToHSL(foreground, &fg_hsl); | |
| 40 color_utils::SkColorToHSL(kURLTextColor, &hue_hsl); | |
| 41 | |
| 42 // Only allow colors that have a fair amount of saturation in them (color vs | |
| 43 // white). This means that our output color will always be fairly green. | |
| 44 double s = std::max(0.5, fg_hsl.s); | |
| 45 | |
| 46 // Make sure the luminance is at least as bright as the |kURLTextColor| green | |
| 47 // would be if we were to use that. | |
| 48 double l; | |
| 49 if (fg_hsl.l < hue_hsl.l) | |
| 50 l = hue_hsl.l; | |
| 51 else | |
| 52 l = (fg_hsl.l + hue_hsl.l) / 2; | |
| 53 | |
| 54 color_utils::HSL output = {hue_hsl.h, s, l}; | |
| 55 return color_utils::HSLToSkColor(output, 255); | |
| 56 } | |
| 57 | |
| 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 | |
| 60 // |kURLTextColor|, the current text color, and the background color (the | |
| 61 // select highlight). It is more important to contrast with the background | |
| 62 // saturation than to look exactly like the foreground color. | |
| 63 SkColor SelectedURLColor(SkColor foreground, SkColor background) { | |
| 64 color_utils::HSL fg_hsl, bg_hsl, hue_hsl; | |
| 65 color_utils::SkColorToHSL(foreground, &fg_hsl); | |
| 66 color_utils::SkColorToHSL(background, &bg_hsl); | |
| 67 color_utils::SkColorToHSL(kURLTextColor, &hue_hsl); | |
| 68 | |
| 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 | |
| 71 // less than 0.8 so it's not the oversaturated neon-color. | |
| 72 double opposite_s = 1 - bg_hsl.s; | |
| 73 double s = std::max(0.2, std::min(0.8, opposite_s)); | |
| 74 | |
| 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. | |
| 77 double opposite_l = fg_hsl.l; | |
| 78 double l = std::max(0.1, std::min(0.9, opposite_l)); | |
| 79 | |
| 80 color_utils::HSL output = {hue_hsl.h, s, l}; | |
| 81 return color_utils::HSLToSkColor(output, 255); | |
| 82 } | |
| 83 | |
| 84 enum WidgetState { | |
| 85 NORMAL = 0, | |
| 86 ACTIVE = 1, | |
| 87 PRELIGHT = 2, | |
| 88 SELECTED = 3, | |
| 89 INSENSITIVE = 4, | |
| 90 }; | |
| 91 | |
| 92 #if GTK_MAJOR_VERSION == 2 | |
| 93 // Same order as enum WidgetState above | |
| 94 const GtkStateType stateMap[] = { | |
| 95 GTK_STATE_NORMAL, | |
| 96 GTK_STATE_ACTIVE, | |
| 97 GTK_STATE_PRELIGHT, | |
| 98 GTK_STATE_SELECTED, | |
| 99 GTK_STATE_INSENSITIVE, | |
| 100 }; | |
| 101 | |
| 102 SkColor GetFGColor(GtkWidget* widget, WidgetState state) { | |
| 103 return GdkColorToSkColor(gtk_rc_get_style(widget)->fg[stateMap[state]]); | |
| 104 } | |
| 105 SkColor GetBGColor(GtkWidget* widget, WidgetState state) { | |
| 106 return GdkColorToSkColor(gtk_rc_get_style(widget)->bg[stateMap[state]]); | |
| 107 } | |
| 108 | |
| 109 SkColor GetTextColor(GtkWidget* widget, WidgetState state) { | |
| 110 return GdkColorToSkColor(gtk_rc_get_style(widget)->text[stateMap[state]]); | |
| 111 } | |
| 112 SkColor GetTextAAColor(GtkWidget* widget, WidgetState state) { | |
| 113 return GdkColorToSkColor(gtk_rc_get_style(widget)->text_aa[stateMap[state]]); | |
| 114 } | |
| 115 SkColor GetBaseColor(GtkWidget* widget, WidgetState state) { | |
| 116 return GdkColorToSkColor(gtk_rc_get_style(widget)->base[stateMap[state]]); | |
| 117 } | |
| 118 | |
| 119 #else | |
| 120 // Same order as enum WidgetState above | |
| 121 const GtkStateFlags stateMap[] = { | |
| 122 GTK_STATE_FLAG_NORMAL, GTK_STATE_FLAG_ACTIVE, | |
| 123 GTK_STATE_FLAG_PRELIGHT, GTK_STATE_FLAG_SELECTED, | |
| 124 GTK_STATE_FLAG_INSENSITIVE, | |
| 125 }; | |
| 126 | |
| 127 SkColor GetFGColor(GtkWidget* widget, WidgetState state) { | |
| 128 GdkRGBA color; | |
| 129 gtk_style_context_get_color(gtk_widget_get_style_context(widget), | |
| 130 stateMap[state], &color); | |
| 131 return SkColorSetRGB(color.red * 255, color.green * 255, color.blue * 255); | |
| 132 } | |
| 133 SkColor GetBGColor(GtkWidget* widget, WidgetState state) { | |
| 134 GdkRGBA color; | |
| 135 | |
| 136 G_GNUC_BEGIN_IGNORE_DEPRECATIONS | |
| 137 gtk_style_context_get_background_color(gtk_widget_get_style_context(widget), | |
| 138 stateMap[state], &color); | |
| 139 G_GNUC_END_IGNORE_DEPRECATIONS | |
| 140 | |
| 141 // Hack for default color | |
| 142 if (color.alpha == 0.0) | |
| 143 color = {1, 1, 1, 1}; | |
| 144 | |
| 145 return SkColorSetRGB(color.red * 255, color.green * 255, color.blue * 255); | |
| 146 } | |
| 147 | |
| 148 SkColor GetTextColor(GtkWidget* widget, WidgetState state) { | |
| 149 return GetFGColor(widget, state); | |
| 150 } | |
| 151 SkColor GetTextAAColor(GtkWidget* widget, WidgetState state) { | |
| 152 return GetFGColor(widget, state); | |
| 153 } | |
| 154 SkColor GetBaseColor(GtkWidget* widget, WidgetState state) { | |
| 155 return GetBGColor(widget, state); | |
| 156 } | |
| 157 | |
| 158 #endif | |
| 159 | |
| 160 } // namespace | |
| 161 | |
| 162 // static | |
| 163 NativeThemeGtk2* NativeThemeGtk2::instance() { | |
| 164 CR_DEFINE_STATIC_LOCAL(NativeThemeGtk2, s_native_theme, ()); | |
| 165 return &s_native_theme; | |
| 166 } | |
| 167 | |
| 168 // Constructors automatically called | |
| 169 NativeThemeGtk2::NativeThemeGtk2() {} | |
| 170 // This doesn't actually get called | |
| 171 NativeThemeGtk2::~NativeThemeGtk2() {} | |
| 172 | |
| 173 void NativeThemeGtk2::PaintMenuPopupBackground( | |
| 174 SkCanvas* canvas, | |
| 175 const gfx::Size& size, | |
| 176 const MenuBackgroundExtraParams& menu_background) const { | |
| 177 if (menu_background.corner_radius > 0) { | |
| 178 SkPaint paint; | |
| 179 paint.setStyle(SkPaint::kFill_Style); | |
| 180 paint.setFlags(SkPaint::kAntiAlias_Flag); | |
| 181 paint.setColor(GetSystemColor(kColorId_MenuBackgroundColor)); | |
| 182 | |
| 183 gfx::Path path; | |
| 184 SkRect rect = SkRect::MakeWH(SkIntToScalar(size.width()), | |
| 185 SkIntToScalar(size.height())); | |
| 186 SkScalar radius = SkIntToScalar(menu_background.corner_radius); | |
| 187 SkScalar radii[8] = {radius, radius, radius, radius, | |
| 188 radius, radius, radius, radius}; | |
| 189 path.addRoundRect(rect, radii); | |
| 190 | |
| 191 canvas->drawPath(path, paint); | |
| 192 } else { | |
| 193 canvas->drawColor(GetSystemColor(kColorId_MenuBackgroundColor), | |
| 194 SkBlendMode::kSrc); | |
| 195 } | |
| 196 } | |
| 197 | |
| 198 void NativeThemeGtk2::PaintMenuItemBackground( | |
| 199 SkCanvas* canvas, | |
| 200 State state, | |
| 201 const gfx::Rect& rect, | |
| 202 const MenuItemExtraParams& menu_item) const { | |
| 203 SkColor color; | |
| 204 SkPaint paint; | |
| 205 switch (state) { | |
| 206 case NativeTheme::kNormal: | |
| 207 case NativeTheme::kDisabled: | |
| 208 color = GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor); | |
| 209 paint.setColor(color); | |
| 210 break; | |
| 211 case NativeTheme::kHovered: | |
| 212 color = | |
| 213 GetSystemColor(NativeTheme::kColorId_FocusedMenuItemBackgroundColor); | |
| 214 paint.setColor(color); | |
| 215 break; | |
| 216 default: | |
| 217 NOTREACHED() << "Invalid state " << state; | |
| 218 break; | |
| 219 } | |
| 220 if (menu_item.corner_radius > 0) { | |
| 221 const SkScalar radius = SkIntToScalar(menu_item.corner_radius); | |
| 222 canvas->drawRoundRect(gfx::RectToSkRect(rect), radius, radius, paint); | |
| 223 return; | |
| 224 } | |
| 225 canvas->drawRect(gfx::RectToSkRect(rect), paint); | |
| 226 } | |
| 227 | |
| 228 SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const { | |
| 229 const SkColor kPositiveTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); | |
| 230 const SkColor kNegativeTextColor = SkColorSetRGB(0xc5, 0x39, 0x29); | |
| 231 | |
| 232 switch (color_id) { | |
| 233 // Windows | |
| 234 case kColorId_WindowBackground: | |
| 235 return GetBGColor(GetWindow(), SELECTED); | |
| 236 | |
| 237 // Dialogs | |
| 238 case kColorId_DialogBackground: | |
| 239 case kColorId_BubbleBackground: | |
| 240 return GetBGColor(GetWindow(), NORMAL); | |
| 241 | |
| 242 // FocusableBorder | |
| 243 case kColorId_FocusedBorderColor: | |
| 244 return GetBGColor(GetEntry(), SELECTED); | |
| 245 case kColorId_UnfocusedBorderColor: | |
| 246 return GetTextAAColor(GetEntry(), NORMAL); | |
| 247 | |
| 248 // MenuItem | |
| 249 case kColorId_SelectedMenuItemForegroundColor: | |
| 250 return GetTextColor(GetMenuItem(), SELECTED); | |
| 251 case kColorId_FocusedMenuItemBackgroundColor: | |
| 252 return GetBGColor(GetMenuItem(), SELECTED); | |
| 253 | |
| 254 case kColorId_EnabledMenuItemForegroundColor: | |
| 255 return GetTextColor(GetMenuItem(), NORMAL); | |
| 256 case kColorId_DisabledMenuItemForegroundColor: | |
| 257 return GetTextColor(GetMenuItem(), INSENSITIVE); | |
| 258 case kColorId_FocusedMenuButtonBorderColor: | |
| 259 return GetBGColor(GetEntry(), NORMAL); | |
| 260 case kColorId_HoverMenuButtonBorderColor: | |
| 261 return GetTextAAColor(GetEntry(), PRELIGHT); | |
| 262 case kColorId_MenuBorderColor: | |
| 263 case kColorId_EnabledMenuButtonBorderColor: | |
| 264 case kColorId_MenuSeparatorColor: { | |
| 265 return GetTextColor(GetMenuItem(), INSENSITIVE); | |
| 266 } | |
| 267 case kColorId_MenuBackgroundColor: | |
| 268 return GetBGColor(GetMenu(), NORMAL); | |
| 269 | |
| 270 // Label | |
| 271 case kColorId_LabelEnabledColor: | |
| 272 return GetTextColor(GetEntry(), NORMAL); | |
| 273 case kColorId_LabelDisabledColor: | |
| 274 return GetTextColor(GetLabel(), INSENSITIVE); | |
| 275 case kColorId_LabelTextSelectionColor: | |
| 276 return GetTextColor(GetLabel(), SELECTED); | |
| 277 case kColorId_LabelTextSelectionBackgroundFocused: | |
| 278 return GetBaseColor(GetLabel(), SELECTED); | |
| 279 | |
| 280 // Link | |
| 281 case kColorId_LinkDisabled: | |
| 282 return SkColorSetA(GetSystemColor(kColorId_LinkEnabled), 0xBB); | |
| 283 case kColorId_LinkEnabled: { | |
| 284 SkColor link_color = SK_ColorTRANSPARENT; | |
| 285 GetChromeStyleColor("link-color", &link_color); | |
| 286 if (link_color != SK_ColorTRANSPARENT) | |
| 287 return link_color; | |
| 288 // Default color comes from gtklinkbutton.c. | |
| 289 return SkColorSetRGB(0x00, 0x00, 0xEE); | |
| 290 } | |
| 291 case kColorId_LinkPressed: | |
| 292 return SK_ColorRED; | |
| 293 | |
| 294 // Button | |
| 295 case kColorId_ButtonEnabledColor: | |
| 296 return GetTextColor(GetButton(), NORMAL); | |
| 297 case kColorId_BlueButtonEnabledColor: | |
| 298 return GetTextColor(GetBlueButton(), NORMAL); | |
| 299 case kColorId_ButtonDisabledColor: | |
| 300 return GetTextColor(GetButton(), INSENSITIVE); | |
| 301 case kColorId_BlueButtonDisabledColor: | |
| 302 return GetTextColor(GetBlueButton(), INSENSITIVE); | |
| 303 case kColorId_ButtonHoverColor: | |
| 304 return GetTextColor(GetButton(), PRELIGHT); | |
| 305 case kColorId_BlueButtonHoverColor: | |
| 306 return GetTextColor(GetBlueButton(), PRELIGHT); | |
| 307 case kColorId_BlueButtonPressedColor: | |
| 308 return GetTextColor(GetBlueButton(), ACTIVE); | |
| 309 case kColorId_BlueButtonShadowColor: | |
| 310 return SK_ColorTRANSPARENT; | |
| 311 case kColorId_ProminentButtonColor: | |
| 312 return GetSystemColor(kColorId_LinkEnabled); | |
| 313 case kColorId_TextOnProminentButtonColor: | |
| 314 return GetTextColor(GetLabel(), SELECTED); | |
| 315 case kColorId_ButtonPressedShade: | |
| 316 return SK_ColorTRANSPARENT; | |
| 317 | |
| 318 // Textfield | |
| 319 case kColorId_TextfieldDefaultColor: | |
| 320 return GetTextColor(GetEntry(), NORMAL); | |
| 321 case kColorId_TextfieldDefaultBackground: | |
| 322 return GetBaseColor(GetEntry(), NORMAL); | |
| 323 | |
| 324 #if GTK_MAJOR_VERSION == 2 | |
| 325 case kColorId_TextfieldReadOnlyColor: | |
| 326 return GetTextColor(GetEntry(), ACTIVE); | |
| 327 case kColorId_TextfieldReadOnlyBackground: | |
| 328 return GetBaseColor(GetEntry(), ACTIVE); | |
| 329 case kColorId_TextfieldSelectionColor: | |
| 330 return GetTextColor(GetEntry(), SELECTED); | |
| 331 case kColorId_TextfieldSelectionBackgroundFocused: | |
| 332 return GetBaseColor(GetEntry(), SELECTED); | |
| 333 #else | |
| 334 case kColorId_TextfieldReadOnlyColor: | |
| 335 return GetTextColor(GetEntry(), SELECTED); | |
| 336 case kColorId_TextfieldReadOnlyBackground: | |
| 337 return GetBaseColor(GetEntry(), SELECTED); | |
| 338 case kColorId_TextfieldSelectionColor: | |
| 339 return GetTextColor(GetLabel(), SELECTED); | |
| 340 case kColorId_TextfieldSelectionBackgroundFocused: | |
| 341 return GetBaseColor(GetLabel(), SELECTED); | |
| 342 #endif | |
| 343 | |
| 344 // Tooltips | |
| 345 case kColorId_TooltipBackground: | |
| 346 return GetBGColor(GetTooltip(), NORMAL); | |
| 347 case kColorId_TooltipText: | |
| 348 return GetFGColor(GetTooltip(), NORMAL); | |
| 349 | |
| 350 // Trees and Tables (implemented on GTK using the same class) | |
| 351 case kColorId_TableBackground: | |
| 352 case kColorId_TreeBackground: | |
| 353 return GetBGColor(GetTree(), NORMAL); | |
| 354 case kColorId_TableText: | |
| 355 case kColorId_TreeText: | |
| 356 return GetTextColor(GetTree(), NORMAL); | |
| 357 case kColorId_TableSelectedText: | |
| 358 case kColorId_TableSelectedTextUnfocused: | |
| 359 case kColorId_TreeSelectedText: | |
| 360 case kColorId_TreeSelectedTextUnfocused: | |
| 361 return GetTextColor(GetTree(), SELECTED); | |
| 362 case kColorId_TableSelectionBackgroundFocused: | |
| 363 case kColorId_TableSelectionBackgroundUnfocused: | |
| 364 case kColorId_TreeSelectionBackgroundFocused: | |
| 365 case kColorId_TreeSelectionBackgroundUnfocused: | |
| 366 return GetBGColor(GetTree(), SELECTED); | |
| 367 case kColorId_TreeArrow: | |
| 368 return GetFGColor(GetTree(), NORMAL); | |
| 369 case kColorId_TableGroupingIndicatorColor: | |
| 370 return GetTextAAColor(GetTree(), NORMAL); | |
| 371 | |
| 372 // Results Table | |
| 373 case kColorId_ResultsTableNormalBackground: | |
| 374 return GetSystemColor(kColorId_TextfieldDefaultBackground); | |
| 375 case kColorId_ResultsTableHoveredBackground: | |
| 376 return color_utils::AlphaBlend( | |
| 377 GetSystemColor(kColorId_TextfieldDefaultBackground), | |
| 378 GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused), 0x80); | |
| 379 case kColorId_ResultsTableSelectedBackground: | |
| 380 return GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused); | |
| 381 case kColorId_ResultsTableNormalText: | |
| 382 case kColorId_ResultsTableHoveredText: | |
| 383 return GetSystemColor(kColorId_TextfieldDefaultColor); | |
| 384 case kColorId_ResultsTableSelectedText: | |
| 385 return GetSystemColor(kColorId_TextfieldSelectionColor); | |
| 386 case kColorId_ResultsTableNormalDimmedText: | |
| 387 case kColorId_ResultsTableHoveredDimmedText: | |
| 388 return color_utils::AlphaBlend( | |
| 389 GetSystemColor(kColorId_TextfieldDefaultColor), | |
| 390 GetSystemColor(kColorId_TextfieldDefaultBackground), 0x80); | |
| 391 case kColorId_ResultsTableSelectedDimmedText: | |
| 392 return color_utils::AlphaBlend( | |
| 393 GetSystemColor(kColorId_TextfieldSelectionColor), | |
| 394 GetSystemColor(kColorId_TextfieldDefaultBackground), 0x80); | |
| 395 case kColorId_ResultsTableNormalUrl: | |
| 396 case kColorId_ResultsTableHoveredUrl: | |
| 397 return NormalURLColor(GetSystemColor(kColorId_TextfieldDefaultColor)); | |
| 398 | |
| 399 case kColorId_ResultsTableSelectedUrl: | |
| 400 return SelectedURLColor( | |
| 401 GetSystemColor(kColorId_TextfieldSelectionColor), | |
| 402 GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused)); | |
| 403 | |
| 404 case kColorId_ResultsTablePositiveText: { | |
| 405 return color_utils::GetReadableColor(kPositiveTextColor, | |
| 406 GetBaseColor(GetEntry(), NORMAL)); | |
| 407 } | |
| 408 case kColorId_ResultsTablePositiveHoveredText: { | |
| 409 return color_utils::GetReadableColor(kPositiveTextColor, | |
| 410 GetBaseColor(GetEntry(), PRELIGHT)); | |
| 411 } | |
| 412 case kColorId_ResultsTablePositiveSelectedText: { | |
| 413 return color_utils::GetReadableColor(kPositiveTextColor, | |
| 414 GetBaseColor(GetEntry(), SELECTED)); | |
| 415 } | |
| 416 case kColorId_ResultsTableNegativeText: { | |
| 417 return color_utils::GetReadableColor(kNegativeTextColor, | |
| 418 GetBaseColor(GetEntry(), NORMAL)); | |
| 419 } | |
| 420 case kColorId_ResultsTableNegativeHoveredText: { | |
| 421 return color_utils::GetReadableColor(kNegativeTextColor, | |
| 422 GetBaseColor(GetEntry(), PRELIGHT)); | |
| 423 } | |
| 424 case kColorId_ResultsTableNegativeSelectedText: { | |
| 425 return color_utils::GetReadableColor(kNegativeTextColor, | |
| 426 GetBaseColor(GetEntry(), SELECTED)); | |
| 427 } | |
| 428 | |
| 429 // Throbber | |
| 430 case kColorId_ThrobberSpinningColor: | |
| 431 case kColorId_ThrobberLightColor: | |
| 432 return GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused); | |
| 433 | |
| 434 case kColorId_ThrobberWaitingColor: | |
| 435 return color_utils::AlphaBlend( | |
| 436 GetSystemColor(kColorId_TextfieldSelectionBackgroundFocused), | |
| 437 GetBGColor(GetWindow(), NORMAL), 0x80); | |
| 438 | |
| 439 // Alert icons | |
| 440 // Just fall back to the same colors as Aura. | |
| 441 case kColorId_AlertSeverityLow: | |
| 442 case kColorId_AlertSeverityMedium: | |
| 443 case kColorId_AlertSeverityHigh: { | |
| 444 ui::NativeTheme* fallback_theme = | |
| 445 color_utils::IsDark(GetTextColor(GetEntry(), NORMAL)) | |
| 446 ? ui::NativeTheme::GetInstanceForNativeUi() | |
| 447 : ui::NativeThemeDarkAura::instance(); | |
| 448 return fallback_theme->GetSystemColor(color_id); | |
| 449 } | |
| 450 | |
| 451 case kColorId_NumColors: | |
| 452 NOTREACHED(); | |
| 453 break; | |
| 454 } | |
| 455 | |
| 456 return kInvalidColorIdColor; | |
| 457 } | |
| 458 | |
| 459 // Get ChromeGtkFrame theme colors. No-op in GTK3. | |
| 460 bool NativeThemeGtk2::GetChromeStyleColor(const char* style_property, | |
| 461 SkColor* ret_color) const { | |
| 462 #if GTK_MAJOR_VERSION == 2 | |
| 463 GdkColor* style_color = nullptr; | |
| 464 gtk_widget_style_get(GetWindow(), style_property, &style_color, nullptr); | |
| 465 if (style_color) { | |
| 466 *ret_color = GdkColorToSkColor(*style_color); | |
| 467 gdk_color_free(style_color); | |
| 468 return true; | |
| 469 } | |
| 470 #endif | |
| 471 | |
| 472 return false; | |
| 473 } | |
| 474 | |
| 475 GtkWidget* NativeThemeGtk2::GetWindow() const { | |
| 476 static GtkWidget* fake_window = NULL; | |
| 477 | |
| 478 if (!fake_window) { | |
| 479 fake_window = chrome_gtk_frame_new(); | |
| 480 gtk_widget_realize(fake_window); | |
| 481 } | |
| 482 | |
| 483 return fake_window; | |
| 484 } | |
| 485 | |
| 486 GtkWidget* NativeThemeGtk2::GetEntry() const { | |
| 487 static GtkWidget* fake_entry = NULL; | |
| 488 | |
| 489 if (!fake_entry) { | |
| 490 fake_entry = gtk_entry_new(); | |
| 491 | |
| 492 // The fake entry needs to be in the window so it can be realized so we can | |
| 493 // use the computed parts of the style. | |
| 494 gtk_container_add(GTK_CONTAINER(GetWindow()), fake_entry); | |
| 495 gtk_widget_realize(fake_entry); | |
| 496 } | |
| 497 | |
| 498 return fake_entry; | |
| 499 } | |
| 500 | |
| 501 GtkWidget* NativeThemeGtk2::GetLabel() const { | |
| 502 static GtkWidget* fake_label = NULL; | |
| 503 | |
| 504 if (!fake_label) | |
| 505 fake_label = gtk_label_new(""); | |
| 506 | |
| 507 return fake_label; | |
| 508 } | |
| 509 | |
| 510 GtkWidget* NativeThemeGtk2::GetButton() const { | |
| 511 static GtkWidget* fake_button = NULL; | |
| 512 | |
| 513 if (!fake_button) | |
| 514 fake_button = gtk_button_new(); | |
| 515 | |
| 516 return fake_button; | |
| 517 } | |
| 518 | |
| 519 GtkWidget* NativeThemeGtk2::GetBlueButton() const { | |
| 520 static GtkWidget* fake_bluebutton = NULL; | |
| 521 | |
| 522 if (!fake_bluebutton) { | |
| 523 fake_bluebutton = gtk_button_new(); | |
| 524 TurnButtonBlue(fake_bluebutton); | |
| 525 } | |
| 526 | |
| 527 return fake_bluebutton; | |
| 528 } | |
| 529 | |
| 530 GtkWidget* NativeThemeGtk2::GetTree() const { | |
| 531 static GtkWidget* fake_tree = NULL; | |
| 532 | |
| 533 if (!fake_tree) | |
| 534 fake_tree = gtk_tree_view_new(); | |
| 535 | |
| 536 return fake_tree; | |
| 537 } | |
| 538 | |
| 539 GtkWidget* NativeThemeGtk2::GetTooltip() const { | |
| 540 static GtkWidget* fake_tooltip = NULL; | |
| 541 | |
| 542 if (!fake_tooltip) { | |
| 543 fake_tooltip = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 544 gtk_widget_set_name(fake_tooltip, "gtk-tooltip"); | |
| 545 gtk_widget_realize(fake_tooltip); | |
| 546 } | |
| 547 | |
| 548 return fake_tooltip; | |
| 549 } | |
| 550 | |
| 551 GtkWidget* NativeThemeGtk2::GetMenu() const { | |
| 552 static GtkWidget* fake_menu = NULL; | |
| 553 | |
| 554 if (!fake_menu) | |
| 555 fake_menu = gtk_custom_menu_new(); | |
| 556 | |
| 557 return fake_menu; | |
| 558 } | |
| 559 | |
| 560 GtkWidget* NativeThemeGtk2::GetMenuItem() const { | |
| 561 static GtkWidget* fake_menu_item = NULL; | |
| 562 | |
| 563 if (!fake_menu_item) { | |
| 564 fake_menu_item = gtk_custom_menu_item_new(); | |
| 565 gtk_menu_shell_append(GTK_MENU_SHELL(GetMenu()), fake_menu_item); | |
| 566 } | |
| 567 | |
| 568 return fake_menu_item; | |
| 569 } | |
| 570 | |
| 571 } // namespace libgtkui | |
| OLD | NEW |