From 09e84c09b661be4714e66216ac66ee2814eec28e Mon Sep 17 00:00:00 2001 From: Simon Montagu Date: Mon, 21 Dec 2009 12:21:52 +0200 Subject: [PATCH] Bug 224547: Change the organization of the window title bar for RTL XUL windows. Part 1, refactoring, r=enndeakin --- chrome/src/nsChromeRegistry.cpp | 31 ++++++++++++++++++++++ content/base/public/nsIChromeRegistry.idl | 5 +++- content/xul/document/src/nsXULDocument.cpp | 25 +++-------------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/chrome/src/nsChromeRegistry.cpp b/chrome/src/nsChromeRegistry.cpp index e707ed9e782..c4382c2cea1 100644 --- a/chrome/src/nsChromeRegistry.cpp +++ b/chrome/src/nsChromeRegistry.cpp @@ -764,6 +764,37 @@ nsChromeRegistry::GetSelectedLocale(const nsACString& aPackage, nsACString& aLoc return NS_OK; } +NS_IMETHODIMP +nsChromeRegistry::IsLocaleRTL(const nsACString& package, PRBool *aResult) +{ + *aResult = PR_FALSE; + + nsCAutoString locale; + GetSelectedLocale(package, locale); + if (locale.Length() < 2) + return NS_OK; + + // first check the intl.uidirection. 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. + nsCAutoString prefString = NS_LITERAL_CSTRING("intl.uidirection.") + locale; + nsCOMPtr prefBranch (do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (!prefBranch) + return NS_OK; + + nsXPIDLCString dir; + prefBranch->GetCharPref(prefString.get(), getter_Copies(dir)); + if (dir.IsEmpty()) { + PRInt32 hyphen = prefString.FindChar('-'); + if (hyphen >= 1) { + nsCAutoString shortPref(Substring(prefString, 0, hyphen)); + prefBranch->GetCharPref(shortPref.get(), getter_Copies(dir)); + } + } + *aResult = dir.EqualsLiteral("rtl"); + return NS_OK; +} + NS_IMETHODIMP nsChromeRegistry::GetLocalesForPackage(const nsACString& aPackage, nsIUTF8StringEnumerator* *aResult) diff --git a/content/base/public/nsIChromeRegistry.idl b/content/base/public/nsIChromeRegistry.idl index f95dad800b2..43362895ee9 100644 --- a/content/base/public/nsIChromeRegistry.idl +++ b/content/base/public/nsIChromeRegistry.idl @@ -80,7 +80,7 @@ interface nsIChromeRegistry : nsISupports [notxpcom] boolean wrappersEnabled(in nsIURI aURI); }; -[scriptable, uuid(2860e205-490e-4b06-90b6-87160d35a5a7)] +[scriptable, uuid(c2461347-2b8f-48c7-9d59-3a61fb868828)] interface nsIXULChromeRegistry : nsIChromeRegistry { /* Should be called when locales change to reload all chrome (including XUL). */ @@ -88,6 +88,9 @@ interface nsIXULChromeRegistry : nsIChromeRegistry ACString getSelectedLocale(in ACString packageName); + // Get the direction of the locale via the intl.uidirection. pref + boolean isLocaleRTL(in ACString package); + /* Should be called when skins change. Reloads only stylesheets. */ void refreshSkins(); diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 9d0a848fd21..f288afabee2 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -4700,27 +4700,10 @@ nsXULDocument::IsDocumentRightToLeft() } } - nsCAutoString locale; - reg->GetSelectedLocale(package, locale); - if (locale.Length() >= 2) { - // first check the intl.uidirection. 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. - nsCAutoString prefString = - NS_LITERAL_CSTRING("intl.uidirection.") + locale; - nsAdoptingCString dir = nsContentUtils::GetCharPref(prefString.get()); - if (dir.IsEmpty()) { - PRInt32 hyphen = prefString.FindChar('-'); - if (hyphen >= 1) { - nsCAutoString shortPref(Substring(prefString, 0, hyphen)); - dir = nsContentUtils::GetCharPref(shortPref.get()); - } - } - - mDocDirection = dir.EqualsLiteral("rtl") ? - Direction_RightToLeft : Direction_LeftToRight; - } + PRBool isRTL = PR_FALSE; + reg->IsLocaleRTL(package, &isRTL); + mDocDirection = isRTL ? + Direction_RightToLeft : Direction_LeftToRight; } }