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

Side by Side Diff: chrome/browser/ui/libgtk2ui/gtk2_ui.cc

Issue 2401363005: Remove sundry IsModeMaterial checks. (Closed)
Patch Set: resolve merge conflict Created 4 years, 2 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/libgtk2ui/gtk2_ui.h ('k') | chrome/browser/ui/tabs/tab_utils.cc » ('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/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 22 matching lines...) Expand all
33 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h" 33 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h"
34 #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" 34 #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h"
35 #include "chrome/browser/ui/libgtk2ui/unity_service.h" 35 #include "chrome/browser/ui/libgtk2ui/unity_service.h"
36 #include "chrome/browser/ui/libgtk2ui/x11_input_method_context_impl_gtk2.h" 36 #include "chrome/browser/ui/libgtk2ui/x11_input_method_context_impl_gtk2.h"
37 #include "chrome/grit/theme_resources.h" 37 #include "chrome/grit/theme_resources.h"
38 #include "components/grit/components_scaled_resources.h" 38 #include "components/grit/components_scaled_resources.h"
39 #include "third_party/skia/include/core/SkBitmap.h" 39 #include "third_party/skia/include/core/SkBitmap.h"
40 #include "third_party/skia/include/core/SkCanvas.h" 40 #include "third_party/skia/include/core/SkCanvas.h"
41 #include "third_party/skia/include/core/SkColor.h" 41 #include "third_party/skia/include/core/SkColor.h"
42 #include "third_party/skia/include/core/SkShader.h" 42 #include "third_party/skia/include/core/SkShader.h"
43 #include "ui/base/material_design/material_design_controller.h"
44 #include "ui/base/resource/resource_bundle.h" 43 #include "ui/base/resource/resource_bundle.h"
45 #include "ui/display/display.h" 44 #include "ui/display/display.h"
46 #include "ui/gfx/canvas.h" 45 #include "ui/gfx/canvas.h"
47 #include "ui/gfx/geometry/rect.h" 46 #include "ui/gfx/geometry/rect.h"
48 #include "ui/gfx/geometry/size.h" 47 #include "ui/gfx/geometry/size.h"
49 #include "ui/gfx/image/image.h" 48 #include "ui/gfx/image/image.h"
50 #include "ui/gfx/image/image_skia_source.h" 49 #include "ui/gfx/image/image_skia_source.h"
51 #include "ui/gfx/skbitmap_operations.h" 50 #include "ui/gfx/skbitmap_operations.h"
52 #include "ui/gfx/skia_util.h" 51 #include "ui/gfx/skia_util.h"
53 #include "ui/gfx/x/x11_types.h" 52 #include "ui/gfx/x/x11_types.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 220
222 // Prefix for app indicator ids 221 // Prefix for app indicator ids
223 const char kAppIndicatorIdPrefix[] = "chrome_app_indicator_"; 222 const char kAppIndicatorIdPrefix[] = "chrome_app_indicator_";
224 223
225 // Number of app indicators used (used as part of app-indicator id). 224 // Number of app indicators used (used as part of app-indicator id).
226 int indicators_count; 225 int indicators_count;
227 226
228 // The unknown content type. 227 // The unknown content type.
229 const char* kUnknownContentType = "application/octet-stream"; 228 const char* kUnknownContentType = "application/octet-stream";
230 229
231 // Values used as the new luminance and saturation values in the inactive tab
232 // text color.
233 const double kInactiveLuminance = 0.15;
234 const double kInactiveSaturation = 0.3;
235
236 // TODO(erg): ThemeService has a whole interface just for reading default 230 // TODO(erg): ThemeService has a whole interface just for reading default
237 // 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
238 // copy the constants themselves here. 232 // copy the constants themselves here.
239 // 233 //
240 // Default tints. 234 // Default tints.
241 const color_utils::HSL kDefaultTintFrameIncognito = { -1, 0.2f, 0.35f }; 235 const color_utils::HSL kDefaultTintFrameIncognito = { -1, 0.2f, 0.35f };
242 const color_utils::HSL kDefaultTintFrameIncognitoInactive = { -1, 0.3f, 0.6f }; 236 const color_utils::HSL kDefaultTintFrameIncognitoInactive = { -1, 0.3f, 0.6f };
243 237
244 #if GTK_MAJOR_VERSION == 3 238 #if GTK_MAJOR_VERSION == 3
245 const color_utils::HSL kDefaultTintFrameInactive = { -1, -1, 0.75f }; 239 const color_utils::HSL kDefaultTintFrameInactive = { -1, -1, 0.75f };
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 // We must build this after GTK gets initialized. 454 // We must build this after GTK gets initialized.
461 gconf_listener_.reset(new GConfListener(this)); 455 gconf_listener_.reset(new GConfListener(this));
462 #endif // defined(USE_GCONF) 456 #endif // defined(USE_GCONF)
463 457
464 indicators_count = 0; 458 indicators_count = 0;
465 459
466 // Instantiate the singleton instance of Gtk2EventLoop. 460 // Instantiate the singleton instance of Gtk2EventLoop.
467 Gtk2EventLoop::GetInstance(); 461 Gtk2EventLoop::GetInstance();
468 } 462 }
469 463
470 void Gtk2UI::MaterialDesignControllerReady() {
471 UpdateMaterialDesignColors();
472 }
473
474 bool Gtk2UI::GetTint(int id, color_utils::HSL* tint) const { 464 bool Gtk2UI::GetTint(int id, color_utils::HSL* tint) const {
475 switch (id) { 465 switch (id) {
476 // Tints for which the cross-platform default is fine. Before adding new 466 // Tints for which the cross-platform default is fine. Before adding new
477 // values here, specifically verify they work well on Linux. 467 // values here, specifically verify they work well on Linux.
478 case ThemeProperties::TINT_BACKGROUND_TAB: 468 case ThemeProperties::TINT_BACKGROUND_TAB:
479 // TODO(estade): Return something useful for TINT_BUTTONS so that chrome:// 469 // TODO(estade): Return something useful for TINT_BUTTONS so that chrome://
480 // page icons are colored appropriately. 470 // page icons are colored appropriately.
481 case ThemeProperties::TINT_BUTTONS: 471 case ThemeProperties::TINT_BUTTONS:
482 break; 472 break;
483 default: 473 default:
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor); 808 theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor);
819 809
820 colors_[ThemeProperties::COLOR_CONTROL_BACKGROUND] = toolbar_color; 810 colors_[ThemeProperties::COLOR_CONTROL_BACKGROUND] = toolbar_color;
821 colors_[ThemeProperties::COLOR_TOOLBAR] = toolbar_color; 811 colors_[ThemeProperties::COLOR_TOOLBAR] = toolbar_color;
822 812
823 colors_[ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON] = 813 colors_[ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON] =
824 color_utils::DeriveDefaultIconColor(label_color); 814 color_utils::DeriveDefaultIconColor(label_color);
825 815
826 colors_[ThemeProperties::COLOR_TAB_TEXT] = label_color; 816 colors_[ThemeProperties::COLOR_TAB_TEXT] = label_color;
827 colors_[ThemeProperties::COLOR_BOOKMARK_TEXT] = label_color; 817 colors_[ThemeProperties::COLOR_BOOKMARK_TEXT] = label_color;
818 colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] =
819 color_utils::BlendTowardOppositeLuma(label_color, 50);
828 820
829 UpdateDefaultFont(); 821 UpdateDefaultFont();
830 822
831 // Build the various icon tints. 823 // Build the various icon tints.
832 GetNormalButtonTintHSL(&button_tint_); 824 GetNormalButtonTintHSL(&button_tint_);
833 GetNormalEntryForegroundHSL(&entry_tint_); 825 GetNormalEntryForegroundHSL(&entry_tint_);
834 GetSelectedEntryForegroundHSL(&selected_entry_tint_); 826 GetSelectedEntryForegroundHSL(&selected_entry_tint_);
835 827
836 // The inactive frame color never occurs naturally in the theme, as it is a
837 // tinted version of the normal frame color. We generate another color based
838 // on the background tab color, with the lightness and saturation moved in the
839 // opposite direction. (We don't touch the hue, since there should be subtle
840 // hints of the color in the text.)
841 color_utils::HSL inactive_tab_text_hsl;
842 color_utils::SkColorToHSL(
843 theme->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground),
844 &inactive_tab_text_hsl);
845 inactive_tab_text_hsl.s = kInactiveLuminance;
846 inactive_tab_text_hsl.l = kInactiveSaturation;
847
848 colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] =
849 color_utils::HSLToSkColor(inactive_tab_text_hsl, 255);
850
851 // We pick the text and background colors for the NTP out of the colors for a 828 // We pick the text and background colors for the NTP out of the colors for a
852 // GtkEntry. We do this because GtkEntries background color is never the same 829 // GtkEntry. We do this because GtkEntries background color is never the same
853 // as |toolbar_color|, is usually a white, and when it isn't a white, 830 // as |toolbar_color|, is usually a white, and when it isn't a white,
854 // provides sufficient contrast to |toolbar_color|. Try this out with 831 // provides sufficient contrast to |toolbar_color|. Try this out with
855 // Darklooks, HighContrastInverse or ThinIce. 832 // Darklooks, HighContrastInverse or ThinIce.
856 833
857 SkColor ntp_background = 834 SkColor ntp_background =
858 theme->GetSystemColor( 835 theme->GetSystemColor(
859 ui::NativeTheme::kColorId_TextfieldDefaultBackground); 836 ui::NativeTheme::kColorId_TextfieldDefaultBackground);
860 SkColor ntp_foreground = 837 SkColor ntp_foreground =
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 nullptr); 897 nullptr);
921 898
922 if (theme) 899 if (theme)
923 XcursorSetTheme(gfx::GetXDisplay(), theme); 900 XcursorSetTheme(gfx::GetXDisplay(), theme);
924 if (size) 901 if (size)
925 XcursorSetDefaultSize(gfx::GetXDisplay(), size); 902 XcursorSetDefaultSize(gfx::GetXDisplay(), size);
926 903
927 g_free(theme); 904 g_free(theme);
928 } 905 }
929 906
930 void Gtk2UI::UpdateMaterialDesignColors() {
931 // TODO(varkha): This should be merged back into LoadGtkValues() once Material
932 // Design is on unconditionally.
933 // Early return when Material Design Controller is not initialized yet. This
934 // is harmless and the colors will get updated when this method is called
935 // again after the initialization. See http://crbug.com/622234.
936 if (!ui::MaterialDesignController::is_mode_initialized() ||
937 !ui::MaterialDesignController::IsModeMaterial()) {
938 return;
939 }
940 NativeThemeGtk2* theme = NativeThemeGtk2::instance();
941 SkColor label_color =
942 theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor);
943 colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] =
944 color_utils::BlendTowardOppositeLuma(label_color, 50);
945 }
946
947 void Gtk2UI::BuildFrameColors() { 907 void Gtk2UI::BuildFrameColors() {
948 #if GTK_MAJOR_VERSION == 2 908 #if GTK_MAJOR_VERSION == 2
949 NativeThemeGtk2* theme = NativeThemeGtk2::instance(); 909 NativeThemeGtk2* theme = NativeThemeGtk2::instance();
950 color_utils::HSL kDefaultFrameShift = { -1, -1, 0.4 }; 910 color_utils::HSL kDefaultFrameShift = { -1, -1, 0.4 };
951 SkColor frame_color = 911 SkColor frame_color =
952 theme->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground); 912 theme->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground);
953 frame_color = color_utils::HSLShift(frame_color, kDefaultFrameShift); 913 frame_color = color_utils::HSLShift(frame_color, kDefaultFrameShift);
954 theme->GetChromeStyleColor("frame-color", &frame_color); 914 theme->GetChromeStyleColor("frame-color", &frame_color);
955 colors_[ThemeProperties::COLOR_FRAME] = frame_color; 915 colors_[ThemeProperties::COLOR_FRAME] = frame_color;
956 916
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) 1064 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC)
1105 query.style |= gfx::Font::ITALIC; 1065 query.style |= gfx::Font::ITALIC;
1106 1066
1107 default_font_render_params_ = 1067 default_font_render_params_ =
1108 gfx::GetFontRenderParams(query, &default_font_family_); 1068 gfx::GetFontRenderParams(query, &default_font_family_);
1109 default_font_style_ = query.style; 1069 default_font_style_ = query.style;
1110 } 1070 }
1111 1071
1112 void Gtk2UI::ResetStyle() { 1072 void Gtk2UI::ResetStyle() {
1113 LoadGtkValues(); 1073 LoadGtkValues();
1114 // TODO(varkha): There will be no need to call UpdateMaterialDesignColors()
1115 // once Material Design is on unconditionally.
1116 UpdateMaterialDesignColors();
1117 NativeThemeGtk2::instance()->NotifyObservers(); 1074 NativeThemeGtk2::instance()->NotifyObservers();
1118 } 1075 }
1119 1076
1120 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { 1077 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) {
1121 device_scale_factor_ = device_scale_factor; 1078 device_scale_factor_ = device_scale_factor;
1122 UpdateDefaultFont(); 1079 UpdateDefaultFont();
1123 } 1080 }
1124 1081
1125 float Gtk2UI::GetDeviceScaleFactor() const { 1082 float Gtk2UI::GetDeviceScaleFactor() const {
1126 if (display::Display::HasForceDeviceScaleFactor()) 1083 if (display::Display::HasForceDeviceScaleFactor())
1127 return display::Display::GetForcedDeviceScaleFactor(); 1084 return display::Display::GetForcedDeviceScaleFactor();
1128 const int kCSSDefaultDPI = 96; 1085 const int kCSSDefaultDPI = 96;
1129 const float scale = GetDPI() / kCSSDefaultDPI; 1086 const float scale = GetDPI() / kCSSDefaultDPI;
1130 1087
1131 // Blacklist scaling factors <130% (crbug.com/484400) and round 1088 // Blacklist scaling factors <130% (crbug.com/484400) and round
1132 // to 1 decimal to prevent rendering problems (crbug.com/485183). 1089 // to 1 decimal to prevent rendering problems (crbug.com/485183).
1133 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; 1090 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10;
1134 } 1091 }
1135 1092
1136 } // namespace libgtk2ui 1093 } // namespace libgtk2ui
1137 1094
1138 views::LinuxUI* BuildGtk2UI() { 1095 views::LinuxUI* BuildGtk2UI() {
1139 return new libgtk2ui::Gtk2UI; 1096 return new libgtk2ui::Gtk2UI;
1140 } 1097 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtk2ui/gtk2_ui.h ('k') | chrome/browser/ui/tabs/tab_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698