diff options
-rw-r--r-- | chrome/browser/resources/ntp4/new_incognito_tab_theme.css | 12 | ||||
-rw-r--r-- | chrome/browser/resources/ntp4/new_tab_theme.css | 56 | ||||
-rwxr-xr-x | chrome/browser/test_presubmit.py | 4 | ||||
-rw-r--r-- | chrome/browser/ui/webui/ntp/ntp_resource_cache.cc | 105 | ||||
-rw-r--r-- | chrome/browser/web_dev_style/css_checker.py | 9 | ||||
-rw-r--r-- | ui/base/BUILD.gn | 3 | ||||
-rw-r--r-- | ui/base/template_expressions.cc | 42 | ||||
-rw-r--r-- | ui/base/template_expressions.h | 28 | ||||
-rw-r--r-- | ui/base/template_expressions_unittest.cc | 36 | ||||
-rw-r--r-- | ui/base/ui_base.gyp | 3 | ||||
-rw-r--r-- | ui/base/ui_base_tests.gyp | 1 | ||||
-rw-r--r-- | ui/base/webui/web_ui_util.cc | 11 | ||||
-rw-r--r-- | ui/webui/resources/css/text_defaults.css | 8 |
13 files changed, 204 insertions, 114 deletions
diff --git a/chrome/browser/resources/ntp4/new_incognito_tab_theme.css b/chrome/browser/resources/ntp4/new_incognito_tab_theme.css index b4d1df1..dd31189 100644 --- a/chrome/browser/resources/ntp4/new_incognito_tab_theme.css +++ b/chrome/browser/resources/ntp4/new_incognito_tab_theme.css @@ -5,18 +5,18 @@ html { background-attachment: fixed; - background-color: $2; - background-image: url(chrome://theme/IDR_THEME_NTP_BACKGROUND?$1); - background-position: $3; - background-repeat: $5; + background-color: ${colorBackground}; + background-image: url(chrome://theme/IDR_THEME_NTP_BACKGROUND?${themeId}); + background-position: ${backgroundBarDetached}; + background-repeat: ${backgroundTiling}; height: 100%; overflow: auto; } #attribution-img { - content: url(chrome://theme/IDR_THEME_NTP_ATTRIBUTION?$1); + content: url(chrome://theme/IDR_THEME_NTP_ATTRIBUTION?${themeId}); } html[bookmarkbarattached='true'] { - background-position: $4; + background-position: ${backgroundBarAttached}; } diff --git a/chrome/browser/resources/ntp4/new_tab_theme.css b/chrome/browser/resources/ntp4/new_tab_theme.css index 52281e8..4b822b5 100644 --- a/chrome/browser/resources/ntp4/new_tab_theme.css +++ b/chrome/browser/resources/ntp4/new_tab_theme.css @@ -4,97 +4,97 @@ html { background-attachment: fixed; - background-color: $2; /* COLOR_NTP_BACKGROUND */ - background-image: url(chrome://theme/IDR_THEME_NTP_BACKGROUND?$1); - background-position: $3; - background-repeat: $5; + background-color: ${colorBackground}; + background-image: url(chrome://theme/IDR_THEME_NTP_BACKGROUND?${themeId}); + background-position: ${backgroundBarDetached}; + background-repeat: ${backgroundTiling}; } #attribution-img { - content: url(chrome://theme/IDR_THEME_NTP_ATTRIBUTION?$1); + content: url(chrome://theme/IDR_THEME_NTP_ATTRIBUTION?${themeId}); } html[bookmarkbarattached='true'] { - background-position: $4; + background-position: ${backgroundBarAttached}; } body { - color: $8; /* COLOR_NTP_TEXT */ + color: ${colorTextRgba}; height: 100%; overflow: auto; } #attribution, [is='action-link'] { - color: $21; /* COLOR_NTP_TEXT_LIGHT */ + color: ${colorTextLight}; } [is='action-link']:active { - color: $8; /* COLOR_NTP_TEXT */ + color: ${colorTextRgba}; } .page-switcher { - color: rgba($23, 0.5); /* COLOR_NTP_TEXT */ + color: rgba(${colorText}, 0.5); } .page-switcher:hover, .page-switcher:focus, .page-switcher.drag-target { - background-color: rgba($23, 0.06); /* COLOR_NTP_TEXT */ + background-color: rgba(${colorText}, 0.06); } /* Only change the background to a gradient when a promo is showing. */ .showing-login-area #page-switcher-end:hover, .showing-login-area #page-switcher-end:focus, .showing-login-area #page-switcher-end.drag-target { - background: - -webkit-linear-gradient(top, rgba($23, 0) 0, - rgba($23, .01) 60px, - rgba($23, .06) 183px); /* COLOR_NTP_TEXT */ + background: linear-gradient(top, + rgba(${colorText}, 0) 0, + rgba(${colorText}, .01) 60px, + rgba(${colorText}, .06) 183px); } .tile-page-scrollbar { - background-color: $21; /* COLOR_NTP_TEXT_LIGHT */ + background-color: ${colorTextLight}; } /* Footer *********************************************************************/ #footer-border { - background: -webkit-linear-gradient(left, - rgba($22, 0.2), /* COLOR_NTP_SECTION_BORDER */ - rgba($22, 0.3) 20%, /* COLOR_NTP_SECTION_BORDER */ - rgba($22, 0.3) 80%, /* COLOR_NTP_SECTION_BORDER */ - rgba($22, 0.2)); /* COLOR_NTP_SECTION_BORDER */ + background: linear-gradient(left, + rgba(${colorSectionBorder}, 0.2), + rgba(${colorSectionBorder}, 0.3) 20%, + rgba(${colorSectionBorder}, 0.3) 80%, + rgba(${colorSectionBorder}, 0.2)); } .dot input:focus { - background-color: $2; /* COLOR_NTP_BACKGROUND */ + background-color: ${colorBackground}; } .bare-minimum #footer { - color: $8; /* COLOR_NTP_TEXT */ + color: ${colorTextRgba}; } .bare-minimum .disclosure-triangle { - background-color: $8; /* COLOR_NTP_TEXT */ + background-color: ${colorTextRgba}; } .bare-minimum .footer-menu-button:hover, .bare-minimum .footer-menu-button[menu-shown], .bare-minimum #chrome-web-store-link:hover { - color: rgba($23, 0.85); /* COLOR_NTP_TEXT */ + color: rgba(${colorText}, 0.85); } .bare-minimum .footer-menu-button:hover .disclosure-triangle, .bare-minimum .footer-menu-button[menu-shown] .disclosure-triangle { - background-color: rgba($23, 0.85); /* COLOR_NTP_TEXT */ + background-color: rgba(${colorText}, 0.85); } .thumbnail-wrapper { /* This shows through at the (rounded) thumbnail's corners. */ - background-color: $11; /* COLOR_NTP_SECTION_BORDER */ + background-color: ${colorSectionBorder}; } .filler .thumbnail { - border-color: $2; /* COLOR_NTP_BACKGROUND */ + border-color: ${colorBackground}; } diff --git a/chrome/browser/test_presubmit.py b/chrome/browser/test_presubmit.py index 1ad8ed2..c4293de 100755 --- a/chrome/browser/test_presubmit.py +++ b/chrome/browser/test_presubmit.py @@ -762,6 +762,10 @@ blah /* hey! */ 100% { height: 500px; } } +#rule { /* ${TemplateExpressions} should be ignored. */ + rule: ${someValue}; +} + #rule { rule: value; }""", """ - Always put a rule closing brace (}) on a new line. diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc index 2724c7d..4514adc 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc @@ -53,6 +53,7 @@ #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/base/template_expressions.h" #include "ui/base/theme_provider.h" #include "ui/base/webui/jstemplate_builder.h" #include "ui/base/webui/web_ui_util.h" @@ -545,17 +546,17 @@ void NTPResourceCache::CreateNewTabIncognitoCSS() { GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND); // Generate the replacements. - std::vector<std::string> subst; + std::map<base::StringPiece, std::string> substitutions; // Cache-buster for background. - subst.push_back( - profile_->GetPrefs()->GetString(prefs::kCurrentThemeID)); // $1 + substitutions["themeId"] = + profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); // Colors. - subst.push_back(SkColorToRGBAString(color_background)); // $2 - subst.push_back(GetNewTabBackgroundCSS(tp, false)); // $3 - subst.push_back(GetNewTabBackgroundCSS(tp, true)); // $4 - subst.push_back(GetNewTabBackgroundTilingCSS(tp)); // $5 + substitutions["colorBackground"] = SkColorToRGBAString(color_background); + substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); + substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); + substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); // Get our template. static const base::StringPiece new_tab_theme_css( @@ -563,8 +564,8 @@ void NTPResourceCache::CreateNewTabIncognitoCSS() { IDR_NEW_INCOGNITO_TAB_THEME_CSS)); // Create the string from our template and the replacements. - std::string full_css = base::ReplaceStringPlaceholders( - new_tab_theme_css, subst, NULL); + std::string full_css = + ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); new_tab_incognito_css_ = base::RefCountedString::TakeString(&full_css); } @@ -578,17 +579,17 @@ void NTPResourceCache::CreateNewTabGuestCSS() { GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND); // Generate the replacements. - std::vector<std::string> subst; + std::map<base::StringPiece, std::string> substitutions; // Cache-buster for background. - subst.push_back( - profile_->GetPrefs()->GetString(prefs::kCurrentThemeID)); // $1 + substitutions["themeId"] = + profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); // Colors. - subst.push_back(SkColorToRGBAString(color_background)); // $2 - subst.push_back(GetNewTabBackgroundCSS(tp, false)); // $3 - subst.push_back(GetNewTabBackgroundCSS(tp, true)); // $4 - subst.push_back(GetNewTabBackgroundTilingCSS(tp)); // $5 + substitutions["colorBackground"] = SkColorToRGBAString(color_background); + substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); + substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); + substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); // Get our template. static const base::StringPiece new_tab_theme_css( @@ -596,8 +597,8 @@ void NTPResourceCache::CreateNewTabGuestCSS() { IDR_NEW_INCOGNITO_TAB_THEME_CSS)); // Create the string from our template and the replacements. - std::string full_css = base::ReplaceStringPlaceholders( - new_tab_theme_css, subst, NULL); + std::string full_css = + ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); new_tab_guest_css_ = base::RefCountedString::TakeString(&full_css); } @@ -610,26 +611,6 @@ void NTPResourceCache::CreateNewTabCSS() { SkColor color_background = GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND); SkColor color_text = GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT); - SkColor color_link = GetThemeColor(tp, ThemeProperties::COLOR_NTP_LINK); - SkColor color_link_underline = - GetThemeColor(tp, ThemeProperties::COLOR_NTP_LINK_UNDERLINE); - - SkColor color_section = - GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION); - SkColor color_section_text = - GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_TEXT); - SkColor color_section_link = - GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_LINK); - SkColor color_section_link_underline = - GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE); - SkColor color_section_header_text = - GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_HEADER_TEXT); - SkColor color_section_header_text_hover = - GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER); - SkColor color_section_header_rule = - GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_HEADER_RULE); - SkColor color_section_header_rule_light = - GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT); SkColor color_text_light = GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT_LIGHT); @@ -639,8 +620,6 @@ void NTPResourceCache::CreateNewTabCSS() { color_utils::HSL header_lighter; color_utils::SkColorToHSL(color_header, &header_lighter); header_lighter.l += (1 - header_lighter.l) * 0.33; - SkColor color_header_gradient_light = - color_utils::HSLToSkColor(header_lighter, SkColorGetA(color_header)); // Generate section border color from the header color. See // BookmarkBarView::Paint for how we do this for the bookmark bar @@ -652,38 +631,24 @@ void NTPResourceCache::CreateNewTabCSS() { SkColorGetB(color_header)); // Generate the replacements. - std::vector<std::string> subst; + std::map<base::StringPiece, std::string> substitutions; // Cache-buster for background. - subst.push_back( - profile_->GetPrefs()->GetString(prefs::kCurrentThemeID)); // $1 + substitutions["themeId"] = + profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); // Colors. - subst.push_back(SkColorToRGBAString(color_background)); // $2 - subst.push_back(GetNewTabBackgroundCSS(tp, false)); // $3 - subst.push_back(GetNewTabBackgroundCSS(tp, true)); // $4 - subst.push_back(GetNewTabBackgroundTilingCSS(tp)); // $5 - subst.push_back(SkColorToRGBAString(color_header)); // $6 - subst.push_back(SkColorToRGBAString(color_header_gradient_light)); // $7 - subst.push_back(SkColorToRGBAString(color_text)); // $8 - subst.push_back(SkColorToRGBAString(color_link)); // $9 - subst.push_back(SkColorToRGBAString(color_section)); // $10 - subst.push_back(SkColorToRGBAString(color_section_border)); // $11 - subst.push_back(SkColorToRGBAString(color_section_text)); // $12 - subst.push_back(SkColorToRGBAString(color_section_link)); // $13 - subst.push_back(SkColorToRGBAString(color_link_underline)); // $14 - subst.push_back(SkColorToRGBAString(color_section_link_underline)); // $15 - subst.push_back(SkColorToRGBAString(color_section_header_text)); // $16 - subst.push_back(SkColorToRGBAString( - color_section_header_text_hover)); // $17 - subst.push_back(SkColorToRGBAString(color_section_header_rule)); // $18 - subst.push_back(SkColorToRGBAString( - color_section_header_rule_light)); // $19 - subst.push_back(SkColorToRGBAString( - SkColorSetA(color_section_header_rule, 0))); // $20 - subst.push_back(SkColorToRGBAString(color_text_light)); // $21 - subst.push_back(SkColorToRGBComponents(color_section_border)); // $22 - subst.push_back(SkColorToRGBComponents(color_text)); // $23 + substitutions["colorBackground"] = SkColorToRGBAString(color_background); + substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); + substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); + substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); + substitutions["colorTextRgba"] = SkColorToRGBAString(color_text); + substitutions["colorSectionBorder"] = + SkColorToRGBAString(color_section_border); + substitutions["colorTextLight"] = SkColorToRGBAString(color_text_light); + substitutions["colorSectionBorder"] = + SkColorToRGBComponents(color_section_border); + substitutions["colorText"] = SkColorToRGBComponents(color_text); // Get our template. static const base::StringPiece new_tab_theme_css( @@ -691,7 +656,7 @@ void NTPResourceCache::CreateNewTabCSS() { IDR_NEW_TAB_4_THEME_CSS)); // Create the string from our template and the replacements. - std::string css_string; - css_string = base::ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); + std::string css_string = + ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); new_tab_css_ = base::RefCountedString::TakeString(&css_string); } diff --git a/chrome/browser/web_dev_style/css_checker.py b/chrome/browser/web_dev_style/css_checker.py index 2c56fb6..09982f5 100644 --- a/chrome/browser/web_dev_style/css_checker.py +++ b/chrome/browser/web_dev_style/css_checker.py @@ -29,7 +29,11 @@ class CSSChecker(object): return s[0] == s[1] == s[2] if len(s) == 3 else s[0:2] == s[2:4] == s[4:6] def _remove_all(s): - return _remove_grit(_remove_ats(_remove_comments(s))) + s = _remove_grit(s) + s = _remove_ats(s) + s = _remove_comments(s) + s = _remove_template_expressions(s) + return s def _remove_ats(s): at_reg = re.compile(r""" @@ -43,6 +47,9 @@ class CSSChecker(object): def _remove_comments(s): return re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', s) + def _remove_template_expressions(s): + return re.sub(re.compile(r'\${[^}]*}', re.DOTALL), '', s) + def _remove_grit(s): grit_reg = re.compile(r""" <if[^>]+>.*?<\s*/\s*if[^>]*>| # <if> contents </if> diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn index d6f5ed3..00ad6a4 100644 --- a/ui/base/BUILD.gn +++ b/ui/base/BUILD.gn @@ -222,6 +222,8 @@ component("base") { "resource/resource_data_dll_win.cc", "resource/resource_data_dll_win.h", "resource/resource_handle.h", + "template_expressions.cc", + "template_expressions.h", "text/bytes_formatting.cc", "text/bytes_formatting.h", "theme_provider.cc", @@ -639,6 +641,7 @@ test("ui_base_unittests") { "resource/data_pack_unittest.cc", "resource/material_design/material_design_controller_unittest.cc", "resource/resource_bundle_unittest.cc", + "template_expressions_unittest.cc", "test/run_all_unittests.cc", "test/scoped_fake_nswindow_fullscreen_unittest.mm", "test/test_clipboard_unittest.cc", diff --git a/ui/base/template_expressions.cc b/ui/base/template_expressions.cc new file mode 100644 index 0000000..43cfa53 --- /dev/null +++ b/ui/base/template_expressions.cc @@ -0,0 +1,42 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/base/template_expressions.h" + +#include "base/logging.h" + +namespace ui { + +std::string ReplaceTemplateExpressions( + base::StringPiece format_string, + const std::map<base::StringPiece, std::string>& substitutions) { + std::string formatted; + const size_t kValueLengthGuess = 16; + formatted.reserve(format_string.length() + + substitutions.size() * kValueLengthGuess); + base::StringPiece::const_iterator i = format_string.begin(); + while (i < format_string.end()) { + if (*i == '$' && i + 1 < format_string.end() && i[1] == '{') { + size_t key_start = i + strlen("${") - format_string.begin(); + size_t key_length = format_string.find('}', key_start); + if (key_length == base::StringPiece::npos) + NOTREACHED() << "TemplateExpression missing ending brace '}'"; + key_length -= key_start; + base::StringPiece key(format_string.begin() + key_start, key_length); + const auto& replacement = substitutions.find(key); + if (replacement != substitutions.end()) { + formatted.append(replacement->second); + i += strlen("${") + key_length + strlen("}"); + continue; + } else { + NOTREACHED() << "TemplateExpression key not found: " << key; + } + } + formatted.push_back(*i); + ++i; + } + return formatted; +} + +} // namespace ui diff --git a/ui/base/template_expressions.h b/ui/base/template_expressions.h new file mode 100644 index 0000000..ff14ee1 --- /dev/null +++ b/ui/base/template_expressions.h @@ -0,0 +1,28 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file defines utility functions for replacing template expressions. +// For example "Hello ${name}" could have ${name} replaced by the user's name. + +#ifndef UI_BASE_TEMPLATE_EXPRESSIONS_H_ +#define UI_BASE_TEMPLATE_EXPRESSIONS_H_ + +#include <map> +#include <string> + +#include "base/strings/string_piece.h" +#include "ui/base/ui_base_export.h" + +namespace ui { + +// Replace ${foo} in the format string with the value for the foo key in +// |subst|. If the key is not found in the |substitutions| that item will +// be unaltered. +UI_BASE_EXPORT std::string ReplaceTemplateExpressions( + base::StringPiece format_string, + const std::map<base::StringPiece, std::string>& substitutions); + +} // namespace ui + +#endif // UI_BASE_TEMPLATE_EXPRESSIONS_H_ diff --git a/ui/base/template_expressions_unittest.cc b/ui/base/template_expressions_unittest.cc new file mode 100644 index 0000000..f5c3631 --- /dev/null +++ b/ui/base/template_expressions_unittest.cc @@ -0,0 +1,36 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/base/template_expressions.h" + +#include "testing/gtest/include/gtest/gtest.h" + +namespace ui { + +TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsPieces) { + std::map<base::StringPiece, std::string> substitutions; + substitutions["test"] = "word"; + substitutions["5"] = "number"; + substitutions[""] = "blank"; + + EXPECT_EQ(ReplaceTemplateExpressions("${}", substitutions), "blank"); + EXPECT_EQ(ReplaceTemplateExpressions("", substitutions), ""); + EXPECT_EQ(ReplaceTemplateExpressions("${test}", substitutions), "word"); + EXPECT_EQ(ReplaceTemplateExpressions("${5} ", substitutions), "number "); + EXPECT_EQ( + ReplaceTemplateExpressions("multiple: ${test}, ${5}.", substitutions), + "multiple: word, number."); +} + +TEST(TemplateExpressionsTest, + ReplaceTemplateExpressionsConsecutiveDollarSignsPieces) { + std::map<base::StringPiece, std::string> substitutions; + substitutions["a"] = "x"; + EXPECT_EQ(ReplaceTemplateExpressions("$ $$ $$$", substitutions), "$ $$ $$$"); + EXPECT_EQ(ReplaceTemplateExpressions("$${a}", substitutions), "$x"); + EXPECT_EQ(ReplaceTemplateExpressions("$$${a}", substitutions), "$$x"); + EXPECT_EQ(ReplaceTemplateExpressions("$12", substitutions), "$12"); +} + +} // namespace ui diff --git a/ui/base/ui_base.gyp b/ui/base/ui_base.gyp index 3f8f69e..9787853 100644 --- a/ui/base/ui_base.gyp +++ b/ui/base/ui_base.gyp @@ -271,6 +271,8 @@ 'resource/resource_data_dll_win.cc', 'resource/resource_data_dll_win.h', 'resource/resource_handle.h', + 'template_expressions.cc', + 'template_expressions.h', 'text/bytes_formatting.cc', 'text/bytes_formatting.h', 'theme_provider.cc', @@ -368,6 +370,7 @@ ['include', '^layout'], ['include', '^page_transition_type'], ['include', '^resource/'], + ['include', 'template_expressions.cc'], ['include', '^ui_base_'], ['include', '^webui/'], ['include', '^window_open_disposition\\.cc'], diff --git a/ui/base/ui_base_tests.gyp b/ui/base/ui_base_tests.gyp index ef433e0..d47436b 100644 --- a/ui/base/ui_base_tests.gyp +++ b/ui/base/ui_base_tests.gyp @@ -44,6 +44,7 @@ 'resource/data_pack_literal.cc', 'resource/data_pack_unittest.cc', 'resource/resource_bundle_unittest.cc', + 'template_expressions_unittest.cc', 'test/run_all_unittests.cc', ], 'all_sources': [ diff --git a/ui/base/webui/web_ui_util.cc b/ui/base/webui/web_ui_util.cc index c0f5a9d..6483f07 100644 --- a/ui/base/webui/web_ui_util.cc +++ b/ui/base/webui/web_ui_util.cc @@ -16,6 +16,7 @@ #include "net/base/escape.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/base/template_expressions.h" #include "ui/base/window_open_disposition.h" #include "ui/gfx/codec/png_codec.h" #include "ui/gfx/font.h" @@ -119,10 +120,10 @@ void SetLoadTimeDataDefaults(const std::string& app_locale, } std::string GetWebUiCssTextDefaults() { - std::vector<std::string> placeholders; - placeholders.push_back(GetTextDirection()); // $1 - placeholders.push_back(GetFontFamily()); // $2 - placeholders.push_back(GetFontSize()); // $3 + std::map<base::StringPiece, std::string> placeholders; + placeholders["textDirection"] = GetTextDirection(); + placeholders["fontFamily"] = GetFontFamily(); + placeholders["fontSize"] = GetFontSize(); const ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); @@ -130,7 +131,7 @@ std::string GetWebUiCssTextDefaults() { resource_bundle.GetRawDataResource(IDR_WEBUI_CSS_TEXT_DEFAULTS) .as_string(); - return base::ReplaceStringPlaceholders(css_template, placeholders, nullptr); + return ui::ReplaceTemplateExpressions(css_template, placeholders); } void AppendWebUiCssTextDefaults(std::string* html) { diff --git a/ui/webui/resources/css/text_defaults.css b/ui/webui/resources/css/text_defaults.css index 1af823b..037ade7 100644 --- a/ui/webui/resources/css/text_defaults.css +++ b/ui/webui/resources/css/text_defaults.css @@ -16,14 +16,14 @@ * Otherwise its $placeholders won't be expanded. */ html { - direction: $1; + direction: ${textDirection}; } body { - font-family: $2; - font-size: $3; + font-family: ${fontFamily}; + font-size: ${fontSize}; } button { - font-family: $2; + font-family: ${fontFamily}; } |