Commit 7b6e7920 authored by jeremy@chromium.org's avatar jeremy@chromium.org

Remove Hunspell on OS X - step 1

This CL removes Hunspell-related options from the spelling context menu on the Mac and tries to bring the menu more inline with the native platform menu.

Notably:
* Spelling submenu observer is split into Hunspell and Mac implementation files.
* strings are split into mac/non-mac variants (saving a bit of space on non-mac platforms?) and the titles are brought more in line with OS X (probably need more work to make this match on all OS X versions).
* Menu is reordered on Mac to more closely match the Cocoa spelling submenu. 

BUG=69944
TEST=Spelling submenu should continue to work on non-Mac platforms. On Mac it should contain 3 items - "Show Spelling and Grammar", "Check Spelling while you Type" and "Language Settings..."


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113457 0039d316-1c4b-4281-b951-d872f2087c98
parent ce81fbd0
......@@ -517,15 +517,6 @@ are declared in build/common.gypi.
<message name="IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS" desc="The name of the Language Settings command in the content area context menu">
&amp;Language settings...
</message>
<message name="IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD" desc="The name of the Check the spelling of this field command in the content area context menu">
&amp;Check the spelling of this field
</message>
<message name="IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL" desc="The name of the Show Spelling Panel command in the content area context menu">
&amp;Show spelling panel
</message>
<message name="IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL" desc="The name of the Hide Spelling Panel command in the content area context menu">
&amp;Hide spelling panel
</message>
<message name="IDS_CONTENT_CONTEXT_SELECTALL" desc="The name of the Select All command in the content area context menu">
Select &amp;all
</message>
......@@ -782,6 +773,30 @@ are declared in build/common.gypi.
</message>
</if>
<!-- Spelling submenu -->
<if expr="is_macosx">
<message name="IDS_CONTENT_CONTEXT_SPELLCHECK_MENU" desc="In Title Case: The name of the Spellcheck Options submenu in the spelling context menu">
Spelling and Grammar
</message>
<message name="IDS_CONTENT_CONTEXT_CHECK_SPELLING_WHILE_TYPING" desc="The name of the Check Spelling while Typing field command in the spelling context menu">
Check Spelling While Typing
</message>
<message name="IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL" desc="The name of the Show Spelling Panel command in the spelling context menu">
Show Spelling and Grammar
</message>
<message name="IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL" desc="The name of the Hide Spelling Panel command in the spelling context menu">
Hide Spelling and Grammar
</message>
</if>
<if expr="not is_macosx">
<message name="IDS_CONTENT_CONTEXT_SPELLCHECK_MENU" desc="In Title Case: The name of the Spellcheck Options submenu in the spelling context menu">
&amp;Spell-checker Options
</message>
<message name="IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD" desc="The name of the Check the spelling of this field command in the spelling context menu">
&amp;Check the spelling of this field
</message>
</if>
<!-- Paste and Match Style / Paste as Plain Text -->
<if expr="is_macosx">
<message name="IDS_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE" desc="Mac/In Title Case: The name of the 'Paste and Match Style' command in the content area context menu">
......
......@@ -41,6 +41,13 @@ class SpellCheckerSubMenuObserver : public RenderViewContextMenuObserver {
// submenu and add it to the parent menu.
ui::SimpleMenuModel submenu_model_;
#if defined(OS_MACOSX)
// On OS X we use the Cocoa spellchecker and try to match the native context
// menu.
bool check_spelling_while_typing_;
#else
// Hunspell spelling submenu.
// Whether spellchecking is enabled in the focused element or not.
bool spellcheck_enabled_;
......@@ -51,6 +58,7 @@ class SpellCheckerSubMenuObserver : public RenderViewContextMenuObserver {
int language_group_;
int language_selected_;
std::vector<std::string> languages_;
#endif // !OS_MACOSX
DISALLOW_COPY_AND_ASSIGN(SpellCheckerSubMenuObserver);
};
......
......@@ -11,7 +11,6 @@
#include "chrome/browser/prefs/pref_member.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/spellchecker/spellcheck_host.h"
#include "chrome/browser/spellchecker/spellchecker_platform_engine.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"
......@@ -73,18 +72,6 @@ void SpellCheckerSubMenuObserver::InitMenu(const ContextMenuParams& params) {
l10n_util::GetStringUTF16(
IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD));
// Add an item that shows the spelling panel if the platform spellchecker
// supports it.
if (SpellCheckerPlatform::SpellCheckerAvailable() &&
SpellCheckerPlatform::SpellCheckerProvidesPanel()) {
submenu_model_.AddCheckItem(
IDC_SPELLPANEL_TOGGLE,
l10n_util::GetStringUTF16(
SpellCheckerPlatform::SpellingPanelVisible() ?
IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL :
IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL));
}
#if defined(OS_WIN)
// If we have not integrated the spelling service, we show an "Ask Google for
// spelling suggestions" item. On the other hand, if we have integrated the
......@@ -202,11 +189,6 @@ void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) {
rvh->Send(new SpellCheckMsg_ToggleSpellCheck(rvh->routing_id()));
break;
case IDC_SPELLPANEL_TOGGLE:
rvh->Send(new SpellCheckMsg_ToggleSpellPanel(
rvh->routing_id(), SpellCheckerPlatform::SpellingPanelVisible()));
break;
#if defined(OS_WIN)
case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE:
// When a user chooses the "Ask Google for spelling suggestions" item, we
......
// 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 "chrome/browser/tab_contents/spellchecker_submenu_observer.h"
#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/tab_contents/render_view_context_menu.h"
#include "chrome/browser/tab_contents/spelling_bubble_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/spellcheck_messages.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/renderer_host/render_widget_host_view.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/simple_menu_model.h"
using content::BrowserThread;
SpellCheckerSubMenuObserver::SpellCheckerSubMenuObserver(
RenderViewContextMenuProxy* proxy,
ui::SimpleMenuModel::Delegate* delegate,
int group)
: proxy_(proxy),
submenu_model_(delegate),
check_spelling_while_typing_(false) {
DCHECK(proxy_);
}
SpellCheckerSubMenuObserver::~SpellCheckerSubMenuObserver() {
}
void SpellCheckerSubMenuObserver::InitMenu(const ContextMenuParams& params) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
check_spelling_while_typing_ = params.spellcheck_enabled;
// Add an item that toggles the spelling panel.
submenu_model_.AddCheckItem(
IDC_SPELLPANEL_TOGGLE,
l10n_util::GetStringUTF16(
SpellCheckerPlatform::SpellingPanelVisible() ?
IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL :
IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL));
submenu_model_.AddSeparator();
// Add a 'Check Spelling While Typing' item in the sub menu.
submenu_model_.AddCheckItem(
IDC_CHECK_SPELLING_OF_THIS_FIELD,
l10n_util::GetStringUTF16(
IDS_CONTENT_CONTEXT_CHECK_SPELLING_WHILE_TYPING));
// Add an item that opens the 'fonts and languages options' page.
submenu_model_.AddSeparator();
submenu_model_.AddItemWithStringId(
IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS,
IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS);
proxy_->AddSubMenu(
IDC_SPELLCHECK_MENU,
l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU),
&submenu_model_);
}
bool SpellCheckerSubMenuObserver::IsCommandIdSupported(int command_id) {
switch (command_id) {
case IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS:
// Return false so RenderViewContextMenu can handle this item because it
// is hard for this class to handle it.
return false;
case IDC_CHECK_SPELLING_OF_THIS_FIELD:
case IDC_SPELLPANEL_TOGGLE:
case IDC_SPELLCHECK_MENU:
case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE:
return true;
}
return false;
}
bool SpellCheckerSubMenuObserver::IsCommandIdChecked(int command_id) {
DCHECK(IsCommandIdSupported(command_id));
// Check box for 'Check the Spelling of this field'.
if (command_id == IDC_CHECK_SPELLING_OF_THIS_FIELD) {
Profile* profile = proxy_->GetProfile();
if (!profile || !profile->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck))
return false;
return check_spelling_while_typing_;
}
return false;
}
bool SpellCheckerSubMenuObserver::IsCommandIdEnabled(int command_id) {
DCHECK(IsCommandIdSupported(command_id));
Profile* profile = proxy_->GetProfile();
if (!profile)
return false;
const PrefService* pref = profile->GetPrefs();
switch (command_id) {
case IDC_CHECK_SPELLING_OF_THIS_FIELD:
return pref->GetBoolean(prefs::kEnableSpellCheck);
case IDC_SPELLPANEL_TOGGLE:
case IDC_SPELLCHECK_MENU:
case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE:
return true;
}
return false;
}
void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) {
DCHECK(IsCommandIdSupported(command_id));
RenderViewHost* rvh = proxy_->GetRenderViewHost();
switch (command_id) {
case IDC_CHECK_SPELLING_OF_THIS_FIELD:
rvh->Send(new SpellCheckMsg_ToggleSpellCheck(rvh->routing_id()));
break;
case IDC_SPELLPANEL_TOGGLE:
rvh->Send(new SpellCheckMsg_ToggleSpellPanel(
rvh->routing_id(), SpellCheckerPlatform::SpellingPanelVisible()));
break;
}
}
......@@ -2356,8 +2356,9 @@
'browser/tab_contents/tab_util.h',
'browser/tab_contents/thumbnail_generator.cc',
'browser/tab_contents/thumbnail_generator.h',
'browser/tab_contents/spellchecker_submenu_observer.cc',
'browser/tab_contents/spellchecker_submenu_observer.h',
'browser/tab_contents/spellchecker_submenu_observer_hunspell.cc',
'browser/tab_contents/spellchecker_submenu_observer_mac.cc',
'browser/tab_contents/spelling_bubble_model.cc',
'browser/tab_contents/spelling_bubble_model.h',
'browser/tab_contents/spelling_menu_observer.cc',
......@@ -4374,6 +4375,7 @@
'browser/importer/nss_decryptor_system_nss.h',
'browser/jankometer.cc',
'browser/password_manager/login_database_posix.cc',
'browser/tab_contents/spellchecker_submenu_observer_hunspell.cc',
'browser/ui/browser_list_stub.cc',
'browser/ui/certificate_dialogs.cc',
'browser/ui/certificate_dialogs.h',
......
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