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