| 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 "webkit/glue/webpreferences.h" | 5 #include "webkit/glue/webpreferences.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifi
er.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifi
er.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 167 |
| 168 void setFantasyFontFamilyWrapper(WebSettings* settings, | 168 void setFantasyFontFamilyWrapper(WebSettings* settings, |
| 169 const string16& font, | 169 const string16& font, |
| 170 UScriptCode script) { | 170 UScriptCode script) { |
| 171 settings->setFantasyFontFamily(font, script); | 171 settings->setFantasyFontFamily(font, script); |
| 172 } | 172 } |
| 173 | 173 |
| 174 typedef void (*SetFontFamilyWrapper)( | 174 typedef void (*SetFontFamilyWrapper)( |
| 175 WebKit::WebSettings*, const string16&, UScriptCode); | 175 WebKit::WebSettings*, const string16&, UScriptCode); |
| 176 | 176 |
| 177 // If |scriptCode| is a member of a family of "similar" script codes, returns |
| 178 // the script code in that family that is used by WebKit for font selection |
| 179 // purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are |
| 180 // considered equivalent for the purposes of font selection. WebKit uses the |
| 181 // script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is |
| 182 // USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit |
| 183 // uses different scripts than the ones in Chrome pref names because the version |
| 184 // of ICU included on certain ports does not have some of the newer scripts. If |
| 185 // |scriptCode| is not a member of such a family, returns |scriptCode|. |
| 186 UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) { |
| 187 switch (scriptCode) { |
| 188 case USCRIPT_HIRAGANA: |
| 189 case USCRIPT_KATAKANA: |
| 190 case USCRIPT_JAPANESE: |
| 191 return USCRIPT_KATAKANA_OR_HIRAGANA; |
| 192 case USCRIPT_KOREAN: |
| 193 return USCRIPT_HANGUL; |
| 194 default: |
| 195 return scriptCode; |
| 196 } |
| 197 } |
| 198 |
| 177 void ApplyFontsFromMap(const WebPreferences::ScriptFontFamilyMap& map, | 199 void ApplyFontsFromMap(const WebPreferences::ScriptFontFamilyMap& map, |
| 178 SetFontFamilyWrapper setter, | 200 SetFontFamilyWrapper setter, |
| 179 WebSettings* settings) { | 201 WebSettings* settings) { |
| 180 for (WebPreferences::ScriptFontFamilyMap::const_iterator it = map.begin(); | 202 for (WebPreferences::ScriptFontFamilyMap::const_iterator it = map.begin(); |
| 181 it != map.end(); ++it) { | 203 it != map.end(); ++it) { |
| 182 int32 script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str()); | 204 int32 script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str()); |
| 183 if (script >= 0 && script < USCRIPT_CODE_LIMIT) | 205 if (script >= 0 && script < USCRIPT_CODE_LIMIT) { |
| 184 (*setter)(settings, it->second, (UScriptCode) script); | 206 UScriptCode code = static_cast<UScriptCode>(script); |
| 207 (*setter)(settings, it->second, GetScriptForWebSettings(code)); |
| 208 } |
| 185 } | 209 } |
| 186 } | 210 } |
| 187 | 211 |
| 188 } // namespace | 212 } // namespace |
| 189 | 213 |
| 190 void WebPreferences::Apply(WebView* web_view) const { | 214 void WebPreferences::Apply(WebView* web_view) const { |
| 191 WebSettings* settings = web_view->settings(); | 215 WebSettings* settings = web_view->settings(); |
| 192 ApplyFontsFromMap(standard_font_family_map, setStandardFontFamilyWrapper, | 216 ApplyFontsFromMap(standard_font_family_map, setStandardFontFamilyWrapper, |
| 193 settings); | 217 settings); |
| 194 ApplyFontsFromMap(fixed_font_family_map, setFixedFontFamilyWrapper, settings); | 218 ApplyFontsFromMap(fixed_font_family_map, setFixedFontFamilyWrapper, settings); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 settings->setMaxUntiledLayerSize( | 406 settings->setMaxUntiledLayerSize( |
| 383 WebSize(max_untiled_layer_width, max_untiled_layer_height)); | 407 WebSize(max_untiled_layer_width, max_untiled_layer_height)); |
| 384 | 408 |
| 385 settings->setFixedPositionCreatesStackingContext( | 409 settings->setFixedPositionCreatesStackingContext( |
| 386 fixed_position_creates_stacking_context); | 410 fixed_position_creates_stacking_context); |
| 387 | 411 |
| 388 WebNetworkStateNotifier::setOnLine(is_online); | 412 WebNetworkStateNotifier::setOnLine(is_online); |
| 389 } | 413 } |
| 390 | 414 |
| 391 } // namespace webkit_glue | 415 } // namespace webkit_glue |
| OLD | NEW |