Chromium Code Reviews| 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/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" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 return RIGHT_TO_LEFT; | 146 return RIGHT_TO_LEFT; |
| 147 } else if ((property == U_LEFT_TO_RIGHT) || | 147 } else if ((property == U_LEFT_TO_RIGHT) || |
| 148 (property == U_LEFT_TO_RIGHT_EMBEDDING) || | 148 (property == U_LEFT_TO_RIGHT_EMBEDDING) || |
| 149 (property == U_LEFT_TO_RIGHT_OVERRIDE)) { | 149 (property == U_LEFT_TO_RIGHT_OVERRIDE)) { |
| 150 return LEFT_TO_RIGHT; | 150 return LEFT_TO_RIGHT; |
| 151 } | 151 } |
| 152 | 152 |
| 153 position = next_position; | 153 position = next_position; |
| 154 } | 154 } |
| 155 | 155 |
| 156 return LEFT_TO_RIGHT; | 156 return LEFT_TO_RIGHT; |
|
msw
2012/09/12 20:46:52
FYI: This is what my tangential RenderTextWin TODO
| |
| 157 } | 157 } |
| 158 | 158 |
| 159 #if defined(OS_WIN) | 159 #if defined(OS_WIN) |
| 160 bool AdjustStringForLocaleDirection(string16* text) { | 160 bool AdjustStringForLocaleDirection(string16* text) { |
| 161 if (!IsRTL() || text->empty()) | 161 if (!IsRTL() || text->empty()) |
| 162 return false; | 162 return false; |
| 163 | 163 |
| 164 // Marking the string as LTR if the locale is RTL and the string does not | 164 // Marking the string as LTR if the locale is RTL and the string does not |
| 165 // contain strong RTL characters. Otherwise, mark the string as RTL. | 165 // contain strong RTL characters. Otherwise, mark the string as RTL. |
| 166 bool has_rtl_chars = StringContainsStrongRTLChars(*text); | 166 bool has_rtl_chars = StringContainsStrongRTLChars(*text); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 rtl_safe_path->append(path.value()); | 312 rtl_safe_path->append(path.value()); |
| 313 #else // defined(OS_POSIX) && !defined(OS_MACOSX) | 313 #else // defined(OS_POSIX) && !defined(OS_MACOSX) |
| 314 std::wstring wide_path = base::SysNativeMBToWide(path.value()); | 314 std::wstring wide_path = base::SysNativeMBToWide(path.value()); |
| 315 rtl_safe_path->append(WideToUTF16(wide_path)); | 315 rtl_safe_path->append(WideToUTF16(wide_path)); |
| 316 #endif | 316 #endif |
| 317 // Inserting a PDF (Pop Directional Formatting) mark as the last character. | 317 // Inserting a PDF (Pop Directional Formatting) mark as the last character. |
| 318 rtl_safe_path->push_back(kPopDirectionalFormatting); | 318 rtl_safe_path->push_back(kPopDirectionalFormatting); |
| 319 } | 319 } |
| 320 | 320 |
| 321 string16 GetDisplayStringInLTRDirectionality(const string16& text) { | 321 string16 GetDisplayStringInLTRDirectionality(const string16& text) { |
| 322 if (!IsRTL()) | 322 // Always wrap the string in RTL UI (it may be appended to RTL string). |
| 323 // Also wrap strings with an RTL first strong character direction in LTR UI. | |
| 324 if (!IsRTL() && GetFirstStrongCharacterDirection(text) == LEFT_TO_RIGHT) | |
|
xji
2012/09/10 18:07:26
why RTL locale is specially handled (always wrap i
msw
2012/09/10 18:37:31
I don't know about Mac/GTK, but Win and CrOs use f
xji
2012/09/10 22:27:57
In English windows (windows xp), if a user does no
msw
2012/09/10 22:46:13
Cool, this still avoids adding them in LTR for LTR
jungshik at Google
2012/09/12 20:24:35
Can we match the comment and if-statement? At firs
msw
2012/09/12 20:46:52
Done, flipped condition & blocks.
See my comment a
| |
| 323 return text; | 325 return text; |
| 324 string16 text_mutable(text); | 326 string16 text_mutable(text); |
| 325 WrapStringWithLTRFormatting(&text_mutable); | 327 WrapStringWithLTRFormatting(&text_mutable); |
| 326 return text_mutable; | 328 return text_mutable; |
| 327 } | 329 } |
| 328 | 330 |
| 329 string16 StripWrappingBidiControlCharacters(const string16& text) { | 331 string16 StripWrappingBidiControlCharacters(const string16& text) { |
| 330 if (text.empty()) | 332 if (text.empty()) |
| 331 return text; | 333 return text; |
| 332 size_t begin_index = 0; | 334 size_t begin_index = 0; |
| 333 char16 begin = text[begin_index]; | 335 char16 begin = text[begin_index]; |
| 334 if (begin == kLeftToRightEmbeddingMark || | 336 if (begin == kLeftToRightEmbeddingMark || |
| 335 begin == kRightToLeftEmbeddingMark || | 337 begin == kRightToLeftEmbeddingMark || |
| 336 begin == kLeftToRightOverride || | 338 begin == kLeftToRightOverride || |
| 337 begin == kRightToLeftOverride) | 339 begin == kRightToLeftOverride) |
| 338 ++begin_index; | 340 ++begin_index; |
| 339 size_t end_index = text.length() - 1; | 341 size_t end_index = text.length() - 1; |
| 340 if (text[end_index] == kPopDirectionalFormatting) | 342 if (text[end_index] == kPopDirectionalFormatting) |
| 341 --end_index; | 343 --end_index; |
| 342 return text.substr(begin_index, end_index - begin_index + 1); | 344 return text.substr(begin_index, end_index - begin_index + 1); |
| 343 } | 345 } |
| 344 | 346 |
| 345 } // namespace i18n | 347 } // namespace i18n |
| 346 } // namespace base | 348 } // namespace base |
| OLD | NEW |