Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: base/i18n/rtl.cc

Issue 2833052: [chromeos]Set GtkWidget's default direction correctly. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Update comment. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/file_path.h" 7 #include "base/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
12 #include "unicode/coll.h" 12 #include "unicode/coll.h"
13 #include "unicode/locid.h" 13 #include "unicode/locid.h"
14 #include "unicode/uchar.h" 14 #include "unicode/uchar.h"
15 #include "unicode/uscript.h" 15 #include "unicode/uscript.h"
16 16
17 #if defined(TOOLKIT_GTK) 17 #if defined(TOOLKIT_USES_GTK)
18 #include <gtk/gtk.h> 18 #include <gtk/gtk.h>
19 #endif 19 #endif
20 20
21 namespace base { 21 namespace base {
22 namespace i18n { 22 namespace i18n {
23 23
24 // Represents the locale-specific ICU text direction. 24 // Represents the locale-specific ICU text direction.
25 static TextDirection g_icu_text_direction = UNKNOWN_DIRECTION; 25 static TextDirection g_icu_text_direction = UNKNOWN_DIRECTION;
26 26
27 void GetLanguageAndRegionFromOS(std::string* lang, std::string* region) { 27 void GetLanguageAndRegionFromOS(std::string* lang, std::string* region) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 void SetICUDefaultLocale(const std::string& locale_string) { 68 void SetICUDefaultLocale(const std::string& locale_string) {
69 icu::Locale locale(ICULocaleName(locale_string).c_str()); 69 icu::Locale locale(ICULocaleName(locale_string).c_str());
70 UErrorCode error_code = U_ZERO_ERROR; 70 UErrorCode error_code = U_ZERO_ERROR;
71 icu::Locale::setDefault(locale, error_code); 71 icu::Locale::setDefault(locale, error_code);
72 // This return value is actually bogus because Locale object is 72 // This return value is actually bogus because Locale object is
73 // an ID and setDefault seems to always succeed (regardless of the 73 // an ID and setDefault seems to always succeed (regardless of the
74 // presence of actual locale data). However, 74 // presence of actual locale data). However,
75 // it does not hurt to have it as a sanity check. 75 // it does not hurt to have it as a sanity check.
76 DCHECK(U_SUCCESS(error_code)); 76 DCHECK(U_SUCCESS(error_code));
77 g_icu_text_direction = UNKNOWN_DIRECTION; 77 g_icu_text_direction = UNKNOWN_DIRECTION;
78
79 // If we use Views toolkit on top of GtkWidget, then we need to keep
80 // GtkWidget's default text direction consistent with ICU's text direction.
81 // Because in this case ICU's text direction will be used instead.
82 // See IsRTL() function below.
83 #if defined(TOOLKIT_USES_GTK) && !defined(TOOLKIT_GTK)
84 gtk_widget_set_default_direction(
85 ICUIsRTL() ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
86 #endif
78 } 87 }
79 88
80 bool IsRTL() { 89 bool IsRTL() {
81 #if defined(TOOLKIT_GTK) 90 #if defined(TOOLKIT_GTK)
82 GtkTextDirection gtk_dir = gtk_widget_get_default_direction(); 91 GtkTextDirection gtk_dir = gtk_widget_get_default_direction();
83 return (gtk_dir == GTK_TEXT_DIR_RTL); 92 return (gtk_dir == GTK_TEXT_DIR_RTL);
84 #else 93 #else
85 return ICUIsRTL(); 94 return ICUIsRTL();
86 #endif 95 #endif
87 } 96 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 begin == kRightToLeftOverride) 286 begin == kRightToLeftOverride)
278 ++begin_index; 287 ++begin_index;
279 size_t end_index = text.length() - 1; 288 size_t end_index = text.length() - 1;
280 if (text[end_index] == kPopDirectionalFormatting) 289 if (text[end_index] == kPopDirectionalFormatting)
281 --end_index; 290 --end_index;
282 return text.substr(begin_index, end_index - begin_index + 1); 291 return text.substr(begin_index, end_index - begin_index + 1);
283 } 292 }
284 293
285 } // namespace i18n 294 } // namespace i18n
286 } // namespace base 295 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698