| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/i18n/rtl.h" | 5 #include "base/i18n/rtl.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "third_party/icu/source/common/unicode/locid.h" | 12 #include "third_party/icu/source/common/unicode/locid.h" |
| 13 #include "third_party/icu/source/common/unicode/uchar.h" | 13 #include "third_party/icu/source/common/unicode/uchar.h" |
| 14 #include "third_party/icu/source/common/unicode/uscript.h" | 14 #include "third_party/icu/source/common/unicode/uscript.h" |
| 15 #include "third_party/icu/source/i18n/unicode/coll.h" | 15 #include "third_party/icu/source/i18n/unicode/coll.h" |
| 16 | 16 |
| 17 #if defined(TOOLKIT_GTK) | |
| 18 #include <gtk/gtk.h> | |
| 19 #endif | |
| 20 | |
| 21 namespace { | 17 namespace { |
| 22 | 18 |
| 23 // Extract language, country and variant, but ignore keywords. For example, | 19 // Extract language, country and variant, but ignore keywords. For example, |
| 24 // en-US, ca@valencia, ca-ES@valencia. | 20 // en-US, ca@valencia, ca-ES@valencia. |
| 25 std::string GetLocaleString(const icu::Locale& locale) { | 21 std::string GetLocaleString(const icu::Locale& locale) { |
| 26 const char* language = locale.getLanguage(); | 22 const char* language = locale.getLanguage(); |
| 27 const char* country = locale.getCountry(); | 23 const char* country = locale.getCountry(); |
| 28 const char* variant = locale.getVariant(); | 24 const char* variant = locale.getVariant(); |
| 29 | 25 |
| 30 std::string result = | 26 std::string result = |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 icu::Locale::setDefault(locale, error_code); | 112 icu::Locale::setDefault(locale, error_code); |
| 117 // This return value is actually bogus because Locale object is | 113 // This return value is actually bogus because Locale object is |
| 118 // an ID and setDefault seems to always succeed (regardless of the | 114 // an ID and setDefault seems to always succeed (regardless of the |
| 119 // presence of actual locale data). However, | 115 // presence of actual locale data). However, |
| 120 // it does not hurt to have it as a sanity check. | 116 // it does not hurt to have it as a sanity check. |
| 121 DCHECK(U_SUCCESS(error_code)); | 117 DCHECK(U_SUCCESS(error_code)); |
| 122 g_icu_text_direction = UNKNOWN_DIRECTION; | 118 g_icu_text_direction = UNKNOWN_DIRECTION; |
| 123 } | 119 } |
| 124 | 120 |
| 125 bool IsRTL() { | 121 bool IsRTL() { |
| 126 #if defined(TOOLKIT_GTK) | |
| 127 GtkTextDirection gtk_dir = gtk_widget_get_default_direction(); | |
| 128 return gtk_dir == GTK_TEXT_DIR_RTL; | |
| 129 #else | |
| 130 return ICUIsRTL(); | 122 return ICUIsRTL(); |
| 131 #endif | |
| 132 } | 123 } |
| 133 | 124 |
| 134 bool ICUIsRTL() { | 125 bool ICUIsRTL() { |
| 135 if (g_icu_text_direction == UNKNOWN_DIRECTION) { | 126 if (g_icu_text_direction == UNKNOWN_DIRECTION) { |
| 136 const icu::Locale& locale = icu::Locale::getDefault(); | 127 const icu::Locale& locale = icu::Locale::getDefault(); |
| 137 g_icu_text_direction = GetTextDirectionForLocale(locale.getName()); | 128 g_icu_text_direction = GetTextDirectionForLocale(locale.getName()); |
| 138 } | 129 } |
| 139 return g_icu_text_direction == RIGHT_TO_LEFT; | 130 return g_icu_text_direction == RIGHT_TO_LEFT; |
| 140 } | 131 } |
| 141 | 132 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 begin == kRightToLeftOverride) | 385 begin == kRightToLeftOverride) |
| 395 ++begin_index; | 386 ++begin_index; |
| 396 size_t end_index = text.length() - 1; | 387 size_t end_index = text.length() - 1; |
| 397 if (text[end_index] == kPopDirectionalFormatting) | 388 if (text[end_index] == kPopDirectionalFormatting) |
| 398 --end_index; | 389 --end_index; |
| 399 return text.substr(begin_index, end_index - begin_index + 1); | 390 return text.substr(begin_index, end_index - begin_index + 1); |
| 400 } | 391 } |
| 401 | 392 |
| 402 } // namespace i18n | 393 } // namespace i18n |
| 403 } // namespace base | 394 } // namespace base |
| OLD | NEW |