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

Side by Side Diff: chrome/browser/ui/views/download_item_view.cc

Issue 6713119: Make 'dangerous download warning' visible in Japanese UI on Windows. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 | « base/i18n/break_iterator.cc ('k') | 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) 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 "chrome/browser/ui/views/download_item_view.h" 5 #include "chrome/browser/ui/views/download_item_view.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/i18n/break_iterator.h"
11 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
12 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
14 #include "base/sys_string_conversions.h" 15 #include "base/sys_string_conversions.h"
15 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/download/download_item_model.h" 18 #include "chrome/browser/download/download_item_model.h"
18 #include "chrome/browser/download/download_util.h" 19 #include "chrome/browser/download/download_util.h"
19 #include "chrome/browser/themes/theme_service.h" 20 #include "chrome/browser/themes/theme_service.h"
20 #include "chrome/browser/ui/views/download_shelf_view.h" 21 #include "chrome/browser/ui/views/download_shelf_view.h"
21 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
22 #include "grit/theme_resources.h" 23 #include "grit/theme_resources.h"
23 #include "ui/base/accessibility/accessible_view_state.h" 24 #include "ui/base/accessibility/accessible_view_state.h"
24 #include "ui/base/animation/slide_animation.h" 25 #include "ui/base/animation/slide_animation.h"
25 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/base/text/text_elider.h" 28 #include "ui/base/text/text_elider.h"
28 #include "ui/gfx/canvas_skia.h" 29 #include "ui/gfx/canvas_skia.h"
29 #include "ui/gfx/color_utils.h" 30 #include "ui/gfx/color_utils.h"
30 #include "ui/gfx/image.h" 31 #include "ui/gfx/image.h"
32 #include "unicode/uchar.h"
31 #include "views/controls/button/native_button.h" 33 #include "views/controls/button/native_button.h"
32 #include "views/controls/menu/menu_2.h" 34 #include "views/controls/menu/menu_2.h"
33 #include "views/widget/root_view.h" 35 #include "views/widget/root_view.h"
34 #include "views/widget/widget.h" 36 #include "views/widget/widget.h"
35 37
36 using base::TimeDelta; 38 using base::TimeDelta;
37 39
38 // TODO(paulg): These may need to be adjusted when download progress 40 // TODO(paulg): These may need to be adjusted when download progress
39 // animation is added, and also possibly to take into account 41 // animation is added, and also possibly to take into account
40 // different screen resolutions. 42 // different screen resolutions.
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 std::wstring text = dangerous_download_label_->GetText(); 1042 std::wstring text = dangerous_download_label_->GetText();
1041 TrimWhitespace(text, TRIM_ALL, &text); 1043 TrimWhitespace(text, TRIM_ALL, &text);
1042 DCHECK_EQ(std::wstring::npos, text.find(L"\n")); 1044 DCHECK_EQ(std::wstring::npos, text.find(L"\n"));
1043 1045
1044 // Make the label big so that GetPreferredSize() is not constrained by the 1046 // Make the label big so that GetPreferredSize() is not constrained by the
1045 // current width. 1047 // current width.
1046 dangerous_download_label_->SetBounds(0, 0, 1000, 1000); 1048 dangerous_download_label_->SetBounds(0, 0, 1000, 1000);
1047 1049
1048 gfx::Size size; 1050 gfx::Size size;
1049 int min_width = -1; 1051 int min_width = -1;
1050 size_t sp_index = text.find(L" "); 1052 string16 text16 = WideToUTF16(text);
1051 while (sp_index != std::wstring::npos) { 1053 // Using BREAK_WORD can work in most cases, but it can also break
1052 text.replace(sp_index, 1, L"\n"); 1054 // lines where it should not. Using BREAK_LINE is safer although
1053 dangerous_download_label_->SetText(text); 1055 // slower for Chinese/Japanese. This is not perf-critical at all, though.
1056 base::BreakIterator iter(&text16, base::BreakIterator::BREAK_LINE);
1057 bool status = iter.Init();
1058 DCHECK(status);
1059
1060 string16 current_text = text16;
1061 string16 prev_text = text16;
1062 while (iter.Advance()) {
1063 size_t pos = iter.pos();
1064 if (pos >= text16.length())
1065 break;
1066 // This can be a low surrogate codepoint, but u_isUWhiteSpace will
1067 // return false and inserting a new line after a surrogate pair
1068 // is perfectly ok.
1069 char16 line_end_char = text16[pos - 1];
1070 if (u_isUWhiteSpace(line_end_char))
1071 current_text.replace(pos - 1, 1, 1, char16('\n'));
1072 else
1073 current_text.insert(pos, 1, char16('\n'));
1074 dangerous_download_label_->SetText(UTF16ToWide(current_text));
1054 size = dangerous_download_label_->GetPreferredSize(); 1075 size = dangerous_download_label_->GetPreferredSize();
1055 1076
1056 if (min_width == -1) 1077 if (min_width == -1)
1057 min_width = size.width(); 1078 min_width = size.width();
1058 1079
1059 // If the width is growing again, it means we passed the optimal width spot. 1080 // If the width is growing again, it means we passed the optimal width spot.
1060 if (size.width() > min_width) 1081 if (size.width() > min_width) {
1082 dangerous_download_label_->SetText(UTF16ToWide(prev_text));
1061 break; 1083 break;
1062 else 1084 } else {
1063 min_width = size.width(); 1085 min_width = size.width();
1086 }
1064 1087
1065 // Restore the string. 1088 // Restore the string.
1066 text.replace(sp_index, 1, L" "); 1089 prev_text = current_text;
1067 1090 current_text = text16;
1068 sp_index = text.find(L" ", sp_index + 1);
1069 } 1091 }
1070 1092
1071 // If we have a line with no space, we won't cut it. 1093 // If we have a line with no line breaking opportunity (which is very
1094 // unlikely), we won't cut it.
1072 if (min_width == -1) 1095 if (min_width == -1)
1073 size = dangerous_download_label_->GetPreferredSize(); 1096 size = dangerous_download_label_->GetPreferredSize();
1074 1097
1075 dangerous_download_label_->SetBounds(0, 0, size.width(), size.height()); 1098 dangerous_download_label_->SetBounds(0, 0, size.width(), size.height());
1076 dangerous_download_label_sized_ = true; 1099 dangerous_download_label_sized_ = true;
1077 } 1100 }
1078 1101
1079 void DownloadItemView::Reenable() { 1102 void DownloadItemView::Reenable() {
1080 disabled_while_opening_ = false; 1103 disabled_while_opening_ = false;
1081 SetEnabled(true); // Triggers a repaint. 1104 SetEnabled(true); // Triggers a repaint.
(...skipping 17 matching lines...) Expand all
1099 // If the name has changed, notify assistive technology that the name 1122 // If the name has changed, notify assistive technology that the name
1100 // has changed so they can announce it immediately. 1123 // has changed so they can announce it immediately.
1101 if (new_name != accessible_name_) { 1124 if (new_name != accessible_name_) {
1102 accessible_name_ = new_name; 1125 accessible_name_ = new_name;
1103 if (GetWidget()) { 1126 if (GetWidget()) {
1104 GetWidget()->NotifyAccessibilityEvent( 1127 GetWidget()->NotifyAccessibilityEvent(
1105 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true); 1128 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true);
1106 } 1129 }
1107 } 1130 }
1108 } 1131 }
OLDNEW
« no previous file with comments | « base/i18n/break_iterator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698