Chromium Code Reviews| 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 <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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::UpdateWithLocalState() { | |
| 520 UpdateColors(); | |
| 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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 colors_[ThemeProperties::COLOR_BOOKMARK_TEXT] = label_color; | 898 colors_[ThemeProperties::COLOR_BOOKMARK_TEXT] = label_color; |
| 895 | 899 |
| 896 UpdateDefaultFont(); | 900 UpdateDefaultFont(); |
| 897 | 901 |
| 898 // Build the various icon tints. | 902 // Build the various icon tints. |
| 899 GetNormalButtonTintHSL(&button_tint_); | 903 GetNormalButtonTintHSL(&button_tint_); |
| 900 GetNormalEntryForegroundHSL(&entry_tint_); | 904 GetNormalEntryForegroundHSL(&entry_tint_); |
| 901 GetSelectedEntryForegroundHSL(&selected_entry_tint_); | 905 GetSelectedEntryForegroundHSL(&selected_entry_tint_); |
| 902 SkColor frame_color = BuildFrameColors(); | 906 SkColor frame_color = BuildFrameColors(); |
| 903 | 907 |
| 904 if (ui::MaterialDesignController::IsModeMaterial()) { | 908 // The inactive frame color never occurs naturally in the theme, as it is a |
| 905 colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] = | 909 // tinted version of |frame_color|. We generate another color based on the |
| 906 color_utils::BlendTowardOppositeLuma(label_color, 50); | 910 // background tab color, with the lightness and saturation moved in the |
| 907 } else { | 911 // opposite direction. (We don't touch the hue, since there should be subtle |
| 908 // The inactive frame color never occurs naturally in the theme, as it is a | 912 // hints of the color in the text.) |
| 909 // tinted version of |frame_color|. We generate another color based on the | 913 color_utils::HSL inactive_tab_text_hsl; |
| 910 // background tab color, with the lightness and saturation moved in the | 914 color_utils::SkColorToHSL( |
| 911 // opposite direction. (We don't touch the hue, since there should be subtle | 915 theme->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground), |
| 912 // hints of the color in the text.) | 916 &inactive_tab_text_hsl); |
| 913 color_utils::HSL inactive_tab_text_hsl; | 917 inactive_tab_text_hsl.s = kInactiveLuminance; |
| 914 color_utils::SkColorToHSL( | 918 inactive_tab_text_hsl.l = kInactiveSaturation; |
| 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 } | |
| 923 | 922 |
| 924 // We pick the text and background colors for the NTP out of the colors for a | 923 // We pick the text and background colors for the NTP out of the colors for a |
| 925 // GtkEntry. We do this because GtkEntries background color is never the same | 924 // GtkEntry. We do this because GtkEntries background color is never the same |
| 926 // as |toolbar_color|, is usually a white, and when it isn't a white, | 925 // as |toolbar_color|, is usually a white, and when it isn't a white, |
| 927 // provides sufficient contrast to |toolbar_color|. Try this out with | 926 // provides sufficient contrast to |toolbar_color|. Try this out with |
| 928 // Darklooks, HighContrastInverse or ThinIce. | 927 // Darklooks, HighContrastInverse or ThinIce. |
| 929 | 928 |
| 930 SkColor ntp_background = | 929 SkColor ntp_background = |
| 931 theme->GetSystemColor( | 930 theme->GetSystemColor( |
| 932 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | 931 ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 inactive_selection_fg_color_ = | 972 inactive_selection_fg_color_ = |
| 974 theme->GetSystemColor( | 973 theme->GetSystemColor( |
| 975 ui::NativeTheme::kColorId_TextfieldReadOnlyColor); | 974 ui::NativeTheme::kColorId_TextfieldReadOnlyColor); |
| 976 | 975 |
| 977 colors_[ThemeProperties::COLOR_TAB_THROBBER_SPINNING] = | 976 colors_[ThemeProperties::COLOR_TAB_THROBBER_SPINNING] = |
| 978 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberSpinningColor); | 977 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberSpinningColor); |
| 979 colors_[ThemeProperties::COLOR_TAB_THROBBER_WAITING] = | 978 colors_[ThemeProperties::COLOR_TAB_THROBBER_WAITING] = |
| 980 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberWaitingColor); | 979 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberWaitingColor); |
| 981 } | 980 } |
| 982 | 981 |
| 982 void Gtk2UI::UpdateColors() { | |
| 983 if (ui::MaterialDesignController::IsModeMaterial()) { | |
| 984 NativeThemeGtk2* theme = NativeThemeGtk2::instance(); | |
| 985 SkColor label_color = | |
| 986 theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor); | |
| 987 colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] = | |
| 988 color_utils::BlendTowardOppositeLuma(label_color, 50); | |
| 989 } | |
| 990 } | |
| 991 | |
| 983 SkColor Gtk2UI::BuildFrameColors() { | 992 SkColor Gtk2UI::BuildFrameColors() { |
| 984 NativeThemeGtk2* theme = NativeThemeGtk2::instance(); | 993 NativeThemeGtk2* theme = NativeThemeGtk2::instance(); |
| 985 SkColor frame_color = | 994 SkColor frame_color = |
| 986 theme->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground); | 995 theme->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground); |
| 987 SkColor temp_color; | 996 SkColor temp_color; |
| 988 | 997 |
| 989 #if GTK_MAJOR_VERSION == 2 | 998 #if GTK_MAJOR_VERSION == 2 |
| 990 color_utils::HSL kDefaultFrameShift = { -1, -1, 0.4 }; | 999 color_utils::HSL kDefaultFrameShift = { -1, -1, 0.4 }; |
| 991 GtkStyle* style = gtk_rc_get_style(theme->GetWindow()); | 1000 GtkStyle* style = gtk_rc_get_style(theme->GetWindow()); |
| 992 | 1001 |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1352 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) | 1361 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) |
| 1353 query.style |= gfx::Font::ITALIC; | 1362 query.style |= gfx::Font::ITALIC; |
| 1354 | 1363 |
| 1355 default_font_render_params_ = | 1364 default_font_render_params_ = |
| 1356 gfx::GetFontRenderParams(query, &default_font_family_); | 1365 gfx::GetFontRenderParams(query, &default_font_family_); |
| 1357 default_font_style_ = query.style; | 1366 default_font_style_ = query.style; |
| 1358 } | 1367 } |
| 1359 | 1368 |
| 1360 void Gtk2UI::ResetStyle() { | 1369 void Gtk2UI::ResetStyle() { |
| 1361 ClearAllThemeData(); | 1370 ClearAllThemeData(); |
| 1362 LoadGtkValues(); | 1371 LoadGtkValues(); |
|
Evan Stade
2016/04/01 23:24:18
wouldn't you have to UpdateColors here to?
I'm no
varkha
2016/04/01 23:55:40
Yes I would.
| |
| 1363 NativeThemeGtk2::instance()->NotifyObservers(); | 1372 NativeThemeGtk2::instance()->NotifyObservers(); |
| 1364 } | 1373 } |
| 1365 | 1374 |
| 1366 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { | 1375 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { |
| 1367 device_scale_factor_ = device_scale_factor; | 1376 device_scale_factor_ = device_scale_factor; |
| 1368 UpdateDefaultFont(); | 1377 UpdateDefaultFont(); |
| 1369 } | 1378 } |
| 1370 | 1379 |
| 1371 float Gtk2UI::GetDeviceScaleFactor() const { | 1380 float Gtk2UI::GetDeviceScaleFactor() const { |
| 1372 if (gfx::Display::HasForceDeviceScaleFactor()) | 1381 if (gfx::Display::HasForceDeviceScaleFactor()) |
| 1373 return gfx::Display::GetForcedDeviceScaleFactor(); | 1382 return gfx::Display::GetForcedDeviceScaleFactor(); |
| 1374 const int kCSSDefaultDPI = 96; | 1383 const int kCSSDefaultDPI = 96; |
| 1375 const float scale = GetDPI() / kCSSDefaultDPI; | 1384 const float scale = GetDPI() / kCSSDefaultDPI; |
| 1376 | 1385 |
| 1377 // Blacklist scaling factors <130% (crbug.com/484400) and round | 1386 // Blacklist scaling factors <130% (crbug.com/484400) and round |
| 1378 // to 1 decimal to prevent rendering problems (crbug.com/485183). | 1387 // to 1 decimal to prevent rendering problems (crbug.com/485183). |
| 1379 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; | 1388 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; |
| 1380 } | 1389 } |
| 1381 | 1390 |
| 1382 } // namespace libgtk2ui | 1391 } // namespace libgtk2ui |
| 1383 | 1392 |
| 1384 views::LinuxUI* BuildGtk2UI() { | 1393 views::LinuxUI* BuildGtk2UI() { |
| 1385 return new libgtk2ui::Gtk2UI; | 1394 return new libgtk2ui::Gtk2UI; |
| 1386 } | 1395 } |
| OLD | NEW |