diff options
-rw-r--r-- | chrome/app/generated_resources.grd | 6 | ||||
-rw-r--r-- | chrome/browser/dom_ui/options/core_options_handler.cc | 41 | ||||
-rw-r--r-- | chrome/browser/dom_ui/options/core_options_handler.h | 24 | ||||
-rw-r--r-- | chrome/browser/dom_ui/options/font_settings_handler.cc | 26 | ||||
-rw-r--r-- | chrome/browser/options_util.cc | 2 | ||||
-rw-r--r-- | chrome/browser/resources/options.html | 3 | ||||
-rw-r--r-- | chrome/browser/resources/options/font_settings.html | 14 | ||||
-rw-r--r-- | chrome/browser/resources/options/font_settings.js | 2 | ||||
-rw-r--r-- | chrome/browser/resources/options/font_settings_ui.js | 83 | ||||
-rw-r--r-- | chrome/browser/resources/options/preferences.js | 11 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 2 |
11 files changed, 190 insertions, 24 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 9604aa8..9aec5e1 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -6137,6 +6137,12 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_FONT_LANGUAGE_SETTING_FONT_SIZE_SELECTOR_LABEL" desc="Dialog label for font size selection"> Size: </message> + <message name="IDS_FONT_LANGUAGE_SETTING_MINIMUM_FONT_SIZE_TITLE" desc="Section title for minimum font size selection"> + Minimum Font Size + </message> + <message name="IDS_FONT_LANGUAGE_SETTING_NO_MINIMUM_FONT_SIZE_LABEL" desc="Label for the 'None' minimum font size selection"> + None + </message> <!-- HTTP POST Warning --> <message name="IDS_HTTP_POST_WARNING_TITLE" desc="Title for dialog that warns users about a navigation that results in a repost"> diff --git a/chrome/browser/dom_ui/options/core_options_handler.cc b/chrome/browser/dom_ui/options/core_options_handler.cc index cb19ceb..520c57bd 100644 --- a/chrome/browser/dom_ui/options/core_options_handler.cc +++ b/chrome/browser/dom_ui/options/core_options_handler.cc @@ -117,6 +117,8 @@ void CoreOptionsHandler::RegisterMessages() { NewCallback(this, &CoreOptionsHandler::HandleSetStringPref)); dom_ui_->RegisterMessageCallback("setObjectPref", NewCallback(this, &CoreOptionsHandler::HandleSetObjectPref)); + dom_ui_->RegisterMessageCallback("clearPref", + NewCallback(this, &CoreOptionsHandler::HandleClearPref)); dom_ui_->RegisterMessageCallback("coreOptionsUserMetricsAction", NewCallback(this, &CoreOptionsHandler::HandleUserMetricsAction)); } @@ -126,7 +128,6 @@ void CoreOptionsHandler::HandleInitialize(const ListValue* args) { } Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) { - DCHECK(dom_ui_); PrefService* pref_service = dom_ui_->GetProfile()->GetPrefs(); const PrefService::Preference* pref = @@ -152,7 +153,6 @@ void CoreOptionsHandler::SetPref(const std::string& pref_name, Value::ValueType pref_type, const std::string& value_string, const std::string& metric) { - DCHECK(dom_ui_); PrefService* pref_service = dom_ui_->GetProfile()->GetPrefs(); switch (pref_type) { @@ -176,6 +176,16 @@ void CoreOptionsHandler::SetPref(const std::string& pref_name, ProcessUserMetric(pref_type, value_string, metric); } +void CoreOptionsHandler::ClearPref(const std::string& pref_name, + const std::string& metric) { + PrefService* pref_service = dom_ui_->GetProfile()->GetPrefs(); + pref_service->ClearPref(pref_name.c_str()); + pref_service->ScheduleSavePersistentPrefs(); + + if (!metric.empty()) + UserMetricsRecordAction(UserMetricsAction(metric.c_str())); +} + void CoreOptionsHandler::ProcessUserMetric(Value::ValueType pref_type, const std::string& value_string, const std::string& metric) { @@ -196,9 +206,7 @@ void CoreOptionsHandler::StopObservingPref(const std::string& path) { void CoreOptionsHandler::HandleFetchPrefs(const ListValue* args) { // First param is name of callback function, so, there needs to be at least // one more element for the actual preference identifier. - const size_t kMinFetchPrefsParamCount = 2; - if (args->GetSize() < kMinFetchPrefsParamCount) - return; + DCHECK_GE(static_cast<int>(args->GetSize()), 2); // Get callback JS function name. Value* callback; @@ -233,9 +241,7 @@ void CoreOptionsHandler::HandleFetchPrefs(const ListValue* args) { void CoreOptionsHandler::HandleObservePrefs(const ListValue* args) { // First param is name is JS callback function name, the rest are pref // identifiers that we are observing. - const size_t kMinObservePrefsParamCount = 2; - if (args->GetSize() < kMinObservePrefsParamCount) - return; + DCHECK_GE(static_cast<int>(args->GetSize()), 2); // Get preference change callback function name. string16 callback_func_name; @@ -281,8 +287,7 @@ void CoreOptionsHandler::HandleSetObjectPref(const ListValue* args) { void CoreOptionsHandler::HandleSetPref(const ListValue* args, Value::ValueType type) { - if (args->GetSize() < 2) - return; + DCHECK_GT(static_cast<int>(args->GetSize()), 1); std::string pref_name; if (!args->GetString(0, &pref_name)) @@ -299,6 +304,20 @@ void CoreOptionsHandler::HandleSetPref(const ListValue* args, SetPref(pref_name, type, value_string, metric); } +void CoreOptionsHandler::HandleClearPref(const ListValue* args) { + DCHECK_GT(static_cast<int>(args->GetSize()), 0); + + std::string pref_name; + if (!args->GetString(0, &pref_name)) + return; + + std::string metric; + if (args->GetSize() > 1) + args->GetString(1, &metric); + + ClearPref(pref_name, metric); +} + void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { std::string metric = WideToUTF8(ExtractStringValue(args)); if (!metric.empty()) @@ -306,8 +325,6 @@ void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { } void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) { - DCHECK(pref_name); - DCHECK(dom_ui_); PrefService* pref_service = dom_ui_->GetProfile()->GetPrefs(); const PrefService::Preference* pref = pref_service->FindPreference(pref_name->c_str()); diff --git a/chrome/browser/dom_ui/options/core_options_handler.h b/chrome/browser/dom_ui/options/core_options_handler.h index 42dcc23..85618e2 100644 --- a/chrome/browser/dom_ui/options/core_options_handler.h +++ b/chrome/browser/dom_ui/options/core_options_handler.h @@ -46,6 +46,9 @@ class CoreOptionsHandler : public OptionsPageUIHandler { const std::string& value_string, const std::string& metric); + // Clears pref value for given |pref_name|. + void ClearPref(const std::string& pref_name, const std::string& metric); + // Stops observing given preference identified by |path|. virtual void StopObservingPref(const std::string& path); @@ -63,9 +66,9 @@ class CoreOptionsHandler : public OptionsPageUIHandler { void HandleInitialize(const ListValue* args); // Callback for the "fetchPrefs" message. This message accepts the list of - // preference names passed as |value| parameter (ListValue). It passes results - // dictionary of preference values by calling prefsFetched() JS method on the - // page. + // preference names passed as the |args| parameter (ListValue). It passes + // results dictionary of preference values by calling prefsFetched() JS method + // on the page. void HandleFetchPrefs(const ListValue* args); // Callback for the "observePrefs" message. This message initiates @@ -73,8 +76,10 @@ class CoreOptionsHandler : public OptionsPageUIHandler { void HandleObservePrefs(const ListValue* args); // Callbacks for the "set<type>Pref" message. This message saves the new - // preference value. The input value is an array of strings representing - // name-value preference pair. + // preference value. |args| is an array of parameters as follows: + // item 0 - name of the preference. + // item 1 - the value of the preference in string form. + // item 2 - name of the metric identifier (optional). void HandleSetBooleanPref(const ListValue* args); void HandleSetIntegerPref(const ListValue* args); void HandleSetStringPref(const ListValue* args); @@ -82,8 +87,15 @@ class CoreOptionsHandler : public OptionsPageUIHandler { void HandleSetPref(const ListValue* args, Value::ValueType type); + // Callback for the "clearPref" message. This message clears a preference + // value. |args| is an array of parameters as follows: + // item 0 - name of the preference. + // item 1 - name of the metric identifier (optional). + void HandleClearPref(const ListValue* args); + // Callback for the "coreOptionsUserMetricsAction" message. This records - // an action that should be tracked if metrics recording is enabled. + // an action that should be tracked if metrics recording is enabled. |args| + // is an array that contains a single item, the name of the metric identifier. void HandleUserMetricsAction(const ListValue* args); void NotifyPrefChanged(const std::string* pref_name); diff --git a/chrome/browser/dom_ui/options/font_settings_handler.cc b/chrome/browser/dom_ui/options/font_settings_handler.cc index 2ae0d9f..ce0c31e 100644 --- a/chrome/browser/dom_ui/options/font_settings_handler.cc +++ b/chrome/browser/dom_ui/options/font_settings_handler.cc @@ -46,6 +46,11 @@ void FontSettingsHandler::GetLocalizedValues( localized_strings->SetString("fontSettingsSizeLabel", l10n_util::GetStringUTF16( IDS_FONT_LANGUAGE_SETTING_FONT_SIZE_SELECTOR_LABEL)); + + localized_strings->SetString("fontSettingsMinimumSizeTitle", + l10n_util::GetStringUTF16( + IDS_FONT_LANGUAGE_SETTING_MINIMUM_FONT_SIZE_TITLE)); + localized_strings->SetString("fontSettingsEncodingTitle", l10n_util::GetStringUTF16( IDS_FONT_LANGUAGE_SETTING_FONT_SUB_DIALOG_ENCODING_TITLE)); @@ -70,6 +75,27 @@ void FontSettingsHandler::GetLocalizedValues( } localized_strings->Set("fontSettingsFontSizeList", font_size_list); + // Miniumum font size + int minimum_font_sizes[] = { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, + 24 }; + count = arraysize(minimum_font_sizes); + ListValue* minimum_font_size_list = new ListValue; + ListValue* default_option = new ListValue(); + default_option->Append(Value::CreateIntegerValue(0)); + default_option->Append(Value::CreateStringValue( + l10n_util::GetStringUTF16( + IDS_FONT_LANGUAGE_SETTING_NO_MINIMUM_FONT_SIZE_LABEL))); + minimum_font_size_list->Append(default_option); + for (int i = 0; i < count; i++) { + ListValue* option = new ListValue(); + option->Append(Value::CreateIntegerValue(minimum_font_sizes[i])); + option->Append( + Value::CreateStringValue(base::IntToString(minimum_font_sizes[i]))); + minimum_font_size_list->Append(option); + } + localized_strings->Set("fontSettingsMinimumFontSizeList", + minimum_font_size_list); + // Encodings count = CharacterEncoding::GetSupportCanonicalEncodingCount(); ListValue* encoding_list = new ListValue; diff --git a/chrome/browser/options_util.cc b/chrome/browser/options_util.cc index 659c8b9..698b2f1 100644 --- a/chrome/browser/options_util.cc +++ b/chrome/browser/options_util.cc @@ -67,6 +67,8 @@ void OptionsUtil::ResetToDefaults(Profile* profile) { prefs::kWebKitPluginsEnabled, prefs::kWebKitSansSerifFontFamily, prefs::kWebKitSerifFontFamily, + prefs::kWebKitMinimumFontSize, + prefs::kWebKitMinimumLogicalFontSize, prefs::kWebkitTabsToLinks, }; profile->GetDownloadManager()->download_prefs()->ResetToDefaults(); diff --git a/chrome/browser/resources/options.html b/chrome/browser/resources/options.html index 3006471..27a5069 100644 --- a/chrome/browser/resources/options.html +++ b/chrome/browser/resources/options.html @@ -112,6 +112,7 @@ <script src="options/cookies_view.js"></script> <script src="options/edit_search_engine_overlay.js"></script> <script src="options/font_settings.js"></script> +<script src="options/font_settings_ui.js"></script> <script src="options/import_data_overlay.js"></script> <script src="options/passwords_exceptions.js"></script> <script src="options/passwords_exceptions_list.js"></script> @@ -345,6 +346,8 @@ cr.ui.decorate('input[pref][type=text]', options.PrefTextField); cr.ui.decorate('input[pref][type=url]', options.PrefTextField); cr.ui.decorate('#contentSettingsPage input[type=radio]', options.ContentSettingsRadio); +cr.ui.decorate('#fontSettingsMinimumSizeSelector', + options.MinimumFontSizeSelect); console.log('in bottom script'); </script> </body> diff --git a/chrome/browser/resources/options/font_settings.html b/chrome/browser/resources/options/font_settings.html index bb71136..24b080f2 100644 --- a/chrome/browser/resources/options/font_settings.html +++ b/chrome/browser/resources/options/font_settings.html @@ -51,14 +51,16 @@ </div> </section> <section> + <h3 i18n-content="fontSettingsMinimumSizeTitle"></h3> + <div> + <select id="fontSettingsMinimumSizeSelector"></select> + </div> + </section> + <section> <h3 i18n-content="fontSettingsEncodingTitle"></h3> <div> - <label style="display:inline;"> - <span i18n-content="fontSettingsEncodingLabel"></span> - <select id="fontSettingsEncodingSelector" - pref="intl.charset_default" metric="Options_ChangeFontEncoding"> - </select> - </label> + <select id="fontSettingsEncodingSelector" pref="intl.charset_default" + metric="Options_ChangeFontEncoding"></select> </div> </section> </div> diff --git a/chrome/browser/resources/options/font_settings.js b/chrome/browser/resources/options/font_settings.js index a5af374..50445ce 100644 --- a/chrome/browser/resources/options/font_settings.js +++ b/chrome/browser/resources/options/font_settings.js @@ -43,6 +43,8 @@ cr.define('options', function() { templateData.fontSettingsFontList) $('fontSettingsFixedWidthSizeSelector').initializeValues( templateData.fontSettingsFontSizeList) + $('fontSettingsMinimumSizeSelector').initializeValues( + templateData.fontSettingsMinimumFontSizeList) $('fontSettingsEncodingSelector').initializeValues( templateData.fontSettingsEncodingList) } diff --git a/chrome/browser/resources/options/font_settings_ui.js b/chrome/browser/resources/options/font_settings_ui.js new file mode 100644 index 0000000..d53557a --- /dev/null +++ b/chrome/browser/resources/options/font_settings_ui.js @@ -0,0 +1,83 @@ +// Copyright (c) 2010 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. + +cr.define('options', function() { + + ///////////////////////////////////////////////////////////////////////////// + // MinimumFontSizeSelect class: + + // Define a constructor that uses a select element as its underlying element. + var MinimumFontSizeSelect = cr.ui.define('select'); + + MinimumFontSizeSelect.prototype = { + // Set up the prototype chain + __proto__: HTMLSelectElement.prototype, + + /** + * Initialization function for the cr.ui framework. + */ + decorate: function() { + var self = this; + + // Listen to pref changes. + Preferences.getInstance().addEventListener( + 'webkit.webprefs.minimum_font_size', function(event) { + var value = (event.value && event.value['value'] != undefined) + ? event.value['value'] : event.value; + self.managed = (event.value && event.value['managed'] != undefined) + ? event.value['managed'] : false; + self.disabled = self.managed; + for (var i = 0; i < self.options.length; i++) { + if (self.options[i].value == value) { + self.selectedIndex = i; + return; + } + } + // Item not found, select first item. + self.selectedIndex = 0; + }); + + // Listen to user events. + this.addEventListener('change', + function(e) { + if (self.options[self.selectedIndex].value > 0) { + Preferences.setIntegerPref( + 'webkit.webprefs.minimum_font_size', + self.options[self.selectedIndex].value, + 'Options_ChangeMinimumFontSize'); + Preferences.setIntegerPref( + 'webkit.webprefs.minimum_logical_font_size', + self.options[self.selectedIndex].value, ''); + } else { + Preferences.clearPref( + 'webkit.webprefs.minimum_font_size', + 'Options_ChangeMinimumFontSize'); + Preferences.clearPref( + 'webkit.webprefs.minimum_logical_font_size', ''); + } + }); + }, + + /** + * Sets up options in select element. + * @param {Array} options List of option and their display text. + * Each element in the array is an array of length 2 which contains options + * value in the first element and display text in the second element. + * + * TODO(zelidrag): move this to that i18n template classes. + */ + initializeValues: function(options) { + options.forEach(function(values) { + this.appendChild(new Option(values[1], values[0])); + }, this); + } + }; + + // Export + return { + MinimumFontSizeSelect: MinimumFontSizeSelect + }; + +}); + diff --git a/chrome/browser/resources/options/preferences.js b/chrome/browser/resources/options/preferences.js index b641f37..207a6f5 100644 --- a/chrome/browser/resources/options/preferences.js +++ b/chrome/browser/resources/options/preferences.js @@ -88,6 +88,17 @@ cr.define('options', function() { chrome.send('setObjectPref', arguments); }; + /** + * Clears value of a JSON preference. + * @param {string} name Preference name. + * @param {string} metric User metrics identifier. + */ + Preferences.clearPref = function(name, metric) { + var arguments = [name]; + if (metric != undefined) arguments.push(metric); + chrome.send('clearPref', arguments); + }; + Preferences.prototype = { __proto__: cr.EventTarget.prototype, diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 7c4a35a..fa50b41 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -177,6 +177,8 @@ const char* kPrefsToObserve[] = { prefs::kWebKitFixedFontFamily, prefs::kWebKitDefaultFontSize, prefs::kWebKitDefaultFixedFontSize, + prefs::kWebKitMinimumFontSize, + prefs::kWebKitMinimumLogicalFontSize, prefs::kWebkitTabsToLinks, prefs::kDefaultCharset // kWebKitStandardFontIsSerif needs to be added |