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

Side by Side Diff: chrome/browser/ui/views/download/download_shelf_view.cc

Issue 12995025: [Mac] DownloadShelf should be notified when autoclosing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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
OLDNEW
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 int CenterPosition(int size, int target_size) { 88 int CenterPosition(int size, int target_size) {
89 return std::max((target_size - size) / 2, kTopBottomPadding); 89 return std::max((target_size - size) / 2, kTopBottomPadding);
90 } 90 }
91 91
92 } // namespace 92 } // namespace
93 93
94 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent) 94 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent)
95 : browser_(browser), 95 : browser_(browser),
96 parent_(parent), 96 parent_(parent),
97 auto_closed_(true),
98 ALLOW_THIS_IN_INITIALIZER_LIST( 97 ALLOW_THIS_IN_INITIALIZER_LIST(
99 mouse_watcher_(new views::MouseWatcherViewHost(this, gfx::Insets()), 98 mouse_watcher_(new views::MouseWatcherViewHost(this, gfx::Insets()),
100 this)) { 99 this)) {
101 mouse_watcher_.set_notify_on_exit_time( 100 mouse_watcher_.set_notify_on_exit_time(
102 base::TimeDelta::FromMilliseconds(kNotifyOnExitTimeMS)); 101 base::TimeDelta::FromMilliseconds(kNotifyOnExitTimeMS));
103 set_id(VIEW_ID_DOWNLOAD_SHELF); 102 set_id(VIEW_ID_DOWNLOAD_SHELF);
104 parent->AddChildView(this); 103 parent->AddChildView(this);
105 } 104 }
106 105
107 DownloadShelfView::~DownloadShelfView() { 106 DownloadShelfView::~DownloadShelfView() {
(...skipping 12 matching lines...) Expand all
120 new_item_animation_->Reset(); 119 new_item_animation_->Reset();
121 new_item_animation_->Show(); 120 new_item_animation_->Show();
122 } 121 }
123 122
124 void DownloadShelfView::DoAddDownload(DownloadItem* download) { 123 void DownloadShelfView::DoAddDownload(DownloadItem* download) {
125 DownloadItemView* view = new DownloadItemView(download, this); 124 DownloadItemView* view = new DownloadItemView(download, this);
126 AddDownloadView(view); 125 AddDownloadView(view);
127 } 126 }
128 127
129 void DownloadShelfView::MouseMovedOutOfHost() { 128 void DownloadShelfView::MouseMovedOutOfHost() {
130 Close(); 129 Close(AUTOMATIC);
131 } 130 }
132 131
133 void DownloadShelfView::OnWillChangeFocus(views::View* focused_before, 132 void DownloadShelfView::OnWillChangeFocus(views::View* focused_before,
134 views::View* focused_now) { 133 views::View* focused_now) {
135 SchedulePaintForDownloadItem(focused_before); 134 SchedulePaintForDownloadItem(focused_before);
136 SchedulePaintForDownloadItem(focused_now); 135 SchedulePaintForDownloadItem(focused_now);
137 } 136 }
138 137
139 void DownloadShelfView::OnDidChangeFocus(views::View* focused_before, 138 void DownloadShelfView::OnDidChangeFocus(views::View* focused_before,
140 views::View* focused_now) { 139 views::View* focused_now) {
141 AccessiblePaneView::OnDidChangeFocus(focused_before, focused_now); 140 AccessiblePaneView::OnDidChangeFocus(focused_before, focused_now);
142 } 141 }
143 142
144 void DownloadShelfView::RemoveDownloadView(View* view) { 143 void DownloadShelfView::RemoveDownloadView(View* view) {
145 DCHECK(view); 144 DCHECK(view);
146 std::vector<DownloadItemView*>::iterator i = 145 std::vector<DownloadItemView*>::iterator i =
147 find(download_views_.begin(), download_views_.end(), view); 146 find(download_views_.begin(), download_views_.end(), view);
148 DCHECK(i != download_views_.end()); 147 DCHECK(i != download_views_.end());
149 download_views_.erase(i); 148 download_views_.erase(i);
150 RemoveChildView(view); 149 RemoveChildView(view);
151 delete view; 150 delete view;
152 if (download_views_.empty()) 151 if (download_views_.empty())
153 Close(); 152 Close(AUTOMATIC);
154 else if (CanAutoClose()) 153 else if (CanAutoClose())
155 mouse_watcher_.Start(); 154 mouse_watcher_.Start();
156 Layout(); 155 Layout();
157 SchedulePaint(); 156 SchedulePaint();
158 } 157 }
159 158
160 views::View* DownloadShelfView::GetDefaultFocusableChild() { 159 views::View* DownloadShelfView::GetDefaultFocusableChild() {
161 return download_views_.empty() ? 160 return download_views_.empty() ?
162 static_cast<View*>(show_all_view_) : download_views_[0]; 161 static_cast<View*>(show_all_view_) : download_views_[0];
163 } 162 }
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 void DownloadShelfView::OnThemeChanged() { 377 void DownloadShelfView::OnThemeChanged() {
379 UpdateColorsFromTheme(); 378 UpdateColorsFromTheme();
380 } 379 }
381 380
382 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) { 381 void DownloadShelfView::LinkClicked(views::Link* source, int event_flags) {
383 chrome::ShowDownloads(browser_); 382 chrome::ShowDownloads(browser_);
384 } 383 }
385 384
386 void DownloadShelfView::ButtonPressed( 385 void DownloadShelfView::ButtonPressed(
387 views::Button* button, const ui::Event& event) { 386 views::Button* button, const ui::Event& event) {
388 auto_closed_ = false; 387 Close(USER_ACTION);
389 Close();
390 } 388 }
391 389
392 bool DownloadShelfView::IsShowing() const { 390 bool DownloadShelfView::IsShowing() const {
393 return shelf_animation_->IsShowing(); 391 return shelf_animation_->IsShowing();
394 } 392 }
395 393
396 bool DownloadShelfView::IsClosing() const { 394 bool DownloadShelfView::IsClosing() const {
397 return shelf_animation_->IsClosing(); 395 return shelf_animation_->IsClosing();
398 } 396 }
399 397
400 void DownloadShelfView::DoShow() { 398 void DownloadShelfView::DoShow() {
401 shelf_animation_->Show(); 399 shelf_animation_->Show();
402 } 400 }
403 401
404 void DownloadShelfView::DoClose() { 402 void DownloadShelfView::DoClose(CloseReason reason) {
405 int num_in_progress = 0; 403 int num_in_progress = 0;
406 for (size_t i = 0; i < download_views_.size(); ++i) { 404 for (size_t i = 0; i < download_views_.size(); ++i) {
407 if (download_views_[i]->download()->IsInProgress()) 405 if (download_views_[i]->download()->IsInProgress())
408 ++num_in_progress; 406 ++num_in_progress;
409 } 407 }
410 download_util::RecordShelfClose( 408 download_util::RecordShelfClose(download_views_.size(),
411 download_views_.size(), num_in_progress, auto_closed_); 409 num_in_progress,
410 (reason == AUTOMATIC));
Nico 2013/03/22 20:24:11 ditto
asanka 2013/03/22 21:22:13 Done.
412 parent_->SetDownloadShelfVisible(false); 411 parent_->SetDownloadShelfVisible(false);
413 shelf_animation_->Hide(); 412 shelf_animation_->Hide();
414 auto_closed_ = true;
415 } 413 }
416 414
417 Browser* DownloadShelfView::browser() const { 415 Browser* DownloadShelfView::browser() const {
418 return browser_; 416 return browser_;
419 } 417 }
420 418
421 void DownloadShelfView::Closed() { 419 void DownloadShelfView::Closed() {
422 // Don't remove completed downloads if the shelf is just being auto-hidden 420 // Don't remove completed downloads if the shelf is just being auto-hidden
423 // rather than explicitly closed by the user. 421 // rather than explicitly closed by the user.
424 if (is_hidden()) 422 if (is_hidden())
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 const DownloadItemView* download_item_view) { 471 const DownloadItemView* download_item_view) {
474 gfx::Rect bounds = download_item_view->bounds(); 472 gfx::Rect bounds = download_item_view->bounds();
475 473
476 #if defined(TOOLKIT_VIEWS) 474 #if defined(TOOLKIT_VIEWS)
477 bounds.set_height(bounds.height() - 1); 475 bounds.set_height(bounds.height() - 1);
478 bounds.Offset(0, 3); 476 bounds.Offset(0, 3);
479 #endif 477 #endif
480 478
481 return bounds; 479 return bounds;
482 } 480 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698