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/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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } // namespace | 86 } // namespace |
87 | 87 |
88 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent) | 88 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent) |
89 : browser_(browser), | 89 : browser_(browser), |
90 parent_(parent), | 90 parent_(parent), |
91 ALLOW_THIS_IN_INITIALIZER_LIST( | 91 ALLOW_THIS_IN_INITIALIZER_LIST( |
92 mouse_watcher_(this, this, gfx::Insets())) { | 92 mouse_watcher_(this, this, gfx::Insets())) { |
93 mouse_watcher_.set_notify_on_exit_time_ms(kNotifyOnExitTimeMS); | 93 mouse_watcher_.set_notify_on_exit_time_ms(kNotifyOnExitTimeMS); |
94 set_id(VIEW_ID_DOWNLOAD_SHELF); | 94 set_id(VIEW_ID_DOWNLOAD_SHELF); |
95 parent->AddChildView(this); | 95 parent->AddChildView(this); |
96 Init(); | 96 Show(); |
97 } | 97 } |
98 | 98 |
99 DownloadShelfView::~DownloadShelfView() { | 99 DownloadShelfView::~DownloadShelfView() { |
100 parent_->RemoveChildView(this); | 100 parent_->RemoveChildView(this); |
101 } | 101 } |
102 | 102 |
103 void DownloadShelfView::Init() { | |
104 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); | |
105 arrow_image_ = new views::ImageView(); | |
106 arrow_image_->SetImage(rb.GetBitmapNamed(IDR_DOWNLOADS_FAVICON)); | |
107 AddChildView(arrow_image_); | |
108 | |
109 show_all_view_ = new views::Link( | |
110 l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS)); | |
111 show_all_view_->set_listener(this); | |
112 AddChildView(show_all_view_); | |
113 | |
114 close_button_ = new views::ImageButton(this); | |
115 close_button_->SetImage(views::CustomButton::BS_NORMAL, | |
116 rb.GetBitmapNamed(IDR_CLOSE_BAR)); | |
117 close_button_->SetImage(views::CustomButton::BS_HOT, | |
118 rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); | |
119 close_button_->SetImage(views::CustomButton::BS_PUSHED, | |
120 rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); | |
121 close_button_->SetAccessibleName( | |
122 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | |
123 UpdateButtonColors(); | |
124 AddChildView(close_button_); | |
125 | |
126 new_item_animation_.reset(new ui::SlideAnimation(this)); | |
127 new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs); | |
128 | |
129 shelf_animation_.reset(new ui::SlideAnimation(this)); | |
130 shelf_animation_->SetSlideDuration(kShelfAnimationDurationMs); | |
131 Show(); | |
132 } | |
133 | |
134 void DownloadShelfView::AddDownloadView(DownloadItemView* view) { | 103 void DownloadShelfView::AddDownloadView(DownloadItemView* view) { |
135 mouse_watcher_.Stop(); | 104 mouse_watcher_.Stop(); |
136 | 105 |
137 Show(); | 106 Show(); |
138 | 107 |
139 DCHECK(view); | 108 DCHECK(view); |
140 download_views_.push_back(view); | 109 download_views_.push_back(view); |
141 AddChildView(view); | 110 AddChildView(view); |
142 if (download_views_.size() > kMaxDownloadViews) | 111 if (download_views_.size() > kMaxDownloadViews) |
143 RemoveDownloadView(*download_views_.begin()); | 112 RemoveDownloadView(*download_views_.begin()); |
(...skipping 29 matching lines...) Expand all Loading... |
173 delete view; | 142 delete view; |
174 if (download_views_.empty()) | 143 if (download_views_.empty()) |
175 Close(); | 144 Close(); |
176 else if (CanAutoClose()) | 145 else if (CanAutoClose()) |
177 mouse_watcher_.Start(); | 146 mouse_watcher_.Start(); |
178 Layout(); | 147 Layout(); |
179 SchedulePaint(); | 148 SchedulePaint(); |
180 } | 149 } |
181 | 150 |
182 views::View* DownloadShelfView::GetDefaultFocusableChild() { | 151 views::View* DownloadShelfView::GetDefaultFocusableChild() { |
183 if (!download_views_.empty()) | 152 return download_views_.empty() ? |
184 return download_views_[0]; | 153 static_cast<View*>(show_all_view_) : download_views_[0]; |
185 else | |
186 return show_all_view_; | |
187 } | 154 } |
188 | 155 |
189 void DownloadShelfView::OnPaint(gfx::Canvas* canvas) { | 156 void DownloadShelfView::OnPaint(gfx::Canvas* canvas) { |
190 OnPaintBackground(canvas); | 157 OnPaintBackground(canvas); |
191 OnPaintBorder(canvas); | 158 OnPaintBorder(canvas); |
192 | 159 |
193 // Draw the focus rect here, since it's outside the bounds of the item. | 160 // Draw the focus rect here, since it's outside the bounds of the item. |
194 for (size_t i = 0; i < download_views_.size(); ++i) { | 161 for (size_t i = 0; i < download_views_.size(); ++i) { |
195 if (download_views_[i]->HasFocus()) { | 162 if (download_views_[i]->HasFocus()) { |
196 gfx::Rect r = GetFocusRectBounds(download_views_[i]); | 163 gfx::Rect r = GetFocusRectBounds(download_views_[i]); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 211 |
245 void DownloadShelfView::AnimationEnded(const ui::Animation *animation) { | 212 void DownloadShelfView::AnimationEnded(const ui::Animation *animation) { |
246 if (animation == shelf_animation_.get()) { | 213 if (animation == shelf_animation_.get()) { |
247 parent_->SetDownloadShelfVisible(shelf_animation_->IsShowing()); | 214 parent_->SetDownloadShelfVisible(shelf_animation_->IsShowing()); |
248 if (!shelf_animation_->IsShowing()) | 215 if (!shelf_animation_->IsShowing()) |
249 Closed(); | 216 Closed(); |
250 } | 217 } |
251 } | 218 } |
252 | 219 |
253 void DownloadShelfView::Layout() { | 220 void DownloadShelfView::Layout() { |
254 // Now that we know we have a parent, we can safely set our theme colors. | |
255 show_all_view_->SetColor( | |
256 GetThemeProvider()->GetColor(ThemeService::COLOR_BOOKMARK_TEXT)); | |
257 set_background(views::Background::CreateSolidBackground( | |
258 GetThemeProvider()->GetColor(ThemeService::COLOR_TOOLBAR))); | |
259 | |
260 // Let our base class layout our child views | 221 // Let our base class layout our child views |
261 views::View::Layout(); | 222 views::View::Layout(); |
262 | 223 |
263 // If there is not enough room to show the first download item, show the | 224 // If there is not enough room to show the first download item, show the |
264 // "Show all downloads" link to the left to make it more visible that there is | 225 // "Show all downloads" link to the left to make it more visible that there is |
265 // something to see. | 226 // something to see. |
266 bool show_link_only = !CanFitFirstDownloadItem(); | 227 bool show_link_only = !CanFitFirstDownloadItem(); |
267 | 228 |
268 gfx::Size image_size = arrow_image_->GetPreferredSize(); | 229 gfx::Size image_size = arrow_image_->GetPreferredSize(); |
269 gfx::Size close_button_size = close_button_->GetPreferredSize(); | 230 gfx::Size close_button_size = close_button_->GetPreferredSize(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 if (next_x < max_download_x) { | 281 if (next_x < max_download_x) { |
321 (*ri)->SetVisible(true); | 282 (*ri)->SetVisible(true); |
322 (*ri)->SetBounds(x, CenterPosition(view_size.height(), height()), | 283 (*ri)->SetBounds(x, CenterPosition(view_size.height(), height()), |
323 item_width, view_size.height()); | 284 item_width, view_size.height()); |
324 } else { | 285 } else { |
325 (*ri)->SetVisible(false); | 286 (*ri)->SetVisible(false); |
326 } | 287 } |
327 } | 288 } |
328 } | 289 } |
329 | 290 |
| 291 void DownloadShelfView::ViewHierarchyChanged(bool is_add, |
| 292 View* parent, |
| 293 View* child) { |
| 294 View::ViewHierarchyChanged(is_add, parent, child); |
| 295 |
| 296 if (is_add && (child == this)) { |
| 297 set_background(views::Background::CreateSolidBackground( |
| 298 GetThemeProvider()->GetColor(ThemeService::COLOR_TOOLBAR))); |
| 299 |
| 300 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 301 arrow_image_ = new views::ImageView(); |
| 302 arrow_image_->SetImage(rb.GetBitmapNamed(IDR_DOWNLOADS_FAVICON)); |
| 303 AddChildView(arrow_image_); |
| 304 |
| 305 show_all_view_ = new views::Link( |
| 306 l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS)); |
| 307 show_all_view_->set_listener(this); |
| 308 show_all_view_->SetBackgroundColor(background()->get_color()); |
| 309 show_all_view_->SetEnabledColor( |
| 310 GetThemeProvider()->GetColor(ThemeService::COLOR_BOOKMARK_TEXT)); |
| 311 AddChildView(show_all_view_); |
| 312 |
| 313 close_button_ = new views::ImageButton(this); |
| 314 close_button_->SetImage(views::CustomButton::BS_NORMAL, |
| 315 rb.GetBitmapNamed(IDR_CLOSE_BAR)); |
| 316 close_button_->SetImage(views::CustomButton::BS_HOT, |
| 317 rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); |
| 318 close_button_->SetImage(views::CustomButton::BS_PUSHED, |
| 319 rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); |
| 320 close_button_->SetAccessibleName( |
| 321 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 322 UpdateButtonColors(); |
| 323 AddChildView(close_button_); |
| 324 |
| 325 new_item_animation_.reset(new ui::SlideAnimation(this)); |
| 326 new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs); |
| 327 |
| 328 shelf_animation_.reset(new ui::SlideAnimation(this)); |
| 329 shelf_animation_->SetSlideDuration(kShelfAnimationDurationMs); |
| 330 } |
| 331 } |
| 332 |
330 bool DownloadShelfView::CanFitFirstDownloadItem() { | 333 bool DownloadShelfView::CanFitFirstDownloadItem() { |
331 if (download_views_.empty()) | 334 if (download_views_.empty()) |
332 return true; | 335 return true; |
333 | 336 |
334 gfx::Size image_size = arrow_image_->GetPreferredSize(); | 337 gfx::Size image_size = arrow_image_->GetPreferredSize(); |
335 gfx::Size close_button_size = close_button_->GetPreferredSize(); | 338 gfx::Size close_button_size = close_button_->GetPreferredSize(); |
336 gfx::Size show_all_size = show_all_view_->GetPreferredSize(); | 339 gfx::Size show_all_size = show_all_view_->GetPreferredSize(); |
337 | 340 |
338 // Let's compute the width available for download items, which is the width | 341 // Let's compute the width available for download items, which is the width |
339 // of the shelf minus the "Show all downloads" link, arrow and close button | 342 // of the shelf minus the "Show all downloads" link, arrow and close button |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 const DownloadItemView* download_item_view) { | 447 const DownloadItemView* download_item_view) { |
445 gfx::Rect bounds = download_item_view->bounds(); | 448 gfx::Rect bounds = download_item_view->bounds(); |
446 | 449 |
447 #if defined(TOOLKIT_VIEWS) | 450 #if defined(TOOLKIT_VIEWS) |
448 bounds.set_height(bounds.height() - 1); | 451 bounds.set_height(bounds.height() - 1); |
449 bounds.Offset(0, 3); | 452 bounds.Offset(0, 3); |
450 #endif | 453 #endif |
451 | 454 |
452 return bounds; | 455 return bounds; |
453 } | 456 } |
OLD | NEW |