summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/spellchecker/spellcheck.cc8
-rw-r--r--chrome/renderer/spellchecker/spellcheck.h7
-rw-r--r--chrome/renderer/spellchecker/spellcheck_provider.cc55
-rw-r--r--chrome/renderer/spellchecker/spellcheck_provider.h5
-rw-r--r--chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc5
-rw-r--r--chrome/renderer/spellchecker/spellcheck_unittest.cc57
6 files changed, 90 insertions, 47 deletions
diff --git a/chrome/renderer/spellchecker/spellcheck.cc b/chrome/renderer/spellchecker/spellcheck.cc
index a423dff..e8ccc1a 100644
--- a/chrome/renderer/spellchecker/spellcheck.cc
+++ b/chrome/renderer/spellchecker/spellcheck.cc
@@ -11,9 +11,9 @@
#include "chrome/common/render_messages.h"
#include "chrome/common/spellcheck_common.h"
#include "chrome/common/spellcheck_messages.h"
+#include "chrome/common/spellcheck_result.h"
#include "content/public/renderer/render_thread.h"
#include "third_party/hunspell/src/hunspell/hunspell.hxx"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult.h"
using base::TimeTicks;
using content::RenderThread;
@@ -148,7 +148,7 @@ bool SpellCheck::SpellCheckWord(
bool SpellCheck::SpellCheckParagraph(
const string16& text,
int tag,
- std::vector<WebKit::WebTextCheckingResult>* results) {
+ std::vector<SpellCheckResult>* results) {
#if !defined(OS_MACOSX)
// Mac has its own spell checker, so this method will not be used.
@@ -175,8 +175,8 @@ bool SpellCheck::SpellCheckParagraph(
}
if (results) {
- results->push_back(WebKit::WebTextCheckingResult(
- WebKit::WebTextCheckingTypeSpelling,
+ results->push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING,
misspelling_start + offset,
misspelling_length));
}
diff --git a/chrome/renderer/spellchecker/spellcheck.h b/chrome/renderer/spellchecker/spellcheck.h
index c4c0e87..8567163 100644
--- a/chrome/renderer/spellchecker/spellcheck.h
+++ b/chrome/renderer/spellchecker/spellcheck.h
@@ -20,15 +20,12 @@
#include "unicode/uscript.h"
class Hunspell;
+struct SpellCheckResult;
namespace file_util {
class MemoryMappedFile;
}
-namespace WebKit {
-struct WebTextCheckingResult;
-}
-
// TODO(morrita): Needs reorg with SpellCheckProvider.
// See http://crbug.com/73699.
class SpellCheck : public content::RenderProcessObserver {
@@ -64,7 +61,7 @@ class SpellCheck : public content::RenderProcessObserver {
// or 0.
bool SpellCheckParagraph(const string16& text,
int tag,
- std::vector<WebKit::WebTextCheckingResult>* results);
+ std::vector<SpellCheckResult>* results);
// 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
diff --git a/chrome/renderer/spellchecker/spellcheck_provider.cc b/chrome/renderer/spellchecker/spellcheck_provider.cc
index 07b86d9..81b6643 100644
--- a/chrome/renderer/spellchecker/spellcheck_provider.cc
+++ b/chrome/renderer/spellchecker/spellcheck_provider.cc
@@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/spellcheck_messages.h"
+#include "chrome/common/spellcheck_result.h"
#include "chrome/renderer/chrome_content_renderer_client.h"
#include "chrome/renderer/spellchecker/spellcheck.h"
#include "content/public/renderer/render_view.h"
@@ -21,8 +22,50 @@ using WebKit::WebFrame;
using WebKit::WebString;
using WebKit::WebTextCheckingCompletion;
using WebKit::WebTextCheckingResult;
+using WebKit::WebTextCheckingType;
using WebKit::WebVector;
+COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeSpelling) ==
+ int(SpellCheckResult::SPELLING), mismatching_enums);
+COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeGrammar) ==
+ int(SpellCheckResult::GRAMMAR), mismatching_enums);
+COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeLink) ==
+ int(SpellCheckResult::LINK), mismatching_enums);
+COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeQuote) ==
+ int(SpellCheckResult::QUOTE), mismatching_enums);
+COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeDash) ==
+ int(SpellCheckResult::DASH), mismatching_enums);
+COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeReplacement) ==
+ int(SpellCheckResult::REPLACEMENT), mismatching_enums);
+COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeCorrection) ==
+ int(SpellCheckResult::CORRECTION), mismatching_enums);
+COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeShowCorrectionPanel) ==
+ int(SpellCheckResult::SHOWCORRECTIONPANEL), mismatching_enums);
+
+namespace {
+void ToWebResultList(
+ const std::vector<SpellCheckResult>& results,
+ WebVector<WebTextCheckingResult>* web_results) {
+ WebVector<WebTextCheckingResult> list(results.size());
+ for (size_t i = 0; i < results.size(); ++i) {
+ list[i] = WebTextCheckingResult(
+ static_cast<WebTextCheckingType>(results[i].type),
+ results[i].location,
+ results[i].length,
+ results[i].replacement);
+ }
+
+ list.swap(*web_results);
+}
+
+WebVector<WebTextCheckingResult> ToWebResultList(
+ const std::vector<SpellCheckResult>& results) {
+ WebVector<WebTextCheckingResult> web_results;
+ ToWebResultList(results, &web_results);
+ return web_results;
+}
+} // namespace
+
SpellCheckProvider::SpellCheckProvider(
content::RenderView* render_view,
chrome::ChromeContentRendererClient* renderer_client)
@@ -157,12 +200,12 @@ void SpellCheckProvider::checkTextOfParagraph(
if (!chrome_content_renderer_client_)
return;
- std::vector<WebKit::WebTextCheckingResult> tmp_results;
+ std::vector<SpellCheckResult> tmp_results;
chrome_content_renderer_client_->spellcheck()->SpellCheckParagraph(
string16(text),
document_tag_,
&tmp_results);
- *results = tmp_results;
+ ToWebResultList(tmp_results, results);
#endif
}
@@ -214,13 +257,13 @@ void SpellCheckProvider::OnAdvanceToNextMisspelling() {
void SpellCheckProvider::OnRespondSpellingService(
int identifier,
int tag,
- const std::vector<WebTextCheckingResult>& results) {
+ const std::vector<SpellCheckResult>& results) {
WebTextCheckingCompletion* completion =
text_check_completions_.Lookup(identifier);
if (!completion)
return;
text_check_completions_.Remove(identifier);
- completion->didFinishCheckingText(results);
+ completion->didFinishCheckingText(ToWebResultList(results));
}
#endif
@@ -228,13 +271,13 @@ void SpellCheckProvider::OnRespondSpellingService(
void SpellCheckProvider::OnRespondTextCheck(
int identifier,
int tag,
- const std::vector<WebTextCheckingResult>& results) {
+ const std::vector<SpellCheckResult>& results) {
WebTextCheckingCompletion* completion =
text_check_completions_.Lookup(identifier);
if (!completion)
return;
text_check_completions_.Remove(identifier);
- completion->didFinishCheckingText(results);
+ completion->didFinishCheckingText(ToWebResultList(results));
}
#endif
diff --git a/chrome/renderer/spellchecker/spellcheck_provider.h b/chrome/renderer/spellchecker/spellcheck_provider.h
index 4fd79f0..9598184 100644
--- a/chrome/renderer/spellchecker/spellcheck_provider.h
+++ b/chrome/renderer/spellchecker/spellcheck_provider.h
@@ -13,6 +13,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSpellCheckClient.h"
class RenderView;
+struct SpellCheckResult;
namespace chrome {
class ChromeContentRendererClient;
@@ -81,13 +82,13 @@ class SpellCheckProvider : public content::RenderViewObserver,
void OnRespondSpellingService(
int identifier,
int tag,
- const std::vector<WebKit::WebTextCheckingResult>& results);
+ const std::vector<SpellCheckResult>& results);
#endif
#if defined(OS_MACOSX)
void OnRespondTextCheck(
int identifier,
int tag,
- const std::vector<WebKit::WebTextCheckingResult>& results);
+ const std::vector<SpellCheckResult>& results);
#endif
void OnToggleSpellCheck();
void OnToggleSpellPanel(bool is_currently_visible);
diff --git a/chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc b/chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc
index 75c5357..257851d 100644
--- a/chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc
+++ b/chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,6 +7,7 @@
#include "base/utf_string_conversions.h"
#include "base/stl_util.h"
#include "chrome/common/spellcheck_messages.h"
+#include "chrome/common/spellcheck_result.h"
#include "chrome/renderer/spellchecker/spellcheck_provider.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
@@ -89,7 +90,7 @@ MessageParameters ReadRequestTextCheck(IPC::Message* message) {
void FakeMessageArrival(SpellCheckProvider* provider,
const MessageParameters& parameters) {
- std::vector<WebKit::WebTextCheckingResult> fake_result;
+ std::vector<SpellCheckResult> fake_result;
bool handled = provider->OnMessageReceived(
SpellCheckMsg_RespondTextCheck(
0,
diff --git a/chrome/renderer/spellchecker/spellcheck_unittest.cc b/chrome/renderer/spellchecker/spellcheck_unittest.cc
index ed06323..eeb0a4d 100644
--- a/chrome/renderer/spellchecker/spellcheck_unittest.cc
+++ b/chrome/renderer/spellchecker/spellcheck_unittest.cc
@@ -13,8 +13,9 @@
#include "chrome/renderer/spellchecker/spellcheck.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/spellcheck_common.h"
+#include "chrome/common/spellcheck_result.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult.h"
+
namespace {
@@ -57,8 +58,8 @@ class SpellCheckTest : public testing::Test {
protected:
void TestSpellCheckParagraph(
const string16& input,
- const std::vector<WebKit::WebTextCheckingResult>& expected) {
- std::vector<WebKit::WebTextCheckingResult> results;
+ const std::vector<SpellCheckResult>& expected) {
+ std::vector<SpellCheckResult> results;
spell_check()->SpellCheckParagraph(input,
0,
&results);
@@ -66,7 +67,7 @@ class SpellCheckTest : public testing::Test {
EXPECT_EQ(results.size(), expected.size());
size_t size = std::min(results.size(), expected.size());
for (size_t j = 0; j < size; ++j) {
- EXPECT_EQ(results[j].type, WebKit::WebTextCheckingTypeSpelling);
+ EXPECT_EQ(results[j].type, SpellCheckResult::SPELLING);
EXPECT_EQ(results[j].location, expected[j].location);
EXPECT_EQ(results[j].length, expected[j].length);
}
@@ -733,23 +734,23 @@ TEST_F(SpellCheckTest, GetAutoCorrectionWord_EN_US) {
// Make sure SpellCheckParagraph does not crash if the input is empty.
TEST_F(SpellCheckTest, SpellCheckParagraphEmptyParagraph) {
- std::vector<WebKit::WebTextCheckingResult> expected;
+ std::vector<SpellCheckResult> expected;
TestSpellCheckParagraph(UTF8ToUTF16(""), expected);
}
// A simple test case having no misspellings.
TEST_F(SpellCheckTest, SpellCheckParagraphNoMisspellings) {
const string16 text = UTF8ToUTF16("apple");
- std::vector<WebKit::WebTextCheckingResult> expected;
+ std::vector<SpellCheckResult> expected;
TestSpellCheckParagraph(text, expected);
}
// A simple test case having one misspelling.
TEST_F(SpellCheckTest, SpellCheckParagraphSingleMisspellings) {
const string16 text = UTF8ToUTF16("zz");
- std::vector<WebKit::WebTextCheckingResult> expected;
- expected.push_back(WebKit::WebTextCheckingResult(
- WebKit::WebTextCheckingTypeSpelling, 0, 2));
+ std::vector<SpellCheckResult> expected;
+ expected.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 0, 2));
TestSpellCheckParagraph(text, expected);
}
@@ -757,18 +758,18 @@ TEST_F(SpellCheckTest, SpellCheckParagraphSingleMisspellings) {
// A simple test case having multiple misspellings.
TEST_F(SpellCheckTest, SpellCheckParagraphMultipleMisspellings) {
const string16 text = UTF8ToUTF16("zz, zz");
- std::vector<WebKit::WebTextCheckingResult> expected;
- expected.push_back(WebKit::WebTextCheckingResult(
- WebKit::WebTextCheckingTypeSpelling, 0, 2));
- expected.push_back(WebKit::WebTextCheckingResult(
- WebKit::WebTextCheckingTypeSpelling, 4, 2));
+ std::vector<SpellCheckResult> expected;
+ expected.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 0, 2));
+ expected.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 4, 2));
TestSpellCheckParagraph(text, expected);
}
// Make sure a relatively long (correct) sentence can be spellchecked.
TEST_F(SpellCheckTest, SpellCheckParagraphLongSentence) {
- std::vector<WebKit::WebTextCheckingResult> expected;
+ std::vector<SpellCheckResult> expected;
// The text is taken from US constitution preamble.
const string16 text = UTF8ToUTF16(
"We the people of the United States, in order to form a more perfect "
@@ -782,7 +783,7 @@ TEST_F(SpellCheckTest, SpellCheckParagraphLongSentence) {
// Make sure all misspellings can be found in a relatively long sentence.
TEST_F(SpellCheckTest, SpellCheckParagraphLongSentenceMultipleMisspellings) {
- std::vector<WebKit::WebTextCheckingResult> expected;
+ std::vector<SpellCheckResult> expected;
// All 'the' are converted to 'hte' in US consitition preamble.
const string16 text = UTF8ToUTF16(
@@ -792,18 +793,18 @@ TEST_F(SpellCheckTest, SpellCheckParagraphLongSentenceMultipleMisspellings) {
"blessings of liberty to ourselves and our posterity, do ordain and "
"establish this Constitution for hte United States of America.");
- expected.push_back(WebKit::WebTextCheckingResult(
- WebKit::WebTextCheckingTypeSpelling, 3, 3));
- expected.push_back(WebKit::WebTextCheckingResult(
- WebKit::WebTextCheckingTypeSpelling, 17, 3));
- expected.push_back(WebKit::WebTextCheckingResult(
- WebKit::WebTextCheckingTypeSpelling, 135, 3));
- expected.push_back(WebKit::WebTextCheckingResult(
- WebKit::WebTextCheckingTypeSpelling, 163, 3));
- expected.push_back(WebKit::WebTextCheckingResult(
- WebKit::WebTextCheckingTypeSpelling, 195, 3));
- expected.push_back(WebKit::WebTextCheckingResult(
- WebKit::WebTextCheckingTypeSpelling, 298, 3));
+ expected.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 3, 3));
+ expected.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 17, 3));
+ expected.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 135, 3));
+ expected.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 163, 3));
+ expected.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 195, 3));
+ expected.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 298, 3));
TestSpellCheckParagraph(text, expected);
}