| 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 // The unknown content type. | 236 // The unknown content type. |
| 237 const char* kUnknownContentType = "application/octet-stream"; | 237 const char* kUnknownContentType = "application/octet-stream"; |
| 238 | 238 |
| 239 // TODO(erg): ThemeService has a whole interface just for reading default | 239 // TODO(erg): ThemeService has a whole interface just for reading default |
| 240 // constants. Figure out what to do with that more long term; for now, just | 240 // constants. Figure out what to do with that more long term; for now, just |
| 241 // copy the constants themselves here. | 241 // copy the constants themselves here. |
| 242 // | 242 // |
| 243 // Default tints. | 243 // Default tints. |
| 244 const color_utils::HSL kDefaultTintFrameIncognito = {-1, 0.2f, 0.35f}; | 244 const color_utils::HSL kDefaultTintFrameIncognito = {-1, 0.2f, 0.35f}; |
| 245 #if GTK_MAJOR_VERSION == 2 |
| 245 const color_utils::HSL kDefaultTintFrameIncognitoInactive = {-1, 0.3f, 0.6f}; | 246 const color_utils::HSL kDefaultTintFrameIncognitoInactive = {-1, 0.3f, 0.6f}; |
| 246 | 247 #endif |
| 247 #if GTK_MAJOR_VERSION == 3 | |
| 248 const color_utils::HSL kDefaultTintFrameInactive = {-1, -1, 0.75f}; | |
| 249 #endif // GTK_MAJOR_VERSION == 3 | |
| 250 | 248 |
| 251 // Picks a button tint from a set of background colors. While | 249 // Picks a button tint from a set of background colors. While |
| 252 // |accent_color| will usually be the same color through a theme, this | 250 // |accent_color| will usually be the same color through a theme, this |
| 253 // function will get called with the normal GtkLabel |text_color|/GtkWindow | 251 // function will get called with the normal GtkLabel |text_color|/GtkWindow |
| 254 // |background_color| pair and the GtkEntry |text_color|/|background_color| | 252 // |background_color| pair and the GtkEntry |text_color|/|background_color| |
| 255 // pair. While 3/4 of the time the resulting tint will be the same, themes that | 253 // pair. While 3/4 of the time the resulting tint will be the same, themes that |
| 256 // have a dark window background (with light text) and a light text entry (with | 254 // have a dark window background (with light text) and a light text entry (with |
| 257 // dark text) will get better icons with this separated out. | 255 // dark text) will get better icons with this separated out. |
| 258 void PickButtonTintFromColors(SkColor accent_color, | 256 void PickButtonTintFromColors(SkColor accent_color, |
| 259 SkColor text_color, | 257 SkColor text_color, |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 ui::NativeTheme::kColorId_TextfieldReadOnlyBackground); | 870 ui::NativeTheme::kColorId_TextfieldReadOnlyBackground); |
| 873 inactive_selection_fg_color_ = native_theme_->GetSystemColor( | 871 inactive_selection_fg_color_ = native_theme_->GetSystemColor( |
| 874 ui::NativeTheme::kColorId_TextfieldReadOnlyColor); | 872 ui::NativeTheme::kColorId_TextfieldReadOnlyColor); |
| 875 | 873 |
| 876 colors_[ThemeProperties::COLOR_TAB_THROBBER_SPINNING] = | 874 colors_[ThemeProperties::COLOR_TAB_THROBBER_SPINNING] = |
| 877 native_theme_->GetSystemColor( | 875 native_theme_->GetSystemColor( |
| 878 ui::NativeTheme::kColorId_ThrobberSpinningColor); | 876 ui::NativeTheme::kColorId_ThrobberSpinningColor); |
| 879 colors_[ThemeProperties::COLOR_TAB_THROBBER_WAITING] = | 877 colors_[ThemeProperties::COLOR_TAB_THROBBER_WAITING] = |
| 880 native_theme_->GetSystemColor( | 878 native_theme_->GetSystemColor( |
| 881 ui::NativeTheme::kColorId_ThrobberWaitingColor); | 879 ui::NativeTheme::kColorId_ThrobberWaitingColor); |
| 880 |
| 881 #if GTK_MAJOR_VERSION > 2 |
| 882 colors_[ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR] = |
| 883 colors_[ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_SEPARATOR] = |
| 884 GetBorderColor("GtkToolbar.primary-toolbar.toolbar"); |
| 885 #endif |
| 882 } | 886 } |
| 883 | 887 |
| 884 void Gtk2UI::LoadCursorTheme() { | 888 void Gtk2UI::LoadCursorTheme() { |
| 885 GtkSettings* settings = gtk_settings_get_default(); | 889 GtkSettings* settings = gtk_settings_get_default(); |
| 886 | 890 |
| 887 gchar* theme = nullptr; | 891 gchar* theme = nullptr; |
| 888 gint size = 0; | 892 gint size = 0; |
| 889 g_object_get(settings, "gtk-cursor-theme-name", &theme, | 893 g_object_get(settings, "gtk-cursor-theme-name", &theme, |
| 890 "gtk-cursor-theme-size", &size, nullptr); | 894 "gtk-cursor-theme-size", &size, nullptr); |
| 891 | 895 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 914 | 918 |
| 915 temp_color = color_utils::HSLShift(frame_color, kDefaultTintFrameIncognito); | 919 temp_color = color_utils::HSLShift(frame_color, kDefaultTintFrameIncognito); |
| 916 GetChromeStyleColor("incognito-frame-color", &temp_color); | 920 GetChromeStyleColor("incognito-frame-color", &temp_color); |
| 917 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO] = temp_color; | 921 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO] = temp_color; |
| 918 | 922 |
| 919 temp_color = | 923 temp_color = |
| 920 color_utils::HSLShift(frame_color, kDefaultTintFrameIncognitoInactive); | 924 color_utils::HSLShift(frame_color, kDefaultTintFrameIncognitoInactive); |
| 921 GetChromeStyleColor("incognito-inactive-frame-color", &temp_color); | 925 GetChromeStyleColor("incognito-inactive-frame-color", &temp_color); |
| 922 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = temp_color; | 926 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = temp_color; |
| 923 #else | 927 #else |
| 924 auto set_frame_color = [this](int color_id) { | 928 // TODO(thomasanderson): Render a GtkHeaderBar directly. |
| 925 // Render a GtkHeaderBar as our title bar, cropping out any curved edges | 929 SkColor color_frame = GetBGColor(".headerbar.header-bar.titlebar"); |
| 926 // on the left and right sides. Also remove the bottom border for good | 930 SkColor color_frame_inactive = |
| 927 // measure. | 931 GetBGColor(".headerbar.header-bar.titlebar:backdrop"); |
| 928 SkBitmap bitmap; | 932 colors_[ThemeProperties::COLOR_FRAME] = color_frame; |
| 929 bitmap.allocN32Pixels(1, 1); | 933 colors_[ThemeProperties::COLOR_FRAME_INACTIVE] = color_frame_inactive; |
| 930 bitmap.eraseColor(0); | 934 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO] = |
| 931 | 935 color_utils::HSLShift(color_frame, kDefaultTintFrameIncognito); |
| 932 static GtkWidget* menu = nullptr; | 936 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = |
| 933 if (!menu) { | 937 color_utils::HSLShift(color_frame_inactive, kDefaultTintFrameIncognito); |
| 934 menu = gtk_menu_bar_new(); | |
| 935 gtk_widget_set_size_request(menu, 1, 1); | |
| 936 | |
| 937 GtkWidget* window = gtk_offscreen_window_new(); | |
| 938 gtk_container_add(GTK_CONTAINER(window), menu); | |
| 939 | |
| 940 gtk_widget_show_all(window); | |
| 941 } | |
| 942 | |
| 943 cairo_surface_t* surface = cairo_image_surface_create_for_data( | |
| 944 static_cast<unsigned char*>(bitmap.getAddr(0, 0)), CAIRO_FORMAT_ARGB32, | |
| 945 bitmap.width(), bitmap.height(), | |
| 946 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, 1)); | |
| 947 cairo_t* cr = cairo_create(surface); | |
| 948 gtk_widget_draw(menu, cr); | |
| 949 cairo_destroy(cr); | |
| 950 cairo_surface_destroy(surface); | |
| 951 | |
| 952 switch (color_id) { | |
| 953 case ThemeProperties::COLOR_FRAME_INACTIVE: | |
| 954 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( | |
| 955 bitmap, kDefaultTintFrameInactive); | |
| 956 break; | |
| 957 case ThemeProperties::COLOR_FRAME_INCOGNITO: | |
| 958 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( | |
| 959 bitmap, kDefaultTintFrameIncognito); | |
| 960 break; | |
| 961 case ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE: | |
| 962 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( | |
| 963 bitmap, kDefaultTintFrameIncognitoInactive); | |
| 964 break; | |
| 965 } | |
| 966 | |
| 967 bitmap.lockPixels(); | |
| 968 colors_[color_id] = bitmap.getColor(0, 0); | |
| 969 bitmap.unlockPixels(); | |
| 970 }; | |
| 971 | |
| 972 set_frame_color(ThemeProperties::COLOR_FRAME); | |
| 973 set_frame_color(ThemeProperties::COLOR_FRAME_INACTIVE); | |
| 974 set_frame_color(ThemeProperties::COLOR_FRAME_INCOGNITO); | |
| 975 set_frame_color(ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE); | |
| 976 #endif | 938 #endif |
| 977 } | 939 } |
| 978 | 940 |
| 979 void Gtk2UI::GetNormalButtonTintHSL(color_utils::HSL* tint) const { | 941 void Gtk2UI::GetNormalButtonTintHSL(color_utils::HSL* tint) const { |
| 980 SkColor accent_color = native_theme_->GetSystemColor( | 942 SkColor accent_color = native_theme_->GetSystemColor( |
| 981 ui::NativeTheme::kColorId_ProminentButtonColor); | 943 ui::NativeTheme::kColorId_ProminentButtonColor); |
| 982 SkColor text_color = native_theme_->GetSystemColor( | 944 SkColor text_color = native_theme_->GetSystemColor( |
| 983 ui::NativeTheme::kColorId_LabelEnabledColor); | 945 ui::NativeTheme::kColorId_LabelEnabledColor); |
| 984 SkColor base_color = | 946 SkColor base_color = |
| 985 native_theme_->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); | 947 native_theme_->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 | 1047 |
| 1086 float Gtk2UI::GetDeviceScaleFactor() const { | 1048 float Gtk2UI::GetDeviceScaleFactor() const { |
| 1087 return device_scale_factor_; | 1049 return device_scale_factor_; |
| 1088 } | 1050 } |
| 1089 | 1051 |
| 1090 } // namespace libgtkui | 1052 } // namespace libgtkui |
| 1091 | 1053 |
| 1092 views::LinuxUI* BuildGtk2UI() { | 1054 views::LinuxUI* BuildGtk2UI() { |
| 1093 return new libgtkui::Gtk2UI; | 1055 return new libgtkui::Gtk2UI; |
| 1094 } | 1056 } |
| OLD | NEW |