Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / gtk / download / download_item_gtk.h
blobaec4f95a5354fd91219555920f6a363e586a4ea2
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.
5 #ifndef CHROME_BROWSER_UI_GTK_DOWNLOAD_DOWNLOAD_ITEM_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_DOWNLOAD_DOWNLOAD_ITEM_GTK_H_
8 #include <gtk/gtk.h>
10 #include <string>
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/time/time.h"
16 #include "base/timer/timer.h"
17 #include "chrome/browser/download/download_item_model.h"
18 #include "chrome/browser/icon_manager.h"
19 #include "chrome/common/cancelable_task_tracker.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"
28 class DownloadShelfContextMenuGtk;
29 class DownloadShelfGtk;
30 class GtkThemeService;
31 class NineBox;
33 namespace gfx {
34 class Image;
35 class SlideAnimation;
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);
46 // Destroys all widgets belonging to this DownloadItemGtk.
47 virtual ~DownloadItemGtk();
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;
54 // gfx::AnimationDelegate implementation.
55 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
57 // Overridden from content::NotificationObserver:
58 virtual void Observe(int type,
59 const content::NotificationSource& source,
60 const content::NotificationDetails& details) OVERRIDE;
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);
67 // Returns the DownloadItem model object belonging to this item.
68 content::DownloadItem* download() { return download_model_.download(); }
70 private:
71 friend class DownloadShelfContextMenuGtk;
73 // Functions for controlling the progress animation.
74 // Repaint the download progress.
75 void UpdateDownloadProgress();
77 // Starts a repeating timer for UpdateDownloadProgress.
78 void StartDownloadProgress();
80 // Stops the repeating timer.
81 void StopDownloadProgress();
83 // Ask the icon manager to asynchronously start loading the icon for the file.
84 void LoadIcon();
86 // Sets the tooltip on the download button.
87 void UpdateTooltip();
89 // Sets the name label to the correct color.
90 void UpdateNameLabel();
92 // Sets the text of |status_label_| with the correct color.
93 void UpdateStatusLabel(const std::string& status_text);
95 // Sets the components of the danger warning.
96 void UpdateDangerWarning();
98 // Sets the icon for the danger warning dialog.
99 void UpdateDangerIcon();
101 // Reenables the download button after it has been clicked.
102 void ReenableHbox();
104 static void InitNineBoxes();
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);
110 // Draws everything in GTK rendering mode.
111 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnHboxExpose,
112 GdkEventExpose*);
114 // Used for the download item's body and menu button in chrome theme mode.
115 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnExpose, GdkEventExpose*);
117 // Called when |body_| is clicked.
118 CHROMEGTK_CALLBACK_0(DownloadItemGtk, void, OnClick);
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*);
125 // Used for the download icon.
126 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnProgressAreaExpose,
127 GdkEventExpose*);
129 CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnMenuButtonPressEvent,
130 GdkEventButton*);
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);
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_;
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_;
148 // Ninebox for the background of the dangerous download prompt.
149 static NineBox* dangerous_nine_box_;
151 // The shelf on which we are displayed.
152 DownloadShelfGtk* parent_shelf_;
154 // The widget that contains the body and menu dropdown.
155 ui::OwnedWidgetGtk hbox_;
157 // The widget that contains the name of the download and the progress
158 // animation.
159 ui::OwnedWidgetGtk body_;
161 // The widget that contains the texts of |name_label_| and |status_label_|.
162 GtkWidget* text_stack_;
164 // The GtkLabel that holds the download title text.
165 GtkWidget* name_label_;
167 // The GtkLabel that holds the status text.
168 GtkWidget* status_label_;
170 // The current text of status label
171 std::string status_text_;
173 // The widget that creates a dropdown menu when pressed.
174 GtkWidget* menu_button_;
176 // A gtk arrow pointing downward displayed in |menu_button_|. Only displayed
177 // in GTK mode.
178 GtkWidget* arrow_;
180 // Whether the menu is currently showing for |menu_button_|. Affects how we
181 // draw the button.
182 bool menu_showing_;
184 // Whether we should use the GTK text color
185 GtkThemeService* theme_service_;
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_;
191 // In degrees. Only used for downloads with no known total size.
192 int progress_angle_;
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_;
198 // The download item model we represent.
199 DownloadItemModel download_model_;
201 // The dangerous download dialog. This will be null for safe downloads.
202 GtkWidget* dangerous_prompt_;
203 GtkWidget* dangerous_image_;
204 GtkWidget* dangerous_label_;
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_;
211 // The animation when this item is first added to the shelf.
212 scoped_ptr<gfx::SlideAnimation> new_item_animation_;
214 // Progress animation.
215 base::RepeatingTimer<DownloadItemGtk> progress_timer_;
217 // Animation for download complete.
218 gfx::SlideAnimation complete_animation_;
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_;
226 // The last download file path for which we requested an icon.
227 base::FilePath icon_filepath_;
229 content::NotificationRegistrar registrar_;
231 // The time at which we were insantiated.
232 base::Time creation_time_;
234 // For canceling an in progress icon request.
235 CancelableTaskTracker cancelable_task_tracker_;
237 // Indicates when the download has completed, so we don't redo
238 // on-completion actions.
239 bool download_complete_;
241 // Whether we are currently disabled as part of opening the downloaded file.
242 bool disabled_while_opening_;
244 // Method factory used to delay reenabling of the item when opening the
245 // downloaded file.
246 base::WeakPtrFactory<DownloadItemGtk> weak_ptr_factory_;
249 #endif // CHROME_BROWSER_UI_GTK_DOWNLOAD_DOWNLOAD_ITEM_GTK_H_