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

Side by Side Diff: ui/base/webui/web_ui_util.cc

Issue 747923004: webui: minimize webui flicker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
OLDNEW
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 "net/base/escape.h" 15 #include "net/base/escape.h"
16 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/base/window_open_disposition.h" 18 #include "ui/base/window_open_disposition.h"
19 #include "ui/gfx/codec/png_codec.h" 19 #include "ui/gfx/codec/png_codec.h"
20 #include "ui/gfx/font.h" 20 #include "ui/gfx/font.h"
21 #include "ui/gfx/image/image_skia.h" 21 #include "ui/gfx/image/image_skia.h"
22 #include "ui/strings/grit/app_locale_settings.h" 22 #include "ui/strings/grit/app_locale_settings.h"
23 #include "url/gurl.h" 23 #include "url/gurl.h"
24 24
25 #if defined(OS_WIN) 25 #if defined(OS_WIN)
26 #include "base/win/windows_version.h" 26 #include "base/win/windows_version.h"
27 #endif 27 #endif
28 28
29 namespace {
30
31 std::string GetFontFamily() {
32 int web_font_family_id = IDS_WEB_FONT_FAMILY;
33 #if defined(OS_WIN)
34 if (base::win::GetVersion() < base::win::VERSION_VISTA)
35 web_font_family_id = IDS_WEB_FONT_FAMILY_XP;
36 #endif
37 std::string font_family = l10n_util::GetStringUTF8(web_font_family_id);
38 // TODO(dnicoara) Remove Ozone check when PlatformFont support is introduced
39 // into Ozone: crbug.com/320050
40 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(USE_OZONE)
41 font_family = ui::ResourceBundle::GetSharedInstance().GetFont(
42 ui::ResourceBundle::BaseFont).GetFontName() + ", " + font_family;
43 #endif
44 return font_family;
45 }
46
47 std::string GetFontSize() {
48 int web_font_size_id = IDS_WEB_FONT_SIZE;
49 #if defined(OS_WIN)
50 if (base::win::GetVersion() < base::win::VERSION_VISTA)
51 web_font_size_id = IDS_WEB_FONT_SIZE_XP;
52 #endif
53 return l10n_util::GetStringUTF8(web_font_size_id);
54 }
55
56 }
Evan Stade 2014/11/22 05:14:44 nit: // namespace
57
29 namespace webui { 58 namespace webui {
30 59
31 std::string GetBitmapDataUrl(const SkBitmap& bitmap) { 60 std::string GetBitmapDataUrl(const SkBitmap& bitmap) {
32 TRACE_EVENT2("oobe", "GetImageDataUrl", 61 TRACE_EVENT2("oobe", "GetImageDataUrl",
33 "width", bitmap.width(), "height", bitmap.height()); 62 "width", bitmap.width(), "height", bitmap.height());
34 std::vector<unsigned char> output; 63 std::vector<unsigned char> output;
35 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &output); 64 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &output);
36 std::string str_url; 65 std::string str_url;
37 str_url.insert(str_url.end(), output.begin(), output.end()); 66 str_url.insert(str_url.end(), output.begin(), output.end());
38 67
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 pos + 1, stripped_path.length() - pos - 1), &factor)) { 147 pos + 1, stripped_path.length() - pos - 1), &factor)) {
119 // Strip scale factor specification from path. 148 // Strip scale factor specification from path.
120 stripped_path.remove_suffix(stripped_path.length() - pos); 149 stripped_path.remove_suffix(stripped_path.length() - pos);
121 stripped_path.CopyToString(path); 150 stripped_path.CopyToString(path);
122 } 151 }
123 if (scale_factor) 152 if (scale_factor)
124 *scale_factor = factor; 153 *scale_factor = factor;
125 } 154 }
126 } 155 }
127 156
128 // static
129 void SetFontAndTextDirection(base::DictionaryValue* localized_strings) { 157 void SetFontAndTextDirection(base::DictionaryValue* localized_strings) {
130 int web_font_family_id = IDS_WEB_FONT_FAMILY; 158 localized_strings->SetString("fontfamily", GetFontFamily());
131 int web_font_size_id = IDS_WEB_FONT_SIZE; 159 localized_strings->SetString("fontsize", GetFontSize());
132 #if defined(OS_WIN)
133 // Vary font settings for Windows XP.
134 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
135 web_font_family_id = IDS_WEB_FONT_FAMILY_XP;
136 web_font_size_id = IDS_WEB_FONT_SIZE_XP;
137 }
138 #endif
139
140 std::string font_family = l10n_util::GetStringUTF8(web_font_family_id);
141
142 // TODO(dnicoara) Remove Ozone check when PlatformFont support is introduced
143 // into Ozone: crbug.com/320050
144 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(USE_OZONE)
145 font_family = ui::ResourceBundle::GetSharedInstance().GetFont(
146 ui::ResourceBundle::BaseFont).GetFontName() + ", " + font_family;
147 #endif
148
149 localized_strings->SetString("fontfamily", font_family);
150 localized_strings->SetString("fontsize",
151 l10n_util::GetStringUTF8(web_font_size_id));
152 localized_strings->SetString("textdirection", 160 localized_strings->SetString("textdirection",
153 base::i18n::IsRTL() ? "rtl" : "ltr"); 161 base::i18n::IsRTL() ? "rtl" : "ltr");
154 } 162 }
155 163
164 std::string ReplaceFontFamilyAndSize(const std::string& html_page) {
165 std::vector<std::string> replacements = { GetFontFamily(), GetFontSize() };
166 return ReplaceStringPlaceholders(html_page, replacements, NULL);
167 }
168
156 } // namespace webui 169 } // namespace webui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698