| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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_UI_GTK_DOWNLOAD_DOWNLOAD_ITEM_GTK_H_ | |
| 6 #define CHROME_BROWSER_UI_GTK_DOWNLOAD_DOWNLOAD_ITEM_GTK_H_ | |
| 7 | |
| 8 #include <gtk/gtk.h> | |
| 9 | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "base/task/cancelable_task_tracker.h" | |
| 16 #include "base/time/time.h" | |
| 17 #include "base/timer/timer.h" | |
| 18 #include "chrome/browser/download/download_item_model.h" | |
| 19 #include "chrome/browser/icon_manager.h" | |
| 20 #include "content/public/browser/download_item.h" | |
| 21 #include "content/public/browser/notification_observer.h" | |
| 22 #include "content/public/browser/notification_registrar.h" | |
| 23 #include "ui/base/gtk/gtk_signal.h" | |
| 24 #include "ui/base/gtk/owned_widget_gtk.h" | |
| 25 #include "ui/gfx/animation/animation_delegate.h" | |
| 26 #include "ui/gfx/animation/slide_animation.h" | |
| 27 | |
| 28 class DownloadShelfContextMenuGtk; | |
| 29 class DownloadShelfGtk; | |
| 30 class GtkThemeService; | |
| 31 class NineBox; | |
| 32 | |
| 33 namespace gfx { | |
| 34 class Image; | |
| 35 class SlideAnimation; | |
| 36 } | |
| 37 | |
| 38 class DownloadItemGtk : public content::DownloadItem::Observer, | |
| 39 public gfx::AnimationDelegate, | |
| 40 public content::NotificationObserver { | |
| 41 public: | |
| 42 // DownloadItemGtk takes ownership of |download_item_model|. | |
| 43 DownloadItemGtk(DownloadShelfGtk* parent_shelf, | |
| 44 content::DownloadItem* download_item); | |
| 45 | |
| 46 // Destroys all widgets belonging to this DownloadItemGtk. | |
| 47 virtual ~DownloadItemGtk(); | |
| 48 | |
| 49 // content::DownloadItem::Observer implementation. | |
| 50 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; | |
| 51 virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE; | |
| 52 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE; | |
| 53 | |
| 54 // gfx::AnimationDelegate implementation. | |
| 55 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; | |
| 56 | |
| 57 // Overridden from content::NotificationObserver: | |
| 58 virtual void Observe(int type, | |
| 59 const content::NotificationSource& source, | |
| 60 const content::NotificationDetails& details) OVERRIDE; | |
| 61 | |
| 62 // Called when the icon manager has finished loading the icon. We take | |
| 63 // ownership of |icon_bitmap|. | |
| 64 void OnLoadSmallIconComplete(gfx::Image* image); | |
| 65 void OnLoadLargeIconComplete(gfx::Image* image); | |
| 66 | |
| 67 // Returns the DownloadItem model object belonging to this item. | |
| 68 content::DownloadItem* download() { return download_model_.download(); } | |
| 69 | |
| 70 private: | |
| 71 friend class DownloadShelfContextMenuGtk; | |
| 72 | |
| 73 // Functions for controlling the progress animation. | |
| 74 // Repaint the download progress. | |
| 75 void UpdateDownloadProgress(); | |
| 76 | |
| 77 // Starts a repeating timer for UpdateDownloadProgress. | |
| 78 void StartDownloadProgress(); | |
| 79 | |
| 80 // Stops the repeating timer. | |
| 81 void StopDownloadProgress(); | |
| 82 | |
| 83 // Ask the icon manager to asynchronously start loading the icon for the file. | |
| 84 void LoadIcon(); | |
| 85 | |
| 86 // Sets the tooltip on the download button. | |
| 87 void UpdateTooltip(); | |
| 88 | |
| 89 // Sets the name label to the correct color. | |
| 90 void UpdateNameLabel(); | |
| 91 | |
| 92 // Sets the text of |status_label_| with the correct color. | |
| 93 void UpdateStatusLabel(const std::string& status_text); | |
| 94 | |
| 95 // Sets the components of the danger warning. | |
| 96 void UpdateDangerWarning(); | |
| 97 | |
| 98 // Sets the icon for the danger warning dialog. | |
| 99 void UpdateDangerIcon(); | |
| 100 | |
| 101 // Reenables the download button after it has been clicked. | |
| 102 void ReenableHbox(); | |
| 103 | |
| 104 static void InitNineBoxes(); | |
| 105 | |
| 106 // Show popup context menu. If |button| is not NULL, show the menu dropping | |
| 107 // down from |button|. Otherwise, show the menu where the user clicks. | |
| 108 void ShowPopupMenu(GtkWidget* button, GdkEventButton* event); | |
| 109 | |
| 110 // Draws everything in GTK rendering mode. | |
| 111 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnHboxExpose, | |
| 112 GdkEventExpose*); | |
| 113 | |
| 114 // Used for the download item's body and menu button in chrome theme mode. | |
| 115 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnExpose, GdkEventExpose*); | |
| 116 | |
| 117 // Called when |body_| is clicked. | |
| 118 CHROMEGTK_CALLBACK_0(DownloadItemGtk, void, OnClick); | |
| 119 | |
| 120 // Called when |body_| is pressed with mouse button. This function is used to | |
| 121 // show popup menu with right button click. | |
| 122 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnButtonPress, | |
| 123 GdkEventButton*); | |
| 124 | |
| 125 // Used for the download icon. | |
| 126 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnProgressAreaExpose, | |
| 127 GdkEventExpose*); | |
| 128 | |
| 129 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnMenuButtonPressEvent, | |
| 130 GdkEventButton*); | |
| 131 | |
| 132 // Dangerous download related. ----------------------------------------------- | |
| 133 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnDangerousPromptExpose, | |
| 134 GdkEventExpose*); | |
| 135 CHROMEGTK_CALLBACK_0(DownloadItemGtk, void, OnDangerousAccept); | |
| 136 CHROMEGTK_CALLBACK_0(DownloadItemGtk, void, OnDangerousDecline); | |
| 137 | |
| 138 // Nineboxes for the body area. | |
| 139 static NineBox* body_nine_box_normal_; | |
| 140 static NineBox* body_nine_box_prelight_; | |
| 141 static NineBox* body_nine_box_active_; | |
| 142 | |
| 143 // Nineboxes for the menu button. | |
| 144 static NineBox* menu_nine_box_normal_; | |
| 145 static NineBox* menu_nine_box_prelight_; | |
| 146 static NineBox* menu_nine_box_active_; | |
| 147 | |
| 148 // Ninebox for the background of the dangerous download prompt. | |
| 149 static NineBox* dangerous_nine_box_; | |
| 150 | |
| 151 // The shelf on which we are displayed. | |
| 152 DownloadShelfGtk* parent_shelf_; | |
| 153 | |
| 154 // The widget that contains the body and menu dropdown. | |
| 155 ui::OwnedWidgetGtk hbox_; | |
| 156 | |
| 157 // The widget that contains the name of the download and the progress | |
| 158 // animation. | |
| 159 ui::OwnedWidgetGtk body_; | |
| 160 | |
| 161 // The widget that contains the texts of |name_label_| and |status_label_|. | |
| 162 GtkWidget* text_stack_; | |
| 163 | |
| 164 // The GtkLabel that holds the download title text. | |
| 165 GtkWidget* name_label_; | |
| 166 | |
| 167 // The GtkLabel that holds the status text. | |
| 168 GtkWidget* status_label_; | |
| 169 | |
| 170 // The current text of status label | |
| 171 std::string status_text_; | |
| 172 | |
| 173 // The widget that creates a dropdown menu when pressed. | |
| 174 GtkWidget* menu_button_; | |
| 175 | |
| 176 // A gtk arrow pointing downward displayed in |menu_button_|. Only displayed | |
| 177 // in GTK mode. | |
| 178 GtkWidget* arrow_; | |
| 179 | |
| 180 // Whether the menu is currently showing for |menu_button_|. Affects how we | |
| 181 // draw the button. | |
| 182 bool menu_showing_; | |
| 183 | |
| 184 // Whether we should use the GTK text color | |
| 185 GtkThemeService* theme_service_; | |
| 186 | |
| 187 // The widget that contains the animation progress and the file's icon | |
| 188 // (as well as the complete animation). | |
| 189 ui::OwnedWidgetGtk progress_area_; | |
| 190 | |
| 191 // In degrees. Only used for downloads with no known total size. | |
| 192 int progress_angle_; | |
| 193 | |
| 194 // The menu that pops down when the user presses |menu_button_|. We do not | |
| 195 // create this until the first time we actually need it. | |
| 196 scoped_ptr<DownloadShelfContextMenuGtk> menu_; | |
| 197 | |
| 198 // The download item model we represent. | |
| 199 DownloadItemModel download_model_; | |
| 200 | |
| 201 // The dangerous download dialog. This will be null for safe downloads. | |
| 202 GtkWidget* dangerous_prompt_; | |
| 203 GtkWidget* dangerous_image_; | |
| 204 GtkWidget* dangerous_label_; | |
| 205 | |
| 206 // An hbox for holding components of the dangerous download dialog. | |
| 207 ui::OwnedWidgetGtk dangerous_hbox_; | |
| 208 int dangerous_hbox_start_width_; | |
| 209 int dangerous_hbox_full_width_; | |
| 210 | |
| 211 // The animation when this item is first added to the shelf. | |
| 212 scoped_ptr<gfx::SlideAnimation> new_item_animation_; | |
| 213 | |
| 214 // Progress animation. | |
| 215 base::RepeatingTimer<DownloadItemGtk> progress_timer_; | |
| 216 | |
| 217 // Animation for download complete. | |
| 218 gfx::SlideAnimation complete_animation_; | |
| 219 | |
| 220 // The file icon for the download. May be null. The small version is used | |
| 221 // for display in the shelf; the large version is for use as a drag icon. | |
| 222 // These icons are owned by the IconManager (owned by the BrowserProcess). | |
| 223 gfx::Image* icon_small_; | |
| 224 gfx::Image* icon_large_; | |
| 225 | |
| 226 // The last download file path for which we requested an icon. | |
| 227 base::FilePath icon_filepath_; | |
| 228 | |
| 229 content::NotificationRegistrar registrar_; | |
| 230 | |
| 231 // The time at which we were insantiated. | |
| 232 base::Time creation_time_; | |
| 233 | |
| 234 // For canceling an in progress icon request. | |
| 235 base::CancelableTaskTracker cancelable_task_tracker_; | |
| 236 | |
| 237 // Indicates when the download has completed, so we don't redo | |
| 238 // on-completion actions. | |
| 239 bool download_complete_; | |
| 240 | |
| 241 // Whether we are currently disabled as part of opening the downloaded file. | |
| 242 bool disabled_while_opening_; | |
| 243 | |
| 244 // Method factory used to delay reenabling of the item when opening the | |
| 245 // downloaded file. | |
| 246 base::WeakPtrFactory<DownloadItemGtk> weak_ptr_factory_; | |
| 247 }; | |
| 248 | |
| 249 #endif // CHROME_BROWSER_UI_GTK_DOWNLOAD_DOWNLOAD_ITEM_GTK_H_ | |
| OLD | NEW |