Bug 224547: Change the organization of the window title bar for RTL XUL windows. Part 1, refactoring, r=enndeakin

This commit is contained in:
Simon Montagu 2009-12-21 12:21:52 +02:00
Родитель c9554765f2
Коммит b7f575fe1e
3 изменённых файлов: 39 добавлений и 22 удалений

Просмотреть файл

@ -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.<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.
nsCAutoString prefString = NS_LITERAL_CSTRING("intl.uidirection.") + locale;
nsCOMPtr<nsIPrefBranch> 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)

Просмотреть файл

@ -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.<locale> pref
boolean isLocaleRTL(in ACString package);
/* Should be called when skins change. Reloads only stylesheets. */
void refreshSkins();

Просмотреть файл

@ -4700,27 +4700,10 @@ nsXULDocument::IsDocumentRightToLeft()
}
}
nsCAutoString locale;
reg->GetSelectedLocale(package, locale);
if (locale.Length() >= 2) {
// 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.
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;
}
}