| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "platform/fonts/AcceptLanguagesResolver.h" | 5 #include "platform/fonts/AcceptLanguagesResolver.h" |
| 6 | 6 |
| 7 #include "platform/LayoutLocale.h" | 7 #include "platform/LayoutLocale.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| 11 static String& currentAcceptLanguages() |
| 12 { |
| 13 DEFINE_STATIC_LOCAL(String, s_current, ()); |
| 14 return s_current; |
| 15 } |
| 16 |
| 11 void AcceptLanguagesResolver::acceptLanguagesChanged( | 17 void AcceptLanguagesResolver::acceptLanguagesChanged( |
| 12 const String& acceptLanguages) | 18 const String& acceptLanguages) |
| 13 { | 19 { |
| 14 LayoutLocale::setLocaleForHan( | 20 String& currentValue = currentAcceptLanguages(); |
| 15 localeForHanFromAcceptLanguages(acceptLanguages)); | 21 if (currentValue == acceptLanguages) |
| 22 return; |
| 23 |
| 24 currentValue = acceptLanguages; |
| 25 LayoutLocale::invalidateLocaleForHan(); |
| 26 } |
| 27 |
| 28 const LayoutLocale* AcceptLanguagesResolver::localeForHan() |
| 29 { |
| 30 return localeForHanFromAcceptLanguages(currentAcceptLanguages()); |
| 16 } | 31 } |
| 17 | 32 |
| 18 const LayoutLocale* AcceptLanguagesResolver::localeForHanFromAcceptLanguages( | 33 const LayoutLocale* AcceptLanguagesResolver::localeForHanFromAcceptLanguages( |
| 19 const String& acceptLanguages) | 34 const String& acceptLanguages) |
| 20 { | 35 { |
| 21 // Use the first acceptLanguages that can disambiguate. | 36 // Use the first acceptLanguages that can disambiguate. |
| 22 Vector<String> languages; | 37 Vector<String> languages; |
| 23 acceptLanguages.split(',', languages); | 38 acceptLanguages.split(',', languages); |
| 24 for (String token : languages) { | 39 for (String token : languages) { |
| 25 token = token.stripWhiteSpace(); | 40 token = token.stripWhiteSpace(); |
| 26 const LayoutLocale* locale = LayoutLocale::get(AtomicString(token)); | 41 const LayoutLocale* locale = LayoutLocale::get(AtomicString(token)); |
| 27 if (locale->hasScriptForHan()) | 42 if (locale->hasScriptForHan()) |
| 28 return locale; | 43 return locale; |
| 29 } | 44 } |
| 30 | 45 |
| 31 return nullptr; | 46 return nullptr; |
| 32 } | 47 } |
| 33 | 48 |
| 34 } // namespace blink | 49 } // namespace blink |
| OLD | NEW |