Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(547)

Side by Side Diff: chrome/renderer/render_view.cc

Issue 6392045: Integrating Mac OS Grammar checker into Chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated the patch to catch up WebKit side changes. Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/render_view.h" 5 #include "chrome/renderer/render_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h" 140 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
141 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" 141 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
142 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" 142 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
143 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" 143 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
144 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData .h" 144 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData .h"
145 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 145 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
146 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h" 146 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
147 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" 147 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
148 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h " 148 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h "
149 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 149 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
150 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple tion.h"
151 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult .h"
150 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" 152 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
151 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" 153 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
152 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" 154 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
153 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" 155 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
154 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" 156 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
155 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 157 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
156 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" 158 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
157 #include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h" 159 #include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
158 #include "third_party/skia/include/core/SkBitmap.h" 160 #include "third_party/skia/include/core/SkBitmap.h"
159 #include "ui/base/message_box_flags.h" 161 #include "ui/base/message_box_flags.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 using WebKit::WebRect; 255 using WebKit::WebRect;
254 using WebKit::WebScriptSource; 256 using WebKit::WebScriptSource;
255 using WebKit::WebSearchableFormData; 257 using WebKit::WebSearchableFormData;
256 using WebKit::WebSecurityOrigin; 258 using WebKit::WebSecurityOrigin;
257 using WebKit::WebSettings; 259 using WebKit::WebSettings;
258 using WebKit::WebSharedWorker; 260 using WebKit::WebSharedWorker;
259 using WebKit::WebSize; 261 using WebKit::WebSize;
260 using WebKit::WebStorageNamespace; 262 using WebKit::WebStorageNamespace;
261 using WebKit::WebString; 263 using WebKit::WebString;
262 using WebKit::WebTextAffinity; 264 using WebKit::WebTextAffinity;
265 using WebKit::WebTextCheckingResult;
263 using WebKit::WebTextDirection; 266 using WebKit::WebTextDirection;
264 using WebKit::WebURL; 267 using WebKit::WebURL;
265 using WebKit::WebURLError; 268 using WebKit::WebURLError;
266 using WebKit::WebURLRequest; 269 using WebKit::WebURLRequest;
267 using WebKit::WebURLResponse; 270 using WebKit::WebURLResponse;
268 using WebKit::WebVector; 271 using WebKit::WebVector;
269 using WebKit::WebView; 272 using WebKit::WebView;
270 using WebKit::WebWidget; 273 using WebKit::WebWidget;
271 using WebKit::WebWindowFeatures; 274 using WebKit::WebWindowFeatures;
272 using WebKit::WebWorker; 275 using WebKit::WebWorker;
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) 988 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
986 #if defined(OS_MACOSX) 989 #if defined(OS_MACOSX)
987 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) 990 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
988 #endif 991 #endif
989 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) 992 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
990 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) 993 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
991 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel) 994 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
992 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling, 995 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
993 OnAdvanceToNextMisspelling) 996 OnAdvanceToNextMisspelling)
994 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) 997 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
998 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_RespondTextCheck,
999 OnRespondTextCheck);
995 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) 1000 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
996 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) 1001 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
997 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) 1002 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
998 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) 1003 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
999 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) 1004 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
1000 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) 1005 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
1001 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) 1006 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
1002 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) 1007 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
1003 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL, 1008 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
1004 OnSetContentSettingsForLoadingURL) 1009 OnSetContentSettingsForLoadingURL)
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 void RenderView::OnToggleSpellPanel(bool is_currently_visible) { 1593 void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1589 if (!webview()) 1594 if (!webview())
1590 return; 1595 return;
1591 // We need to tell the webView whether the spelling panel is visible or not so 1596 // We need to tell the webView whether the spelling panel is visible or not so
1592 // that it won't need to make ipc calls later. 1597 // that it won't need to make ipc calls later.
1593 spelling_panel_visible_ = is_currently_visible; 1598 spelling_panel_visible_ = is_currently_visible;
1594 webview()->focusedFrame()->executeCommand( 1599 webview()->focusedFrame()->executeCommand(
1595 WebString::fromUTF8("ToggleSpellPanel")); 1600 WebString::fromUTF8("ToggleSpellPanel"));
1596 } 1601 }
1597 1602
1603 static WebVector<WebTextCheckingResult> toWebResults(
1604 const TextCheckingResultList& results) {
1605 std::vector<WebTextCheckingResult> webResults;
1606 for (size_t i = 0; i < results.size(); ++i) {
1607 switch (results[i].type) {
1608 case TextCheckingResult::MISSPELLING:
1609 webResults.push_back(WebTextCheckingResult(
1610 WebTextCheckingResult::ErrorSpelling,
1611 results[i].location, results[i].length));
1612 break;
1613 case TextCheckingResult::BAD_GRAMMAR:
1614 webResults.push_back(WebTextCheckingResult(
1615 WebTextCheckingResult::ErrorGrammar,
1616 results[i].location, results[i].length));
1617 break;
1618 default:
1619 break;
1620 }
1621 }
1622
1623 return webResults;
1624 }
1625
1626 void RenderView::OnRespondTextCheck(
1627 int identifier, int tag, const TextCheckingResultList& results) {
1628 WebKit::WebTextCheckingCompletion* completion =
1629 text_check_completions_.Lookup(identifier);
1630 if (!completion)
1631 return;
1632 text_check_completions_.Remove(identifier);
1633 completion->didFinishCheckingText(toWebResults(results));
Hironori Bono 2011/02/09 05:43:51 Out of curiosity, who deletes this 'completion' ob
gmorrita 2011/02/10 02:15:21 didFinishCheckingText() removes |this| at the end
1634 }
1635
1598 void RenderView::OnToggleSpellCheck() { 1636 void RenderView::OnToggleSpellCheck() {
1599 if (!webview()) 1637 if (!webview())
1600 return; 1638 return;
1601 1639
1602 WebFrame* frame = webview()->focusedFrame(); 1640 WebFrame* frame = webview()->focusedFrame();
1603 frame->enableContinuousSpellChecking( 1641 frame->enableContinuousSpellChecking(
1604 !frame->isContinuousSpellCheckingEnabled()); 1642 !frame->isContinuousSpellCheckingEnabled());
1605 } 1643 }
1606 1644
1607 void RenderView::OnDelete() { 1645 void RenderView::OnDelete() {
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
2328 string16 word(text); 2366 string16 word(text);
2329 RenderThread* thread = RenderThread::current(); 2367 RenderThread* thread = RenderThread::current();
2330 // Will be NULL during unit tests. 2368 // Will be NULL during unit tests.
2331 if (thread) { 2369 if (thread) {
2332 thread->spellchecker()->SpellCheckWord( 2370 thread->spellchecker()->SpellCheckWord(
2333 word.c_str(), word.size(), document_tag_, 2371 word.c_str(), word.size(), document_tag_,
2334 &misspelled_offset, &misspelled_length, NULL); 2372 &misspelled_offset, &misspelled_length, NULL);
2335 } 2373 }
2336 } 2374 }
2337 2375
2376 void RenderView::requestCheckingOfText(
2377 const WebString& text,
2378 WebKit::WebTextCheckingCompletion* completion) {
2379 // Text check (unified request for grammar and spell check) is only
Hironori Bono 2011/02/09 05:43:51 it may be a good idea to enclose this block with '
gmorrita 2011/02/10 02:15:21 Absolutely. Moved to spellchecker.cc
2380 // available for browser process, so we do IPC instead of
2381 // asking the Spellchecker.
2382 int32 id = text_check_completions_.Add(completion);
2383 Send(new ViewHostMsg_SpellChecker_RequestTextCheck(
2384 routing_id_, routing_id_, id, document_tag_,
2385 string16(text)));
2386 }
2387
2338 WebString RenderView::autoCorrectWord(const WebKit::WebString& word) { 2388 WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
2339 string16 autocorrect_word; 2389 string16 autocorrect_word;
2340 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 2390 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2341 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) { 2391 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
2342 EnsureDocumentTag(); 2392 EnsureDocumentTag();
2343 RenderThread* thread = RenderThread::current(); 2393 RenderThread* thread = RenderThread::current();
2344 // Will be NULL during unit tests. 2394 // Will be NULL during unit tests.
2345 if (thread) { 2395 if (thread) {
2346 autocorrect_word = 2396 autocorrect_word =
2347 thread->spellchecker()->GetAutoCorrectionWord( 2397 thread->spellchecker()->GetAutoCorrectionWord(
(...skipping 3433 matching lines...) Expand 10 before | Expand all | Expand 10 after
5781 } 5831 }
5782 } 5832 }
5783 5833
5784 void RenderView::OnContextMenuClosed( 5834 void RenderView::OnContextMenuClosed(
5785 const webkit_glue::CustomContextMenuContext& custom_context) { 5835 const webkit_glue::CustomContextMenuContext& custom_context) {
5786 if (custom_context.is_pepper_menu) 5836 if (custom_context.is_pepper_menu)
5787 pepper_delegate_.OnContextMenuClosed(custom_context); 5837 pepper_delegate_.OnContextMenuClosed(custom_context);
5788 else 5838 else
5789 context_menu_node_.reset(); 5839 context_menu_node_.reset();
5790 } 5840 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698