diff options
author | markusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 07:30:39 +0000 |
---|---|---|
committer | markusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 07:30:39 +0000 |
commit | 96f766b47eaade693c4df32420a79400327e1204 (patch) | |
tree | b043e33ede7e9d8b5983bb08fcb8dc803300b460 /chrome/browser | |
parent | b75b829359b4b432d0462ab5011542f99f2021a5 (diff) | |
download | chromium_src-96f766b47eaade693c4df32420a79400327e1204.zip chromium_src-96f766b47eaade693c4df32420a79400327e1204.tar.gz chromium_src-96f766b47eaade693c4df32420a79400327e1204.tar.bz2 |
Display homepage preferences correctly.
BUG=57064
TEST=manual
Review URL: http://codereview.chromium.org/3452028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61154 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/resources/options/browser_options.html | 8 | ||||
-rw-r--r-- | chrome/browser/resources/options/browser_options.js | 184 |
2 files changed, 177 insertions, 15 deletions
diff --git a/chrome/browser/resources/options/browser_options.html b/chrome/browser/resources/options/browser_options.html index 16262d2..a713416 100644 --- a/chrome/browser/resources/options/browser_options.html +++ b/chrome/browser/resources/options/browser_options.html @@ -35,16 +35,16 @@ <section> <h3 i18n-content="homepageGroupName"></h3> <div> - <label><input type="radio" name="homepage" - pref="homepage_is_newtabpage" value="true" + <label><input type="radio" name="homepage" id="homepageUseNTPButton" + value="true" metric="Options_Homepage_IsNewTabPage"> <span i18n-content="homepageUseNewTab"></span></label> <label><input type="radio" name="homepage" id="homepageUseURLButton" - pref="homepage_is_newtabpage" value="false" + value="false" metric="Options_Homepage_IsNewTabPage"> <span i18n-content="homepageUseURL"></span></label> <div class="suboption"> - <input id="homepageURL" type="url" pref="homepage"> + <input id="homepageURL" type="url"> </div> <div class="option"> <label><input id="homepageShowButton" diff --git a/chrome/browser/resources/options/browser_options.js b/chrome/browser/resources/options/browser_options.js index bdac565..6b84fe0 100644 --- a/chrome/browser/resources/options/browser_options.js +++ b/chrome/browser/resources/options/browser_options.js @@ -21,6 +21,18 @@ cr.define('options', function() { // Inherit BrowserOptions from OptionsPage. __proto__: options.OptionsPage.prototype, + homepage_pref_: { + 'name': 'homepage', + 'value': '', + 'managed': false + }, + + homepage_is_newtabpage_pref_: { + 'name': 'homepage_is_newtabpage', + 'value': true, + 'managed': false + }, + /** * Initialize BrowserOptions page. */ @@ -42,6 +54,14 @@ cr.define('options', function() { chrome.send('coreOptionsUserMetricsAction', ['Options_ManageSearchEngines']); }; + + $('homepageUseNTPButton').onchange = + this.handleHomepageUseNTPButtonChange_.bind(this); + $('homepageUseURLButton').onchange = + this.handleHomepageUseURLButtonChange_.bind(this); + $('homepageURL').onchange = + this.handleHomepageURLChange_.bind(this) + if (!cr.isChromeOS) { $('defaultBrowserUseAsDefaultButton').onclick = function(event) { chrome.send('becomeDefaultBrowser'); @@ -63,9 +83,11 @@ cr.define('options', function() { Preferences.getInstance().addEventListener('session.restore_on_startup', this.updateCustomStartupPageControlStates_.bind(this)); Preferences.getInstance().addEventListener('homepage_is_newtabpage', - this.updateHomepageFieldState_.bind(this)); + this.handleHomepageIsNewTabPageChange_.bind(this)); + Preferences.getInstance().addEventListener('homepage', + this.handleHomepageChange_.bind(this)); + this.updateCustomStartupPageControlStates_(); - this.updateHomepageFieldState_(); // Remove Windows-style accelerators from button labels. // TODO(stuartmorgan): Remove this once the strings are updated. @@ -145,6 +167,155 @@ cr.define('options', function() { }, /** + * Handles change events of the radio button 'homepageUseURLButton'. + * @private + * @param {event} change event. + */ + handleHomepageUseURLButtonChange_: function(event) { + Preferences.setBooleanPref('homepage_is_newtabpage', false); + }, + + /** + * Handles change events of the radio button 'homepageUseNTPButton'. + * @private + * @param {event} change event. + */ + handleHomepageUseNTPButtonChange_: function(event) { + Preferences.setBooleanPref('homepage_is_newtabpage', true); + }, + + /** + * Handles change events of the text field 'homepageURL'. + * @private + * @param {event} change event. + */ + handleHomepageURLChange_: function(event) { + Preferences.setStringPref('homepage', $('homepageURL').value); + }, + + /** + * Handle change events of the preference 'homepage'. + * @private + * @param {event} preference changed event. + */ + handleHomepageChange_: function(event) { + this.homepage_pref_.value = event.value['value']; + this.homepage_pref_.managed = event.value['managed']; + if (this.isHomepageURLNewTabPageURL_() && !this.homepage_pref_.managed && + !this.homepage_is_newtabpage_pref_.managed) { + var useNewTabPage = this.isHomepageIsNewTabPageChoiceSelected_(); + Preferences.setStringPref('homepage', '') + Preferences.setBooleanPref('homepage_is_newtabpage', useNewTabPage) + } + this.updateHomepageControlStates_(); + }, + + /** + * Handle change events of the preference homepage_is_newtabpage. + * @private + * @param {event} preference changed event. + */ + handleHomepageIsNewTabPageChange_: function(event) { + this.homepage_is_newtabpage_pref_.value = event.value['value']; + this.homepage_is_newtabpage_pref_.managed = event.value['managed']; + this.updateHomepageControlStates_(); + }, + + /** + * Update homepage preference UI controls. Here's a table describing the + * desired characteristics of the homepage choice radio value, its enabled + * state and the URL field enabled state. They depend on the values of the + * managed bits for homepage (m_hp) and homepageIsNewTabPage (m_ntp) + * preferences, as well as the value of the homepageIsNewTabPage preference + * (ntp) and whether the homepage preference is equal to the new tab page + * URL (hpisntp). + * + * m_hp m_ntp ntp hpisntp| choice value| choice enabled| URL field enabled + * ------------------------------------------------------------------------ + * 0 0 0 0 | homepage | 1 | 1 + * 0 0 0 1 | new tab page| 1 | 0 + * 0 0 1 0 | new tab page| 1 | 0 + * 0 0 1 1 | new tab page| 1 | 0 + * 0 1 0 0 | homepage | 0 | 1 + * 0 1 0 1 | homepage | 0 | 1 + * 0 1 1 0 | new tab page| 0 | 0 + * 0 1 1 1 | new tab page| 0 | 0 + * 1 0 0 0 | homepage | 1 | 0 + * 1 0 0 1 | new tab page| 0 | 0 + * 1 0 1 0 | new tab page| 1 | 0 + * 1 0 1 1 | new tab page| 0 | 0 + * 1 1 0 0 | homepage | 0 | 0 + * 1 1 0 1 | new tab page| 0 | 0 + * 1 1 1 0 | new tab page| 0 | 0 + * 1 1 1 1 | new tab page| 0 | 0 + * + * thus, we have: + * + * choice value is new tab page === ntp || (hpisntp && (m_hp || !m_ntp)) + * choice enabled === !m_ntp && !(m_hp && hpisntp) + * URL field enabled === !ntp && !mhp && !(hpisntp && !m_ntp) + * + * which also make sense if you think about them. + * @private + */ + updateHomepageControlStates_: function() { + $('homepageURL').disabled = !this.isHomepageURLFieldEnabled_(); + $('homepageURL').value = this.homepage_pref_.value; + var disableChoice = !this.isHomepageChoiceEnabled_(); + $('homepageUseURLButton').disabled = disableChoice; + $('homepageUseNTPButton').disabled = disableChoice; + var useNewTabPage = this.isHomepageIsNewTabPageChoiceSelected_(); + $('homepageUseNTPButton').checked = useNewTabPage; + $('homepageUseURLButton').checked = !useNewTabPage; + }, + + /** + * Tests whether the value of the 'homepage' preference equls the new tab + * page url (chrome://newtab). + * @private + * @returns {boolean} True if the 'homepage' value equals the new tab page + * url. + */ + isHomepageURLNewTabPageURL_ : function() { + return (this.homepage_pref_.value.toLowerCase() == 'chrome://newtab'); + }, + + /** + * Tests whether the Homepage choice "Use New Tab Page" is selected. + * @private + * @returns {boolean} True if "Use New Tab Page" is selected. + */ + isHomepageIsNewTabPageChoiceSelected_: function() { + return (this.homepage_is_newtabpage_pref_.value || + (this.isHomepageURLNewTabPageURL_() && + (this.homepage_pref_.managed || + !this.homepage_is_newtabpage_pref_.managed))); + }, + + /** + * Tests whether the home page choice controls are enabled. + * @private + * @returns {boolean} True if the home page choice controls are enabled. + */ + isHomepageChoiceEnabled_: function() { + return (!this.homepage_is_newtabpage_pref_.managed && + !(this.homepage_pref_.managed && + this.isHomepageURLNewTabPageURL_())); + }, + + /** + * Checks whether the home page field should be enabled. + * @private + * @returns {boolean} True if the home page field should be enabled. + */ + isHomepageURLFieldEnabled_: function() { + return (!this.homepage_is_newtabpage_pref_.value && + !this.homepage_pref_.managed && + !(this.isHomepageURLNewTabPageURL_() && + !this.homepage_is_newtabpage_pref_.managed)); + }, + + /** * Sets the enabled state of the custom startup page list controls * based on the current startup radio button selection. * @private @@ -187,15 +358,6 @@ cr.define('options', function() { }, /** - * Sets the enabled state of the homepage field based on the current - * homepage radio button selection. - * @private - */ - updateHomepageFieldState_: function() { - $('homepageURL').disabled = !$('homepageUseURLButton').checked; - }, - - /** * Set the default search engine based on the popup selection. */ setDefaultSearchEngine: function() { |