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

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

Issue 16533: Convert download manager to FilePath. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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
« no previous file with comments | « chrome/browser/history/history_unittest.cc ('k') | chrome/browser/views/download_tab_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/views/download_item_view.h" 5 #include "chrome/browser/views/download_item_view.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 save_button_ = new views::NativeButton( 194 save_button_ = new views::NativeButton(
195 l10n_util::GetString(IDS_SAVE_DOWNLOAD)); 195 l10n_util::GetString(IDS_SAVE_DOWNLOAD));
196 save_button_->set_enforce_dlu_min_size(false); 196 save_button_->set_enforce_dlu_min_size(false);
197 save_button_->SetListener(this); 197 save_button_->SetListener(this);
198 discard_button_ = new views::NativeButton( 198 discard_button_ = new views::NativeButton(
199 l10n_util::GetString(IDS_DISCARD_DOWNLOAD)); 199 l10n_util::GetString(IDS_DISCARD_DOWNLOAD));
200 discard_button_->SetListener(this); 200 discard_button_->SetListener(this);
201 discard_button_->set_enforce_dlu_min_size(false); 201 discard_button_->set_enforce_dlu_min_size(false);
202 AddChildView(save_button_); 202 AddChildView(save_button_);
203 AddChildView(discard_button_); 203 AddChildView(discard_button_);
204 std::wstring file_name = download->original_name(); 204 std::wstring file_name = download->original_name().ToWStringHack();
205 205
206 // Ensure the file name is not too long. 206 // Ensure the file name is not too long.
207 207
208 // Extract the file extension (if any). 208 // Extract the file extension (if any).
209 std::wstring extension = file_util::GetFileExtensionFromPath(file_name); 209 std::wstring extension = file_util::GetFileExtensionFromPath(file_name);
210 std::wstring rootname = 210 std::wstring rootname =
211 file_util::GetFilenameWithoutExtensionFromPath(file_name); 211 file_util::GetFilenameWithoutExtensionFromPath(file_name);
212 212
213 // Elide giant extensions (this shouldn't currently be hit, but might 213 // Elide giant extensions (this shouldn't currently be hit, but might
214 // in future, should we ever notice unsafe giant extensions). 214 // in future, should we ever notice unsafe giant extensions).
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 450
451 canvas->restore(); 451 canvas->restore();
452 } 452 }
453 } 453 }
454 454
455 // Print the text, left aligned and always print the file extension. 455 // Print the text, left aligned and always print the file extension.
456 // Last value of x was the end of the right image, just before the button. 456 // Last value of x was the end of the right image, just before the button.
457 // Note that in dangerous mode we use a label (as the text is multi-line). 457 // Note that in dangerous mode we use a label (as the text is multi-line).
458 if (!IsDangerousMode()) { 458 if (!IsDangerousMode()) {
459 std::wstring filename = 459 std::wstring filename =
460 gfx::ElideFilename(download_->GetFileName(), 460 gfx::ElideFilename(download_->GetFileName().ToWStringHack(),
461 font_, 461 font_,
462 kTextWidth); 462 kTextWidth);
463 463
464 if (show_status_text_) { 464 if (show_status_text_) {
465 int y = box_y_ + kVerticalPadding; 465 int y = box_y_ + kVerticalPadding;
466 466
467 // Draw the file's name. 467 // Draw the file's name.
468 canvas->DrawStringInt(filename, font_, kFileNameColor, 468 canvas->DrawStringInt(filename, font_, kFileNameColor,
469 download_util::kSmallProgressIconSize, y, 469 download_util::kSmallProgressIconSize, y,
470 kTextWidth, font_.height()); 470 kTextWidth, font_.height());
471 471
472 y += font_.height() + kVerticalTextPadding; 472 y += font_.height() + kVerticalTextPadding;
473 473
474 canvas->DrawStringInt(status_text_, font_, kStatusColor, 474 canvas->DrawStringInt(status_text_, font_, kStatusColor,
475 download_util::kSmallProgressIconSize, y, 475 download_util::kSmallProgressIconSize, y,
476 kTextWidth, font_.height()); 476 kTextWidth, font_.height());
477 } else { 477 } else {
478 int y = box_y_ + (box_height_ - font_.height()) / 2; 478 int y = box_y_ + (box_height_ - font_.height()) / 2;
479 479
480 // Draw the file's name. 480 // Draw the file's name.
481 canvas->DrawStringInt(filename, font_, kFileNameColor, 481 canvas->DrawStringInt(filename, font_, kFileNameColor,
482 download_util::kSmallProgressIconSize, y, 482 download_util::kSmallProgressIconSize, y,
483 kTextWidth, font_.height()); 483 kTextWidth, font_.height());
484 } 484 }
485 } 485 }
486 486
487 // Paint the icon. 487 // Paint the icon.
488 IconManager* im = g_browser_process->icon_manager(); 488 IconManager* im = g_browser_process->icon_manager();
489 SkBitmap* icon = IsDangerousMode() ? warning_icon_ : 489 SkBitmap* icon = IsDangerousMode() ? warning_icon_ :
490 im->LookupIcon(download_->full_path(), IconLoader::SMALL); 490 im->LookupIcon(download_->full_path().ToWStringHack(), IconLoader::SMALL);
491 491
492 // We count on the fact that the icon manager will cache the icons and if one 492 // We count on the fact that the icon manager will cache the icons and if one
493 // is available, it will be cached here. We *don't* want to request the icon 493 // is available, it will be cached here. We *don't* want to request the icon
494 // to be loaded here, since this will also get called if the icon can't be 494 // to be loaded here, since this will also get called if the icon can't be
495 // loaded, in which case LookupIcon will always be NULL. The loading will be 495 // loaded, in which case LookupIcon will always be NULL. The loading will be
496 // triggered only when we think the status might change. 496 // triggered only when we think the status might change.
497 if (icon) { 497 if (icon) {
498 if (!IsDangerousMode()) { 498 if (!IsDangerousMode()) {
499 if (download_->state() == DownloadItem::IN_PROGRESS) { 499 if (download_->state() == DownloadItem::IN_PROGRESS) {
500 download_util::PaintDownloadProgress(canvas, this, 0, 0, 500 download_util::PaintDownloadProgress(canvas, this, 0, 0,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 if (IsDangerousMode()) 709 if (IsDangerousMode())
710 return true; 710 return true;
711 711
712 if (!starting_drag_) { 712 if (!starting_drag_) {
713 starting_drag_ = true; 713 starting_drag_ = true;
714 drag_start_point_ = event.location(); 714 drag_start_point_ = event.location();
715 } 715 }
716 if (dragging_) { 716 if (dragging_) {
717 if (download_->state() == DownloadItem::COMPLETE) { 717 if (download_->state() == DownloadItem::COMPLETE) {
718 IconManager* im = g_browser_process->icon_manager(); 718 IconManager* im = g_browser_process->icon_manager();
719 SkBitmap* icon = im->LookupIcon(download_->full_path(), 719 SkBitmap* icon = im->LookupIcon(download_->full_path().ToWStringHack(),
720 IconLoader::SMALL); 720 IconLoader::SMALL);
721 if (icon) 721 if (icon)
722 download_util::DragDownload(download_, icon); 722 download_util::DragDownload(download_, icon);
723 } 723 }
724 } else if (win_util::IsDrag(drag_start_point_.ToPOINT(), 724 } else if (win_util::IsDrag(drag_start_point_.ToPOINT(),
725 event.location().ToPOINT())) { 725 event.location().ToPOINT())) {
726 dragging_ = true; 726 dragging_ = true;
727 } 727 }
728 return true; 728 return true;
729 } 729 }
(...skipping 13 matching lines...) Expand all
743 } 743 }
744 744
745 void DownloadItemView::OnExtractIconComplete(IconManager::Handle handle, 745 void DownloadItemView::OnExtractIconComplete(IconManager::Handle handle,
746 SkBitmap* icon_bitmap) { 746 SkBitmap* icon_bitmap) {
747 if (icon_bitmap) 747 if (icon_bitmap)
748 GetParent()->SchedulePaint(); 748 GetParent()->SchedulePaint();
749 } 749 }
750 750
751 void DownloadItemView::LoadIcon() { 751 void DownloadItemView::LoadIcon() {
752 IconManager* im = g_browser_process->icon_manager(); 752 IconManager* im = g_browser_process->icon_manager();
753 im->LoadIcon(download_->full_path(), IconLoader::SMALL, 753 im->LoadIcon(download_->full_path().ToWStringHack(), IconLoader::SMALL,
754 &icon_consumer_, 754 &icon_consumer_,
755 NewCallback(this, &DownloadItemView::OnExtractIconComplete)); 755 NewCallback(this, &DownloadItemView::OnExtractIconComplete));
756 } 756 }
757 757
758 gfx::Size DownloadItemView::GetButtonSize() { 758 gfx::Size DownloadItemView::GetButtonSize() {
759 DCHECK(save_button_ && discard_button_); 759 DCHECK(save_button_ && discard_button_);
760 gfx::Size size; 760 gfx::Size size;
761 761
762 // We cache the size when successfully retrieved, not for performance reasons 762 // We cache the size when successfully retrieved, not for performance reasons
763 // but because if this DownloadItemView is being animated while the tab is 763 // but because if this DownloadItemView is being animated while the tab is
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 sp_index = text.find(L" ", sp_index + 1); 816 sp_index = text.find(L" ", sp_index + 1);
817 } 817 }
818 818
819 // If we have a line with no space, we won't cut it. 819 // If we have a line with no space, we won't cut it.
820 if (min_width == -1) 820 if (min_width == -1)
821 size = dangerous_download_label_->GetPreferredSize(); 821 size = dangerous_download_label_->GetPreferredSize();
822 822
823 dangerous_download_label_->SetBounds(0, 0, size.width(), size.height()); 823 dangerous_download_label_->SetBounds(0, 0, size.width(), size.height());
824 dangerous_download_label_sized_ = true; 824 dangerous_download_label_sized_ = true;
825 } 825 }
OLDNEW
« no previous file with comments | « chrome/browser/history/history_unittest.cc ('k') | chrome/browser/views/download_tab_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698