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 #ifndef LayoutLocale_h | 5 #ifndef LayoutLocale_h |
6 #define LayoutLocale_h | 6 #define LayoutLocale_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "platform/text/Hyphenation.h" | 9 #include "platform/text/Hyphenation.h" |
10 #include "wtf/Forward.h" | 10 #include "wtf/Forward.h" |
11 #include "wtf/RefCounted.h" | 11 #include "wtf/RefCounted.h" |
12 #include "wtf/text/AtomicString.h" | 12 #include "wtf/text/AtomicString.h" |
13 | 13 |
14 #include <unicode/uscript.h> | 14 #include <unicode/uscript.h> |
15 | 15 |
16 struct hb_language_impl_t; | 16 struct hb_language_impl_t; |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 | 19 |
20 class Hyphenation; | 20 class Hyphenation; |
21 | 21 |
22 class PLATFORM_EXPORT LayoutLocale : public RefCounted<LayoutLocale> { | 22 class PLATFORM_EXPORT LayoutLocale : public RefCounted<LayoutLocale> { |
23 public: | 23 public: |
24 static const LayoutLocale* get(const AtomicString& locale); | 24 static const LayoutLocale* get(const AtomicString& locale); |
25 static const LayoutLocale& getDefault(); | 25 static const LayoutLocale& getDefault(); |
| 26 static const LayoutLocale& getSystem(); |
26 static const LayoutLocale& valueOrDefault(const LayoutLocale* locale) { retu
rn locale ? *locale : getDefault(); } | 27 static const LayoutLocale& valueOrDefault(const LayoutLocale* locale) { retu
rn locale ? *locale : getDefault(); } |
27 | 28 |
| 29 bool operator==(const LayoutLocale& other) const { return m_string == other.
m_string; } |
| 30 bool operator!=(const LayoutLocale& other) const { return m_string != other.
m_string; } |
| 31 |
28 const AtomicString& localeString() const { return m_string; } | 32 const AtomicString& localeString() const { return m_string; } |
29 static const AtomicString& localeString(const LayoutLocale* locale) { return
locale ? locale->m_string : nullAtom; } | 33 static const AtomicString& localeString(const LayoutLocale* locale) { return
locale ? locale->m_string : nullAtom; } |
30 operator const AtomicString&() const { return m_string; } | 34 operator const AtomicString&() const { return m_string; } |
31 CString ascii() const { return m_string.ascii(); } | 35 CString ascii() const { return m_string.ascii(); } |
32 | 36 |
33 const hb_language_impl_t* harfbuzzLanguage() const { return m_harfbuzzLangua
ge; } | 37 const hb_language_impl_t* harfbuzzLanguage() const { return m_harfbuzzLangua
ge; } |
34 const CString& localeForSkFontMgr() const; | 38 const char* localeForSkFontMgr() const; |
35 UScriptCode script() const { return m_script; } | 39 UScriptCode script() const { return m_script; } |
| 40 |
| 41 // Disambiguation of the Unified Han Ideographs. |
36 UScriptCode scriptForHan() const; | 42 UScriptCode scriptForHan() const; |
| 43 bool hasScriptForHan() const; |
| 44 static const LayoutLocale* localeForHan(const LayoutLocale*); |
| 45 static void setLocaleForHan(const LayoutLocale*); |
| 46 const char* localeForHanForSkFontMgr() const; |
37 | 47 |
38 Hyphenation* getHyphenation() const; | 48 Hyphenation* getHyphenation() const; |
39 | 49 |
| 50 static PassRefPtr<LayoutLocale> createForTesting(const AtomicString&); |
40 static void clearForTesting(); | 51 static void clearForTesting(); |
41 static void setHyphenationForTesting(const AtomicString&, PassRefPtr<Hyphena
tion>); | 52 static void setHyphenationForTesting(const AtomicString&, PassRefPtr<Hyphena
tion>); |
42 | 53 |
43 private: | 54 private: |
44 explicit LayoutLocale(const AtomicString&); | 55 explicit LayoutLocale(const AtomicString&); |
45 | 56 |
| 57 void computeScriptForHan() const; |
| 58 |
46 AtomicString m_string; | 59 AtomicString m_string; |
47 mutable CString m_stringForSkFontMgr; | 60 mutable CString m_stringForSkFontMgr; |
48 mutable RefPtr<Hyphenation> m_hyphenation; | 61 mutable RefPtr<Hyphenation> m_hyphenation; |
49 | 62 |
50 // hb_language_t is defined in hb.h, which not all files can include. | 63 // hb_language_t is defined in hb.h, which not all files can include. |
51 const hb_language_impl_t* m_harfbuzzLanguage; | 64 const hb_language_impl_t* m_harfbuzzLanguage; |
52 | 65 |
53 UScriptCode m_script; | 66 UScriptCode m_script; |
54 mutable UScriptCode m_scriptForHan; | 67 mutable UScriptCode m_scriptForHan; |
55 | 68 |
| 69 mutable unsigned m_hasScriptForHan : 1; |
56 mutable unsigned m_hyphenationComputed : 1; | 70 mutable unsigned m_hyphenationComputed : 1; |
57 | 71 |
58 static const LayoutLocale* s_default; | 72 static const LayoutLocale* s_default; |
| 73 static const LayoutLocale* s_system; |
| 74 static const LayoutLocale* s_defaultForHan; |
| 75 static bool s_defaultForHanComputed; |
59 }; | 76 }; |
60 | 77 |
61 } // namespace blink | 78 } // namespace blink |
62 | 79 |
63 #endif // LayoutLocale_h | 80 #endif // LayoutLocale_h |
OLD | NEW |