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/libgtk2ui/gtk2_ui.h" | 5 #include "chrome/browser/ui/libgtk2ui/gtk2_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 #include <set> | 10 #include <set> |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 // TODO(erg): ThemeService has a whole interface just for reading default | 230 // TODO(erg): ThemeService has a whole interface just for reading default |
231 // constants. Figure out what to do with that more long term; for now, just | 231 // constants. Figure out what to do with that more long term; for now, just |
232 // copy the constants themselves here. | 232 // copy the constants themselves here. |
233 // | 233 // |
234 // Default tints. | 234 // Default tints. |
235 const color_utils::HSL kDefaultTintFrameIncognito = { -1, 0.2f, 0.35f }; | 235 const color_utils::HSL kDefaultTintFrameIncognito = { -1, 0.2f, 0.35f }; |
236 const color_utils::HSL kDefaultTintFrameIncognitoInactive = { -1, 0.3f, 0.6f }; | 236 const color_utils::HSL kDefaultTintFrameIncognitoInactive = { -1, 0.3f, 0.6f }; |
237 | 237 |
238 #if GTK_MAJOR_VERSION == 3 | 238 #if GTK_MAJOR_VERSION == 3 |
239 const color_utils::HSL kDefaultTintFrameInactive = { -1, -1, 0.75f }; | 239 const color_utils::HSL kDefaultTintFrameInactive = { -1, -1, 0.75f }; |
240 | |
241 // The size of the rendered toolbar image. | |
242 const int kToolbarImageWidth = 64; | |
243 const int kToolbarImageHeight = 128; | |
244 #endif // GTK_MAJOR_VERSION == 3 | 240 #endif // GTK_MAJOR_VERSION == 3 |
245 | 241 |
246 // Picks a button tint from a set of background colors. While | 242 // Picks a button tint from a set of background colors. While |
247 // |accent_color| will usually be the same color through a theme, this | 243 // |accent_color| will usually be the same color through a theme, this |
248 // function will get called with the normal GtkLabel |text_color|/GtkWindow | 244 // function will get called with the normal GtkLabel |text_color|/GtkWindow |
249 // |background_color| pair and the GtkEntry |text_color|/|background_color| | 245 // |background_color| pair and the GtkEntry |text_color|/|background_color| |
250 // pair. While 3/4 of the time the resulting tint will be the same, themes that | 246 // pair. While 3/4 of the time the resulting tint will be the same, themes that |
251 // have a dark window background (with light text) and a light text entry (with | 247 // have a dark window background (with light text) and a light text entry (with |
252 // dark text) will get better icons with this separated out. | 248 // dark text) will get better icons with this separated out. |
253 void PickButtonTintFromColors(SkColor accent_color, | 249 void PickButtonTintFromColors(SkColor accent_color, |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 frame_color, | 926 frame_color, |
931 kDefaultTintFrameIncognitoInactive); | 927 kDefaultTintFrameIncognitoInactive); |
932 theme->GetChromeStyleColor("incognito-inactive-frame-color", &temp_color); | 928 theme->GetChromeStyleColor("incognito-inactive-frame-color", &temp_color); |
933 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = temp_color; | 929 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = temp_color; |
934 #else | 930 #else |
935 auto set_frame_color = [this](int color_id) { | 931 auto set_frame_color = [this](int color_id) { |
936 // Render a GtkHeaderBar as our title bar, cropping out any curved edges | 932 // Render a GtkHeaderBar as our title bar, cropping out any curved edges |
937 // on the left and right sides. Also remove the bottom border for good | 933 // on the left and right sides. Also remove the bottom border for good |
938 // measure. | 934 // measure. |
939 SkBitmap bitmap; | 935 SkBitmap bitmap; |
940 bitmap.allocN32Pixels(kToolbarImageWidth, 40); | 936 bitmap.allocN32Pixels(1, 1); |
941 bitmap.eraseColor(0); | 937 bitmap.eraseColor(0); |
942 | 938 |
943 static GtkWidget* title = nullptr; | 939 static GtkWidget* menu = nullptr; |
944 if (!title) { | 940 if (!menu) { |
945 title = gtk_header_bar_new(); | 941 menu = gtk_menu_bar_new(); |
946 gtk_widget_set_size_request(title, kToolbarImageWidth * 2, 48); | 942 gtk_widget_set_size_request(menu, 1, 1); |
947 | 943 |
948 GtkWidget* window = gtk_offscreen_window_new(); | 944 GtkWidget* window = gtk_offscreen_window_new(); |
949 gtk_container_add(GTK_CONTAINER(window), title); | 945 gtk_container_add(GTK_CONTAINER(window), menu); |
950 | 946 |
951 gtk_widget_show_all(window); | 947 gtk_widget_show_all(window); |
952 } | 948 } |
953 | 949 |
954 cairo_surface_t* surface = cairo_image_surface_create_for_data( | 950 cairo_surface_t* surface = cairo_image_surface_create_for_data( |
955 static_cast<unsigned char*>(bitmap.getAddr(0, 0)), CAIRO_FORMAT_ARGB32, | 951 static_cast<unsigned char*>(bitmap.getAddr(0, 0)), CAIRO_FORMAT_ARGB32, |
956 bitmap.width(), bitmap.height(), bitmap.width() * 4); | 952 bitmap.width(), bitmap.height(), |
| 953 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, 1)); |
957 cairo_t* cr = cairo_create(surface); | 954 cairo_t* cr = cairo_create(surface); |
958 cairo_translate(cr, kToolbarImageWidth / -2, 0); | 955 gtk_widget_draw(menu, cr); |
959 gtk_widget_draw(title, cr); | |
960 cairo_destroy(cr); | 956 cairo_destroy(cr); |
961 cairo_surface_destroy(surface); | 957 cairo_surface_destroy(surface); |
962 | 958 |
963 switch (color_id) { | 959 switch (color_id) { |
964 case ThemeProperties::COLOR_FRAME_INACTIVE: | 960 case ThemeProperties::COLOR_FRAME_INACTIVE: |
965 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( | 961 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( |
966 bitmap, kDefaultTintFrameInactive); | 962 bitmap, kDefaultTintFrameInactive); |
967 break; | 963 break; |
968 case ThemeProperties::COLOR_FRAME_INCOGNITO: | 964 case ThemeProperties::COLOR_FRAME_INCOGNITO: |
969 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( | 965 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( |
970 bitmap, kDefaultTintFrameIncognito); | 966 bitmap, kDefaultTintFrameIncognito); |
971 break; | 967 break; |
972 case ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE: | 968 case ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE: |
973 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( | 969 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( |
974 bitmap, kDefaultTintFrameIncognitoInactive); | 970 bitmap, kDefaultTintFrameIncognitoInactive); |
975 break; | 971 break; |
976 } | 972 } |
977 | 973 |
978 bitmap.lockPixels(); | 974 bitmap.lockPixels(); |
979 colors_[color_id] = | 975 colors_[color_id] = bitmap.getColor(0, 0); |
980 bitmap.getColor(bitmap.width() / 2, bitmap.height() - 1); | |
981 bitmap.unlockPixels(); | 976 bitmap.unlockPixels(); |
982 }; | 977 }; |
983 | 978 |
984 set_frame_color(ThemeProperties::COLOR_FRAME); | 979 set_frame_color(ThemeProperties::COLOR_FRAME); |
985 set_frame_color(ThemeProperties::COLOR_FRAME_INACTIVE); | 980 set_frame_color(ThemeProperties::COLOR_FRAME_INACTIVE); |
986 set_frame_color(ThemeProperties::COLOR_FRAME_INCOGNITO); | 981 set_frame_color(ThemeProperties::COLOR_FRAME_INCOGNITO); |
987 set_frame_color(ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE); | 982 set_frame_color(ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE); |
988 #endif | 983 #endif |
989 } | 984 } |
990 | 985 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 // Blacklist scaling factors <130% (crbug.com/484400) and round | 1082 // Blacklist scaling factors <130% (crbug.com/484400) and round |
1088 // to 1 decimal to prevent rendering problems (crbug.com/485183). | 1083 // to 1 decimal to prevent rendering problems (crbug.com/485183). |
1089 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; | 1084 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; |
1090 } | 1085 } |
1091 | 1086 |
1092 } // namespace libgtk2ui | 1087 } // namespace libgtk2ui |
1093 | 1088 |
1094 views::LinuxUI* BuildGtk2UI() { | 1089 views::LinuxUI* BuildGtk2UI() { |
1095 return new libgtk2ui::Gtk2UI; | 1090 return new libgtk2ui::Gtk2UI; |
1096 } | 1091 } |
OLD | NEW |