| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/support/test_webkit_platform_support.h" | 5 #include "webkit/support/test_webkit_platform_support.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/metrics/stats_counters.h" | 8 #include "base/metrics/stats_counters.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 TestWebKitPlatformSupport::createRTCPeerConnectionHandler( | 495 TestWebKitPlatformSupport::createRTCPeerConnectionHandler( |
| 496 WebKit::WebRTCPeerConnectionHandlerClient* client) { | 496 WebKit::WebRTCPeerConnectionHandlerClient* client) { |
| 497 if (shadow_platform_delegate_) | 497 if (shadow_platform_delegate_) |
| 498 return shadow_platform_delegate_->createRTCPeerConnectionHandler(client); | 498 return shadow_platform_delegate_->createRTCPeerConnectionHandler(client); |
| 499 | 499 |
| 500 return webkit_glue::WebKitPlatformSupportImpl::createRTCPeerConnectionHandler( | 500 return webkit_glue::WebKitPlatformSupportImpl::createRTCPeerConnectionHandler( |
| 501 client); | 501 client); |
| 502 } | 502 } |
| 503 | 503 |
| 504 bool TestWebKitPlatformSupport::canHyphenate(const WebKit::WebString& locale) { | 504 bool TestWebKitPlatformSupport::canHyphenate(const WebKit::WebString& locale) { |
| 505 return locale.isEmpty() || locale.equals("en_US"); | 505 return locale.isEmpty() || locale.equals("en") || locale.equals("en_US") || |
| 506 locale.equals("en_GB"); |
| 506 } | 507 } |
| 507 | 508 |
| 508 size_t TestWebKitPlatformSupport::computeLastHyphenLocation( | 509 size_t TestWebKitPlatformSupport::computeLastHyphenLocation( |
| 509 const char16* characters, | 510 const char16* characters, |
| 510 size_t length, | 511 size_t length, |
| 511 size_t before_index, | 512 size_t before_index, |
| 512 const WebKit::WebString& locale) { | 513 const WebKit::WebString& locale) { |
| 513 DCHECK(locale.isEmpty() || locale.equals("en_US")); | 514 DCHECK(locale.isEmpty() || locale.equals("en") || locale.equals("en_US") || |
| 515 locale.equals("en_GB")); |
| 514 if (!hyphen_dictionary_) { | 516 if (!hyphen_dictionary_) { |
| 515 // Initialize the hyphen library with a sample dictionary. To avoid test | 517 // Initialize the hyphen library with a sample dictionary. To avoid test |
| 516 // flakiness, this code synchronously loads the dictionary. | 518 // flakiness, this code synchronously loads the dictionary. |
| 517 FilePath path; | 519 FilePath path; |
| 518 if (!PathService::Get(base::DIR_SOURCE_ROOT, &path)) | 520 if (!PathService::Get(base::DIR_SOURCE_ROOT, &path)) |
| 519 return 0; | 521 return 0; |
| 520 path = path.AppendASCII("third_party"); | 522 path = path.AppendASCII("third_party"); |
| 521 path = path.AppendASCII("hyphen"); | 523 path = path.AppendASCII("hyphen"); |
| 522 path = path.AppendASCII("hyph_en_US.dic"); | 524 path = path.AppendASCII("hyph_en_US.dic"); |
| 523 std::string dictionary; | 525 std::string dictionary; |
| 524 if (!file_util::ReadFileToString(path, &dictionary)) | 526 if (!file_util::ReadFileToString(path, &dictionary)) |
| 525 return 0; | 527 return 0; |
| 526 hyphen_dictionary_ = hnj_hyphen_load( | 528 hyphen_dictionary_ = hnj_hyphen_load( |
| 527 reinterpret_cast<const unsigned char*>(dictionary.data()), | 529 reinterpret_cast<const unsigned char*>(dictionary.data()), |
| 528 dictionary.length()); | 530 dictionary.length()); |
| 529 if (!hyphen_dictionary_) | 531 if (!hyphen_dictionary_) |
| 530 return 0; | 532 return 0; |
| 531 } | 533 } |
| 532 // Retrieve the positions where we can insert hyphens. This function assumes | 534 // Retrieve the positions where we can insert hyphens. This function assumes |
| 533 // the input word is an English word so it can use the position returned by | 535 // the input word is an English word so it can use the position returned by |
| 534 // the hyphen library without conversion. | 536 // the hyphen library without conversion. |
| 535 string16 word_utf16(characters, length); | 537 string16 word_utf16(characters, length); |
| 536 if (!IsStringASCII(word_utf16)) | 538 if (!IsStringASCII(word_utf16)) |
| 537 return 0; | 539 return 0; |
| 538 std::string word = UTF16ToASCII(word_utf16); | 540 std::string word = StringToLowerASCII(UTF16ToASCII(word_utf16)); |
| 539 scoped_array<char> hyphens(new char[word.length() + 5]); | 541 scoped_array<char> hyphens(new char[word.length() + 5]); |
| 540 char** rep = NULL; | 542 char** rep = NULL; |
| 541 int* pos = NULL; | 543 int* pos = NULL; |
| 542 int* cut = NULL; | 544 int* cut = NULL; |
| 543 int error = hnj_hyphen_hyphenate2(hyphen_dictionary_, | 545 int error = hnj_hyphen_hyphenate2(hyphen_dictionary_, |
| 544 word.data(), | 546 word.data(), |
| 545 static_cast<int>(word.length()), | 547 static_cast<int>(word.length()), |
| 546 hyphens.get(), | 548 hyphens.get(), |
| 547 NULL, | 549 NULL, |
| 548 &rep, | 550 &rep, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 568 // Retrieve the last position where we can insert a hyphen before the given | 570 // Retrieve the last position where we can insert a hyphen before the given |
| 569 // index. | 571 // index. |
| 570 if (before_index >= 2) { | 572 if (before_index >= 2) { |
| 571 for (size_t index = before_index - 2; index > 0; --index) { | 573 for (size_t index = before_index - 2; index > 0; --index) { |
| 572 if (hyphens[index] & 1) | 574 if (hyphens[index] & 1) |
| 573 return index + 1; | 575 return index + 1; |
| 574 } | 576 } |
| 575 } | 577 } |
| 576 return 0; | 578 return 0; |
| 577 } | 579 } |
| OLD | NEW |