Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: chrome/browser/resources/options2/browser_options.js

Issue 9296038: [uber] Redoing the homepage selection UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reverting a couple unintentional changes Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/options2/browser_options.js
diff --git a/chrome/browser/resources/options2/browser_options.js b/chrome/browser/resources/options2/browser_options.js
index 879cf6a02e986adddfded3c7c85fea44bd48ff92..11b220f5226b0d62c446915aede23a052843f395 100644
--- a/chrome/browser/resources/options2/browser_options.js
+++ b/chrome/browser/resources/options2/browser_options.js
@@ -28,7 +28,17 @@ cr.define('options', function() {
syncSetupCompleted: false,
/**
- * An autocomplete list that can be attached to the homepage URL text field
+ * The value attribute of the most recently selected option in the home page
+ * selector.
+ * @type {string} (One of: 'none', 'ntp', 'url')
+ */
+ previousHomePageSelection_: null,
+
+ showHomeButton_: false,
+ homePageIsNtp_: false,
+
+ /**
+ * An autocomplete list that can be attached to the home page URL text field
* during editing.
* @type {HTMLElement}
* @private
@@ -76,9 +86,17 @@ cr.define('options', function() {
});
// Appearance section.
- $('change-home-page').addEventListener('click', function(event) {
- OptionsPage.navigateToPage('homePageOverlay');
+ $('homepage-select').addEventListener(
+ 'change', this.onHomePageSelectChange_.bind(this));
+
+ ['browser.show_home_button',
+ 'homepage',
+ 'homepage_is_newtabpage'].forEach(function(pref) {
+ Preferences.getInstance().addEventListener(
+ pref,
+ self.onHomePagePrefChanged_.bind(self));
});
+
$('themes-gallery').addEventListener('click', function(event) {
window.open(localStrings.getString('themesGalleryURL'));
});
@@ -314,12 +332,90 @@ cr.define('options', function() {
},
/**
- * Sets the label for the 'Show Home page' input.
- * @param {string} label The HTML of the input label.
+ * Returns the <option> element with the given |value|.
+ * @param {string} value One of 'none', 'ntp', 'url', 'choose'.
+ * @return {HTMLOptionElement} the specified <option> element.
+ */
+ getHomePageOption_: function(value) {
+ var select = $('homepage-select');
+ return select.querySelector('option[value=' + value + ']');
+ },
+
+ /**
+ * Selects the <option> element with the given |value|.
+ * @private
+ */
+ selectHomePageOption_: function(value) {
+ var select = $('homepage-select');
+ var option = this.getHomePageOption_(value);
+ if (!option.selected)
+ option.selected = true;
+ },
+
+ /**
+ * Event listener for the |change| event on the homepage <select> element.
* @private
*/
- updateHomePageLabel_: function(label) {
- $('home-page-label').innerHTML = label;
+ onHomePageSelectChange_: function() {
+ var option = $('homepage-select').value;
+ if (option == 'choose') {
+ OptionsPage.navigateToPage('homePageOverlay');
+ return;
+ }
+
+ this.previousHomePageSelection_ = option;
+
+ var showHomeButton = (option != 'none');
+ Preferences.setBooleanPref('browser.show_home_button', showHomeButton);
+
+ if (option == 'ntp')
+ Preferences.setBooleanPref('homepage_is_newtabpage', true);
+ else if (option == 'url')
+ Preferences.setBooleanPref('homepage_is_newtabpage', false);
+ },
+
+ /**
+ * Event listener called when any homepage-related preferences change.
+ * @private
+ */
+ onHomePagePrefChanged_: function(event) {
+ switch (event.type) {
+ case 'homepage':
+ this.getHomePageOption_('url').textContent = event.value['value'];
+ break;
+ case 'browser.show_home_button':
+ this.showHomeButton_ = event.value['value'];
+ break;
+ case 'homepage_is_newtabpage':
+ this.homePageIsNtp_ = event.value['value'];
+ break;
+ default:
+ console.error('Unexpected pref change event:', event.type);
+ }
+ this.updateHomePageSelector();
+ },
+
+ /**
+ * Updates the homepage <select> element to have the appropriate option
+ * selected.
+ */
+ updateHomePageSelector: function() {
+ if (this.showHomeButton_) {
+ if (this.homePageIsNtp_)
+ this.selectHomePageOption_('ntp');
+ else
+ this.selectHomePageOption_('url');
+ } else {
+ this.selectHomePageOption_('none');
+ }
+ },
+
+ /**
+ * Sets the home page selector to the 'url' option.Called when user clicks
+ * OK in the "Choose another..." dialog.
+ */
+ homePageSelectUrl: function() {
+ this.selectHomePageOption_('url');
},
/**
@@ -404,34 +500,6 @@ cr.define('options', function() {
},
/**
- * Returns true if the custom startup page control block should
- * be enabled.
- * @returns {boolean} Whether the startup page controls should be
- * enabled.
- */
- shouldEnableCustomStartupPageControls: function(pages) {
- return $('startupShowPagesButton').checked &&
- !this.startup_pages_pref_.disabled;
- },
-
- /**
- * Sets the enabled state of the custom startup page list controls
- * based on the current startup radio button selection.
- * @private
- */
- updateCustomStartupPageControlStates_: function() {
- var disable = !this.shouldEnableCustomStartupPageControls();
- var startupPagesList = $('startupPagesList');
- startupPagesList.disabled = disable;
- startupPagesList.setAttribute('tabindex', disable ? -1 : 0);
- // Explicitly set disabled state for input text elements.
- var inputs = startupPagesList.querySelectorAll("input[type='text']");
- for (var i = 0; i < inputs.length; i++)
- inputs[i].disabled = disable;
- $('startupUseCurrentButton').disabled = disable;
- },
-
- /**
* Set the default search engine based on the popup selection.
* @private
*/
@@ -587,7 +655,6 @@ cr.define('options', function() {
'setThemesResetButtonEnabled',
'updateAccountPicture',
'updateAutocompleteSuggestions',
- 'updateHomePageLabel',
'updateSearchEngines',
'updateStartupPages',
].forEach(function(name) {

Powered by Google App Engine
This is Rietveld 408576698