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

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

Issue 1878973002: [reland] Makes MaterialDesignController initialization explicit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made it possible to restore MaterialDesignController state after each test case (nits) Created 4 years, 8 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/startup/bad_flags_prompt.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 <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 // We must build this after GTK gets initialized. 509 // We must build this after GTK gets initialized.
510 gconf_listener_.reset(new GConfListener(this)); 510 gconf_listener_.reset(new GConfListener(this));
511 #endif // defined(USE_GCONF) 511 #endif // defined(USE_GCONF)
512 512
513 indicators_count = 0; 513 indicators_count = 0;
514 514
515 // Instantiate the singleton instance of Gtk2EventLoop. 515 // Instantiate the singleton instance of Gtk2EventLoop.
516 Gtk2EventLoop::GetInstance(); 516 Gtk2EventLoop::GetInstance();
517 } 517 }
518 518
519 void Gtk2UI::MaterialDesignControllerReady() {
520 UpdateMaterialDesignColors();
521 }
522
519 Gtk2UI::~Gtk2UI() { 523 Gtk2UI::~Gtk2UI() {
520 ClearAllThemeData(); 524 ClearAllThemeData();
521 } 525 }
522 526
523 gfx::Image Gtk2UI::GetThemeImageNamed(int id) const { 527 gfx::Image Gtk2UI::GetThemeImageNamed(int id) const {
524 // Try to get our cached version: 528 // Try to get our cached version:
525 ImageCache::const_iterator it = gtk_images_.find(id); 529 ImageCache::const_iterator it = gtk_images_.find(id);
526 if (it != gtk_images_.end()) 530 if (it != gtk_images_.end())
527 return it->second; 531 return it->second;
528 532
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 colors_[ThemeProperties::COLOR_BOOKMARK_TEXT] = label_color; 897 colors_[ThemeProperties::COLOR_BOOKMARK_TEXT] = label_color;
894 898
895 UpdateDefaultFont(); 899 UpdateDefaultFont();
896 900
897 // Build the various icon tints. 901 // Build the various icon tints.
898 GetNormalButtonTintHSL(&button_tint_); 902 GetNormalButtonTintHSL(&button_tint_);
899 GetNormalEntryForegroundHSL(&entry_tint_); 903 GetNormalEntryForegroundHSL(&entry_tint_);
900 GetSelectedEntryForegroundHSL(&selected_entry_tint_); 904 GetSelectedEntryForegroundHSL(&selected_entry_tint_);
901 SkColor frame_color = BuildFrameColors(); 905 SkColor frame_color = BuildFrameColors();
902 906
903 if (ui::MaterialDesignController::IsModeMaterial()) { 907 // The inactive frame color never occurs naturally in the theme, as it is a
904 colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] = 908 // tinted version of |frame_color|. We generate another color based on the
905 color_utils::BlendTowardOppositeLuma(label_color, 50); 909 // background tab color, with the lightness and saturation moved in the
906 } else { 910 // opposite direction. (We don't touch the hue, since there should be subtle
907 // The inactive frame color never occurs naturally in the theme, as it is a 911 // hints of the color in the text.)
908 // tinted version of |frame_color|. We generate another color based on the 912 color_utils::HSL inactive_tab_text_hsl;
909 // background tab color, with the lightness and saturation moved in the 913 color_utils::SkColorToHSL(
910 // opposite direction. (We don't touch the hue, since there should be subtle 914 theme->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground),
911 // hints of the color in the text.) 915 &inactive_tab_text_hsl);
912 color_utils::HSL inactive_tab_text_hsl; 916 inactive_tab_text_hsl.s = kInactiveLuminance;
913 color_utils::SkColorToHSL( 917 inactive_tab_text_hsl.l = kInactiveSaturation;
914 theme->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground),
915 &inactive_tab_text_hsl);
916 inactive_tab_text_hsl.s = kInactiveLuminance;
917 inactive_tab_text_hsl.l = kInactiveSaturation;
918 918
919 colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] = 919 colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] =
920 color_utils::HSLToSkColor(inactive_tab_text_hsl, 255); 920 color_utils::HSLToSkColor(inactive_tab_text_hsl, 255);
921 }
922 921
923 // We pick the text and background colors for the NTP out of the colors for a 922 // We pick the text and background colors for the NTP out of the colors for a
924 // GtkEntry. We do this because GtkEntries background color is never the same 923 // GtkEntry. We do this because GtkEntries background color is never the same
925 // as |toolbar_color|, is usually a white, and when it isn't a white, 924 // as |toolbar_color|, is usually a white, and when it isn't a white,
926 // provides sufficient contrast to |toolbar_color|. Try this out with 925 // provides sufficient contrast to |toolbar_color|. Try this out with
927 // Darklooks, HighContrastInverse or ThinIce. 926 // Darklooks, HighContrastInverse or ThinIce.
928 927
929 SkColor ntp_background = 928 SkColor ntp_background =
930 theme->GetSystemColor( 929 theme->GetSystemColor(
931 ui::NativeTheme::kColorId_TextfieldDefaultBackground); 930 ui::NativeTheme::kColorId_TextfieldDefaultBackground);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 inactive_selection_fg_color_ = 971 inactive_selection_fg_color_ =
973 theme->GetSystemColor( 972 theme->GetSystemColor(
974 ui::NativeTheme::kColorId_TextfieldReadOnlyColor); 973 ui::NativeTheme::kColorId_TextfieldReadOnlyColor);
975 974
976 colors_[ThemeProperties::COLOR_TAB_THROBBER_SPINNING] = 975 colors_[ThemeProperties::COLOR_TAB_THROBBER_SPINNING] =
977 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberSpinningColor); 976 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberSpinningColor);
978 colors_[ThemeProperties::COLOR_TAB_THROBBER_WAITING] = 977 colors_[ThemeProperties::COLOR_TAB_THROBBER_WAITING] =
979 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberWaitingColor); 978 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberWaitingColor);
980 } 979 }
981 980
981 void Gtk2UI::UpdateMaterialDesignColors() {
982 // TODO(varkha): This should be merged back into LoadGtkValues() once Material
983 // Design is on unconditionally.
984 if (ui::MaterialDesignController::IsModeMaterial()) {
985 NativeThemeGtk2* theme = NativeThemeGtk2::instance();
986 SkColor label_color =
987 theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor);
988 colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] =
989 color_utils::BlendTowardOppositeLuma(label_color, 50);
990 }
991 }
992
982 SkColor Gtk2UI::BuildFrameColors() { 993 SkColor Gtk2UI::BuildFrameColors() {
983 NativeThemeGtk2* theme = NativeThemeGtk2::instance(); 994 NativeThemeGtk2* theme = NativeThemeGtk2::instance();
984 SkColor frame_color = 995 SkColor frame_color =
985 theme->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground); 996 theme->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground);
986 SkColor temp_color; 997 SkColor temp_color;
987 998
988 #if GTK_MAJOR_VERSION == 2 999 #if GTK_MAJOR_VERSION == 2
989 color_utils::HSL kDefaultFrameShift = { -1, -1, 0.4 }; 1000 color_utils::HSL kDefaultFrameShift = { -1, -1, 0.4 };
990 GtkStyle* style = gtk_rc_get_style(theme->GetWindow()); 1001 GtkStyle* style = gtk_rc_get_style(theme->GetWindow());
991 1002
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 query.style |= gfx::Font::ITALIC; 1363 query.style |= gfx::Font::ITALIC;
1353 1364
1354 default_font_render_params_ = 1365 default_font_render_params_ =
1355 gfx::GetFontRenderParams(query, &default_font_family_); 1366 gfx::GetFontRenderParams(query, &default_font_family_);
1356 default_font_style_ = query.style; 1367 default_font_style_ = query.style;
1357 } 1368 }
1358 1369
1359 void Gtk2UI::ResetStyle() { 1370 void Gtk2UI::ResetStyle() {
1360 ClearAllThemeData(); 1371 ClearAllThemeData();
1361 LoadGtkValues(); 1372 LoadGtkValues();
1373 // TODO(varkha): There will be no need to call UpdateMaterialDesignColors()
1374 // once Material Design is on unconditionally.
1375 UpdateMaterialDesignColors();
1362 NativeThemeGtk2::instance()->NotifyObservers(); 1376 NativeThemeGtk2::instance()->NotifyObservers();
1363 } 1377 }
1364 1378
1365 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { 1379 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) {
1366 device_scale_factor_ = device_scale_factor; 1380 device_scale_factor_ = device_scale_factor;
1367 UpdateDefaultFont(); 1381 UpdateDefaultFont();
1368 } 1382 }
1369 1383
1370 float Gtk2UI::GetDeviceScaleFactor() const { 1384 float Gtk2UI::GetDeviceScaleFactor() const {
1371 if (gfx::Display::HasForceDeviceScaleFactor()) 1385 if (gfx::Display::HasForceDeviceScaleFactor())
1372 return gfx::Display::GetForcedDeviceScaleFactor(); 1386 return gfx::Display::GetForcedDeviceScaleFactor();
1373 const int kCSSDefaultDPI = 96; 1387 const int kCSSDefaultDPI = 96;
1374 const float scale = GetDPI() / kCSSDefaultDPI; 1388 const float scale = GetDPI() / kCSSDefaultDPI;
1375 1389
1376 // Blacklist scaling factors <130% (crbug.com/484400) and round 1390 // Blacklist scaling factors <130% (crbug.com/484400) and round
1377 // to 1 decimal to prevent rendering problems (crbug.com/485183). 1391 // to 1 decimal to prevent rendering problems (crbug.com/485183).
1378 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; 1392 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10;
1379 } 1393 }
1380 1394
1381 } // namespace libgtk2ui 1395 } // namespace libgtk2ui
1382 1396
1383 views::LinuxUI* BuildGtk2UI() { 1397 views::LinuxUI* BuildGtk2UI() {
1384 return new libgtk2ui::Gtk2UI; 1398 return new libgtk2ui::Gtk2UI;
1385 } 1399 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtk2ui/gtk2_ui.h ('k') | chrome/browser/ui/startup/bad_flags_prompt.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698