| 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/browser/tab_contents/spelling_menu_observer.h" | 5 #include "chrome/browser/tab_contents/spelling_menu_observer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 12 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 13 #include "chrome/browser/spellchecker/spellcheck_host.h" | 13 #include "chrome/browser/spellchecker/spellcheck_host.h" |
| 14 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" | 14 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
| 15 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h" | 15 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h" |
| 16 #include "chrome/browser/spellchecker/spelling_service_client.h" | 16 #include "chrome/browser/spellchecker/spelling_service_client.h" |
| 17 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 17 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 18 #include "chrome/browser/tab_contents/spelling_bubble_model.h" | 18 #include "chrome/browser/tab_contents/spelling_bubble_model.h" |
| 19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/spellcheck_result.h" |
| 21 #include "content/browser/renderer_host/render_view_host.h" | 22 #include "content/browser/renderer_host/render_view_host.h" |
| 22 #include "content/browser/renderer_host/render_widget_host_view.h" | 23 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 23 #include "content/public/common/context_menu_params.h" | 24 #include "content/public/common/context_menu_params.h" |
| 24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult
.h" | |
| 26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 27 | 27 |
| 28 using content::BrowserThread; | 28 using content::BrowserThread; |
| 29 | 29 |
| 30 SpellingMenuObserver::SpellingMenuObserver(RenderViewContextMenuProxy* proxy) | 30 SpellingMenuObserver::SpellingMenuObserver(RenderViewContextMenuProxy* proxy) |
| 31 : proxy_(proxy), | 31 : proxy_(proxy), |
| 32 loading_frame_(0), | 32 loading_frame_(0), |
| 33 succeeded_(false), | 33 succeeded_(false), |
| 34 integrate_spelling_service_(false) { | 34 integrate_spelling_service_(false) { |
| 35 } | 35 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 Profile* profile = proxy_->GetProfile(); | 233 Profile* profile = proxy_->GetProfile(); |
| 234 if (profile) | 234 if (profile) |
| 235 profile->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, | 235 profile->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, |
| 236 false); | 236 false); |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 | 240 |
| 241 void SpellingMenuObserver::OnTextCheckComplete( | 241 void SpellingMenuObserver::OnTextCheckComplete( |
| 242 int tag, | 242 int tag, |
| 243 const std::vector<WebKit::WebTextCheckingResult>& results) { | 243 const std::vector<SpellCheckResult>& results) { |
| 244 animation_timer_.Stop(); | 244 animation_timer_.Stop(); |
| 245 | 245 |
| 246 // Scan the text-check results and replace the misspelled regions with | 246 // Scan the text-check results and replace the misspelled regions with |
| 247 // suggested words. If the replaced text is included in the suggestion list | 247 // suggested words. If the replaced text is included in the suggestion list |
| 248 // provided by the local spellchecker, we show a "No suggestions from Google" | 248 // provided by the local spellchecker, we show a "No suggestions from Google" |
| 249 // message. | 249 // message. |
| 250 succeeded_ = true; | 250 succeeded_ = true; |
| 251 if (results.empty()) { | 251 if (results.empty()) { |
| 252 succeeded_ = false; | 252 succeeded_ = false; |
| 253 } else { | 253 } else { |
| 254 typedef std::vector<WebKit::WebTextCheckingResult> WebTextCheckingResults; | 254 typedef std::vector<SpellCheckResult> SpellCheckResults; |
| 255 for (WebTextCheckingResults::const_iterator it = results.begin(); | 255 for (SpellCheckResults::const_iterator it = results.begin(); |
| 256 it != results.end(); ++it) { | 256 it != results.end(); ++it) { |
| 257 result_.replace(it->position, it->length, it->replacement); | 257 result_.replace(it->location(), it->length(), it->replacement()); |
| 258 } | 258 } |
| 259 for (std::vector<string16>::const_iterator it = suggestions_.begin(); | 259 for (std::vector<string16>::const_iterator it = suggestions_.begin(); |
| 260 it != suggestions_.end(); ++it) { | 260 it != suggestions_.end(); ++it) { |
| 261 if (result_ == *it) { | 261 if (result_ == *it) { |
| 262 succeeded_ = false; | 262 succeeded_ = false; |
| 263 break; | 263 break; |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 if (!succeeded_) { | 267 if (!succeeded_) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 280 loading_frame_ = (loading_frame_ + 1) & 3; | 280 loading_frame_ = (loading_frame_ + 1) & 3; |
| 281 string16 loading_message = loading_message_; | 281 string16 loading_message = loading_message_; |
| 282 for (int i = 0; i < loading_frame_; ++i) | 282 for (int i = 0; i < loading_frame_; ++i) |
| 283 loading_message.push_back('.'); | 283 loading_message.push_back('.'); |
| 284 | 284 |
| 285 // Update the menu item with the text. We disable this item to prevent users | 285 // Update the menu item with the text. We disable this item to prevent users |
| 286 // from selecting it. | 286 // from selecting it. |
| 287 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, | 287 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, |
| 288 loading_message); | 288 loading_message); |
| 289 } | 289 } |
| OLD | NEW |