| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 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_DONWLOAD_TAB_VIEW_H__ | |
| 6 #define CHROME_BROWSER_DONWLOAD_TAB_VIEW_H__ | |
| 7 | |
| 8 #include "base/hash_tables.h" | |
| 9 #include "chrome/browser/cancelable_request.h" | |
| 10 #include "chrome/browser/download_manager.h" | |
| 11 #include "chrome/browser/download_util.h" | |
| 12 #include "chrome/browser/icon_manager.h" | |
| 13 #include "chrome/browser/native_ui_contents.h" | |
| 14 #include "chrome/views/event.h" | |
| 15 #include "chrome/views/label.h" | |
| 16 #include "chrome/views/link.h" | |
| 17 #include "chrome/views/scroll_view.h" | |
| 18 | |
| 19 class DownloadTabView; | |
| 20 class SkBitmap; | |
| 21 class Task; | |
| 22 | |
| 23 namespace base { | |
| 24 class Timer; | |
| 25 } | |
| 26 | |
| 27 class DownloadItemTabView : public ChromeViews::View, | |
| 28 public ChromeViews::LinkController { | |
| 29 public: | |
| 30 DownloadItemTabView(); | |
| 31 virtual ~DownloadItemTabView(); | |
| 32 | |
| 33 // View overrides | |
| 34 virtual void Layout(); | |
| 35 virtual void Paint(ChromeCanvas* canvas); | |
| 36 void PaintBackground(ChromeCanvas* canvas); | |
| 37 virtual void GetPreferredSize(CSize* out); | |
| 38 virtual void DidChangeBounds(const CRect& previous, const CRect& current); | |
| 39 virtual bool OnMousePressed(const ChromeViews::MouseEvent& event); | |
| 40 virtual bool OnMouseDragged(const ChromeViews::MouseEvent& event); | |
| 41 | |
| 42 // Mode specific layouts | |
| 43 void LayoutDate(); | |
| 44 void LayoutComplete(); | |
| 45 void LayoutCancelled(); | |
| 46 void LayoutInProgress(); | |
| 47 | |
| 48 // LinkController overrides | |
| 49 virtual void LinkActivated(ChromeViews::Link* source, int event_flags); | |
| 50 | |
| 51 // Used to set our model temporarily during layout and paint operations | |
| 52 void SetModel(DownloadItem* model, DownloadTabView* parent); | |
| 53 | |
| 54 private: | |
| 55 // Our model. | |
| 56 DownloadItem* model_; | |
| 57 | |
| 58 // Containing view. | |
| 59 DownloadTabView* parent_; | |
| 60 | |
| 61 // Time display. | |
| 62 ChromeViews::Label* since_; | |
| 63 ChromeViews::Label* date_; | |
| 64 | |
| 65 // The name of the file. Clicking this link will open the download. | |
| 66 ChromeViews::Link* file_name_; | |
| 67 | |
| 68 // The name of the downloaded URL. | |
| 69 ChromeViews::Label* download_url_; | |
| 70 | |
| 71 // The current status of the download. | |
| 72 ChromeViews::Label* time_remaining_; | |
| 73 ChromeViews::Label* download_progress_; | |
| 74 | |
| 75 // Actions that can be initiated. | |
| 76 ChromeViews::Link* pause_; | |
| 77 ChromeViews::Link* cancel_; | |
| 78 ChromeViews::Link* show_; | |
| 79 | |
| 80 DISALLOW_EVIL_CONSTRUCTORS(DownloadItemTabView); | |
| 81 }; | |
| 82 | |
| 83 | |
| 84 // A view that manages each of the individual download views | |
| 85 // (DownloadItemTabView) in the destination tab. | |
| 86 class DownloadTabView : public ChromeViews::View, | |
| 87 public DownloadItem::Observer, | |
| 88 public DownloadManager::Observer { | |
| 89 public: | |
| 90 DownloadTabView(DownloadManager* model); | |
| 91 ~DownloadTabView(); | |
| 92 | |
| 93 void Initialize(); | |
| 94 | |
| 95 DownloadManager* model() const { return model_; } | |
| 96 | |
| 97 // View overrides | |
| 98 virtual void DidChangeBounds(const CRect& previous, const CRect& current); | |
| 99 virtual void Layout(); | |
| 100 virtual void Paint(ChromeCanvas* canvas); | |
| 101 virtual bool GetFloatingViewIDForPoint(int x, int y, int* id); | |
| 102 virtual bool EnumerateFloatingViews( | |
| 103 ChromeViews::View::FloatingViewPosition position, | |
| 104 int starting_id, int* id); | |
| 105 virtual ChromeViews::View* ValidateFloatingViewForID(int id); | |
| 106 | |
| 107 // DownloadItem::Observer interface | |
| 108 virtual void OnDownloadUpdated(DownloadItem* download); | |
| 109 | |
| 110 // DownloadManager::Observer interface | |
| 111 virtual void ModelChanged(); | |
| 112 virtual void SetDownloads(std::vector<DownloadItem*>& downloads); | |
| 113 | |
| 114 // IconManager callback interface | |
| 115 void OnExtractIconComplete(IconManager::Handle handle, SkBitmap* icon_bitmap); | |
| 116 | |
| 117 // Progress animation task interface and timer management. | |
| 118 void UpdateDownloadProgress(); | |
| 119 void StartDownloadProgress(); | |
| 120 void StopDownloadProgress(); | |
| 121 | |
| 122 // Returns a non owning pointer to an icon in the icon_cache_. If | |
| 123 // that file extension doesn't exist in our cache, we query Windows | |
| 124 // and add it to our cache. Returns NULL if we can't determine the | |
| 125 // icon. | |
| 126 SkBitmap* LookupIcon(DownloadItem* download); | |
| 127 | |
| 128 // Determine if we should draw the date beside a particular download | |
| 129 bool ShouldDrawDateForDownload(DownloadItem* download); | |
| 130 | |
| 131 virtual int GetPageScrollIncrement(ChromeViews::ScrollView* scroll_view, | |
| 132 bool is_horizontal, bool is_positive); | |
| 133 virtual int GetLineScrollIncrement(ChromeViews::ScrollView* scroll_view, | |
| 134 bool is_horizontal, bool is_positive); | |
| 135 | |
| 136 int start_angle() const { return start_angle_; } | |
| 137 | |
| 138 // Called by a DownloadItemTabView when it becomes selected. Passing a NULL | |
| 139 // for 'download' causes any selected download to become unselected. | |
| 140 void ItemBecameSelected(const DownloadItem* download); | |
| 141 bool ItemIsSelected(DownloadItem* download); | |
| 142 | |
| 143 // The destination view's search box text has changed. | |
| 144 void SetSearchText(const std::wstring& search_text); | |
| 145 | |
| 146 private: | |
| 147 // Creates and attaches to the view the floating view at |index|. | |
| 148 ChromeViews::View* CreateFloatingViewForIndex(int index); | |
| 149 | |
| 150 // Utility functions for operating on DownloadItemTabViews by index. | |
| 151 void SchedulePaintForViewAtIndex(int index); | |
| 152 int GetYPositionForIndex(int index); | |
| 153 | |
| 154 // Initiates an asynchronous icon extraction. | |
| 155 void LoadIcon(DownloadItem* download); | |
| 156 | |
| 157 // Clears the list of "in progress" downloads and removes the this | |
| 158 // DownloadTabView from their observer list. | |
| 159 void ClearDownloadInProgress(); | |
| 160 | |
| 161 // Our model | |
| 162 DownloadManager* model_; | |
| 163 | |
| 164 // For drawing individual download items | |
| 165 DownloadItemTabView download_renderer_; | |
| 166 | |
| 167 // The current set of visible DownloadItems for this view received from the | |
| 168 // DownloadManager. DownloadManager owns the DownloadItems. The vector is | |
| 169 // kept in order, sorted by ascending start time. | |
| 170 typedef std::vector<DownloadItem*> OrderedDownloads; | |
| 171 OrderedDownloads downloads_; | |
| 172 | |
| 173 // Progress animations | |
| 174 base::RepeatingTimer<DownloadTabView> progress_timer_; | |
| 175 | |
| 176 // Since this view manages the progress animation timers for all the floating | |
| 177 // views, we need to track the current in progress downloads. This container | |
| 178 // does not own the DownloadItems. | |
| 179 base::hash_set<DownloadItem*> in_progress_; | |
| 180 | |
| 181 // Provide a start position for downloads with no known size. | |
| 182 int start_angle_; | |
| 183 | |
| 184 ChromeViews::FixedRowHeightScrollHelper scroll_helper_; | |
| 185 | |
| 186 // Keep track of the currently selected view, so that we can inform it when | |
| 187 // the user changes the selection. | |
| 188 int selected_index_; | |
| 189 | |
| 190 // Text in the download search box input by the user. | |
| 191 std::wstring search_text_; | |
| 192 | |
| 193 // For requesting icons from the IconManager. | |
| 194 CancelableRequestConsumerT<DownloadItem*, 0> icon_consumer_; | |
| 195 | |
| 196 DISALLOW_EVIL_CONSTRUCTORS(DownloadTabView); | |
| 197 }; | |
| 198 | |
| 199 // DownloadTabUI ------------------------------------------------------------- | |
| 200 | |
| 201 // DownloadTabUI provides the glue to make DownloadTabView available in | |
| 202 // NativeUIContents. | |
| 203 | |
| 204 class DownloadTabUI : public NativeUI, | |
| 205 public SearchableUIContainer::Delegate, | |
| 206 public NotificationObserver { | |
| 207 public: | |
| 208 explicit DownloadTabUI(NativeUIContents* contents); | |
| 209 virtual ~DownloadTabUI(); | |
| 210 | |
| 211 virtual const std::wstring GetTitle() const; | |
| 212 virtual const int GetFavIconID() const; | |
| 213 virtual const int GetSectionIconID() const; | |
| 214 virtual const std::wstring GetSearchButtonText() const; | |
| 215 virtual ChromeViews::View* GetView(); | |
| 216 virtual void WillBecomeVisible(NativeUIContents* parent); | |
| 217 virtual void WillBecomeInvisible(NativeUIContents* parent); | |
| 218 virtual void Navigate(const PageState& state); | |
| 219 virtual bool SetInitialFocus(); | |
| 220 | |
| 221 // Return the URL that can be used to show this view in a NativeUIContents. | |
| 222 static GURL GetURL(); | |
| 223 | |
| 224 // Return the NativeUIFactory object for application views. This object is | |
| 225 // owned by the caller. | |
| 226 static NativeUIFactory* GetNativeUIFactory(); | |
| 227 | |
| 228 private: | |
| 229 // Sent from the search box, updates the search text appropriately. | |
| 230 virtual void DoSearch(const std::wstring& new_text); | |
| 231 | |
| 232 // NotificationObserver method, updates loading state based on whether | |
| 233 // any downloads are in progress. | |
| 234 virtual void Observe(NotificationType type, | |
| 235 const NotificationSource& source, | |
| 236 const NotificationDetails& details); | |
| 237 | |
| 238 Profile* profile() const { return contents_->profile(); } | |
| 239 | |
| 240 // Our host. | |
| 241 NativeUIContents* contents_; | |
| 242 | |
| 243 // The view we return from GetView. The contents of this is the | |
| 244 // bookmarks_view_ | |
| 245 SearchableUIContainer searchable_container_; | |
| 246 | |
| 247 DownloadTabView* download_tab_view_; | |
| 248 | |
| 249 DISALLOW_EVIL_CONSTRUCTORS(DownloadTabUI); | |
| 250 }; | |
| 251 | |
| 252 #endif // CHROME_BROWSER_DONWLOAD_TAB_VIEW_H__ | |
| OLD | NEW |