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 "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/memory_mapped_file.h" | 8 #include "base/files/memory_mapped_file.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/timer/elapsed_timer.h" | 10 #include "base/timer/elapsed_timer.h" |
11 #include "mojo/public/cpp/system/platform_handle.h" | 11 #include "mojo/public/cpp/system/platform_handle.h" |
12 #include "platform/LayoutLocale.h" | 12 #include "platform/LayoutLocale.h" |
13 #include "platform/text/hyphenation/HyphenatorAOSP.h" | 13 #include "platform/text/hyphenation/HyphenatorAOSP.h" |
| 14 #include "public/platform/InterfaceProvider.h" |
14 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
15 #include "public/platform/ServiceRegistry.h" | |
16 #include "public/platform/modules/hyphenation/hyphenation.mojom-blink.h" | 16 #include "public/platform/modules/hyphenation/hyphenation.mojom-blink.h" |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 | 19 |
20 using Hyphenator = android::Hyphenator; | 20 using Hyphenator = android::Hyphenator; |
21 | 21 |
22 class HyphenationMinikin : public Hyphenation { | 22 class HyphenationMinikin : public Hyphenation { |
23 public: | 23 public: |
24 bool openDictionary(const AtomicString& locale); | 24 bool openDictionary(const AtomicString& locale); |
25 | 25 |
26 size_t lastHyphenLocation(const StringView& text, size_t beforeIndex) const
override; | 26 size_t lastHyphenLocation(const StringView& text, size_t beforeIndex) const
override; |
27 Vector<size_t, 8> hyphenLocations(const StringView&) const override; | 27 Vector<size_t, 8> hyphenLocations(const StringView&) const override; |
28 | 28 |
29 private: | 29 private: |
30 static base::PlatformFile openDictionaryFile(const AtomicString& locale); | 30 static base::PlatformFile openDictionaryFile(const AtomicString& locale); |
31 | 31 |
32 std::vector<uint8_t> hyphenate(const StringView&) const; | 32 std::vector<uint8_t> hyphenate(const StringView&) const; |
33 | 33 |
34 base::MemoryMappedFile m_file; | 34 base::MemoryMappedFile m_file; |
35 std::unique_ptr<Hyphenator> m_hyphenator; | 35 std::unique_ptr<Hyphenator> m_hyphenator; |
36 }; | 36 }; |
37 | 37 |
38 static mojom::blink::HyphenationPtr connectToRemoteService() | 38 static mojom::blink::HyphenationPtr connectToRemoteService() |
39 { | 39 { |
40 mojom::blink::HyphenationPtr service; | 40 mojom::blink::HyphenationPtr service; |
41 Platform::current()->serviceRegistry()->connectToRemoteService( | 41 Platform::current()->interfaceProvider()->getInterface(mojo::GetProxy(&servi
ce)); |
42 mojo::GetProxy(&service)); | |
43 return service; | 42 return service; |
44 } | 43 } |
45 | 44 |
46 static const mojom::blink::HyphenationPtr& getService() | 45 static const mojom::blink::HyphenationPtr& getService() |
47 { | 46 { |
48 DEFINE_STATIC_LOCAL(mojom::blink::HyphenationPtr, service, | 47 DEFINE_STATIC_LOCAL(mojom::blink::HyphenationPtr, service, |
49 (connectToRemoteService())); | 48 (connectToRemoteService())); |
50 return service; | 49 return service; |
51 } | 50 } |
52 | 51 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 172 |
174 DEFINE_STATIC_LOCAL(LocaleMap, localeFallback, (createLocaleFallbackMap())); | 173 DEFINE_STATIC_LOCAL(LocaleMap, localeFallback, (createLocaleFallbackMap())); |
175 const auto& it = localeFallback.find(locale); | 174 const auto& it = localeFallback.find(locale); |
176 if (it != localeFallback.end()) | 175 if (it != localeFallback.end()) |
177 return LayoutLocale::get(it->value)->getHyphenation(); | 176 return LayoutLocale::get(it->value)->getHyphenation(); |
178 | 177 |
179 return nullptr; | 178 return nullptr; |
180 } | 179 } |
181 | 180 |
182 } // namespace blink | 181 } // namespace blink |
OLD | NEW |