mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
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:
@@ -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>
|
||||
|
Reference in New Issue
Block a user