OLD | NEW |
1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_ | 5 #ifndef CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_ |
6 #define CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_ | 6 #define CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <gtk/gtk.h> | 9 #include "chrome/browser/ui/gtk/download_item_gtk.h" |
10 | 10 // TODO(msw): remove this file once all includes have been updated. |
11 #include <string> | |
12 | |
13 #include "app/gtk_signal.h" | |
14 #include "base/scoped_ptr.h" | |
15 #include "base/time.h" | |
16 #include "chrome/browser/download/download_item.h" | |
17 #include "chrome/browser/icon_manager.h" | |
18 #include "chrome/browser/gtk/owned_widget_gtk.h" | |
19 #include "chrome/common/notification_observer.h" | |
20 #include "chrome/common/notification_registrar.h" | |
21 #include "ui/base/animation/animation_delegate.h" | |
22 | |
23 class BaseDownloadItemModel; | |
24 class DownloadShelfContextMenuGtk; | |
25 class DownloadShelfGtk; | |
26 class GtkThemeProvider; | |
27 class NineBox; | |
28 class SkBitmap; | |
29 | |
30 namespace ui { | |
31 class SlideAnimation; | |
32 } | |
33 | |
34 class DownloadItemGtk : public DownloadItem::Observer, | |
35 public ui::AnimationDelegate, | |
36 public NotificationObserver { | |
37 public: | |
38 // DownloadItemGtk takes ownership of |download_item_model|. | |
39 DownloadItemGtk(DownloadShelfGtk* parent_shelf, | |
40 BaseDownloadItemModel* download_item_model); | |
41 | |
42 // Destroys all widgets belonging to this DownloadItemGtk. | |
43 ~DownloadItemGtk(); | |
44 | |
45 // DownloadItem::Observer implementation. | |
46 virtual void OnDownloadUpdated(DownloadItem* download); | |
47 virtual void OnDownloadFileCompleted(DownloadItem* download) { } | |
48 virtual void OnDownloadOpened(DownloadItem* download) { } | |
49 | |
50 // ui::AnimationDelegate implementation. | |
51 virtual void AnimationProgressed(const ui::Animation* animation); | |
52 | |
53 // Overridden from NotificationObserver: | |
54 virtual void Observe(NotificationType type, | |
55 const NotificationSource& source, | |
56 const NotificationDetails& details); | |
57 | |
58 // Called when the icon manager has finished loading the icon. We take | |
59 // ownership of |icon_bitmap|. | |
60 void OnLoadSmallIconComplete(IconManager::Handle handle, | |
61 SkBitmap* icon_bitmap); | |
62 void OnLoadLargeIconComplete(IconManager::Handle handle, | |
63 SkBitmap* icon_bitmap); | |
64 | |
65 // Returns the DownloadItem model object belonging to this item. | |
66 DownloadItem* get_download(); | |
67 | |
68 private: | |
69 friend class DownloadShelfContextMenuGtk; | |
70 | |
71 // Returns true IFF the download is dangerous and unconfirmed. | |
72 bool IsDangerous(); | |
73 | |
74 // Functions for controlling the progress animation. | |
75 // Repaint the download progress. | |
76 void UpdateDownloadProgress(); | |
77 | |
78 // Starts a repeating timer for UpdateDownloadProgress. | |
79 void StartDownloadProgress(); | |
80 | |
81 // Stops the repeating timer. | |
82 void StopDownloadProgress(); | |
83 | |
84 // Ask the icon manager to asynchronously start loading the icon for the file. | |
85 void LoadIcon(); | |
86 | |
87 // Sets the tooltip on the download button. | |
88 void UpdateTooltip(); | |
89 | |
90 // Sets the name label to the correct color. | |
91 void UpdateNameLabel(); | |
92 | |
93 // Sets the text of |status_label_| with the correct color. | |
94 void UpdateStatusLabel(const std::string& status_text); | |
95 | |
96 // Sets the components of the danger warning. | |
97 void UpdateDangerWarning(); | |
98 | |
99 static void InitNineBoxes(); | |
100 | |
101 // Draws everything in GTK rendering mode. | |
102 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnHboxExpose, | |
103 GdkEventExpose*); | |
104 | |
105 // Used for the download item's body and menu button in chrome theme mode. | |
106 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnExpose, GdkEventExpose*); | |
107 | |
108 // Called when |body_| is clicked. | |
109 CHROMEGTK_CALLBACK_0(DownloadItemGtk, void, OnClick); | |
110 | |
111 // Used for the download icon. | |
112 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnProgressAreaExpose, | |
113 GdkEventExpose*); | |
114 | |
115 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnMenuButtonPressEvent, | |
116 GdkEvent*); | |
117 | |
118 // Dangerous download related. ----------------------------------------------- | |
119 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnDangerousPromptExpose, | |
120 GdkEventExpose*); | |
121 CHROMEGTK_CALLBACK_0(DownloadItemGtk, void, OnDangerousAccept); | |
122 CHROMEGTK_CALLBACK_0(DownloadItemGtk, void, OnDangerousDecline); | |
123 | |
124 // Nineboxes for the body area. | |
125 static NineBox* body_nine_box_normal_; | |
126 static NineBox* body_nine_box_prelight_; | |
127 static NineBox* body_nine_box_active_; | |
128 | |
129 // Nineboxes for the menu button. | |
130 static NineBox* menu_nine_box_normal_; | |
131 static NineBox* menu_nine_box_prelight_; | |
132 static NineBox* menu_nine_box_active_; | |
133 | |
134 // Ninebox for the background of the dangerous download prompt. | |
135 static NineBox* dangerous_nine_box_; | |
136 | |
137 // The shelf on which we are displayed. | |
138 DownloadShelfGtk* parent_shelf_; | |
139 | |
140 // The widget that contains the body and menu dropdown. | |
141 OwnedWidgetGtk hbox_; | |
142 | |
143 // The widget that contains the name of the download and the progress | |
144 // animation. | |
145 OwnedWidgetGtk body_; | |
146 | |
147 // The GtkLabel that holds the download title text. | |
148 GtkWidget* name_label_; | |
149 | |
150 // The GtkLabel that holds the status text. | |
151 GtkWidget* status_label_; | |
152 | |
153 // The current text of status label | |
154 std::string status_text_; | |
155 | |
156 // The widget that creates a dropdown menu when pressed. | |
157 GtkWidget* menu_button_; | |
158 | |
159 // A gtk arrow pointing downward displayed in |menu_button_|. Only displayed | |
160 // in GTK mode. | |
161 GtkWidget* arrow_; | |
162 | |
163 // Whether the menu is currently showing for |menu_button_|. Affects how we | |
164 // draw the button. | |
165 bool menu_showing_; | |
166 | |
167 // Whether we should use the GTK text color | |
168 GtkThemeProvider* theme_provider_; | |
169 | |
170 // The widget that contains the animation progress and the file's icon | |
171 // (as well as the complete animation). | |
172 OwnedWidgetGtk progress_area_; | |
173 | |
174 // In degrees. Only used for downloads with no known total size. | |
175 int progress_angle_; | |
176 | |
177 // The menu that pops down when the user presses |menu_button_|. We do not | |
178 // create this until the first time we actually need it. | |
179 scoped_ptr<DownloadShelfContextMenuGtk> menu_; | |
180 | |
181 // The download item model we represent. | |
182 scoped_ptr<BaseDownloadItemModel> download_model_; | |
183 | |
184 // The dangerous download dialog. This will be null for safe downloads. | |
185 GtkWidget* dangerous_prompt_; | |
186 GtkWidget* dangerous_image_; | |
187 GtkWidget* dangerous_label_; | |
188 | |
189 // An hbox for holding components of the dangerous download dialog. | |
190 GtkWidget* dangerous_hbox_; | |
191 int dangerous_hbox_start_width_; | |
192 int dangerous_hbox_full_width_; | |
193 | |
194 // The animation when this item is first added to the shelf. | |
195 scoped_ptr<ui::SlideAnimation> new_item_animation_; | |
196 | |
197 // Progress animation. | |
198 base::RepeatingTimer<DownloadItemGtk> progress_timer_; | |
199 | |
200 // Animation for download complete. | |
201 scoped_ptr<ui::SlideAnimation> complete_animation_; | |
202 | |
203 // The file icon for the download. May be null. The small version is used | |
204 // for display in the shelf; the large version is for use as a drag icon. | |
205 SkBitmap* icon_small_; | |
206 SkBitmap* icon_large_; | |
207 | |
208 // The last download file path for which we requested an icon. | |
209 FilePath icon_filepath_; | |
210 | |
211 NotificationRegistrar registrar_; | |
212 | |
213 // The time at which we were insantiated. | |
214 base::Time creation_time_; | |
215 | |
216 // For canceling an in progress icon request. | |
217 CancelableRequestConsumerT<int, 0> icon_consumer_; | |
218 }; | |
219 | 11 |
220 #endif // CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_ | 12 #endif // CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_ |
OLD | NEW |