OLD | NEW |
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/gtk/download/download_item_gtk.h" | 5 #include "chrome/browser/ui/gtk/download/download_item_gtk.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/browser/ui/gtk/download/download_shelf_context_menu_gtk.h" | 21 #include "chrome/browser/ui/gtk/download/download_shelf_context_menu_gtk.h" |
22 #include "chrome/browser/ui/gtk/download/download_shelf_gtk.h" | 22 #include "chrome/browser/ui/gtk/download/download_shelf_gtk.h" |
23 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 23 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
24 #include "chrome/browser/ui/gtk/gtk_util.h" | 24 #include "chrome/browser/ui/gtk/gtk_util.h" |
25 #include "chrome/browser/ui/gtk/nine_box.h" | 25 #include "chrome/browser/ui/gtk/nine_box.h" |
26 #include "content/public/browser/download_manager.h" | 26 #include "content/public/browser/download_manager.h" |
27 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
29 #include "grit/theme_resources.h" | 29 #include "grit/theme_resources.h" |
30 #include "third_party/skia/include/core/SkBitmap.h" | 30 #include "third_party/skia/include/core/SkBitmap.h" |
31 #include "ui/base/animation/slide_animation.h" | |
32 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
33 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| 33 #include "ui/gfx/animation/slide_animation.h" |
34 #include "ui/gfx/canvas_skia_paint.h" | 34 #include "ui/gfx/canvas_skia_paint.h" |
35 #include "ui/gfx/color_utils.h" | 35 #include "ui/gfx/color_utils.h" |
36 #include "ui/gfx/image/image.h" | 36 #include "ui/gfx/image/image.h" |
37 #include "ui/gfx/skia_utils_gtk.h" | 37 #include "ui/gfx/skia_utils_gtk.h" |
38 #include "ui/gfx/text_elider.h" | 38 #include "ui/gfx/text_elider.h" |
39 #include "ui/gfx/text_utils.h" | 39 #include "ui/gfx/text_utils.h" |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 // The width of the |menu_button_| widget. It has to be at least as wide as the | 43 // The width of the |menu_button_| widget. It has to be at least as wide as the |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 g_signal_connect(hbox_.get(), "expose-event", | 188 g_signal_connect(hbox_.get(), "expose-event", |
189 G_CALLBACK(OnHboxExposeThunk), this); | 189 G_CALLBACK(OnHboxExposeThunk), this); |
190 gtk_box_pack_start(GTK_BOX(hbox_.get()), body_.get(), FALSE, FALSE, 0); | 190 gtk_box_pack_start(GTK_BOX(hbox_.get()), body_.get(), FALSE, FALSE, 0); |
191 gtk_box_pack_start(GTK_BOX(hbox_.get()), menu_button_, FALSE, FALSE, 0); | 191 gtk_box_pack_start(GTK_BOX(hbox_.get()), menu_button_, FALSE, FALSE, 0); |
192 gtk_box_pack_start(GTK_BOX(shelf_hbox), hbox_.get(), FALSE, FALSE, 0); | 192 gtk_box_pack_start(GTK_BOX(shelf_hbox), hbox_.get(), FALSE, FALSE, 0); |
193 // Insert as the leftmost item. | 193 // Insert as the leftmost item. |
194 gtk_box_reorder_child(GTK_BOX(shelf_hbox), hbox_.get(), 0); | 194 gtk_box_reorder_child(GTK_BOX(shelf_hbox), hbox_.get(), 0); |
195 | 195 |
196 download()->AddObserver(this); | 196 download()->AddObserver(this); |
197 | 197 |
198 new_item_animation_.reset(new ui::SlideAnimation(this)); | 198 new_item_animation_.reset(new gfx::SlideAnimation(this)); |
199 new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs); | 199 new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs); |
200 gtk_widget_show_all(hbox_.get()); | 200 gtk_widget_show_all(hbox_.get()); |
201 | 201 |
202 if (download_model_.IsDangerous()) { | 202 if (download_model_.IsDangerous()) { |
203 // Hide the download item components for now. | 203 // Hide the download item components for now. |
204 gtk_widget_set_no_show_all(body_.get(), TRUE); | 204 gtk_widget_set_no_show_all(body_.get(), TRUE); |
205 gtk_widget_set_no_show_all(menu_button_, TRUE); | 205 gtk_widget_set_no_show_all(menu_button_, TRUE); |
206 gtk_widget_hide(body_.get()); | 206 gtk_widget_hide(body_.get()); |
207 gtk_widget_hide(menu_button_); | 207 gtk_widget_hide(menu_button_); |
208 | 208 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // Set the initial width of the widget to be animated. | 267 // Set the initial width of the widget to be animated. |
268 if (download_model_.IsDangerous()) { | 268 if (download_model_.IsDangerous()) { |
269 gtk_widget_set_size_request(dangerous_hbox_.get(), | 269 gtk_widget_set_size_request(dangerous_hbox_.get(), |
270 dangerous_hbox_start_width_, -1); | 270 dangerous_hbox_start_width_, -1); |
271 } else { | 271 } else { |
272 gtk_widget_set_size_request(body_.get(), kMinDownloadItemWidth, -1); | 272 gtk_widget_set_size_request(body_.get(), kMinDownloadItemWidth, -1); |
273 } | 273 } |
274 | 274 |
275 new_item_animation_->Show(); | 275 new_item_animation_->Show(); |
276 | 276 |
277 complete_animation_.SetTweenType(ui::Tween::LINEAR); | 277 complete_animation_.SetTweenType(gfx::Tween::LINEAR); |
278 complete_animation_.SetSlideDuration(kCompleteAnimationDurationMs); | 278 complete_animation_.SetSlideDuration(kCompleteAnimationDurationMs); |
279 | 279 |
280 // Update the status text and animation state. | 280 // Update the status text and animation state. |
281 OnDownloadUpdated(download()); | 281 OnDownloadUpdated(download()); |
282 } | 282 } |
283 | 283 |
284 DownloadItemGtk::~DownloadItemGtk() { | 284 DownloadItemGtk::~DownloadItemGtk() { |
285 // First close the menu and then destroy the GtkWidgets. Bug#97724 | 285 // First close the menu and then destroy the GtkWidgets. Bug#97724 |
286 if (menu_.get()) | 286 if (menu_.get()) |
287 menu_.reset(); | 287 menu_.reset(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 status_text_ = UTF16ToUTF8(download_model_.GetStatusText()); | 367 status_text_ = UTF16ToUTF8(download_model_.GetStatusText()); |
368 UpdateStatusLabel(status_text_); | 368 UpdateStatusLabel(status_text_); |
369 } | 369 } |
370 | 370 |
371 void DownloadItemGtk::OnDownloadDestroyed(DownloadItem* download_item) { | 371 void DownloadItemGtk::OnDownloadDestroyed(DownloadItem* download_item) { |
372 DCHECK_EQ(download(), download_item); | 372 DCHECK_EQ(download(), download_item); |
373 parent_shelf_->RemoveDownloadItem(this); | 373 parent_shelf_->RemoveDownloadItem(this); |
374 // This will delete us! | 374 // This will delete us! |
375 } | 375 } |
376 | 376 |
377 void DownloadItemGtk::AnimationProgressed(const ui::Animation* animation) { | 377 void DownloadItemGtk::AnimationProgressed(const gfx::Animation* animation) { |
378 if (animation == &complete_animation_) { | 378 if (animation == &complete_animation_) { |
379 gtk_widget_queue_draw(progress_area_.get()); | 379 gtk_widget_queue_draw(progress_area_.get()); |
380 } else { | 380 } else { |
381 DCHECK(animation == new_item_animation_.get()); | 381 DCHECK(animation == new_item_animation_.get()); |
382 if (download_model_.IsDangerous()) { | 382 if (download_model_.IsDangerous()) { |
383 int progress = static_cast<int>((dangerous_hbox_full_width_ - | 383 int progress = static_cast<int>((dangerous_hbox_full_width_ - |
384 dangerous_hbox_start_width_) * | 384 dangerous_hbox_start_width_) * |
385 animation->GetCurrentValue()); | 385 animation->GetCurrentValue()); |
386 int showing_width = dangerous_hbox_start_width_ + progress; | 386 int showing_width = dangerous_hbox_start_width_ + progress; |
387 gtk_widget_set_size_request(dangerous_hbox_.get(), showing_width, -1); | 387 gtk_widget_set_size_request(dangerous_hbox_.get(), showing_width, -1); |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", | 928 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", |
929 base::Time::Now() - creation_time_); | 929 base::Time::Now() - creation_time_); |
930 download()->ValidateDangerousDownload(); | 930 download()->ValidateDangerousDownload(); |
931 } | 931 } |
932 | 932 |
933 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { | 933 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { |
934 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 934 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
935 base::Time::Now() - creation_time_); | 935 base::Time::Now() - creation_time_); |
936 download()->Remove(); | 936 download()->Remove(); |
937 } | 937 } |
OLD | NEW |