Skip to content

Commit

Permalink
Backed out changeset c7174ac72d14 (bug 1347272) for build bustage
Browse files Browse the repository at this point in the history
  • Loading branch information
IrisHsiao committed Mar 28, 2017
1 parent 9e69c21 commit 642b6e3
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 78 deletions.
32 changes: 26 additions & 6 deletions browser/base/content/utilityOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,33 @@ function isBidiEnabled() {
if (getBoolPref("bidi.browser.ui", false))
return true;

// now see if the app locale is an RTL one.
const isRTL = Services.locale.isAppLocaleRTL;
// then check intl.uidirection.<locale>
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"].
getService(Components.interfaces.nsIXULChromeRegistry);
if (chromeReg.isLocaleRTL("global"))
return true;

if (isRTL) {
Services.prefs.setBoolPref("bidi.browser.ui", true);
}
return isRTL;
// now see if the system locale is an RTL one.
var rv = false;

try {
var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
.getService(Components.interfaces.nsILocaleService);
var systemLocale = localeService.getSystemLocale().getCategory("NSILOCALE_CTYPE").substr(0, 3);

switch (systemLocale) {
case "ar-":
case "he-":
case "fa-":
case "ug-":
case "ur-":
case "syr":
rv = true;
Services.prefs.setBoolPref("bidi.browser.ui", true);
}
} catch (e) {}

return rv;
}

function openAboutDialog() {
Expand Down
8 changes: 6 additions & 2 deletions devtools/client/jsonview/converter-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ Converter.prototype = {
os = "linux";
}

let dir = Services.locale.isAppLocaleRTL ? "rtl" : "ltr";
let chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
.getService(Ci.nsIXULChromeRegistry);
let dir = chromeReg.isLocaleRTL("global") ? "rtl" : "ltr";

return "<!DOCTYPE html>\n" +
"<html platform=\"" + os + "\" class=\"" + themeClassName +
Expand Down Expand Up @@ -266,7 +268,9 @@ Converter.prototype = {
output += "</div><div id=\"json\">" + this.highlightError(data,
errorInfo.line, errorInfo.column) + "</div>";

let dir = Services.locale.isAppLocaleRTL ? "rtl" : "ltr";
let chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
.getService(Ci.nsIXULChromeRegistry);
let dir = chromeReg.isLocaleRTL("global") ? "rtl" : "ltr";

return "<!DOCTYPE html>\n" +
"<html><head><title>" + this.htmlEncode(uri + " - Error") + "</title>" +
Expand Down
38 changes: 1 addition & 37 deletions intl/locale/LocaleService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ mozilla::StaticRefPtr<LocaleService> LocaleService::sInstance;
* The BCP47 form should be used for all calls to ICU/Intl APIs.
* The canonical form is used for all internal operations.
*/
static void
SanitizeForBCP47(nsACString& aLocale)
static void SanitizeForBCP47(nsACString& aLocale)
{
#ifdef ENABLE_INTL_API
// Currently, the only locale code we use that's not BCP47-conformant is
Expand Down Expand Up @@ -397,35 +396,6 @@ LocaleService::NegotiateLanguages(const nsTArray<nsCString>& aRequested,
return true;
}

bool
LocaleService::IsAppLocaleRTL()
{
nsAutoCString locale;
GetAppLocaleAsBCP47(locale);

#ifdef ENABLE_INTL_API
int pref = Preferences::GetInt("intl.uidirection", -1);
if (pref >= 0) {
return (pref > 0);
}
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 dir;
Preferences::GetCString(prefString.get(), &dir);
if (dir.IsEmpty()) {
int32_t hyphen = prefString.FindChar('-');
if (hyphen >= 1) {
prefString.Truncate(hyphen);
Preferences::GetCString(prefString.get(), &dir);
}
}
return dir.EqualsLiteral("rtl");
#endif
}

NS_IMETHODIMP
LocaleService::Observe(nsISupports *aSubject, const char *aTopic,
const char16_t *aData)
Expand Down Expand Up @@ -752,12 +722,6 @@ LocaleService::GetAvailableLocales(uint32_t* aCount, char*** aOutArray)

*aCount = availableLocales.Length();
*aOutArray = CreateOutArray(availableLocales);
return NS_OK;
}

NS_IMETHODIMP
LocaleService::GetIsAppLocaleRTL(bool* aRetVal)
{
(*aRetVal) = IsAppLocaleRTL();
return NS_OK;
}
5 changes: 0 additions & 5 deletions intl/locale/LocaleService.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ class LocaleService : public mozILocaleService,
LangNegStrategy aLangNegStrategy,
nsTArray<nsCString>& aRetVal);

/**
* Returns whether the current app locale is RTL.
*/
bool IsAppLocaleRTL();

private:
/**
* Locale object, a BCP47-style tag decomposed into subtags for
Expand Down
5 changes: 0 additions & 5 deletions intl/locale/mozILocaleService.idl
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,4 @@ interface mozILocaleService : nsISupports
*/
void getAvailableLocales([optional] out unsigned long aCount,
[retval, array, size_is(aCount)] out string aLocales);

/**
* Returns whether the current app locale is RTL.
*/
readonly attribute boolean isAppLocaleRTL;
};
7 changes: 0 additions & 7 deletions intl/locale/tests/gtest/TestLocaleService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,3 @@ TEST(Intl_Locale_LocaleService, GetAppLocaleAsLangTag) {

ASSERT_TRUE(appLocales[0] == locale);
}

TEST(Intl_Locale_LocaleService, IsAppLocaleRTL) {
// For now we can only test if the method doesn't crash.
LocaleService::GetInstance()->IsAppLocaleRTL();
ASSERT_TRUE(true);

}
6 changes: 0 additions & 6 deletions intl/locale/tests/unit/test_localeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ add_test(function test_setRequestedLocales() {
run_next_test();
});

add_test(function test_isAppLocaleRTL() {
do_check_true(typeof localeService.isAppLocaleRTL === 'boolean');

run_next_test();
});

do_register_cleanup(() => {
Services.prefs.clearUserPref(PREF_SELECTED_LOCALE);
Services.prefs.clearUserPref(PREF_MATCH_OS_LOCALE);
Expand Down
14 changes: 9 additions & 5 deletions netwerk/streamconv/converters/nsIndexedToHTML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "DateTimeFormat.h"
#include "nsIndexedToHTML.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla/intl/LocaleService.h"
#include "nsNetUtil.h"
#include "netCore.h"
#include "nsStringStream.h"
Expand All @@ -19,14 +18,13 @@
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefLocalizedString.h"
#include "nsIChromeRegistry.h"
#include "nsIStringBundle.h"
#include "nsITextToSubURI.h"
#include "nsXPIDLString.h"
#include <algorithm>
#include "nsIChannel.h"

using mozilla::intl::LocaleService;

NS_IMPL_ISUPPORTS(nsIndexedToHTML,
nsIDirIndexListener,
nsIStreamConverter,
Expand Down Expand Up @@ -564,8 +562,14 @@ nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext,
}

nsCString direction(NS_LITERAL_CSTRING("ltr"));
if (LocaleService::GetInstance()->IsAppLocaleRTL()) {
direction.AssignLiteral("rtl");
nsCOMPtr<nsIXULChromeRegistry> reg =
mozilla::services::GetXULChromeRegistryService();
if (reg) {
bool isRTL = false;
reg->IsLocaleRTL(NS_LITERAL_CSTRING("global"), &isRTL);
if (isRTL) {
direction.AssignLiteral("rtl");
}
}

buffer.AppendLiteral("</head>\n<body dir=\"");
Expand Down
3 changes: 2 additions & 1 deletion toolkit/components/extensions/ExtensionUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ LocaleData.prototype = {
if (message == "@@ui_locale") {
return this.uiLocale;
} else if (message.startsWith("@@bidi_")) {
let rtl = Services.locale.isAppLocaleRTL;
let registry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry);
let rtl = registry.isLocaleRTL("global");

if (message == "@@bidi_dir") {
return rtl ? "rtl" : "ltr";
Expand Down
4 changes: 3 additions & 1 deletion toolkit/components/reader/AboutReader.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "NarrateControls", "resource://gre/modul
XPCOMUtils.defineLazyModuleGetter(this, "Rect", "resource://gre/modules/Geometry.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "UITelemetry", "resource://gre/modules/UITelemetry.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "gChromeRegistry",
"@mozilla.org/chrome/chrome-registry;1", Ci.nsIXULChromeRegistry);
XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", "resource://gre/modules/PluralForm.jsm");

var gStrings = Services.strings.createBundle("chrome://global/locale/aboutReader.properties");
Expand Down Expand Up @@ -731,7 +733,7 @@ AboutReader.prototype = {
this._headerElement.setAttribute("dir", article.dir);

// The native locale could be set differently than the article's text direction.
var localeDirection = Services.locale.isAppLocaleRTL ? "rtl" : "ltr";
var localeDirection = gChromeRegistry.isLocaleRTL("global") ? "rtl" : "ltr";
this._readTimeElement.setAttribute("dir", localeDirection);
this._readTimeElement.style.textAlign = article.dir == "rtl" ? "right" : "left";
}
Expand Down
13 changes: 10 additions & 3 deletions xpfe/appshell/nsAppShellService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "nsContentUtils.h"
#include "nsThreadUtils.h"
#include "nsISupportsPrimitives.h"
#include "nsIChromeRegistry.h"
#include "nsILoadContext.h"
#include "nsIWebNavigation.h"
#include "nsIWindowlessBrowser.h"
Expand All @@ -39,7 +40,6 @@
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "mozilla/StartupTimeline.h"
#include "mozilla/intl/LocaleService.h"

#include "nsEmbedCID.h"
#include "nsIWebBrowser.h"
Expand All @@ -50,7 +50,6 @@
#endif

using namespace mozilla;
using mozilla::intl::LocaleService;

// Default URL for the hidden window, can be overridden by a pref on Mac
#define DEFAULT_HIDDENWINDOW_URL "resource://gre-resources/hiddenWindow.html"
Expand Down Expand Up @@ -721,7 +720,15 @@ nsAppShellService::JustCreateTopWindow(nsIXULWindow *aParent,

bool center = aChromeMask & nsIWebBrowserChrome::CHROME_CENTER_SCREEN;

widgetInitData.mRTL = LocaleService::GetInstance()->IsAppLocaleRTL();
nsCOMPtr<nsIXULChromeRegistry> reg =
mozilla::services::GetXULChromeRegistryService();
if (reg) {
nsAutoCString package;
package.AssignLiteral("global");
bool isRTL = false;
reg->IsLocaleRTL(package, &isRTL);
widgetInitData.mRTL = isRTL;
}

#ifdef MOZ_WIDGET_GONK
// B2G multi-screen support. Screen ID is for differentiating screens of
Expand Down

0 comments on commit 642b6e3

Please sign in to comment.