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

Side by Side Diff: chrome/common/l10n_util.cc

Issue 20038: Review request: fix 7324 and 7326: missing icon and wrong path in "download location" (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/l10n_util.h ('k') | chrome/common/l10n_util_unittest.cc » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/common/l10n_util.h" 7 #include "chrome/common/l10n_util.h"
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
11 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/scoped_ptr.h"
14 #include "base/string16.h"
15 #include "base/string_piece.h"
16 #include "base/string_util.h"
17 #include "base/sys_string_conversions.h"
12 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/gfx/chrome_canvas.h" 20 #include "chrome/common/gfx/chrome_canvas.h"
15 #if defined(OS_WIN) || defined(OS_LINUX) 21 #if defined(OS_WIN) || defined(OS_LINUX)
16 // TODO(port): re-enable. 22 // TODO(port): re-enable.
17 #include "chrome/common/resource_bundle.h" 23 #include "chrome/common/resource_bundle.h"
18 #endif 24 #endif
19 #if defined(OS_WIN) 25 #if defined(OS_WIN)
20 #include "chrome/views/view.h" 26 #include "chrome/views/view.h"
21 #endif // defined(OS_WIN) 27 #endif // defined(OS_WIN)
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 WriteInto(&name_local_utf16, buffer_size + 1), buffer_size, &error); 302 WriteInto(&name_local_utf16, buffer_size + 1), buffer_size, &error);
297 std::wstring name_local = UTF16ToWide(name_local_utf16); 303 std::wstring name_local = UTF16ToWide(name_local_utf16);
298 #else 304 #else
299 std::wstring name_local; 305 std::wstring name_local;
300 int actual_size = uloc_getDisplayName(locale_code, app_locale.c_str(), 306 int actual_size = uloc_getDisplayName(locale_code, app_locale.c_str(),
301 WriteInto(&name_local, buffer_size + 1), buffer_size, &error); 307 WriteInto(&name_local, buffer_size + 1), buffer_size, &error);
302 #endif 308 #endif
303 DCHECK(U_SUCCESS(error)); 309 DCHECK(U_SUCCESS(error));
304 name_local.resize(actual_size); 310 name_local.resize(actual_size);
305 // Add an RTL mark so parentheses are properly placed. 311 // Add an RTL mark so parentheses are properly placed.
306 if (is_for_ui && GetTextDirection() == RIGHT_TO_LEFT) 312 if (is_for_ui && GetTextDirection() == RIGHT_TO_LEFT) {
307 return name_local + kRightToLeftMark; 313 name_local.push_back(static_cast<wchar_t>(kRightToLeftMark));
308 else 314 }
309 return name_local; 315 return name_local;
310 } 316 }
311 317
312 std::wstring GetString(int message_id) { 318 std::wstring GetString(int message_id) {
313 #if defined(OS_WIN) || defined(OS_LINUX) 319 #if defined(OS_WIN) || defined(OS_LINUX)
314 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); 320 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
315 return rb.GetLocalizedString(message_id); 321 return rb.GetLocalizedString(message_id);
316 #else 322 #else
317 NOTIMPLEMENTED(); // TODO(port): Real implementation of GetString. 323 NOTIMPLEMENTED(); // TODO(port): Real implementation of GetString.
318 // Return something non-empty so callers don't freak out. 324 // Return something non-empty so callers don't freak out.
319 return L"true"; 325 return L"true";
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 bool has_rtl_chars = StringContainsStrongRTLChars(text); 513 bool has_rtl_chars = StringContainsStrongRTLChars(text);
508 if (!has_rtl_chars) 514 if (!has_rtl_chars)
509 WrapStringWithLTRFormatting(localized_text); 515 WrapStringWithLTRFormatting(localized_text);
510 else 516 else
511 WrapStringWithRTLFormatting(localized_text); 517 WrapStringWithRTLFormatting(localized_text);
512 518
513 return true; 519 return true;
514 } 520 }
515 521
516 bool StringContainsStrongRTLChars(const std::wstring& text) { 522 bool StringContainsStrongRTLChars(const std::wstring& text) {
517 const wchar_t* string = text.c_str(); 523 #if defined(WCHAR_T_IS_UTF32)
518 int length = static_cast<int>(text.length()); 524 string16 text_utf16 = WideToUTF16(text);
519 int position = 0; 525 const UChar* string = text_utf16.c_str();
526 #else
527 const UChar* string = text.c_str();
528 #endif
529 size_t length = text.length();
530 size_t position = 0;
520 while (position < length) { 531 while (position < length) {
521 UChar32 character; 532 UChar32 character;
522 int next_position = position; 533 size_t next_position = position;
523 U16_NEXT(string, next_position, length, character); 534 U16_NEXT(string, next_position, length, character);
524 535
525 // Now that we have the character, we use ICU in order to query for the 536 // Now that we have the character, we use ICU in order to query for the
526 // appropriate Unicode BiDi character type. 537 // appropriate Unicode BiDi character type.
527 int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS); 538 int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS);
528 if ((property == U_RIGHT_TO_LEFT) || (property == U_RIGHT_TO_LEFT_ARABIC)) 539 if ((property == U_RIGHT_TO_LEFT) || (property == U_RIGHT_TO_LEFT_ARABIC))
529 return true; 540 return true;
530 541
531 position = next_position; 542 position = next_position;
532 } 543 }
533 544
534 return false; 545 return false;
535 } 546 }
536 547
537 void WrapStringWithLTRFormatting(std::wstring* text) { 548 void WrapStringWithLTRFormatting(std::wstring* text) {
538 // Inserting an LRE (Left-To-Right Embedding) mark as the first character. 549 // Inserting an LRE (Left-To-Right Embedding) mark as the first character.
539 text->insert(0, L"\x202A"); 550 text->insert(0, 1, static_cast<wchar_t>(kLeftToRightEmbeddingMark));
540 551
541 // Inserting a PDF (Pop Directional Formatting) mark as the last character. 552 // Inserting a PDF (Pop Directional Formatting) mark as the last character.
542 text->append(L"\x202C"); 553 text->push_back(static_cast<wchar_t>(kPopDirectionalFormatting));
543 } 554 }
544 555
545 void WrapStringWithRTLFormatting(std::wstring* text) { 556 void WrapStringWithRTLFormatting(std::wstring* text) {
546 // Inserting an RLE (Right-To-Left Embedding) mark as the first character. 557 // Inserting an RLE (Right-To-Left Embedding) mark as the first character.
547 text->insert(0, L"\x202B"); 558 text->insert(0, 1, static_cast<wchar_t>(kRightToLeftEmbeddingMark));
548 559
549 // Inserting a PDF (Pop Directional Formatting) mark as the last character. 560 // Inserting a PDF (Pop Directional Formatting) mark as the last character.
550 text->append(L"\x202C"); 561 text->push_back(static_cast<wchar_t>(kPopDirectionalFormatting));
562 }
563
564 void WrapPathWithLTRFormatting(const FilePath& path,
565 string16* rtl_safe_path) {
566 // Split the path.
567 std::vector<FilePath::StringType> path_components;
568 file_util::PathComponents(path, &path_components);
569 // Compose the whole path from components with the following 2 additions:
570 // 1. Wrap the overall path with LRE-PDF pair which essentialy marks the
571 // string as a Left-To-Right string. Otherwise, the punctuation (if there is
572 // any) at the end of the path will not be displayed at the correct position.
573 // Inserting an LRE (Left-To-Right Embedding) mark as the first character.
574 rtl_safe_path->push_back(kLeftToRightEmbeddingMark);
575 char16 path_separator = static_cast<char16>(FilePath::kSeparators[0]);
576 for (size_t index = 0; index < path_components.size(); ++index) {
577 #if defined(OS_MACOSX)
578 rtl_safe_path->append(UTF8ToUTF16(path_components[index]));
579 #elif defined(OS_WIN)
580 rtl_safe_path->append(path_components[index]);
581 #else // defined(OS_LINUX)
582 std::wstring one_component =
583 base::SysNativeMBToWide(path_components[index]);
584 rtl_safe_path->append(WideToUTF16(one_component));
585 #endif
586 bool first_component_is_separator =
587 ((index == 0) &&
588 (path_components[0].length() == 1) &&
589 (FilePath::IsSeparator(path_components[0][0])));
590 bool last_component = (index == path_components.size() - 1);
591 // Add separator for components except for the first component if itself is
592 // a separator, and except for the last component.
593 if (!last_component && !first_component_is_separator) {
594 rtl_safe_path->push_back(path_separator);
595 // 2. Add left-to-right mark after path separator to force each subfolder
596 // in the path to have LTR directionality. Otherwise, folder path
597 // "CBA/FED" (in which, "CBA" and "FED" stand for folder names in Hebrew,
598 // and "FED" is a subfolder of "CBA") will be displayed as "FED/CBA".
599 rtl_safe_path->push_back(kLeftToRightMark);
600 }
601 }
602 // Inserting a PDF (Pop Directional Formatting) mark as the last character.
603 rtl_safe_path->push_back(kPopDirectionalFormatting);
551 } 604 }
552 605
553 int DefaultCanvasTextAlignment() { 606 int DefaultCanvasTextAlignment() {
554 if (GetTextDirection() == LEFT_TO_RIGHT) { 607 if (GetTextDirection() == LEFT_TO_RIGHT) {
555 return ChromeCanvas::TEXT_ALIGN_LEFT; 608 return ChromeCanvas::TEXT_ALIGN_LEFT;
556 } else { 609 } else {
557 return ChromeCanvas::TEXT_ALIGN_RIGHT; 610 return ChromeCanvas::TEXT_ALIGN_RIGHT;
558 } 611 }
559 } 612 }
560 613
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 724 }
672 725
673 void BiDiLineIterator::GetLogicalRun(int start, 726 void BiDiLineIterator::GetLogicalRun(int start,
674 int* end, 727 int* end,
675 UBiDiLevel* level) { 728 UBiDiLevel* level) {
676 DCHECK(bidi_ != NULL); 729 DCHECK(bidi_ != NULL);
677 ubidi_getLogicalRun(bidi_, start, end, level); 730 ubidi_getLogicalRun(bidi_, start, end, level);
678 } 731 }
679 732
680 } 733 }
OLDNEW
« no previous file with comments | « chrome/common/l10n_util.h ('k') | chrome/common/l10n_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698