summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-19 19:17:32 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-19 19:17:32 +0000
commit2a3a7764dc3343682a888f194c59b9ad48729e4b (patch)
treea99a6831e8ae561ff3230b254496aa3705684ef2 /chrome/browser
parent58ce21e623685e1e7b4c97ed7d59fbfb9c8e9801 (diff)
downloadchromium_src-2a3a7764dc3343682a888f194c59b9ad48729e4b.zip
chromium_src-2a3a7764dc3343682a888f194c59b9ad48729e4b.tar.gz
chromium_src-2a3a7764dc3343682a888f194c59b9ad48729e4b.tar.bz2
Convert the spellchecker and associated messages and functions to use string16
for words instead of wstring. I also changed some places where it converted the word to a string to do that conversion at the last possible second before giving it to Hunspell (since this conversion isn't needed for Mac). TEST=Covered by unit tests BUG=none Review URL: http://codereview.chromium.org/274077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29435 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc2
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.h2
-rw-r--r--chrome/browser/renderer_host/mock_render_process_host.cc2
-rw-r--r--chrome/browser/renderer_host/mock_render_process_host.h2
-rw-r--r--chrome/browser/renderer_host/render_process_host.h2
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc6
-rw-r--r--chrome/browser/renderer_host/render_view_host.h3
-rw-r--r--chrome/browser/renderer_host/render_widget_host.cc2
-rw-r--r--chrome/browser/renderer_host/render_widget_host.h3
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_mac.mm6
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc13
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h7
-rw-r--r--chrome/browser/spellcheck_unittest.cc136
-rw-r--r--chrome/browser/spellchecker.cc62
-rw-r--r--chrome/browser/spellchecker.h17
-rw-r--r--chrome/browser/spellchecker_linux.cc23
-rw-r--r--chrome/browser/spellchecker_mac.mm29
-rw-r--r--chrome/browser/spellchecker_platform_engine.h19
-rw-r--r--chrome/browser/spellchecker_win.cc24
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc4
20 files changed, 183 insertions, 181 deletions
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index 8ad39ad..7831ab5 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -401,7 +401,7 @@ void BrowserRenderProcessHost::WidgetHidden() {
}
}
-void BrowserRenderProcessHost::AddWord(const std::wstring& word) {
+void BrowserRenderProcessHost::AddWord(const string16& word) {
base::Thread* io_thread = g_browser_process->io_thread();
SpellChecker* spellchecker = profile()->GetSpellChecker();
if (spellchecker) {
diff --git a/chrome/browser/renderer_host/browser_render_process_host.h b/chrome/browser/renderer_host/browser_render_process_host.h
index 367b19c..b7c6803 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.h
+++ b/chrome/browser/renderer_host/browser_render_process_host.h
@@ -65,7 +65,7 @@ class BrowserRenderProcessHost : public RenderProcessHost,
virtual void WidgetRestored();
virtual void WidgetHidden();
virtual void ViewCreated();
- virtual void AddWord(const std::wstring& word);
+ virtual void AddWord(const string16& word);
virtual void AddVisitedLinks(const VisitedLinkCommon::Fingerprints& links);
virtual void ResetVisitedLinks();
virtual bool FastShutdownIfPossible();
diff --git a/chrome/browser/renderer_host/mock_render_process_host.cc b/chrome/browser/renderer_host/mock_render_process_host.cc
index 37c60bf..8e3dd3f 100644
--- a/chrome/browser/renderer_host/mock_render_process_host.cc
+++ b/chrome/browser/renderer_host/mock_render_process_host.cc
@@ -49,7 +49,7 @@ void MockRenderProcessHost::WidgetHidden() {
void MockRenderProcessHost::ViewCreated() {
}
-void MockRenderProcessHost::AddWord(const std::wstring& word) {
+void MockRenderProcessHost::AddWord(const string16& word) {
}
void MockRenderProcessHost::AddVisitedLinks(
diff --git a/chrome/browser/renderer_host/mock_render_process_host.h b/chrome/browser/renderer_host/mock_render_process_host.h
index 6d24cf6..e28ac68 100644
--- a/chrome/browser/renderer_host/mock_render_process_host.h
+++ b/chrome/browser/renderer_host/mock_render_process_host.h
@@ -41,7 +41,7 @@ class MockRenderProcessHost : public RenderProcessHost {
virtual void WidgetRestored();
virtual void WidgetHidden();
virtual void ViewCreated();
- virtual void AddWord(const std::wstring& word);
+ virtual void AddWord(const string16& word);
virtual void AddVisitedLinks(
const VisitedLinkCommon::Fingerprints& visited_links);
virtual void ResetVisitedLinks();
diff --git a/chrome/browser/renderer_host/render_process_host.h b/chrome/browser/renderer_host/render_process_host.h
index 4014b63..5c15b1c 100644
--- a/chrome/browser/renderer_host/render_process_host.h
+++ b/chrome/browser/renderer_host/render_process_host.h
@@ -173,7 +173,7 @@ class RenderProcessHost : public IPC::Channel::Sender,
virtual void ViewCreated() = 0;
// Add a word in the spellchecker.
- virtual void AddWord(const std::wstring& word) = 0;
+ virtual void AddWord(const string16& word) = 0;
// Notify the renderer that a link was visited.
virtual void AddVisitedLinks(
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index d8b86a7..8465992 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -530,15 +530,11 @@ void RenderViewHost::Paste() {
Send(new ViewMsg_Paste(routing_id()));
}
-void RenderViewHost::Replace(const std::wstring& text_to_replace) {
- Send(new ViewMsg_Replace(routing_id(), text_to_replace));
-}
-
void RenderViewHost::ToggleSpellCheck() {
Send(new ViewMsg_ToggleSpellCheck(routing_id()));
}
-void RenderViewHost::AddToDictionary(const std::wstring& word) {
+void RenderViewHost::AddToDictionary(const string16& word) {
process()->AddWord(word);
}
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index f6c1733..6d6104a 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -274,9 +274,8 @@ class RenderViewHost : public RenderWidgetHost,
void Copy();
void CopyToFindPboard();
void Paste();
- void Replace(const std::wstring& text);
void ToggleSpellCheck();
- void AddToDictionary(const std::wstring& word);
+ void AddToDictionary(const string16& word);
void Delete();
void SelectAll();
void ToggleSpellPanel(bool is_currently_visible);
diff --git a/chrome/browser/renderer_host/render_widget_host.cc b/chrome/browser/renderer_host/render_widget_host.cc
index c1ddaef..6d2b4bd 100644
--- a/chrome/browser/renderer_host/render_widget_host.cc
+++ b/chrome/browser/renderer_host/render_widget_host.cc
@@ -894,7 +894,7 @@ void RenderWidgetHost::ToggleSpellPanel(bool is_currently_visible) {
Send(new ViewMsg_ToggleSpellPanel(routing_id(), is_currently_visible));
}
-void RenderWidgetHost::ReplaceWord(const std::wstring& word) {
+void RenderWidgetHost::Replace(const string16& word) {
Send(new ViewMsg_Replace(routing_id_, word));
}
diff --git a/chrome/browser/renderer_host/render_widget_host.h b/chrome/browser/renderer_host/render_widget_host.h
index 27bf238..01fce6c 100644
--- a/chrome/browser/renderer_host/render_widget_host.h
+++ b/chrome/browser/renderer_host/render_widget_host.h
@@ -11,6 +11,7 @@
#include "base/process.h"
#include "base/gfx/size.h"
#include "base/scoped_ptr.h"
+#include "base/string16.h"
#include "base/timer.h"
#include "chrome/common/edit_command.h"
#include "chrome/common/native_web_keyboard_event.h"
@@ -334,7 +335,7 @@ class RenderWidgetHost : public IPC::Channel::Listener,
void ToggleSpellPanel(bool is_currently_visible);
// Makes an IPC call to tell webkit to replace the currently selected word.
- void ReplaceWord(const std::wstring& word);
+ void Replace(const string16& word);
// Makes an IPC call to tell webkit to advance to the next misspelling.
void AdvanceToNextMisspelling();
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
index 7709790..4df230e 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
@@ -795,8 +795,8 @@ void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) {
NSString* newWord = [[sender selectedCell] stringValue];
if (newWord != nil) {
RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac];
- thisHostView->GetRenderWidgetHost()->ReplaceWord(
- base::SysNSStringToWide(newWord));
+ thisHostView->GetRenderWidgetHost()->Replace(
+ base::SysNSStringToUTF16(newWord));
}
}
@@ -819,7 +819,7 @@ void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) {
// SpellCheckerPlatform::IgnoreWord assumes that is the correct tag.
NSString* wordToIgnore = [sender stringValue];
if (wordToIgnore != nil) {
- SpellCheckerPlatform::IgnoreWord(base::SysNSStringToUTF8(wordToIgnore));
+ SpellCheckerPlatform::IgnoreWord(base::SysNSStringToUTF16(wordToIgnore));
// Strangely, the spellingPanel doesn't send checkSpelling after a word is
// ignored, so we have to explicitly call AdvanceToNextMisspelling here.
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index da1e8ad..5d2efab 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -936,7 +936,7 @@ Clipboard* ResourceMessageFilter::GetClipboard() {
// spellings are correct.
//
// Note: This is called in the IO thread.
-void ResourceMessageFilter::OnSpellCheck(const std::wstring& word, int tag,
+void ResourceMessageFilter::OnSpellCheck(const string16& word, int tag,
IPC::Message* reply_msg) {
int misspell_location = 0;
int misspell_length = 0;
@@ -964,13 +964,12 @@ void ResourceMessageFilter::OnDocumentWithTagClosed(int tag) {
SpellCheckerPlatform::CloseDocumentWithTag(tag);
}
-void ResourceMessageFilter::OnGetAutoCorrectWord(const std::wstring& word,
+void ResourceMessageFilter::OnGetAutoCorrectWord(const string16& word,
int tag,
IPC::Message* reply_msg) {
- std::wstring autocorrect_word;
- if (spellchecker_ != NULL) {
- spellchecker_->GetAutoCorrectionWord(word, tag, &autocorrect_word);
- }
+ string16 autocorrect_word;
+ if (spellchecker_ != NULL)
+ autocorrect_word = spellchecker_->GetAutoCorrectionWord(word, tag);
ViewHostMsg_GetAutoCorrectWord::WriteReplyParams(reply_msg,
autocorrect_word);
@@ -983,7 +982,7 @@ void ResourceMessageFilter::OnShowSpellingPanel(bool show) {
}
void ResourceMessageFilter::OnUpdateSpellingPanelWithMisspelledWord(
- const std::wstring& word) {
+ const string16& word) {
SpellCheckerPlatform::UpdateSpellingPanelWithMisspelledWord(word);
}
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index 34a17f3..02c934f 100644
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -166,14 +166,13 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
void OnDownloadUrl(const IPC::Message& message,
const GURL& url,
const GURL& referrer);
- void OnSpellCheck(const std::wstring& word, int tag,
- IPC::Message* reply_msg);
+ void OnSpellCheck(const string16& word, int tag, IPC::Message* reply_msg);
void OnGetDocumentTag(IPC::Message* reply_msg);
void OnDocumentWithTagClosed(int tag);
- void OnGetAutoCorrectWord(const std::wstring& word, int tag,
+ void OnGetAutoCorrectWord(const string16& word, int tag,
IPC::Message* reply_msg);
void OnShowSpellingPanel(bool show);
- void OnUpdateSpellingPanelWithMisspelledWord(const std::wstring& word);
+ void OnUpdateSpellingPanelWithMisspelledWord(const string16& word);
void OnDnsPrefetch(const std::vector<std::string>& hostnames);
void OnRendererHistograms(int sequence_number,
const std::vector<std::string>& histogram_info);
diff --git a/chrome/browser/spellcheck_unittest.cc b/chrome/browser/spellcheck_unittest.cc
index d328ed6..d57f15c 100644
--- a/chrome/browser/spellcheck_unittest.cc
+++ b/chrome/browser/spellcheck_unittest.cc
@@ -82,7 +82,6 @@ TEST_F(SpellCheckTest, SpellCheckStrings_EN_US) {
int misspelling_length;
} kTestCases[] = {
// Empty strings.
- {NULL, true, 0, 0},
{L"", true, 0, 0},
{L" ", true, 0, 0},
{L"\xA0", true, 0, 0},
@@ -280,11 +279,12 @@ TEST_F(SpellCheckTest, SpellCheckStrings_EN_US) {
}
int misspelling_start;
int misspelling_length;
- bool result = spell_checker->SpellCheckWord(kTestCases[i].input,
- static_cast<int>(input_length),
- 0,
- &misspelling_start,
- &misspelling_length, NULL);
+ bool result = spell_checker->SpellCheckWord(
+ WideToUTF16(kTestCases[i].input).c_str(),
+ static_cast<int>(input_length),
+ 0,
+ &misspelling_start,
+ &misspelling_length, NULL);
EXPECT_EQ(kTestCases[i].expected_result, result);
EXPECT_EQ(kTestCases[i].misspelling_start, misspelling_start);
@@ -618,19 +618,20 @@ TEST_F(SpellCheckTest, SpellCheckSuggestions_EN_US) {
hunspell_directory, "en-US", NULL, FilePath()));
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
- std::vector<std::wstring> suggestions;
+ std::vector<string16> suggestions;
size_t input_length = 0;
if (kTestCases[i].input != NULL) {
input_length = wcslen(kTestCases[i].input);
}
int misspelling_start;
int misspelling_length;
- bool result = spell_checker->SpellCheckWord(kTestCases[i].input,
- static_cast<int>(input_length),
- 0,
- &misspelling_start,
- &misspelling_length,
- &suggestions);
+ bool result = spell_checker->SpellCheckWord(
+ WideToUTF16(kTestCases[i].input).c_str(),
+ static_cast<int>(input_length),
+ 0,
+ &misspelling_start,
+ &misspelling_length,
+ &suggestions);
// Check for spelling.
EXPECT_EQ(kTestCases[i].expected_result, result);
@@ -638,7 +639,8 @@ TEST_F(SpellCheckTest, SpellCheckSuggestions_EN_US) {
// Check if the suggested words occur.
bool suggested_word_is_present = false;
for (int j=0; j < static_cast<int>(suggestions.size()); j++) {
- if (suggestions.at(j).compare(kTestCases[i].suggested_word) == 0) {
+ if (suggestions.at(j).compare(WideToUTF16(kTestCases[i].suggested_word))
+ == 0) {
suggested_word_is_present = true;
break;
}
@@ -894,11 +896,12 @@ TEST_F(SpellCheckTest, SpellCheckText) {
int misspelling_start = 0;
int misspelling_length = 0;
- bool result = spell_checker->SpellCheckWord(kTestCases[i].input,
- static_cast<int>(input_length),
- 0,
- &misspelling_start,
- &misspelling_length, NULL);
+ bool result = spell_checker->SpellCheckWord(
+ WideToUTF16(kTestCases[i].input).c_str(),
+ static_cast<int>(input_length),
+ 0,
+ &misspelling_start,
+ &misspelling_length, NULL);
EXPECT_EQ(true, result) << kTestCases[i].language;
EXPECT_EQ(0, misspelling_start);
@@ -926,22 +929,23 @@ TEST_F(SpellCheckTest, DISABLED_SpellCheckAddToDictionary_EN_US) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
// Add the word to spellchecker.
- spell_checker->AddWord(std::wstring(kTestCases[i].word_to_add));
+ spell_checker->AddWord(WideToUTF16(kTestCases[i].word_to_add));
// Now check whether it is added to Spellchecker.
- std::vector<std::wstring> suggestions;
+ std::vector<string16> suggestions;
size_t input_length = 0;
if (kTestCases[i].word_to_add != NULL) {
input_length = wcslen(kTestCases[i].word_to_add);
}
int misspelling_start;
int misspelling_length;
- bool result = spell_checker->SpellCheckWord(kTestCases[i].word_to_add,
- static_cast<int>(input_length),
- 0,
- &misspelling_start,
- &misspelling_length,
- &suggestions);
+ bool result = spell_checker->SpellCheckWord(
+ WideToUTF16(kTestCases[i].word_to_add).c_str(),
+ static_cast<int>(input_length),
+ 0,
+ &misspelling_start,
+ &misspelling_length,
+ &suggestions);
// Check for spelling.
EXPECT_TRUE(result);
@@ -953,7 +957,7 @@ TEST_F(SpellCheckTest, DISABLED_SpellCheckAddToDictionary_EN_US) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
// Now check whether it is added to Spellchecker.
- std::vector<std::wstring> suggestions;
+ std::vector<string16> suggestions;
size_t input_length = 0;
if (kTestCases[i].word_to_add != NULL) {
input_length = wcslen(kTestCases[i].word_to_add);
@@ -961,7 +965,7 @@ TEST_F(SpellCheckTest, DISABLED_SpellCheckAddToDictionary_EN_US) {
int misspelling_start;
int misspelling_length;
bool result = spell_checker_new->SpellCheckWord(
- kTestCases[i].word_to_add,
+ WideToUTF16(kTestCases[i].word_to_add).c_str(),
static_cast<int>(input_length),
0,
&misspelling_start,
@@ -996,7 +1000,7 @@ TEST_F(SpellCheckTest, DISABLED_SpellCheckSuggestionsAddToDictionary_EN_US) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
// Add the word to spellchecker.
- spell_checker->AddWord(std::wstring(kTestCases[i].word_to_add));
+ spell_checker->AddWord(WideToUTF16(kTestCases[i].word_to_add));
}
// Now check to see whether the custom words are suggested for
@@ -1021,19 +1025,20 @@ TEST_F(SpellCheckTest, DISABLED_SpellCheckSuggestionsAddToDictionary_EN_US) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCasesToBeTested); ++i) {
- std::vector<std::wstring> suggestions;
+ std::vector<string16> suggestions;
size_t input_length = 0;
if (kTestCasesToBeTested[i].input != NULL) {
input_length = wcslen(kTestCasesToBeTested[i].input);
}
int misspelling_start;
int misspelling_length;
- bool result = spell_checker->SpellCheckWord(kTestCasesToBeTested[i].input,
- static_cast<int>(input_length),
- 0,
- &misspelling_start,
- &misspelling_length,
- &suggestions);
+ bool result = spell_checker->SpellCheckWord(
+ WideToUTF16(kTestCasesToBeTested[i].input).c_str(),
+ static_cast<int>(input_length),
+ 0,
+ &misspelling_start,
+ &misspelling_length,
+ &suggestions);
// Check for spelling.
EXPECT_EQ(result, kTestCasesToBeTested[i].expected_result);
@@ -1041,8 +1046,9 @@ TEST_F(SpellCheckTest, DISABLED_SpellCheckSuggestionsAddToDictionary_EN_US) {
// Check if the suggested words occur.
bool suggested_word_is_present = false;
for (int j=0; j < static_cast<int>(suggestions.size()); j++) {
- if (suggestions.at(j).compare(kTestCasesToBeTested[i].suggested_word) ==
- 0) {
+ if (suggestions.at(j).compare(
+ WideToUTF16(kTestCasesToBeTested[i].suggested_word)) ==
+ 0) {
suggested_word_is_present = true;
break;
}
@@ -1058,17 +1064,17 @@ TEST_F(SpellCheckTest, DISABLED_SpellCheckSuggestionsAddToDictionary_EN_US) {
TEST_F(SpellCheckTest, GetAutoCorrectionWord_EN_US) {
static const struct {
// A misspelled word.
- const wchar_t* input;
+ const char* input;
// An expected result for this test case.
// Should be an empty string if there are no suggestions for auto correct.
- const wchar_t* expected_result;
+ const char* expected_result;
} kTestCases[] = {
- {L"teh", L"the"},
- {L"moer", L"more"},
- {L"watre", L"water"},
- {L"noen", L""},
- {L"what", L""},
+ {"teh", "the"},
+ {"moer", "more"},
+ {"watre", "water"},
+ {"noen", ""},
+ {"what", ""},
};
FilePath hunspell_directory = GetHunspellDirectory();
@@ -1079,10 +1085,11 @@ TEST_F(SpellCheckTest, GetAutoCorrectionWord_EN_US) {
spell_checker->EnableAutoSpellCorrect(true);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
- std::wstring misspelled_word(kTestCases[i].input);
- std::wstring expected_autocorrect_word(kTestCases[i].expected_result);
- std::wstring autocorrect_word;
- spell_checker->GetAutoCorrectionWord(misspelled_word, 0, &autocorrect_word);
+ string16 misspelled_word(UTF8ToUTF16(kTestCases[i].input));
+ string16 expected_autocorrect_word(
+ UTF8ToUTF16(kTestCases[i].expected_result));
+ string16 autocorrect_word = spell_checker->GetAutoCorrectionWord(
+ misspelled_word, 0);
// Check for spelling.
EXPECT_EQ(expected_autocorrect_word, autocorrect_word);
@@ -1097,14 +1104,14 @@ TEST_F(SpellCheckTest, GetAutoCorrectionWord_EN_US) {
TEST_F(SpellCheckTest, IgnoreWords_EN_US) {
static const struct {
// A misspelled word.
- const wchar_t* input;
+ const char* input;
bool input_result;
- } kTestCases[] = {
- {L"teh", false},
- {L"moer", false},
- {L"watre", false},
- {L"noen", false},
- };
+ } kTestCases[] = {
+ {"teh", false},
+ {"moer", false},
+ {"watre", false},
+ {"noen", false},
+ };
FilePath hunspell_directory = GetHunspellDirectory();
ASSERT_FALSE(hunspell_directory.empty());
@@ -1113,18 +1120,17 @@ TEST_F(SpellCheckTest, IgnoreWords_EN_US) {
hunspell_directory, "en-US", NULL, FilePath()));
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
- std::wstring word(kTestCases[i].input);
- std::string misspelled_word = base::SysWideToUTF8(word);
- std::vector<std::wstring> suggestions;
+ string16 word(UTF8ToUTF16(kTestCases[i].input));
+ std::vector<string16> suggestions;
size_t input_length = 0;
if (kTestCases[i].input != NULL) {
- input_length = wcslen(kTestCases[i].input);
+ input_length = word.length();
}
int misspelling_start;
int misspelling_length;
int doc_tag = SpellCheckerPlatform::GetDocumentTag();
- bool result = spell_checker->SpellCheckWord(kTestCases[i].input,
+ bool result = spell_checker->SpellCheckWord(word.c_str(),
static_cast<int>(input_length),
doc_tag,
&misspelling_start,
@@ -1135,10 +1141,10 @@ TEST_F(SpellCheckTest, IgnoreWords_EN_US) {
EXPECT_EQ(kTestCases[i].input_result, result);
// Ignore the word.
- SpellCheckerPlatform::IgnoreWord(misspelled_word);
+ SpellCheckerPlatform::IgnoreWord(word);
// Spellcheck again.
- result = spell_checker->SpellCheckWord(kTestCases[i].input,
+ result = spell_checker->SpellCheckWord(word.c_str(),
static_cast<int>(input_length),
doc_tag,
&misspelling_start,
@@ -1153,7 +1159,7 @@ TEST_F(SpellCheckTest, IgnoreWords_EN_US) {
SpellCheckerPlatform::CloseDocumentWithTag(doc_tag);
// Spellcheck one more time.
- result = spell_checker->SpellCheckWord(kTestCases[i].input,
+ result = spell_checker->SpellCheckWord(word.c_str(),
static_cast<int>(input_length),
doc_tag,
&misspelling_start,
diff --git a/chrome/browser/spellchecker.cc b/chrome/browser/spellchecker.cc
index 128c7f3..6df9c7e 100644
--- a/chrome/browser/spellchecker.cc
+++ b/chrome/browser/spellchecker.cc
@@ -662,18 +662,17 @@ void SpellChecker::DoDictionaryDownload() {
}
}
-void SpellChecker::GetAutoCorrectionWord(const std::wstring& word, int tag,
- std::wstring* autocorrect_word) {
- autocorrect_word->clear();
+string16 SpellChecker::GetAutoCorrectionWord(const string16& word, int tag) {
+ string16 autocorrect_word;
if (!auto_spell_correct_turned_on_)
- return;
+ return autocorrect_word; // Return the empty string.
int word_length = static_cast<int>(word.size());
if (word_length < 2 || word_length > kMaxAutoCorrectWordSize)
- return;
+ return autocorrect_word;
- wchar_t misspelled_word[kMaxAutoCorrectWordSize + 1];
- const wchar_t* word_char = word.c_str();
+ char16 misspelled_word[kMaxAutoCorrectWordSize + 1];
+ const char16* word_char = word.c_str();
for (int i = 0; i <= kMaxAutoCorrectWordSize; i++) {
if (i >= word_length)
misspelled_word[i] = NULL;
@@ -695,17 +694,18 @@ void SpellChecker::GetAutoCorrectionWord(const std::wstring& word, int tag,
// Make decision: if only one swap produced a valid word, then we want to
// return it. If we found two or more, we don't do autocorrection.
if (misspelling_len == 0) {
- if (autocorrect_word->empty()) {
- autocorrect_word->assign(misspelled_word);
+ if (autocorrect_word.empty()) {
+ autocorrect_word.assign(misspelled_word);
} else {
- autocorrect_word->clear();
- return;
+ autocorrect_word.clear();
+ break;
}
}
// Restore the swapped characters.
std::swap(misspelled_word[i], misspelled_word[i + 1]);
}
+ return autocorrect_word;
}
void SpellChecker::EnableAutoSpellCorrect(bool turn_on) {
@@ -725,19 +725,19 @@ bool SpellChecker::IsValidContraction(const string16& contraction, int tag) {
int word_start;
int word_length;
while (word_iterator.GetNextWord(&word, &word_start, &word_length)) {
- if (!CheckSpelling(UTF16ToUTF8(word), tag))
+ if (!CheckSpelling(word, tag))
return false;
}
return true;
}
bool SpellChecker::SpellCheckWord(
- const wchar_t* in_word,
+ const char16* in_word,
int in_word_len,
int tag,
int* misspelling_start,
int* misspelling_len,
- std::vector<std::wstring>* optional_suggestions) {
+ std::vector<string16>* optional_suggestions) {
DCHECK(in_word_len >= 0);
DCHECK(misspelling_start && misspelling_len) << "Out vars must be given.";
@@ -764,17 +764,13 @@ bool SpellChecker::SpellCheckWord(
SpellcheckWordIterator word_iterator;
string16 word;
- string16 in_word_utf16;
- WideToUTF16(in_word, in_word_len, &in_word_utf16);
int word_start;
int word_length;
- word_iterator.Initialize(&character_attributes_, in_word_utf16.c_str(),
- in_word_len, true);
+ word_iterator.Initialize(&character_attributes_, in_word, in_word_len, true);
while (word_iterator.GetNextWord(&word, &word_start, &word_length)) {
// Found a word (or a contraction) that the spellchecker can check the
// spelling of.
- std::string encoded_word = UTF16ToUTF8(word);
- bool word_ok = CheckSpelling(encoded_word, tag);
+ bool word_ok = CheckSpelling(word, tag);
if (word_ok)
continue;
@@ -787,9 +783,8 @@ bool SpellChecker::SpellCheckWord(
*misspelling_len = word_length;
// Get the list of suggested words.
- if (optional_suggestions) {
- FillSuggestionList(encoded_word, optional_suggestions);
- }
+ if (optional_suggestions)
+ FillSuggestionList(word, optional_suggestions);
return false;
}
@@ -801,9 +796,9 @@ bool SpellChecker::SpellCheckWord(
class AddWordToCustomDictionaryTask : public Task {
public:
AddWordToCustomDictionaryTask(const FilePath& file_name,
- const std::wstring& word)
+ const string16& word)
: file_name_(file_name),
- word_(WideToUTF8(word)) {
+ word_(UTF16ToUTF8(word)) {
}
private:
@@ -825,7 +820,7 @@ void AddWordToCustomDictionaryTask::Run() {
file_util::CloseFile(f);
}
-void SpellChecker::AddWord(const std::wstring& word) {
+void SpellChecker::AddWord(const string16& word) {
if (is_using_platform_spelling_engine_) {
SpellCheckerPlatform::AddWord(word);
return;
@@ -835,7 +830,7 @@ void SpellChecker::AddWord(const std::wstring& word) {
Initialize();
// Add the word to hunspell.
- std::string word_to_add = WideToUTF8(word);
+ std::string word_to_add = UTF16ToUTF8(word);
if (!word_to_add.empty()) {
// Either add the word to |hunspell_|, or, if |hunspell_| is still loading,
// defer it till after the load completes.
@@ -856,7 +851,7 @@ void SpellChecker::AddWord(const std::wstring& word) {
}
}
-bool SpellChecker::CheckSpelling(const std::string& word_to_check, int tag) {
+bool SpellChecker::CheckSpelling(const string16& word_to_check, int tag) {
bool word_correct = false;
TimeTicks begin_time = TimeTicks::Now();
@@ -865,15 +860,16 @@ bool SpellChecker::CheckSpelling(const std::string& word_to_check, int tag) {
} else {
// |hunspell_->spell| returns 0 if the word is spelled correctly and
// non-zero otherwsie.
- word_correct = (hunspell_->spell(word_to_check.c_str()) != 0);
+ word_correct = (hunspell_->spell(UTF16ToUTF8(word_to_check).c_str()) != 0);
}
DHISTOGRAM_TIMES("Spellcheck.CheckTime", TimeTicks::Now() - begin_time);
return word_correct;
}
-void SpellChecker::FillSuggestionList(const std::string& wrong_word,
- std::vector<std::wstring>* optional_suggestions) {
+void SpellChecker::FillSuggestionList(
+ const string16& wrong_word,
+ std::vector<string16>* optional_suggestions) {
if (is_using_platform_spelling_engine_) {
SpellCheckerPlatform::FillSuggestionList(wrong_word, optional_suggestions);
return;
@@ -881,14 +877,14 @@ void SpellChecker::FillSuggestionList(const std::string& wrong_word,
char** suggestions;
TimeTicks begin_time = TimeTicks::Now();
int number_of_suggestions = hunspell_->suggest(&suggestions,
- wrong_word.c_str());
+ UTF16ToUTF8(wrong_word).c_str());
DHISTOGRAM_TIMES("Spellcheck.SuggestTime",
TimeTicks::Now() - begin_time);
// Populate the vector of WideStrings.
for (int i = 0; i < number_of_suggestions; i++) {
if (i < kMaxSuggestions)
- optional_suggestions->push_back(UTF8ToWide(suggestions[i]));
+ optional_suggestions->push_back(UTF8ToUTF16(suggestions[i]));
free(suggestions[i]);
}
if (suggestions != NULL)
diff --git a/chrome/browser/spellchecker.h b/chrome/browser/spellchecker.h
index a8acafd..1a78f61 100644
--- a/chrome/browser/spellchecker.h
+++ b/chrome/browser/spellchecker.h
@@ -10,7 +10,7 @@
#include <vector>
#include "app/l10n_util.h"
-#include "base/string_util.h"
+#include "base/string16.h"
#include "base/task.h"
#include "base/time.h"
#include "chrome/browser/browser_process.h"
@@ -72,18 +72,17 @@ class SpellChecker : public base::RefCountedThreadSafe<SpellChecker>,
// If the word is spelled correctly, the vector is empty.
// If optional_suggestions is NULL, suggested words will not be looked up.
// Note that Doing suggest lookups can be slow.
- bool SpellCheckWord(const wchar_t* in_word,
+ bool SpellCheckWord(const char16* in_word,
int in_word_len,
int tag,
int* misspelling_start,
int* misspelling_len,
- std::vector<std::wstring>* optional_suggestions);
+ std::vector<string16>* optional_suggestions);
// Find a possible correctly spelled word for a misspelled word. Computes an
// empty string if input misspelled word is too long, there is ambiguity, or
// the correct spelling cannot be determined.
- void GetAutoCorrectionWord(const std::wstring& word, int tag,
- std::wstring* autocorrect_word);
+ string16 GetAutoCorrectionWord(const string16& word, int tag);
// Turn auto spell correct support ON or OFF.
// |turn_on| = true means turn ON; false means turn OFF.
@@ -92,7 +91,7 @@ class SpellChecker : public base::RefCountedThreadSafe<SpellChecker>,
// Add custom word to the dictionary, which means:
// a) Add it to the current hunspell object for immediate use,
// b) Add the word to a file in disk for custom dictionary.
- void AddWord(const std::wstring& word);
+ void AddWord(const string16& word);
// Get SpellChecker supported languages.
static void SpellCheckLanguages(std::vector<std::string>* languages);
@@ -129,12 +128,12 @@ class SpellChecker : public base::RefCountedThreadSafe<SpellChecker>,
// When called, relays the request to check the spelling to the proper
// backend, either hunspell or a platform-specific backend.
- bool CheckSpelling(const std::string& word_to_check, int tag);
+ bool CheckSpelling(const string16& word_to_check, int tag);
// When called, relays the request to fill the list with suggestions to
// the proper backend, either hunspell or a platform-specific backend.
- void FillSuggestionList(const std::string& wrong_word,
- std::vector<std::wstring>* optional_suggestions);
+ void FillSuggestionList(const string16& wrong_word,
+ std::vector<string16>* optional_suggestions);
// Initializes the Hunspell Dictionary.
bool Initialize();
diff --git a/chrome/browser/spellchecker_linux.cc b/chrome/browser/spellchecker_linux.cc
index 1596b50..9f0f144 100644
--- a/chrome/browser/spellchecker_linux.cc
+++ b/chrome/browser/spellchecker_linux.cc
@@ -5,6 +5,7 @@
// If linux ever gains a platform specific spellchecker, it will be
// implemented here.
+#include "base/string16.h"
#include "chrome/browser/spellchecker_common.h"
namespace SpellCheckerPlatform {
@@ -32,29 +33,29 @@ bool SpellingPanelVisible() {
return false;
}
-void ShowSpellingPanel(bool show) { }
+void ShowSpellingPanel(bool show) {}
-void UpdateSpellingPanelWithMisspelledWord(const std::wstring& word) { }
+void UpdateSpellingPanelWithMisspelledWord(const string16& word) {}
-void Init() { }
+void Init() {}
-void SetLanguage(const std::string& lang_to_set) { }
+void SetLanguage(const std::string& lang_to_set) {}
-bool CheckSpelling(const std::string& word_to_check, int tag) {
+bool CheckSpelling(const string16& word_to_check, int tag) {
return false;
}
-void FillSuggestionList(const std::string& wrong_word,
- std::vector<std::wstring>* optional_suggestions) { }
+void FillSuggestionList(const string16& wrong_word,
+ std::vector<string16>* optional_suggestions) {}
-void AddWord(const std::wstring& word) { }
+void AddWord(const string16& word) {}
-void RemoveWord(const std::wstring& word) { }
+void RemoveWord(const string16& word) {}
int GetDocumentTag() { return 0; }
-void IgnoreWord(const std::string& word) { }
+void IgnoreWord(const std::string& word) {}
-void CloseDocumentWithTag(int tag) { }
+void CloseDocumentWithTag(int tag) {}
} // namespace SpellCheckerPlatform
diff --git a/chrome/browser/spellchecker_mac.mm b/chrome/browser/spellchecker_mac.mm
index 0a4d52e..99b20a7 100644
--- a/chrome/browser/spellchecker_mac.mm
+++ b/chrome/browser/spellchecker_mac.mm
@@ -113,8 +113,8 @@ void ShowSpellingPanel(bool show) {
}
}
-void UpdateSpellingPanelWithMisspelledWord(const std::wstring& word) {
- NSString * word_to_display = base::SysWideToNSString(word);
+void UpdateSpellingPanelWithMisspelledWord(const string16& word) {
+ NSString * word_to_display = base::SysUTF16ToNSString(word);
[[NSSpellChecker sharedSpellChecker]
updateSpellingPanelWithMisspelledWord:word_to_display];
}
@@ -142,7 +142,7 @@ void SetLanguage(const std::string& lang_to_set) {
static int last_seen_tag_;
-bool CheckSpelling(const std::string& word_to_check, int tag) {
+bool CheckSpelling(const string16& word_to_check, int tag) {
last_seen_tag_ = tag;
// [[NSSpellChecker sharedSpellChecker] checkSpellingOfString] returns an
@@ -150,7 +150,7 @@ bool CheckSpelling(const std::string& word_to_check, int tag) {
NSRange spell_range = {0,0};
// Convert the word to an NSString.
- NSString* NS_word_to_check = base::SysUTF8ToNSString(word_to_check);
+ NSString* NS_word_to_check = base::SysUTF16ToNSString(word_to_check);
// Check the spelling, starting at the beginning of the word.
spell_range = [[NSSpellChecker sharedSpellChecker]
checkSpellingOfString:NS_word_to_check startingAt:0
@@ -163,9 +163,9 @@ bool CheckSpelling(const std::string& word_to_check, int tag) {
return word_correct;
}
-void FillSuggestionList(const std::string& wrong_word,
- std::vector<std::wstring>* optional_suggestions) {
- NSString* NS_wrong_word = base::SysUTF8ToNSString(wrong_word);
+void FillSuggestionList(const string16& wrong_word,
+ std::vector<string16>* optional_suggestions) {
+ NSString* NS_wrong_word = base::SysUTF16ToNSString(wrong_word);
TimeTicks begin_time = TimeTicks::Now();
// The suggested words for |wrong_word|.
NSArray* guesses =
@@ -175,19 +175,19 @@ void FillSuggestionList(const std::string& wrong_word,
for (int i = 0; i < static_cast<int>([guesses count]); i++) {
if (i < kMaxSuggestions) {
- optional_suggestions->push_back(base::SysNSStringToWide(
+ optional_suggestions->push_back(base::SysNSStringToUTF16(
[guesses objectAtIndex:i]));
}
}
}
-void AddWord(const std::wstring& word) {
- NSString* word_to_add = base::SysWideToNSString(word);
+void AddWord(const string16& word) {
+ NSString* word_to_add = base::SysUTF16ToNSString(word);
[[NSSpellChecker sharedSpellChecker] learnWord:word_to_add];
}
-void RemoveWord(const std::wstring& word) {
- NSString *word_to_remove = base::SysWideToNSString(word);
+void RemoveWord(const string16& word) {
+ NSString *word_to_remove = base::SysUTF16ToNSString(word);
[[NSSpellChecker sharedSpellChecker] unlearnWord:word_to_remove];
}
@@ -196,8 +196,8 @@ int GetDocumentTag() {
return static_cast<int>(doc_tag);
}
-void IgnoreWord(const std::string& word) {
- [[NSSpellChecker sharedSpellChecker] ignoreWord:base::SysUTF8ToNSString(word)
+void IgnoreWord(const string16& word) {
+ [[NSSpellChecker sharedSpellChecker] ignoreWord:base::SysUTF16ToNSString(word)
inSpellDocumentWithTag:last_seen_tag_];
}
@@ -205,5 +205,6 @@ void CloseDocumentWithTag(int tag) {
[[NSSpellChecker sharedSpellChecker]
closeSpellDocumentWithTag:static_cast<NSInteger>(tag)];
}
+
} // namespace SpellCheckerPlatform
diff --git a/chrome/browser/spellchecker_platform_engine.h b/chrome/browser/spellchecker_platform_engine.h
index bf5eb94..d9a0588 100644
--- a/chrome/browser/spellchecker_platform_engine.h
+++ b/chrome/browser/spellchecker_platform_engine.h
@@ -11,9 +11,11 @@
#include <string>
#include <vector>
+#include "base/string16.h"
#include "chrome/browser/spellchecker_common.h"
namespace SpellCheckerPlatform {
+
// Get the languages supported by the platform spellchecker and store them in
// |spellcheck_languages|. Note that they must be converted to
// Chromium style codes (en-US not en_US). See spellchecker.cc for a full list.
@@ -33,7 +35,7 @@ void ShowSpellingPanel(bool show);
// Changes the word show in the spelling panel to be |word|. Note that the
// spelling panel need not be displayed for this to work.
-void UpdateSpellingPanelWithMisspelledWord(const std::wstring& word);
+void UpdateSpellingPanelWithMisspelledWord(const string16& word);
// Do any initialization needed for spellchecker.
void Init();
@@ -50,19 +52,19 @@ void SetLanguage(const std::string& lang_to_set);
// Checks the spelling of the given string, using the platform-specific
// spellchecker. Returns true if the word is spelled correctly.
-bool CheckSpelling(const std::string& word_to_check, int tag);
+bool CheckSpelling(const string16& word_to_check, int tag);
// Fills the given vector |optional_suggestions| with a number (up to
// kMaxSuggestions, which is defined in spellchecker_common.h) of suggestions
// for the string |wrong_word|.
-void FillSuggestionList(const std::string& wrong_word,
- std::vector<std::wstring>* optional_suggestions);
+void FillSuggestionList(const string16& wrong_word,
+ std::vector<string16>* optional_suggestions);
// Adds the given word to the platform dictionary.
-void AddWord(const std::wstring& word);
+void AddWord(const string16& word);
// Remove a given word from the platform dictionary.
-void RemoveWord(const std::wstring& word);
+void RemoveWord(const string16& word);
// Gets a unique tag to identify a document. Used in ignoring words.
int GetDocumentTag();
@@ -72,12 +74,13 @@ int GetDocumentTag();
// the tag for sure is to ask the renderer, which would mean blocking in the
// browser, so (on the mac, anyway) we remember the most recent tag and use
// it, since it should always be from the same document.
-void IgnoreWord(const std::string& word);
+void IgnoreWord(const string16& word);
// Tells the platform spellchecker that a document associated with a tag has
// closed. Generally, this means that any ignored words associated with that
// document can now be forgotten.
void CloseDocumentWithTag(int tag);
-}
+
+} // namespace SpellCheckerPlatform
#endif // CHROME_BROWSER_SPELLCHECKER_PLATFORM_ENGINE_H_
diff --git a/chrome/browser/spellchecker_win.cc b/chrome/browser/spellchecker_win.cc
index 4fd2dfa..cee7a98 100644
--- a/chrome/browser/spellchecker_win.cc
+++ b/chrome/browser/spellchecker_win.cc
@@ -5,6 +5,8 @@
// If windows ever gains a platform specific spellchecker, it will be
// implemented here.
+#include "chrome/browser/spellchecker_platform_engine.h"
+
#include "chrome/browser/spellchecker_common.h"
namespace SpellCheckerPlatform {
@@ -32,29 +34,29 @@ bool SpellingPanelVisible() {
return false;
}
-void ShowSpellingPanel(bool show) { }
+void ShowSpellingPanel(bool show) {}
-void UpdateSpellingPanelWithMisspelledWord(const std::wstring& word) { }
+void UpdateSpellingPanelWithMisspelledWord(const std::wstring& word) {}
-void Init() { }
+void Init() {}
-void SetLanguage(const std::string& lang_to_set) { }
+void SetLanguage(const std::string& lang_to_set) {}
-bool CheckSpelling(const std::string& word_to_check, int tag) {
+bool CheckSpelling(const string16& word_to_check, int tag) {
return false;
}
-void FillSuggestionList(const std::string& wrong_word,
- std::vector<std::wstring>* optional_suggestions) { }
+void FillSuggestionList(const string16& wrong_word,
+ std::vector<string16>* optional_suggestions) {}
-void AddWord(const std::wstring& word) { }
+void AddWord(const string16& word) {}
-void RemoveWord(const std::wstring& word) { }
+void RemoveWord(const string16& word) {}
int GetDocumentTag() { return 0; }
-void IgnoreWord(const std::string& word) { }
+void IgnoreWord(const string16& word) {}
-void CloseDocumentWithTag(int tag) { }
+void CloseDocumentWithTag(int tag) {}
} // namespace SpellCheckerPlatform
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 053e9ac..ff719c4e 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -239,7 +239,7 @@ void RenderViewContextMenu::AppendEditableItems() {
IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST;
++i) {
AppendMenuItem(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i),
- WideToUTF16(params_.dictionary_suggestions[i]));
+ params_.dictionary_suggestions[i]);
}
if (params_.dictionary_suggestions.size() > 0)
AppendSeparator();
@@ -740,7 +740,7 @@ void RenderViewContextMenu::ExecuteItemCommand(int id) {
case IDC_SPELLPANEL_TOGGLE:
source_tab_contents_->render_view_host()->ToggleSpellPanel(
- SpellCheckerPlatform::SpellingPanelVisible());
+ SpellCheckerPlatform::SpellingPanelVisible());
break;
case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented.
default: