Further improvements to spell checking support (issue #137).

- Add "Add to dictionary" context menu option.
- Use available translations for "Add to dictionary" and "No spelling suggestions".
- Fix placement of context menu separators.
- Display the "No spelling suggestions" option as grayed out.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1879 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2014-10-19 01:47:27 +00:00
parent a20b5cc88d
commit ff77107e73
10 changed files with 110 additions and 14 deletions

View File

@ -367,6 +367,12 @@ typedef struct _cef_browser_host_t {
void (CEF_CALLBACK *replace_misspelling)(struct _cef_browser_host_t* self, void (CEF_CALLBACK *replace_misspelling)(struct _cef_browser_host_t* self,
const cef_string_t* word); const cef_string_t* word);
///
// Add the specified |word| to the spelling dictionary.
///
void (CEF_CALLBACK *add_word_to_dictionary)(struct _cef_browser_host_t* self,
const cef_string_t* word);
/// ///
// Returns true (1) if window rendering is disabled. // Returns true (1) if window rendering is disabled.
/// ///

View File

@ -413,6 +413,12 @@ class CefBrowserHost : public virtual CefBase {
/*--cef()--*/ /*--cef()--*/
virtual void ReplaceMisspelling(const CefString& word) =0; virtual void ReplaceMisspelling(const CefString& word) =0;
///
// Add the specified |word| to the spelling dictionary.
///
/*--cef()--*/
virtual void AddWordToDictionary(const CefString& word) =0;
/// ///
// Returns true if window rendering is disabled. // Returns true if window rendering is disabled.
/// ///

View File

@ -1308,6 +1308,7 @@ typedef enum {
MENU_ID_SPELLCHECK_SUGGESTION_4 = 204, MENU_ID_SPELLCHECK_SUGGESTION_4 = 204,
MENU_ID_SPELLCHECK_SUGGESTION_LAST = 204, MENU_ID_SPELLCHECK_SUGGESTION_LAST = 204,
MENU_ID_NO_SPELLING_SUGGESTIONS = 205, MENU_ID_NO_SPELLING_SUGGESTIONS = 205,
MENU_ID_ADD_TO_DICTIONARY = 206,
// All user-defined menu IDs should come between MENU_ID_USER_FIRST and // All user-defined menu IDs should come between MENU_ID_USER_FIRST and
// MENU_ID_USER_LAST to avoid overlapping the Chromium and CEF ID ranges // MENU_ID_USER_LAST to avoid overlapping the Chromium and CEF ID ranges

View File

@ -36,6 +36,8 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "chrome/browser/spellchecker/spellcheck_service.h"
#include "components/pdf/common/pdf_messages.h" #include "components/pdf/common/pdf_messages.h"
#include "content/browser/gpu/compositor_util.h" #include "content/browser/gpu/compositor_util.h"
#include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/render_widget_host_impl.h"
@ -61,6 +63,10 @@
#include "ui/gfx/font_render_params.h" #include "ui/gfx/font_render_params.h"
#endif #endif
#if defined(OS_MACOSX)
#include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
#endif
#if defined(USE_AURA) #if defined(USE_AURA)
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#endif #endif
@ -876,6 +882,29 @@ void CefBrowserHostImpl::ReplaceMisspelling(const CefString& word) {
web_contents()->ReplaceMisspelling(word); web_contents()->ReplaceMisspelling(word);
} }
void CefBrowserHostImpl::AddWordToDictionary(const CefString& word) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT,
base::Bind(&CefBrowserHostImpl::AddWordToDictionary, this, word));
return;
}
if (!web_contents())
return;
content::BrowserContext* browser_context =
web_contents()->GetBrowserContext();
if (browser_context) {
SpellcheckService* spellcheck =
SpellcheckServiceFactory::GetForContext(browser_context);
if (spellcheck)
spellcheck->GetCustomDictionary()->AddWord(word);
}
#if defined(OS_MACOSX)
spellcheck_mac::AddWord(word);
#endif
}
void CefBrowserHostImpl::WasResized() { void CefBrowserHostImpl::WasResized() {
if (!IsWindowless()) { if (!IsWindowless()) {
NOTREACHED() << "Window rendering is not disabled"; NOTREACHED() << "Window rendering is not disabled";

View File

@ -160,6 +160,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
virtual bool IsMouseCursorChangeDisabled() OVERRIDE; virtual bool IsMouseCursorChangeDisabled() OVERRIDE;
virtual bool IsWindowRenderingDisabled() OVERRIDE; virtual bool IsWindowRenderingDisabled() OVERRIDE;
virtual void ReplaceMisspelling(const CefString& word) OVERRIDE; virtual void ReplaceMisspelling(const CefString& word) OVERRIDE;
virtual void AddWordToDictionary(const CefString& word) OVERRIDE;
virtual void WasResized() OVERRIDE; virtual void WasResized() OVERRIDE;
virtual void WasHidden(bool hidden) OVERRIDE; virtual void WasHidden(bool hidden) OVERRIDE;
virtual void NotifyScreenInfoChanged() OVERRIDE; virtual void NotifyScreenInfoChanged() OVERRIDE;

View File

@ -233,23 +233,33 @@ void CefMenuCreator::CreateDefaultModel() {
model_->SetEnabled(MENU_ID_SELECT_ALL, false); model_->SetEnabled(MENU_ID_SELECT_ALL, false);
if(!params_.misspelled_word.empty()) { if(!params_.misspelled_word.empty()) {
if (!params_.dictionary_suggestions.empty()) // Always add a separator before the list of dictionary suggestions or
// "No spelling suggestions".
model_->AddSeparator();
if (!params_.dictionary_suggestions.empty()) {
for (size_t i = 0;
i < params_.dictionary_suggestions.size() &&
MENU_ID_SPELLCHECK_SUGGESTION_0 + i <=
MENU_ID_SPELLCHECK_SUGGESTION_LAST;
++i) {
model_->AddItem(MENU_ID_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i),
params_.dictionary_suggestions[i].c_str());
}
// When there are dictionary suggestions add a separator before "Add to
// dictionary".
model_->AddSeparator(); model_->AddSeparator();
} else {
for (size_t i = 0;
i < params_.dictionary_suggestions.size() &&
MENU_ID_SPELLCHECK_SUGGESTION_0 + i <=
MENU_ID_SPELLCHECK_SUGGESTION_LAST;
++i) {
model_->AddItem(MENU_ID_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i),
params_.dictionary_suggestions[i].c_str());
}
if (params_.dictionary_suggestions.empty()) {
model_->AddItem( model_->AddItem(
MENU_ID_NO_SPELLING_SUGGESTIONS, MENU_ID_NO_SPELLING_SUGGESTIONS,
GetLabel(IDS_MENU_NO_SPELLING_SUGGESTIONS)); GetLabel(IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS));
model_->SetEnabled(MENU_ID_NO_SPELLING_SUGGESTIONS, false);
} }
model_->AddItem(
MENU_ID_ADD_TO_DICTIONARY,
GetLabel(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY));
} }
} else if (!params_.selection_text.empty()) { } else if (!params_.selection_text.empty()) {
// Something is selected. // Something is selected.
@ -336,6 +346,11 @@ void CefMenuCreator::ExecuteDefaultCommand(int command_id) {
browser_->GetFocusedFrame()->ViewSource(); browser_->GetFocusedFrame()->ViewSource();
break; break;
// Spell checking.
case MENU_ID_ADD_TO_DICTIONARY:
browser_->GetHost()->AddWordToDictionary(params_.misspelled_word);
break;
default: default:
break; break;
} }

View File

@ -333,7 +333,10 @@ need to be translated for each locale.-->
<message name="IDS_SPELLCHECK_DICTIONARY" use_name_for_id="true"> <message name="IDS_SPELLCHECK_DICTIONARY" use_name_for_id="true">
en-US en-US
</message> </message>
<message name="IDS_MENU_NO_SPELLING_SUGGESTIONS" desc="The name of the No Spelling Suggestions display in the content area context menu"> <message name="IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY" desc="The name of the Add to dictionary command in the content area context menu">
&amp;Add to dictionary
</message>
<message name="IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS" desc="The name of the No Spelling Suggestions display in the content area context menu">
&amp;No spelling suggestions &amp;No spelling suggestions
</message> </message>
</messages> </messages>

View File

@ -434,6 +434,23 @@ void CEF_CALLBACK browser_host_replace_misspelling(
CefString(word)); CefString(word));
} }
void CEF_CALLBACK browser_host_add_word_to_dictionary(
struct _cef_browser_host_t* self, const cef_string_t* word) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: word; type: string_byref_const
DCHECK(word);
if (!word)
return;
// Execute
CefBrowserHostCppToC::Get(self)->AddWordToDictionary(
CefString(word));
}
int CEF_CALLBACK browser_host_is_window_rendering_disabled( int CEF_CALLBACK browser_host_is_window_rendering_disabled(
struct _cef_browser_host_t* self) { struct _cef_browser_host_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
@ -806,6 +823,7 @@ CefBrowserHostCppToC::CefBrowserHostCppToC(CefBrowserHost* cls)
struct_.struct_.is_mouse_cursor_change_disabled = struct_.struct_.is_mouse_cursor_change_disabled =
browser_host_is_mouse_cursor_change_disabled; browser_host_is_mouse_cursor_change_disabled;
struct_.struct_.replace_misspelling = browser_host_replace_misspelling; struct_.struct_.replace_misspelling = browser_host_replace_misspelling;
struct_.struct_.add_word_to_dictionary = browser_host_add_word_to_dictionary;
struct_.struct_.is_window_rendering_disabled = struct_.struct_.is_window_rendering_disabled =
browser_host_is_window_rendering_disabled; browser_host_is_window_rendering_disabled;
struct_.struct_.was_resized = browser_host_was_resized; struct_.struct_.was_resized = browser_host_was_resized;

View File

@ -350,6 +350,22 @@ void CefBrowserHostCToCpp::ReplaceMisspelling(const CefString& word) {
word.GetStruct()); word.GetStruct());
} }
void CefBrowserHostCToCpp::AddWordToDictionary(const CefString& word) {
if (CEF_MEMBER_MISSING(struct_, add_word_to_dictionary))
return;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: word; type: string_byref_const
DCHECK(!word.empty());
if (word.empty())
return;
// Execute
struct_->add_word_to_dictionary(struct_,
word.GetStruct());
}
bool CefBrowserHostCToCpp::IsWindowRenderingDisabled() { bool CefBrowserHostCToCpp::IsWindowRenderingDisabled() {
if (CEF_MEMBER_MISSING(struct_, is_window_rendering_disabled)) if (CEF_MEMBER_MISSING(struct_, is_window_rendering_disabled))
return false; return false;

View File

@ -63,6 +63,7 @@ class CefBrowserHostCToCpp
virtual void SetMouseCursorChangeDisabled(bool disabled) OVERRIDE; virtual void SetMouseCursorChangeDisabled(bool disabled) OVERRIDE;
virtual bool IsMouseCursorChangeDisabled() OVERRIDE; virtual bool IsMouseCursorChangeDisabled() OVERRIDE;
virtual void ReplaceMisspelling(const CefString& word) OVERRIDE; virtual void ReplaceMisspelling(const CefString& word) OVERRIDE;
virtual void AddWordToDictionary(const CefString& word) OVERRIDE;
virtual bool IsWindowRenderingDisabled() OVERRIDE; virtual bool IsWindowRenderingDisabled() OVERRIDE;
virtual void WasResized() OVERRIDE; virtual void WasResized() OVERRIDE;
virtual void WasHidden(bool hidden) OVERRIDE; virtual void WasHidden(bool hidden) OVERRIDE;