Bug 1355771 - Automatically enable Firefox touch mode in Windows Tablet mode. draft
authorJohann Hofmann <jhofmann@mozilla.com>
Wed, 07 Jun 2017 12:54:39 +0200
changeset 594066 5198da77613f4ad427df9aa44eaeb2c775fc2da0
parent 594056 ad3f1138ce6f199408ad58d65c7476636e924909
child 633321 92eebd09fd003864afe1c819876fdc05d7bd7e7b
push id63921
push userbmo:jhofmann@mozilla.com
push dateWed, 14 Jun 2017 13:03:26 +0000
bugs1355771
milestone56.0a1
Bug 1355771 - Automatically enable Firefox touch mode in Windows Tablet mode. MozReview-Commit-ID: 1KLFdsNlib1
browser/app/profile/firefox.js
browser/base/content/browser.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -235,16 +235,23 @@ pref("general.smoothScroll", true);
 pref("general.autoScroll", false);
 #else
 pref("general.autoScroll", true);
 #endif
 
 // UI density of the browser chrome. This mostly affects toolbarbutton
 // and urlbar spacing. The possible values are 0=normal, 1=compact, 2=touch.
 pref("browser.uidensity", 0);
+// Whether Firefox will automatically override the uidensity to "touch"
+// while the user is in a touch environment (such as Windows tablet mode).
+#ifdef MOZ_PHOTON_THEME
+pref("browser.touchmode.auto", true);
+#else
+pref("browser.touchmode.auto", false);
+#endif
 
 // At startup, check if we're the default browser and prompt user if not.
 pref("browser.shell.checkDefaultBrowser", true);
 pref("browser.shell.shortcutFavicons",true);
 pref("browser.shell.mostRecentDateSetAsDefault", "");
 pref("browser.shell.skipDefaultBrowserCheckOnFirstRun", true);
 pref("browser.shell.didSkipDefaultBrowserCheckOnFirstRun", false);
 pref("browser.shell.defaultBrowserCheckCount", 0);
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -5402,16 +5402,17 @@ var TabletModeUpdater = {
   update(isInTabletMode) {
     let wasInTabletMode = document.documentElement.hasAttribute("tabletmode");
     if (isInTabletMode) {
       document.documentElement.setAttribute("tabletmode", "true");
     } else {
       document.documentElement.removeAttribute("tabletmode");
     }
     if (wasInTabletMode != isInTabletMode) {
+      gUIDensity.update();
       TabsInTitlebar.updateAppearance(true);
     }
   },
 };
 
 var gTabletModePageCounter = {
   enabled: false,
   inc() {
@@ -5441,31 +5442,44 @@ var gTabletModePageCounter = {
 };
 
 function displaySecurityInfo() {
   BrowserPageInfo(null, "securityTab");
 }
 
 // Updates the UI density (for touch and compact mode) based on the uidensity pref.
 var gUIDensity = {
+  MODE_COMPACT: 1,
+  MODE_TOUCH: 2,
   prefDomain: "browser.uidensity",
+
   observe(aSubject, aTopic, aPrefName) {
     if (aTopic != "nsPref:changed" || aPrefName != this.prefDomain)
       return;
 
     this.update();
   },
 
   update() {
+    let mode;
+    // Automatically override the uidensity to touch in Windows tablet mode.
+    if (AppConstants.isPlatformAndVersionAtLeast("win", "10") &&
+        WindowsUIUtils.inTabletMode &&
+        gPrefService.getBoolPref("browser.touchmode.auto")) {
+      mode = this.MODE_TOUCH;
+    } else {
+      mode = gPrefService.getIntPref(this.prefDomain);
+    }
+
     let doc = document.documentElement;
-    switch (gPrefService.getIntPref(this.prefDomain)) {
-    case 1:
+    switch (mode) {
+    case this.MODE_COMPACT:
       doc.setAttribute("uidensity", "compact");
       break;
-    case 2:
+    case this.MODE_TOUCH:
       doc.setAttribute("uidensity", "touch");
       break;
     default:
       doc.removeAttribute("uidensity");
       break;
     }
   },
 };