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

Side by Side Diff: chrome/browser/gtk/download_item_gtk.cc

Issue 6154001: Move animation code to new ui/base/animation directory.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/gtk/download_item_gtk.h" 5 #include "chrome/browser/gtk/download_item_gtk.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "app/slide_animation.h"
10 #include "app/text_elider.h" 9 #include "app/text_elider.h"
11 #include "base/basictypes.h" 10 #include "base/basictypes.h"
12 #include "base/callback.h" 11 #include "base/callback.h"
13 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
14 #include "base/string_util.h" 13 #include "base/string_util.h"
15 #include "base/time.h" 14 #include "base/time.h"
16 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
17 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/download/download_item.h" 17 #include "chrome/browser/download/download_item.h"
19 #include "chrome/browser/download/download_item_model.h" 18 #include "chrome/browser/download/download_item_model.h"
20 #include "chrome/browser/download/download_manager.h" 19 #include "chrome/browser/download/download_manager.h"
21 #include "chrome/browser/download/download_shelf.h" 20 #include "chrome/browser/download/download_shelf.h"
22 #include "chrome/browser/download/download_util.h" 21 #include "chrome/browser/download/download_util.h"
23 #include "chrome/browser/gtk/custom_drag.h" 22 #include "chrome/browser/gtk/custom_drag.h"
24 #include "chrome/browser/gtk/download_shelf_gtk.h" 23 #include "chrome/browser/gtk/download_shelf_gtk.h"
25 #include "chrome/browser/gtk/gtk_theme_provider.h" 24 #include "chrome/browser/gtk/gtk_theme_provider.h"
26 #include "chrome/browser/gtk/gtk_util.h" 25 #include "chrome/browser/gtk/gtk_util.h"
27 #include "chrome/browser/gtk/menu_gtk.h" 26 #include "chrome/browser/gtk/menu_gtk.h"
28 #include "chrome/browser/gtk/nine_box.h" 27 #include "chrome/browser/gtk/nine_box.h"
29 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
30 #include "chrome/common/notification_service.h" 29 #include "chrome/common/notification_service.h"
31 #include "gfx/canvas_skia_paint.h" 30 #include "gfx/canvas_skia_paint.h"
32 #include "gfx/color_utils.h" 31 #include "gfx/color_utils.h"
33 #include "gfx/font.h" 32 #include "gfx/font.h"
34 #include "gfx/skia_utils_gtk.h" 33 #include "gfx/skia_utils_gtk.h"
35 #include "grit/generated_resources.h" 34 #include "grit/generated_resources.h"
36 #include "grit/theme_resources.h" 35 #include "grit/theme_resources.h"
37 #include "third_party/skia/include/core/SkBitmap.h" 36 #include "third_party/skia/include/core/SkBitmap.h"
37 #include "ui/base/animation/slide_animation.h"
38 38
39 namespace { 39 namespace {
40 40
41 // The width of the |menu_button_| widget. It has to be at least as wide as the 41 // The width of the |menu_button_| widget. It has to be at least as wide as the
42 // bitmap that we use to draw it, i.e. 16, but can be more. 42 // bitmap that we use to draw it, i.e. 16, but can be more.
43 const int kMenuButtonWidth = 16; 43 const int kMenuButtonWidth = 16;
44 44
45 // Padding on left and right of items in dangerous download prompt. 45 // Padding on left and right of items in dangerous download prompt.
46 const int kDangerousElementPadding = 3; 46 const int kDangerousElementPadding = 3;
47 47
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 g_signal_connect(hbox_.get(), "expose-event", 238 g_signal_connect(hbox_.get(), "expose-event",
239 G_CALLBACK(OnHboxExposeThunk), this); 239 G_CALLBACK(OnHboxExposeThunk), this);
240 gtk_box_pack_start(GTK_BOX(hbox_.get()), body_.get(), FALSE, FALSE, 0); 240 gtk_box_pack_start(GTK_BOX(hbox_.get()), body_.get(), FALSE, FALSE, 0);
241 gtk_box_pack_start(GTK_BOX(hbox_.get()), menu_button_, FALSE, FALSE, 0); 241 gtk_box_pack_start(GTK_BOX(hbox_.get()), menu_button_, FALSE, FALSE, 0);
242 gtk_box_pack_start(GTK_BOX(shelf_hbox), hbox_.get(), FALSE, FALSE, 0); 242 gtk_box_pack_start(GTK_BOX(shelf_hbox), hbox_.get(), FALSE, FALSE, 0);
243 // Insert as the leftmost item. 243 // Insert as the leftmost item.
244 gtk_box_reorder_child(GTK_BOX(shelf_hbox), hbox_.get(), 0); 244 gtk_box_reorder_child(GTK_BOX(shelf_hbox), hbox_.get(), 0);
245 245
246 get_download()->AddObserver(this); 246 get_download()->AddObserver(this);
247 247
248 new_item_animation_.reset(new SlideAnimation(this)); 248 new_item_animation_.reset(new ui::SlideAnimation(this));
249 new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs); 249 new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs);
250 gtk_widget_show_all(hbox_.get()); 250 gtk_widget_show_all(hbox_.get());
251 251
252 if (IsDangerous()) { 252 if (IsDangerous()) {
253 // Hide the download item components for now. 253 // Hide the download item components for now.
254 gtk_widget_hide(body_.get()); 254 gtk_widget_hide(body_.get());
255 gtk_widget_hide(menu_button_); 255 gtk_widget_hide(menu_button_);
256 256
257 // Create an hbox to hold it all. 257 // Create an hbox to hold it all.
258 dangerous_hbox_ = gtk_hbox_new(FALSE, kDangerousElementPadding); 258 dangerous_hbox_ = gtk_hbox_new(FALSE, kDangerousElementPadding);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 case DownloadItem::COMPLETE: 375 case DownloadItem::COMPLETE:
376 if (download->auto_opened()) { 376 if (download->auto_opened()) {
377 parent_shelf_->RemoveDownloadItem(this); // This will delete us! 377 parent_shelf_->RemoveDownloadItem(this); // This will delete us!
378 return; 378 return;
379 } 379 }
380 StopDownloadProgress(); 380 StopDownloadProgress();
381 381
382 // Set up the widget as a drag source. 382 // Set up the widget as a drag source.
383 DownloadItemDrag::SetSource(body_.get(), get_download(), icon_large_); 383 DownloadItemDrag::SetSource(body_.get(), get_download(), icon_large_);
384 384
385 complete_animation_.reset(new SlideAnimation(this)); 385 complete_animation_.reset(new ui::SlideAnimation(this));
386 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); 386 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs);
387 complete_animation_->SetTweenType(Tween::LINEAR); 387 complete_animation_->SetTweenType(ui::Tween::LINEAR);
388 complete_animation_->Show(); 388 complete_animation_->Show();
389 break; 389 break;
390 case DownloadItem::IN_PROGRESS: 390 case DownloadItem::IN_PROGRESS:
391 get_download()->is_paused() ? 391 get_download()->is_paused() ?
392 StopDownloadProgress() : StartDownloadProgress(); 392 StopDownloadProgress() : StartDownloadProgress();
393 break; 393 break;
394 default: 394 default:
395 NOTREACHED(); 395 NOTREACHED();
396 } 396 }
397 397
398 // Now update the status label. We may have already removed it; if so, we 398 // Now update the status label. We may have already removed it; if so, we
399 // do nothing. 399 // do nothing.
400 if (!status_label_) { 400 if (!status_label_) {
401 return; 401 return;
402 } 402 }
403 403
404 status_text_ = UTF16ToUTF8(download_model_->GetStatusText()); 404 status_text_ = UTF16ToUTF8(download_model_->GetStatusText());
405 // Remove the status text label. 405 // Remove the status text label.
406 if (status_text_.empty()) { 406 if (status_text_.empty()) {
407 gtk_widget_destroy(status_label_); 407 gtk_widget_destroy(status_label_);
408 return; 408 return;
409 } 409 }
410 410
411 UpdateStatusLabel(status_text_); 411 UpdateStatusLabel(status_text_);
412 } 412 }
413 413
414 void DownloadItemGtk::AnimationProgressed(const Animation* animation) { 414 void DownloadItemGtk::AnimationProgressed(const ui::Animation* animation) {
415 if (animation == complete_animation_.get()) { 415 if (animation == complete_animation_.get()) {
416 gtk_widget_queue_draw(progress_area_.get()); 416 gtk_widget_queue_draw(progress_area_.get());
417 } else { 417 } else {
418 if (IsDangerous()) { 418 if (IsDangerous()) {
419 int progress = static_cast<int>((dangerous_hbox_full_width_ - 419 int progress = static_cast<int>((dangerous_hbox_full_width_ -
420 dangerous_hbox_start_width_) * 420 dangerous_hbox_start_width_) *
421 new_item_animation_->GetCurrentValue()); 421 new_item_animation_->GetCurrentValue());
422 int showing_width = dangerous_hbox_start_width_ + progress; 422 int showing_width = dangerous_hbox_start_width_ + progress;
423 gtk_widget_set_size_request(dangerous_hbox_, showing_width, -1); 423 gtk_widget_set_size_request(dangerous_hbox_, showing_width, -1);
424 } else { 424 } else {
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 get_download()->DangerousDownloadValidated(); 870 get_download()->DangerousDownloadValidated();
871 } 871 }
872 872
873 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { 873 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) {
874 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", 874 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download",
875 base::Time::Now() - creation_time_); 875 base::Time::Now() - creation_time_);
876 if (get_download()->state() == DownloadItem::IN_PROGRESS) 876 if (get_download()->state() == DownloadItem::IN_PROGRESS)
877 get_download()->Cancel(true); 877 get_download()->Cancel(true);
878 get_download()->Remove(true); 878 get_download()->Remove(true);
879 } 879 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/download_item_gtk.h ('k') | chrome/browser/gtk/download_started_animation_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698