| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spellchecker/spellcheck_provider.h" | 5 #include "chrome/renderer/spellchecker/spellcheck_provider.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/common/spellcheck_messages.h" | 10 #include "chrome/common/spellcheck_messages.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 int(SpellCheckResult::SHOWCORRECTIONPANEL), mismatching_enums); | 43 int(SpellCheckResult::SHOWCORRECTIONPANEL), mismatching_enums); |
| 44 | 44 |
| 45 SpellCheckProvider::SpellCheckProvider( | 45 SpellCheckProvider::SpellCheckProvider( |
| 46 content::RenderView* render_view, | 46 content::RenderView* render_view, |
| 47 SpellCheck* spellcheck) | 47 SpellCheck* spellcheck) |
| 48 : content::RenderViewObserver(render_view), | 48 : content::RenderViewObserver(render_view), |
| 49 content::RenderViewObserverTracker<SpellCheckProvider>(render_view), | 49 content::RenderViewObserverTracker<SpellCheckProvider>(render_view), |
| 50 spelling_panel_visible_(false), | 50 spelling_panel_visible_(false), |
| 51 spellcheck_(spellcheck) { | 51 spellcheck_(spellcheck) { |
| 52 DCHECK(spellcheck_); | 52 DCHECK(spellcheck_); |
| 53 if (render_view) // NULL in unit tests. | 53 if (render_view) { // NULL in unit tests. |
| 54 render_view->GetWebView()->setSpellCheckClient(this); | 54 render_view->GetWebView()->setSpellCheckClient(this); |
| 55 EnableSpellCheck(spellcheck_->is_spellcheck_enabled()); |
| 56 } |
| 55 } | 57 } |
| 56 | 58 |
| 57 SpellCheckProvider::~SpellCheckProvider() { | 59 SpellCheckProvider::~SpellCheckProvider() { |
| 58 #if defined(OS_MACOSX) | 60 #if defined(OS_MACOSX) |
| 59 Send(new SpellCheckHostMsg_DocumentClosed(routing_id(), routing_id())); | 61 Send(new SpellCheckHostMsg_DocumentClosed(routing_id(), routing_id())); |
| 60 #endif | 62 #endif |
| 61 } | 63 } |
| 62 | 64 |
| 63 void SpellCheckProvider::RequestTextChecking( | 65 void SpellCheckProvider::RequestTextChecking( |
| 64 const WebString& text, | 66 const WebString& text, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 #if !defined(OS_MACOSX) | 106 #if !defined(OS_MACOSX) |
| 105 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondSpellingService, | 107 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondSpellingService, |
| 106 OnRespondSpellingService) | 108 OnRespondSpellingService) |
| 107 #endif | 109 #endif |
| 108 #if defined(OS_MACOSX) | 110 #if defined(OS_MACOSX) |
| 109 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, | 111 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, |
| 110 OnAdvanceToNextMisspelling) | 112 OnAdvanceToNextMisspelling) |
| 111 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck) | 113 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck) |
| 112 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) | 114 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) |
| 113 #endif | 115 #endif |
| 114 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellCheck, OnToggleSpellCheck) | |
| 115 IPC_MESSAGE_UNHANDLED(handled = false) | 116 IPC_MESSAGE_UNHANDLED(handled = false) |
| 116 IPC_END_MESSAGE_MAP() | 117 IPC_END_MESSAGE_MAP() |
| 117 return handled; | 118 return handled; |
| 118 } | 119 } |
| 119 | 120 |
| 120 void SpellCheckProvider::FocusedNodeChanged(const WebKit::WebNode& unused) { | 121 void SpellCheckProvider::FocusedNodeChanged(const WebKit::WebNode& unused) { |
| 121 #if defined(OS_MACOSX) | 122 #if defined(OS_MACOSX) |
| 122 bool enabled = false; | 123 bool enabled = false; |
| 123 WebKit::WebNode node = render_view()->GetFocusedNode(); | 124 WebKit::WebNode node = render_view()->GetFocusedNode(); |
| 124 if (!node.isNull()) | 125 if (!node.isNull()) |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 if (!render_view()->GetWebView()) | 289 if (!render_view()->GetWebView()) |
| 289 return; | 290 return; |
| 290 // We need to tell the webView whether the spelling panel is visible or not so | 291 // We need to tell the webView whether the spelling panel is visible or not so |
| 291 // that it won't need to make ipc calls later. | 292 // that it won't need to make ipc calls later. |
| 292 spelling_panel_visible_ = is_currently_visible; | 293 spelling_panel_visible_ = is_currently_visible; |
| 293 render_view()->GetWebView()->focusedFrame()->executeCommand( | 294 render_view()->GetWebView()->focusedFrame()->executeCommand( |
| 294 WebString::fromUTF8("ToggleSpellPanel")); | 295 WebString::fromUTF8("ToggleSpellPanel")); |
| 295 } | 296 } |
| 296 #endif | 297 #endif |
| 297 | 298 |
| 298 void SpellCheckProvider::OnToggleSpellCheck() { | 299 void SpellCheckProvider::EnableSpellCheck(bool enable) { |
| 299 if (!render_view()->GetWebView()) | 300 if (!render_view()->GetWebView()) |
| 300 return; | 301 return; |
| 301 | 302 |
| 302 WebFrame* frame = render_view()->GetWebView()->focusedFrame(); | 303 WebFrame* frame = render_view()->GetWebView()->focusedFrame(); |
| 303 frame->enableContinuousSpellChecking( | 304 frame->enableContinuousSpellChecking(enable); |
| 304 !frame->isContinuousSpellCheckingEnabled()); | |
| 305 } | 305 } |
| 306 | 306 |
| 307 #if !defined(OS_MACOSX) | 307 #if !defined(OS_MACOSX) |
| 308 bool SpellCheckProvider::SatisfyRequestFromCache( | 308 bool SpellCheckProvider::SatisfyRequestFromCache( |
| 309 const WebString& text, | 309 const WebString& text, |
| 310 WebTextCheckingCompletion* completion) { | 310 WebTextCheckingCompletion* completion) { |
| 311 // Cancel this spellcheck request if the cached text is a substring of the | 311 // Cancel this spellcheck request if the cached text is a substring of the |
| 312 // given text and the given text is the middle of a possible word. | 312 // given text and the given text is the middle of a possible word. |
| 313 string16 request(text); | 313 string16 request(text); |
| 314 size_t text_length = request.length(); | 314 size_t text_length = request.length(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 results[i].replacement = last_results_[i].replacement; | 348 results[i].replacement = last_results_[i].replacement; |
| 349 } | 349 } |
| 350 completion->didFinishCheckingText(results); | 350 completion->didFinishCheckingText(results); |
| 351 return true; | 351 return true; |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 return false; | 355 return false; |
| 356 } | 356 } |
| 357 #endif | 357 #endif |
| OLD | NEW |