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

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

Issue 9309110: Refactored MouseWatcher to allow regions other than Views to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor cleanup Created 8 years, 10 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 12 matching lines...) Expand all
23 #include "grit/theme_resources_standard.h" 23 #include "grit/theme_resources_standard.h"
24 #include "grit/ui_resources_standard.h" 24 #include "grit/ui_resources_standard.h"
25 #include "ui/base/animation/slide_animation.h" 25 #include "ui/base/animation/slide_animation.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/gfx/canvas.h" 28 #include "ui/gfx/canvas.h"
29 #include "ui/views/background.h" 29 #include "ui/views/background.h"
30 #include "ui/views/controls/button/image_button.h" 30 #include "ui/views/controls/button/image_button.h"
31 #include "ui/views/controls/image_view.h" 31 #include "ui/views/controls/image_view.h"
32 #include "ui/views/controls/link.h" 32 #include "ui/views/controls/link.h"
33 #include "ui/views/mouse_watcher_view_host.h"
33 34
34 // Max number of download views we'll contain. Any time a view is added and 35 // Max number of download views we'll contain. Any time a view is added and
35 // we already have this many download views, one is removed. 36 // we already have this many download views, one is removed.
36 static const size_t kMaxDownloadViews = 15; 37 static const size_t kMaxDownloadViews = 15;
37 38
38 // Padding from left edge and first download view. 39 // Padding from left edge and first download view.
39 static const int kLeftPadding = 2; 40 static const int kLeftPadding = 2;
40 41
41 // Padding from right edge and close button/show downloads link. 42 // Padding from right edge and close button/show downloads link.
42 static const int kRightPadding = 10; 43 static const int kRightPadding = 10;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return std::max((target_size - size) / 2, kTopBottomPadding); 87 return std::max((target_size - size) / 2, kTopBottomPadding);
87 } 88 }
88 89
89 } // namespace 90 } // namespace
90 91
91 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent) 92 DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent)
92 : browser_(browser), 93 : browser_(browser),
93 parent_(parent), 94 parent_(parent),
94 auto_closed_(true), 95 auto_closed_(true),
95 ALLOW_THIS_IN_INITIALIZER_LIST( 96 ALLOW_THIS_IN_INITIALIZER_LIST(
96 mouse_watcher_(this, this, gfx::Insets())) { 97 mouse_watcher_(new views::MouseWatcherViewHost(this, gfx::Insets()),
98 this)) {
97 mouse_watcher_.set_notify_on_exit_time_ms(kNotifyOnExitTimeMS); 99 mouse_watcher_.set_notify_on_exit_time_ms(kNotifyOnExitTimeMS);
98 set_id(VIEW_ID_DOWNLOAD_SHELF); 100 set_id(VIEW_ID_DOWNLOAD_SHELF);
99 parent->AddChildView(this); 101 parent->AddChildView(this);
100 } 102 }
101 103
102 DownloadShelfView::~DownloadShelfView() { 104 DownloadShelfView::~DownloadShelfView() {
103 parent_->RemoveChildView(this); 105 parent_->RemoveChildView(this);
104 } 106 }
105 107
106 void DownloadShelfView::AddDownloadView(DownloadItemView* view) { 108 void DownloadShelfView::AddDownloadView(DownloadItemView* view) {
107 mouse_watcher_.Stop(); 109 mouse_watcher_.Stop();
108 110
109 DCHECK(view); 111 DCHECK(view);
110 download_views_.push_back(view); 112 download_views_.push_back(view);
111 AddChildView(view); 113 AddChildView(view);
112 if (download_views_.size() > kMaxDownloadViews) 114 if (download_views_.size() > kMaxDownloadViews)
113 RemoveDownloadView(*download_views_.begin()); 115 RemoveDownloadView(*download_views_.begin());
114 116
115 new_item_animation_->Reset(); 117 new_item_animation_->Reset();
116 new_item_animation_->Show(); 118 new_item_animation_->Show();
117 } 119 }
118 120
119 void DownloadShelfView::DoAddDownload(BaseDownloadItemModel* download_model) { 121 void DownloadShelfView::DoAddDownload(BaseDownloadItemModel* download_model) {
120 DownloadItemView* view = new DownloadItemView( 122 DownloadItemView* view = new DownloadItemView(
121 download_model->download(), this, download_model); 123 download_model->download(), this, download_model);
122 AddDownloadView(view); 124 AddDownloadView(view);
123 } 125 }
124 126
125 void DownloadShelfView::MouseMovedOutOfView() { 127 void DownloadShelfView::MouseMovedOutOfHost() {
126 Close(); 128 Close();
127 } 129 }
128 130
129 void DownloadShelfView::OnWillChangeFocus(views::View* focused_before, 131 void DownloadShelfView::OnWillChangeFocus(views::View* focused_before,
130 views::View* focused_now) { 132 views::View* focused_now) {
131 SchedulePaintForDownloadItem(focused_before); 133 SchedulePaintForDownloadItem(focused_before);
132 SchedulePaintForDownloadItem(focused_now); 134 SchedulePaintForDownloadItem(focused_now);
133 } 135 }
134 136
135 void DownloadShelfView::OnDidChangeFocus(views::View* focused_before, 137 void DownloadShelfView::OnDidChangeFocus(views::View* focused_before,
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 const DownloadItemView* download_item_view) { 468 const DownloadItemView* download_item_view) {
467 gfx::Rect bounds = download_item_view->bounds(); 469 gfx::Rect bounds = download_item_view->bounds();
468 470
469 #if defined(TOOLKIT_VIEWS) 471 #if defined(TOOLKIT_VIEWS)
470 bounds.set_height(bounds.height() - 1); 472 bounds.set_height(bounds.height() - 1);
471 bounds.Offset(0, 3); 473 bounds.Offset(0, 3);
472 #endif 474 #endif
473 475
474 return bounds; 476 return bounds;
475 } 477 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698