Bug 1346341 - Ifdef more OSPreferences platform-specific calls that depend on ICU. r?jfkthame
MozReview-Commit-ID: F0H4LiXK1R6
--- a/intl/locale/gtk/OSPreferences_gtk.cpp
+++ b/intl/locale/gtk/OSPreferences_gtk.cpp
@@ -9,24 +9,26 @@
#include "glib.h"
#include "gio/gio.h"
using namespace mozilla::intl;
bool
OSPreferences::ReadSystemLocales(nsTArray<nsCString>& aLocaleList)
{
+#ifdef ENABLE_INTL_API
MOZ_ASSERT(aLocaleList.IsEmpty());
nsAutoCString defaultLang(uloc_getDefault());
if (CanonicalizeLanguageTag(defaultLang)) {
aLocaleList.AppendElement(defaultLang);
return true;
}
+#endif
return false;
}
/*
* This looks up into gtk settings for hourCycle format.
*
* This works for all GUIs that use gtk settings like Gnome, Elementary etc.
* Ubuntu does not use those settings so we'll want to support them separately.
@@ -105,16 +107,17 @@ HourCycle()
* * gtk 24h, pl: 24h
* * gtk 12h, en: 12h
*/
bool
OSPreferences::ReadDateTimePattern(DateTimeFormatStyle aDateStyle,
DateTimeFormatStyle aTimeStyle,
const nsACString& aLocale, nsAString& aRetVal)
{
+#ifdef ENABLE_INTL_API
nsAutoString skeleton;
if (!GetDateTimeSkeletonForStyle(aDateStyle, aTimeStyle, aLocale, skeleton)) {
return false;
}
// Customize the skeleton if necessary to reflect user's 12/24hr pref
switch (HourCycle()) {
case 12: {
@@ -165,10 +168,13 @@ OSPreferences::ReadDateTimePattern(DateT
break;
}
if (!GetPatternForSkeleton(skeleton, aLocale, aRetVal)) {
return false;
}
return true;
+#else
+ return false;
+#endif
}
--- a/intl/locale/mac/OSPreferences_mac.cpp
+++ b/intl/locale/mac/OSPreferences_mac.cpp
@@ -7,16 +7,17 @@
#include "OSPreferences.h"
#include <Carbon/Carbon.h>
using namespace mozilla::intl;
bool
OSPreferences::ReadSystemLocales(nsTArray<nsCString>& aLocaleList)
{
+#ifdef ENABLE_INTL_API
MOZ_ASSERT(aLocaleList.IsEmpty());
// Get string representation of user's current locale
CFLocaleRef userLocaleRef = ::CFLocaleCopyCurrent();
CFStringRef userLocaleStr = ::CFLocaleGetIdentifier(userLocaleRef);
AutoTArray<UniChar, 32> buffer;
int size = ::CFStringGetLength(userLocaleStr);
@@ -30,17 +31,17 @@ OSPreferences::ReadSystemLocales(nsTArra
reinterpret_cast<const char16_t*>(buffer.Elements()), buffer.Length());
CFRelease(userLocaleRef);
if (CanonicalizeLanguageTag(locale)) {
aLocaleList.AppendElement(locale);
return true;
}
-
+#endif
return false;
}
static CFDateFormatterStyle
ToCFDateFormatterStyle(OSPreferences::DateTimeFormatStyle aFormatStyle)
{
switch (aFormatStyle) {
case OSPreferences::DateTimeFormatStyle::None:
@@ -91,16 +92,17 @@ CreateCFLocaleFor(const nsACString& aLoc
*
* In all other cases it will return the default pattern for a given locale.
*/
bool
OSPreferences::ReadDateTimePattern(DateTimeFormatStyle aDateStyle,
DateTimeFormatStyle aTimeStyle,
const nsACString& aLocale, nsAString& aRetVal)
{
+#ifdef ENABLE_INTL_API
CFLocaleRef locale = CreateCFLocaleFor(aLocale);
if (!locale) {
return false;
}
CFDateFormatterRef formatter =
CFDateFormatterCreate(kCFAllocatorDefault, locale,
ToCFDateFormatterStyle(aDateStyle),
@@ -110,9 +112,12 @@ OSPreferences::ReadDateTimePattern(DateT
CFRange range = CFRangeMake(0, CFStringGetLength(format));
aRetVal.SetLength(range.length);
CFStringGetCharacters(format, range,
reinterpret_cast<UniChar*>(aRetVal.BeginWriting()));
CFRelease(formatter);
return true;
+#else
+ return false;
+#endif
}
--- a/intl/locale/windows/OSPreferences_win.cpp
+++ b/intl/locale/windows/OSPreferences_win.cpp
@@ -7,29 +7,31 @@
#include "OSPreferences.h"
#include "nsWin32Locale.h"
using namespace mozilla::intl;
bool
OSPreferences::ReadSystemLocales(nsTArray<nsCString>& aLocaleList)
{
+#ifdef ENABLE_INTL_API
MOZ_ASSERT(aLocaleList.IsEmpty());
nsAutoString locale;
LCID win_lcid = GetSystemDefaultLCID();
nsWin32Locale::GetXPLocale(win_lcid, locale);
NS_LossyConvertUTF16toASCII loc(locale);
if (CanonicalizeLanguageTag(loc)) {
aLocaleList.AppendElement(loc);
return true;
}
+#endif
return false;
}
static LCTYPE
ToDateLCType(OSPreferences::DateTimeFormatStyle aFormatStyle)
{
switch (aFormatStyle) {
case OSPreferences::DateTimeFormatStyle::None:
@@ -87,16 +89,17 @@ ToTimeLCType(OSPreferences::DateTimeForm
* for combined date/time string, since Windows API does not provide an
* option for this.
*/
bool
OSPreferences::ReadDateTimePattern(DateTimeFormatStyle aDateStyle,
DateTimeFormatStyle aTimeStyle,
const nsACString& aLocale, nsAString& aRetVal)
{
+#ifdef ENABLE_INTL_API
LPWSTR localeName = LOCALE_NAME_USER_DEFAULT;
nsAutoString localeNameBuffer;
if (!aLocale.IsEmpty()) {
localeNameBuffer.AppendASCII(aLocale.BeginReading(), aLocale.Length());
localeName = (LPWSTR)localeNameBuffer.BeginReading();
}
bool isDate = aDateStyle != DateTimeFormatStyle::None &&
@@ -200,9 +203,12 @@ OSPreferences::ReadDateTimePattern(DateT
aRetVal.EndReading(end);
if (FindInReadable(NS_LITERAL_STRING("{0}"), pos, end)) {
aRetVal.Replace(pos - start, 3, tmpStr);
}
}
}
return true;
+#else
+ return false;
+#endif
}