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

Side by Side Diff: chrome/browser/ui/views/about_chrome_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/about_chrome_view.h" 5 #include "chrome/browser/ui/views/about_chrome_view.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <commdlg.h> 8 #include <commdlg.h>
9 #endif // defined(OS_WIN) 9 #endif // defined(OS_WIN)
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #if defined(OS_WIN) 45 #if defined(OS_WIN)
46 #include "base/win/win_util.h" 46 #include "base/win/win_util.h"
47 #include "chrome/browser/browser_process.h" 47 #include "chrome/browser/browser_process.h"
48 #include "chrome/browser/ui/views/restart_message_box.h" 48 #include "chrome/browser/ui/views/restart_message_box.h"
49 #include "chrome/installer/util/install_util.h" 49 #include "chrome/installer/util/install_util.h"
50 #endif // defined(OS_WIN) 50 #endif // defined(OS_WIN)
51 51
52 namespace { 52 namespace {
53 // These are used as placeholder text around the links in the text in the about 53 // These are used as placeholder text around the links in the text in the about
54 // dialog. 54 // dialog.
55 const string16 kBeginLink(ASCIIToUTF16("BEGIN_LINK")); 55 const wchar_t* kBeginLink = L"BEGIN_LINK";
56 const string16 kEndLink(ASCIIToUTF16("END_LINK")); 56 const wchar_t* kEndLink = L"END_LINK";
57 const string16 kBeginLinkChr(ASCIIToUTF16("BEGIN_LINK_CHR")); 57 const wchar_t* kBeginLinkChr = L"BEGIN_LINK_CHR";
58 const string16 kBeginLinkOss(ASCIIToUTF16("BEGIN_LINK_OSS")); 58 const wchar_t* kBeginLinkOss = L"BEGIN_LINK_OSS";
59 const string16 kEndLinkChr(ASCIIToUTF16("END_LINK_CHR")); 59 const wchar_t* kEndLinkChr = L"END_LINK_CHR";
60 const string16 kEndLinkOss(ASCIIToUTF16("END_LINK_OSS")); 60 const wchar_t* kEndLinkOss = L"END_LINK_OSS";
61 61
62 // The background bitmap used to draw the background color for the About box 62 // The background bitmap used to draw the background color for the About box
63 // and the separator line (this is the image we will draw the logo on top of). 63 // and the separator line (this is the image we will draw the logo on top of).
64 static const SkBitmap* kBackgroundBmp = NULL; 64 static const SkBitmap* kBackgroundBmp = NULL;
65 65
66 // Returns a substring from |text| between start and end. 66 // Returns a substring from |text| between start and end.
67 string16 StringSubRange(const string16& text, size_t start, size_t end) { 67 std::wstring StringSubRange(const std::wstring& text, size_t start,
68 size_t end) {
68 DCHECK(end > start); 69 DCHECK(end > start);
69 return text.substr(start, end - start); 70 return text.substr(start, end - start);
70 } 71 }
71 72
72 } // namespace 73 } // namespace
73 74
74 namespace browser { 75 namespace browser {
75 76
76 // Declared in browser_dialogs.h so that others don't 77 // Declared in browser_dialogs.h so that others don't
77 // need to depend on our .h. 78 // need to depend on our .h.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // layout of the view. 157 // layout of the view.
157 about_dlg_background_logo_ = new views::ImageView(); 158 about_dlg_background_logo_ = new views::ImageView();
158 SkBitmap* about_background_logo = rb.GetBitmapNamed(base::i18n::IsRTL() ? 159 SkBitmap* about_background_logo = rb.GetBitmapNamed(base::i18n::IsRTL() ?
159 IDR_ABOUT_BACKGROUND_RTL : IDR_ABOUT_BACKGROUND); 160 IDR_ABOUT_BACKGROUND_RTL : IDR_ABOUT_BACKGROUND);
160 161
161 about_dlg_background_logo_->SetImage(*about_background_logo); 162 about_dlg_background_logo_->SetImage(*about_background_logo);
162 AddChildView(about_dlg_background_logo_); 163 AddChildView(about_dlg_background_logo_);
163 164
164 // Add the dialog labels. 165 // Add the dialog labels.
165 about_title_label_ = new views::Label( 166 about_title_label_ = new views::Label(
166 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 167 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
167 about_title_label_->SetFont(ResourceBundle::GetSharedInstance().GetFont( 168 about_title_label_->SetFont(ResourceBundle::GetSharedInstance().GetFont(
168 ResourceBundle::BaseFont).DeriveFont(18)); 169 ResourceBundle::BaseFont).DeriveFont(18));
169 about_title_label_->SetColor(SK_ColorBLACK); 170 about_title_label_->SetColor(SK_ColorBLACK);
170 AddChildView(about_title_label_); 171 AddChildView(about_title_label_);
171 172
172 // This is a text field so people can copy the version number from the dialog. 173 // This is a text field so people can copy the version number from the dialog.
173 version_label_ = new views::Textfield(); 174 version_label_ = new views::Textfield();
174 chrome::VersionInfo version_info; 175 chrome::VersionInfo version_info;
175 version_label_->SetText(UTF8ToUTF16(version_info.CreateVersionString())); 176 version_label_->SetText(UTF8ToUTF16(version_info.CreateVersionString()));
176 version_label_->SetReadOnly(true); 177 version_label_->SetReadOnly(true);
177 version_label_->RemoveBorder(); 178 version_label_->RemoveBorder();
178 version_label_->SetTextColor(SK_ColorBLACK); 179 version_label_->SetTextColor(SK_ColorBLACK);
179 version_label_->SetBackgroundColor(SK_ColorWHITE); 180 version_label_->SetBackgroundColor(SK_ColorWHITE);
180 version_label_->SetFont(ResourceBundle::GetSharedInstance().GetFont( 181 version_label_->SetFont(ResourceBundle::GetSharedInstance().GetFont(
181 ResourceBundle::BaseFont)); 182 ResourceBundle::BaseFont));
182 AddChildView(version_label_); 183 AddChildView(version_label_);
183 184
184 // The copyright URL portion of the main label. 185 // The copyright URL portion of the main label.
185 copyright_label_ = new views::Label( 186 copyright_label_ = new views::Label(
186 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COPYRIGHT)); 187 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COPYRIGHT)));
187 copyright_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 188 copyright_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
188 AddChildView(copyright_label_); 189 AddChildView(copyright_label_);
189 190
190 main_text_label_ = new views::Label(string16()); 191 main_text_label_ = new views::Label(L"");
191 192
192 // Figure out what to write in the main label of the About box. 193 // Figure out what to write in the main label of the About box.
193 string16 text = l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_LICENSE); 194 std::wstring text =
195 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_LICENSE));
194 196
195 chromium_url_appears_first_ = 197 chromium_url_appears_first_ =
196 text.find(kBeginLinkChr) < text.find(kBeginLinkOss); 198 text.find(kBeginLinkChr) < text.find(kBeginLinkOss);
197 199
198 size_t link1 = text.find(kBeginLink); 200 size_t link1 = text.find(kBeginLink);
199 DCHECK(link1 != std::wstring::npos); 201 DCHECK(link1 != std::wstring::npos);
200 size_t link1_end = text.find(kEndLink, link1); 202 size_t link1_end = text.find(kEndLink, link1);
201 DCHECK(link1_end != std::wstring::npos); 203 DCHECK(link1_end != std::wstring::npos);
202 size_t link2 = text.find(kBeginLink, link1_end); 204 size_t link2 = text.find(kBeginLink, link1_end);
203 DCHECK(link2 != std::wstring::npos); 205 DCHECK(link2 != std::wstring::npos);
204 size_t link2_end = text.find(kEndLink, link2); 206 size_t link2_end = text.find(kEndLink, link2);
205 DCHECK(link1_end != std::wstring::npos); 207 DCHECK(link1_end != std::wstring::npos);
206 208
207 main_label_chunk1_ = text.substr(0, link1); 209 main_label_chunk1_ = text.substr(0, link1);
208 main_label_chunk2_ = StringSubRange(text, link1_end + kEndLinkOss.size(), 210 main_label_chunk2_ = StringSubRange(text, link1_end + wcslen(kEndLinkOss),
209 link2); 211 link2);
210 main_label_chunk3_ = text.substr(link2_end + kEndLinkOss.size()); 212 main_label_chunk3_ = text.substr(link2_end + wcslen(kEndLinkOss));
211 213
212 // The Chromium link within the main text of the dialog. 214 // The Chromium link within the main text of the dialog.
213 chromium_url_ = new views::Link( 215 chromium_url_ = new views::Link(
214 StringSubRange(text, text.find(kBeginLinkChr) + kBeginLinkChr.size(), 216 StringSubRange(text, text.find(kBeginLinkChr) + wcslen(kBeginLinkChr),
215 text.find(kEndLinkChr))); 217 text.find(kEndLinkChr)));
216 AddChildView(chromium_url_); 218 AddChildView(chromium_url_);
217 chromium_url_->set_listener(this); 219 chromium_url_->set_listener(this);
218 220
219 // The Open Source link within the main text of the dialog. 221 // The Open Source link within the main text of the dialog.
220 open_source_url_ = new views::Link( 222 open_source_url_ = new views::Link(
221 StringSubRange(text, text.find(kBeginLinkOss) + kBeginLinkOss.size(), 223 StringSubRange(text, text.find(kBeginLinkOss) + wcslen(kBeginLinkOss),
222 text.find(kEndLinkOss))); 224 text.find(kEndLinkOss)));
223 AddChildView(open_source_url_); 225 AddChildView(open_source_url_);
224 open_source_url_->set_listener(this); 226 open_source_url_->set_listener(this);
225 227
226 // Add together all the strings in the dialog for the purpose of calculating 228 // Add together all the strings in the dialog for the purpose of calculating
227 // the height of the dialog. The space for the Terms of Service string is not 229 // the height of the dialog. The space for the Terms of Service string is not
228 // included (it is added later, if needed). 230 // included (it is added later, if needed).
229 string16 full_text = main_label_chunk1_ + chromium_url_->GetText() + 231 std::wstring full_text = main_label_chunk1_ + chromium_url_->GetText() +
230 main_label_chunk2_ + open_source_url_->GetText() + 232 main_label_chunk2_ + open_source_url_->GetText() +
231 main_label_chunk3_; 233 main_label_chunk3_;
232 234
233 dialog_dimensions_ = views::Widget::GetLocalizedContentsSize( 235 dialog_dimensions_ = views::Widget::GetLocalizedContentsSize(
234 IDS_ABOUT_DIALOG_WIDTH_CHARS, 236 IDS_ABOUT_DIALOG_WIDTH_CHARS,
235 IDS_ABOUT_DIALOG_MINIMUM_HEIGHT_LINES); 237 IDS_ABOUT_DIALOG_MINIMUM_HEIGHT_LINES);
236 238
237 // Create a label and add the full text so we can query it for the height. 239 // Create a label and add the full text so we can query it for the height.
238 views::Label dummy_text(full_text); 240 views::Label dummy_text(full_text);
239 dummy_text.SetMultiLine(true); 241 dummy_text.SetMultiLine(true);
240 gfx::Font font = 242 gfx::Font font =
241 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); 243 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 &chromium_url_rect_ : &open_source_url_rect_; 399 &chromium_url_rect_ : &open_source_url_rect_;
398 gfx::Rect* rect2 = chromium_url_appears_first_ ? 400 gfx::Rect* rect2 = chromium_url_appears_first_ ?
399 &open_source_url_rect_ : &chromium_url_rect_; 401 &open_source_url_rect_ : &chromium_url_rect_;
400 402
401 // This struct keeps track of where to write the next word (which x,y 403 // This struct keeps track of where to write the next word (which x,y
402 // pixel coordinate). This struct is updated after drawing text and checking 404 // pixel coordinate). This struct is updated after drawing text and checking
403 // if we need to wrap. 405 // if we need to wrap.
404 gfx::Size position; 406 gfx::Size position;
405 // Draw the first text chunk and position the Chromium url. 407 // Draw the first text chunk and position the Chromium url.
406 view_text_utils::DrawTextAndPositionUrl(canvas, main_text_label_, 408 view_text_utils::DrawTextAndPositionUrl(canvas, main_text_label_,
407 UTF16ToWideHack(main_label_chunk1_), link1, rect1, &position, 409 main_label_chunk1_, link1, rect1, &position, text_direction_is_rtl_,
408 text_direction_is_rtl_, label_bounds, font); 410 label_bounds, font);
409 // Draw the second text chunk and position the Open Source url. 411 // Draw the second text chunk and position the Open Source url.
410 view_text_utils::DrawTextAndPositionUrl(canvas, main_text_label_, 412 view_text_utils::DrawTextAndPositionUrl(canvas, main_text_label_,
411 UTF16ToWideHack(main_label_chunk2_), link2, rect2, &position, 413 main_label_chunk2_, link2, rect2, &position, text_direction_is_rtl_,
412 text_direction_is_rtl_, label_bounds, font); 414 label_bounds, font);
413 // Draw the third text chunk (which has no URL associated with it). 415 // Draw the third text chunk (which has no URL associated with it).
414 view_text_utils::DrawTextAndPositionUrl(canvas, main_text_label_, 416 view_text_utils::DrawTextAndPositionUrl(canvas, main_text_label_,
415 UTF16ToWideHack(main_label_chunk3_), NULL, NULL, &position, 417 main_label_chunk3_, NULL, NULL, &position, text_direction_is_rtl_,
416 text_direction_is_rtl_, label_bounds, font); 418 label_bounds, font);
417 419
418 #if defined(GOOGLE_CHROME_BUILD) 420 #if defined(GOOGLE_CHROME_BUILD)
419 // Insert a line break and some whitespace. 421 // Insert a line break and some whitespace.
420 position.set_width(0); 422 position.set_width(0);
421 position.Enlarge(0, font.GetHeight() + views::kRelatedControlVerticalSpacing); 423 position.Enlarge(0, font.GetHeight() + views::kRelatedControlVerticalSpacing);
422 424
423 // And now the Terms of Service and position the TOS url. 425 // And now the Terms of Service and position the TOS url.
424 view_text_utils::DrawTextAndPositionUrl(canvas, main_text_label_, 426 view_text_utils::DrawTextAndPositionUrl(canvas, main_text_label_,
425 main_label_chunk4_, terms_of_service_url_, &terms_of_service_url_rect_, 427 main_label_chunk4_, terms_of_service_url_, &terms_of_service_url_rect_,
426 &position, text_direction_is_rtl_, label_bounds, font); 428 &position, text_direction_is_rtl_, label_bounds, font);
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 IDS_UPGRADE_SUCCESSFUL_RELAUNCH, 692 IDS_UPGRADE_SUCCESSFUL_RELAUNCH,
691 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); 693 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
692 update_label_.SetText(update_string); 694 update_label_.SetText(update_string);
693 show_success_indicator = true; 695 show_success_indicator = true;
694 break; 696 break;
695 } 697 }
696 case UPGRADE_ERROR: 698 case UPGRADE_ERROR:
697 UserMetrics::RecordAction(UserMetricsAction("UpgradeCheck_Error")); 699 UserMetrics::RecordAction(UserMetricsAction("UpgradeCheck_Error"));
698 restart_button_visible_ = false; 700 restart_button_visible_ = false;
699 if (error_code != GOOGLE_UPDATE_DISABLED_BY_POLICY) { 701 if (error_code != GOOGLE_UPDATE_DISABLED_BY_POLICY) {
700 update_label_.SetText( 702 update_label_.SetText(UTF16ToWide(
701 l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code)); 703 l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code)));
702 } else { 704 } else {
703 update_label_.SetText( 705 update_label_.SetText(UTF16ToWide(
704 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)); 706 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY)));
705 } 707 }
706 show_timeout_indicator = true; 708 show_timeout_indicator = true;
707 break; 709 break;
708 default: 710 default:
709 NOTREACHED(); 711 NOTREACHED();
710 } 712 }
711 713
712 success_indicator_.SetVisible(show_success_indicator); 714 success_indicator_.SetVisible(show_success_indicator);
713 update_available_indicator_.SetVisible(show_update_available_indicator); 715 update_available_indicator_.SetVisible(show_update_available_indicator);
714 timeout_indicator_.SetVisible(show_timeout_indicator); 716 timeout_indicator_.SetVisible(show_timeout_indicator);
715 update_label_.SetVisible(show_update_label); 717 update_label_.SetVisible(show_update_label);
716 throbber_->SetVisible(show_throbber); 718 throbber_->SetVisible(show_throbber);
717 if (show_throbber) 719 if (show_throbber)
718 throbber_->Start(); 720 throbber_->Start();
719 else 721 else
720 throbber_->Stop(); 722 throbber_->Stop();
721 723
722 // We have updated controls on the parent, so we need to update its layout. 724 // We have updated controls on the parent, so we need to update its layout.
723 parent()->Layout(); 725 parent()->Layout();
724 726
725 // Check button may have appeared/disappeared. We cannot call this during 727 // Check button may have appeared/disappeared. We cannot call this during
726 // ViewHierarchyChanged because the view hasn't been added to a Widget yet. 728 // ViewHierarchyChanged because the view hasn't been added to a Widget yet.
727 if (GetWidget()) 729 if (GetWidget())
728 GetDialogClientView()->UpdateDialogButtons(); 730 GetDialogClientView()->UpdateDialogButtons();
729 } 731 }
730 732
731 #endif 733 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/about_chrome_view.h ('k') | chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698