| OLD | NEW |
| 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/browser/tab_contents/spelling_menu_observer.h" | 5 #include "chrome/browser/tab_contents/spelling_menu_observer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 void SpellingMenuObserver::InitMenu(const ContextMenuParams& params) { | 50 void SpellingMenuObserver::InitMenu(const ContextMenuParams& params) { |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 52 | 52 |
| 53 // Exit if we are not in an editable element because we add a menu item only | 53 // Exit if we are not in an editable element because we add a menu item only |
| 54 // for editable elements. | 54 // for editable elements. |
| 55 if (!params.is_editable) | 55 if (!params.is_editable) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 // Append Dictionary spell check suggestions. |
| 59 suggestions_ = params.dictionary_suggestions; |
| 60 for (size_t i = 0; i < params.dictionary_suggestions.size() && |
| 61 IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST; |
| 62 ++i) { |
| 63 proxy_->AddMenuItem(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i), |
| 64 params.dictionary_suggestions[i]); |
| 65 } |
| 66 |
| 58 Profile* profile = proxy_->GetProfile(); | 67 Profile* profile = proxy_->GetProfile(); |
| 59 if (!profile || !profile->GetRequestContext()) | 68 if (!profile || !profile->GetRequestContext()) |
| 60 return; | 69 return; |
| 61 | 70 |
| 62 PrefService* pref = profile->GetPrefs(); | 71 PrefService* pref = profile->GetPrefs(); |
| 63 if (pref->GetBoolean(prefs::kEnableSpellCheck) && | 72 if (pref->GetBoolean(prefs::kEnableSpellCheck) && |
| 64 pref->GetBoolean(prefs::kSpellCheckUseSpellingService)) { | 73 pref->GetBoolean(prefs::kSpellCheckUseSpellingService)) { |
| 65 // Retrieve the misspelled word to be sent to the Spelling service. | 74 // Retrieve the misspelled word to be sent to the Spelling service. |
| 66 string16 text = params.misspelled_word; | 75 string16 text = params.misspelled_word; |
| 67 if (text.empty()) | 76 if (text.empty()) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 83 loading_message_); | 92 loading_message_); |
| 84 | 93 |
| 85 // Invoke a JSON-RPC call to the Spelling service in the background so we | 94 // Invoke a JSON-RPC call to the Spelling service in the background so we |
| 86 // can update the placeholder item when we receive its response. It also | 95 // can update the placeholder item when we receive its response. It also |
| 87 // starts the animation timer so we can show animation until we receive it. | 96 // starts the animation timer so we can show animation until we receive it. |
| 88 const PrefService* pref = profile->GetPrefs(); | 97 const PrefService* pref = profile->GetPrefs(); |
| 89 std::string language = | 98 std::string language = |
| 90 pref ? pref->GetString(prefs::kSpellCheckDictionary) : "en-US"; | 99 pref ? pref->GetString(prefs::kSpellCheckDictionary) : "en-US"; |
| 91 Invoke(text, language, profile->GetRequestContext()); | 100 Invoke(text, language, profile->GetRequestContext()); |
| 92 } | 101 } |
| 93 | |
| 94 // Append Dictionary spell check suggestions. | |
| 95 suggestions_ = params.dictionary_suggestions; | |
| 96 for (size_t i = 0; i < params.dictionary_suggestions.size() && | |
| 97 IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST; | |
| 98 ++i) { | |
| 99 proxy_->AddMenuItem(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i), | |
| 100 params.dictionary_suggestions[i]); | |
| 101 } | |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool SpellingMenuObserver::IsCommandIdSupported(int command_id) { | 104 bool SpellingMenuObserver::IsCommandIdSupported(int command_id) { |
| 105 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && | 105 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && |
| 106 command_id <= IDC_SPELLCHECK_SUGGESTION_4) | 106 command_id <= IDC_SPELLCHECK_SUGGESTION_4) |
| 107 return true; | 107 return true; |
| 108 | 108 |
| 109 return command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION; | 109 return command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION; |
| 110 } | 110 } |
| 111 | 111 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 loading_frame_ = (loading_frame_ + 1) & 3; | 315 loading_frame_ = (loading_frame_ + 1) & 3; |
| 316 string16 loading_message = loading_message_; | 316 string16 loading_message = loading_message_; |
| 317 for (int i = 0; i < loading_frame_; ++i) | 317 for (int i = 0; i < loading_frame_; ++i) |
| 318 loading_message.push_back('.'); | 318 loading_message.push_back('.'); |
| 319 | 319 |
| 320 // Update the menu item with the text. We disable this item to prevent users | 320 // Update the menu item with the text. We disable this item to prevent users |
| 321 // from selecting it. | 321 // from selecting it. |
| 322 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, | 322 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, |
| 323 loading_message); | 323 loading_message); |
| 324 } | 324 } |
| OLD | NEW |