OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/download_shelf_view.h" | 5 #include "chrome/browser/ui/views/download/download_shelf_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 DownloadShelfView::~DownloadShelfView() { | 108 DownloadShelfView::~DownloadShelfView() { |
109 parent_->RemoveChildView(this); | 109 parent_->RemoveChildView(this); |
110 } | 110 } |
111 | 111 |
112 void DownloadShelfView::AddDownloadView(DownloadItemView* view) { | 112 void DownloadShelfView::AddDownloadView(DownloadItemView* view) { |
113 mouse_watcher_.Stop(); | 113 mouse_watcher_.Stop(); |
114 | 114 |
115 DCHECK(view); | 115 DCHECK(view); |
116 download_views_.push_back(view); | 116 download_views_.push_back(view); |
117 AddChildView(view); | 117 |
| 118 // Insert the new view as the first child, so the logical child order matches |
| 119 // the visual order. This ensures that tabbing through downloads happens in |
| 120 // the order users would expect. |
| 121 AddChildViewAt(view, 0); |
118 if (download_views_.size() > kMaxDownloadViews) | 122 if (download_views_.size() > kMaxDownloadViews) |
119 RemoveDownloadView(*download_views_.begin()); | 123 RemoveDownloadView(*download_views_.begin()); |
120 | 124 |
121 new_item_animation_->Reset(); | 125 new_item_animation_->Reset(); |
122 new_item_animation_->Show(); | 126 new_item_animation_->Show(); |
123 } | 127 } |
124 | 128 |
125 void DownloadShelfView::DoAddDownload(DownloadItem* download) { | 129 void DownloadShelfView::DoAddDownload(DownloadItem* download) { |
126 DownloadItemView* view = new DownloadItemView(download, this); | 130 DownloadItemView* view = new DownloadItemView(download, this); |
127 AddDownloadView(view); | 131 AddDownloadView(view); |
(...skipping 14 matching lines...) Expand all Loading... |
142 if (download_views_.empty()) | 146 if (download_views_.empty()) |
143 Close(AUTOMATIC); | 147 Close(AUTOMATIC); |
144 else if (CanAutoClose()) | 148 else if (CanAutoClose()) |
145 mouse_watcher_.Start(); | 149 mouse_watcher_.Start(); |
146 Layout(); | 150 Layout(); |
147 SchedulePaint(); | 151 SchedulePaint(); |
148 } | 152 } |
149 | 153 |
150 views::View* DownloadShelfView::GetDefaultFocusableChild() { | 154 views::View* DownloadShelfView::GetDefaultFocusableChild() { |
151 return download_views_.empty() ? | 155 return download_views_.empty() ? |
152 static_cast<View*>(show_all_view_) : download_views_[0]; | 156 static_cast<View*>(show_all_view_) : download_views_.back(); |
153 } | 157 } |
154 | 158 |
155 void DownloadShelfView::OnPaintBorder(gfx::Canvas* canvas) { | 159 void DownloadShelfView::OnPaintBorder(gfx::Canvas* canvas) { |
156 canvas->FillRect(gfx::Rect(0, 0, width(), 1), kBorderColor); | 160 canvas->FillRect(gfx::Rect(0, 0, width(), 1), kBorderColor); |
157 } | 161 } |
158 | 162 |
159 void DownloadShelfView::OpenedDownload(DownloadItemView* view) { | 163 void DownloadShelfView::OpenedDownload(DownloadItemView* view) { |
160 if (CanAutoClose()) | 164 if (CanAutoClose()) |
161 mouse_watcher_.Start(); | 165 mouse_watcher_.Start(); |
162 } | 166 } |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 } | 418 } |
415 } | 419 } |
416 | 420 |
417 bool DownloadShelfView::CanAutoClose() { | 421 bool DownloadShelfView::CanAutoClose() { |
418 for (size_t i = 0; i < download_views_.size(); ++i) { | 422 for (size_t i = 0; i < download_views_.size(); ++i) { |
419 if (!download_views_[i]->download()->GetOpened()) | 423 if (!download_views_[i]->download()->GetOpened()) |
420 return false; | 424 return false; |
421 } | 425 } |
422 return true; | 426 return true; |
423 } | 427 } |
OLD | NEW |