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

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

Issue 2854773002: Gtk3: Fix black patches on GtkFileChooser dialogs (Closed)
Patch Set: . Created 3 years, 7 months 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
« no previous file with comments | « chrome/browser/ui/libgtkui/native_theme_gtk3.h ('k') | ui/base/glib/scoped_gobject.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_gtk3.h" 5 #include "chrome/browser/ui/libgtkui/native_theme_gtk3.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/gtk_util.h" 11 #include "chrome/browser/ui/libgtkui/gtk_util.h"
12 #include "chrome/browser/ui/libgtkui/skia_utils_gtk.h" 12 #include "chrome/browser/ui/libgtkui/skia_utils_gtk.h"
13 #include "ui/gfx/color_palette.h" 13 #include "ui/gfx/color_palette.h"
14 #include "ui/gfx/color_utils.h" 14 #include "ui/gfx/color_utils.h"
15 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/skbitmap_operations.h" 16 #include "ui/gfx/skbitmap_operations.h"
17 #include "ui/gfx/skia_util.h" 17 #include "ui/gfx/skia_util.h"
18 #include "ui/native_theme/native_theme_dark_aura.h" 18 #include "ui/native_theme/native_theme_dark_aura.h"
19 19
20 namespace libgtkui { 20 namespace libgtkui {
21 21
22 namespace { 22 namespace {
23 23
24 enum BackgroundRenderMode { 24 enum BackgroundRenderMode {
25 BG_RENDER_NORMAL, 25 BG_RENDER_NORMAL,
26 BG_RENDER_NONE, 26 BG_RENDER_NONE,
27 BG_RENDER_RECURSIVE, 27 BG_RENDER_RECURSIVE,
28 }; 28 };
29 29
30 std::string GetGtkSettingsStringProperty(GtkSettings* settings,
31 const gchar* prop_name) {
32 GValue layout = G_VALUE_INIT;
33 g_value_init(&layout, G_TYPE_STRING);
34 g_object_get_property(G_OBJECT(settings), prop_name, &layout);
35 DCHECK(G_VALUE_HOLDS_STRING(&layout));
36 std::string prop_value(g_value_get_string(&layout));
37 g_value_unset(&layout);
38 return prop_value;
39 }
40
30 SkBitmap GetWidgetBitmap(const gfx::Size& size, 41 SkBitmap GetWidgetBitmap(const gfx::Size& size,
31 GtkStyleContext* context, 42 GtkStyleContext* context,
32 BackgroundRenderMode bg_mode, 43 BackgroundRenderMode bg_mode,
33 bool render_frame) { 44 bool render_frame) {
34 DCHECK(bg_mode != BG_RENDER_NONE || render_frame); 45 DCHECK(bg_mode != BG_RENDER_NONE || render_frame);
35 SkBitmap bitmap; 46 SkBitmap bitmap;
36 bitmap.allocN32Pixels(size.width(), size.height()); 47 bitmap.allocN32Pixels(size.width(), size.height());
37 bitmap.eraseColor(0); 48 bitmap.eraseColor(0);
38 49
39 CairoSurface surface(bitmap); 50 CairoSurface surface(bitmap);
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 return fallback_theme->GetSystemColor(color_id); 374 return fallback_theme->GetSystemColor(color_id);
364 } 375 }
365 376
366 case ui::NativeTheme::kColorId_NumColors: 377 case ui::NativeTheme::kColorId_NumColors:
367 NOTREACHED(); 378 NOTREACHED();
368 break; 379 break;
369 } 380 }
370 return kInvalidColorIdColor; 381 return kInvalidColorIdColor;
371 } 382 }
372 383
373 void OnThemeChanged(GObject* obj, GParamSpec* param, NativeThemeGtk3* theme) {
374 theme->ResetColorCache();
375 }
376
377 } // namespace 384 } // namespace
378 385
379 // static 386 // static
380 NativeThemeGtk3* NativeThemeGtk3::instance() { 387 NativeThemeGtk3* NativeThemeGtk3::instance() {
381 CR_DEFINE_STATIC_LOCAL(NativeThemeGtk3, s_native_theme, ()); 388 CR_DEFINE_STATIC_LOCAL(NativeThemeGtk3, s_native_theme, ());
382 return &s_native_theme; 389 return &s_native_theme;
383 } 390 }
384 391
385 // Constructors automatically called
386 NativeThemeGtk3::NativeThemeGtk3() { 392 NativeThemeGtk3::NativeThemeGtk3() {
387 // These types are needed by g_type_from_name(), but may not be registered at 393 // These types are needed by g_type_from_name(), but may not be registered at
388 // this point. We need the g_type_class magic to make sure the compiler 394 // this point. We need the g_type_class magic to make sure the compiler
389 // doesn't optimize away this code. 395 // doesn't optimize away this code.
390 g_type_class_unref(g_type_class_ref(gtk_button_get_type())); 396 g_type_class_unref(g_type_class_ref(gtk_button_get_type()));
391 g_type_class_unref(g_type_class_ref(gtk_entry_get_type())); 397 g_type_class_unref(g_type_class_ref(gtk_entry_get_type()));
392 g_type_class_unref(g_type_class_ref(gtk_info_bar_get_type())); 398 g_type_class_unref(g_type_class_ref(gtk_info_bar_get_type()));
393 g_type_class_unref(g_type_class_ref(gtk_label_get_type())); 399 g_type_class_unref(g_type_class_ref(gtk_label_get_type()));
394 g_type_class_unref(g_type_class_ref(gtk_menu_get_type())); 400 g_type_class_unref(g_type_class_ref(gtk_menu_get_type()));
395 g_type_class_unref(g_type_class_ref(gtk_menu_bar_get_type())); 401 g_type_class_unref(g_type_class_ref(gtk_menu_bar_get_type()));
396 g_type_class_unref(g_type_class_ref(gtk_menu_item_get_type())); 402 g_type_class_unref(g_type_class_ref(gtk_menu_item_get_type()));
397 g_type_class_unref(g_type_class_ref(gtk_range_get_type())); 403 g_type_class_unref(g_type_class_ref(gtk_range_get_type()));
398 g_type_class_unref(g_type_class_ref(gtk_scrollbar_get_type())); 404 g_type_class_unref(g_type_class_ref(gtk_scrollbar_get_type()));
399 g_type_class_unref(g_type_class_ref(gtk_scrolled_window_get_type())); 405 g_type_class_unref(g_type_class_ref(gtk_scrolled_window_get_type()));
400 g_type_class_unref(g_type_class_ref(gtk_separator_get_type())); 406 g_type_class_unref(g_type_class_ref(gtk_separator_get_type()));
401 g_type_class_unref(g_type_class_ref(gtk_spinner_get_type())); 407 g_type_class_unref(g_type_class_ref(gtk_spinner_get_type()));
402 g_type_class_unref(g_type_class_ref(gtk_text_view_get_type())); 408 g_type_class_unref(g_type_class_ref(gtk_text_view_get_type()));
403 g_type_class_unref(g_type_class_ref(gtk_tooltip_get_type())); 409 g_type_class_unref(g_type_class_ref(gtk_tooltip_get_type()));
404 g_type_class_unref(g_type_class_ref(gtk_tree_view_get_type())); 410 g_type_class_unref(g_type_class_ref(gtk_tree_view_get_type()));
405 g_type_class_unref(g_type_class_ref(gtk_window_get_type())); 411 g_type_class_unref(g_type_class_ref(gtk_window_get_type()));
406 412
407 g_signal_connect_after(gtk_settings_get_default(), "notify::gtk-theme-name", 413 g_signal_connect_after(gtk_settings_get_default(), "notify::gtk-theme-name",
408 G_CALLBACK(OnThemeChanged), this); 414 G_CALLBACK(OnThemeChangedThunk), this);
415 OnThemeChanged(gtk_settings_get_default(), nullptr);
409 } 416 }
410 417
411 // This doesn't actually get called 418 NativeThemeGtk3::~NativeThemeGtk3() {
412 NativeThemeGtk3::~NativeThemeGtk3() {} 419 NOTREACHED();
420 }
413 421
414 void NativeThemeGtk3::ResetColorCache() { 422 void NativeThemeGtk3::SetThemeCssOverride(ScopedCssProvider provider) {
423 if (theme_css_override_) {
424 gtk_style_context_remove_provider_for_screen(
425 gdk_screen_get_default(),
426 GTK_STYLE_PROVIDER(theme_css_override_.get()));
427 }
428 theme_css_override_ = std::move(provider);
429 if (theme_css_override_) {
430 gtk_style_context_add_provider_for_screen(
431 gdk_screen_get_default(), GTK_STYLE_PROVIDER(theme_css_override_.get()),
432 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
433 }
434 }
435
436 void NativeThemeGtk3::OnThemeChanged(GtkSettings* settings,
437 GtkParamSpec* param) {
438 SetThemeCssOverride(ScopedCssProvider());
415 for (auto& color : color_cache_) 439 for (auto& color : color_cache_)
416 color = base::nullopt; 440 color = base::nullopt;
441
442 // Hack to workaround a bug on GNOME standard themes which would
443 // cause black patches to be rendered on GtkFileChooser dialogs.
444 std::string theme_name =
445 GetGtkSettingsStringProperty(settings, "gtk-theme-name");
446 if (!GtkVersionCheck(3, 14)) {
447 if (theme_name == "Adwaita") {
448 SetThemeCssOverride(GetCssProvider(
449 "GtkFileChooser GtkPaned { background-color: @theme_bg_color; }"));
450 } else if (theme_name == "HighContrast") {
451 SetThemeCssOverride(GetCssProvider(
452 "GtkFileChooser GtkPaned { background-color: @theme_base_color; }"));
453 }
454 }
417 } 455 }
418 456
419 SkColor NativeThemeGtk3::GetSystemColor(ColorId color_id) const { 457 SkColor NativeThemeGtk3::GetSystemColor(ColorId color_id) const {
420 if (color_cache_[color_id]) 458 if (color_cache_[color_id])
421 return color_cache_[color_id].value(); 459 return color_cache_[color_id].value();
422 460
423 SkColor color = SkColorFromColorId(color_id); 461 SkColor color = SkColorFromColorId(color_id);
424 color_cache_[color_id] = color; 462 color_cache_[color_id] = color;
425 return color; 463 return color;
426 } 464 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 638
601 if (frame_top_area.incognito) { 639 if (frame_top_area.incognito) {
602 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( 640 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap(
603 bitmap, kDefaultTintFrameIncognito); 641 bitmap, kDefaultTintFrameIncognito);
604 } 642 }
605 643
606 canvas->drawBitmap(bitmap, rect.x(), rect.y()); 644 canvas->drawBitmap(bitmap, rect.x(), rect.y());
607 } 645 }
608 646
609 } // namespace libgtkui 647 } // namespace libgtkui
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtkui/native_theme_gtk3.h ('k') | ui/base/glib/scoped_gobject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698