Commit f1e969da authored by jeremy@chromium.org's avatar jeremy@chromium.org

Remove Hunspell on OS X - step 2

* Remove empty Linux & Win implementations of the class.
* Rename files and unit test to be Mac only.
* Rename namespace SpellCheckerPlatform -> SpellCheckerMac
* Surround usage in crossplatform files with #ifdef OS_MACOSX as a temporary measure (a future step will be to remove the calls entirely from these files).

BUG=69944
TEST=Spelling correction feature should continue to work as expected on Mac/Win/Linux .


Review URL: http://codereview.chromium.org/8890022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113974 0039d316-1c4b-4281-b951-d872f2087c98
parent ebd3727a
......@@ -8,7 +8,7 @@
#include "base/sys_string_conversions.h"
#include "chrome/browser/debugger/devtools_window.h"
#include "chrome/browser/spellchecker/spellchecker_platform_engine.h"
#include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#import "chrome/browser/ui/cocoa/history_overlay_controller.h"
......@@ -309,17 +309,17 @@ class SpellCheckRenderViewObserver : public content::RenderViewHostObserver {
- (void)ignoreSpelling:(id)sender {
// Ideally, we would ask the current RenderView for its tag, but that would
// mean making a blocking IPC call from the browser. Instead,
// SpellCheckerPlatform::CheckSpelling remembers the last tag and
// SpellCheckerPlatform::IgnoreWord assumes that is the correct tag.
// spellcheck_mac::CheckSpelling remembers the last tag and
// spellcheck_mac::IgnoreWord assumes that is the correct tag.
NSString* wordToIgnore = [sender stringValue];
if (wordToIgnore != nil)
SpellCheckerPlatform::IgnoreWord(base::SysNSStringToUTF16(wordToIgnore));
spellcheck_mac::IgnoreWord(base::SysNSStringToUTF16(wordToIgnore));
}
- (void)showGuessPanel:(id)sender {
render_widget_host_->Send(new SpellCheckMsg_ToggleSpellPanel(
render_widget_host_->routing_id(),
SpellCheckerPlatform::SpellingPanelVisible()));
spellcheck_mac::SpellingPanelVisible()));
}
- (void)toggleContinuousSpellChecking:(id)sender {
......
......@@ -9,7 +9,7 @@
#include "chrome/browser/prefs/pref_member.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/spellchecker/spellcheck_host_impl.h"
#include "chrome/browser/spellchecker/spellchecker_platform_engine.h"
#include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/spellcheck_common.h"
......@@ -59,10 +59,14 @@ int SpellCheckHost::GetSpellCheckLanguages(
// from this list to the existing list of spell check languages.
std::vector<std::string> accept_languages;
if (SpellCheckerPlatform::SpellCheckerAvailable())
SpellCheckerPlatform::GetAvailableLanguages(&accept_languages);
#if defined(OS_MACOSX)
if (spellcheck_mac::SpellCheckerAvailable())
spellcheck_mac::GetAvailableLanguages(&accept_languages);
else
base::SplitString(accept_languages_pref.GetValue(), ',', &accept_languages);
#else
base::SplitString(accept_languages_pref.GetValue(), ',', &accept_languages);
#endif // !OS_MACOSX
for (std::vector<std::string>::const_iterator i = accept_languages.begin();
i != accept_languages.end(); ++i) {
......
......@@ -17,8 +17,8 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
#include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
#include "chrome/browser/spellchecker/spellcheck_profile_provider.h"
#include "chrome/browser/spellchecker/spellchecker_platform_engine.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
......@@ -101,15 +101,17 @@ SpellCheckHostImpl::~SpellCheckHostImpl() {
void SpellCheckHostImpl::Initialize() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (SpellCheckerPlatform::SpellCheckerAvailable() &&
SpellCheckerPlatform::PlatformSupportsLanguage(language_)) {
#if defined(OS_MACOSX)
if (spellcheck_mac::SpellCheckerAvailable() &&
spellcheck_mac::PlatformSupportsLanguage(language_)) {
use_platform_spellchecker_ = true;
SpellCheckerPlatform::SetLanguage(language_);
spellcheck_mac::SetLanguage(language_);
MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(&SpellCheckHostImpl::InformProfileOfInitialization,
weak_ptr_factory_.GetWeakPtr()));
return;
}
#endif // OS_MACOSX
BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE,
base::Bind(&SpellCheckHostImpl::InitializeDictionaryLocation,
......
......@@ -8,7 +8,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/spellchecker/spellcheck_host.h"
#include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
#include "chrome/browser/spellchecker/spellchecker_platform_engine.h"
#include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
#include "chrome/common/spellcheck_messages.h"
#include "content/public/browser/render_process_host.h"
......@@ -57,30 +57,42 @@ bool SpellCheckMessageFilter::OnMessageReceived(const IPC::Message& message,
void SpellCheckMessageFilter::OnPlatformCheckSpelling(const string16& word,
int tag,
bool* correct) {
*correct = SpellCheckerPlatform::CheckSpelling(word, tag);
#if defined(OS_MACOSX)
*correct = spellcheck_mac::CheckSpelling(word, tag);
#endif
}
void SpellCheckMessageFilter::OnPlatformFillSuggestionList(
const string16& word,
std::vector<string16>* suggestions) {
SpellCheckerPlatform::FillSuggestionList(word, suggestions);
#if defined(OS_MACOSX)
spellcheck_mac::FillSuggestionList(word, suggestions);
#endif
}
void SpellCheckMessageFilter::OnGetDocumentTag(int* tag) {
*tag = SpellCheckerPlatform::GetDocumentTag();
#if defined(OS_MACOSX)
*tag = spellcheck_mac::GetDocumentTag();
#endif
}
void SpellCheckMessageFilter::OnDocumentWithTagClosed(int tag) {
SpellCheckerPlatform::CloseDocumentWithTag(tag);
#if defined(OS_MACOSX)
spellcheck_mac::CloseDocumentWithTag(tag);
#endif
}
void SpellCheckMessageFilter::OnShowSpellingPanel(bool show) {
SpellCheckerPlatform::ShowSpellingPanel(show);
#if defined(OS_MACOSX)
spellcheck_mac::ShowSpellingPanel(show);
#endif
}
void SpellCheckMessageFilter::OnUpdateSpellingPanelWithMisspelledWord(
const string16& word) {
SpellCheckerPlatform::UpdateSpellingPanelWithMisspelledWord(word);
#if defined(OS_MACOSX)
spellcheck_mac::UpdateSpellingPanelWithMisspelledWord(word);
#endif
}
void SpellCheckMessageFilter::OnPlatformRequestTextCheck(
......@@ -88,8 +100,10 @@ void SpellCheckMessageFilter::OnPlatformRequestTextCheck(
int identifier,
int document_tag,
const string16& text) {
SpellCheckerPlatform::RequestTextCheck(
#if defined(OS_MACOSX)
spellcheck_mac::RequestTextCheck(
route_id, identifier, document_tag, text, this);
#endif
}
void SpellCheckMessageFilter::OnSpellCheckerRequestDictionary() {
......
......@@ -5,8 +5,8 @@
// This file defines the interface that any platform-specific spellchecker
// needs to implement in order to be used by the browser.
#ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECKER_PLATFORM_ENGINE_H_
#define CHROME_BROWSER_SPELLCHECKER_SPELLCHECKER_PLATFORM_ENGINE_H_
#ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PLATFORM_MAC_H_
#define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PLATFORM_MAC_H_
#pragma once
#include <string>
......@@ -17,7 +17,7 @@
class BrowserMessageFilter;
namespace SpellCheckerPlatform {
namespace spellcheck_mac {
// Get the languages supported by the platform spellchecker and store them in
// |spellcheck_languages|. Note that they must be converted to
......@@ -40,10 +40,6 @@ void ShowSpellingPanel(bool show);
// spelling panel need not be displayed for this to work.
void UpdateSpellingPanelWithMisspelledWord(const string16& word);
// Do any initialization needed for spellchecker.
void Init();
// TODO(pwicks): should we add a companion to this, TearDown or something?
// Translates the codes used by chrome to the language codes used by os x
// and checks the given language agains the languages that the current system
// supports. If the platform-specific spellchecker supports the language,
......@@ -93,6 +89,6 @@ void RequestTextCheck(int route_id,
const string16& text,
BrowserMessageFilter* destination);
} // namespace SpellCheckerPlatform
} // namespace spellcheck_mac
#endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECKER_PLATFORM_ENGINE_H_
#endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PLATFORM_MAC_H_
......@@ -2,10 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file implements the interface defined in spellchecker_platform_engine.h
// for the OS X platform.
// Integration with OS X native spellchecker.
#include "chrome/browser/spellchecker/spellchecker_platform_engine.h"
#include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
#import <Cocoa/Cocoa.h>
......@@ -164,7 +163,7 @@ std::string ConvertLanguageCodeFromMac(NSString* lang_code) {
} // namespace
namespace SpellCheckerPlatform {
namespace spellcheck_mac {
void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) {
NSArray* availableLanguages = [SharedSpellChecker() availableLanguages];
......@@ -214,9 +213,6 @@ void UpdateSpellingPanelWithMisspelledWord(const string16& word) {
waitUntilDone:YES];
}
void Init() {
}
bool PlatformSupportsLanguage(const std::string& current_language) {
// First, convert the language to an OS X language code.
NSString* mac_lang_code = ConvertLanguageCodeToMac(current_language);
......@@ -307,4 +303,4 @@ void RequestTextCheck(int route_id,
destination, route_id, identifier, text, document_tag));
}
} // namespace SpellCheckerPlatform
} // namespace spellcheck_mac
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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.
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/spellchecker/spellchecker_platform_engine.h"
#include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
#include "testing/gtest/include/gtest/gtest.h"
// Tests that words are properly ignored. Currently only enabled on OS X as it
// is the only platform to support ignoring words. Note that in this test, we
// supply a non-zero doc_tag, in order to test that ignored words are matched to
// the correct document.
TEST(PlatformSpellCheckTest, IgnoreWords_EN_US) {
TEST(spellcheck_macTest, IgnoreWords_EN_US) {
const char* kTestCases[] = {
"teh",
"morblier",
......@@ -21,27 +21,27 @@ TEST(PlatformSpellCheckTest, IgnoreWords_EN_US) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
const string16 word(ASCIIToUTF16(kTestCases[i]));
const int doc_tag = SpellCheckerPlatform::GetDocumentTag();
const int doc_tag = spellcheck_mac::GetDocumentTag();
// The word should show up as misspelled.
EXPECT_FALSE(SpellCheckerPlatform::CheckSpelling(word, doc_tag)) << word;
EXPECT_FALSE(spellcheck_mac::CheckSpelling(word, doc_tag)) << word;
// Ignore the word.
SpellCheckerPlatform::IgnoreWord(word);
spellcheck_mac::IgnoreWord(word);
// The word should now show up as correctly spelled.
EXPECT_TRUE(SpellCheckerPlatform::CheckSpelling(word, doc_tag)) << word;
EXPECT_TRUE(spellcheck_mac::CheckSpelling(word, doc_tag)) << word;
// Close the docuemnt. Any words that we had previously ignored should no
// longer be ignored and thus should show up as misspelled.
SpellCheckerPlatform::CloseDocumentWithTag(doc_tag);
spellcheck_mac::CloseDocumentWithTag(doc_tag);
// The word should now show be spelled wrong again
EXPECT_FALSE(SpellCheckerPlatform::CheckSpelling(word, doc_tag)) << word;
EXPECT_FALSE(spellcheck_mac::CheckSpelling(word, doc_tag)) << word;
}
} // Test IgnoreWords_EN_US
TEST(PlatformSpellCheckTest, SpellCheckSuggestions_EN_US) {
TEST(spellcheck_macTest, SpellCheckSuggestions_EN_US) {
static const struct {
const char* input; // A string to be tested.
const char* suggested_word; // A suggested word that should occur.
......@@ -316,11 +316,11 @@ TEST(PlatformSpellCheckTest, SpellCheckSuggestions_EN_US) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
const string16 word(ASCIIToUTF16(kTestCases[i].input));
EXPECT_FALSE(SpellCheckerPlatform::CheckSpelling(word, 0)) << word;
EXPECT_FALSE(spellcheck_mac::CheckSpelling(word, 0)) << word;
// Check if the suggested words occur.
std::vector<string16> suggestions;
SpellCheckerPlatform::FillSuggestionList(word, &suggestions);
spellcheck_mac::FillSuggestionList(word, &suggestions);
bool suggested_word_is_present = false;
const string16 suggested_word(ASCIIToUTF16(kTestCases[i].suggested_word));
for (size_t j = 0; j < suggestions.size(); j++) {
......
// Copyright (c) 2009 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.
// If linux ever gains a platform specific spellchecker, it will be
// implemented here.
#include "spellchecker_platform_engine.h"
namespace SpellCheckerPlatform {
bool SpellCheckerAvailable() {
// As of Summer 2009, there is no commonly accepted platform spellchecker
// for Linux, so we'll return false here.
return false;
}
// The following methods are just stubs to keep the linker happy.
bool PlatformSupportsLanguage(const std::string& current_language) {
return false;
}
void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) {
spellcheck_languages->clear();
}
bool SpellCheckerProvidesPanel() {
return false;
}
bool SpellingPanelVisible() {
return false;
}
void ShowSpellingPanel(bool show) {}
void UpdateSpellingPanelWithMisspelledWord(const string16& word) {}
void Init() {}
void SetLanguage(const std::string& lang_to_set) {}
bool CheckSpelling(const string16& word_to_check, int tag) {
return false;
}
void FillSuggestionList(const string16& wrong_word,
std::vector<string16>* optional_suggestions) {}
void AddWord(const string16& word) {}
void RemoveWord(const string16& word) {}
int GetDocumentTag() { return 0; }
void IgnoreWord(const string16& word) {}
void CloseDocumentWithTag(int tag) {}
void RequestTextCheck(int route_id,
int identifier,
int document_tag,
const string16& text,
BrowserMessageFilter* destination) {}
} // namespace SpellCheckerPlatform
// Copyright (c) 2009 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.
// If windows ever gains a platform specific spellchecker, it will be
// implemented here.
#include "chrome/browser/spellchecker/spellchecker_platform_engine.h"
namespace SpellCheckerPlatform {
bool SpellCheckerAvailable() {
// No current version of Windows (as of Summer 2009) has a common spellchecker
// so we'll return false here.
return false;
}
// The following methods are just stubs to keep the linker happy.
bool PlatformSupportsLanguage(const std::string& current_language) {
return false;
}
void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) {
spellcheck_languages->clear();
}
bool SpellCheckerProvidesPanel() {
return false;
}
bool SpellingPanelVisible() {
return false;
}
void ShowSpellingPanel(bool show) {}
void UpdateSpellingPanelWithMisspelledWord(const std::wstring& word) {}
void Init() {}
void SetLanguage(const std::string& lang_to_set) {}
bool CheckSpelling(const string16& word_to_check, int tag) {
return false;
}
void FillSuggestionList(const string16& wrong_word,
std::vector<string16>* optional_suggestions) {}
void AddWord(const string16& word) {}
void RemoveWord(const string16& word) {}
int GetDocumentTag() { return 0; }
void IgnoreWord(const string16& word) {}
void CloseDocumentWithTag(int tag) {}
void RequestTextCheck(int route_id,
int identifier,
int document_tag,
const string16& text,
BrowserMessageFilter* destination) {}
} // namespace SpellCheckerPlatform
......@@ -7,7 +7,7 @@
#include "base/logging.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/spellchecker/spellchecker_platform_engine.h"
#include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
#include "chrome/browser/tab_contents/render_view_context_menu.h"
#include "chrome/browser/tab_contents/spelling_bubble_model.h"
#include "chrome/common/chrome_switches.h"
......@@ -43,7 +43,7 @@ void SpellCheckerSubMenuObserver::InitMenu(const ContextMenuParams& params) {
submenu_model_.AddCheckItem(
IDC_SPELLPANEL_TOGGLE,
l10n_util::GetStringUTF16(
SpellCheckerPlatform::SpellingPanelVisible() ?
spellcheck_mac::SpellingPanelVisible() ?
IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL :
IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL));
submenu_model_.AddSeparator();
......@@ -124,7 +124,7 @@ void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) {
case IDC_SPELLPANEL_TOGGLE:
rvh->Send(new SpellCheckMsg_ToggleSpellPanel(
rvh->routing_id(), SpellCheckerPlatform::SpellingPanelVisible()));
rvh->routing_id(), spellcheck_mac::SpellingPanelVisible()));
break;
}
}
......@@ -17,7 +17,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/spellchecker/spellcheck_host.h"
#include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
#include "chrome/browser/spellchecker/spellchecker_platform_engine.h"
#include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
#include "chrome/browser/tab_contents/render_view_context_menu.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
......@@ -219,7 +219,9 @@ void SpellingMenuObserver::ExecuteCommand(int command_id) {
Profile* profile = proxy_->GetProfile();
if (profile && profile->GetSpellCheckHost())
profile->GetSpellCheckHost()->AddWord(UTF16ToUTF8(misspelled_word_));
SpellCheckerPlatform::AddWord(misspelled_word_);
#if defined(OS_MACOSX)
spellcheck_mac::AddWord(misspelled_word_);
#endif
}
}
......
......@@ -2182,13 +2182,11 @@
'browser/spellchecker/spellcheck_host_metrics.h',
'browser/spellchecker/spellcheck_message_filter.cc',
'browser/spellchecker/spellcheck_message_filter.h',
'browser/spellchecker/spellcheck_platform_mac.h',
'browser/spellchecker/spellcheck_platform_mac.mm',
'browser/spellchecker/spellcheck_profile.cc',
'browser/spellchecker/spellcheck_profile.h',
'browser/spellchecker/spellcheck_profile_provider.h',
'browser/spellchecker/spellchecker_linux.cc',
'browser/spellchecker/spellchecker_mac.mm',
'browser/spellchecker/spellchecker_platform_engine.h',
'browser/spellchecker/spellchecker_win.cc',
'browser/ssl/ssl_add_cert_handler.cc',
'browser/ssl/ssl_add_cert_handler.h',
'browser/ssl/ssl_add_cert_handler_mac.mm',
......
......@@ -1631,7 +1631,7 @@
'browser/sessions/session_service_unittest.cc',
'browser/shell_integration_unittest.cc',
'browser/speech/speech_input_bubble_controller_unittest.cc',
'browser/spellchecker/spellchecker_platform_engine_unittest.cc',
'browser/spellchecker/spellcheck_platform_mac_unittest.cc',
'browser/spellchecker/spellcheck_profile_unittest.cc',
'browser/status_icons/status_icon_unittest.cc',
'browser/status_icons/status_tray_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment