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 /chrome/browser/renderer_host | |
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 'chrome/browser/renderer_host')
8 files changed, 118 insertions, 7 deletions
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 9085996..64fc364 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -558,6 +558,10 @@ void RenderViewHost::SelectAll() { Send(new ViewMsg_SelectAll(routing_id())); } +void RenderViewHost::ToggleSpellPanel(bool is_currently_visible) { + Send(new ViewMsg_ToggleSpellPanel(routing_id(), is_currently_visible)); +} + int RenderViewHost::DownloadFavIcon(const GURL& url, int image_size) { if (!url.is_valid()) { NOTREACHED(); diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 81637aa..28cadfe 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -275,6 +275,7 @@ class RenderViewHost : public RenderWidgetHost, void AddToDictionary(const std::wstring& word); void Delete(); void SelectAll(); + void ToggleSpellPanel(bool is_currently_visible); // Downloads an image notifying the FavIcon delegate appropriately. The // returned integer uniquely identifies the download for the lifetime of the diff --git a/chrome/browser/renderer_host/render_widget_host.cc b/chrome/browser/renderer_host/render_widget_host.cc index e28b006..473f129 100644 --- a/chrome/browser/renderer_host/render_widget_host.cc +++ b/chrome/browser/renderer_host/render_widget_host.cc @@ -877,3 +877,15 @@ void RenderWidgetHost::ScrollBackingStoreRect(TransportDIB* bitmap, backing_store->ScrollRect(process_->process().handle(), bitmap, bitmap_rect, dx, dy, clip_rect, view_size); } + +void RenderWidgetHost::ToggleSpellPanel(bool is_currently_visible) { + Send(new ViewMsg_ToggleSpellPanel(routing_id(), is_currently_visible)); +} + +void RenderWidgetHost::ReplaceWord(const std::wstring& word) { + Send(new ViewMsg_Replace(routing_id_, word)); +} + +void RenderWidgetHost::AdvanceToNextMisspelling() { + Send(new ViewMsg_AdvanceToNextMisspelling(routing_id_)); +} diff --git a/chrome/browser/renderer_host/render_widget_host.h b/chrome/browser/renderer_host/render_widget_host.h index b06bce3..90e0b9c 100644 --- a/chrome/browser/renderer_host/render_widget_host.h +++ b/chrome/browser/renderer_host/render_widget_host.h @@ -328,6 +328,15 @@ class RenderWidgetHost : public IPC::Channel::Listener, // And to also expose it to the RenderWidgetHostView. virtual gfx::Rect GetRootWindowResizerRect() const; + // Makes an IPC call to toggle the spelling panel. + void ToggleSpellPanel(bool is_currently_visible); + + // Makes an IPC call to tell webkit to replace the currently selected word. + void ReplaceWord(const std::wstring& word); + + // Makes an IPC call to tell webkit to advance to the next misspelling. + void AdvanceToNextMisspelling(); + // Sets the active state (i.e., control tints). virtual void SetActive(bool active); diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.h b/chrome/browser/renderer_host/render_widget_host_view_mac.h index 1633a52..b8f4146 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.h +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.h @@ -30,7 +30,7 @@ class RWHVMEditCommandHelper; // when it's removed from the view system. @interface RenderWidgetHostViewCocoa - : BaseView <RenderWidgetHostViewMacOwner, NSTextInput> { + : BaseView <RenderWidgetHostViewMacOwner, NSTextInput, NSChangeSpelling> { @private RenderWidgetHostViewMac* renderWidgetHostView_; BOOL canBeKeyView_; diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm index fef480b..3587616 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -12,6 +12,7 @@ #include "chrome/browser/renderer_host/backing_store.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_widget_host.h" +#include "chrome/browser/spellchecker_platform_engine.h" #include "chrome/common/native_web_keyboard_event.h" #include "skia/ext/platform_canvas.h" #include "webkit/api/public/mac/WebInputEventFactory.h" @@ -690,6 +691,58 @@ void RenderWidgetHostViewMac::SetActive(bool active) { return ([event type] == NSKeyDown) ? YES : NO; } +// Spellchecking methods +// The next three methods are implemented here since this class is the first +// responder for anything in the browser. + +// This message is sent whenever the user specifies that a word should be +// changed from the spellChecker. +- (void)changeSpelling:(id)sender { + // Grab the currently selected word from the spell panel, as this is the word + // that we want to replace the selected word in the text with. + NSString* newWord = [[sender selectedCell] stringValue]; + if (newWord != nil) { + RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac]; + thisHostView->GetRenderWidgetHost()->ReplaceWord( + base::SysNSStringToWide(newWord)); + } +} + +// This message is sent by NSSpellChecker whenever the next word should be +// advanced to, either after a correction or clicking the "Find Next" button. +// This isn't documented anywhere useful, like in NSSpellProtocol.h with the +// other spelling panel methods. This is probably because Apple assumes that the +// the spelling panel will be used with an NSText, which will automatically +// catch this and advance to the next word for you. Thanks Apple. +- (void)checkSpelling:(id)sender { + RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac]; + thisHostView->GetRenderWidgetHost()->AdvanceToNextMisspelling(); +} + +// This message is sent by the spelling panel whenever a word is ignored. +- (void)ignoreSpelling:(id)sender { + // Ideally, we would ask the current RenderView for its tag, but that would + // mean making a blocking IPC call from the browser. Instead, + // SpellCheckerPlatform::CheckSpelling remembers the last tag and + // SpellCheckerPlatform::IgnoreWord assumes that is the correct tag. + NSString* wordToIgnore = [sender stringValue]; + if (wordToIgnore != nil) { + SpellCheckerPlatform::IgnoreWord(base::SysNSStringToUTF8(wordToIgnore)); + + // Strangely, the spellingPanel doesn't send checkSpelling after a word is + // ignored, so we have to explicitly call AdvanceToNextMisspelling here. + RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac]; + thisHostView->GetRenderWidgetHost()->AdvanceToNextMisspelling(); + } +} + +- (void)showGuessPanel:(id)sender { + RenderWidgetHostViewMac* thisHostView = [self renderWidgetHostViewMac]; + thisHostView->GetRenderWidgetHost()->ToggleSpellPanel( + SpellCheckerPlatform::SpellingPanelVisible()); +} + +// END Spellchecking methods // Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm // with minor modifications for code style and commenting. diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index 5a21f34..1190fd3 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -27,6 +27,7 @@ #include "chrome/browser/renderer_host/file_system_accessor.h" #include "chrome/browser/renderer_host/render_widget_helper.h" #include "chrome/browser/spellchecker.h" +#include "chrome/browser/spellchecker_platform_engine.h" #include "chrome/browser/worker_host/message_port_dispatcher.h" #include "chrome/browser/worker_host/worker_service.h" #include "chrome/common/appcache/appcache_dispatcher_host.h" @@ -296,8 +297,15 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_ForwardToWorker, OnForwardToWorker) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SpellCheck, OnSpellCheck) + IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetDocumentTag, + OnGetDocumentTag) + IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentWithTagClosed, + OnDocumentWithTagClosed) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetAutoCorrectWord, OnGetAutoCorrectWord) + IPC_MESSAGE_HANDLER(ViewHostMsg_ShowSpellingPanel, OnShowSpellingPanel) + IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateSpellingPanelWithMisspelledWord, + OnUpdateSpellingPanelWithMisspelledWord) IPC_MESSAGE_HANDLER(ViewHostMsg_DnsPrefetch, OnDnsPrefetch) IPC_MESSAGE_HANDLER(ViewHostMsg_RendererHistograms, OnRendererHistograms) @@ -376,7 +384,7 @@ void ResourceMessageFilter::OnReceiveContextMenuMsg(const IPC::Message& msg) { int misspell_location, misspell_length; bool is_misspelled = !spellchecker_->SpellCheckWord( params.misspelled_word.c_str(), - static_cast<int>(params.misspelled_word.length()), + static_cast<int>(params.misspelled_word.length()), 0, &misspell_location, &misspell_length, ¶ms.dictionary_suggestions); @@ -870,14 +878,14 @@ Clipboard* ResourceMessageFilter::GetClipboard() { // spellings are correct. // // Note: This is called in the IO thread. -void ResourceMessageFilter::OnSpellCheck(const std::wstring& word, +void ResourceMessageFilter::OnSpellCheck(const std::wstring& word, int tag, IPC::Message* reply_msg) { int misspell_location = 0; int misspell_length = 0; if (spellchecker_ != NULL) { spellchecker_->SpellCheckWord(word.c_str(), - static_cast<int>(word.length()), + static_cast<int>(word.length()), tag, &misspell_location, &misspell_length, NULL); } @@ -887,12 +895,23 @@ void ResourceMessageFilter::OnSpellCheck(const std::wstring& word, return; } +void ResourceMessageFilter::OnGetDocumentTag(IPC::Message* reply_msg) { + int tag = SpellCheckerPlatform::GetDocumentTag(); + ViewHostMsg_GetDocumentTag::WriteReplyParams(reply_msg, tag); + Send(reply_msg); + return; +} + +void ResourceMessageFilter::OnDocumentWithTagClosed(int tag) { + SpellCheckerPlatform::CloseDocumentWithTag(tag); +} void ResourceMessageFilter::OnGetAutoCorrectWord(const std::wstring& word, + int tag, IPC::Message* reply_msg) { std::wstring autocorrect_word; if (spellchecker_ != NULL) { - spellchecker_->GetAutoCorrectionWord(word, &autocorrect_word); + spellchecker_->GetAutoCorrectionWord(word, tag, &autocorrect_word); } ViewHostMsg_GetAutoCorrectWord::WriteReplyParams(reply_msg, @@ -901,6 +920,15 @@ void ResourceMessageFilter::OnGetAutoCorrectWord(const std::wstring& word, return; } +void ResourceMessageFilter::OnShowSpellingPanel(bool show) { + SpellCheckerPlatform::ShowSpellingPanel(show); +} + +void ResourceMessageFilter::OnUpdateSpellingPanelWithMisspelledWord( + const std::wstring& word) { + SpellCheckerPlatform::UpdateSpellingPanelWithMisspelledWord(word); +} + void ResourceMessageFilter::Observe(NotificationType type, const NotificationSource &source, const NotificationDetails &details) { diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 4c467c6..743b7f6 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -159,10 +159,14 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, void OnDownloadUrl(const IPC::Message& message, const GURL& url, const GURL& referrer); - void OnSpellCheck(const std::wstring& word, + void OnSpellCheck(const std::wstring& word, int tag, IPC::Message* reply_msg); - void OnGetAutoCorrectWord(const std::wstring& word, + void OnGetDocumentTag(IPC::Message* reply_msg); + void OnDocumentWithTagClosed(int tag); + void OnGetAutoCorrectWord(const std::wstring& word, int tag, IPC::Message* reply_msg); + void OnShowSpellingPanel(bool show); + void OnUpdateSpellingPanelWithMisspelledWord(const std::wstring& word); void OnDnsPrefetch(const std::vector<std::string>& hostnames); void OnRendererHistograms(int sequence_number, const std::vector<std::string>& histogram_info); |