Bug 1614767 - Use AppLocale to set document direction for chrome, about and resource protcols. r=jfkthame
authorZibi Braniecki <zbraniecki@mozilla.com>
Thu, 20 Feb 2020 18:43:53 +0000
changeset 514859 127a116c7f53951bf27f1f7aae3faa8ee611b451
parent 514858 226c9c2a517f6c337d965765d8b1e8373eabc1be
child 514860 3eb51d4d849995a9c70f235dd335d923e0220f14
push id107860
push userzbraniecki@mozilla.com
push dateThu, 20 Feb 2020 18:47:31 +0000
treeherderautoland@127a116c7f53 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1614767
milestone75.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 1614767 - Use AppLocale to set document direction for chrome, about and resource protcols. r=jfkthame Differential Revision: https://phabricator.services.mozilla.com/D62528
dom/base/Document.cpp
toolkit/content/tests/chrome/chrome.ini
toolkit/content/tests/chrome/rtltest/content/dirtest.xhtml
toolkit/content/tests/chrome/rtltest/righttoleft.manifest
toolkit/content/tests/chrome/test_righttoleft.xhtml
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -90,16 +90,17 @@
 #include "PermissionDelegateHandler.h"
 
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/BasicEvents.h"
 #include "mozilla/EventListenerManager.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/FullscreenChange.h"
 #include "mozilla/PendingAnimationTracker.h"
+#include "mozilla/intl/LocaleService.h"
 
 #include "mozilla/dom/Attr.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/dom/BrowsingContext.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/CSSImportRule.h"
 #include "mozilla/dom/CSPDictionariesBinding.h"
 #include "mozilla/dom/DOMIntersectionObserver.h"
@@ -306,17 +307,16 @@
 #include "mozilla/dom/SVGSVGElement.h"
 #include "mozilla/dom/DocGroup.h"
 #include "mozilla/dom/TabGroup.h"
 #include "mozilla/dom/ChromeObserver.h"
 #ifdef MOZ_XUL
 #  include "mozilla/dom/XULBroadcastManager.h"
 #  include "mozilla/dom/XULPersist.h"
 #  include "nsIAppWindow.h"
-#  include "nsIChromeRegistry.h"
 #  include "nsXULPrototypeDocument.h"
 #  include "nsXULCommandDispatcher.h"
 #  include "nsXULPopupManager.h"
 #  include "nsIDocShellTreeOwner.h"
 #endif
 
 #include "mozilla/DocLoadingTimelineMarker.h"
 
@@ -11568,38 +11568,22 @@ bool Document::IsDocumentRightToLeft() {
         return false;
       case 1:
         return true;
       default:
         break;  // otherwise, not a valid value, so fall through
     }
   }
 
-  // otherwise, get the locale from the chrome registry and
-  // look up the intl.uidirection.<locale> preference
-  nsCOMPtr<nsIXULChromeRegistry> reg =
-      mozilla::services::GetXULChromeRegistryService();
-  if (!reg) return false;
-
-  nsAutoCString package;
-  if (mDocumentURI->SchemeIs("chrome")) {
-    mDocumentURI->GetHostPort(package);
-  } else {
-    // use the 'global' package for about and resource uris.
-    // otherwise, just default to left-to-right.
-    if (mDocumentURI->SchemeIs("about") || mDocumentURI->SchemeIs("resource")) {
-      package.AssignLiteral("global");
-    } else {
-      return false;
-    }
-  }
-
-  bool isRTL = false;
-  reg->IsLocaleRTL(package, &isRTL);
-  return isRTL;
+  if (!mDocumentURI->SchemeIs("chrome") && !mDocumentURI->SchemeIs("about") &&
+      !mDocumentURI->SchemeIs("resource")) {
+    return false;
+  }
+
+  return intl::LocaleService::GetInstance()->IsAppLocaleRTL();
 }
 
 class nsDelayedEventDispatcher : public Runnable {
  public:
   explicit nsDelayedEventDispatcher(nsTArray<nsCOMPtr<Document>>& aDocuments)
       : mozilla::Runnable("nsDelayedEventDispatcher") {
     mDocuments.SwapElements(aDocuments);
   }
--- a/toolkit/content/tests/chrome/chrome.ini
+++ b/toolkit/content/tests/chrome/chrome.ini
@@ -47,18 +47,16 @@ support-files =
   window_showcaret.xhtml
   window_subframe_origin.xhtml
   window_titlebar.xhtml
   window_tooltip.xhtml
   xul_selectcontrol.js
   rtlchrome/rtl.css
   rtlchrome/rtl.dtd
   rtlchrome/rtl.manifest
-  rtltest/righttoleft.manifest
-  rtltest/content/dirtest.xhtml
 
 [test_about_networking.html]
 [test_arrowpanel.xhtml]
 skip-if = (verify && (os == 'win')) || (debug && (os == 'win') && (bits == 32)) # Bug 1546256
 [test_autocomplete2.xhtml]
 [test_autocomplete3.xhtml]
 [test_autocomplete4.xhtml]
 [test_autocomplete5.xhtml]
@@ -164,17 +162,16 @@ skip-if = (verify && (os == 'win'))
 [test_preferences.xhtml]
 [test_preferences_beforeaccept.xhtml]
 support-files = window_preferences_beforeaccept.xhtml
 [test_preferences_onsyncfrompreference.xhtml]
 support-files = window_preferences_onsyncfrompreference.xhtml
 [test_props.xhtml]
 [test_radio.xhtml]
 [test_richlistbox.xhtml]
-[test_righttoleft.xhtml]
 [test_screenPersistence.xhtml]
 [test_scrollbar.xhtml]
 [test_showcaret.xhtml]
 [test_subframe_origin.xhtml]
 [test_tabbox.xhtml]
 [test_tabindex.xhtml]
 [test_textbox_search.xhtml]
 [test_titlebar.xhtml]
deleted file mode 100644
--- a/toolkit/content/tests/chrome/rtltest/content/dirtest.xhtml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0"?>
-
-<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
-
-<window xmlns:html="http://www.w3.org/1999/xhtml"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-
-<html:style>
-hbox, vbox { background-color: white; }
-hbox:-moz-locale-dir(ltr) { background-color: yellow; }
-vbox:-moz-locale-dir(rtl) { background-color: green; }
-</html:style>
-
-<hbox id="hbox">
-  <button label="One"/>
-  <button label="Two"/>
-  <button label="Three"/>
-</hbox>
-<vbox id="vbox">
-  <button label="One"/>
-  <button label="Two"/>
-  <button label="Three"/>
-</vbox>
-
-</window>
deleted file mode 100644
--- a/toolkit/content/tests/chrome/rtltest/righttoleft.manifest
+++ /dev/null
@@ -1,3 +0,0 @@
-content ltrtest content/
-content rtltest content/
-locale rtltest ar-QA content/
deleted file mode 100644
--- a/toolkit/content/tests/chrome/test_righttoleft.xhtml
+++ /dev/null
@@ -1,120 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
-<?xml-stylesheet 
-  href="chrome://mochikit/content/tests/SimpleTest/test.css"
-  type="text/css"?>
-
-<window title="Right to Left UI Test"
-        onload="runTest()"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-
-  <script type="application/javascript" 
-          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="application/javascript" 
-          src="chrome://mochikit/content/chrome-harness.js"></script>
-  <script type="application/javascript" 
-          src="RegisterUnregisterChrome.js"></script>
-
-  <body  xmlns="http://www.w3.org/1999/xhtml">
-    <p id="display"></p>
-    <div id="content" style="display: none">
-    </div>
-    <pre id="test">
-    </pre>
-  </body>
-
-  <iframe id="subframe" width="100" height="100" onload="frameLoaded();"/>
-
-  <script type="application/javascript">
-    <![CDATA[
-
-      SimpleTest.waitForExplicitFinish();
-
-      let prefs = Cc["@mozilla.org/preferences-service;1"].
-                  getService(Ci.nsIPrefBranch);
-      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.xhtml");
-      }
-
-      function frameLoaded()
-      {
-        var subframe = document.getElementById("subframe");
-        var subwin = subframe.contentWindow;
-        var subdoc = subframe.contentDocument;
-        var url = String(subwin.location);
-        if (url.indexOf("chrome://ltrtest") == 0) {
-          is(subwin.getComputedStyle(subdoc.getElementById("hbox")).backgroundColor,
-             "rgb(255, 255, 0)", "left to right with :-moz-locale-dir(ltr)");
-          is(subwin.getComputedStyle(subdoc.getElementById("vbox")).backgroundColor,
-             "rgb(255, 255, 255)", "left to right with :-moz-locale-dir(rtl)");
-
-          is(subwin.getComputedStyle(subdoc.documentElement).direction, "ltr",
-             "left to right direction");
-
-          subdoc.documentElement.setAttribute("localedir", "rtl");
-
-          is(subwin.getComputedStyle(subdoc.getElementById("hbox")).backgroundColor,
-             "rgb(255, 255, 255)", "left to right with :-moz-locale-dir(ltr) and localedir='rtl'");
-          is(subwin.getComputedStyle(subdoc.getElementById("vbox")).backgroundColor,
-             "rgb(0, 128, 0)", "left to right with :-moz-locale-dir(rtl) and localedir='rtl'");
-          is(subwin.getComputedStyle(subdoc.documentElement).direction, "rtl",
-             "left to right direction with localedir='rtl'");
-
-          subdoc.documentElement.removeAttribute("localedir");
-
-          is(subwin.getComputedStyle(subdoc.getElementById("hbox")).backgroundColor,
-             "rgb(255, 255, 0)", "left to right with :-moz-locale-dir(ltr) and localedir removed");
-          is(subwin.getComputedStyle(subdoc.getElementById("vbox")).backgroundColor,
-             "rgb(255, 255, 255)", "left to right with :-moz-locale-dir(rtl) and localedir removed");
-          is(subwin.getComputedStyle(subdoc.documentElement).direction, "ltr",
-             "left to right direction with localedir removed");
-
-          subframe.setAttribute("src", "chrome://rtltest/content/dirtest.xhtml");
-        }
-        else if (url.indexOf("chrome://rtltest") == 0) {
-          is(subwin.getComputedStyle(subdoc.getElementById("hbox")).backgroundColor,
-             "rgb(255, 255, 255)", "right to left with :-moz-locale-dir(ltr)");
-          is(subwin.getComputedStyle(subdoc.getElementById("vbox")).backgroundColor,
-             "rgb(0, 128, 0)", "right to left with :-moz-locale-dir(rtl)");
-          is(subwin.getComputedStyle(subdoc.documentElement).direction, "rtl",
-             "right to left direction");
-
-          subdoc.documentElement.setAttribute("localedir", "ltr");
-
-          is(subwin.getComputedStyle(subdoc.getElementById("hbox")).backgroundColor,
-             "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.setIntPref(UI_DIRECTION_PREF, -1);
-          is(subwin.getComputedStyle(subdoc.documentElement).direction, "rtl",
-             "right to left direction with default uidirection preference");
-          prefs.setIntPref(UI_DIRECTION_PREF, 0);
-          is(subwin.getComputedStyle(subdoc.documentElement).direction, "ltr",
-             "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();
-        }
-      }
-    ]]>
-  </script>
-
-</window>