diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-09 21:16:05 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-09 21:16:05 +0000 |
commit | 98324891649cf5fa7430c2e231ad5493fdb76c8e (patch) | |
tree | 4c48f7d44d002691e717526bdb2d7870296b10df /webkit | |
parent | 1edc999cee504ed756ee798dfb1bfd95f53b4262 (diff) | |
download | chromium_src-98324891649cf5fa7430c2e231ad5493fdb76c8e.zip chromium_src-98324891649cf5fa7430c2e231ad5493fdb76c8e.tar.gz chromium_src-98324891649cf5fa7430c2e231ad5493fdb76c8e.tar.bz2 |
Adds support for the os x spelling panel to chromium. Users can
now access it from the main menu and context menu and use it to perform
spelling tasks. For more detail, see
http://code.google.com/p/chromium/wiki/SpellingPanelPlanningDoc
Patch from pwicks86@gmail.com (Paul Wicks).
BUG=None
TEST=The spelling panel should work in os x.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25786 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/editor_client_impl.cc | 32 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.cc | 6 | ||||
-rw-r--r-- | webkit/glue/webview.h | 3 | ||||
-rw-r--r-- | webkit/glue/webview_delegate.h | 15 | ||||
-rw-r--r-- | webkit/glue/webview_impl.cc | 8 | ||||
-rw-r--r-- | webkit/glue/webview_impl.h | 6 |
6 files changed, 62 insertions, 8 deletions
diff --git a/webkit/glue/editor_client_impl.cc b/webkit/glue/editor_client_impl.cc index a090eb7..f7d2561 100644 --- a/webkit/glue/editor_client_impl.cc +++ b/webkit/glue/editor_client_impl.cc @@ -152,7 +152,13 @@ void EditorClientImpl::toggleGrammarChecking() { } int EditorClientImpl::spellCheckerDocumentTag() { +#if defined(OS_MACOSX) + WebViewDelegate* d = web_view_->delegate(); + if (d) + return d->SpellCheckerDocumentTag(); +#else NOTIMPLEMENTED(); +#endif // OS_MACOSX return 0; } @@ -838,7 +844,8 @@ void EditorClientImpl::checkSpellingOfString(const UChar* str, int length, if (isContinuousSpellCheckingEnabled() && d) { std::wstring word = webkit_glue::StringToStdWString(WebCore::String(str, length)); - d->SpellCheck(word, &spell_location, &spell_length); + d->SpellCheck(word, spellCheckerDocumentTag(), + &spell_location, &spell_length); } else { spell_location = 0; spell_length = 0; @@ -867,7 +874,8 @@ WebCore::String EditorClientImpl::getAutoCorrectSuggestionForMisspelledWord( return WebCore::String(); } - std::wstring autocorrect_word = d->GetAutoCorrectWord(word); + std::wstring autocorrect_word = + d->GetAutoCorrectWord(word, spellCheckerDocumentTag()); return webkit_glue::StdWStringToString(autocorrect_word); } @@ -887,16 +895,28 @@ void EditorClientImpl::updateSpellingUIWithGrammarString(const WebCore::String&, NOTIMPLEMENTED(); } -void EditorClientImpl::updateSpellingUIWithMisspelledWord(const WebCore::String&) { - NOTIMPLEMENTED(); +void EditorClientImpl::updateSpellingUIWithMisspelledWord( + const WebCore::String& misspelled_word) { + std::wstring word = webkit_glue::StringToStdWString(misspelled_word); + WebViewDelegate* d = web_view_->delegate(); + if (d) { + d->UpdateSpellingUIWithMisspelledWord(word); + } } void EditorClientImpl::showSpellingUI(bool show) { - NOTIMPLEMENTED(); + WebViewDelegate* d = web_view_->delegate(); + if (d) { + d->ShowSpellingUI(show); + } } bool EditorClientImpl::spellingUIIsShowing() { - return false; + // SpellingPanel visibility is stored in the web_view_ every time a toggle + // message is sent from the browser. If we were to send a message to the + // browser and ask for the visibility, then we run into problems accessing + // cocoa methods on the UI thread. + return web_view_->GetSpellingPanelVisibility(); } void EditorClientImpl::getGuessesForWord(const WebCore::String&, diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index 7521532..e52075c 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -973,6 +973,12 @@ bool WebFrameImpl::executeCommand(const WebString& name) { rv = frame()->editor()->command(AtomicString("BackwardDelete")).execute(); } else if (EqualsASCII(command, "DeleteForward")) { rv = frame()->editor()->command(AtomicString("ForwardDelete")).execute(); + } else if (EqualsASCII(command, "AdvanceToNextMisspelling")) { + // False must be passed here, or the currently selected word will never be + // skipped. + frame()->editor()->advanceToNextMisspelling(false); + } else if (EqualsASCII(command, "ToggleSpellPanel")) { + frame()->editor()->showSpellingGuessPanel(); } else { rv = frame()->editor()->command(AtomicString(command.c_str())).execute(); } diff --git a/webkit/glue/webview.h b/webkit/glue/webview.h index 0cd33fc..db4e6fb 100644 --- a/webkit/glue/webview.h +++ b/webkit/glue/webview.h @@ -243,6 +243,9 @@ class WebView : public WebKit::WebWidget { virtual void SetIsTransparent(bool is_transparent) = 0; virtual bool GetIsTransparent() const = 0; + virtual void SetSpellingPanelVisibility(bool is_visible) = 0; + virtual bool GetSpellingPanelVisibility() = 0; + // Performs an action from a context menu for the node at the given // location. virtual void MediaPlayerActionAt(int x, diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h index 99d9be36..3bbdf02 100644 --- a/webkit/glue/webview_delegate.h +++ b/webkit/glue/webview_delegate.h @@ -729,17 +729,28 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { // indices (inclusive) will be filled with the offsets of the boundary of the // word within the given buffer. The out pointers must be specified. If the // word is correctly spelled (returns true), they will be set to (0,0). - virtual void SpellCheck(const std::wstring& word, int* misspell_location, + virtual void SpellCheck(const std::wstring& word, int tag, + int* misspell_location, int* misspell_length) { *misspell_location = *misspell_length = 0; } // Computes an auto correct word for a misspelled word. If no word is found, // empty string is computed. - virtual std::wstring GetAutoCorrectWord(const std::wstring& misspelled_word) { + virtual std::wstring GetAutoCorrectWord(const std::wstring& misspelled_word, + int tag) { return std::wstring(); } + // Returns the document tag for the current WebView. + virtual int SpellCheckerDocumentTag() { return 0; } + + // Switches the spelling panel to be displayed or not based on |show|. + virtual void ShowSpellingUI(bool show) { } + + // Update the spelling panel with the |word|. + virtual void UpdateSpellingUIWithMisspelledWord(const std::wstring& word) { } + // Asks the user to print the page or a specific frame. Called in response to // a window.print() call. virtual void ScriptedPrint(WebKit::WebFrame* frame) { } diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index f3cf268..effb17d 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -1934,3 +1934,11 @@ HitTestResult WebViewImpl::HitTestResultForWindowPos(const IntPoint& pos) { return page_->mainFrame()->eventHandler()-> hitTestResultAtPoint(doc_point, false); } + +void WebViewImpl::SetSpellingPanelVisibility(bool is_visible) { + spelling_panel_is_visible_ = is_visible; +} + +bool WebViewImpl::GetSpellingPanelVisibility() { + return spelling_panel_is_visible_; +} diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h index 3c753ac..7bc66e9 100644 --- a/webkit/glue/webview_impl.h +++ b/webkit/glue/webview_impl.h @@ -242,6 +242,9 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { // the underlying Node for them. WebCore::Node* GetNodeForWindowPos(int x, int y); + virtual void SetSpellingPanelVisibility(bool is_visible); + virtual bool GetSpellingPanelVisibility(); + #if ENABLE(NOTIFICATIONS) // Returns the provider of desktop notifications. WebKit::NotificationPresenterImpl* GetNotificationPresenter(); @@ -394,6 +397,9 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { // Whether the webview is rendering transparently. bool is_transparent_; + // Whether the spelling panel is currently being displayed or not. + bool spelling_panel_is_visible_; + // Inspector settings. std::wstring inspector_settings_; |