Bug 606548 - Start page options > Custom vs Current pages is redundant [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Fri, 05 Nov 2010 10:10:00 -0400
changeset 66972 d20f3bc85e0c8107dd7ccb1ef68950cd692b3202
parent 66971 65f69c611234fd8a9033ebf418fc7f703785d687
child 66973 733113252ca21b3b032929784e76979aa3a6f163
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs606548
Bug 606548 - Start page options > Custom vs Current pages is redundant [r=mfinkle]
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.xul
mobile/chrome/content/preferences.js
mobile/themes/core/browser.css
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -2411,30 +2411,45 @@ var MenuListHelperUI = {
     return this._popup = document.getElementById("menulist-popup");
   },
 
   get _title() {
     delete this._title;
     return this._title = document.getElementById("menulist-title");
   },
 
+  _firePopupEvent: function firePopupEvent(aEventName) {
+    let menupopup = this._currentList.menupopup;
+    if (menupopup.hasAttribute(aEventName)) {
+      let func = new Function("event", menupopup.getAttribute(aEventName));
+      func.call(this);
+    }
+  },
+
   _currentList: null,
   show: function mn_show(aMenulist) {
     this._currentList = aMenulist;
+    this._container.setAttribute("for", aMenulist.id);
     this._title.value = aMenulist.title || "";
+    this._firePopupEvent("onpopupshowing");
 
     let container = this._container;
     let listbox = this._popup.lastChild;
     while (listbox.firstChild)
       listbox.removeChild(listbox.firstChild);
 
     let children = this._currentList.menupopup.children;
     for (let i = 0; i < children.length; i++) {
       let child = children[i];
       let item = document.createElement("richlistitem");
+      if (child.disabled)
+        item.setAttribute("disabled", "true");
+      if (child.hidden)
+        item.setAttribute("hidden", "true");
+
       // Add selected as a class name instead of an attribute to not being overidden
       // by the richlistbox behavior (it sets the "current" and "selected" attribute
       item.setAttribute("class", "menulist-command prompt-button" + (child.selected ? " selected" : ""));
 
       let image = document.createElement("image");
       image.setAttribute("src", child.image || "");
       item.appendChild(image);
 
@@ -2448,16 +2463,17 @@ var MenuListHelperUI = {
     window.addEventListener("resize", this, true);
     container.hidden = false;
     this.sizeToContent();
     BrowserUI.pushPopup(this, [this._popup]);
   },
 
   hide: function mn_hide() {
     this._currentList = null;
+    this._container.removeAttribute("for");
     this._container.hidden = true;
     window.removeEventListener("resize", this, true);
     BrowserUI.popPopup(this);
   },
 
   selectByIndex: function mn_selectByIndex(aIndex) {
     this._currentList.selectedIndex = aIndex;
 
--- a/mobile/chrome/content/browser.xul
+++ b/mobile/chrome/content/browser.xul
@@ -431,17 +431,17 @@
                   <menulist id="prefs-languages" oncommand="PreferencesView.updateLocale();">
                     <menupopup>
                       <menuitem id="prefs-languages-auto" label="&language.auto;" value="auto"/>
                     </menupopup>
                   </menulist>
                 </setting>
                 <setting id="prefs-homepage" title="&homepage.title;" type="control">
                   <menulist id="prefs-homepage-options" oncommand="PreferencesView.updateHomePage();">
-                    <menupopup>
+                    <menupopup onpopupshowing="PreferencesView.updateHomePageList();">
                       <menuitem id="prefs-homepage-default" label="&homepage.default;" value="default"/>
                       <menuitem id="prefs-homepage-none" label="&homepage.none;" value="none"/>
                       <menuitem id="prefs-homepage-currentpage" label="&homepage.currentpage;" value="currentpage"/>
                     </menupopup>
                   </menulist>
                 </setting>
 #ifdef MOZ_SERVICES_SYNC
                 <settings id="prefs-sync" label="&sync.title;">
--- a/mobile/chrome/content/preferences.js
+++ b/mobile/chrome/content/preferences.js
@@ -165,17 +165,17 @@ var PreferencesView = {
     } else {
       this._languages.selectedItem = selectedItem;
     }
     
     // Hide the setting if we only have one locale
     if (localeCount == 1)
       document.getElementById("prefs-uilanguage").hidden = true;
   },
-  
+
   updateLocale: function updateLocale() {
     // Which locale did the user select?
     let newLocale = this._languages.selectedItem.value;
     let prefs = Services.prefs;
 
     if (newLocale == "auto") {
       if (prefs.prefHasUserValue("general.useragent.locale"))
         prefs.clearUserPref("general.useragent.locale");
@@ -218,45 +218,67 @@ var PreferencesView = {
         break;
       default:
         value = "custom";
         break;
     }
 
     // Show or hide the title or URL of the custom homepage
     this._showHomePageHint(display);
-  
+
     // Add the helper "Custom Page" item in the menulist, if needed
     let options = document.getElementById("prefs-homepage-options");
     if (value == "custom") {
       // Make sure nothing is selected and just use a label to show the state
       options.appendItem(Elements.browserBundle.getString("homepage.custom2"), "custom");
     }
 
     // Select the right menulist item
     options.value = value;
   },
 
+  updateHomePageList: function updateHomePageMenuList() {
+    // Update the "Use Current Page" item in the menulist by disabling it if
+    // the current page is already the user homepage
+    let currentUrl = Browser.selectedBrowser.currentURI.spec;
+    let currentHomepage = Browser.getHomePage();
+    let isHomepage = (currentHomepage == currentUrl);
+    let itemRow = document.getElementById("prefs-homepage-currentpage");
+    if (currentHomepage == "about:home") {
+      itemRow.disabled = isHomepage;
+      itemRow.hidden = false;
+    } else {
+      itemRow.hidden = isHomepage;
+      itemRow.disabled = false;
+    }
+  },
+
   updateHomePage: function updateHomePage() {
     let options = document.getElementById("prefs-homepage-options");
     let value = options.selectedItem.value;
 
     let url = "about:home";
     let display = null;
 
     switch (value) {
       case "none":
         url = "about:empty";
         break;
       case "default":
         url = "about:home";
         break;
       case "currentpage":
-        url = Browser.selectedBrowser.currentURI.spec;
-        display = Browser.selectedBrowser.contentTitle || url;
+        // If the selected page is the about:home page, emulate the default case
+        let currentURL = Browser.selectedBrowser.currentURI.spec;
+        if (currentURL == "about:home") {
+          value = "default";
+        } else {
+          url = currentURL;
+          display = Browser.selectedBrowser.contentTitle || currentURL;
+        }
         break;
     }
 
     // Show or hide the title or URL of the custom homepage
     this._showHomePageHint(display);
 
     // Is the helper already in the list
     let helper = null;
@@ -267,18 +289,21 @@ var PreferencesView = {
     // Update the helper "Custom Page" item in the menulist
     if (value == "currentpage") {
       // If the helper item is not already in the list, we need to put it there
       // (this can happen when changing from one custom page to another)
       if (!helper)
         helper = options.appendItem(Elements.browserBundle.getString("homepage.custom2"), "custom");
 
       options.selectedItem = helper;
-    } else if (helper) {
-      options.menupopup.removeChild(helper);
+    } else {
+      if (helper)
+        options.menupopup.removeChild(helper);
+
+      options.selectedItem = options.menupopup.getElementsByAttribute("value", value)[0];
     }
 
     // Save the homepage URL to a preference
     let pls = Cc["@mozilla.org/pref-localizedstring;1"].createInstance(Ci.nsIPrefLocalizedString);
     pls.data = url;
     Services.prefs.setComplexValue("browser.startup.homepage", Ci.nsIPrefLocalizedString, pls);
 
     // Save the homepage title to a preference
--- a/mobile/themes/core/browser.css
+++ b/mobile/themes/core/browser.css
@@ -432,16 +432,21 @@ toolbarbutton.choice-remotetabs {
 #tool-preferences {
   list-style-image: url("chrome://browser/skin/images/preferences-default-64.png");
 }
 
 #tool-console {
   list-style-image: url("chrome://browser/skin/images/console-default-64.png");
 }
 
+/* preferences panel UI -----------------------------------------------------*/
+#menulist-container[for="prefs-homepage-options"] .menulist-command.selected {
+  pointer-events: none;
+}
+
 /* addons panel UI   ------------------------------------------------------- */
 @media (min-width: 500px) {
   #addons-repo {
     -moz-box-orient: horizontal;
     -moz-box-align: center;
   }
 }
 
@@ -1026,16 +1031,22 @@ pageaction {
   width: 100%;
 }
 
 .prompt-button,
 .context-command {
   -moz-box-align: center;
 }
 
+.prompt-button[disabled="true"],
+.context-command[disabled="true"] {
+  pointer-events: none;
+  color: #aaa !important;
+}
+
 .prompt-button[selected="true"],
 .context-command[selected="true"] {
   background: transparent;
 }
 
 /* Override button styles */
 .prompt-button {
   margin: 0;
@@ -1061,17 +1072,17 @@ pageaction {
 
   .prompt-button:last-child:nth-child(odd),
   pageaction.odd-last-child {
     width: 100%;
   }
 }
 
 .prompt-button:not([disabled]):hover:active,
-.context-command:hover:active,
+.context-command:not([disabled]):hover:active,
 pageaction:not([disabled]):hover:active {
   background: url("chrome://browser/skin/images/popup-selected-item-hdpi.png") repeat-x !important;
   background-origin: border-box !important;
   background-clip: border-box !important;
   -moz-border-top-colors: transparent;
   -moz-border-left-colors: transparent;
 }
 
@@ -1392,17 +1403,17 @@ pageaction:not([image]) > hbox >.pageact
 .chrome-select-option[filtered="true"] {
   display: none;
 }
 
 .chrome-select-option[selected="true"] {
   background-color: #8db8d8;
 }
 
-echrome-select-option[disabled="true"] {
+.chrome-select-option[disabled="true"] {
   pointer-events: none;
   color: #aaa !important;
 }
 
 .chrome-select-option.optgroup {
   font-weight: bold;
   font-style: italic;
 }