blob: 1b793dc03b306363d8bfd9158dd85cbeb528a402 [file] [log] [blame]
[email protected]5043b9832009-03-04 23:24:471// 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
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_
6#define CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_
7
8#include <gtk/gtk.h>
9
[email protected]5fdafb22009-07-13 23:23:0810#include <string>
11
[email protected]220705c2009-05-05 04:52:1112#include "app/animation.h"
[email protected]8c9e6142010-05-05 00:47:4513#include "app/gtk_signal.h"
[email protected]5043b9832009-03-04 23:24:4714#include "base/scoped_ptr.h"
[email protected]f6fb6852009-08-11 22:25:0715#include "base/time.h"
[email protected]6c69796d2010-07-16 21:41:1616#include "chrome/browser/download/download_item.h"
[email protected]dcefa302009-05-20 00:24:3917#include "chrome/browser/icon_manager.h"
[email protected]5fdafb22009-07-13 23:23:0818#include "chrome/common/notification_observer.h"
19#include "chrome/common/notification_registrar.h"
[email protected]59560e0b2009-06-04 03:30:2220#include "chrome/common/owned_widget_gtk.h"
[email protected]5043b9832009-03-04 23:24:4721
22class BaseDownloadItemModel;
[email protected]001c3c02009-03-06 00:59:2223class DownloadShelfContextMenuGtk;
[email protected]b2cc4352009-05-05 20:50:4424class DownloadShelfGtk;
[email protected]5fdafb22009-07-13 23:23:0825class GtkThemeProvider;
[email protected]5043b9832009-03-04 23:24:4726class NineBox;
[email protected]dcefa302009-05-20 00:24:3927class SkBitmap;
[email protected]1aab6b892009-04-22 18:54:1128class SlideAnimation;
[email protected]5043b9832009-03-04 23:24:4729
[email protected]1aab6b892009-04-22 18:54:1130class DownloadItemGtk : public DownloadItem::Observer,
[email protected]5fdafb22009-07-13 23:23:0831 public AnimationDelegate,
32 public NotificationObserver {
[email protected]5043b9832009-03-04 23:24:4733 public:
[email protected]3a164a12009-03-05 03:28:2234 // DownloadItemGtk takes ownership of |download_item_model|.
[email protected]b2cc4352009-05-05 20:50:4435 DownloadItemGtk(DownloadShelfGtk* parent_shelf,
36 BaseDownloadItemModel* download_item_model);
[email protected]5043b9832009-03-04 23:24:4737
[email protected]59560e0b2009-06-04 03:30:2238 // Destroys all widgets belonging to this DownloadItemGtk.
[email protected]6f35e04b2009-03-05 20:36:3139 ~DownloadItemGtk();
40
[email protected]1aab6b892009-04-22 18:54:1141 // DownloadItem::Observer implementation.
[email protected]5228d562009-03-26 18:50:5142 virtual void OnDownloadUpdated(DownloadItem* download);
[email protected]6aa4a1c02010-01-15 18:49:5843 virtual void OnDownloadFileCompleted(DownloadItem* download) { }
[email protected]45e3c122009-04-07 19:58:0344 virtual void OnDownloadOpened(DownloadItem* download) { }
[email protected]5228d562009-03-26 18:50:5145
[email protected]1aab6b892009-04-22 18:54:1146 // AnimationDelegate implementation.
47 virtual void AnimationProgressed(const Animation* animation);
48
[email protected]5fdafb22009-07-13 23:23:0849 // Overridden from NotificationObserver:
50 virtual void Observe(NotificationType type,
51 const NotificationSource& source,
52 const NotificationDetails& details);
[email protected]d9954792009-07-10 19:55:3053
[email protected]dcefa302009-05-20 00:24:3954 // Called when the icon manager has finished loading the icon. We take
55 // ownership of |icon_bitmap|.
[email protected]d0aa2032010-04-22 22:46:4256 void OnLoadSmallIconComplete(IconManager::Handle handle,
57 SkBitmap* icon_bitmap);
58 void OnLoadLargeIconComplete(IconManager::Handle handle,
59 SkBitmap* icon_bitmap);
[email protected]dcefa302009-05-20 00:24:3960
[email protected]848364342009-08-27 21:13:4261 // Returns the DownloadItem model object belonging to this item.
62 DownloadItem* get_download();
63
[email protected]5043b9832009-03-04 23:24:4764 private:
[email protected]9d8ad7632009-05-21 17:55:4065 friend class DownloadShelfContextMenuGtk;
66
[email protected]a0a9577b2009-05-27 23:52:3267 // Returns true IFF the download is dangerous and unconfirmed.
68 bool IsDangerous();
69
[email protected]79114c02009-05-11 22:18:1970 // Functions for controlling the progress animation.
71 // Repaint the download progress.
72 void UpdateDownloadProgress();
73
74 // Starts a repeating timer for UpdateDownloadProgress.
75 void StartDownloadProgress();
76
77 // Stops the repeating timer.
78 void StopDownloadProgress();
79
[email protected]dcefa302009-05-20 00:24:3980 // Ask the icon manager to asynchronously start loading the icon for the file.
81 void LoadIcon();
82
[email protected]113a42f32010-04-14 20:08:2083 // Sets the tooltip on the download button.
84 void UpdateTooltip();
85
[email protected]d9954792009-07-10 19:55:3086 // Sets the name label to the correct color.
87 void UpdateNameLabel();
88
[email protected]74f7df7d2010-07-16 18:58:2289 // Sets the text of |status_label_| with the correct color.
90 void UpdateStatusLabel(const std::string& status_text);
[email protected]d9954792009-07-10 19:55:3091
[email protected]92d7e3cf2009-08-24 21:07:2392 // Sets the components of the danger warning.
93 void UpdateDangerWarning();
94
[email protected]5043b9832009-03-04 23:24:4795 static void InitNineBoxes();
96
[email protected]c451714f2009-08-21 21:51:5797 // Draws everything in GTK rendering mode.
[email protected]8c9e6142010-05-05 00:47:4598 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnHboxExpose,
99 GdkEventExpose*);
[email protected]c451714f2009-08-21 21:51:57100
101 // Used for the download item's body and menu button in chrome theme mode.
[email protected]8c9e6142010-05-05 00:47:45102 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnExpose, GdkEventExpose*);
[email protected]5043b9832009-03-04 23:24:47103
[email protected]de86a8512009-05-28 20:29:40104 // Called when |body_| is clicked.
[email protected]8c9e6142010-05-05 00:47:45105 CHROMEGTK_CALLBACK_0(DownloadItemGtk, void, OnClick);
[email protected]de86a8512009-05-28 20:29:40106
[email protected]79114c02009-05-11 22:18:19107 // Used for the download icon.
[email protected]8c9e6142010-05-05 00:47:45108 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnProgressAreaExpose,
109 GdkEventExpose*);
[email protected]79114c02009-05-11 22:18:19110
[email protected]8c9e6142010-05-05 00:47:45111 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnMenuButtonPressEvent,
112 GdkEvent*);
[email protected]001c3c02009-03-06 00:59:22113
[email protected]a0a9577b2009-05-27 23:52:32114 // Dangerous download related. -----------------------------------------------
[email protected]8c9e6142010-05-05 00:47:45115 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnDangerousPromptExpose,
116 GdkEventExpose*);
117 CHROMEGTK_CALLBACK_0(DownloadItemGtk, void, OnDangerousAccept);
118 CHROMEGTK_CALLBACK_0(DownloadItemGtk, void, OnDangerousDecline);
[email protected]a0a9577b2009-05-27 23:52:32119
[email protected]3a164a12009-03-05 03:28:22120 // Nineboxes for the body area.
121 static NineBox* body_nine_box_normal_;
122 static NineBox* body_nine_box_prelight_;
123 static NineBox* body_nine_box_active_;
124
125 // Nineboxes for the menu button.
126 static NineBox* menu_nine_box_normal_;
127 static NineBox* menu_nine_box_prelight_;
128 static NineBox* menu_nine_box_active_;
[email protected]5043b9832009-03-04 23:24:47129
[email protected]a0a9577b2009-05-27 23:52:32130 // Ninebox for the background of the dangerous download prompt.
131 static NineBox* dangerous_nine_box_;
132
[email protected]b2cc4352009-05-05 20:50:44133 // The shelf on which we are displayed.
134 DownloadShelfGtk* parent_shelf_;
135
[email protected]5043b9832009-03-04 23:24:47136 // The widget that contains the body and menu dropdown.
[email protected]59560e0b2009-06-04 03:30:22137 OwnedWidgetGtk hbox_;
[email protected]5043b9832009-03-04 23:24:47138
139 // The widget that contains the name of the download and the progress
140 // animation.
[email protected]59560e0b2009-06-04 03:30:22141 OwnedWidgetGtk body_;
[email protected]5043b9832009-03-04 23:24:47142
[email protected]1aab6b892009-04-22 18:54:11143 // The GtkLabel that holds the download title text.
144 GtkWidget* name_label_;
145
[email protected]5228d562009-03-26 18:50:51146 // The GtkLabel that holds the status text.
147 GtkWidget* status_label_;
148
[email protected]d9954792009-07-10 19:55:30149 // The current text of status label
150 std::string status_text_;
151
[email protected]3a164a12009-03-05 03:28:22152 // The widget that creates a dropdown menu when pressed.
153 GtkWidget* menu_button_;
154
[email protected]c451714f2009-08-21 21:51:57155 // A gtk arrow pointing downward displayed in |menu_button_|. Only displayed
156 // in GTK mode.
157 GtkWidget* arrow_;
158
[email protected]9d8ad7632009-05-21 17:55:40159 // Whether the menu is currently showing for |menu_button_|. Affects how we
160 // draw the button.
161 bool menu_showing_;
162
[email protected]d9954792009-07-10 19:55:30163 // Whether we should use the GTK text color
[email protected]5fdafb22009-07-13 23:23:08164 GtkThemeProvider* theme_provider_;
[email protected]d9954792009-07-10 19:55:30165
[email protected]79114c02009-05-11 22:18:19166 // The widget that contains the animation progress and the file's icon
167 // (as well as the complete animation).
[email protected]59560e0b2009-06-04 03:30:22168 OwnedWidgetGtk progress_area_;
[email protected]79114c02009-05-11 22:18:19169
170 // In degrees. Only used for downloads with no known total size.
171 int progress_angle_;
172
[email protected]001c3c02009-03-06 00:59:22173 // The menu that pops down when the user presses |menu_button_|. We do not
174 // create this until the first time we actually need it.
175 scoped_ptr<DownloadShelfContextMenuGtk> menu_;
176
[email protected]5043b9832009-03-04 23:24:47177 // The download item model we represent.
178 scoped_ptr<BaseDownloadItemModel> download_model_;
179
[email protected]a0a9577b2009-05-27 23:52:32180 // The dangerous download dialog. This will be null for safe downloads.
181 GtkWidget* dangerous_prompt_;
[email protected]92d7e3cf2009-08-24 21:07:23182 GtkWidget* dangerous_image_;
183 GtkWidget* dangerous_label_;
[email protected]a0a9577b2009-05-27 23:52:32184
185 // An hbox for holding components of the dangerous download dialog.
186 GtkWidget* dangerous_hbox_;
[email protected]c4bb3c42009-06-01 22:54:16187 int dangerous_hbox_start_width_;
[email protected]a0a9577b2009-05-27 23:52:32188 int dangerous_hbox_full_width_;
189
[email protected]1aab6b892009-04-22 18:54:11190 // The animation when this item is first added to the shelf.
191 scoped_ptr<SlideAnimation> new_item_animation_;
[email protected]79114c02009-05-11 22:18:19192
193 // Progress animation.
194 base::RepeatingTimer<DownloadItemGtk> progress_timer_;
195
196 // Animation for download complete.
197 scoped_ptr<SlideAnimation> complete_animation_;
[email protected]dcefa302009-05-20 00:24:39198
[email protected]d0aa2032010-04-22 22:46:42199 // The file icon for the download. May be null. The small version is used
200 // for display in the shelf; the large version is for use as a drag icon.
201 SkBitmap* icon_small_;
202 SkBitmap* icon_large_;
[email protected]848364342009-08-27 21:13:42203
[email protected]f6fb6852009-08-11 22:25:07204 // The last download file path for which we requested an icon.
205 FilePath icon_filepath_;
[email protected]dcefa302009-05-20 00:24:39206
[email protected]5fdafb22009-07-13 23:23:08207 NotificationRegistrar registrar_;
208
[email protected]f6fb6852009-08-11 22:25:07209 // The time at which we were insantiated.
210 base::Time creation_time_;
211
[email protected]dcefa302009-05-20 00:24:39212 // For canceling an in progress icon request.
213 CancelableRequestConsumerT<int, 0> icon_consumer_;
[email protected]5043b9832009-03-04 23:24:47214};
215
216#endif // CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_