Bug 1335907 - Pref Reorg. WORK IN PROGRESS. r?jaws, r?mconley draft
authorZack Herrick <herrickz@msu.edu>
Thu, 09 Feb 2017 20:21:51 -0500
changeset 481572 944d3beb3d987309c00d50bbd276125bd22d514f
parent 481568 29e2ef3b61980dcd6c5e7c6e0c30357c3ebff1aa
child 482213 29a038a79ae4632bf220f159e8c947a81242df0f
push id44845
push userbmo:herrickz@msu.edu
push dateFri, 10 Feb 2017 01:41:00 +0000
reviewersjaws, mconley
bugs1335907
milestone54.0a1
Bug 1335907 - Pref Reorg. WORK IN PROGRESS. r?jaws, r?mconley MozReview-Commit-ID: 2cqH5lhOUzW
browser/components/preferences/in-content/advanced.xul
browser/components/preferences/in-content/content.js
browser/components/preferences/in-content/content.xul
browser/components/preferences/in-content/main.js
browser/components/preferences/in-content/main.xul
--- a/browser/components/preferences/in-content/advanced.xul
+++ b/browser/components/preferences/in-content/advanced.xul
@@ -171,17 +171,17 @@
                   accesskey="&searchOnStartTyping.accesskey;"
                   preference="accessibility.typeaheadfind"/>
         <checkbox id="blockAutoRefresh"
                   label="&blockAutoReload.label;"
                   accesskey="&blockAutoReload.accesskey;"
                   preference="accessibility.blockautorefresh"/>
       </groupbox>-->
       <!-- Browsing -->
-      <groupbox id="browsingGroup" align="start">
+      <!--<groupbox id="browsingGroup" align="start">
         <caption><label>&browsing.label;</label></caption>
 
         <checkbox id="useAutoScroll"
                   label="&useAutoScroll.label;"
                   accesskey="&useAutoScroll.accesskey;"
                   preference="general.autoScroll"/>
         <checkbox id="useSmoothScrolling"
                   label="&useSmoothScrolling.label;"
@@ -192,17 +192,17 @@
                   accesskey="&allowHWAccel.accesskey;"
                   preference="layers.acceleration.disabled"/>
         <checkbox id="checkSpelling"
                   label="&checkUserSpelling.label;"
                   accesskey="&checkUserSpelling.accesskey;"
                   onsyncfrompreference="return gAdvancedPane.readCheckSpelling();"
                   onsynctopreference="return gAdvancedPane.writeCheckSpelling();"
                   preference="layout.spellcheckDefault"/>
-      </groupbox>
+      </groupbox>-->
     </tabpanel>
 #ifdef MOZ_DATA_REPORTING
     <!-- Data Choices -->
     <tabpanel id="dataChoicesPanel" orient="vertical">
 #ifdef MOZ_TELEMETRY_REPORTING
       <groupbox>
         <caption>
           <checkbox id="submitHealthReportBox" label="&enableHealthReport.label;"
--- a/browser/components/preferences/in-content/content.js
+++ b/browser/components/preferences/in-content/content.js
@@ -18,21 +18,21 @@ XPCOMUtils.defineLazyGetter(this, "Alert
 var gContentPane = {
   init() {
     function setEventListener(aId, aEventType, aCallback) {
       document.getElementById(aId)
               .addEventListener(aEventType, aCallback.bind(gContentPane));
     }
 
     // Initializes the fonts dropdowns displayed in this pane.
-    this._rebuildFonts();
-    var menulist = document.getElementById("defaultFont");
-    if (menulist.selectedIndex == -1) {
-      menulist.value = FontBuilder.readFontSelection(menulist);
-    }
+    // this._rebuildFonts();
+    // var menulist = document.getElementById("defaultFont");
+    // if (menulist.selectedIndex == -1) {
+    //   menulist.value = FontBuilder.readFontSelection(menulist);
+    // }
 
     // Show translation preferences if we may:
     const prefName = "browser.translation.ui.show";
     if (Services.prefs.getBoolPref(prefName)) {
       let row = document.getElementById("translationBox");
       row.removeAttribute("hidden");
       // Showing attribution only for Bing Translator.
       Components.utils.import("resource:///modules/translation/Translation.jsm");
@@ -53,20 +53,20 @@ var gContentPane = {
     }
 
     setEventListener("font.language.group", "change",
       gContentPane._rebuildFonts);
     setEventListener("notificationsPolicyButton", "command",
       gContentPane.showNotificationExceptions);
     setEventListener("popupPolicyButton", "command",
       gContentPane.showPopupExceptions);
-    setEventListener("advancedFonts", "command",
-      gContentPane.configureFonts);
-    setEventListener("colors", "command",
-      gContentPane.configureColors);
+    // setEventListener("advancedFonts", "command",
+    //   gContentPane.configureFonts);
+    // setEventListener("colors", "command",
+    //   gContentPane.configureColors);
     // setEventListener("chooseLanguage", "command",
     //   gContentPane.showLanguages);
     // setEventListener("translationAttributionImage", "click",
     //   gContentPane.openTranslationProviderAttribution);
     // setEventListener("translateButton", "command",
     //   gContentPane.showTranslationExceptions);
     setEventListener("notificationsDoNotDisturb", "command",
       gContentPane.toggleDoNotDisturbNotifications);
@@ -231,31 +231,31 @@ var gContentPane = {
       preference.setAttribute("name", defaultFontTypePref);
       preference.setAttribute("type", "string");
       preference.setAttribute("onchange", "gContentPane._rebuildFonts();");
       document.getElementById("contentPreferences").appendChild(preference);
     }
     return preference.value;
   },
 
-  /**
-   * Displays the fonts dialog, where web page font names and sizes can be
-   * configured.
-   */
-  configureFonts() {
-    gSubDialog.open("chrome://browser/content/preferences/fonts.xul", "resizable=no");
-  },
+  // /**
+  //  * Displays the fonts dialog, where web page font names and sizes can be
+  //  * configured.
+  //  */
+  // configureFonts() {
+  //   gSubDialog.open("chrome://browser/content/preferences/fonts.xul", "resizable=no");
+  // },
 
-  /**
-   * Displays the colors dialog, where default web page/link/etc. colors can be
-   * configured.
-   */
-  configureColors() {
-    gSubDialog.open("chrome://browser/content/preferences/colors.xul", "resizable=no");
-  },
+  // /**
+  //  * Displays the colors dialog, where default web page/link/etc. colors can be
+  //  * configured.
+  //  */
+  // configureColors() {
+  //   gSubDialog.open("chrome://browser/content/preferences/colors.xul", "resizable=no");
+  // },
 
   // LANGUAGES
 
   // /**
   //  * Shows a dialog in which the preferred language for web content may be set.
   //  */
   // showLanguages() {
   //   gSubDialog.open("chrome://browser/content/preferences/languages.xul");
--- a/browser/components/preferences/in-content/content.xul
+++ b/browser/components/preferences/in-content/content.xul
@@ -112,17 +112,17 @@
                   accesskey="&popupExceptions.accesskey;"/>
         </hbox>
       </row>
     </rows>
   </grid>
 </groupbox>
 
 <!-- Fonts and Colors -->
-<groupbox id="fontsGroup" data-category="paneContent" hidden="true">
+<!--<groupbox id="fontsGroup" data-category="paneContent" hidden="true">
   <caption><label>&fontsAndColors.label;</label></caption>
 
   <grid id="fontsGrid">
     <columns>
       <column flex="1"/>
       <column/>
     </columns>
     <rows id="fontsRows">
@@ -168,17 +168,17 @@
       <row id="colorsRow">
         <hbox/>
         <button id="colors" icon="select-color"
                 label="&colors.label;"
                 accesskey="&colors.accesskey;"/>
       </row>
     </rows>
   </grid>
-</groupbox>
+</groupbox>-->
 
 <!-- Languages -->
 <!--<groupbox id="languagesGroup" data-category="paneContent" hidden="true">
   <caption><label>&languages.label;</label></caption>
 
   <hbox id="languagesBox" align="center">
     <description flex="1" control="chooseLanguage">&chooseLanguage.label;</description>
     <button id="chooseLanguage"
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -76,24 +76,38 @@ var gMainPane = {
                      gMainPane.setHomePageToCurrent);
     setEventListener("useBookmark", "command",
                      gMainPane.setHomePageToBookmark);
     setEventListener("restoreDefaultHomePage", "command",
                      gMainPane.restoreDefaultHomePage);
     //setEventListener("chooseFolder", "command",
     //                 gMainPane.chooseFolder);
 
-    // Content.js setEventListener functions
+    // Content.js setEventListener language functions
     setEventListener("chooseLanguage", "command",
       gMainPane.showLanguages);
     setEventListener("translationAttributionImage", "click",
       gMainPane.openTranslationProviderAttribution);
     setEventListener("translateButton", "command",
       gMainPane.showTranslationExceptions);
 
+    // Content.js setEventListener font functions
+    setEventListener("advancedFonts", "command",
+      gMainPane.configureFonts);
+    setEventListener("colors", "command",
+      gMainPane.configureColors);
+
+    // Content.js init function
+    // Initializes the fonts dropdowns displayed in this pane.
+    this._rebuildFonts();
+    var menulist = document.getElementById("defaultFont");
+    if (menulist.selectedIndex == -1) {
+      menulist.value = FontBuilder.readFontSelection(menulist);
+    }
+
     if (AppConstants.E10S_TESTING_ONLY) {
       setEventListener("e10sAutoStart", "command",
                        gMainPane.enableE10SChange);
       let e10sCheckbox = document.getElementById("e10sAutoStart");
 
       let e10sPref = document.getElementById("browser.tabs.remote.autostart");
       let e10sTempPref = document.getElementById("e10sTempPref");
       let e10sForceEnable = document.getElementById("e10sForceEnable");
@@ -719,9 +733,106 @@ var gMainPane = {
   showTranslationExceptions() {
     gSubDialog.open("chrome://browser/content/preferences/translation.xul");
   },
 
   openTranslationProviderAttribution() {
     Components.utils.import("resource:///modules/translation/Translation.jsm");
     Translation.openProviderAttribution();
   },
+
+  /**
+   * Displays the fonts dialog, where web page font names and sizes can be
+   * configured.
+   */
+  configureFonts() {
+    gSubDialog.open("chrome://browser/content/preferences/fonts.xul", "resizable=no");
+  },
+
+  /**
+   * Displays the colors dialog, where default web page/link/etc. colors can be
+   * configured.
+   */
+  configureColors() {
+    gSubDialog.open("chrome://browser/content/preferences/colors.xul", "resizable=no");
+  },
+
+  // FONTS
+
+  /**
+   * Populates the default font list in UI.
+   */
+  _rebuildFonts() {
+    var preferences = document.getElementById("contentPreferences");
+    // Ensure preferences are "visible" to ensure bindings work.
+    preferences.hidden = false;
+    // Force flush:
+    preferences.clientHeight;
+    var langGroupPref = document.getElementById("font.language.group");
+    this._selectDefaultLanguageGroup(langGroupPref.value,
+                                     this._readDefaultFontTypeForLanguage(langGroupPref.value) == "serif");
+  },
+
+  /**
+   * Returns the type of the current default font for the language denoted by
+   * aLanguageGroup.
+   */
+  _readDefaultFontTypeForLanguage(aLanguageGroup) {
+    const kDefaultFontType = "font.default.%LANG%";
+    var defaultFontTypePref = kDefaultFontType.replace(/%LANG%/, aLanguageGroup);
+    var preference = document.getElementById(defaultFontTypePref);
+    if (!preference) {
+      preference = document.createElement("preference");
+      preference.id = defaultFontTypePref;
+      preference.setAttribute("name", defaultFontTypePref);
+      preference.setAttribute("type", "string");
+      preference.setAttribute("onchange", "gContentPane._rebuildFonts();");
+      document.getElementById("contentPreferences").appendChild(preference);
+    }
+    return preference.value;
+  },
+
+  _selectDefaultLanguageGroup(aLanguageGroup, aIsSerif) {
+    const kFontNameFmtSerif         = "font.name.serif.%LANG%";
+    const kFontNameFmtSansSerif     = "font.name.sans-serif.%LANG%";
+    const kFontNameListFmtSerif     = "font.name-list.serif.%LANG%";
+    const kFontNameListFmtSansSerif = "font.name-list.sans-serif.%LANG%";
+    const kFontSizeFmtVariable      = "font.size.variable.%LANG%";
+
+    var preferences = document.getElementById("contentPreferences");
+    var prefs = [{ format   : aIsSerif ? kFontNameFmtSerif : kFontNameFmtSansSerif,
+                   type     : "fontname",
+                   element  : "defaultFont",
+                   fonttype : aIsSerif ? "serif" : "sans-serif" },
+                 { format   : aIsSerif ? kFontNameListFmtSerif : kFontNameListFmtSansSerif,
+                   type     : "unichar",
+                   element  : null,
+                   fonttype : aIsSerif ? "serif" : "sans-serif" },
+                 { format   : kFontSizeFmtVariable,
+                   type     : "int",
+                   element  : "defaultFontSize",
+                   fonttype : null }];
+    for (var i = 0; i < prefs.length; ++i) {
+      var preference = document.getElementById(prefs[i].format.replace(/%LANG%/, aLanguageGroup));
+      if (!preference) {
+        preference = document.createElement("preference");
+        var name = prefs[i].format.replace(/%LANG%/, aLanguageGroup);
+        preference.id = name;
+        preference.setAttribute("name", name);
+        preference.setAttribute("type", prefs[i].type);
+        preferences.appendChild(preference);
+      }
+
+      if (!prefs[i].element)
+        continue;
+
+      var element = document.getElementById(prefs[i].element);
+      if (element) {
+        element.setAttribute("preference", preference.id);
+
+        if (prefs[i].fonttype)
+          FontBuilder.buildFontList(aLanguageGroup, prefs[i].fonttype, element);
+
+        preference.setElementValue(element);
+      }
+    }
+  },
 };
--- a/browser/components/preferences/in-content/main.xul
+++ b/browser/components/preferences/in-content/main.xul
@@ -431,8 +431,91 @@
         <separator orient="vertical" class="thin"/>
         <label>&translation.options.attribution.afterLogo;</label>
       </hbox>
     </hbox>
     <button id="translateButton" label="&translateExceptions.label;"
             accesskey="&translateExceptions.accesskey;"/>
   </hbox>
 </groupbox>
+
+<!-- Fonts and Colors -->
+<groupbox id="fontsGroup" data-category="paneGeneral" hidden="true">
+  <caption><label>&fontsAndColors.label;</label></caption>
+
+  <grid id="fontsGrid">
+    <columns>
+      <column flex="1"/>
+      <column/>
+    </columns>
+    <rows id="fontsRows">
+      <row id="fontRow">
+        <hbox align="center">
+          <label control="defaultFont" accesskey="&defaultFont.accesskey;">&defaultFont.label;</label>
+          <menulist id="defaultFont" delayprefsave="true"/>
+          <label id="defaultFontSizeLabel" control="defaultFontSize" accesskey="&defaultSize.accesskey;">&defaultSize.label;</label>
+          <menulist id="defaultFontSize" delayprefsave="true">
+            <menupopup>
+              <menuitem value="9" label="9"/>
+              <menuitem value="10" label="10"/>
+              <menuitem value="11" label="11"/>
+              <menuitem value="12" label="12"/>
+              <menuitem value="13" label="13"/>
+              <menuitem value="14" label="14"/>
+              <menuitem value="15" label="15"/>
+              <menuitem value="16" label="16"/>
+              <menuitem value="17" label="17"/>
+              <menuitem value="18" label="18"/>
+              <menuitem value="20" label="20"/>
+              <menuitem value="22" label="22"/>
+              <menuitem value="24" label="24"/>
+              <menuitem value="26" label="26"/>
+              <menuitem value="28" label="28"/>
+              <menuitem value="30" label="30"/>
+              <menuitem value="32" label="32"/>
+              <menuitem value="34" label="34"/>
+              <menuitem value="36" label="36"/>
+              <menuitem value="40" label="40"/>
+              <menuitem value="44" label="44"/>
+              <menuitem value="48" label="48"/>
+              <menuitem value="56" label="56"/>
+              <menuitem value="64" label="64"/>
+              <menuitem value="72" label="72"/>
+            </menupopup>
+          </menulist>
+        </hbox>
+        <button id="advancedFonts" icon="select-font"
+                label="&advancedFonts.label;"
+                accesskey="&advancedFonts.accesskey;"/>
+      </row>
+      <row id="colorsRow">
+        <hbox/>
+        <button id="colors" icon="select-color"
+                label="&colors.label;"
+                accesskey="&colors.accesskey;"/>
+      </row>
+    </rows>
+  </grid>
+</groupbox>
+
+<!-- Browsing -->
+<groupbox id="browsingGroup" align="start" data-category="paneGeneral">
+  <caption><label>&browsing.label;</label></caption>
+
+  <checkbox id="useAutoScroll"
+            label="&useAutoScroll.label;"
+            accesskey="&useAutoScroll.accesskey;"
+            preference="general.autoScroll"/>
+  <checkbox id="useSmoothScrolling"
+            label="&useSmoothScrolling.label;"
+            accesskey="&useSmoothScrolling.accesskey;"
+            preference="general.smoothScroll"/>
+  <checkbox id="allowHWAccel"
+            label="&allowHWAccel.label;"
+            accesskey="&allowHWAccel.accesskey;"
+            preference="layers.acceleration.disabled"/>
+  <checkbox id="checkSpelling"
+            label="&checkUserSpelling.label;"
+            accesskey="&checkUserSpelling.accesskey;"
+            onsyncfrompreference="return gAdvancedPane.readCheckSpelling();"
+            onsynctopreference="return gAdvancedPane.writeCheckSpelling();"
+            preference="layout.spellcheckDefault"/>
+</groupbox>