| Index: third_party/WebKit/Source/platform/text/hyphenation/HyphenationMinikin.cpp
|
| diff --git a/third_party/WebKit/Source/platform/text/hyphenation/HyphenationMinikin.cpp b/third_party/WebKit/Source/platform/text/hyphenation/HyphenationMinikin.cpp
|
| index ab972fc648b0dbd96d1406a6c21a51d8cbfb822a..5a73cf42d743c2259951948b5e220ef7c1bdcaf3 100644
|
| --- a/third_party/WebKit/Source/platform/text/hyphenation/HyphenationMinikin.cpp
|
| +++ b/third_party/WebKit/Source/platform/text/hyphenation/HyphenationMinikin.cpp
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "platform/text/Hyphenation.h"
|
| +#include "platform/text/hyphenation/HyphenationMinikin.h"
|
|
|
| #include "base/files/file.h"
|
| #include "base/files/memory_mapped_file.h"
|
| @@ -18,23 +18,6 @@ namespace blink {
|
|
|
| using Hyphenator = android::Hyphenator;
|
|
|
| -class HyphenationMinikin : public Hyphenation {
|
| - public:
|
| - bool openDictionary(const AtomicString& locale);
|
| -
|
| - size_t lastHyphenLocation(const StringView& text,
|
| - size_t beforeIndex) const override;
|
| - Vector<size_t, 8> hyphenLocations(const StringView&) const override;
|
| -
|
| - private:
|
| - static base::File openDictionaryFile(const AtomicString& locale);
|
| -
|
| - std::vector<uint8_t> hyphenate(const StringView&) const;
|
| -
|
| - base::MemoryMappedFile m_file;
|
| - std::unique_ptr<Hyphenator> m_hyphenator;
|
| -};
|
| -
|
| static mojom::blink::HyphenationPtr connectToRemoteService() {
|
| mojom::blink::HyphenationPtr service;
|
| Platform::current()->interfaceProvider()->getInterface(
|
| @@ -48,17 +31,17 @@ static const mojom::blink::HyphenationPtr& getService() {
|
| return service;
|
| }
|
|
|
| -base::File HyphenationMinikin::openDictionaryFile(const AtomicString& locale) {
|
| +bool HyphenationMinikin::openDictionary(const AtomicString& locale) {
|
| const mojom::blink::HyphenationPtr& service = getService();
|
| base::File file;
|
| base::ElapsedTimer timer;
|
| service->OpenDictionary(locale, &file);
|
| UMA_HISTOGRAM_TIMES("Hyphenation.Open", timer.Elapsed());
|
| - return file;
|
| +
|
| + return openDictionary(std::move(file));
|
| }
|
|
|
| -bool HyphenationMinikin::openDictionary(const AtomicString& locale) {
|
| - base::File file = openDictionaryFile(locale);
|
| +bool HyphenationMinikin::openDictionary(base::File file) {
|
| if (!file.IsValid())
|
| return false;
|
| if (!m_file.Initialize(std::move(file))) {
|
| @@ -87,14 +70,17 @@ std::vector<uint8_t> HyphenationMinikin::hyphenate(
|
|
|
| size_t HyphenationMinikin::lastHyphenLocation(const StringView& text,
|
| size_t beforeIndex) const {
|
| - if (text.length() < minimumPrefixLength + minimumSuffixLength)
|
| + if (text.length() < minimumPrefixLength + minimumSuffixLength ||
|
| + beforeIndex <= minimumPrefixLength)
|
| return 0;
|
|
|
| std::vector<uint8_t> result = hyphenate(text);
|
| - static_assert(minimumPrefixLength >= 1,
|
| - "Change the 'if' above if this fails");
|
| - for (size_t i = text.length() - minimumSuffixLength - 1;
|
| - i >= minimumPrefixLength; i--) {
|
| + beforeIndex =
|
| + std::min<size_t>(beforeIndex, text.length() - minimumSuffixLength);
|
| + CHECK_LE(beforeIndex, result.size());
|
| + CHECK_GE(beforeIndex, 1u);
|
| + static_assert(minimumPrefixLength >= 1, "|beforeIndex - 1| can underflow");
|
| + for (size_t i = beforeIndex - 1; i >= minimumPrefixLength; i--) {
|
| if (result[i])
|
| return i;
|
| }
|
| @@ -170,4 +156,12 @@ PassRefPtr<Hyphenation> Hyphenation::platformGetHyphenation(
|
| return nullptr;
|
| }
|
|
|
| +PassRefPtr<HyphenationMinikin> HyphenationMinikin::fromFileForTesting(
|
| + base::File file) {
|
| + RefPtr<HyphenationMinikin> hyphenation(adoptRef(new HyphenationMinikin));
|
| + if (hyphenation->openDictionary(std::move(file)))
|
| + return hyphenation.release();
|
| + return nullptr;
|
| +}
|
| +
|
| } // namespace blink
|
|
|