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

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

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