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

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

Issue 7344: Convert GetPreferredSize from:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 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) 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_shelf_view.h" 5 #include "chrome/browser/views/download_shelf_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "chrome/app/theme/theme_resources.h" 9 #include "chrome/app/theme/theme_resources.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 static const SkColor kBorderColor = SkColorSetRGB(214, 214, 214); 53 static const SkColor kBorderColor = SkColorSetRGB(214, 214, 214);
54 54
55 // New download item animation speed in milliseconds. 55 // New download item animation speed in milliseconds.
56 static const int kNewItemAnimationDurationMs = 800; 56 static const int kNewItemAnimationDurationMs = 800;
57 57
58 // Shelf show/hide speed. 58 // Shelf show/hide speed.
59 static const int kShelfAnimationDurationMs = 120; 59 static const int kShelfAnimationDurationMs = 120;
60 60
61 namespace { 61 namespace {
62 62
63 // Sets size->cx to view's preferred width + size->cx. 63 // Sets size->width() to view's preferred width + size->width().s
64 // Sets size->cy to the max of the view's preferred height and size->cy; 64 // Sets size->height() to the max of the view's preferred height and
65 void AdjustSize(ChromeViews::View* view, CSize* size) { 65 // size->height();
66 CSize view_preferred; 66 void AdjustSize(ChromeViews::View* view, gfx::Size* size) {
67 view->GetPreferredSize(&view_preferred); 67 gfx::Size view_preferred = view->GetPreferredSize();
68 size->cx += view_preferred.cx; 68 size->Enlarge(view_preferred.width(), 0);
Elliot Glaysher 2008/10/15 17:21:46 One general comment: I haven't seen a case yet whe
Ben Goodger (Google) 2008/10/15 17:37:32 OK I tried EnlargeWidth and EnlargeHeight. But I d
69 size->cy = std::max(view_preferred.cy, size->cy); 69 size->set_height(std::max(view_preferred.height(), size->height()));
70 } 70 }
71 71
72 int CenterPosition(int size, int target_size) { 72 int CenterPosition(int size, int target_size) {
73 return std::max((target_size - size) / 2, kTopBottomPadding); 73 return std::max((target_size - size) / 2, kTopBottomPadding);
74 } 74 }
75 75
76 } // namespace 76 } // namespace
77 77
78 DownloadShelfView::DownloadShelfView(TabContents* tab_contents) 78 DownloadShelfView::DownloadShelfView(TabContents* tab_contents)
79 : tab_contents_(tab_contents) { 79 : tab_contents_(tab_contents) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 void DownloadShelfView::Paint(ChromeCanvas* canvas) { 153 void DownloadShelfView::Paint(ChromeCanvas* canvas) {
154 PaintBackground(canvas); 154 PaintBackground(canvas);
155 PaintBorder(canvas); 155 PaintBorder(canvas);
156 } 156 }
157 157
158 void DownloadShelfView::PaintBorder(ChromeCanvas* canvas) { 158 void DownloadShelfView::PaintBorder(ChromeCanvas* canvas) {
159 canvas->FillRectInt(kBorderColor, 0, 0, width(), 1); 159 canvas->FillRectInt(kBorderColor, 0, 0, width(), 1);
160 } 160 }
161 161
162 void DownloadShelfView::GetPreferredSize(CSize *out) { 162 gfx::Size DownloadShelfView::GetPreferredSize() {
163 out->cx = kRightPadding + kLeftPadding + kCloseAndLinkPadding; 163 gfx::Size prefsize(kRightPadding + kLeftPadding + kCloseAndLinkPadding, 0);
164 out->cy = 0; 164 AdjustSize(close_button_, &prefsize);
165 AdjustSize(close_button_, out); 165 AdjustSize(show_all_view_, &prefsize);
166 AdjustSize(show_all_view_, out);
167 // Add one download view to the preferred size. 166 // Add one download view to the preferred size.
168 if (download_views_.size() > 0) { 167 if (download_views_.size() > 0) {
169 AdjustSize(*download_views_.begin(), out); 168 AdjustSize(*download_views_.begin(), &prefsize);
170 out->cx += kDownloadPadding; 169 prefsize.Enlarge(kDownloadPadding, 0);
171 } 170 }
172 out->cy += kTopBottomPadding + kTopBottomPadding; 171 prefsize.Enlarge(0, kTopBottomPadding + kTopBottomPadding);
173 if (shelf_animation_->IsAnimating()) { 172 if (shelf_animation_->IsAnimating()) {
174 out->cy = static_cast<int>(static_cast<double>(out->cy) * 173 prefsize.set_height(static_cast<int>(
175 shelf_animation_->GetCurrentValue()); 174 static_cast<double>(prefsize.height()) *
175 shelf_animation_->GetCurrentValue()));
176 } 176 }
177 return prefsize;
177 } 178 }
178 179
179 void DownloadShelfView::DidChangeBounds(const CRect& previous, 180 void DownloadShelfView::DidChangeBounds(const CRect& previous,
180 const CRect& current) { 181 const CRect& current) {
181 Layout(); 182 Layout();
182 } 183 }
183 184
184 void DownloadShelfView::AnimationProgressed(const Animation *animation) { 185 void DownloadShelfView::AnimationProgressed(const Animation *animation) {
185 if (animation == new_item_animation_.get()) { 186 if (animation == new_item_animation_.get()) {
186 Layout(); 187 Layout();
187 SchedulePaint(); 188 SchedulePaint();
188 } else if (animation == shelf_animation_.get()) { 189 } else if (animation == shelf_animation_.get()) {
189 // Force a re-layout of the parent, which will call back into 190 // Force a re-layout of the parent, which will call back into
190 // GetPreferredSize, where we will do our animation. In the case where the 191 // GetPreferredSize, where we will do our animation. In the case where the
191 // animation is hiding, we do a full resize - the fast resizing would 192 // animation is hiding, we do a full resize - the fast resizing would
192 // otherwise leave blank white areas where the shelf was and where the 193 // otherwise leave blank white areas where the shelf was and where the
193 // user's eye is. Thankfully bottom-resizing is a lot faster than 194 // user's eye is. Thankfully bottom-resizing is a lot faster than
194 // top-resizing. 195 // top-resizing.
195 tab_contents_->ToolbarSizeChanged(shelf_animation_->IsShowing()); 196 tab_contents_->ToolbarSizeChanged(shelf_animation_->IsShowing());
196 } 197 }
197 } 198 }
198 199
199 void DownloadShelfView::AnimationEnded(const Animation *animation) { 200 void DownloadShelfView::AnimationEnded(const Animation *animation) {
200 if (animation == shelf_animation_.get()) { 201 if (animation == shelf_animation_.get()) {
201 tab_contents_->SetDownloadShelfVisible(shelf_animation_->IsShowing()); 202 tab_contents_->SetDownloadShelfVisible(shelf_animation_->IsShowing());
202 } 203 }
203 } 204 }
204 205
205 void DownloadShelfView::Layout() { 206 void DownloadShelfView::Layout() {
206 CSize image_size; 207 gfx::Size image_size = arrow_image_->GetPreferredSize();
207 arrow_image_->GetPreferredSize(&image_size); 208 gfx::Size close_button_size = close_button_->GetPreferredSize();
208 CSize close_button_size; 209 gfx::Size show_all_size = show_all_view_->GetPreferredSize();
209 close_button_->GetPreferredSize(&close_button_size);
210 CSize show_all_size;
211 show_all_view_->GetPreferredSize(&show_all_size);
212 int max_download_x = 210 int max_download_x =
213 std::max<int>(0, width() - kRightPadding - close_button_size.cx - 211 std::max<int>(0, width() - kRightPadding - close_button_size.width() -
214 kCloseAndLinkPadding - show_all_size.cx - 212 kCloseAndLinkPadding - show_all_size.width() -
215 image_size.cx - kDownloadPadding); 213 image_size.width() - kDownloadPadding);
216 int next_x = max_download_x + kDownloadPadding; 214 int next_x = max_download_x + kDownloadPadding;
217 // Align vertically with show_all_view_. 215 // Align vertically with show_all_view_.
218 arrow_image_->SetBounds(next_x, CenterPosition(show_all_size.cy, height()), 216 arrow_image_->SetBounds(next_x,
219 image_size.cx, image_size.cy); 217 CenterPosition(show_all_size.height(), height()),
220 next_x += image_size.cx + kDownloadsTitlePadding; 218 image_size.width(), image_size.height());
219 next_x += image_size.width() + kDownloadsTitlePadding;
221 show_all_view_->SetBounds(next_x, 220 show_all_view_->SetBounds(next_x,
222 CenterPosition(show_all_size.cy, height()), 221 CenterPosition(show_all_size.height(), height()),
223 show_all_size.cx, 222 show_all_size.width(),
224 show_all_size.cy); 223 show_all_size.height());
225 next_x += show_all_size.cx + kCloseAndLinkPadding; 224 next_x += show_all_size.width() + kCloseAndLinkPadding;
226 close_button_->SetBounds(next_x, 225 close_button_->SetBounds(next_x,
227 CenterPosition(close_button_size.cy, height()), 226 CenterPosition(close_button_size.height(), height()),
228 close_button_size.cx, 227 close_button_size.width(),
229 close_button_size.cy); 228 close_button_size.height());
230 229
231 next_x = kLeftPadding; 230 next_x = kLeftPadding;
232 std::vector<View*>::reverse_iterator ri; 231 std::vector<View*>::reverse_iterator ri;
233 for (ri = download_views_.rbegin(); ri != download_views_.rend(); ++ri) { 232 for (ri = download_views_.rbegin(); ri != download_views_.rend(); ++ri) {
234 CSize view_size; 233 gfx::Size view_size = (*ri)->GetPreferredSize();
235 (*ri)->GetPreferredSize(&view_size);
236 234
237 int x = next_x; 235 int x = next_x;
238 236
239 // Figure out width of item. 237 // Figure out width of item.
240 int item_width = view_size.cx; 238 int item_width = view_size.width();
241 if (new_item_animation_->IsAnimating() && ri == download_views_.rbegin()) { 239 if (new_item_animation_->IsAnimating() && ri == download_views_.rbegin()) {
242 item_width = static_cast<int>(static_cast<double>(view_size.cx) * 240 item_width = static_cast<int>(static_cast<double>(view_size.width()) *
243 new_item_animation_->GetCurrentValue()); 241 new_item_animation_->GetCurrentValue());
244 } 242 }
245 243
246 next_x += (item_width + kDownloadPadding); 244 next_x += (item_width + kDownloadPadding);
247 245
248 // Make sure our item can be contained within the shelf. 246 // Make sure our item can be contained within the shelf.
249 if (next_x < max_download_x) { 247 if (next_x < max_download_x) {
250 (*ri)->SetVisible(true); 248 (*ri)->SetVisible(true);
251 (*ri)->SetBounds(x, CenterPosition(view_size.cy, height()), item_width, 249 (*ri)->SetBounds(x, CenterPosition(view_size.height(), height()),
252 view_size.cy); 250 item_width, view_size.height());
253 } else { 251 } else {
254 (*ri)->SetVisible(false); 252 (*ri)->SetVisible(false);
255 } 253 }
256 } 254 }
257 } 255 }
258 256
259 // Open the download page. 257 // Open the download page.
260 void DownloadShelfView::LinkActivated(ChromeViews::Link* source, 258 void DownloadShelfView::LinkActivated(ChromeViews::Link* source,
261 int event_flags) { 259 int event_flags) {
262 int index; 260 int index;
263 NavigationController* controller = tab_contents_->controller(); 261 NavigationController* controller = tab_contents_->controller();
264 Browser* browser = Browser::GetBrowserForController(controller, &index); 262 Browser* browser = Browser::GetBrowserForController(controller, &index);
265 DCHECK(browser); 263 DCHECK(browser);
266 browser->ShowNativeUI(DownloadTabUI::GetURL()); 264 browser->ShowNativeUI(DownloadTabUI::GetURL());
267 } 265 }
268 266
269 void DownloadShelfView::ButtonPressed(ChromeViews::BaseButton* button) { 267 void DownloadShelfView::ButtonPressed(ChromeViews::BaseButton* button) {
270 shelf_animation_->Hide(); 268 shelf_animation_->Hide();
271 } 269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698