summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui
diff options
context:
space:
mode:
authorrouslan@chromium.org <rouslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-20 08:26:46 +0000
committerrouslan@chromium.org <rouslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-20 08:26:46 +0000
commit6cc4a844cc9caaf721728ba0097cff61bbf7fbeb (patch)
treee9cba89d5d28430f45e8053a274635006503386a /chrome/browser/ui
parent9687e5ef4025dca16d787afdef2bbda6c07e2272 (diff)
downloadchromium_src-6cc4a844cc9caaf721728ba0097cff61bbf7fbeb.zip
chromium_src-6cc4a844cc9caaf721728ba0097cff61bbf7fbeb.tar.gz
chromium_src-6cc4a844cc9caaf721728ba0097cff61bbf7fbeb.tar.bz2
Enable users to alter their custom dictionary from an overlay on chrome://settings/editDictionary. This overlay can also be accessed through:
Settings |_Show advanced settings... ..|_Language and spell-checker settings... ....|_Custom spelling dictionary When a user types an unknown word into a textarea, the browser underlines this word as a misspelling. The user can right-click on this word and select "Add to Dictionary". If the user made a mistake, the user needs a way to remove a word from their custom dictionary. This CL provides this functionality. Automated tests are in https://codereview.chromium.org/11280013/ and https://codereview.chromium.org/11308076/. BUG=18238 Review URL: https://chromiumcodereview.appspot.com/11362063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r--chrome/browser/ui/webui/options/core_options_handler.cc2
-rw-r--r--chrome/browser/ui/webui/options/language_dictionary_overlay_handler.cc138
-rw-r--r--chrome/browser/ui/webui/options/language_dictionary_overlay_handler.h60
-rw-r--r--chrome/browser/ui/webui/options/options_ui.cc3
4 files changed, 203 insertions, 0 deletions
diff --git a/chrome/browser/ui/webui/options/core_options_handler.cc b/chrome/browser/ui/webui/options/core_options_handler.cc
index a49a69b..3a07265 100644
--- a/chrome/browser/ui/webui/options/core_options_handler.cc
+++ b/chrome/browser/ui/webui/options/core_options_handler.cc
@@ -121,6 +121,8 @@ void CoreOptionsHandler::GetStaticLocalizedValues(
l10n_util::GetStringUTF16(IDS_LEARN_MORE));
localized_strings->SetString("close",
l10n_util::GetStringUTF16(IDS_CLOSE));
+ localized_strings->SetString("done",
+ l10n_util::GetStringUTF16(IDS_DONE));
}
void CoreOptionsHandler::Uninitialize() {
diff --git a/chrome/browser/ui/webui/options/language_dictionary_overlay_handler.cc b/chrome/browser/ui/webui/options/language_dictionary_overlay_handler.cc
new file mode 100644
index 0000000..2f86de4
--- /dev/null
+++ b/chrome/browser/ui/webui/options/language_dictionary_overlay_handler.cc
@@ -0,0 +1,138 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/options/language_dictionary_overlay_handler.h"
+
+#include "base/bind.h"
+#include "base/values.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/spellchecker/spellcheck_factory.h"
+#include "chrome/browser/spellchecker/spellcheck_service.h"
+#include "content/public/browser/web_ui.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+
+namespace options {
+
+namespace {
+bool StringCompare(const std::string& a, const std::string& b) {
+ return a.compare(b) < 0;
+}
+} // namespace
+
+LanguageDictionaryOverlayHandler::LanguageDictionaryOverlayHandler()
+ : overlay_initialized_(false),
+ dictionary_(NULL) {
+}
+
+LanguageDictionaryOverlayHandler::~LanguageDictionaryOverlayHandler() {
+}
+
+void LanguageDictionaryOverlayHandler::GetLocalizedValues(
+ base::DictionaryValue* localized_strings) {
+ RegisterTitle(localized_strings,
+ "languageDictionaryOverlayPage",
+ IDS_LANGUAGE_DICTIONARY_OVERLAY_TITLE);
+ localized_strings->SetString(
+ "languageDictionaryOverlayTitle",
+ l10n_util::GetStringUTF16(IDS_LANGUAGE_DICTIONARY_OVERLAY_TITLE));
+ localized_strings->SetString(
+ "languageDictionaryOverlayAddWordLabel",
+ l10n_util::GetStringUTF16(
+ IDS_LANGUAGE_DICTIONARY_OVERLAY_ADD_WORD_LABEL));
+}
+
+void LanguageDictionaryOverlayHandler::InitializeHandler() {
+ dictionary_ = SpellcheckServiceFactory::GetForProfile(
+ Profile::FromWebUI(web_ui()))->GetCustomDictionary();
+ dictionary_->AddObserver(this);
+}
+
+void LanguageDictionaryOverlayHandler::InitializePage() {
+}
+
+void LanguageDictionaryOverlayHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(
+ "addDictionaryWord",
+ base::Bind(&LanguageDictionaryOverlayHandler::AddWord,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "removeDictionaryWord",
+ base::Bind(&LanguageDictionaryOverlayHandler::RemoveWord,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "refreshDictionaryWords",
+ base::Bind(&LanguageDictionaryOverlayHandler::RefreshWords,
+ base::Unretained(this)));
+}
+
+void LanguageDictionaryOverlayHandler::Uninitialize() {
+ overlay_initialized_ = false;
+ if (dictionary_)
+ dictionary_->RemoveObserver(this);
+}
+
+void LanguageDictionaryOverlayHandler::OnCustomDictionaryLoaded() {
+ ResetDataModel();
+ UpdateWordList();
+}
+
+void LanguageDictionaryOverlayHandler::OnCustomDictionaryWordAdded(
+ const std::string& word) {
+}
+
+void LanguageDictionaryOverlayHandler::OnCustomDictionaryWordRemoved(
+ const std::string& word) {
+}
+
+void LanguageDictionaryOverlayHandler::ResetDataModel() {
+ // TODO(rouslan): Paginate dictionary words.
+ data_model_ = dictionary_->GetWords();
+ sort(data_model_.begin(), data_model_.end(), StringCompare);
+}
+
+void LanguageDictionaryOverlayHandler::UpdateWordList() {
+ if (!overlay_initialized_)
+ return;
+ ListValue list_value;
+ list_value.AppendStrings(data_model_);
+ web_ui()->CallJavascriptFunction("EditDictionaryOverlay.setWordList",
+ list_value);
+}
+
+void LanguageDictionaryOverlayHandler::RefreshWords(const ListValue* args) {
+ overlay_initialized_ = true;
+ ResetDataModel();
+ UpdateWordList();
+}
+
+void LanguageDictionaryOverlayHandler::AddWord(const ListValue* args) {
+ std::string new_word;
+ if (!args->GetString(0, &new_word) || new_word.empty()) {
+ NOTREACHED();
+ return;
+ }
+ dictionary_->AddWord(new_word);
+ data_model_.push_back(new_word);
+ UpdateWordList();
+}
+
+void LanguageDictionaryOverlayHandler::RemoveWord(const ListValue* args) {
+ std::string index_string;
+ if (!args->GetString(0, &index_string) || index_string.empty()) {
+ NOTREACHED();
+ return;
+ }
+ std::stringstream ss(index_string);
+ int i = -1;
+ if ((ss >> i).fail() || i < 0 || i >= (int) data_model_.size()) {
+ NOTREACHED();
+ return;
+ }
+ dictionary_->RemoveWord(data_model_.at(i));
+ data_model_.erase(data_model_.begin() + i);
+ UpdateWordList();
+}
+
+} // namespace options
diff --git a/chrome/browser/ui/webui/options/language_dictionary_overlay_handler.h b/chrome/browser/ui/webui/options/language_dictionary_overlay_handler.h
new file mode 100644
index 0000000..4c9fae2
--- /dev/null
+++ b/chrome/browser/ui/webui/options/language_dictionary_overlay_handler.h
@@ -0,0 +1,60 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_LANGUAGE_DICTIONARY_OVERLAY_HANDLER_H_
+#define CHROME_BROWSER_UI_WEBUI_OPTIONS_LANGUAGE_DICTIONARY_OVERLAY_HANDLER_H_
+
+#include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h"
+#include "chrome/browser/ui/webui/options/options_ui.h"
+
+namespace options {
+
+class LanguageDictionaryOverlayHandler
+ : public OptionsPageUIHandler,
+ public SpellcheckCustomDictionary::Observer {
+ public:
+ LanguageDictionaryOverlayHandler();
+ virtual ~LanguageDictionaryOverlayHandler();
+
+ // Overridden from OptionsPageUIHandler:
+ virtual void GetLocalizedValues(
+ base::DictionaryValue* localized_strings) OVERRIDE;
+ virtual void InitializeHandler() OVERRIDE;
+ virtual void InitializePage() OVERRIDE;
+ virtual void RegisterMessages() OVERRIDE;
+ virtual void Uninitialize() OVERRIDE;
+
+ // Overridden from SpellcheckCustomDictionary::Observer:
+ virtual void OnCustomDictionaryLoaded() OVERRIDE;
+ virtual void OnCustomDictionaryWordAdded(const std::string& word) OVERRIDE;
+ virtual void OnCustomDictionaryWordRemoved(const std::string& word) OVERRIDE;
+
+ private:
+ // Resets the data model with the words from the dictionary.
+ void ResetDataModel();
+
+ // Calls WebUI to update the dictionary words.
+ void UpdateWordList();
+
+ // Refreshes the dictionary words. Called from WebUI.
+ void RefreshWords(const base::ListValue* args);
+
+ // Adds a new word to the dictionary. Called from WebUI.
+ void AddWord(const base::ListValue* args);
+
+ // Removes a word from the dictionary. Called from WebUI.
+ void RemoveWord(const base::ListValue* args);
+
+ // Whether the overlay is initialized and ready to show data.
+ bool overlay_initialized_;
+
+ SpellcheckCustomDictionary* dictionary_;
+ std::vector<std::string> data_model_;
+
+ DISALLOW_COPY_AND_ASSIGN(LanguageDictionaryOverlayHandler);
+};
+
+} // namespace options
+
+#endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_LANGUAGE_DICTIONARY_OVERLAY_HANDLER_H_
diff --git a/chrome/browser/ui/webui/options/options_ui.cc b/chrome/browser/ui/webui/options/options_ui.cc
index 567122f..81e6db5 100644
--- a/chrome/browser/ui/webui/options/options_ui.cc
+++ b/chrome/browser/ui/webui/options/options_ui.cc
@@ -33,6 +33,7 @@
#include "chrome/browser/ui/webui/options/handler_options_handler.h"
#include "chrome/browser/ui/webui/options/home_page_overlay_handler.h"
#include "chrome/browser/ui/webui/options/import_data_handler.h"
+#include "chrome/browser/ui/webui/options/language_dictionary_overlay_handler.h"
#include "chrome/browser/ui/webui/options/language_options_handler.h"
#include "chrome/browser/ui/webui/options/manage_profile_handler.h"
#include "chrome/browser/ui/webui/options/media_devices_selection_handler.h"
@@ -249,6 +250,8 @@ OptionsUI::OptionsUI(content::WebUI* web_ui)
#else
AddOptionsPageUIHandler(localized_strings, new LanguageOptionsHandler());
#endif
+ AddOptionsPageUIHandler(localized_strings,
+ new LanguageDictionaryOverlayHandler());
AddOptionsPageUIHandler(localized_strings, new ManageProfileHandler());
AddOptionsPageUIHandler(localized_strings, new PasswordManagerHandler());
AddOptionsPageUIHandler(localized_strings, new SearchEngineManagerHandler());