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/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 "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
11 #include "app/text_elider.h" | |
12 #include "base/callback.h" | 11 #include "base/callback.h" |
13 #include "base/file_path.h" | 12 #include "base/file_path.h" |
14 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
15 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
16 #include "base/string_util.h" | 15 #include "base/string_util.h" |
17 #include "base/sys_string_conversions.h" | 16 #include "base/sys_string_conversions.h" |
18 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
19 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/download/download_item_model.h" | 19 #include "chrome/browser/download/download_item_model.h" |
21 #include "chrome/browser/download/download_util.h" | 20 #include "chrome/browser/download/download_util.h" |
22 #include "chrome/browser/themes/browser_theme_provider.h" | 21 #include "chrome/browser/themes/browser_theme_provider.h" |
23 #include "chrome/browser/ui/views/download_shelf_view.h" | 22 #include "chrome/browser/ui/views/download_shelf_view.h" |
24 #include "gfx/canvas_skia.h" | 23 #include "gfx/canvas_skia.h" |
25 #include "gfx/color_utils.h" | 24 #include "gfx/color_utils.h" |
26 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
27 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
28 #include "ui/base/animation/slide_animation.h" | 27 #include "ui/base/animation/slide_animation.h" |
| 28 #include "ui/base/text/text_elider.h" |
29 #include "views/controls/button/native_button.h" | 29 #include "views/controls/button/native_button.h" |
30 #include "views/controls/menu/menu_2.h" | 30 #include "views/controls/menu/menu_2.h" |
31 #include "views/widget/root_view.h" | 31 #include "views/widget/root_view.h" |
32 #include "views/widget/widget.h" | 32 #include "views/widget/widget.h" |
33 | 33 |
34 using base::TimeDelta; | 34 using base::TimeDelta; |
35 | 35 |
36 // TODO(paulg): These may need to be adjusted when download progress | 36 // TODO(paulg): These may need to be adjusted when download progress |
37 // animation is added, and also possibly to take into account | 37 // animation is added, and also possibly to take into account |
38 // different screen resolutions. | 38 // different screen resolutions. |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 #if defined(OS_LINUX) | 273 #if defined(OS_LINUX) |
274 std::wstring rootname = | 274 std::wstring rootname = |
275 base::SysNativeMBToWide(filename.RemoveExtension().value()); | 275 base::SysNativeMBToWide(filename.RemoveExtension().value()); |
276 #else | 276 #else |
277 std::wstring rootname = filename.RemoveExtension().value(); | 277 std::wstring rootname = filename.RemoveExtension().value(); |
278 #endif | 278 #endif |
279 | 279 |
280 // Elide giant extensions (this shouldn't currently be hit, but might | 280 // Elide giant extensions (this shouldn't currently be hit, but might |
281 // in future, should we ever notice unsafe giant extensions). | 281 // in future, should we ever notice unsafe giant extensions). |
282 if (extension.length() > kFileNameMaxLength / 2) | 282 if (extension.length() > kFileNameMaxLength / 2) |
283 gfx::ElideString(extension, kFileNameMaxLength / 2, &extension); | 283 ui::ElideString(extension, kFileNameMaxLength / 2, &extension); |
284 | 284 |
285 // The dangerous download label text is different for an extension file. | 285 // The dangerous download label text is different for an extension file. |
286 if (download->is_extension_install()) { | 286 if (download->is_extension_install()) { |
287 dangerous_download_label_ = new views::Label(UTF16ToWide( | 287 dangerous_download_label_ = new views::Label(UTF16ToWide( |
288 l10n_util::GetStringUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION))); | 288 l10n_util::GetStringUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION))); |
289 } else { | 289 } else { |
290 gfx::ElideString(rootname, | 290 ui::ElideString(rootname, |
291 kFileNameMaxLength - extension.length(), | 291 kFileNameMaxLength - extension.length(), |
292 &rootname); | 292 &rootname); |
293 std::wstring filename = rootname + L"." + extension; | 293 std::wstring filename = rootname + L"." + extension; |
294 filename = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality( | 294 filename = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality( |
295 WideToUTF16(filename))); | 295 WideToUTF16(filename))); |
296 dangerous_download_label_ = new views::Label(UTF16ToWide( | 296 dangerous_download_label_ = new views::Label(UTF16ToWide( |
297 l10n_util::GetStringFUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD, | 297 l10n_util::GetStringFUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD, |
298 WideToUTF16(filename)))); | 298 WideToUTF16(filename)))); |
299 } | 299 } |
300 dangerous_download_label_->SetMultiLine(true); | 300 dangerous_download_label_->SetMultiLine(true); |
301 dangerous_download_label_->SetHorizontalAlignment( | 301 dangerous_download_label_->SetHorizontalAlignment( |
302 views::Label::ALIGN_LEFT); | 302 views::Label::ALIGN_LEFT); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 // Consequently, the x-axis of following canvas->DrawXXX() method should be | 602 // Consequently, the x-axis of following canvas->DrawXXX() method should be |
603 // mirrored so the text and images are down in the right positions. | 603 // mirrored so the text and images are down in the right positions. |
604 canvas->Restore(); | 604 canvas->Restore(); |
605 | 605 |
606 // Print the text, left aligned and always print the file extension. | 606 // Print the text, left aligned and always print the file extension. |
607 // Last value of x was the end of the right image, just before the button. | 607 // Last value of x was the end of the right image, just before the button. |
608 // Note that in dangerous mode we use a label (as the text is multi-line). | 608 // Note that in dangerous mode we use a label (as the text is multi-line). |
609 if (!IsDangerousMode()) { | 609 if (!IsDangerousMode()) { |
610 string16 filename; | 610 string16 filename; |
611 if (!disabled_while_opening_) { | 611 if (!disabled_while_opening_) { |
612 filename = gfx::ElideFilename(download_->GetFileNameToReportUser(), | 612 filename = ui::ElideFilename(download_->GetFileNameToReportUser(), |
613 font_, kTextWidth); | 613 font_, kTextWidth); |
614 } else { | 614 } else { |
615 // First, Calculate the download status opening string width. | 615 // First, Calculate the download status opening string width. |
616 string16 status_string = | 616 string16 status_string = |
617 l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, string16()); | 617 l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, string16()); |
618 int status_string_width = font_.GetStringWidth(status_string); | 618 int status_string_width = font_.GetStringWidth(status_string); |
619 // Then, elide the file name. | 619 // Then, elide the file name. |
620 string16 filename_string = | 620 string16 filename_string = |
621 gfx::ElideFilename(download_->GetFileNameToReportUser(), font_, | 621 gfx::ElideFilename(download_->GetFileNameToReportUser(), font_, |
622 kTextWidth - status_string_width); | 622 kTextWidth - status_string_width); |
623 // Last, concat the whole string. | 623 // Last, concat the whole string. |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 | 1074 |
1075 // If the name has changed, call SetAccessibleName and notify | 1075 // If the name has changed, call SetAccessibleName and notify |
1076 // assistive technology that the name has changed so they can | 1076 // assistive technology that the name has changed so they can |
1077 // announce it immediately. | 1077 // announce it immediately. |
1078 if (new_name != current_name) { | 1078 if (new_name != current_name) { |
1079 SetAccessibleName(new_name); | 1079 SetAccessibleName(new_name); |
1080 if (GetWidget()) | 1080 if (GetWidget()) |
1081 NotifyAccessibilityEvent(AccessibilityTypes::EVENT_NAME_CHANGED); | 1081 NotifyAccessibilityEvent(AccessibilityTypes::EVENT_NAME_CHANGED); |
1082 } | 1082 } |
1083 } | 1083 } |
OLD | NEW |