Bug 1312049 - Switch nsChromeRegistry::GetDirectionForLocale to use uloc_isRightToLeft instead of a list of known-rtl locales, and replace the now-obsolete intl.uidirection.* prefs with a single override intl.uidirection for testing purposes. r=gandalf
authorJonathan Kew <jkew@mozilla.com>
Thu, 02 Feb 2017 22:12:50 +0000
changeset 381335 e75593853170fa531322517064ac7c29eba9ca24
parent 381334 7e062967c48acea1901b9d12dc40145dce822a33
child 381336 042e3d9aeca2c8c1e6b0c82fbd9042a59c69abcb
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgandalf
bugs1312049
milestone54.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 1312049 - Switch nsChromeRegistry::GetDirectionForLocale to use uloc_isRightToLeft instead of a list of known-rtl locales, and replace the now-obsolete intl.uidirection.* prefs with a single override intl.uidirection for testing purposes. r=gandalf
chrome/nsChromeRegistry.cpp
chrome/nsIChromeRegistry.idl
devtools/client/inspector/test/browser_inspector_breadcrumbs_visibility.js
dom/xul/XULDocument.cpp
modules/libpref/init/all.js
toolkit/components/extensions/test/mochitest/test_ext_i18n_css.html
toolkit/content/tests/chrome/test_bug437844.xul
toolkit/content/tests/chrome/test_righttoleft.xul
--- a/chrome/nsChromeRegistry.cpp
+++ b/chrome/nsChromeRegistry.cpp
@@ -645,16 +645,25 @@ nsChromeRegistry::MustLoadURLRemotely(ns
     *aResult = !!(flags & REMOTE_REQUIRED);
   }
   return NS_OK;
 }
 
 bool
 nsChromeRegistry::GetDirectionForLocale(const nsACString& aLocale)
 {
+#ifdef ENABLE_INTL_API
+  int pref = mozilla::Preferences::GetInt("intl.uidirection", -1);
+  if (pref >= 0) {
+    return (pref > 0);
+  }
+  nsAutoCString locale(aLocale);
+  SanitizeForBCP47(locale);
+  return uloc_isRightToLeft(locale.get());
+#else
   // first check the intl.uidirection.<locale> preference, and if that is not
   // set, check the same preference but with just the first two characters of
   // the locale. If that isn't set, default to left-to-right.
   nsAutoCString prefString = NS_LITERAL_CSTRING("intl.uidirection.") + aLocale;
   nsCOMPtr<nsIPrefBranch> prefBranch (do_GetService(NS_PREFSERVICE_CONTRACTID));
   if (!prefBranch) {
     return false;
   }
@@ -665,16 +674,17 @@ nsChromeRegistry::GetDirectionForLocale(
     int32_t hyphen = prefString.FindChar('-');
     if (hyphen >= 1) {
       nsAutoCString shortPref(Substring(prefString, 0, hyphen));
       prefBranch->GetCharPref(shortPref.get(), getter_Copies(dir));
     }
   }
 
   return dir.EqualsLiteral("rtl");
+#endif
 }
 
 NS_IMETHODIMP_(bool)
 nsChromeRegistry::WrappersEnabled(nsIURI *aURI)
 {
   nsCOMPtr<nsIURL> chromeURL (do_QueryInterface(aURI));
   if (!chromeURL)
     return false;
--- a/chrome/nsIChromeRegistry.idl
+++ b/chrome/nsIChromeRegistry.idl
@@ -53,17 +53,18 @@ interface nsIXULChromeRegistry : nsIChro
 
   // If the optional asBCP47 parameter is true, the locale code will be
   // converted to a BCP47 language tag; in particular, this means that
   // "ja-JP-mac" will be returned as "ja-JP-x-lvariant-mac", which can be
   // passed to ECMA402 Intl API methods without throwing a RangeError.
   ACString getSelectedLocale(in ACString packageName,
                              [optional] in boolean asBCP47);
   
-  // Get the direction of the locale via the intl.uidirection.<locale> pref
+  // Get whether the default writing direction of the locale is RTL
+  // (or may be overridden by intl.uidirection pref)
   boolean isLocaleRTL(in ACString package);
 
   /* Should be called when skins change. Reloads only stylesheets. */
   void refreshSkins();
 
   /**
    * Installable skin XBL is not always granted the same privileges as other
    * chrome. This asks the chrome registry whether scripts are allowed to be
--- a/devtools/client/inspector/test/browser_inspector_breadcrumbs_visibility.js
+++ b/devtools/client/inspector/test/browser_inspector_breadcrumbs_visibility.js
@@ -44,21 +44,21 @@ add_task(function* () {
 
   yield toolbox.switchHost(Toolbox.HostType.WINDOW);
   let hostWindow = toolbox.win.parent;
   let originalWidth = hostWindow.outerWidth;
   let originalHeight = hostWindow.outerHeight;
   hostWindow.resizeTo(640, 300);
 
   info("Testing transitions ltr");
-  yield pushPref("intl.uidirection.en-US", "ltr");
+  yield pushPref("intl.uidirection", 0);
   yield testBreadcrumbTransitions(hostWindow, inspector);
 
   info("Testing transitions rtl");
-  yield pushPref("intl.uidirection.en-US", "rtl");
+  yield pushPref("intl.uidirection", 1);
   yield testBreadcrumbTransitions(hostWindow, inspector);
 
   hostWindow.resizeTo(originalWidth, originalHeight);
 });
 
 function* testBreadcrumbTransitions(hostWindow, inspector) {
   let breadcrumbs = inspector.panelDoc.getElementById("inspector-breadcrumbs");
   let startBtn = breadcrumbs.querySelector(".scrollbutton-up");
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -234,17 +234,17 @@ XULDocument::~XULDocument()
     mPersistenceIds.Clear();
 
     // Destroy our broadcaster map.
     delete mBroadcasterMap;
 
     delete mTemplateBuilderTable;
 
     Preferences::UnregisterCallback(XULDocument::DirectionChanged,
-                                    "intl.uidirection.", this);
+                                    "intl.uidirection", this);
 
     if (mOffThreadCompileStringBuf) {
       js_free(mOffThreadCompileStringBuf);
     }
 }
 
 } // namespace dom
 } // namespace mozilla
@@ -1893,17 +1893,17 @@ XULDocument::Init()
         nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
         if (!cache) {
           NS_ERROR("Could not instantiate nsXULPrototypeCache");
           return NS_ERROR_FAILURE;
         }
     }
 
     Preferences::RegisterCallback(XULDocument::DirectionChanged,
-                                  "intl.uidirection.", this);
+                                  "intl.uidirection", this);
 
     return NS_OK;
 }
 
 
 nsresult
 XULDocument::StartLayout(void)
 {
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2052,22 +2052,26 @@ pref("intl.ime.hack.on_ime_unaware_apps.
 #endif
 
 // If you use legacy Chinese IME which puts an ideographic space to composition
 // string as placeholder, this pref might be useful.  If this is true and when
 // web contents forcibly commits composition (e.g., moving focus), the
 // ideographic space will be ignored (i.e., commits with empty string).
 pref("intl.ime.remove_placeholder_character_at_commit", false);
 
+#ifdef ENABLE_INTL_API
+pref("intl.uidirection", -1); // -1 to set from locale; 0 for LTR; 1 for RTL
+#else
 // these locales have right-to-left UI
 pref("intl.uidirection.ar", "rtl");
 pref("intl.uidirection.he", "rtl");
 pref("intl.uidirection.fa", "rtl");
 pref("intl.uidirection.ug", "rtl");
 pref("intl.uidirection.ur", "rtl");
+#endif
 
 // use en-US hyphenation by default for content tagged with plain lang="en"
 pref("intl.hyphenation-alias.en", "en-us");
 // and for other subtags of en-*, if no specific patterns are available
 pref("intl.hyphenation-alias.en-*", "en-us");
 
 pref("intl.hyphenation-alias.af-*", "af");
 pref("intl.hyphenation-alias.bg-*", "bg");
--- a/toolkit/components/extensions/test/mochitest/test_ext_i18n_css.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_i18n_css.html
@@ -89,28 +89,32 @@ add_task(function* test_i18n_css() {
   win.close();
 
   cssURL = cssURL.replace(/foo.css$/, "locale.css");
 
   css = yield fetch(cssURL);
   is(css, '* { content: "en_US ltr rtl left right" }', "CSS file localized in mochitest scope");
 
   const LOCALE = "general.useragent.locale";
-  const DIR = "intl.uidirection.en";
+  const DIR = "intl.uidirection";
+  const DIR_LEGACY = "intl.uidirection.en"; // Needed for Android until bug 1215247 is resolved
 
   // We don't wind up actually switching the chrome registry locale, since we
-  // don't have a chrome package for Hebrew. So just override it.
+  // don't have a chrome package for Hebrew. So just override it, and force
+  // RTL directionality.
   SpecialPowers.setCharPref(LOCALE, "he");
-  SpecialPowers.setCharPref(DIR, "rtl");
+  SpecialPowers.setIntPref(DIR, 1);
+  SpecialPowers.setCharPref(DIR_LEGACY, "rtl");
 
   css = yield fetch(cssURL);
   is(css, '* { content: "he rtl ltr right left" }', "CSS file localized in mochitest scope");
 
   SpecialPowers.clearUserPref(LOCALE);
   SpecialPowers.clearUserPref(DIR);
+  SpecialPowers.clearUserPref(DIR_LEGACY);
 
   yield extension.awaitFinish("i18n-css");
   yield extension.unload();
 });
 </script>
 
 </body>
 </html>
--- a/toolkit/content/tests/chrome/test_bug437844.xul
+++ b/toolkit/content/tests/chrome/test_bug437844.xul
@@ -39,17 +39,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 
       SimpleTest.expectAssertions(18, 22);
 
       /** Test for Bug 437844 and Bug 348233 **/
       SimpleTest.waitForExplicitFinish();
 
       let prefs = Components.classes["@mozilla.org/preferences-service;1"]
                             .getService(Components.interfaces.nsIPrefBranch);
-      prefs.setCharPref("intl.uidirection.en-US", "rtl");
+      prefs.setIntPref("intl.uidirection", 1);
 
       let rootDir = getRootDirectory(window.location.href);
       let manifest = rootDir + "rtlchrome/rtl.manifest";
 
       //copy rtlchrome to profile/rtlchrome and generate .manifest
       let filePath = chromeURIToFile(manifest);
       let tempProfileDir = copyDirToTempProfile(filePath.path, 'rtlchrome');
       if (tempProfileDir.path.lastIndexOf('\\') >= 0) {
@@ -77,17 +77,17 @@ https://bugzilla.mozilla.org/show_bug.cg
           frame = document.createElement("iframe");
           frame.setAttribute("src", "file://" + tmpd.path); // a file:// URI, bug 348233
           frame.addEventListener("load", function () {
               frame.removeEventListener("load", arguments.callee, false);
 
               is(frame.contentDocument.body.dir, "rtl", "file:// listings should be RTL in RTL locales");
 
               cleanupFunc();
-              prefs.clearUserPref("intl.uidirection.en-US");
+              prefs.clearUserPref("intl.uidirection");
               SimpleTest.finish();
             }, false);
           document.documentElement.appendChild(frame);
         }, false);
       document.documentElement.appendChild(frame);
 
     ]]>
   </script>
--- a/toolkit/content/tests/chrome/test_righttoleft.xul
+++ b/toolkit/content/tests/chrome/test_righttoleft.xul
@@ -27,18 +27,18 @@
 
   <script type="application/javascript">
     <![CDATA[
 
       SimpleTest.waitForExplicitFinish();
 
       let prefs = Cc["@mozilla.org/preferences-service;1"].
                   getService(Ci.nsIPrefBranch);
-      const UI_DIRECTION_PREF = "intl.uidirection.ar";
-      prefs.setCharPref(UI_DIRECTION_PREF, "rtl");
+      const UI_DIRECTION_PREF = "intl.uidirection";
+      prefs.setIntPref(UI_DIRECTION_PREF, -1);
 
       let rootDir = getRootDirectory(window.location.href);
       registerManifestPermanently(rootDir + "rtltest/righttoleft.manifest");
 
       function runTest()
       {
         var subframe = document.getElementById("subframe");
         subframe.setAttribute("src", "chrome://ltrtest/content/dirtest.xul");
@@ -93,31 +93,25 @@
              "rgb(255, 255, 0)", "right to left with :-moz-locale-dir(ltr) and localedir='ltr'");
           is(subwin.getComputedStyle(subdoc.getElementById("vbox")).backgroundColor,
              "rgb(255, 255, 255)", "right to left with :-moz-locale-dir(rtl) and localedir='ltr'");
           is(subwin.getComputedStyle(subdoc.documentElement).direction, "ltr",
              "right to left direction with localedir='ltr'");
 
           subdoc.documentElement.removeAttribute("localedir");
 
-          prefs.setCharPref(UI_DIRECTION_PREF, "");
-          is(subwin.getComputedStyle(subdoc.documentElement).direction, "ltr",
-             "left to right direction with no preference set");
-          prefs.setCharPref(UI_DIRECTION_PREF + "-QA", "rtl");
-          is(subwin.getComputedStyle(subdoc.documentElement).direction, "rtl",
-             "right to left direction with more specific preference set");
-          prefs.setCharPref(UI_DIRECTION_PREF, "ltr");
+          prefs.setIntPref(UI_DIRECTION_PREF, -1);
           is(subwin.getComputedStyle(subdoc.documentElement).direction, "rtl",
-             "right to left direction with less specific and more specific preference set");
-          prefs.setCharPref(UI_DIRECTION_PREF, "rtl");
-          prefs.setCharPref(UI_DIRECTION_PREF + "-QA", "ltr");
+             "right to left direction with default uidirection preference");
+          prefs.setIntPref(UI_DIRECTION_PREF, 0);
           is(subwin.getComputedStyle(subdoc.documentElement).direction, "ltr",
-             "left to right direction specific preference overrides");
-          if (prefs.prefHasUserValue(UI_DIRECTION_PREF + "-QA"))
-            prefs.clearUserPref(UI_DIRECTION_PREF + "-QA");
+             "right to left direction overridden by uidirection preference = 0");
+          prefs.setIntPref(UI_DIRECTION_PREF, 1);
+          is(subwin.getComputedStyle(subdoc.documentElement).direction, "rtl",
+             "right to left direction overridden by uidirection preference = 1");
 
           if (prefs.prefHasUserValue(UI_DIRECTION_PREF))
             prefs.clearUserPref(UI_DIRECTION_PREF);
 
           SimpleTest.finish();
         }
       }
     ]]>