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

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

Issue 8142026: Revert 104076 - Change std::wstring to string16 for views::Link (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 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
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/download_item_view.h" 5 #include "chrome/browser/ui/views/download/download_item_view.h"
6 6
7 #include <algorithm>
8 #include <vector> 7 #include <vector>
9 8
10 #include "base/callback.h" 9 #include "base/callback.h"
11 #include "base/file_path.h" 10 #include "base/file_path.h"
12 #include "base/i18n/break_iterator.h" 11 #include "base/i18n/break_iterator.h"
13 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
14 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
15 #include "base/string_util.h" 14 #include "base/string_util.h"
16 #include "base/sys_string_conversions.h" 15 #include "base/sys_string_conversions.h"
17 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 ui::ElideString(rootname, 269 ui::ElideString(rootname,
271 kFileNameMaxLength - extension.length(), 270 kFileNameMaxLength - extension.length(),
272 &rootname); 271 &rootname);
273 string16 filename = rootname + ASCIIToUTF16(".") + extension; 272 string16 filename = rootname + ASCIIToUTF16(".") + extension;
274 filename = base::i18n::GetDisplayStringInLTRDirectionality(filename); 273 filename = base::i18n::GetDisplayStringInLTRDirectionality(filename);
275 dangerous_label = 274 dangerous_label =
276 l10n_util::GetStringFUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD, filename); 275 l10n_util::GetStringFUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD, filename);
277 } 276 }
278 } 277 }
279 278
280 dangerous_download_label_ = new views::Label(dangerous_label); 279 dangerous_download_label_ = new views::Label(UTF16ToWide(dangerous_label));
281 dangerous_download_label_->SetMultiLine(true); 280 dangerous_download_label_->SetMultiLine(true);
282 dangerous_download_label_->SetHorizontalAlignment( 281 dangerous_download_label_->SetHorizontalAlignment(
283 views::Label::ALIGN_LEFT); 282 views::Label::ALIGN_LEFT);
284 AddChildView(dangerous_download_label_); 283 AddChildView(dangerous_download_label_);
285 SizeLabelToMinWidth(); 284 SizeLabelToMinWidth();
286 } 285 }
287 286
288 UpdateAccessibleName(); 287 UpdateAccessibleName();
289 set_accessibility_focusable(true); 288 set_accessibility_focusable(true);
290 289
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 return size; 1027 return size;
1029 } 1028 }
1030 1029
1031 // This method computes the minimum width of the label for displaying its text 1030 // This method computes the minimum width of the label for displaying its text
1032 // on 2 lines. It just breaks the string in 2 lines on the spaces and keeps the 1031 // on 2 lines. It just breaks the string in 2 lines on the spaces and keeps the
1033 // configuration with minimum width. 1032 // configuration with minimum width.
1034 void DownloadItemView::SizeLabelToMinWidth() { 1033 void DownloadItemView::SizeLabelToMinWidth() {
1035 if (dangerous_download_label_sized_) 1034 if (dangerous_download_label_sized_)
1036 return; 1035 return;
1037 1036
1038 string16 text = dangerous_download_label_->GetText(); 1037 string16 text = WideToUTF16(dangerous_download_label_->GetText());
1039 TrimWhitespace(text, TRIM_ALL, &text); 1038 TrimWhitespace(text, TRIM_ALL, &text);
1040 DCHECK_EQ(string16::npos, text.find('\n')); 1039 DCHECK_EQ(string16::npos, text.find('\n'));
1041 1040
1042 // Make the label big so that GetPreferredSize() is not constrained by the 1041 // Make the label big so that GetPreferredSize() is not constrained by the
1043 // current width. 1042 // current width.
1044 dangerous_download_label_->SetBounds(0, 0, 1000, 1000); 1043 dangerous_download_label_->SetBounds(0, 0, 1000, 1000);
1045 1044
1046 gfx::Size size; 1045 gfx::Size size;
1047 int min_width = -1; 1046 int min_width = -1;
1048 // Using BREAK_WORD can work in most cases, but it can also break 1047 // Using BREAK_WORD can work in most cases, but it can also break
(...skipping 10 matching lines...) Expand all
1059 if (pos >= text.length()) 1058 if (pos >= text.length())
1060 break; 1059 break;
1061 // This can be a low surrogate codepoint, but u_isUWhiteSpace will 1060 // This can be a low surrogate codepoint, but u_isUWhiteSpace will
1062 // return false and inserting a new line after a surrogate pair 1061 // return false and inserting a new line after a surrogate pair
1063 // is perfectly ok. 1062 // is perfectly ok.
1064 char16 line_end_char = text[pos - 1]; 1063 char16 line_end_char = text[pos - 1];
1065 if (u_isUWhiteSpace(line_end_char)) 1064 if (u_isUWhiteSpace(line_end_char))
1066 current_text.replace(pos - 1, 1, 1, char16('\n')); 1065 current_text.replace(pos - 1, 1, 1, char16('\n'));
1067 else 1066 else
1068 current_text.insert(pos, 1, char16('\n')); 1067 current_text.insert(pos, 1, char16('\n'));
1069 dangerous_download_label_->SetText(current_text); 1068 dangerous_download_label_->SetText(UTF16ToWide(current_text));
1070 size = dangerous_download_label_->GetPreferredSize(); 1069 size = dangerous_download_label_->GetPreferredSize();
1071 1070
1072 if (min_width == -1) 1071 if (min_width == -1)
1073 min_width = size.width(); 1072 min_width = size.width();
1074 1073
1075 // If the width is growing again, it means we passed the optimal width spot. 1074 // If the width is growing again, it means we passed the optimal width spot.
1076 if (size.width() > min_width) { 1075 if (size.width() > min_width) {
1077 dangerous_download_label_->SetText(prev_text); 1076 dangerous_download_label_->SetText(UTF16ToWide(prev_text));
1078 break; 1077 break;
1079 } else { 1078 } else {
1080 min_width = size.width(); 1079 min_width = size.width();
1081 } 1080 }
1082 1081
1083 // Restore the string. 1082 // Restore the string.
1084 prev_text = current_text; 1083 prev_text = current_text;
1085 current_text = text; 1084 current_text = text;
1086 } 1085 }
1087 1086
(...skipping 13 matching lines...) Expand all
1101 1100
1102 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) { 1101 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) {
1103 if (x > drop_down_x_left_ && x < drop_down_x_right_) 1102 if (x > drop_down_x_left_ && x < drop_down_x_right_)
1104 return true; 1103 return true;
1105 return false; 1104 return false;
1106 } 1105 }
1107 1106
1108 void DownloadItemView::UpdateAccessibleName() { 1107 void DownloadItemView::UpdateAccessibleName() {
1109 string16 new_name; 1108 string16 new_name;
1110 if (download_->safety_state() == DownloadItem::DANGEROUS) { 1109 if (download_->safety_state() == DownloadItem::DANGEROUS) {
1111 new_name = dangerous_download_label_->GetText(); 1110 new_name = WideToUTF16Hack(dangerous_download_label_->GetText());
1112 } else { 1111 } else {
1113 new_name = status_text_ + char16(' ') + 1112 new_name = status_text_ + char16(' ') +
1114 download_->GetFileNameToReportUser().LossyDisplayName(); 1113 download_->GetFileNameToReportUser().LossyDisplayName();
1115 } 1114 }
1116 1115
1117 // If the name has changed, notify assistive technology that the name 1116 // If the name has changed, notify assistive technology that the name
1118 // has changed so they can announce it immediately. 1117 // has changed so they can announce it immediately.
1119 if (new_name != accessible_name_) { 1118 if (new_name != accessible_name_) {
1120 accessible_name_ = new_name; 1119 accessible_name_ = new_name;
1121 if (GetWidget()) { 1120 if (GetWidget()) {
1122 GetWidget()->NotifyAccessibilityEvent( 1121 GetWidget()->NotifyAccessibilityEvent(
1123 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true); 1122 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true);
1124 } 1123 }
1125 } 1124 }
1126 } 1125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698