Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(622)

Unified Diff: webkit/support/test_webkit_platform_support.cc

Issue 12335128: Switch from using individual methods for hyphenation to using the WebHyphantor interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/support/test_webkit_platform_support.h ('k') | webkit/support/webkit_support.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/support/test_webkit_platform_support.cc
diff --git a/webkit/support/test_webkit_platform_support.cc b/webkit/support/test_webkit_platform_support.cc
index cb79b7e00f04bb72105c34591c02c116d1877446..68fba188a858dbdada1ebab36a0aff6aded7d88b 100644
--- a/webkit/support/test_webkit_platform_support.cc
+++ b/webkit/support/test_webkit_platform_support.cc
@@ -7,10 +7,8 @@
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
-#include "base/memory/scoped_handle.h"
#include "base/metrics/stats_counters.h"
#include "base/path_service.h"
-#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "cc/thread_impl.h"
#include "media/base/media.h"
@@ -31,7 +29,6 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
-#include "third_party/hyphen/hyphen.h"
#include "v8/include/v8.h"
#include "webkit/appcache/web_application_cache_host_impl.h"
#include "webkit/compositor_bindings/web_compositor_support_impl.h"
@@ -73,8 +70,7 @@ using WebKit::WebScriptController;
TestWebKitPlatformSupport::TestWebKitPlatformSupport(bool unit_test_mode,
WebKit::Platform* shadow_platform_delegate)
: unit_test_mode_(unit_test_mode),
- shadow_platform_delegate_(shadow_platform_delegate),
- hyphen_dictionary_(NULL) {
+ shadow_platform_delegate_(shadow_platform_delegate) {
v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
WebKit::initialize(this);
@@ -137,6 +133,17 @@ TestWebKitPlatformSupport::TestWebKitPlatformSupport(bool unit_test_mode,
DCHECK(file_system_root_.path().empty());
}
+ {
+ // Initialize the hyphen library with a sample dictionary.
+ base::FilePath path = webkit_support::GetChromiumRootDirFilePath();
+ path = path.Append(FILE_PATH_LITERAL("third_party/hyphen/hyph_en_US.dic"));
+ base::PlatformFile dict_file = base::CreatePlatformFile(
+ path,
+ base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
+ NULL, NULL);
+ hyphenator_.LoadDictionary(dict_file);
+ }
+
#if defined(OS_WIN)
// Ensure we pick up the default theme engine.
SetThemeEngine(NULL);
@@ -156,8 +163,6 @@ TestWebKitPlatformSupport::TestWebKitPlatformSupport(bool unit_test_mode,
}
TestWebKitPlatformSupport::~TestWebKitPlatformSupport() {
- if (hyphen_dictionary_)
- hnj_hyphen_free(hyphen_dictionary_);
}
WebKit::WebMimeRegistry* TestWebKitPlatformSupport::mimeRegistry() {
@@ -190,6 +195,10 @@ WebKit::WebFileSystem* TestWebKitPlatformSupport::fileSystem() {
return &file_system_;
}
+WebKit::WebHyphenator* TestWebKitPlatformSupport::hyphenator() {
+ return &hyphenator_;
+}
+
bool TestWebKitPlatformSupport::sandboxEnabled() {
return true;
}
@@ -480,8 +489,7 @@ TestWebKitPlatformSupport::createRTCPeerConnectionHandler(
}
bool TestWebKitPlatformSupport::canHyphenate(const WebKit::WebString& locale) {
- return locale.isEmpty() || locale.equals("en") || locale.equals("en_US") ||
- locale.equals("en_GB");
+ return hyphenator()->canHyphenate(locale);
}
size_t TestWebKitPlatformSupport::computeLastHyphenLocation(
@@ -489,73 +497,8 @@ size_t TestWebKitPlatformSupport::computeLastHyphenLocation(
size_t length,
size_t before_index,
const WebKit::WebString& locale) {
- DCHECK(locale.isEmpty() || locale.equals("en") || locale.equals("en_US") ||
- locale.equals("en_GB"));
- if (!hyphen_dictionary_) {
- // Initialize the hyphen library with a sample dictionary. To avoid test
- // flakiness, this code synchronously loads the dictionary.
- base::FilePath path = webkit_support::GetChromiumRootDirFilePath();
- path = path.Append(FILE_PATH_LITERAL("third_party/hyphen/hyph_en_US.dic"));
- base::PlatformFile dict_file = base::CreatePlatformFile(
- path,
- base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
- NULL, NULL);
- if (dict_file == base::kInvalidPlatformFileValue)
- return 0;
- ScopedStdioHandle dict_handle(base::FdopenPlatformFile(dict_file, "r"));
- if (!dict_handle.get()) {
- base::ClosePlatformFile(dict_file);
- return 0;
- }
- hyphen_dictionary_ = hnj_hyphen_load_file(dict_handle.get());
- if (!hyphen_dictionary_)
- return 0;
- }
- // Retrieve the positions where we can insert hyphens. This function assumes
- // the input word is an English word so it can use the position returned by
- // the hyphen library without conversion.
- string16 word_utf16(characters, length);
- if (!IsStringASCII(word_utf16))
- return 0;
- std::string word = StringToLowerASCII(UTF16ToASCII(word_utf16));
- scoped_array<char> hyphens(new char[word.length() + 5]);
- char** rep = NULL;
- int* pos = NULL;
- int* cut = NULL;
- int error = hnj_hyphen_hyphenate2(hyphen_dictionary_,
- word.data(),
- static_cast<int>(word.length()),
- hyphens.get(),
- NULL,
- &rep,
- &pos,
- &cut);
- if (error)
- return 0;
-
- // Release all resources allocated by the hyphen library now because they are
- // not used when hyphenating English words.
- if (rep) {
- for (size_t i = 0; i < word.length(); ++i) {
- if (rep[i])
- free(rep[i]);
- }
- free(rep);
- }
- if (pos)
- free(pos);
- if (cut)
- free(cut);
-
- // Retrieve the last position where we can insert a hyphen before the given
- // index.
- if (before_index >= 2) {
- for (size_t index = before_index - 2; index > 0; --index) {
- if (hyphens[index] & 1)
- return index + 1;
- }
- }
- return 0;
+ return hyphenator()->computeLastHyphenLocation(
+ characters, length, before_index, locale);
}
WebKit::WebGestureCurve* TestWebKitPlatformSupport::createFlingAnimationCurve(
« no previous file with comments | « webkit/support/test_webkit_platform_support.h ('k') | webkit/support/webkit_support.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698