Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 | 426 |
| 427 void GtkUi::Initialize() { | 427 void GtkUi::Initialize() { |
| 428 GtkSettings* settings = gtk_settings_get_default(); | 428 GtkSettings* settings = gtk_settings_get_default(); |
| 429 g_signal_connect_after(settings, "notify::gtk-theme-name", | 429 g_signal_connect_after(settings, "notify::gtk-theme-name", |
| 430 G_CALLBACK(OnThemeChanged), this); | 430 G_CALLBACK(OnThemeChanged), this); |
| 431 g_signal_connect_after(settings, "notify::gtk-icon-theme-name", | 431 g_signal_connect_after(settings, "notify::gtk-icon-theme-name", |
| 432 G_CALLBACK(OnThemeChanged), this); | 432 G_CALLBACK(OnThemeChanged), this); |
| 433 | 433 |
| 434 LoadGtkValues(); | 434 LoadGtkValues(); |
| 435 | 435 |
| 436 LoadCursorTheme(); | |
| 437 | |
| 438 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 436 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 439 printing::PrintingContextLinux::SetCreatePrintDialogFunction( | 437 printing::PrintingContextLinux::SetCreatePrintDialogFunction( |
| 440 &PrintDialogGtk2::CreatePrintDialog); | 438 &PrintDialogGtk2::CreatePrintDialog); |
| 441 printing::PrintingContextLinux::SetPdfPaperSizeFunction( | 439 printing::PrintingContextLinux::SetPdfPaperSizeFunction( |
| 442 &GetPdfPaperSizeDeviceUnitsGtk); | 440 &GetPdfPaperSizeDeviceUnitsGtk); |
| 443 #endif | 441 #endif |
| 444 | 442 |
| 445 #if defined(USE_GCONF) | 443 #if defined(USE_GCONF) |
| 446 // We must build this after GTK gets initialized. | 444 // We must build this after GTK gets initialized. |
| 447 gconf_listener_.reset(new GConfListener(this)); | 445 gconf_listener_.reset(new GConfListener(this)); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 GetChromeStyleColor("scrollbar-slider-normal-color", &thumb_inactive_color_); | 777 GetChromeStyleColor("scrollbar-slider-normal-color", &thumb_inactive_color_); |
| 780 GetChromeStyleColor("scrollbar-trough-color", &track_color_); | 778 GetChromeStyleColor("scrollbar-trough-color", &track_color_); |
| 781 } | 779 } |
| 782 | 780 |
| 783 void GtkUi::LoadGtkValues() { | 781 void GtkUi::LoadGtkValues() { |
| 784 // TODO(erg): GtkThemeService had a comment here about having to muck with | 782 // TODO(erg): GtkThemeService had a comment here about having to muck with |
| 785 // the raw Prefs object to remove prefs::kCurrentThemeImages or else we'd | 783 // the raw Prefs object to remove prefs::kCurrentThemeImages or else we'd |
| 786 // regress startup time. Figure out how to do that when we can't access the | 784 // regress startup time. Figure out how to do that when we can't access the |
| 787 // prefs system from here. | 785 // prefs system from here. |
| 788 | 786 |
| 789 SkColor label_color = native_theme_->GetSystemColor( | 787 UpdateDeviceScaleFactor(); |
| 790 ui::NativeTheme::kColorId_LabelEnabledColor); | 788 UpdateCursorTheme(); |
| 789 | |
| 790 BuildFrameColors(); | |
| 791 | 791 |
| 792 #if GTK_MAJOR_VERSION == 2 | 792 #if GTK_MAJOR_VERSION == 2 |
| 793 SkColor toolbar_color = | 793 SkColor toolbar_color = |
| 794 native_theme_->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); | 794 native_theme_->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); |
| 795 SkColor label_color = native_theme_->GetSystemColor( | |
| 796 ui::NativeTheme::kColorId_LabelEnabledColor); | |
| 795 | 797 |
| 796 colors_[ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON] = | 798 colors_[ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON] = |
| 797 color_utils::DeriveDefaultIconColor(label_color); | 799 color_utils::DeriveDefaultIconColor(label_color); |
| 798 | 800 |
| 799 colors_[ThemeProperties::COLOR_TAB_TEXT] = label_color; | 801 colors_[ThemeProperties::COLOR_TAB_TEXT] = label_color; |
| 800 colors_[ThemeProperties::COLOR_BOOKMARK_TEXT] = label_color; | 802 colors_[ThemeProperties::COLOR_BOOKMARK_TEXT] = label_color; |
| 801 colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] = | 803 colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] = |
| 802 color_utils::BlendTowardOppositeLuma(label_color, 50); | 804 color_utils::BlendTowardOppositeLuma(label_color, 50); |
| 803 | 805 |
| 804 inactive_selection_bg_color_ = native_theme_->GetSystemColor( | 806 inactive_selection_bg_color_ = native_theme_->GetSystemColor( |
| 805 ui::NativeTheme::kColorId_TextfieldReadOnlyBackground); | 807 ui::NativeTheme::kColorId_TextfieldReadOnlyBackground); |
| 806 inactive_selection_fg_color_ = native_theme_->GetSystemColor( | 808 inactive_selection_fg_color_ = native_theme_->GetSystemColor( |
| 807 ui::NativeTheme::kColorId_TextfieldReadOnlyColor); | 809 ui::NativeTheme::kColorId_TextfieldReadOnlyColor); |
| 810 | |
| 811 // We pick the text and background colors for the NTP out of the | |
| 812 // colors for a GtkEntry. We do this because GtkEntries background | |
| 813 // color is never the same as |toolbar_color|, is usually a white, | |
| 814 // and when it isn't a white, provides sufficient contrast to | |
| 815 // |toolbar_color|. Try this out with Darklooks, HighContrastInverse | |
| 816 // or ThinIce. | |
| 817 colors_[ThemeProperties::COLOR_NTP_BACKGROUND] = | |
| 818 native_theme_->GetSystemColor( | |
| 819 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | |
| 820 colors_[ThemeProperties::COLOR_NTP_TEXT] = native_theme_->GetSystemColor( | |
| 821 ui::NativeTheme::kColorId_TextfieldDefaultColor); | |
| 822 // The NTP header is the color that surrounds the current active | |
| 823 // thumbnail on the NTP, and acts as the border of the "Recent | |
| 824 // Links" box. It would be awesome if they were separated so we | |
| 825 // could use GetBorderColor() for the border around the "Recent | |
| 826 // Links" section, but matching the frame color is more important. | |
| 827 colors_[ThemeProperties::COLOR_NTP_HEADER] = | |
| 828 colors_[ThemeProperties::COLOR_FRAME]; | |
| 808 #else | 829 #else |
| 809 SkColor toolbar_color = GetBgColor("GtkToolbar#toolbar"); | 830 SkColor toolbar_color = GetBgColor("GtkToolbar#toolbar"); |
| 810 | 831 |
| 811 colors_[ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON] = | 832 colors_[ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON] = |
| 812 GetFgColor("GtkToolbar#toolbar GtkLabel#label"); | 833 GetFgColor("GtkToolbar#toolbar GtkLabel#label"); |
| 813 | 834 |
| 814 // Tabs use the same background color as the toolbar, so use the | 835 // Tabs use the same background color as the toolbar, so use the |
| 815 // toolbar text color as the tab text color. | 836 // toolbar text color as the tab text color. |
| 816 SkColor tab_text_color = | 837 SkColor tab_text_color = |
| 817 GetFgColor("GtkToolbar#toolbar.horizontal GtkLabel#label"); | 838 GetFgColor("GtkToolbar#toolbar.horizontal GtkLabel#label"); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 850 GetBorderColor("#headerbar.header-bar.titlebar GtkEntry#entry"); | 871 GetBorderColor("#headerbar.header-bar.titlebar GtkEntry#entry"); |
| 851 SkColor entry_inactive_border = | 872 SkColor entry_inactive_border = |
| 852 GetBorderColor("#headerbar.header-bar.titlebar:backdrop GtkEntry#entry"); | 873 GetBorderColor("#headerbar.header-bar.titlebar:backdrop GtkEntry#entry"); |
| 853 // Unlike with toolbars, we always want a border around tabs, so let | 874 // Unlike with toolbars, we always want a border around tabs, so let |
| 854 // ThemeService choose the border color if the theme doesn't provide one. | 875 // ThemeService choose the border color if the theme doesn't provide one. |
| 855 if (SkColorGetA(entry_border) && SkColorGetA(entry_inactive_border)) { | 876 if (SkColorGetA(entry_border) && SkColorGetA(entry_inactive_border)) { |
| 856 colors_[ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR] = entry_border; | 877 colors_[ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR] = entry_border; |
| 857 colors_[ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR_INACTIVE] = | 878 colors_[ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR_INACTIVE] = |
| 858 entry_inactive_border; | 879 entry_inactive_border; |
| 859 } | 880 } |
| 881 | |
| 882 colors_[ThemeProperties::COLOR_NTP_BACKGROUND] = GetBgColor(""); | |
| 883 colors_[ThemeProperties::COLOR_NTP_TEXT] = GetFgColor(""); | |
| 884 colors_[ThemeProperties::COLOR_NTP_HEADER] = GetBorderColor("GtkEntry#entry"); | |
| 860 #endif | 885 #endif |
| 861 | 886 |
| 887 colors_[ThemeProperties::COLOR_TOOLBAR] = toolbar_color; | |
| 862 colors_[ThemeProperties::COLOR_CONTROL_BACKGROUND] = toolbar_color; | 888 colors_[ThemeProperties::COLOR_CONTROL_BACKGROUND] = toolbar_color; |
| 863 colors_[ThemeProperties::COLOR_TOOLBAR] = toolbar_color; | |
| 864 | 889 |
| 865 UpdateDeviceScaleFactor(); | 890 colors_[ThemeProperties::COLOR_NTP_LINK] = |
| 866 | |
| 867 // We pick the text and background colors for the NTP out of the colors for a | |
| 868 // GtkEntry. We do this because GtkEntries background color is never the same | |
| 869 // as |toolbar_color|, is usually a white, and when it isn't a white, | |
| 870 // provides sufficient contrast to |toolbar_color|. Try this out with | |
| 871 // Darklooks, HighContrastInverse or ThinIce. | |
| 872 | |
| 873 SkColor ntp_background = native_theme_->GetSystemColor( | |
| 874 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | |
| 875 SkColor ntp_foreground = native_theme_->GetSystemColor( | |
| 876 ui::NativeTheme::kColorId_TextfieldDefaultColor); | |
| 877 | |
| 878 colors_[ThemeProperties::COLOR_NTP_BACKGROUND] = ntp_background; | |
| 879 colors_[ThemeProperties::COLOR_NTP_TEXT] = ntp_foreground; | |
| 880 | |
| 881 // The NTP header is the color that surrounds the current active thumbnail on | |
| 882 // the NTP, and acts as the border of the "Recent Links" box. It would be | |
| 883 // awesome if they were separated so we could use GetBorderColor() for the | |
| 884 // border around the "Recent Links" section, but matching the frame color is | |
| 885 // more important. | |
| 886 | |
| 887 BuildFrameColors(); | |
| 888 SkColor frame_color = colors_[ThemeProperties::COLOR_FRAME]; | |
| 889 colors_[ThemeProperties::COLOR_NTP_HEADER] = frame_color; | |
| 890 colors_[ThemeProperties::COLOR_NTP_SECTION] = toolbar_color; | |
|
Elliot Glaysher
2017/01/31 18:30:51
If these values are actually unusued, you probably
Tom (Use chromium acct)
2017/01/31 18:57:40
sgtm, but maybe that can be done in a different CL
| |
| 891 colors_[ThemeProperties::COLOR_NTP_SECTION_TEXT] = label_color; | |
| 892 | |
| 893 SkColor link_color = | |
| 894 native_theme_->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); | 891 native_theme_->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); |
| 895 colors_[ThemeProperties::COLOR_NTP_LINK] = link_color; | |
| 896 colors_[ThemeProperties::COLOR_NTP_LINK_UNDERLINE] = link_color; | |
| 897 colors_[ThemeProperties::COLOR_NTP_SECTION_LINK] = link_color; | |
| 898 colors_[ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE] = link_color; | |
| 899 | 892 |
| 900 // Generate the colors that we pass to WebKit. | 893 // Generate the colors that we pass to WebKit. |
| 901 focus_ring_color_ = frame_color; | |
| 902 | |
| 903 SetScrollbarColors(); | 894 SetScrollbarColors(); |
| 895 focus_ring_color_ = native_theme_->GetSystemColor( | |
| 896 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); | |
| 904 | 897 |
| 905 // Some GTK themes only define the text selection colors on the GtkEntry | 898 // Some GTK themes only define the text selection colors on the GtkEntry |
| 906 // class, so we need to use that for getting selection colors. | 899 // class, so we need to use that for getting selection colors. |
| 907 active_selection_bg_color_ = native_theme_->GetSystemColor( | 900 active_selection_bg_color_ = native_theme_->GetSystemColor( |
| 908 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); | 901 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); |
| 909 active_selection_fg_color_ = native_theme_->GetSystemColor( | 902 active_selection_fg_color_ = native_theme_->GetSystemColor( |
| 910 ui::NativeTheme::kColorId_TextfieldSelectionColor); | 903 ui::NativeTheme::kColorId_TextfieldSelectionColor); |
| 911 | 904 |
| 912 colors_[ThemeProperties::COLOR_TAB_THROBBER_SPINNING] = | 905 colors_[ThemeProperties::COLOR_TAB_THROBBER_SPINNING] = |
| 913 native_theme_->GetSystemColor( | 906 native_theme_->GetSystemColor( |
| 914 ui::NativeTheme::kColorId_ThrobberSpinningColor); | 907 ui::NativeTheme::kColorId_ThrobberSpinningColor); |
| 915 colors_[ThemeProperties::COLOR_TAB_THROBBER_WAITING] = | 908 colors_[ThemeProperties::COLOR_TAB_THROBBER_WAITING] = |
| 916 native_theme_->GetSystemColor( | 909 native_theme_->GetSystemColor( |
| 917 ui::NativeTheme::kColorId_ThrobberWaitingColor); | 910 ui::NativeTheme::kColorId_ThrobberWaitingColor); |
| 918 } | 911 } |
| 919 | 912 |
| 920 void GtkUi::LoadCursorTheme() { | 913 void GtkUi::UpdateCursorTheme() { |
| 921 GtkSettings* settings = gtk_settings_get_default(); | 914 GtkSettings* settings = gtk_settings_get_default(); |
| 922 | 915 |
| 923 gchar* theme = nullptr; | 916 gchar* theme = nullptr; |
| 924 gint size = 0; | 917 gint size = 0; |
| 925 g_object_get(settings, "gtk-cursor-theme-name", &theme, | 918 g_object_get(settings, "gtk-cursor-theme-name", &theme, |
| 926 "gtk-cursor-theme-size", &size, nullptr); | 919 "gtk-cursor-theme-size", &size, nullptr); |
| 927 | 920 |
| 928 if (theme) | 921 if (theme) |
| 929 XcursorSetTheme(gfx::GetXDisplay(), theme); | 922 XcursorSetTheme(gfx::GetXDisplay(), theme); |
| 930 if (size) | 923 if (size) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1046 | 1039 |
| 1047 float GtkUi::GetDeviceScaleFactor() const { | 1040 float GtkUi::GetDeviceScaleFactor() const { |
| 1048 return device_scale_factor_; | 1041 return device_scale_factor_; |
| 1049 } | 1042 } |
| 1050 | 1043 |
| 1051 } // namespace libgtkui | 1044 } // namespace libgtkui |
| 1052 | 1045 |
| 1053 views::LinuxUI* BuildGtkUi() { | 1046 views::LinuxUI* BuildGtkUi() { |
| 1054 return new libgtkui::GtkUi; | 1047 return new libgtkui::GtkUi; |
| 1055 } | 1048 } |
| OLD | NEW |