OLD | NEW |
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_tab_view.h" | 5 #include "chrome/browser/views/download_tab_view.h" |
6 | 6 |
7 #include <time.h> | 7 #include <time.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <functional> | 10 #include <functional> |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 187 } |
188 | 188 |
189 void DownloadItemTabView::SetModel(DownloadItem* model, | 189 void DownloadItemTabView::SetModel(DownloadItem* model, |
190 DownloadTabView* parent) { | 190 DownloadTabView* parent) { |
191 DCHECK(model && parent); | 191 DCHECK(model && parent); |
192 model_ = model; | 192 model_ = model; |
193 parent_ = parent; | 193 parent_ = parent; |
194 parent_->LookupIcon(model_); | 194 parent_->LookupIcon(model_); |
195 } | 195 } |
196 | 196 |
197 void DownloadItemTabView::GetPreferredSize(CSize* out) { | 197 gfx::Size DownloadItemTabView::GetPreferredSize() { |
198 CSize pause_size; | 198 gfx::Size pause_size = pause_->GetPreferredSize(); |
199 pause_->GetPreferredSize(&pause_size); | 199 gfx::Size cancel_size = cancel_->GetPreferredSize(); |
200 CSize cancel_size; | 200 gfx::Size show_size = show_->GetPreferredSize(); |
201 cancel_->GetPreferredSize(&cancel_size); | 201 return gfx::Size( |
202 CSize show_size; | 202 download_util::kBigProgressIconSize + |
203 show_->GetPreferredSize(&show_size); | 203 2 * kSpacer + |
204 | 204 kHorizontalLinkPadding + |
205 out->cx = download_util::kBigProgressIconSize + | 205 kFilenameSize + |
206 2 * kSpacer + | 206 std::max(pause_size.width() + cancel_size.width() + |
207 kHorizontalLinkPadding + | 207 kHorizontalLinkPadding, |
208 kFilenameSize + | 208 show_size.width()), |
209 std::max(pause_size.cx + cancel_size.cx + kHorizontalLinkPadding, | 209 download_util::kBigProgressIconSize); |
210 show_size.cx); | |
211 | |
212 out->cy = download_util::kBigProgressIconSize; | |
213 } | 210 } |
214 | 211 |
215 // Each DownloadItemTabView has reasonably complex layout requirements | 212 // Each DownloadItemTabView has reasonably complex layout requirements |
216 // that are based on the state of its model. To make the code much simpler | 213 // that are based on the state of its model. To make the code much simpler |
217 // to read, Layout() is split into state specific code which will result | 214 // to read, Layout() is split into state specific code which will result |
218 // in some redundant code. | 215 // in some redundant code. |
219 void DownloadItemTabView::Layout() { | 216 void DownloadItemTabView::Layout() { |
220 DCHECK(model_); | 217 DCHECK(model_); |
221 switch (model_->state()) { | 218 switch (model_->state()) { |
222 case DownloadItem::COMPLETE: | 219 case DownloadItem::COMPLETE: |
(...skipping 20 matching lines...) Expand all Loading... |
243 | 240 |
244 // Only display the date if the download is the last that occurred | 241 // Only display the date if the download is the last that occurred |
245 // on a given day. | 242 // on a given day. |
246 void DownloadItemTabView::LayoutDate() { | 243 void DownloadItemTabView::LayoutDate() { |
247 if (!parent_->ShouldDrawDateForDownload(model_)) { | 244 if (!parent_->ShouldDrawDateForDownload(model_)) { |
248 since_->SetVisible(false); | 245 since_->SetVisible(false); |
249 date_->SetVisible(false); | 246 date_->SetVisible(false); |
250 return; | 247 return; |
251 } | 248 } |
252 | 249 |
253 CSize since_size; | |
254 | |
255 since_->SetText(TimeFormat::RelativeDate(model_->start_time(), NULL)); | 250 since_->SetText(TimeFormat::RelativeDate(model_->start_time(), NULL)); |
256 since_->GetPreferredSize(&since_size); | 251 gfx::Size since_size = since_->GetPreferredSize(); |
257 since_->SetBounds(kLeftMargin, download_util::kBigProgressIconOffset, | 252 since_->SetBounds(kLeftMargin, download_util::kBigProgressIconOffset, |
258 kDateSize, since_size.cy); | 253 kDateSize, since_size.height()); |
259 since_->SetVisible(true); | 254 since_->SetVisible(true); |
260 | 255 |
261 CSize date_size; | |
262 date_->SetText(base::TimeFormatShortDate(model_->start_time())); | 256 date_->SetText(base::TimeFormatShortDate(model_->start_time())); |
263 date_->GetPreferredSize(&date_size); | 257 gfx::Size date_size = date_->GetPreferredSize(); |
264 date_->SetBounds(kLeftMargin, since_size.cy + kVerticalPadding + | 258 date_->SetBounds(kLeftMargin, since_size.height() + kVerticalPadding + |
265 download_util::kBigProgressIconOffset, | 259 download_util::kBigProgressIconOffset, |
266 kDateSize, date_size.cy); | 260 kDateSize, date_size.height()); |
267 date_->SetVisible(true); | 261 date_->SetVisible(true); |
268 } | 262 } |
269 | 263 |
270 // DownloadItem::COMPLETE state layout | 264 // DownloadItem::COMPLETE state layout |
271 void DownloadItemTabView::LayoutComplete() { | 265 void DownloadItemTabView::LayoutComplete() { |
272 // Hide unused UI elements | 266 // Hide unused UI elements |
273 pause_->SetVisible(false); | 267 pause_->SetVisible(false); |
274 pause_->SetEnabled(false); | 268 pause_->SetEnabled(false); |
275 cancel_->SetVisible(false); | 269 cancel_->SetVisible(false); |
276 cancel_->SetEnabled(false); | 270 cancel_->SetEnabled(false); |
277 time_remaining_->SetVisible(false); | 271 time_remaining_->SetVisible(false); |
278 download_progress_->SetVisible(false); | 272 download_progress_->SetVisible(false); |
279 dangerous_download_warning_->SetVisible(false); | 273 dangerous_download_warning_->SetVisible(false); |
280 save_button_->SetVisible(false); | 274 save_button_->SetVisible(false); |
281 save_button_->SetEnabled(false); | 275 save_button_->SetEnabled(false); |
282 discard_button_->SetVisible(false); | 276 discard_button_->SetVisible(false); |
283 discard_button_->SetEnabled(false); | 277 discard_button_->SetEnabled(false); |
284 | 278 |
285 LayoutDate(); | 279 LayoutDate(); |
286 int dx = kDownloadIconOffset - download_util::kBigProgressIconOffset + | 280 int dx = kDownloadIconOffset - download_util::kBigProgressIconOffset + |
287 download_util::kBigProgressIconSize + kInfoPadding; | 281 download_util::kBigProgressIconSize + kInfoPadding; |
288 | 282 |
289 // File name and URL | 283 // File name and URL |
290 CSize file_name_size; | |
291 file_name_->SetText(model_->file_name()); | 284 file_name_->SetText(model_->file_name()); |
292 file_name_->GetPreferredSize(&file_name_size); | 285 gfx::Size file_name_size = file_name_->GetPreferredSize(); |
293 file_name_->SetBounds(dx, download_util::kBigProgressIconOffset, | 286 file_name_->SetBounds(dx, download_util::kBigProgressIconOffset, |
294 std::min(kFilenameSize, | 287 std::min(kFilenameSize, |
295 static_cast<int>(file_name_size.cx)), | 288 static_cast<int>(file_name_size.width())), |
296 file_name_size.cy); | 289 file_name_size.height()); |
297 file_name_->SetVisible(true); | 290 file_name_->SetVisible(true); |
298 file_name_->SetEnabled(true); | 291 file_name_->SetEnabled(true); |
299 | 292 |
300 GURL url(model_->url()); | 293 GURL url(model_->url()); |
301 download_url_->SetURL(url); | 294 download_url_->SetURL(url); |
302 CSize url_size; | 295 gfx::Size url_size = download_url_->GetPreferredSize(); |
303 download_url_->GetPreferredSize(&url_size); | |
304 download_url_->SetBounds(dx, | 296 download_url_->SetBounds(dx, |
305 file_name_size.cy + kVerticalPadding + | 297 file_name_size.height() + kVerticalPadding + |
306 download_util::kBigProgressIconOffset, | 298 download_util::kBigProgressIconOffset, |
307 std::min(kFilenameSize, | 299 std::min(kFilenameSize, |
308 static_cast<int>(width() - dx)), | 300 static_cast<int>(width() - dx)), |
309 url_size.cy); | 301 url_size.height()); |
310 download_url_->SetVisible(true); | 302 download_url_->SetVisible(true); |
311 dx += kFilenameSize + kSpacer; | 303 dx += kFilenameSize + kSpacer; |
312 | 304 |
313 // Action button (text is constant and set in constructor) | 305 // Action button (text is constant and set in constructor) |
314 CSize show_size; | 306 gfx::Size show_size = show_->GetPreferredSize(); |
315 show_->GetPreferredSize(&show_size); | 307 show_->SetBounds(dx, ((file_name_size.height() + url_size.height()) / 2) + |
316 show_->SetBounds(dx, ((file_name_size.cy + url_size.cy) / 2) + | |
317 download_util::kBigProgressIconOffset, | 308 download_util::kBigProgressIconOffset, |
318 show_size.cx, show_size.cy); | 309 show_size.width(), show_size.height()); |
319 show_->SetVisible(true); | 310 show_->SetVisible(true); |
320 show_->SetEnabled(true); | 311 show_->SetEnabled(true); |
321 } | 312 } |
322 | 313 |
323 // DownloadItem::CANCELLED state layout | 314 // DownloadItem::CANCELLED state layout |
324 void DownloadItemTabView::LayoutCancelled() { | 315 void DownloadItemTabView::LayoutCancelled() { |
325 // Hide unused UI elements | 316 // Hide unused UI elements |
326 show_->SetVisible(false); | 317 show_->SetVisible(false); |
327 show_->SetEnabled(false); | 318 show_->SetEnabled(false); |
328 pause_->SetVisible(false); | 319 pause_->SetVisible(false); |
329 pause_->SetEnabled(false); | 320 pause_->SetEnabled(false); |
330 cancel_->SetVisible(false); | 321 cancel_->SetVisible(false); |
331 cancel_->SetEnabled(false); | 322 cancel_->SetEnabled(false); |
332 dangerous_download_warning_->SetVisible(false); | 323 dangerous_download_warning_->SetVisible(false); |
333 save_button_->SetVisible(false); | 324 save_button_->SetVisible(false); |
334 save_button_->SetEnabled(false); | 325 save_button_->SetEnabled(false); |
335 discard_button_->SetVisible(false); | 326 discard_button_->SetVisible(false); |
336 discard_button_->SetEnabled(false); | 327 discard_button_->SetEnabled(false); |
337 | 328 |
338 LayoutDate(); | 329 LayoutDate(); |
339 int dx = kDownloadIconOffset - download_util::kBigProgressIconOffset + | 330 int dx = kDownloadIconOffset - download_util::kBigProgressIconOffset + |
340 download_util::kBigProgressIconSize + kInfoPadding; | 331 download_util::kBigProgressIconSize + kInfoPadding; |
341 | 332 |
342 // File name and URL, truncated to show cancelled status | 333 // File name and URL, truncated to show cancelled status |
343 CSize file_name_size; | |
344 file_name_->SetText(model_->file_name()); | 334 file_name_->SetText(model_->file_name()); |
345 file_name_->GetPreferredSize(&file_name_size); | 335 gfx::Size file_name_size = file_name_->GetPreferredSize(); |
346 file_name_->SetBounds(dx, download_util::kBigProgressIconOffset, | 336 file_name_->SetBounds(dx, download_util::kBigProgressIconOffset, |
347 kFilenameSize - kProgressSize - kSpacer, | 337 kFilenameSize - kProgressSize - kSpacer, |
348 file_name_size.cy); | 338 file_name_size.height()); |
349 file_name_->SetVisible(true); | 339 file_name_->SetVisible(true); |
350 file_name_->SetEnabled(false); | 340 file_name_->SetEnabled(false); |
351 | 341 |
352 GURL url(model_->url()); | 342 GURL url(model_->url()); |
353 download_url_->SetURL(url); | 343 download_url_->SetURL(url); |
354 CSize url_size; | 344 gfx::Size url_size = download_url_->GetPreferredSize(); |
355 download_url_->GetPreferredSize(&url_size); | |
356 download_url_->SetBounds(dx, | 345 download_url_->SetBounds(dx, |
357 file_name_size.cy + kVerticalPadding + | 346 file_name_size.height() + kVerticalPadding + |
358 download_util::kBigProgressIconOffset, | 347 download_util::kBigProgressIconOffset, |
359 std::min(kFilenameSize - kProgressSize - kSpacer, | 348 std::min(kFilenameSize - kProgressSize - kSpacer, |
360 static_cast<int>(width() - dx)), | 349 static_cast<int>(width() - dx)), |
361 url_size.cy); | 350 url_size.height()); |
362 download_url_->SetVisible(true); | 351 download_url_->SetVisible(true); |
363 | 352 |
364 dx += kFilenameSize - kProgressSize; | 353 dx += kFilenameSize - kProgressSize; |
365 | 354 |
366 // Display cancelled status | 355 // Display cancelled status |
367 CSize cancel_size; | |
368 time_remaining_->SetColor(kStatusColor); | 356 time_remaining_->SetColor(kStatusColor); |
369 time_remaining_->SetText(l10n_util::GetString(IDS_DOWNLOAD_TAB_CANCELLED)); | 357 time_remaining_->SetText(l10n_util::GetString(IDS_DOWNLOAD_TAB_CANCELLED)); |
370 time_remaining_->GetPreferredSize(&cancel_size); | 358 gfx::Size cancel_size = time_remaining_->GetPreferredSize(); |
371 time_remaining_->SetBounds(dx, download_util::kBigProgressIconOffset, | 359 time_remaining_->SetBounds(dx, download_util::kBigProgressIconOffset, |
372 kProgressSize, cancel_size.cy); | 360 kProgressSize, cancel_size.height()); |
373 time_remaining_->SetVisible(true); | 361 time_remaining_->SetVisible(true); |
374 | 362 |
375 // Display received size, we may not know the total size if the server didn't | 363 // Display received size, we may not know the total size if the server didn't |
376 // provide a content-length. | 364 // provide a content-length. |
377 int64 total = model_->total_bytes(); | 365 int64 total = model_->total_bytes(); |
378 int64 size = model_->received_bytes(); | 366 int64 size = model_->received_bytes(); |
379 DataUnits amount_units = GetByteDisplayUnits(size); | 367 DataUnits amount_units = GetByteDisplayUnits(size); |
380 std::wstring received_size = FormatBytes(size, amount_units, true); | 368 std::wstring received_size = FormatBytes(size, amount_units, true); |
381 std::wstring amount = received_size; | 369 std::wstring amount = received_size; |
382 | 370 |
(...skipping 14 matching lines...) Expand all Loading... |
397 &total_text_localized)) | 385 &total_text_localized)) |
398 total_text.assign(total_text_localized); | 386 total_text.assign(total_text_localized); |
399 | 387 |
400 // Note that there is no need to adjust the new amount string for the | 388 // Note that there is no need to adjust the new amount string for the |
401 // locale direction as ChromeViews::Label does that for us. | 389 // locale direction as ChromeViews::Label does that for us. |
402 amount = l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_SIZE, | 390 amount = l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_SIZE, |
403 received_size, | 391 received_size, |
404 total_text); | 392 total_text); |
405 } | 393 } |
406 | 394 |
407 CSize byte_size; | |
408 download_progress_->SetText(amount); | 395 download_progress_->SetText(amount); |
409 download_progress_->GetPreferredSize(&byte_size); | 396 gfx::Size byte_size = download_progress_->GetPreferredSize(); |
410 download_progress_->SetBounds(dx, | 397 download_progress_->SetBounds(dx, |
411 file_name_size.cy + kVerticalPadding + | 398 file_name_size.height() + kVerticalPadding + |
412 download_util::kBigProgressIconOffset, | 399 download_util::kBigProgressIconOffset, |
413 kProgressSize, | 400 kProgressSize, |
414 byte_size.cy); | 401 byte_size.height()); |
415 download_progress_->SetVisible(true); | 402 download_progress_->SetVisible(true); |
416 } | 403 } |
417 | 404 |
418 // DownloadItem::IN_PROGRESS state layout | 405 // DownloadItem::IN_PROGRESS state layout |
419 void DownloadItemTabView::LayoutInProgress() { | 406 void DownloadItemTabView::LayoutInProgress() { |
420 // Hide unused UI elements | 407 // Hide unused UI elements |
421 show_->SetVisible(false); | 408 show_->SetVisible(false); |
422 show_->SetEnabled(false); | 409 show_->SetEnabled(false); |
423 dangerous_download_warning_->SetVisible(false); | 410 dangerous_download_warning_->SetVisible(false); |
424 save_button_->SetVisible(false); | 411 save_button_->SetVisible(false); |
425 save_button_->SetEnabled(false); | 412 save_button_->SetEnabled(false); |
426 discard_button_->SetVisible(false); | 413 discard_button_->SetVisible(false); |
427 discard_button_->SetEnabled(false); | 414 discard_button_->SetEnabled(false); |
428 | 415 |
429 LayoutDate(); | 416 LayoutDate(); |
430 int dx = kDownloadIconOffset - download_util::kBigProgressIconOffset + | 417 int dx = kDownloadIconOffset - download_util::kBigProgressIconOffset + |
431 download_util::kBigProgressIconSize + | 418 download_util::kBigProgressIconSize + |
432 kInfoPadding; | 419 kInfoPadding; |
433 | 420 |
434 // File name and URL, truncated to show progress status | 421 // File name and URL, truncated to show progress status |
435 CSize file_name_size; | |
436 file_name_->SetText(model_->GetFileName()); | 422 file_name_->SetText(model_->GetFileName()); |
437 file_name_->GetPreferredSize(&file_name_size); | 423 gfx::Size file_name_size = file_name_->GetPreferredSize(); |
438 file_name_->SetBounds(dx, download_util::kBigProgressIconOffset, | 424 file_name_->SetBounds(dx, download_util::kBigProgressIconOffset, |
439 kFilenameSize - kProgressSize - kSpacer, | 425 kFilenameSize - kProgressSize - kSpacer, |
440 file_name_size.cy); | 426 file_name_size.height()); |
441 file_name_->SetVisible(true); | 427 file_name_->SetVisible(true); |
442 file_name_->SetEnabled(false); | 428 file_name_->SetEnabled(false); |
443 | 429 |
444 GURL url(model_->url()); | 430 GURL url(model_->url()); |
445 download_url_->SetURL(url); | 431 download_url_->SetURL(url); |
446 CSize url_size; | 432 gfx::Size url_size = download_url_->GetPreferredSize(); |
447 download_url_->GetPreferredSize(&url_size); | 433 download_url_->SetBounds(dx, file_name_size.height() + kVerticalPadding + |
448 download_url_->SetBounds(dx, file_name_size.cy + kVerticalPadding + | |
449 download_util::kBigProgressIconOffset, | 434 download_util::kBigProgressIconOffset, |
450 std::min(kFilenameSize - kProgressSize - kSpacer, | 435 std::min(kFilenameSize - kProgressSize - kSpacer, |
451 static_cast<int>(width() - dx)), | 436 static_cast<int>(width() - dx)), |
452 url_size.cy); | 437 url_size.height()); |
453 download_url_->SetVisible(true); | 438 download_url_->SetVisible(true); |
454 | 439 |
455 dx += kFilenameSize - kProgressSize; | 440 dx += kFilenameSize - kProgressSize; |
456 | 441 |
457 // Set the time remaining and progress display strings. This can | 442 // Set the time remaining and progress display strings. This can |
458 // be complicated by not having received the total download size | 443 // be complicated by not having received the total download size |
459 // In that case, we can't calculate time remaining so we just | 444 // In that case, we can't calculate time remaining so we just |
460 // display speed and received size. | 445 // display speed and received size. |
461 | 446 |
462 // Size | 447 // Size |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 // causes Windows to ignore the 'LRE'/'RLE'/'PDF' Unicode formatting | 496 // causes Windows to ignore the 'LRE'/'RLE'/'PDF' Unicode formatting |
512 // characters within the string and this causes the string to be displayed | 497 // characters within the string and this causes the string to be displayed |
513 // incorrectly on RTL UIs. Therefore, we add the Unicode right-to-left | 498 // incorrectly on RTL UIs. Therefore, we add the Unicode right-to-left |
514 // override character (U+202E) if the locale is RTL in order to fix this | 499 // override character (U+202E) if the locale is RTL in order to fix this |
515 // problem. | 500 // problem. |
516 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) | 501 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) |
517 progress.insert(0, L"\x202E"); | 502 progress.insert(0, L"\x202E"); |
518 } | 503 } |
519 | 504 |
520 // Time remaining | 505 // Time remaining |
521 int y_pos = file_name_size.cy + kVerticalPadding + | 506 int y_pos = file_name_size.height() + kVerticalPadding + |
522 download_util::kBigProgressIconOffset; | 507 download_util::kBigProgressIconOffset; |
523 CSize time_size; | 508 gfx::Size time_size; |
524 time_remaining_->SetColor(kStatusColor); | 509 time_remaining_->SetColor(kStatusColor); |
525 if (model_->is_paused()) { | 510 if (model_->is_paused()) { |
526 time_remaining_->SetColor(kPauseColor); | 511 time_remaining_->SetColor(kPauseColor); |
527 time_remaining_->SetText( | 512 time_remaining_->SetText( |
528 l10n_util::GetString(IDS_DOWNLOAD_PROGRESS_PAUSED)); | 513 l10n_util::GetString(IDS_DOWNLOAD_PROGRESS_PAUSED)); |
529 time_remaining_->GetPreferredSize(&time_size); | 514 time_size = time_remaining_->GetPreferredSize(); |
530 time_remaining_->SetBounds(dx, download_util::kBigProgressIconOffset, | 515 time_remaining_->SetBounds(dx, download_util::kBigProgressIconOffset, |
531 kProgressSize, time_size.cy); | 516 kProgressSize, time_size.height()); |
532 time_remaining_->SetVisible(true); | 517 time_remaining_->SetVisible(true); |
533 } else if (total > 0) { | 518 } else if (total > 0) { |
534 TimeDelta remaining; | 519 TimeDelta remaining; |
535 if (model_->TimeRemaining(&remaining)) | 520 if (model_->TimeRemaining(&remaining)) |
536 time_remaining_->SetText(TimeFormat::TimeRemaining(remaining)); | 521 time_remaining_->SetText(TimeFormat::TimeRemaining(remaining)); |
537 time_remaining_->GetPreferredSize(&time_size); | 522 time_size = time_remaining_->GetPreferredSize(); |
538 time_remaining_->SetBounds(dx, download_util::kBigProgressIconOffset, | 523 time_remaining_->SetBounds(dx, download_util::kBigProgressIconOffset, |
539 kProgressSize, time_size.cy); | 524 kProgressSize, time_size.height()); |
540 time_remaining_->SetVisible(true); | 525 time_remaining_->SetVisible(true); |
541 } else { | 526 } else { |
542 time_remaining_->SetText(L""); | 527 time_remaining_->SetText(L""); |
543 y_pos = ((file_name_size.cy + url_size.cy) / 2) + | 528 y_pos = ((file_name_size.height() + url_size.height()) / 2) + |
544 download_util::kBigProgressIconOffset; | 529 download_util::kBigProgressIconOffset; |
545 } | 530 } |
546 | 531 |
547 CSize byte_size; | |
548 download_progress_->SetText(progress); | 532 download_progress_->SetText(progress); |
549 download_progress_->GetPreferredSize(&byte_size); | 533 gfx::Size byte_size = download_progress_->GetPreferredSize(); |
550 download_progress_->SetBounds(dx, y_pos, | 534 download_progress_->SetBounds(dx, y_pos, |
551 kProgressSize, byte_size.cy); | 535 kProgressSize, byte_size.height()); |
552 download_progress_->SetVisible(true); | 536 download_progress_->SetVisible(true); |
553 | 537 |
554 dx += kProgressSize + kSpacer; | 538 dx += kProgressSize + kSpacer; |
555 y_pos = ((file_name_size.cy + url_size.cy) / 2) + | 539 y_pos = ((file_name_size.height() + url_size.height()) / 2) + |
556 download_util::kBigProgressIconOffset; | 540 download_util::kBigProgressIconOffset; |
557 | 541 |
558 // Pause (or Resume) / Cancel buttons. | 542 // Pause (or Resume) / Cancel buttons. |
559 if (model_->is_paused()) | 543 if (model_->is_paused()) |
560 pause_->SetText(l10n_util::GetString(IDS_DOWNLOAD_LINK_RESUME)); | 544 pause_->SetText(l10n_util::GetString(IDS_DOWNLOAD_LINK_RESUME)); |
561 else | 545 else |
562 pause_->SetText(l10n_util::GetString(IDS_DOWNLOAD_LINK_PAUSE)); | 546 pause_->SetText(l10n_util::GetString(IDS_DOWNLOAD_LINK_PAUSE)); |
563 | 547 |
564 CSize pause_size; | |
565 pause_->SetVisible(true); | 548 pause_->SetVisible(true); |
566 pause_->SetEnabled(true); | 549 pause_->SetEnabled(true); |
567 pause_->GetPreferredSize(&pause_size); | 550 gfx::Size pause_size = pause_->GetPreferredSize(); |
568 pause_->SetBounds(dx, y_pos, pause_size.cx, pause_size.cy); | 551 pause_->SetBounds(dx, y_pos, pause_size.width(), pause_size.height()); |
569 | 552 |
570 dx += pause_size.cx + kHorizontalLinkPadding; | 553 dx += pause_size.width() + kHorizontalLinkPadding; |
571 | 554 |
572 CSize cancel_size; | 555 gfx::Size cancel_size = cancel_->GetPreferredSize(); |
573 cancel_->GetPreferredSize(&cancel_size); | 556 cancel_->SetBounds(dx, y_pos, cancel_size.width(), cancel_size.height()); |
574 cancel_->SetBounds(dx, y_pos, cancel_size.cx, cancel_size.cy); | |
575 cancel_->SetVisible(true); | 557 cancel_->SetVisible(true); |
576 cancel_->SetEnabled(true); | 558 cancel_->SetEnabled(true); |
577 } | 559 } |
578 | 560 |
579 void DownloadItemTabView::LayoutPromptDangerousDownload() { | 561 void DownloadItemTabView::LayoutPromptDangerousDownload() { |
580 // Hide unused UI elements | 562 // Hide unused UI elements |
581 show_->SetVisible(false); | 563 show_->SetVisible(false); |
582 show_->SetEnabled(false); | 564 show_->SetEnabled(false); |
583 file_name_->SetVisible(false); | 565 file_name_->SetVisible(false); |
584 file_name_->SetEnabled(false); | 566 file_name_->SetEnabled(false); |
585 pause_->SetVisible(false); | 567 pause_->SetVisible(false); |
586 pause_->SetEnabled(false); | 568 pause_->SetEnabled(false); |
587 cancel_->SetVisible(false); | 569 cancel_->SetVisible(false); |
588 cancel_->SetEnabled(false); | 570 cancel_->SetEnabled(false); |
589 time_remaining_->SetVisible(false); | 571 time_remaining_->SetVisible(false); |
590 download_progress_->SetVisible(false); | 572 download_progress_->SetVisible(false); |
591 | 573 |
592 LayoutDate(); | 574 LayoutDate(); |
593 int dx = kDownloadIconOffset - download_util::kBigProgressIconOffset + | 575 int dx = kDownloadIconOffset - download_util::kBigProgressIconOffset + |
594 download_util::kBigProgressIconSize + | 576 download_util::kBigProgressIconSize + |
595 kInfoPadding; | 577 kInfoPadding; |
596 | 578 |
597 // Warning message and URL. | 579 // Warning message and URL. |
598 CSize warning_size; | |
599 std::wstring file_name; | 580 std::wstring file_name; |
600 ElideString(model_->original_name(), kFileNameMaxLength, &file_name); | 581 ElideString(model_->original_name(), kFileNameMaxLength, &file_name); |
601 dangerous_download_warning_->SetText( | 582 dangerous_download_warning_->SetText( |
602 l10n_util::GetStringF(IDS_PROMPT_DANGEROUS_DOWNLOAD, file_name)); | 583 l10n_util::GetStringF(IDS_PROMPT_DANGEROUS_DOWNLOAD, file_name)); |
603 dangerous_download_warning_->GetPreferredSize(&warning_size); | 584 gfx::Size warning_size = dangerous_download_warning_->GetPreferredSize(); |
604 dangerous_download_warning_->SetBounds(dx, 0, | 585 dangerous_download_warning_->SetBounds(dx, 0, |
605 kFilenameSize, warning_size.cy); | 586 kFilenameSize, warning_size.height()); |
606 dangerous_download_warning_->SetVisible(true); | 587 dangerous_download_warning_->SetVisible(true); |
607 | 588 |
608 GURL url(model_->url()); | 589 GURL url(model_->url()); |
609 download_url_->SetURL(url); | 590 download_url_->SetURL(url); |
610 CSize url_size; | 591 gfx::Size url_size = download_url_->GetPreferredSize(); |
611 download_url_->GetPreferredSize(&url_size); | 592 download_url_->SetBounds(dx, height() - url_size.height(), |
612 download_url_->SetBounds(dx, height() - url_size.cy, | |
613 std::min(kFilenameSize - kSpacer, | 593 std::min(kFilenameSize - kSpacer, |
614 static_cast<int>(width() - dx)), | 594 static_cast<int>(width() - dx)), |
615 url_size.cy); | 595 url_size.height()); |
616 download_url_->SetVisible(true); | 596 download_url_->SetVisible(true); |
617 | 597 |
618 dx += kFilenameSize + kSpacer; | 598 dx += kFilenameSize + kSpacer; |
619 | 599 |
620 // Save/Discard buttons. | 600 // Save/Discard buttons. |
621 CSize button_size; | 601 gfx::Size button_size = save_button_->GetPreferredSize(); |
622 save_button_->GetPreferredSize(&button_size); | 602 save_button_->SetBounds(dx, (height() - button_size.height()) / 2, |
623 save_button_->SetBounds(dx, (height() - button_size.cy) / 2, | 603 button_size.width(), button_size.height()); |
624 button_size.cx, button_size.cy); | |
625 save_button_->SetVisible(true); | 604 save_button_->SetVisible(true); |
626 save_button_->SetEnabled(true); | 605 save_button_->SetEnabled(true); |
627 | 606 |
628 dx += button_size.cx + kHorizontalButtonPadding; | 607 dx += button_size.width() + kHorizontalButtonPadding; |
629 | 608 |
630 discard_button_->GetPreferredSize(&button_size); | 609 button_size = discard_button_->GetPreferredSize(); |
631 discard_button_->SetBounds(dx, (height() - button_size.cy) / 2, | 610 discard_button_->SetBounds(dx, (height() - button_size.height()) / 2, |
632 button_size.cx, button_size.cy); | 611 button_size.width(), button_size.height()); |
633 discard_button_->SetVisible(true); | 612 discard_button_->SetVisible(true); |
634 discard_button_->SetEnabled(true); | 613 discard_button_->SetEnabled(true); |
635 } | 614 } |
636 | 615 |
637 void DownloadItemTabView::Paint(ChromeCanvas* canvas) { | 616 void DownloadItemTabView::Paint(ChromeCanvas* canvas) { |
638 PaintBackground(canvas); | 617 PaintBackground(canvas); |
639 | 618 |
640 if (model_->state() == DownloadItem::IN_PROGRESS && | 619 if (model_->state() == DownloadItem::IN_PROGRESS && |
641 model_->safety_state() != DownloadItem::DANGEROUS) { | 620 model_->safety_state() != DownloadItem::DANGEROUS) { |
642 download_util::PaintDownloadProgress(canvas, | 621 download_util::PaintDownloadProgress(canvas, |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 DCHECK(profile()->HasCreatedDownloadManager()); | 1311 DCHECK(profile()->HasCreatedDownloadManager()); |
1333 contents_->SetIsLoading( | 1312 contents_->SetIsLoading( |
1334 profile()->GetDownloadManager()->in_progress_count() > 0, | 1313 profile()->GetDownloadManager()->in_progress_count() > 0, |
1335 NULL); | 1314 NULL); |
1336 break; | 1315 break; |
1337 default: | 1316 default: |
1338 break; | 1317 break; |
1339 } | 1318 } |
1340 } | 1319 } |
1341 | 1320 |
OLD | NEW |