Bug 1355771 - Automatically enable Firefox touch mode in Windows Tablet mode. r=dao
authorJohann Hofmann <jhofmann@mozilla.com>
Wed, 07 Jun 2017 12:54:39 +0200
changeset 363916 447ee226867861f9445ccc4727eb99cce8a16b9e
parent 363915 1a4e879533059ab6e9f5a03451324e2ba53238d8
child 363917 10fea15972fa09892bbe1d6bcf2ff7663812c6c5
push id44724
push userjhofmann@mozilla.com
push dateWed, 14 Jun 2017 13:10:58 +0000
treeherderautoland@447ee2268678 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1355771
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1355771 - Automatically enable Firefox touch mode in Windows Tablet mode. r=dao 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;
     }
   },
 };