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

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

Issue 215002: GTK: Download item as drag source.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 3 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/gfx/canvas_paint.h" 8 #include "app/gfx/canvas_paint.h"
9 #include "app/gfx/font.h" 9 #include "app/gfx/font.h"
10 #include "app/gfx/text_elider.h" 10 #include "app/gfx/text_elider.h"
11 #include "app/gtk_dnd_util.h"
11 #include "app/resource_bundle.h" 12 #include "app/resource_bundle.h"
12 #include "app/slide_animation.h" 13 #include "app/slide_animation.h"
13 #include "base/basictypes.h" 14 #include "base/basictypes.h"
14 #include "base/string_util.h" 15 #include "base/string_util.h"
15 #include "base/time.h" 16 #include "base/time.h"
16 #include "chrome/browser/browser.h" 17 #include "chrome/browser/browser.h"
17 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/download/download_item_model.h" 19 #include "chrome/browser/download/download_item_model.h"
19 #include "chrome/browser/download/download_manager.h" 20 #include "chrome/browser/download/download_manager.h"
20 #include "chrome/browser/download/download_shelf.h" 21 #include "chrome/browser/download/download_shelf.h"
21 #include "chrome/browser/download/download_util.h" 22 #include "chrome/browser/download/download_util.h"
22 #include "chrome/browser/gtk/download_shelf_gtk.h" 23 #include "chrome/browser/gtk/download_shelf_gtk.h"
23 #include "chrome/browser/gtk/gtk_theme_provider.h" 24 #include "chrome/browser/gtk/gtk_theme_provider.h"
24 #include "chrome/browser/gtk/menu_gtk.h" 25 #include "chrome/browser/gtk/menu_gtk.h"
25 #include "chrome/browser/gtk/nine_box.h" 26 #include "chrome/browser/gtk/nine_box.h"
26 #include "chrome/browser/gtk/standard_menus.h" 27 #include "chrome/browser/gtk/standard_menus.h"
27 #include "chrome/common/gtk_util.h" 28 #include "chrome/common/gtk_util.h"
28 #include "chrome/common/notification_service.h" 29 #include "chrome/common/notification_service.h"
30 #include "net/base/net_util.h"
29 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
30 #include "grit/theme_resources.h" 32 #include "grit/theme_resources.h"
31 #include "third_party/skia/include/core/SkBitmap.h" 33 #include "third_party/skia/include/core/SkBitmap.h"
32 34
33 namespace { 35 namespace {
34 36
35 // The width of the |menu_button_| widget. It has to be at least as wide as the 37 // The width of the |menu_button_| widget. It has to be at least as wide as the
36 // bitmap that we use to draw it, i.e. 16, but can be more. 38 // bitmap that we use to draw it, i.e. 16, but can be more.
37 const int kMenuButtonWidth = 16; 39 const int kMenuButtonWidth = 16;
38 40
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 G_CALLBACK(OnExpose), this); 213 G_CALLBACK(OnExpose), this);
212 g_signal_connect(body_.get(), "clicked", 214 g_signal_connect(body_.get(), "clicked",
213 G_CALLBACK(OnClick), this); 215 G_CALLBACK(OnClick), this);
214 GTK_WIDGET_UNSET_FLAGS(body_.get(), GTK_CAN_FOCUS); 216 GTK_WIDGET_UNSET_FLAGS(body_.get(), GTK_CAN_FOCUS);
215 // Remove internal padding on the button. 217 // Remove internal padding on the button.
216 GtkRcStyle* no_padding_style = gtk_rc_style_new(); 218 GtkRcStyle* no_padding_style = gtk_rc_style_new();
217 no_padding_style->xthickness = 0; 219 no_padding_style->xthickness = 0;
218 no_padding_style->ythickness = 0; 220 no_padding_style->ythickness = 0;
219 gtk_widget_modify_style(body_.get(), no_padding_style); 221 gtk_widget_modify_style(body_.get(), no_padding_style);
220 g_object_unref(no_padding_style); 222 g_object_unref(no_padding_style);
221 223
Nico 2009/09/18 01:05:42 is this newline intentional? i don't care either w
Evan Stade 2009/09/18 02:43:42 nope, fixed
224
222 name_label_ = gtk_label_new(NULL); 225 name_label_ = gtk_label_new(NULL);
223 226
224 // TODO(estade): This is at best an educated guess, since we don't actually 227 // TODO(estade): This is at best an educated guess, since we don't actually
225 // use gfx::Font() to draw the text. This is why we need to add so 228 // use gfx::Font() to draw the text. This is why we need to add so
226 // much padding when we set the size request. We need to either use gfx::Font 229 // much padding when we set the size request. We need to either use gfx::Font
227 // or somehow extend TextElider. 230 // or somehow extend TextElider.
228 UpdateNameLabel(); 231 UpdateNameLabel();
229 232
230 status_label_ = gtk_label_new(NULL); 233 status_label_ = gtk_label_new(NULL);
231 // Left align and vertically center the labels. 234 // Left align and vertically center the labels.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 switch (download->state()) { 385 switch (download->state()) {
383 case DownloadItem::REMOVING: 386 case DownloadItem::REMOVING:
384 parent_shelf_->RemoveDownloadItem(this); // This will delete us! 387 parent_shelf_->RemoveDownloadItem(this); // This will delete us!
385 return; 388 return;
386 case DownloadItem::CANCELLED: 389 case DownloadItem::CANCELLED:
387 StopDownloadProgress(); 390 StopDownloadProgress();
388 gtk_widget_queue_draw(progress_area_.get()); 391 gtk_widget_queue_draw(progress_area_.get());
389 break; 392 break;
390 case DownloadItem::COMPLETE: 393 case DownloadItem::COMPLETE:
391 StopDownloadProgress(); 394 StopDownloadProgress();
395
396 // Set up the widget as a drag source.
397 gtk_drag_source_set(body_.get(), GDK_BUTTON1_MASK, NULL, 0,
398 GDK_ACTION_COPY);
399 GtkDndUtil::SetSourceTargetListFromCodeMask(body_.get(),
400 GtkDndUtil::TEXT_URI_LIST |
401 GtkDndUtil::CHROME_NAMED_URL);
402 g_signal_connect(body_.get(), "drag-data-get",
403 G_CALLBACK(OnDragDataGet), this);
404
392 complete_animation_.reset(new SlideAnimation(this)); 405 complete_animation_.reset(new SlideAnimation(this));
393 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); 406 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs);
394 complete_animation_->SetTweenType(SlideAnimation::NONE); 407 complete_animation_->SetTweenType(SlideAnimation::NONE);
395 complete_animation_->Show(); 408 complete_animation_->Show();
396 break; 409 break;
397 case DownloadItem::IN_PROGRESS: 410 case DownloadItem::IN_PROGRESS:
398 get_download()->is_paused() ? 411 get_download()->is_paused() ?
399 StopDownloadProgress() : StartDownloadProgress(); 412 StopDownloadProgress() : StartDownloadProgress();
400 break; 413 break;
401 default: 414 default:
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) 858 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
846 out_of_bounds = !out_of_bounds; 859 out_of_bounds = !out_of_bounds;
847 860
848 if (out_of_bounds) 861 if (out_of_bounds)
849 gtk_widget_hide(item->hbox_.get()); 862 gtk_widget_hide(item->hbox_.get());
850 else 863 else
851 gtk_widget_show(item->hbox_.get()); 864 gtk_widget_show(item->hbox_.get());
852 } 865 }
853 866
854 // static 867 // static
868 void DownloadItemGtk::OnDragDataGet(GtkWidget* widget, GdkDragContext* context,
869 GtkSelectionData* selection_data,
870 guint target_type, guint time,
871 DownloadItemGtk* item) {
872 GURL url = net::FilePathToFileURL(
873 item->get_download()->full_path());
Nico 2009/09/18 01:05:42 This looks like it might fit into one line.
Evan Stade 2009/09/18 02:43:42 so it does
874
875 GtkDndUtil::WriteURLWithName(selection_data, url,
876 UTF8ToUTF16(item->get_download()->GetFileName().value()), target_type);
877 }
878
879 // static
855 gboolean DownloadItemGtk::OnDangerousPromptExpose(GtkWidget* widget, 880 gboolean DownloadItemGtk::OnDangerousPromptExpose(GtkWidget* widget,
856 GdkEventExpose* event, DownloadItemGtk* item) { 881 GdkEventExpose* event, DownloadItemGtk* item) {
857 if (!item->theme_provider_->UseGtkTheme()) { 882 if (!item->theme_provider_->UseGtkTheme()) {
858 // The hbox renderer will take care of the border when in GTK mode. 883 // The hbox renderer will take care of the border when in GTK mode.
859 dangerous_nine_box_->RenderToWidget(widget); 884 dangerous_nine_box_->RenderToWidget(widget);
860 } 885 }
861 return FALSE; // Continue propagation. 886 return FALSE; // Continue propagation.
862 } 887 }
863 888
864 // static 889 // static
865 void DownloadItemGtk::OnDangerousAccept(GtkWidget* button, 890 void DownloadItemGtk::OnDangerousAccept(GtkWidget* button,
866 DownloadItemGtk* item) { 891 DownloadItemGtk* item) {
867 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", 892 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download",
868 base::Time::Now() - item->creation_time_); 893 base::Time::Now() - item->creation_time_);
869 item->get_download()->manager()->DangerousDownloadValidated( 894 item->get_download()->manager()->DangerousDownloadValidated(
870 item->get_download()); 895 item->get_download());
871 } 896 }
872 897
873 // static 898 // static
874 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button, 899 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button,
875 DownloadItemGtk* item) { 900 DownloadItemGtk* item) {
876 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", 901 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download",
877 base::Time::Now() - item->creation_time_); 902 base::Time::Now() - item->creation_time_);
878 if (item->get_download()->state() == DownloadItem::IN_PROGRESS) 903 if (item->get_download()->state() == DownloadItem::IN_PROGRESS)
879 item->get_download()->Cancel(true); 904 item->get_download()->Cancel(true);
880 item->get_download()->Remove(true); 905 item->get_download()->Remove(true);
881 } 906 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698