OLD | NEW |
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_tab_view.h" | 5 #include "chrome/browser/views/download_tab_view.h" |
6 | 6 |
7 #include <time.h> | 7 #include <time.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <functional> | 10 #include <functional> |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 cancel_ = new views::Link(l10n_util::GetString(IDS_DOWNLOAD_LINK_CANCEL)); | 178 cancel_ = new views::Link(l10n_util::GetString(IDS_DOWNLOAD_LINK_CANCEL)); |
179 cancel_->SetController(this); | 179 cancel_->SetController(this); |
180 cancel_->SetFont(font); | 180 cancel_->SetFont(font); |
181 AddChildView(cancel_); | 181 AddChildView(cancel_); |
182 | 182 |
183 show_ = new views::Link(l10n_util::GetString(IDS_DOWNLOAD_LINK_SHOW)); | 183 show_ = new views::Link(l10n_util::GetString(IDS_DOWNLOAD_LINK_SHOW)); |
184 show_->SetController(this); | 184 show_->SetController(this); |
185 show_->SetFont(font); | 185 show_->SetFont(font); |
186 AddChildView(show_); | 186 AddChildView(show_); |
| 187 |
| 188 SetFocusable(true); |
| 189 |
| 190 SetContextMenuController(this); |
187 } | 191 } |
188 | 192 |
189 DownloadItemTabView::~DownloadItemTabView() { | 193 DownloadItemTabView::~DownloadItemTabView() { |
190 } | 194 } |
191 | 195 |
192 void DownloadItemTabView::SetModel(DownloadItem* model, | 196 void DownloadItemTabView::SetModel(DownloadItem* model, |
193 DownloadTabView* parent) { | 197 DownloadTabView* parent) { |
194 DCHECK(model && parent); | 198 DCHECK(model && parent); |
195 model_ = model; | 199 model_ = model; |
196 parent_ = parent; | 200 parent_ = parent; |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 highlighted_bounds.width(), | 686 highlighted_bounds.width(), |
683 highlighted_bounds.height()); | 687 highlighted_bounds.height()); |
684 | 688 |
685 canvas->DrawFocusRect(highlighted_bounds.x(), | 689 canvas->DrawFocusRect(highlighted_bounds.x(), |
686 highlighted_bounds.y(), | 690 highlighted_bounds.y(), |
687 highlighted_bounds.width(), | 691 highlighted_bounds.width(), |
688 highlighted_bounds.height()); | 692 highlighted_bounds.height()); |
689 } | 693 } |
690 } | 694 } |
691 | 695 |
| 696 bool DownloadItemTabView::CanProcessTabKeyEvents() { |
| 697 return true; |
| 698 } |
| 699 |
| 700 bool DownloadItemTabView::OnKeyPressed(const views::KeyEvent& event) { |
| 701 // When you press DOWN or TAB select the next item in the downloads, otherwise |
| 702 // when you press SHIFT+TAB or UP select the previous item. Note that the |
| 703 // first download index is always in reverse, hence last index. |
| 704 if (event.GetCharacter() == VK_DOWN || (GetKeyState(VK_SHIFT) >= 0 && |
| 705 event.GetCharacter() == VK_TAB)) { |
| 706 parent_->SelectItemAtIndex(parent_->selected_index() - 1); |
| 707 } |
| 708 else if (event.GetCharacter() == VK_UP || (GetKeyState(VK_SHIFT) < 0 && |
| 709 event.GetCharacter() == VK_TAB)) { |
| 710 parent_->SelectItemAtIndex(parent_->selected_index() + 1); |
| 711 } |
| 712 return true; |
| 713 } |
| 714 |
692 bool DownloadItemTabView::OnMousePressed(const views::MouseEvent& event) { | 715 bool DownloadItemTabView::OnMousePressed(const views::MouseEvent& event) { |
693 gfx::Point point(event.location()); | 716 gfx::Point point(event.location()); |
694 | 717 |
695 // If the click is in the highlight region, then highlight this download. | 718 // If the click is in the highlight region, then highlight this download. |
696 // Otherwise, remove the highlighting from any download. | 719 // Otherwise, remove the highlighting from any download. |
697 gfx::Rect select_rect( | 720 gfx::Rect select_rect( |
698 kDownloadIconOffset - parent_->big_icon_offset(), | 721 kDownloadIconOffset - parent_->big_icon_offset(), |
699 0, | 722 0, |
700 kDownloadIconOffset - parent_->big_icon_offset() + | 723 kDownloadIconOffset - parent_->big_icon_offset() + |
701 parent_->big_icon_size() + kInfoPadding + kFilenameSize, | 724 parent_->big_icon_size() + kInfoPadding + kFilenameSize, |
702 parent_->big_icon_size()); | 725 parent_->big_icon_size()); |
703 | 726 |
704 // The position of the highlighted region does not take into account the | 727 // The position of the highlighted region does not take into account the |
705 // View's UI layout so we have to manually mirror the position if the View is | 728 // View's UI layout so we have to manually mirror the position if the View is |
706 // using a right-to-left UI layout. | 729 // using a right-to-left UI layout. |
707 gfx::Rect mirrored_rect(select_rect); | 730 gfx::Rect mirrored_rect(select_rect); |
708 select_rect.set_x(MirroredLeftPointForRect(mirrored_rect)); | 731 select_rect.set_x(MirroredLeftPointForRect(mirrored_rect)); |
709 if (select_rect.Contains(point)) { | 732 if (select_rect.Contains(point)) { |
| 733 // Request Focus if not present to allow keyboard events to work and context |
| 734 // menu to function properly. |
| 735 if (!HasFocus()) |
| 736 RequestFocus(); |
| 737 |
710 parent_->ItemBecameSelected(model_); | 738 parent_->ItemBecameSelected(model_); |
711 | 739 |
712 // Don't show the right-click menu if we are prompting the user for a | 740 // Don't show the right-click menu if we are prompting the user for a |
713 // dangerous download. | 741 // dangerous download. |
714 if (event.IsRightMouseButton() && | 742 if (event.IsRightMouseButton() && |
715 model_->safety_state() != DownloadItem::DANGEROUS) { | 743 model_->safety_state() != DownloadItem::DANGEROUS) { |
716 views::View::ConvertPointToScreen(this, &point); | 744 views::View::ConvertPointToScreen(this, &point); |
717 | 745 |
718 download_util::DownloadDestinationContextMenu menu( | 746 download_util::DownloadDestinationContextMenu menu( |
719 model_, GetWidget()->GetHWND(), point.ToPOINT()); | 747 model_, GetWidget()->GetHWND(), point.ToPOINT()); |
720 } | 748 } |
721 } else { | 749 } else { |
722 parent_->ItemBecameSelected(NULL); | 750 parent_->ItemBecameSelected(NULL); |
723 } | 751 } |
724 | 752 |
725 return true; | 753 return true; |
726 } | 754 } |
727 | 755 |
728 // Handle drag (file copy) operations. | 756 // Handle drag (file copy) operations. |
729 bool DownloadItemTabView::OnMouseDragged(const views::MouseEvent& event) { | 757 bool DownloadItemTabView::OnMouseDragged(const views::MouseEvent& event) { |
730 if (model_->state() != DownloadItem::COMPLETE || | 758 if (model_->state() != DownloadItem::COMPLETE || |
731 model_->safety_state() == DownloadItem::DANGEROUS) | 759 model_->safety_state() == DownloadItem::DANGEROUS) |
732 return false; | 760 return false; |
733 | 761 |
734 CPoint point(event.x(), event.y()); | 762 gfx::Point point(event.x(), event.y()); |
735 | 763 |
736 // In order to make sure drag and drop works as expected when the UI is | 764 // In order to make sure drag and drop works as expected when the UI is |
737 // mirrored, we can either flip the mouse X coordinate or flip the X position | 765 // mirrored, we can either flip the mouse X coordinate or flip the X position |
738 // of the drag rectangle. Flipping the mouse X coordinate is easier. | 766 // of the drag rectangle. Flipping the mouse X coordinate is easier. |
739 point.x = MirroredXCoordinateInsideView(point.x); | 767 point.set_x(MirroredXCoordinateInsideView(point.x())); |
740 CRect drag_rect(kDownloadIconOffset - | 768 gfx::Rect drag_rect(kDownloadIconOffset - |
741 parent_->big_icon_offset(), | 769 parent_->big_icon_offset(), |
742 0, | 770 0, |
743 kDownloadIconOffset - | 771 kDownloadIconOffset - |
744 parent_->big_icon_offset() + | 772 parent_->big_icon_offset() + |
745 parent_->big_icon_size() + kInfoPadding + | 773 parent_->big_icon_size() + kInfoPadding + |
746 kFilenameSize, | 774 kFilenameSize, |
747 parent_->big_icon_size()); | 775 parent_->big_icon_size()); |
748 | 776 |
749 if (drag_rect.PtInRect(point)) { | 777 if (drag_rect.Contains(point)) { |
750 SkBitmap* icon = parent_->LookupIcon(model_); | 778 SkBitmap* icon = parent_->LookupIcon(model_); |
751 if (icon) | 779 if (icon) |
752 download_util::DragDownload(model_, icon); | 780 download_util::DragDownload(model_, icon); |
753 } | 781 } |
754 | 782 |
755 return true; | 783 return true; |
756 } | 784 } |
757 | 785 |
| 786 void DownloadItemTabView::ShowContextMenu(View* source, |
| 787 int x, |
| 788 int y, |
| 789 bool is_mouse_gesture) { |
| 790 // Only show context menu when an item has been selected. |
| 791 if (parent_->selected_index() != -1) { |
| 792 gfx::Point location (x, y); |
| 793 download_util::DownloadDestinationContextMenu menu( |
| 794 model_, GetWidget()->GetHWND(), location.ToPOINT()); |
| 795 } |
| 796 } |
| 797 |
758 void DownloadItemTabView::LinkActivated(views::Link* source, int event_flags) { | 798 void DownloadItemTabView::LinkActivated(views::Link* source, int event_flags) { |
759 // There are several links in our view that could have been clicked: | 799 // There are several links in our view that could have been clicked: |
760 if (source == file_name_) { | 800 if (source == file_name_) { |
761 views::Widget* widget = this->GetWidget(); | 801 views::Widget* widget = this->GetWidget(); |
762 HWND parent_window = widget ? widget->GetHWND() : NULL; | 802 HWND parent_window = widget ? widget->GetHWND() : NULL; |
763 model_->manager()->OpenDownloadInShell(model_, parent_window); | 803 model_->manager()->OpenDownloadInShell(model_, parent_window); |
764 } else if (source == pause_) { | 804 } else if (source == pause_) { |
765 model_->TogglePause(); | 805 model_->TogglePause(); |
766 } else if (source == cancel_) { | 806 } else if (source == cancel_) { |
767 model_->Cancel(true /* update history service */); | 807 model_->Cancel(true /* update history service */); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 | 1209 |
1170 bool DownloadTabView::ItemIsSelected(DownloadItem* download) { | 1210 bool DownloadTabView::ItemIsSelected(DownloadItem* download) { |
1171 OrderedDownloads::iterator it = find(downloads_.begin(), | 1211 OrderedDownloads::iterator it = find(downloads_.begin(), |
1172 downloads_.end(), | 1212 downloads_.end(), |
1173 download); | 1213 download); |
1174 if (it != downloads_.end()) | 1214 if (it != downloads_.end()) |
1175 return selected_index_ == static_cast<int>(it - downloads_.begin()); | 1215 return selected_index_ == static_cast<int>(it - downloads_.begin()); |
1176 return false; | 1216 return false; |
1177 } | 1217 } |
1178 | 1218 |
| 1219 void DownloadTabView::SelectItemAtIndex(int index) { |
| 1220 if (selected_index() == -1) |
| 1221 ItemBecameSelected(downloads_[total_downloads() - 1]); |
| 1222 else if (index >= 0 && index < total_downloads()) |
| 1223 ItemBecameSelected(downloads_[index]); |
| 1224 } |
| 1225 |
1179 void DownloadTabView::SchedulePaintForViewAtIndex(int index) { | 1226 void DownloadTabView::SchedulePaintForViewAtIndex(int index) { |
1180 int y = GetYPositionForIndex(index); | 1227 int y = GetYPositionForIndex(index); |
1181 SchedulePaint(0, y, width(), big_icon_size_); | 1228 SchedulePaint(0, y, width(), big_icon_size_); |
1182 } | 1229 } |
1183 | 1230 |
1184 int DownloadTabView::GetYPositionForIndex(int index) { | 1231 int DownloadTabView::GetYPositionForIndex(int index) { |
1185 int row = static_cast<int>(downloads_.size()) - 1 - index; | 1232 int row = static_cast<int>(downloads_.size()) - 1 - index; |
1186 return row * (big_icon_size_ + kSpacer) + kSpacer; | 1233 return row * (big_icon_size_ + kSpacer) + kSpacer; |
1187 } | 1234 } |
1188 | 1235 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1326 case NOTIFY_DOWNLOAD_STOP: | 1373 case NOTIFY_DOWNLOAD_STOP: |
1327 DCHECK(profile()->HasCreatedDownloadManager()); | 1374 DCHECK(profile()->HasCreatedDownloadManager()); |
1328 contents_->SetIsLoading( | 1375 contents_->SetIsLoading( |
1329 profile()->GetDownloadManager()->in_progress_count() > 0, | 1376 profile()->GetDownloadManager()->in_progress_count() > 0, |
1330 NULL); | 1377 NULL); |
1331 break; | 1378 break; |
1332 default: | 1379 default: |
1333 break; | 1380 break; |
1334 } | 1381 } |
1335 } | 1382 } |
OLD | NEW |