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

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

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

Powered by Google App Engine
This is Rietveld 408576698