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

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

Issue 2579683002: LibGtkUi: Partition NativeThemeGtk into NativeThemeGtk2 and NativeThemeGtk3 (Closed)
Patch Set: Fix lsan error Created 4 years 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/gtk_ui.h ('k') | chrome/browser/ui/libgtkui/gtk_util.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/gtk_ui.h" 5 #include "chrome/browser/ui/libgtkui/gtk_ui.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <pango/pango.h> 8 #include <pango/pango.h>
9 #include <X11/Xcursor/Xcursor.h> 9 #include <X11/Xcursor/Xcursor.h>
10 10
11 #include <cmath> 11 #include <cmath>
12 #include <set> 12 #include <set>
13 #include <utility> 13 #include <utility>
14 14
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/debug/leak_annotations.h" 16 #include "base/debug/leak_annotations.h"
17 #include "base/environment.h" 17 #include "base/environment.h"
18 #include "base/i18n/rtl.h" 18 #include "base/i18n/rtl.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "base/nix/mime_util_xdg.h" 21 #include "base/nix/mime_util_xdg.h"
22 #include "base/nix/xdg_util.h" 22 #include "base/nix/xdg_util.h"
23 #include "base/stl_util.h" 23 #include "base/stl_util.h"
24 #include "base/strings/string_split.h" 24 #include "base/strings/string_split.h"
25 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
26 #include "chrome/browser/themes/theme_properties.h" 26 #include "chrome/browser/themes/theme_properties.h"
27 #include "chrome/browser/ui/libgtkui/app_indicator_icon.h" 27 #include "chrome/browser/ui/libgtkui/app_indicator_icon.h"
28 #include "chrome/browser/ui/libgtkui/chrome_gtk_frame.h"
28 #include "chrome/browser/ui/libgtkui/gtk_event_loop.h" 29 #include "chrome/browser/ui/libgtkui/gtk_event_loop.h"
29 #include "chrome/browser/ui/libgtkui/gtk_key_bindings_handler.h" 30 #include "chrome/browser/ui/libgtkui/gtk_key_bindings_handler.h"
30 #include "chrome/browser/ui/libgtkui/gtk_status_icon.h" 31 #include "chrome/browser/ui/libgtkui/gtk_status_icon.h"
31 #include "chrome/browser/ui/libgtkui/gtk_util.h" 32 #include "chrome/browser/ui/libgtkui/gtk_util.h"
32 #include "chrome/browser/ui/libgtkui/native_theme_gtk.h"
33 #include "chrome/browser/ui/libgtkui/print_dialog_gtk.h" 33 #include "chrome/browser/ui/libgtkui/print_dialog_gtk.h"
34 #include "chrome/browser/ui/libgtkui/printing_gtk_util.h" 34 #include "chrome/browser/ui/libgtkui/printing_gtk_util.h"
35 #include "chrome/browser/ui/libgtkui/select_file_dialog_impl.h" 35 #include "chrome/browser/ui/libgtkui/select_file_dialog_impl.h"
36 #include "chrome/browser/ui/libgtkui/skia_utils_gtk.h" 36 #include "chrome/browser/ui/libgtkui/skia_utils_gtk.h"
37 #include "chrome/browser/ui/libgtkui/unity_service.h" 37 #include "chrome/browser/ui/libgtkui/unity_service.h"
38 #include "chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk.h" 38 #include "chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk.h"
39 #include "chrome/grit/theme_resources.h" 39 #include "chrome/grit/theme_resources.h"
40 #include "components/grit/components_scaled_resources.h" 40 #include "components/grit/components_scaled_resources.h"
41 #include "printing/features/features.h" 41 #include "printing/features/features.h"
42 #include "third_party/skia/include/core/SkBitmap.h" 42 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 11 matching lines...) Expand all
54 #include "ui/gfx/skia_util.h" 54 #include "ui/gfx/skia_util.h"
55 #include "ui/gfx/x/x11_types.h" 55 #include "ui/gfx/x/x11_types.h"
56 #include "ui/native_theme/native_theme.h" 56 #include "ui/native_theme/native_theme.h"
57 #include "ui/resources/grit/ui_resources.h" 57 #include "ui/resources/grit/ui_resources.h"
58 #include "ui/views/controls/button/blue_button.h" 58 #include "ui/views/controls/button/blue_button.h"
59 #include "ui/views/controls/button/label_button.h" 59 #include "ui/views/controls/button/label_button.h"
60 #include "ui/views/controls/button/label_button_border.h" 60 #include "ui/views/controls/button/label_button_border.h"
61 #include "ui/views/linux_ui/window_button_order_observer.h" 61 #include "ui/views/linux_ui/window_button_order_observer.h"
62 #include "ui/views/resources/grit/views_resources.h" 62 #include "ui/views/resources/grit/views_resources.h"
63 63
64 #if GTK_MAJOR_VERSION == 2
65 #include "chrome/browser/ui/libgtkui/native_theme_gtk2.h" // nogncheck
66 #elif GTK_MAJOR_VERSION == 3
67 #include "chrome/browser/ui/libgtkui/native_theme_gtk3.h" // nogncheck
68 #endif
69
64 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 70 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
65 #include "printing/printing_context_linux.h" 71 #include "printing/printing_context_linux.h"
66 #endif 72 #endif
67 #if defined(USE_GCONF) 73 #if defined(USE_GCONF)
68 #include "chrome/browser/ui/libgtkui/gconf_listener.h" 74 #include "chrome/browser/ui/libgtkui/gconf_listener.h"
69 #endif 75 #endif
70 76
71 // A minimized port of GtkThemeService into something that can provide colors 77 // A minimized port of GtkThemeService into something that can provide colors
72 // and images for aura. 78 // and images for aura.
73 // 79 //
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 310 }
305 311
306 // Returns a gfx::FontRenderParams corresponding to GTK's configuration. 312 // Returns a gfx::FontRenderParams corresponding to GTK's configuration.
307 gfx::FontRenderParams GetGtkFontRenderParams() { 313 gfx::FontRenderParams GetGtkFontRenderParams() {
308 GtkSettings* gtk_settings = gtk_settings_get_default(); 314 GtkSettings* gtk_settings = gtk_settings_get_default();
309 CHECK(gtk_settings); 315 CHECK(gtk_settings);
310 gint antialias = 0; 316 gint antialias = 0;
311 gint hinting = 0; 317 gint hinting = 0;
312 gchar* hint_style = NULL; 318 gchar* hint_style = NULL;
313 gchar* rgba = NULL; 319 gchar* rgba = NULL;
314 g_object_get(gtk_settings, 320 g_object_get(gtk_settings, "gtk-xft-antialias", &antialias, "gtk-xft-hinting",
315 "gtk-xft-antialias", &antialias, 321 &hinting, "gtk-xft-hintstyle", &hint_style, "gtk-xft-rgba",
316 "gtk-xft-hinting", &hinting, 322 &rgba, NULL);
317 "gtk-xft-hintstyle", &hint_style,
318 "gtk-xft-rgba", &rgba,
319 NULL);
320 323
321 gfx::FontRenderParams params; 324 gfx::FontRenderParams params;
322 params.antialiasing = antialias != 0; 325 params.antialiasing = antialias != 0;
323 326
324 if (hinting == 0 || !hint_style || strcmp(hint_style, "hintnone") == 0) { 327 if (hinting == 0 || !hint_style || strcmp(hint_style, "hintnone") == 0) {
325 params.hinting = gfx::FontRenderParams::HINTING_NONE; 328 params.hinting = gfx::FontRenderParams::HINTING_NONE;
326 } else if (strcmp(hint_style, "hintslight") == 0) { 329 } else if (strcmp(hint_style, "hintslight") == 0) {
327 params.hinting = gfx::FontRenderParams::HINTING_SLIGHT; 330 params.hinting = gfx::FontRenderParams::HINTING_SLIGHT;
328 } else if (strcmp(hint_style, "hintmedium") == 0) { 331 } else if (strcmp(hint_style, "hintmedium") == 0) {
329 params.hinting = gfx::FontRenderParams::HINTING_MEDIUM; 332 params.hinting = gfx::FontRenderParams::HINTING_MEDIUM;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE; 408 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE;
406 default: 409 default:
407 return views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER; 410 return views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER;
408 } 411 }
409 } 412 }
410 413
411 } // namespace 414 } // namespace
412 415
413 Gtk2UI::Gtk2UI() : middle_click_action_(GetDefaultMiddleClickAction()) { 416 Gtk2UI::Gtk2UI() : middle_click_action_(GetDefaultMiddleClickAction()) {
414 GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess()); 417 GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess());
418 #if GTK_MAJOR_VERSION == 2
419 native_theme_ = NativeThemeGtk2::instance();
420 fake_window_ = chrome_gtk_frame_new();
421 gtk_widget_realize(fake_window_); // Is this necessary?
422 #elif GTK_MAJOR_VERSION == 3
423 native_theme_ = NativeThemeGtk3::instance();
424 #else
425 #error "Unsupported GTK version"
426 #endif
415 } 427 }
416 428
417 Gtk2UI::~Gtk2UI() {} 429 Gtk2UI::~Gtk2UI() {
430 #if GTK_MAJOR_VERSION == 2
431 gtk_widget_destroy(fake_window_);
432 #endif
433 }
418 434
419 void OnThemeChanged(GObject* obj, GParamSpec* param, Gtk2UI* gtkui) { 435 void OnThemeChanged(GObject* obj, GParamSpec* param, Gtk2UI* gtkui) {
420 gtkui->ResetStyle(); 436 gtkui->ResetStyle();
421 } 437 }
422 438
423 void Gtk2UI::Initialize() { 439 void Gtk2UI::Initialize() {
424 GtkSettings* settings = gtk_settings_get_default(); 440 GtkSettings* settings = gtk_settings_get_default();
425 g_signal_connect_after(settings, "notify::gtk-theme-name", 441 g_signal_connect_after(settings, "notify::gtk-theme-name",
426 G_CALLBACK(OnThemeChanged), this); 442 G_CALLBACK(OnThemeChanged), this);
427 g_signal_connect_after(settings, "notify::gtk-icon-theme-name", 443 g_signal_connect_after(settings, "notify::gtk-icon-theme-name",
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 static const gint kGtkDefaultCursorBlinkTime = 1200; 531 static const gint kGtkDefaultCursorBlinkTime = 1200;
516 532
517 // Dividing GTK's cursor blink cycle time (in milliseconds) by this value 533 // Dividing GTK's cursor blink cycle time (in milliseconds) by this value
518 // yields an appropriate value for 534 // yields an appropriate value for
519 // content::RendererPreferences::caret_blink_interval. This matches the 535 // content::RendererPreferences::caret_blink_interval. This matches the
520 // logic in the WebKit GTK port. 536 // logic in the WebKit GTK port.
521 static const double kGtkCursorBlinkCycleFactor = 2000.0; 537 static const double kGtkCursorBlinkCycleFactor = 2000.0;
522 538
523 gint cursor_blink_time = kGtkDefaultCursorBlinkTime; 539 gint cursor_blink_time = kGtkDefaultCursorBlinkTime;
524 gboolean cursor_blink = TRUE; 540 gboolean cursor_blink = TRUE;
525 g_object_get(gtk_settings_get_default(), 541 g_object_get(gtk_settings_get_default(), "gtk-cursor-blink-time",
526 "gtk-cursor-blink-time", &cursor_blink_time, 542 &cursor_blink_time, "gtk-cursor-blink", &cursor_blink, NULL);
527 "gtk-cursor-blink", &cursor_blink,
528 NULL);
529 return cursor_blink ? (cursor_blink_time / kGtkCursorBlinkCycleFactor) : 0.0; 543 return cursor_blink ? (cursor_blink_time / kGtkCursorBlinkCycleFactor) : 0.0;
530 } 544 }
531 545
532 ui::NativeTheme* Gtk2UI::GetNativeTheme(aura::Window* window) const { 546 ui::NativeTheme* Gtk2UI::GetNativeTheme(aura::Window* window) const {
533 ui::NativeTheme* native_theme_override = NULL; 547 ui::NativeTheme* native_theme_override = NULL;
534 if (!native_theme_overrider_.is_null()) 548 if (!native_theme_overrider_.is_null())
535 native_theme_override = native_theme_overrider_.Run(window); 549 native_theme_override = native_theme_overrider_.Run(window);
536 550
537 if (native_theme_override) 551 if (native_theme_override)
538 return native_theme_override; 552 return native_theme_override;
539 553
540 return NativeThemeGtk2::instance(); 554 return native_theme_;
541 } 555 }
542 556
543 void Gtk2UI::SetNativeThemeOverride(const NativeThemeGetter& callback) { 557 void Gtk2UI::SetNativeThemeOverride(const NativeThemeGetter& callback) {
544 native_theme_overrider_ = callback; 558 native_theme_overrider_ = callback;
545 } 559 }
546 560
547 bool Gtk2UI::GetDefaultUsesSystemTheme() const { 561 bool Gtk2UI::GetDefaultUsesSystemTheme() const {
548 std::unique_ptr<base::Environment> env(base::Environment::Create()); 562 std::unique_ptr<base::Environment> env(base::Environment::Create());
549 563
550 switch (base::nix::GetDesktopEnvironment(env.get())) { 564 switch (base::nix::GetDesktopEnvironment(env.get())) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 629 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
616 image_skia.MakeThreadSafe(); 630 image_skia.MakeThreadSafe();
617 return gfx::Image(image_skia); 631 return gfx::Image(image_skia);
618 } 632 }
619 return gfx::Image(); 633 return gfx::Image();
620 } 634 }
621 635
622 std::unique_ptr<views::Border> Gtk2UI::CreateNativeBorder( 636 std::unique_ptr<views::Border> Gtk2UI::CreateNativeBorder(
623 views::LabelButton* owning_button, 637 views::LabelButton* owning_button,
624 std::unique_ptr<views::LabelButtonBorder> border) { 638 std::unique_ptr<views::LabelButtonBorder> border) {
625 if (owning_button->GetNativeTheme() != NativeThemeGtk2::instance()) 639 if (owning_button->GetNativeTheme() != native_theme_)
626 return std::move(border); 640 return std::move(border);
627 641
628 std::unique_ptr<views::LabelButtonAssetBorder> gtk_border( 642 std::unique_ptr<views::LabelButtonAssetBorder> gtk_border(
629 new views::LabelButtonAssetBorder(owning_button->style())); 643 new views::LabelButtonAssetBorder(owning_button->style()));
630 644
631 gtk_border->set_insets(border->GetInsets()); 645 gtk_border->set_insets(border->GetInsets());
632 646
633 static struct { 647 static struct {
634 const char* idr; 648 const char* idr;
635 const char* idr_blue; 649 const char* idr_blue;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 key_bindings_handler_.reset(new Gtk2KeyBindingsHandler); 783 key_bindings_handler_.reset(new Gtk2KeyBindingsHandler);
770 784
771 return key_bindings_handler_->MatchEvent(event, commands); 785 return key_bindings_handler_->MatchEvent(event, commands);
772 } 786 }
773 787
774 void Gtk2UI::SetScrollbarColors() { 788 void Gtk2UI::SetScrollbarColors() {
775 thumb_active_color_ = SkColorSetRGB(244, 244, 244); 789 thumb_active_color_ = SkColorSetRGB(244, 244, 244);
776 thumb_inactive_color_ = SkColorSetRGB(234, 234, 234); 790 thumb_inactive_color_ = SkColorSetRGB(234, 234, 234);
777 track_color_ = SkColorSetRGB(211, 211, 211); 791 track_color_ = SkColorSetRGB(211, 211, 211);
778 792
779 NativeThemeGtk2::instance()->GetChromeStyleColor( 793 GetChromeStyleColor("scrollbar-slider-prelight-color", &thumb_active_color_);
780 "scrollbar-slider-prelight-color", &thumb_active_color_); 794 GetChromeStyleColor("scrollbar-slider-normal-color", &thumb_inactive_color_);
781 NativeThemeGtk2::instance()->GetChromeStyleColor( 795 GetChromeStyleColor("scrollbar-trough-color", &track_color_);
782 "scrollbar-slider-normal-color", &thumb_inactive_color_);
783 NativeThemeGtk2::instance()->GetChromeStyleColor("scrollbar-trough-color",
784 &track_color_);
785 } 796 }
786 797
787 void Gtk2UI::LoadGtkValues() { 798 void Gtk2UI::LoadGtkValues() {
788 // TODO(erg): GtkThemeService had a comment here about having to muck with 799 // TODO(erg): GtkThemeService had a comment here about having to muck with
789 // the raw Prefs object to remove prefs::kCurrentThemeImages or else we'd 800 // the raw Prefs object to remove prefs::kCurrentThemeImages or else we'd
790 // regress startup time. Figure out how to do that when we can't access the 801 // regress startup time. Figure out how to do that when we can't access the
791 // prefs system from here. 802 // prefs system from here.
792 803
793 NativeThemeGtk2* theme = NativeThemeGtk2::instance();
794
795 SkColor toolbar_color = 804 SkColor toolbar_color =
796 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); 805 native_theme_->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground);
797 SkColor label_color = 806 SkColor label_color = native_theme_->GetSystemColor(
798 theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor); 807 ui::NativeTheme::kColorId_LabelEnabledColor);
799 808
800 colors_[ThemeProperties::COLOR_CONTROL_BACKGROUND] = toolbar_color; 809 colors_[ThemeProperties::COLOR_CONTROL_BACKGROUND] = toolbar_color;
801 colors_[ThemeProperties::COLOR_TOOLBAR] = toolbar_color; 810 colors_[ThemeProperties::COLOR_TOOLBAR] = toolbar_color;
802 811
803 colors_[ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON] = 812 colors_[ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON] =
804 color_utils::DeriveDefaultIconColor(label_color); 813 color_utils::DeriveDefaultIconColor(label_color);
805 814
806 colors_[ThemeProperties::COLOR_TAB_TEXT] = label_color; 815 colors_[ThemeProperties::COLOR_TAB_TEXT] = label_color;
807 colors_[ThemeProperties::COLOR_BOOKMARK_TEXT] = label_color; 816 colors_[ThemeProperties::COLOR_BOOKMARK_TEXT] = label_color;
808 colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] = 817 colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] =
809 color_utils::BlendTowardOppositeLuma(label_color, 50); 818 color_utils::BlendTowardOppositeLuma(label_color, 50);
810 819
811 UpdateDeviceScaleFactor(); 820 UpdateDeviceScaleFactor();
812 821
813 // Build the various icon tints. 822 // Build the various icon tints.
814 GetNormalButtonTintHSL(&button_tint_); 823 GetNormalButtonTintHSL(&button_tint_);
815 GetNormalEntryForegroundHSL(&entry_tint_); 824 GetNormalEntryForegroundHSL(&entry_tint_);
816 GetSelectedEntryForegroundHSL(&selected_entry_tint_); 825 GetSelectedEntryForegroundHSL(&selected_entry_tint_);
817 826
818 // We pick the text and background colors for the NTP out of the colors for a 827 // We pick the text and background colors for the NTP out of the colors for a
819 // GtkEntry. We do this because GtkEntries background color is never the same 828 // GtkEntry. We do this because GtkEntries background color is never the same
820 // as |toolbar_color|, is usually a white, and when it isn't a white, 829 // as |toolbar_color|, is usually a white, and when it isn't a white,
821 // provides sufficient contrast to |toolbar_color|. Try this out with 830 // provides sufficient contrast to |toolbar_color|. Try this out with
822 // Darklooks, HighContrastInverse or ThinIce. 831 // Darklooks, HighContrastInverse or ThinIce.
823 832
824 SkColor ntp_background = theme->GetSystemColor( 833 SkColor ntp_background = native_theme_->GetSystemColor(
825 ui::NativeTheme::kColorId_TextfieldDefaultBackground); 834 ui::NativeTheme::kColorId_TextfieldDefaultBackground);
826 SkColor ntp_foreground = 835 SkColor ntp_foreground = native_theme_->GetSystemColor(
827 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); 836 ui::NativeTheme::kColorId_TextfieldDefaultColor);
828 837
829 colors_[ThemeProperties::COLOR_NTP_BACKGROUND] = ntp_background; 838 colors_[ThemeProperties::COLOR_NTP_BACKGROUND] = ntp_background;
830 colors_[ThemeProperties::COLOR_NTP_TEXT] = ntp_foreground; 839 colors_[ThemeProperties::COLOR_NTP_TEXT] = ntp_foreground;
831 840
832 // The NTP header is the color that surrounds the current active thumbnail on 841 // The NTP header is the color that surrounds the current active thumbnail on
833 // the NTP, and acts as the border of the "Recent Links" box. It would be 842 // the NTP, and acts as the border of the "Recent Links" box. It would be
834 // awesome if they were separated so we could use GetBorderColor() for the 843 // awesome if they were separated so we could use GetBorderColor() for the
835 // border around the "Recent Links" section, but matching the frame color is 844 // border around the "Recent Links" section, but matching the frame color is
836 // more important. 845 // more important.
837 846
838 BuildFrameColors(); 847 BuildFrameColors();
839 SkColor frame_color = colors_[ThemeProperties::COLOR_FRAME]; 848 SkColor frame_color = colors_[ThemeProperties::COLOR_FRAME];
840 colors_[ThemeProperties::COLOR_NTP_HEADER] = frame_color; 849 colors_[ThemeProperties::COLOR_NTP_HEADER] = frame_color;
841 colors_[ThemeProperties::COLOR_NTP_SECTION] = toolbar_color; 850 colors_[ThemeProperties::COLOR_NTP_SECTION] = toolbar_color;
842 colors_[ThemeProperties::COLOR_NTP_SECTION_TEXT] = label_color; 851 colors_[ThemeProperties::COLOR_NTP_SECTION_TEXT] = label_color;
843 852
844 SkColor link_color = 853 SkColor link_color =
845 theme->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); 854 native_theme_->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled);
846 colors_[ThemeProperties::COLOR_NTP_LINK] = link_color; 855 colors_[ThemeProperties::COLOR_NTP_LINK] = link_color;
847 colors_[ThemeProperties::COLOR_NTP_LINK_UNDERLINE] = link_color; 856 colors_[ThemeProperties::COLOR_NTP_LINK_UNDERLINE] = link_color;
848 colors_[ThemeProperties::COLOR_NTP_SECTION_LINK] = link_color; 857 colors_[ThemeProperties::COLOR_NTP_SECTION_LINK] = link_color;
849 colors_[ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE] = link_color; 858 colors_[ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE] = link_color;
850 859
851 // Generate the colors that we pass to WebKit. 860 // Generate the colors that we pass to WebKit.
852 focus_ring_color_ = frame_color; 861 focus_ring_color_ = frame_color;
853 862
854 SetScrollbarColors(); 863 SetScrollbarColors();
855 864
856 // Some GTK themes only define the text selection colors on the GtkEntry 865 // Some GTK themes only define the text selection colors on the GtkEntry
857 // class, so we need to use that for getting selection colors. 866 // class, so we need to use that for getting selection colors.
858 active_selection_bg_color_ = theme->GetSystemColor( 867 active_selection_bg_color_ = native_theme_->GetSystemColor(
859 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); 868 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused);
860 active_selection_fg_color_ = 869 active_selection_fg_color_ = native_theme_->GetSystemColor(
861 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldSelectionColor); 870 ui::NativeTheme::kColorId_TextfieldSelectionColor);
862 inactive_selection_bg_color_ = theme->GetSystemColor( 871 inactive_selection_bg_color_ = native_theme_->GetSystemColor(
863 ui::NativeTheme::kColorId_TextfieldReadOnlyBackground); 872 ui::NativeTheme::kColorId_TextfieldReadOnlyBackground);
864 inactive_selection_fg_color_ = 873 inactive_selection_fg_color_ = native_theme_->GetSystemColor(
865 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldReadOnlyColor); 874 ui::NativeTheme::kColorId_TextfieldReadOnlyColor);
866 875
867 colors_[ThemeProperties::COLOR_TAB_THROBBER_SPINNING] = 876 colors_[ThemeProperties::COLOR_TAB_THROBBER_SPINNING] =
868 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberSpinningColor); 877 native_theme_->GetSystemColor(
878 ui::NativeTheme::kColorId_ThrobberSpinningColor);
869 colors_[ThemeProperties::COLOR_TAB_THROBBER_WAITING] = 879 colors_[ThemeProperties::COLOR_TAB_THROBBER_WAITING] =
870 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberWaitingColor); 880 native_theme_->GetSystemColor(
881 ui::NativeTheme::kColorId_ThrobberWaitingColor);
871 } 882 }
872 883
873 void Gtk2UI::LoadCursorTheme() { 884 void Gtk2UI::LoadCursorTheme() {
874 GtkSettings* settings = gtk_settings_get_default(); 885 GtkSettings* settings = gtk_settings_get_default();
875 886
876 gchar* theme = nullptr; 887 gchar* theme = nullptr;
877 gint size = 0; 888 gint size = 0;
878 g_object_get(settings, 889 g_object_get(settings, "gtk-cursor-theme-name", &theme,
879 "gtk-cursor-theme-name", &theme, 890 "gtk-cursor-theme-size", &size, nullptr);
880 "gtk-cursor-theme-size", &size,
881 nullptr);
882 891
883 if (theme) 892 if (theme)
884 XcursorSetTheme(gfx::GetXDisplay(), theme); 893 XcursorSetTheme(gfx::GetXDisplay(), theme);
885 if (size) 894 if (size)
886 XcursorSetDefaultSize(gfx::GetXDisplay(), size); 895 XcursorSetDefaultSize(gfx::GetXDisplay(), size);
887 896
888 g_free(theme); 897 g_free(theme);
889 } 898 }
890 899
891 void Gtk2UI::BuildFrameColors() { 900 void Gtk2UI::BuildFrameColors() {
892 #if GTK_MAJOR_VERSION == 2 901 #if GTK_MAJOR_VERSION == 2
893 NativeThemeGtk2* theme = NativeThemeGtk2::instance();
894 color_utils::HSL kDefaultFrameShift = {-1, -1, 0.4}; 902 color_utils::HSL kDefaultFrameShift = {-1, -1, 0.4};
895 SkColor frame_color = 903 SkColor frame_color =
896 theme->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground); 904 native_theme_->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground);
897 frame_color = color_utils::HSLShift(frame_color, kDefaultFrameShift); 905 frame_color = color_utils::HSLShift(frame_color, kDefaultFrameShift);
898 theme->GetChromeStyleColor("frame-color", &frame_color); 906 GetChromeStyleColor("frame-color", &frame_color);
899 colors_[ThemeProperties::COLOR_FRAME] = frame_color; 907 colors_[ThemeProperties::COLOR_FRAME] = frame_color;
900 908
901 GtkStyle* style = gtk_rc_get_style(theme->GetWindow()); 909 GtkStyle* style = gtk_rc_get_style(fake_window_);
902 SkColor temp_color = color_utils::HSLShift( 910 SkColor temp_color = color_utils::HSLShift(
903 GdkColorToSkColor(style->bg[GTK_STATE_INSENSITIVE]), kDefaultFrameShift); 911 GdkColorToSkColor(style->bg[GTK_STATE_INSENSITIVE]), kDefaultFrameShift);
904 theme->GetChromeStyleColor("inactive-frame-color", &temp_color); 912 GetChromeStyleColor("inactive-frame-color", &temp_color);
905 colors_[ThemeProperties::COLOR_FRAME_INACTIVE] = temp_color; 913 colors_[ThemeProperties::COLOR_FRAME_INACTIVE] = temp_color;
906 914
907 temp_color = color_utils::HSLShift(frame_color, kDefaultTintFrameIncognito); 915 temp_color = color_utils::HSLShift(frame_color, kDefaultTintFrameIncognito);
908 theme->GetChromeStyleColor("incognito-frame-color", &temp_color); 916 GetChromeStyleColor("incognito-frame-color", &temp_color);
909 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO] = temp_color; 917 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO] = temp_color;
910 918
911 temp_color = 919 temp_color =
912 color_utils::HSLShift(frame_color, kDefaultTintFrameIncognitoInactive); 920 color_utils::HSLShift(frame_color, kDefaultTintFrameIncognitoInactive);
913 theme->GetChromeStyleColor("incognito-inactive-frame-color", &temp_color); 921 GetChromeStyleColor("incognito-inactive-frame-color", &temp_color);
914 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = temp_color; 922 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = temp_color;
915 #else 923 #else
916 auto set_frame_color = [this](int color_id) { 924 auto set_frame_color = [this](int color_id) {
917 // Render a GtkHeaderBar as our title bar, cropping out any curved edges 925 // Render a GtkHeaderBar as our title bar, cropping out any curved edges
918 // on the left and right sides. Also remove the bottom border for good 926 // on the left and right sides. Also remove the bottom border for good
919 // measure. 927 // measure.
920 SkBitmap bitmap; 928 SkBitmap bitmap;
921 bitmap.allocN32Pixels(1, 1); 929 bitmap.allocN32Pixels(1, 1);
922 bitmap.eraseColor(0); 930 bitmap.eraseColor(0);
923 931
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 }; 970 };
963 971
964 set_frame_color(ThemeProperties::COLOR_FRAME); 972 set_frame_color(ThemeProperties::COLOR_FRAME);
965 set_frame_color(ThemeProperties::COLOR_FRAME_INACTIVE); 973 set_frame_color(ThemeProperties::COLOR_FRAME_INACTIVE);
966 set_frame_color(ThemeProperties::COLOR_FRAME_INCOGNITO); 974 set_frame_color(ThemeProperties::COLOR_FRAME_INCOGNITO);
967 set_frame_color(ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE); 975 set_frame_color(ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE);
968 #endif 976 #endif
969 } 977 }
970 978
971 void Gtk2UI::GetNormalButtonTintHSL(color_utils::HSL* tint) const { 979 void Gtk2UI::GetNormalButtonTintHSL(color_utils::HSL* tint) const {
972 NativeThemeGtk2* theme = NativeThemeGtk2::instance(); 980 SkColor accent_color = native_theme_->GetSystemColor(
973 981 ui::NativeTheme::kColorId_ProminentButtonColor);
974 SkColor accent_color = 982 SkColor text_color = native_theme_->GetSystemColor(
975 theme->GetSystemColor(ui::NativeTheme::kColorId_ProminentButtonColor); 983 ui::NativeTheme::kColorId_LabelEnabledColor);
976 SkColor text_color =
977 theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor);
978 SkColor base_color = 984 SkColor base_color =
979 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); 985 native_theme_->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground);
980 986
981 PickButtonTintFromColors(accent_color, text_color, base_color, tint); 987 PickButtonTintFromColors(accent_color, text_color, base_color, tint);
982 } 988 }
983 989
984 void Gtk2UI::GetNormalEntryForegroundHSL(color_utils::HSL* tint) const { 990 void Gtk2UI::GetNormalEntryForegroundHSL(color_utils::HSL* tint) const {
985 NativeThemeGtk2* theme = NativeThemeGtk2::instance(); 991 SkColor accent_color = native_theme_->GetSystemColor(
986 992 ui::NativeTheme::kColorId_ProminentButtonColor);
987 SkColor accent_color = 993 SkColor text_color = native_theme_->GetSystemColor(
988 theme->GetSystemColor(ui::NativeTheme::kColorId_ProminentButtonColor); 994 ui::NativeTheme::kColorId_TextfieldDefaultColor);
989 SkColor text_color = 995 SkColor base_color = native_theme_->GetSystemColor(
990 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor);
991 SkColor base_color = theme->GetSystemColor(
992 ui::NativeTheme::kColorId_TextfieldDefaultBackground); 996 ui::NativeTheme::kColorId_TextfieldDefaultBackground);
993 997
994 PickButtonTintFromColors(accent_color, text_color, base_color, tint); 998 PickButtonTintFromColors(accent_color, text_color, base_color, tint);
995 } 999 }
996 1000
997 void Gtk2UI::GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const { 1001 void Gtk2UI::GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const {
998 // The simplest of all the tints. We just use the selected text in the entry 1002 // The simplest of all the tints. We just use the selected text in the entry
999 // since the icons tinted this way will only be displayed against 1003 // since the icons tinted this way will only be displayed against
1000 // base[GTK_STATE_SELECTED]. 1004 // base[GTK_STATE_SELECTED].
1001 SkColor color = NativeThemeGtk2::instance()->GetSystemColor( 1005 SkColor color = native_theme_->GetSystemColor(
1002 ui::NativeTheme::kColorId_TextfieldSelectionColor); 1006 ui::NativeTheme::kColorId_TextfieldSelectionColor);
1003 1007
1004 color_utils::SkColorToHSL(color, tint); 1008 color_utils::SkColorToHSL(color, tint);
1005 } 1009 }
1006 1010
1007 void Gtk2UI::UpdateDefaultFont() { 1011 void Gtk2UI::UpdateDefaultFont() {
1008 PangoContext* pc = 1012 GtkWidget* fake_label = gtk_label_new(nullptr);
1009 gtk_widget_get_pango_context(NativeThemeGtk2::instance()->GetLabel()); 1013 g_object_ref_sink(fake_label); // Remove the floating reference.
1014 PangoContext* pc = gtk_widget_get_pango_context(fake_label);
1010 const PangoFontDescription* desc = pango_context_get_font_description(pc); 1015 const PangoFontDescription* desc = pango_context_get_font_description(pc);
1011 1016
1012 // Use gfx::FontRenderParams to select a family and determine the rendering 1017 // Use gfx::FontRenderParams to select a family and determine the rendering
1013 // settings. 1018 // settings.
1014 gfx::FontRenderParamsQuery query; 1019 gfx::FontRenderParamsQuery query;
1015 query.families = 1020 query.families =
1016 base::SplitString(pango_font_description_get_family(desc), ",", 1021 base::SplitString(pango_font_description_get_family(desc), ",",
1017 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 1022 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
1018 1023
1019 if (pango_font_description_get_size_is_absolute(desc)) { 1024 if (pango_font_description_get_size_is_absolute(desc)) {
1020 // If the size is absolute, it's specified in Pango units. There are 1025 // If the size is absolute, it's specified in Pango units. There are
1021 // PANGO_SCALE Pango units in a device unit (pixel). 1026 // PANGO_SCALE Pango units in a device unit (pixel).
1022 const int size_pixels = pango_font_description_get_size(desc) / PANGO_SCALE; 1027 const int size_pixels = pango_font_description_get_size(desc) / PANGO_SCALE;
1023 default_font_size_pixels_ = size_pixels; 1028 default_font_size_pixels_ = size_pixels;
1024 query.pixel_size = size_pixels; 1029 query.pixel_size = size_pixels;
1025 } else { 1030 } else {
1026 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). 1031 // Non-absolute sizes are in points (again scaled by PANGO_SIZE).
1027 // Round the value when converting to pixels to match GTK's logic. 1032 // Round the value when converting to pixels to match GTK's logic.
1028 const double size_points = pango_font_description_get_size(desc) / 1033 const double size_points = pango_font_description_get_size(desc) /
1029 static_cast<double>(PANGO_SCALE); 1034 static_cast<double>(PANGO_SCALE);
1030 default_font_size_pixels_ = static_cast<int>( 1035 default_font_size_pixels_ = static_cast<int>(
1031 GetFontSizePixelsInPoint(GetDeviceScaleFactor()) * size_points); 1036 GetFontSizePixelsInPoint(GetDeviceScaleFactor()) * size_points);
1032 query.point_size = static_cast<int>(size_points); 1037 query.point_size = static_cast<int>(size_points);
1033 } 1038 }
1034 1039
1035 query.style = gfx::Font::NORMAL; 1040 query.style = gfx::Font::NORMAL;
1036 query.weight = 1041 query.weight =
1037 static_cast<gfx::Font::Weight>(pango_font_description_get_weight(desc)); 1042 static_cast<gfx::Font::Weight>(pango_font_description_get_weight(desc));
1038 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? 1043 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE?
1039 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) 1044 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC)
1040 query.style |= gfx::Font::ITALIC; 1045 query.style |= gfx::Font::ITALIC;
1041 1046
1042 default_font_render_params_ = 1047 default_font_render_params_ =
1043 gfx::GetFontRenderParams(query, &default_font_family_); 1048 gfx::GetFontRenderParams(query, &default_font_family_);
1044 default_font_style_ = query.style; 1049 default_font_style_ = query.style;
1050
1051 gtk_widget_destroy(fake_label);
1052 g_object_unref(fake_label);
1053 }
1054
1055 bool Gtk2UI::GetChromeStyleColor(const char* style_property,
1056 SkColor* ret_color) const {
1057 #if GTK_MAJOR_VERSION == 2
1058 GdkColor* style_color = nullptr;
1059 gtk_widget_style_get(fake_window_, style_property, &style_color, nullptr);
1060 if (style_color) {
1061 *ret_color = GdkColorToSkColor(*style_color);
1062 gdk_color_free(style_color);
1063 return true;
1064 }
1065 #endif
1066
1067 return false;
1045 } 1068 }
1046 1069
1047 void Gtk2UI::ResetStyle() { 1070 void Gtk2UI::ResetStyle() {
1048 LoadGtkValues(); 1071 LoadGtkValues();
1049 NativeThemeGtk2::instance()->NotifyObservers(); 1072 native_theme_->NotifyObservers();
1050 } 1073 }
1051 1074
1052 void Gtk2UI::UpdateDeviceScaleFactor() { 1075 void Gtk2UI::UpdateDeviceScaleFactor() {
1053 // Note: Linux chrome currently does not support dynamic DPI 1076 // Note: Linux chrome currently does not support dynamic DPI
1054 // changes. This is to allow flags to override the DPI settings 1077 // changes. This is to allow flags to override the DPI settings
1055 // during startup. 1078 // during startup.
1056 float scale = GetRawDeviceScaleFactor(); 1079 float scale = GetRawDeviceScaleFactor();
1057 // Blacklist scaling factors <120% (crbug.com/484400) and round 1080 // Blacklist scaling factors <120% (crbug.com/484400) and round
1058 // to 1 decimal to prevent rendering problems (crbug.com/485183). 1081 // to 1 decimal to prevent rendering problems (crbug.com/485183).
1059 device_scale_factor_ = scale < 1.2f ? 1.0f : roundf(scale * 10) / 10; 1082 device_scale_factor_ = scale < 1.2f ? 1.0f : roundf(scale * 10) / 10;
1060 UpdateDefaultFont(); 1083 UpdateDefaultFont();
1061 } 1084 }
1062 1085
1063 float Gtk2UI::GetDeviceScaleFactor() const { 1086 float Gtk2UI::GetDeviceScaleFactor() const {
1064 return device_scale_factor_; 1087 return device_scale_factor_;
1065 } 1088 }
1066 1089
1067 } // namespace libgtkui 1090 } // namespace libgtkui
1068 1091
1069 views::LinuxUI* BuildGtk2UI() { 1092 views::LinuxUI* BuildGtk2UI() {
1070 return new libgtkui::Gtk2UI; 1093 return new libgtkui::Gtk2UI;
1071 } 1094 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtkui/gtk_ui.h ('k') | chrome/browser/ui/libgtkui/gtk_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698