Commit e3486d52 authored by Mark Striemer's avatar Mark Striemer
Browse files

Bug 1951141 - Convert Browsing section in Settings to config...

Bug 1951141 - Convert Browsing section in Settings to config r=reusable-components-reviewers,desktop-theme-reviewers,mconley,hjones

This is the first change to start moving our settings to a config
approach. These settings are all checkboxes so only checkbox support is
added at this time.

In the future, these settings will be regrouped with other settings in
the Settings Redesign 2025 project. Moving the settings will involve
creating a new config with a different grouping of id/l10n/supportPage
values. It should not require moving any code or markup to move the
settings or convert them to using moz-checkbox rather than XUL checkbox.

Differential Revision: https://phabricator.services.mozilla.com/D240400
parent 82945ae0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -23,3 +23,5 @@ browser.jar:
   content/browser/preferences/more-from-mozilla-qr-code-simple-cn.svg
   content/browser/preferences/web-appearance-dark.svg
   content/browser/preferences/web-appearance-light.svg
   content/browser/preferences/widgets/setting-group.mjs                (widgets/setting-group/setting-group.mjs)
   content/browser/preferences/widgets/setting-group.css                (widgets/setting-group/setting-group.css)
+1 −70
Original line number Diff line number Diff line
@@ -767,76 +767,7 @@
<groupbox id="browsingGroup" data-category="paneGeneral" hidden="true">
  <label class="search-header" hidden="true"><html:h2 data-l10n-id="browsing-title"/></label>

  <checkbox id="useAutoScroll"
            data-l10n-id="browsing-use-autoscroll"
            preference="general.autoScroll"/>
  <checkbox id="useSmoothScrolling"
            data-l10n-id="browsing-use-smooth-scrolling"
            preference="general.smoothScroll"/>
#ifdef MOZ_WIDGET_GTK
  <checkbox id="useOverlayScrollbars"
            data-l10n-id="browsing-gtk-use-non-overlay-scrollbars"
            preference="widget.gtk.overlay-scrollbars.enabled"/>
#endif
#ifdef XP_WIN
  <checkbox id="useOnScreenKeyboard"
            data-l10n-id="browsing-use-onscreen-keyboard"
            preference="ui.osk.enabled"/>
#endif
  <checkbox id="useCursorNavigation"
            data-l10n-id="browsing-use-cursor-navigation"
            preference="accessibility.browsewithcaret"/>
#ifdef XP_MACOSX
  <checkbox id="useFullKeyboardNavigation"
            data-l10n-id="browsing-use-full-keyboard-navigation"
            preference="accessibility.tabfocus" />
#endif
  <checkbox id="alwaysUnderlineLinks"
            data-l10n-id="browsing-always-underline-links"
            preference="layout.css.always_underline_links"/>
  <checkbox id="searchStartTyping"
            data-l10n-id="browsing-search-on-start-typing"
            preference="accessibility.typeaheadfind"/>
  <hbox id="pictureInPictureBox" align="center" hidden="true">
    <checkbox id="pictureInPictureToggleEnabled"
            class="tail-with-learn-more"
            data-l10n-id="browsing-picture-in-picture-toggle-enabled"
            preference="media.videocontrols.picture-in-picture.video-toggle.enabled"/>
    <html:a is="moz-support-link"
          data-l10n-id="browsing-picture-in-picture-learn-more"
          support-page="picture-in-picture"
    />
  </hbox>
  <hbox id="mediaControlBox" align="center" hidden="true">
    <checkbox id="mediaControlToggleEnabled"
            class="tail-with-learn-more"
            data-l10n-id="browsing-media-control"
            preference="media.hardwaremediakeys.enabled"/>
    <html:a is="moz-support-link"
          data-l10n-id="browsing-media-control-learn-more"
          support-page="media-keyboard-control"
    />
  </hbox>
  <hbox align="center" data-subcategory="cfraddons">
    <checkbox id="cfrRecommendations"
            class="tail-with-learn-more"
            data-l10n-id="browsing-cfr-recommendations"
            preference="browser.newtabpage.activity-stream.asrouter.userprefs.cfr.addons"/>
    <html:a is="moz-support-link"
          data-l10n-id="browsing-cfr-recommendations-learn-more"
          support-page="extensionrecommendations"
    />
  </hbox>
  <hbox align="center" data-subcategory="cfrfeatures">
    <checkbox id="cfrRecommendations-features"
            class="tail-with-learn-more"
            data-l10n-id="browsing-cfr-features"
            preference="browser.newtabpage.activity-stream.asrouter.userprefs.cfr.features"/>
    <html:a is="moz-support-link"
          data-l10n-id="browsing-cfr-recommendations-learn-more"
          support-page="extensionrecommendations"
    />
  </hbox>
  <html:setting-group groupid="browsing"/>
</groupbox>

<hbox id="networkProxyCategory"
+168 −81
Original line number Diff line number Diff line
@@ -202,6 +202,173 @@ if (AppConstants.MOZ_UPDATER) {
  }
}

Preferences.addSetting({
  id: "useAutoScroll",
  pref: "general.autoScroll",
});
Preferences.addSetting({
  id: "useSmoothScrolling",
  pref: "general.smoothScroll",
});
Preferences.addSetting({
  id: "useOverlayScrollbars",
  pref: "widget.gtk.overlay-scrollbars.enabled",
  visible: () => AppConstants.MOZ_WIDGET_GTK,
});
Preferences.addSetting({
  id: "useOnScreenKeyboard",
  pref: "ui.osk.enabled",
  visible: () => AppConstants.platform == "win",
});
Preferences.addSetting({
  id: "useCursorNavigation",
  pref: "accessibility.browsewithcaret",
});
Preferences.addSetting({
  id: "useFullKeyboardNavigation",
  pref: "accessibility.tabfocus",
  visible: () => AppConstants.platform == "macosx",
  /**
   * Returns true if any full keyboard nav is enabled and false otherwise, caching
   * the current value to enable proper pref restoration if the checkbox is
   * never changed.
   *
   * accessibility.tabfocus
   * - an integer controlling the focusability of:
   *     1  text controls
   *     2  form elements
   *     4  links
   *     7  all of the above
   */
  get(prefVal) {
    this._storedFullKeyboardNavigation = prefVal;
    return prefVal == 7;
  },
  /**
   * Returns the value of the full keyboard nav preference represented by UI,
   * preserving the preference's "hidden" value if the preference is
   * unchanged and represents a value not strictly allowed in UI.
   */
  set(checked) {
    if (checked) {
      return 7;
    }
    if (this._storedFullKeyboardNavigation != 7) {
      // 1/2/4 values set via about:config should persist
      return this._storedFullKeyboardNavigation;
    }
    // When the checkbox is unchecked, default to just text controls.
    return 1;
  },
});
Preferences.addSetting({
  id: "alwaysUnderlineLinks",
  pref: "layout.css.always_underline_links",
});
Preferences.addSetting({
  id: "searchStartTyping",
  pref: "accessibility.typeaheadfind",
});
Preferences.addSetting({
  id: "pictureInPictureToggleEnabled",
  pref: "media.videocontrols.picture-in-picture.video-toggle.enabled",
  visible: () =>
    Services.prefs.getBoolPref(
      "media.videocontrols.picture-in-picture.enabled"
    ),
  onUserChange(checked) {
    if (!checked) {
      Glean.pictureinpictureSettings.disableSettings.record();
    }
  },
});
Preferences.addSetting({
  id: "mediaControlToggleEnabled",
  pref: "media.hardwaremediakeys.enabled",
  // For media control toggle button, we support it on Windows, macOS and
  // gtk-based Linux.
  visible: () =>
    AppConstants.platform == "win" ||
    AppConstants.platform == "macosx" ||
    AppConstants.MOZ_WIDGET_GTK,
});
Preferences.addSetting({
  id: "cfrRecommendations",
  pref: "browser.newtabpage.activity-stream.asrouter.userprefs.cfr.addons",
});
Preferences.addSetting({
  id: "cfrRecommendations-features",
  pref: "browser.newtabpage.activity-stream.asrouter.userprefs.cfr.features",
});

let SETTINGS_CONFIG = {
  browsing: {
    items: [
      {
        id: "useAutoScroll",
        l10nId: "browsing-use-autoscroll",
      },
      {
        id: "useSmoothScrolling",
        l10nId: "browsing-use-smooth-scrolling",
      },
      {
        id: "useOverlayScrollbars",
        l10nId: "browsing-gtk-use-non-overlay-scrollbars",
      },
      {
        id: "useOnScreenKeyboard",
        l10nId: "browsing-use-onscreen-keyboard",
      },
      {
        id: "useCursorNavigation",
        l10nId: "browsing-use-cursor-navigation",
      },
      {
        id: "useFullKeyboardNavigation",
        l10nId: "browsing-use-full-keyboard-navigation",
      },
      {
        id: "alwaysUnderlineLinks",
        l10nId: "browsing-always-underline-links",
      },
      {
        id: "searchStartTyping",
        l10nId: "browsing-search-on-start-typing",
      },
      {
        id: "pictureInPictureToggleEnabled",
        l10nId: "browsing-picture-in-picture-toggle-enabled",
        supportPage: "picture-in-picture",
      },
      {
        id: "mediaControlToggleEnabled",
        l10nId: "browsing-media-control",
        supportPage: "media-keyboard-control",
      },
      {
        id: "cfrRecommendations",
        l10nId: "browsing-cfr-recommendations",
        supportPage: "extensionrecommendations",
        subcategory: "cfraddons",
      },
      {
        id: "cfrRecommendations-features",
        l10nId: "browsing-cfr-features",
        supportPage: "extensionrecommendations",
        subcategory: "cfrfeatures",
      },
    ],
  },
};

function initSettingGroup(id) {
  let group = document.querySelector(`setting-group[groupid=${id}]`);
  if (group && SETTINGS_CONFIG[id]) {
    group.config = SETTINGS_CONFIG[id];
  }
}

ChromeUtils.defineLazyGetter(this, "gIsPackagedApp", () => {
  return Services.sysinfo.getProperty("isPackagedApp");
});
@@ -340,22 +507,7 @@ var gMainPane = {

    gMainPane.initTranslations();

    if (
      Services.prefs.getBoolPref(
        "media.videocontrols.picture-in-picture.enabled"
      )
    ) {
      document.getElementById("pictureInPictureBox").hidden = false;
      setEventListener(
        "pictureInPictureToggleEnabled",
        "command",
        function (event) {
          if (!event.target.checked) {
            Glean.pictureinpictureSettings.disableSettings.record();
          }
        }
      );
    }
    initSettingGroup("browsing");

    if (AppConstants.platform == "win") {
      // Functionality for "Show tabs in taskbar" on Windows 7 and up.
@@ -551,16 +703,6 @@ var gMainPane = {
      setEventListener("manage-profiles", "command", gMainPane.manageProfiles);
    }

    // For media control toggle button, we support it on Windows, macOS and
    // gtk-based Linux.
    if (
      AppConstants.platform == "win" ||
      AppConstants.platform == "macosx" ||
      AppConstants.MOZ_WIDGET_GTK
    ) {
      document.getElementById("mediaControlBox").hidden = false;
    }

    // Initializes the fonts dropdowns displayed in this pane.
    this._rebuildFonts();

@@ -801,18 +943,6 @@ var gMainPane = {
      document.getElementById("defaultFont"),
      element => FontBuilder.readFontSelection(element)
    );
    if (AppConstants.platform == "macosx") {
      // We only expose this control on macOS, so don't try
      // to add listeners if it doesn't exist.
      Preferences.addSyncFromPrefListener(
        document.getElementById("useFullKeyboardNavigation"),
        () => this.readUseFullKeyboardNavigation()
      );
      Preferences.addSyncToPrefListener(
        document.getElementById("useFullKeyboardNavigation"),
        () => this.writeUseFullKeyboardNavigation()
      );
    }
    Preferences.addSyncFromPrefListener(
      document.getElementById("checkSpelling"),
      () => this.readCheckSpelling()
@@ -2265,49 +2395,6 @@ var gMainPane = {
    migrationWizardDialog.showModal();
  },

  /**
   * Stores the original value of the tabfocus preference to enable proper
   * restoration if unchanged (since we're mapping an int pref onto a checkbox).
   */
  _storedFullKeyboardNavigation: Preferences.get("accessibility.tabfocus"),

  /**
   * Returns true if any full keyboard nav is enabled and false otherwise, caching
   * the current value to enable proper pref restoration if the checkbox is
   * never changed.
   *
   * accessibility.tabfocus
   * - an integer controlling the focusability of:
   *     1  text controls
   *     2  form elements
   *     4  links
   *     7  all of the above
   */
  readUseFullKeyboardNavigation() {
    var pref = Preferences.get("accessibility.tabfocus");
    this._storedFullKeyboardNavigation = pref.value;

    return pref.value == 7;
  },

  /**
   * Returns the value of the full keyboard nav preference represented by UI,
   * preserving the preference's "hidden" value if the preference is
   * unchanged and represents a value not strictly allowed in UI.
   */
  writeUseFullKeyboardNavigation() {
    var checkbox = document.getElementById("useFullKeyboardNavigation");
    if (checkbox.checked) {
      return 7;
    }
    if (this._storedFullKeyboardNavigation != 7) {
      // 1/2/4 values set via about:config should persist
      return this._storedFullKeyboardNavigation;
    }
    // When the checkbox is unchecked, default to just text controls.
    return 1;
  },

  /**
   * Stores the original value of the spellchecking preference to enable proper
   * restoration if unchanged (since we're mapping a tristate onto a checkbox).
+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
    href="chrome://browser/skin/preferences/containers.css"
  />
  <link rel="stylesheet" href="chrome://browser/skin/preferences/privacy.css" />
  <link rel="stylesheet" href="chrome://browser/content/preferences/widgets/setting-group.css" />

  <link rel="localization" href="branding/brand.ftl"/>
  <link rel="localization" href="browser/browser.ftl"/>
@@ -84,6 +85,7 @@
  <script src="chrome://browser/content/preferences/findInPage.js"/>
  <script src="chrome://browser/content/migration/migration-wizard.mjs" type="module"></script>
  <script type="module" src="chrome://browser/content/backup/backup-settings.mjs"></script>
  <script type="module" src="chrome://browser/content/preferences/widgets/setting-group.mjs"></script>
</head>

<html:body xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+2 −0
Original line number Diff line number Diff line
@@ -177,6 +177,8 @@ skip-if = ["true"]

["browser_permissions_urlFieldHidden.js"]

["browser_pip_settings.js"]

["browser_primaryPassword.js"]

["browser_privacy_cookieBannerHandling.js"]
Loading