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:
parent
a20b5cc88d
commit
ff77107e73
|
@ -367,6 +367,12 @@ typedef struct _cef_browser_host_t {
|
|||
void (CEF_CALLBACK *replace_misspelling)(struct _cef_browser_host_t* self,
|
||||
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.
|
||||
///
|
||||
|
|
|
@ -413,6 +413,12 @@ class CefBrowserHost : public virtual CefBase {
|
|||
/*--cef()--*/
|
||||
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.
|
||||
///
|
||||
|
|
|
@ -1308,6 +1308,7 @@ typedef enum {
|
|||
MENU_ID_SPELLCHECK_SUGGESTION_4 = 204,
|
||||
MENU_ID_SPELLCHECK_SUGGESTION_LAST = 204,
|
||||
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
|
||||
// MENU_ID_USER_LAST to avoid overlapping the Chromium and CEF ID ranges
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
#include "base/bind_helpers.h"
|
||||
#include "base/command_line.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 "content/browser/gpu/compositor_util.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
||||
|
@ -61,6 +63,10 @@
|
|||
#include "ui/gfx/font_render_params.h"
|
||||
#endif
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
#include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
|
||||
#endif
|
||||
|
||||
#if defined(USE_AURA)
|
||||
#include "ui/views/widget/widget.h"
|
||||
#endif
|
||||
|
@ -876,6 +882,29 @@ void CefBrowserHostImpl::ReplaceMisspelling(const CefString& 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() {
|
||||
if (!IsWindowless()) {
|
||||
NOTREACHED() << "Window rendering is not disabled";
|
||||
|
|
|
@ -160,6 +160,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
|||
virtual bool IsMouseCursorChangeDisabled() OVERRIDE;
|
||||
virtual bool IsWindowRenderingDisabled() OVERRIDE;
|
||||
virtual void ReplaceMisspelling(const CefString& word) OVERRIDE;
|
||||
virtual void AddWordToDictionary(const CefString& word) OVERRIDE;
|
||||
virtual void WasResized() OVERRIDE;
|
||||
virtual void WasHidden(bool hidden) OVERRIDE;
|
||||
virtual void NotifyScreenInfoChanged() OVERRIDE;
|
||||
|
|
|
@ -233,23 +233,33 @@ void CefMenuCreator::CreateDefaultModel() {
|
|||
model_->SetEnabled(MENU_ID_SELECT_ALL, false);
|
||||
|
||||
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();
|
||||
|
||||
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()) {
|
||||
} else {
|
||||
model_->AddItem(
|
||||
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()) {
|
||||
// Something is selected.
|
||||
|
@ -336,6 +346,11 @@ void CefMenuCreator::ExecuteDefaultCommand(int command_id) {
|
|||
browser_->GetFocusedFrame()->ViewSource();
|
||||
break;
|
||||
|
||||
// Spell checking.
|
||||
case MENU_ID_ADD_TO_DICTIONARY:
|
||||
browser_->GetHost()->AddWordToDictionary(params_.misspelled_word);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -333,7 +333,10 @@ need to be translated for each locale.-->
|
|||
<message name="IDS_SPELLCHECK_DICTIONARY" use_name_for_id="true">
|
||||
en-US
|
||||
</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">
|
||||
&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">
|
||||
&No spelling suggestions
|
||||
</message>
|
||||
</messages>
|
||||
|
|
|
@ -434,6 +434,23 @@ void CEF_CALLBACK browser_host_replace_misspelling(
|
|||
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(
|
||||
struct _cef_browser_host_t* self) {
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
@ -806,6 +823,7 @@ CefBrowserHostCppToC::CefBrowserHostCppToC(CefBrowserHost* cls)
|
|||
struct_.struct_.is_mouse_cursor_change_disabled =
|
||||
browser_host_is_mouse_cursor_change_disabled;
|
||||
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 =
|
||||
browser_host_is_window_rendering_disabled;
|
||||
struct_.struct_.was_resized = browser_host_was_resized;
|
||||
|
|
|
@ -350,6 +350,22 @@ void CefBrowserHostCToCpp::ReplaceMisspelling(const CefString& word) {
|
|||
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() {
|
||||
if (CEF_MEMBER_MISSING(struct_, is_window_rendering_disabled))
|
||||
return false;
|
||||
|
|
|
@ -63,6 +63,7 @@ class CefBrowserHostCToCpp
|
|||
virtual void SetMouseCursorChangeDisabled(bool disabled) OVERRIDE;
|
||||
virtual bool IsMouseCursorChangeDisabled() OVERRIDE;
|
||||
virtual void ReplaceMisspelling(const CefString& word) OVERRIDE;
|
||||
virtual void AddWordToDictionary(const CefString& word) OVERRIDE;
|
||||
virtual bool IsWindowRenderingDisabled() OVERRIDE;
|
||||
virtual void WasResized() OVERRIDE;
|
||||
virtual void WasHidden(bool hidden) OVERRIDE;
|
||||
|
|
Loading…
Reference in New Issue