OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/download/download_item.h" | 14 #include "chrome/browser/download/download_item.h" |
15 #include "chrome/browser/download/download_item_model.h" | 15 #include "chrome/browser/download/download_item_model.h" |
16 #include "chrome/browser/download/download_manager.h" | 16 #include "chrome/browser/download/download_manager.h" |
17 #include "chrome/browser/download/download_shelf_context_menu.h" | |
18 #include "chrome/browser/download/download_util.h" | 17 #include "chrome/browser/download/download_util.h" |
19 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/gtk/custom_drag.h" | 19 #include "chrome/browser/ui/gtk/custom_drag.h" |
20 #include "chrome/browser/ui/gtk/download/download_shelf_context_menu_gtk.h" | |
21 #include "chrome/browser/ui/gtk/download/download_shelf_gtk.h" | 21 #include "chrome/browser/ui/gtk/download/download_shelf_gtk.h" |
22 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 22 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
23 #include "chrome/browser/ui/gtk/gtk_util.h" | 23 #include "chrome/browser/ui/gtk/gtk_util.h" |
24 #include "chrome/browser/ui/gtk/menu_gtk.h" | |
25 #include "chrome/browser/ui/gtk/nine_box.h" | 24 #include "chrome/browser/ui/gtk/nine_box.h" |
26 #include "content/common/notification_service.h" | 25 #include "content/common/notification_service.h" |
27 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
28 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
29 #include "third_party/skia/include/core/SkBitmap.h" | 28 #include "third_party/skia/include/core/SkBitmap.h" |
30 #include "ui/base/animation/slide_animation.h" | 29 #include "ui/base/animation/slide_animation.h" |
31 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
32 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
33 #include "ui/base/text/text_elider.h" | 32 #include "ui/base/text/text_elider.h" |
34 #include "ui/gfx/canvas_skia_paint.h" | 33 #include "ui/gfx/canvas_skia_paint.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 // for the size of the arrow in GTK theme mode. | 71 // for the size of the arrow in GTK theme mode. |
73 const double kTextSize = 13.4; // 13.4px == 10pt @ 96dpi | 72 const double kTextSize = 13.4; // 13.4px == 10pt @ 96dpi |
74 | 73 |
75 // Darken light-on-dark download status text by 20% before drawing, thus | 74 // Darken light-on-dark download status text by 20% before drawing, thus |
76 // creating a "muted" version of title text for both dark-on-light and | 75 // creating a "muted" version of title text for both dark-on-light and |
77 // light-on-dark themes. | 76 // light-on-dark themes. |
78 static const double kDownloadItemLuminanceMod = 0.8; | 77 static const double kDownloadItemLuminanceMod = 0.8; |
79 | 78 |
80 } // namespace | 79 } // namespace |
81 | 80 |
82 // DownloadShelfContextMenuGtk ------------------------------------------------- | |
83 | |
84 class DownloadShelfContextMenuGtk : public DownloadShelfContextMenu, | |
85 public MenuGtk::Delegate { | |
86 public: | |
87 // The constructor creates the menu and immediately pops it up. | |
88 // |model| is the download item model associated with this context menu, | |
89 // |widget| is the button that popped up this context menu, and |e| is | |
90 // the button press event that caused this menu to be created. | |
91 DownloadShelfContextMenuGtk(BaseDownloadItemModel* model, | |
92 DownloadItemGtk* download_item) | |
93 : DownloadShelfContextMenu(model), | |
94 download_item_gtk_(download_item) { | |
95 } | |
96 | |
97 ~DownloadShelfContextMenuGtk() { | |
98 } | |
99 | |
100 void Popup(GtkWidget* widget, GdkEventButton* event) { | |
101 // Create the menu if we have not created it yet or we created it for | |
102 // an in-progress download that has since completed. | |
103 if (download_item()->IsComplete()) | |
104 menu_.reset(new MenuGtk(this, GetFinishedMenuModel())); | |
105 else | |
106 menu_.reset(new MenuGtk(this, GetInProgressMenuModel())); | |
107 | |
108 if (widget) | |
109 menu_->PopupForWidget(widget, event->button, event->time); | |
110 else | |
111 menu_->PopupAsContext(gfx::Point(event->x_root, event->y_root), | |
112 event->time); | |
113 } | |
114 | |
115 // MenuGtk::Delegate implementation: | |
116 virtual void StoppedShowing() { | |
117 download_item_gtk_->menu_showing_ = false; | |
118 gtk_widget_queue_draw(download_item_gtk_->menu_button_); | |
119 } | |
120 | |
121 virtual GtkWidget* GetImageForCommandId(int command_id) const { | |
122 const char* stock = NULL; | |
123 switch (command_id) { | |
124 case SHOW_IN_FOLDER: | |
125 case OPEN_WHEN_COMPLETE: | |
126 stock = GTK_STOCK_OPEN; | |
127 break; | |
128 | |
129 case CANCEL: | |
130 stock = GTK_STOCK_CANCEL; | |
131 break; | |
132 | |
133 case ALWAYS_OPEN_TYPE: | |
134 case TOGGLE_PAUSE: | |
135 stock = NULL; | |
136 } | |
137 | |
138 return stock ? gtk_image_new_from_stock(stock, GTK_ICON_SIZE_MENU) : NULL; | |
139 } | |
140 | |
141 private: | |
142 // The menu we show on Popup(). We keep a pointer to it for a couple reasons: | |
143 // * we don't want to have to recreate the menu every time it's popped up. | |
144 // * we have to keep it in scope for longer than the duration of Popup(), or | |
145 // completing the user-selected action races against the menu's | |
146 // destruction. | |
147 scoped_ptr<MenuGtk> menu_; | |
148 | |
149 // The download item that created us. | |
150 DownloadItemGtk* download_item_gtk_; | |
151 }; | |
152 | |
153 // DownloadItemGtk ------------------------------------------------------------- | 81 // DownloadItemGtk ------------------------------------------------------------- |
asanka
2011/05/20 21:23:52
Nit: We don't need this section header comment her
tfarina
2011/05/20 22:15:47
Done.
| |
154 | 82 |
155 NineBox* DownloadItemGtk::body_nine_box_normal_ = NULL; | 83 NineBox* DownloadItemGtk::body_nine_box_normal_ = NULL; |
156 NineBox* DownloadItemGtk::body_nine_box_prelight_ = NULL; | 84 NineBox* DownloadItemGtk::body_nine_box_prelight_ = NULL; |
157 NineBox* DownloadItemGtk::body_nine_box_active_ = NULL; | 85 NineBox* DownloadItemGtk::body_nine_box_active_ = NULL; |
158 | 86 |
159 NineBox* DownloadItemGtk::menu_nine_box_normal_ = NULL; | 87 NineBox* DownloadItemGtk::menu_nine_box_normal_ = NULL; |
160 NineBox* DownloadItemGtk::menu_nine_box_prelight_ = NULL; | 88 NineBox* DownloadItemGtk::menu_nine_box_prelight_ = NULL; |
161 NineBox* DownloadItemGtk::menu_nine_box_active_ = NULL; | 89 NineBox* DownloadItemGtk::menu_nine_box_active_ = NULL; |
162 | 90 |
163 NineBox* DownloadItemGtk::dangerous_nine_box_ = NULL; | 91 NineBox* DownloadItemGtk::dangerous_nine_box_ = NULL; |
164 | 92 |
165 DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf, | 93 DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf, |
166 BaseDownloadItemModel* download_model) | 94 BaseDownloadItemModel* download_model) |
167 : parent_shelf_(parent_shelf), | 95 : parent_shelf_(parent_shelf), |
168 arrow_(NULL), | 96 arrow_(NULL), |
169 menu_showing_(false), | 97 menu_showing_(false), |
170 theme_service_(GtkThemeService::GetFrom( | 98 theme_service_( |
171 parent_shelf->browser()->profile())), | 99 GtkThemeService::GetFrom(parent_shelf->browser()->profile())), |
172 progress_angle_(download_util::kStartAngleDegrees), | 100 progress_angle_(download_util::kStartAngleDegrees), |
173 download_model_(download_model), | 101 download_model_(download_model), |
174 dangerous_prompt_(NULL), | 102 dangerous_prompt_(NULL), |
175 dangerous_label_(NULL), | 103 dangerous_label_(NULL), |
176 complete_animation_(this), | 104 complete_animation_(this), |
177 icon_small_(NULL), | 105 icon_small_(NULL), |
178 icon_large_(NULL), | 106 icon_large_(NULL), |
179 creation_time_(base::Time::Now()), | 107 creation_time_(base::Time::Now()), |
180 download_complete_(false) { | 108 download_complete_(false) { |
181 LoadIcon(); | 109 LoadIcon(); |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
932 get_download()->DangerousDownloadValidated(); | 860 get_download()->DangerousDownloadValidated(); |
933 } | 861 } |
934 | 862 |
935 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { | 863 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { |
936 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 864 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
937 base::Time::Now() - creation_time_); | 865 base::Time::Now() - creation_time_); |
938 if (get_download()->IsPartialDownload()) | 866 if (get_download()->IsPartialDownload()) |
939 get_download()->Cancel(true); | 867 get_download()->Cancel(true); |
940 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 868 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
941 } | 869 } |
OLD | NEW |