[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 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 |
| 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] | 5fdafb2 | 2009-07-13 23:23:08 | [diff] [blame] | 10 | #include <string> |
| 11 | |
[email protected] | 220705c | 2009-05-05 04:52:11 | [diff] [blame] | 12 | #include "app/animation.h" |
[email protected] | 8c9e614 | 2010-05-05 00:47:45 | [diff] [blame] | 13 | #include "app/gtk_signal.h" |
[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 14 | #include "base/scoped_ptr.h" |
[email protected] | f6fb685 | 2009-08-11 22:25:07 | [diff] [blame] | 15 | #include "base/time.h" |
[email protected] | 6c69796d | 2010-07-16 21:41:16 | [diff] [blame^] | 16 | #include "chrome/browser/download/download_item.h" |
[email protected] | dcefa30 | 2009-05-20 00:24:39 | [diff] [blame] | 17 | #include "chrome/browser/icon_manager.h" |
[email protected] | 5fdafb2 | 2009-07-13 23:23:08 | [diff] [blame] | 18 | #include "chrome/common/notification_observer.h" |
| 19 | #include "chrome/common/notification_registrar.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 20 | #include "chrome/common/owned_widget_gtk.h" |
[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 21 | |
| 22 | class BaseDownloadItemModel; |
[email protected] | 001c3c0 | 2009-03-06 00:59:22 | [diff] [blame] | 23 | class DownloadShelfContextMenuGtk; |
[email protected] | b2cc435 | 2009-05-05 20:50:44 | [diff] [blame] | 24 | class DownloadShelfGtk; |
[email protected] | 5fdafb2 | 2009-07-13 23:23:08 | [diff] [blame] | 25 | class GtkThemeProvider; |
[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 26 | class NineBox; |
[email protected] | dcefa30 | 2009-05-20 00:24:39 | [diff] [blame] | 27 | class SkBitmap; |
[email protected] | 1aab6b89 | 2009-04-22 18:54:11 | [diff] [blame] | 28 | class SlideAnimation; |
[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 29 | |
[email protected] | 1aab6b89 | 2009-04-22 18:54:11 | [diff] [blame] | 30 | class DownloadItemGtk : public DownloadItem::Observer, |
[email protected] | 5fdafb2 | 2009-07-13 23:23:08 | [diff] [blame] | 31 | public AnimationDelegate, |
| 32 | public NotificationObserver { |
[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 33 | public: |
[email protected] | 3a164a1 | 2009-03-05 03:28:22 | [diff] [blame] | 34 | // DownloadItemGtk takes ownership of |download_item_model|. |
[email protected] | b2cc435 | 2009-05-05 20:50:44 | [diff] [blame] | 35 | DownloadItemGtk(DownloadShelfGtk* parent_shelf, |
| 36 | BaseDownloadItemModel* download_item_model); |
[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 37 | |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 38 | // Destroys all widgets belonging to this DownloadItemGtk. |
[email protected] | 6f35e04b | 2009-03-05 20:36:31 | [diff] [blame] | 39 | ~DownloadItemGtk(); |
| 40 | |
[email protected] | 1aab6b89 | 2009-04-22 18:54:11 | [diff] [blame] | 41 | // DownloadItem::Observer implementation. |
[email protected] | 5228d56 | 2009-03-26 18:50:51 | [diff] [blame] | 42 | virtual void OnDownloadUpdated(DownloadItem* download); |
[email protected] | 6aa4a1c0 | 2010-01-15 18:49:58 | [diff] [blame] | 43 | virtual void OnDownloadFileCompleted(DownloadItem* download) { } |
[email protected] | 45e3c12 | 2009-04-07 19:58:03 | [diff] [blame] | 44 | virtual void OnDownloadOpened(DownloadItem* download) { } |
[email protected] | 5228d56 | 2009-03-26 18:50:51 | [diff] [blame] | 45 | |
[email protected] | 1aab6b89 | 2009-04-22 18:54:11 | [diff] [blame] | 46 | // AnimationDelegate implementation. |
| 47 | virtual void AnimationProgressed(const Animation* animation); |
| 48 | |
[email protected] | 5fdafb2 | 2009-07-13 23:23:08 | [diff] [blame] | 49 | // Overridden from NotificationObserver: |
| 50 | virtual void Observe(NotificationType type, |
| 51 | const NotificationSource& source, |
| 52 | const NotificationDetails& details); |
[email protected] | d995479 | 2009-07-10 19:55:30 | [diff] [blame] | 53 | |
[email protected] | dcefa30 | 2009-05-20 00:24:39 | [diff] [blame] | 54 | // Called when the icon manager has finished loading the icon. We take |
| 55 | // ownership of |icon_bitmap|. |
[email protected] | d0aa203 | 2010-04-22 22:46:42 | [diff] [blame] | 56 | void OnLoadSmallIconComplete(IconManager::Handle handle, |
| 57 | SkBitmap* icon_bitmap); |
| 58 | void OnLoadLargeIconComplete(IconManager::Handle handle, |
| 59 | SkBitmap* icon_bitmap); |
[email protected] | dcefa30 | 2009-05-20 00:24:39 | [diff] [blame] | 60 | |
[email protected] | 84836434 | 2009-08-27 21:13:42 | [diff] [blame] | 61 | // Returns the DownloadItem model object belonging to this item. |
| 62 | DownloadItem* get_download(); |
| 63 | |
[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 64 | private: |
[email protected] | 9d8ad763 | 2009-05-21 17:55:40 | [diff] [blame] | 65 | friend class DownloadShelfContextMenuGtk; |
| 66 | |
[email protected] | a0a9577b | 2009-05-27 23:52:32 | [diff] [blame] | 67 | // Returns true IFF the download is dangerous and unconfirmed. |
| 68 | bool IsDangerous(); |
| 69 | |
[email protected] | 79114c0 | 2009-05-11 22:18:19 | [diff] [blame] | 70 | // 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] | dcefa30 | 2009-05-20 00:24:39 | [diff] [blame] | 80 | // Ask the icon manager to asynchronously start loading the icon for the file. |
| 81 | void LoadIcon(); |
| 82 | |
[email protected] | 113a42f3 | 2010-04-14 20:08:20 | [diff] [blame] | 83 | // Sets the tooltip on the download button. |
| 84 | void UpdateTooltip(); |
| 85 | |
[email protected] | d995479 | 2009-07-10 19:55:30 | [diff] [blame] | 86 | // Sets the name label to the correct color. |
| 87 | void UpdateNameLabel(); |
| 88 | |
[email protected] | 74f7df7d | 2010-07-16 18:58:22 | [diff] [blame] | 89 | // Sets the text of |status_label_| with the correct color. |
| 90 | void UpdateStatusLabel(const std::string& status_text); |
[email protected] | d995479 | 2009-07-10 19:55:30 | [diff] [blame] | 91 | |
[email protected] | 92d7e3cf | 2009-08-24 21:07:23 | [diff] [blame] | 92 | // Sets the components of the danger warning. |
| 93 | void UpdateDangerWarning(); |
| 94 | |
[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 95 | static void InitNineBoxes(); |
| 96 | |
[email protected] | c451714f | 2009-08-21 21:51:57 | [diff] [blame] | 97 | // Draws everything in GTK rendering mode. |
[email protected] | 8c9e614 | 2010-05-05 00:47:45 | [diff] [blame] | 98 | CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnHboxExpose, |
| 99 | GdkEventExpose*); |
[email protected] | c451714f | 2009-08-21 21:51:57 | [diff] [blame] | 100 | |
| 101 | // Used for the download item's body and menu button in chrome theme mode. |
[email protected] | 8c9e614 | 2010-05-05 00:47:45 | [diff] [blame] | 102 | CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnExpose, GdkEventExpose*); |
[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 103 | |
[email protected] | de86a851 | 2009-05-28 20:29:40 | [diff] [blame] | 104 | // Called when |body_| is clicked. |
[email protected] | 8c9e614 | 2010-05-05 00:47:45 | [diff] [blame] | 105 | CHROMEGTK_CALLBACK_0(DownloadItemGtk, void, OnClick); |
[email protected] | de86a851 | 2009-05-28 20:29:40 | [diff] [blame] | 106 | |
[email protected] | 79114c0 | 2009-05-11 22:18:19 | [diff] [blame] | 107 | // Used for the download icon. |
[email protected] | 8c9e614 | 2010-05-05 00:47:45 | [diff] [blame] | 108 | CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnProgressAreaExpose, |
| 109 | GdkEventExpose*); |
[email protected] | 79114c0 | 2009-05-11 22:18:19 | [diff] [blame] | 110 | |
[email protected] | 8c9e614 | 2010-05-05 00:47:45 | [diff] [blame] | 111 | CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnMenuButtonPressEvent, |
| 112 | GdkEvent*); |
[email protected] | 001c3c0 | 2009-03-06 00:59:22 | [diff] [blame] | 113 | |
[email protected] | a0a9577b | 2009-05-27 23:52:32 | [diff] [blame] | 114 | // Dangerous download related. ----------------------------------------------- |
[email protected] | 8c9e614 | 2010-05-05 00:47:45 | [diff] [blame] | 115 | CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnDangerousPromptExpose, |
| 116 | GdkEventExpose*); |
| 117 | CHROMEGTK_CALLBACK_0(DownloadItemGtk, void, OnDangerousAccept); |
| 118 | CHROMEGTK_CALLBACK_0(DownloadItemGtk, void, OnDangerousDecline); |
[email protected] | a0a9577b | 2009-05-27 23:52:32 | [diff] [blame] | 119 | |
[email protected] | 3a164a1 | 2009-03-05 03:28:22 | [diff] [blame] | 120 | // 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] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 129 | |
[email protected] | a0a9577b | 2009-05-27 23:52:32 | [diff] [blame] | 130 | // Ninebox for the background of the dangerous download prompt. |
| 131 | static NineBox* dangerous_nine_box_; |
| 132 | |
[email protected] | b2cc435 | 2009-05-05 20:50:44 | [diff] [blame] | 133 | // The shelf on which we are displayed. |
| 134 | DownloadShelfGtk* parent_shelf_; |
| 135 | |
[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 136 | // The widget that contains the body and menu dropdown. |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 137 | OwnedWidgetGtk hbox_; |
[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 138 | |
| 139 | // The widget that contains the name of the download and the progress |
| 140 | // animation. |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 141 | OwnedWidgetGtk body_; |
[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 142 | |
[email protected] | 1aab6b89 | 2009-04-22 18:54:11 | [diff] [blame] | 143 | // The GtkLabel that holds the download title text. |
| 144 | GtkWidget* name_label_; |
| 145 | |
[email protected] | 5228d56 | 2009-03-26 18:50:51 | [diff] [blame] | 146 | // The GtkLabel that holds the status text. |
| 147 | GtkWidget* status_label_; |
| 148 | |
[email protected] | d995479 | 2009-07-10 19:55:30 | [diff] [blame] | 149 | // The current text of status label |
| 150 | std::string status_text_; |
| 151 | |
[email protected] | 3a164a1 | 2009-03-05 03:28:22 | [diff] [blame] | 152 | // The widget that creates a dropdown menu when pressed. |
| 153 | GtkWidget* menu_button_; |
| 154 | |
[email protected] | c451714f | 2009-08-21 21:51:57 | [diff] [blame] | 155 | // A gtk arrow pointing downward displayed in |menu_button_|. Only displayed |
| 156 | // in GTK mode. |
| 157 | GtkWidget* arrow_; |
| 158 | |
[email protected] | 9d8ad763 | 2009-05-21 17:55:40 | [diff] [blame] | 159 | // Whether the menu is currently showing for |menu_button_|. Affects how we |
| 160 | // draw the button. |
| 161 | bool menu_showing_; |
| 162 | |
[email protected] | d995479 | 2009-07-10 19:55:30 | [diff] [blame] | 163 | // Whether we should use the GTK text color |
[email protected] | 5fdafb2 | 2009-07-13 23:23:08 | [diff] [blame] | 164 | GtkThemeProvider* theme_provider_; |
[email protected] | d995479 | 2009-07-10 19:55:30 | [diff] [blame] | 165 | |
[email protected] | 79114c0 | 2009-05-11 22:18:19 | [diff] [blame] | 166 | // The widget that contains the animation progress and the file's icon |
| 167 | // (as well as the complete animation). |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 168 | OwnedWidgetGtk progress_area_; |
[email protected] | 79114c0 | 2009-05-11 22:18:19 | [diff] [blame] | 169 | |
| 170 | // In degrees. Only used for downloads with no known total size. |
| 171 | int progress_angle_; |
| 172 | |
[email protected] | 001c3c0 | 2009-03-06 00:59:22 | [diff] [blame] | 173 | // 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] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 177 | // The download item model we represent. |
| 178 | scoped_ptr<BaseDownloadItemModel> download_model_; |
| 179 | |
[email protected] | a0a9577b | 2009-05-27 23:52:32 | [diff] [blame] | 180 | // The dangerous download dialog. This will be null for safe downloads. |
| 181 | GtkWidget* dangerous_prompt_; |
[email protected] | 92d7e3cf | 2009-08-24 21:07:23 | [diff] [blame] | 182 | GtkWidget* dangerous_image_; |
| 183 | GtkWidget* dangerous_label_; |
[email protected] | a0a9577b | 2009-05-27 23:52:32 | [diff] [blame] | 184 | |
| 185 | // An hbox for holding components of the dangerous download dialog. |
| 186 | GtkWidget* dangerous_hbox_; |
[email protected] | c4bb3c4 | 2009-06-01 22:54:16 | [diff] [blame] | 187 | int dangerous_hbox_start_width_; |
[email protected] | a0a9577b | 2009-05-27 23:52:32 | [diff] [blame] | 188 | int dangerous_hbox_full_width_; |
| 189 | |
[email protected] | 1aab6b89 | 2009-04-22 18:54:11 | [diff] [blame] | 190 | // The animation when this item is first added to the shelf. |
| 191 | scoped_ptr<SlideAnimation> new_item_animation_; |
[email protected] | 79114c0 | 2009-05-11 22:18:19 | [diff] [blame] | 192 | |
| 193 | // Progress animation. |
| 194 | base::RepeatingTimer<DownloadItemGtk> progress_timer_; |
| 195 | |
| 196 | // Animation for download complete. |
| 197 | scoped_ptr<SlideAnimation> complete_animation_; |
[email protected] | dcefa30 | 2009-05-20 00:24:39 | [diff] [blame] | 198 | |
[email protected] | d0aa203 | 2010-04-22 22:46:42 | [diff] [blame] | 199 | // 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] | 84836434 | 2009-08-27 21:13:42 | [diff] [blame] | 203 | |
[email protected] | f6fb685 | 2009-08-11 22:25:07 | [diff] [blame] | 204 | // The last download file path for which we requested an icon. |
| 205 | FilePath icon_filepath_; |
[email protected] | dcefa30 | 2009-05-20 00:24:39 | [diff] [blame] | 206 | |
[email protected] | 5fdafb2 | 2009-07-13 23:23:08 | [diff] [blame] | 207 | NotificationRegistrar registrar_; |
| 208 | |
[email protected] | f6fb685 | 2009-08-11 22:25:07 | [diff] [blame] | 209 | // The time at which we were insantiated. |
| 210 | base::Time creation_time_; |
| 211 | |
[email protected] | dcefa30 | 2009-05-20 00:24:39 | [diff] [blame] | 212 | // For canceling an in progress icon request. |
| 213 | CancelableRequestConsumerT<int, 0> icon_consumer_; |
[email protected] | 5043b983 | 2009-03-04 23:24:47 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | #endif // CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_ |