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/text/Hyphenation.h" | 5 #include "platform/text/Hyphenation.h" |
6 | 6 |
7 #include "wtf/RetainPtr.h" | 7 #include "wtf/RetainPtr.h" |
8 #include "wtf/text/StringView.h" | 8 #include "wtf/text/StringView.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
12 class HyphenationCF : public Hyphenation { | 12 class HyphenationCF : public Hyphenation { |
13 public: | 13 public: |
14 HyphenationCF(RetainPtr<CFLocaleRef>& localeCF) | 14 HyphenationCF(RetainPtr<CFLocaleRef>& localeCF) |
15 : m_localeCF(localeCF) | 15 : m_localeCF(localeCF) |
16 { | 16 { |
17 DCHECK(m_localeCF); | 17 DCHECK(m_localeCF); |
18 } | 18 } |
19 | 19 |
20 size_t lastHyphenLocation(const StringView& text, size_t beforeIndex) const
override | 20 size_t lastHyphenLocation(const StringView& text, size_t beforeIndex) const
override |
21 { | 21 { |
22 CFIndex result = CFStringGetHyphenationLocationBeforeIndex( | 22 CFIndex result = CFStringGetHyphenationLocationBeforeIndex( |
23 text.toString()->createCFString().get(), beforeIndex, | 23 text.toString().impl()->createCFString().get(), beforeIndex, |
24 CFRangeMake(0, text.length()), 0, m_localeCF.get(), 0); | 24 CFRangeMake(0, text.length()), 0, m_localeCF.get(), 0); |
25 return result == kCFNotFound ? 0 : result; | 25 return result == kCFNotFound ? 0 : result; |
26 } | 26 } |
27 | 27 |
28 private: | 28 private: |
29 RetainPtr<CFLocaleRef> m_localeCF; | 29 RetainPtr<CFLocaleRef> m_localeCF; |
30 }; | 30 }; |
31 | 31 |
32 PassRefPtr<Hyphenation> Hyphenation::platformGetHyphenation(const AtomicString&
locale) | 32 PassRefPtr<Hyphenation> Hyphenation::platformGetHyphenation(const AtomicString&
locale) |
33 { | 33 { |
34 RetainPtr<CFStringRef> localeCFString = locale.impl()->createCFString(); | 34 RetainPtr<CFStringRef> localeCFString = locale.impl()->createCFString(); |
35 RetainPtr<CFLocaleRef> localeCF = adoptCF(CFLocaleCreate(kCFAllocatorDefault
, localeCFString.get())); | 35 RetainPtr<CFLocaleRef> localeCF = adoptCF(CFLocaleCreate(kCFAllocatorDefault
, localeCFString.get())); |
36 if (!CFStringIsHyphenationAvailableForLocale(localeCF.get())) | 36 if (!CFStringIsHyphenationAvailableForLocale(localeCF.get())) |
37 return nullptr; | 37 return nullptr; |
38 return adoptRef(new HyphenationCF(localeCF)); | 38 return adoptRef(new HyphenationCF(localeCF)); |
39 } | 39 } |
40 | 40 |
41 } // namespace blink | 41 } // namespace blink |
OLD | NEW |