OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/base/webui/web_ui_util.h" | 5 #include "ui/base/webui/web_ui_util.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" |
15 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/base/window_open_disposition.h" | 19 #include "ui/base/window_open_disposition.h" |
19 #include "ui/gfx/codec/png_codec.h" | 20 #include "ui/gfx/codec/png_codec.h" |
20 #include "ui/gfx/font.h" | 21 #include "ui/gfx/font.h" |
21 #include "ui/gfx/image/image_skia.h" | 22 #include "ui/gfx/image/image_skia.h" |
| 23 #include "ui/resources/grit/webui_resources.h" |
22 #include "ui/strings/grit/app_locale_settings.h" | 24 #include "ui/strings/grit/app_locale_settings.h" |
23 #include "url/gurl.h" | 25 #include "url/gurl.h" |
24 | 26 |
25 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
26 #include "base/win/windows_version.h" | 28 #include "base/win/windows_version.h" |
27 #endif | 29 #endif |
28 | 30 |
29 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
30 #include "ui/base/font_helper_chromeos.h" | 32 #include "ui/base/font_helper_chromeos.h" |
31 #endif | 33 #endif |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 pos + 1, stripped_path.length() - pos - 1), &factor)) { | 124 pos + 1, stripped_path.length() - pos - 1), &factor)) { |
123 // Strip scale factor specification from path. | 125 // Strip scale factor specification from path. |
124 stripped_path.remove_suffix(stripped_path.length() - pos); | 126 stripped_path.remove_suffix(stripped_path.length() - pos); |
125 stripped_path.CopyToString(path); | 127 stripped_path.CopyToString(path); |
126 } | 128 } |
127 if (scale_factor) | 129 if (scale_factor) |
128 *scale_factor = factor; | 130 *scale_factor = factor; |
129 } | 131 } |
130 } | 132 } |
131 | 133 |
| 134 void SetFontAndTextDirection(base::DictionaryValue* localized_strings) { |
| 135 localized_strings->SetString("fontfamily", GetFontFamily()); |
| 136 localized_strings->SetString("fontsize", GetFontSize()); |
| 137 localized_strings->SetString("textdirection", GetTextDirection()); |
| 138 } |
| 139 |
| 140 std::string GetWebUiCssTextDefaults() { |
| 141 std::vector<std::string> placeholders; |
| 142 placeholders.push_back(GetTextDirection()); // $1 |
| 143 placeholders.push_back(GetFontFamily()); // $2 |
| 144 placeholders.push_back(GetFontSize()); // $3 |
| 145 |
| 146 const ui::ResourceBundle& resource_bundle = |
| 147 ui::ResourceBundle::GetSharedInstance(); |
| 148 const std::string& css_template = |
| 149 resource_bundle.GetRawDataResource(IDR_WEBUI_CSS_TEXT_DEFAULTS) |
| 150 .as_string(); |
| 151 |
| 152 return ReplaceStringPlaceholders(css_template, placeholders, nullptr); |
| 153 } |
| 154 |
| 155 void AppendWebUiCssTextDefaults(std::string* html) { |
| 156 html->append("<style>"); |
| 157 html->append(GetWebUiCssTextDefaults()); |
| 158 html->append("</style>"); |
| 159 } |
| 160 |
132 std::string GetFontFamily() { | 161 std::string GetFontFamily() { |
133 std::string font_family = l10n_util::GetStringUTF8( | 162 std::string font_family = l10n_util::GetStringUTF8( |
134 #if defined(OS_WIN) | 163 #if defined(OS_WIN) |
135 base::win::GetVersion() < base::win::VERSION_VISTA ? | 164 base::win::GetVersion() < base::win::VERSION_VISTA ? |
136 IDS_WEB_FONT_FAMILY_XP : | 165 IDS_WEB_FONT_FAMILY_XP : |
137 #endif | 166 #endif |
138 IDS_WEB_FONT_FAMILY); | 167 IDS_WEB_FONT_FAMILY); |
139 | 168 |
140 #if defined(OS_CHROMEOS) | 169 #if defined(OS_CHROMEOS) |
141 ui::ReplaceNotoSansWithRobotoIfEnabled(&font_family); | 170 ui::ReplaceNotoSansWithRobotoIfEnabled(&font_family); |
(...skipping 15 matching lines...) Expand all Loading... |
157 base::win::GetVersion() < base::win::VERSION_VISTA ? | 186 base::win::GetVersion() < base::win::VERSION_VISTA ? |
158 IDS_WEB_FONT_SIZE_XP : | 187 IDS_WEB_FONT_SIZE_XP : |
159 #endif | 188 #endif |
160 IDS_WEB_FONT_SIZE); | 189 IDS_WEB_FONT_SIZE); |
161 } | 190 } |
162 | 191 |
163 std::string GetTextDirection() { | 192 std::string GetTextDirection() { |
164 return base::i18n::IsRTL() ? "rtl" : "ltr"; | 193 return base::i18n::IsRTL() ? "rtl" : "ltr"; |
165 } | 194 } |
166 | 195 |
167 void SetFontAndTextDirection(base::DictionaryValue* localized_strings) { | |
168 localized_strings->SetString("fontfamily", GetFontFamily()); | |
169 localized_strings->SetString("fontsize", GetFontSize()); | |
170 localized_strings->SetString("textdirection", GetTextDirection()); | |
171 } | |
172 | |
173 } // namespace webui | 196 } // namespace webui |
OLD | NEW |