summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download_tab_view.h
diff options
context:
space:
mode:
authorinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-26 23:55:29 +0000
committerinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-26 23:55:29 +0000
commit09911bf300f1a419907a9412154760efd0b7abc3 (patch)
treef131325fb4e2ad12c6d3504ab75b16dd92facfed /chrome/browser/download_tab_view.h
parent586acc5fe142f498261f52c66862fa417c3d52d2 (diff)
downloadchromium_src-09911bf300f1a419907a9412154760efd0b7abc3.zip
chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.tar.gz
chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.tar.bz2
Add chrome to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download_tab_view.h')
-rw-r--r--chrome/browser/download_tab_view.h277
1 files changed, 277 insertions, 0 deletions
diff --git a/chrome/browser/download_tab_view.h b/chrome/browser/download_tab_view.h
new file mode 100644
index 0000000..f237a90
--- /dev/null
+++ b/chrome/browser/download_tab_view.h
@@ -0,0 +1,277 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef CHROME_BROWSER_DONWLOAD_TAB_VIEW_H__
+#define CHROME_BROWSER_DONWLOAD_TAB_VIEW_H__
+
+#include <hash_map>
+#include <hash_set>
+
+#include "chrome/browser/cancelable_request.h"
+#include "chrome/browser/download_manager.h"
+#include "chrome/browser/download_util.h"
+#include "chrome/browser/icon_manager.h"
+#include "chrome/browser/native_ui_contents.h"
+#include "chrome/views/event.h"
+#include "chrome/views/label.h"
+#include "chrome/views/link.h"
+#include "chrome/views/scroll_view.h"
+
+class DownloadTabView;
+class SkBitmap;
+class Task;
+class Timer;
+
+class DownloadItemTabView : public ChromeViews::View,
+ public ChromeViews::LinkController {
+ public:
+ DownloadItemTabView();
+ virtual ~DownloadItemTabView();
+
+ // View overrides
+ virtual void Layout();
+ virtual void Paint(ChromeCanvas* canvas);
+ void PaintBackground(ChromeCanvas* canvas);
+ virtual void GetPreferredSize(CSize* out);
+ virtual void DidChangeBounds(const CRect& previous, const CRect& current);
+ virtual bool OnMousePressed(const ChromeViews::MouseEvent& event);
+ virtual bool OnMouseDragged(const ChromeViews::MouseEvent& event);
+
+ // Mode specific layouts
+ void LayoutDate();
+ void LayoutComplete();
+ void LayoutCancelled();
+ void LayoutInProgress();
+
+ // LinkController overrides
+ virtual void LinkActivated(ChromeViews::Link* source, int event_flags);
+
+ // Used to set our model temporarily during layout and paint operations
+ void SetModel(DownloadItem* model, DownloadTabView* parent);
+
+private:
+ // Our model.
+ DownloadItem* model_;
+
+ // Containing view.
+ DownloadTabView* parent_;
+
+ // Time display.
+ ChromeViews::Label* since_;
+ ChromeViews::Label* date_;
+
+ // The name of the file. Clicking this link will open the download.
+ ChromeViews::Link* file_name_;
+
+ // The name of the downloaded URL.
+ ChromeViews::Label* download_url_;
+
+ // The current status of the download.
+ ChromeViews::Label* time_remaining_;
+ ChromeViews::Label* download_progress_;
+
+ // Actions that can be initiated.
+ ChromeViews::Link* pause_;
+ ChromeViews::Link* cancel_;
+ ChromeViews::Link* show_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(DownloadItemTabView);
+};
+
+
+// A view that manages each of the individual download views
+// (DownloadItemTabView) in the destination tab.
+class DownloadTabView : public ChromeViews::View,
+ public DownloadItem::Observer,
+ public DownloadManager::Observer {
+ public:
+ DownloadTabView(DownloadManager* model);
+ ~DownloadTabView();
+
+ void Initialize();
+
+ DownloadManager* model() const { return model_; }
+
+ // View overrides
+ virtual void DidChangeBounds(const CRect& previous, const CRect& current);
+ virtual void Layout();
+ virtual void Paint(ChromeCanvas* canvas);
+ virtual bool GetFloatingViewIDForPoint(int x, int y, int* id);
+ virtual bool EnumerateFloatingViews(
+ ChromeViews::View::FloatingViewPosition position,
+ int starting_id, int* id);
+ virtual ChromeViews::View* ValidateFloatingViewForID(int id);
+
+ // DownloadItem::Observer interface
+ virtual void OnDownloadUpdated(DownloadItem* download);
+
+ // DownloadManager::Observer interface
+ virtual void ModelChanged();
+ virtual void SetDownloads(std::vector<DownloadItem*>& downloads);
+
+ // IconManager callback interface
+ void OnExtractIconComplete(IconManager::Handle handle, SkBitmap* icon_bitmap);
+
+ // Progress animation task interface and timer management.
+ void UpdateDownloadProgress();
+ void StartDownloadProgress();
+ void StopDownloadProgress();
+
+ // Returns a non owning pointer to an icon in the icon_cache_. If
+ // that file extension doesn't exist in our cache, we query Windows
+ // and add it to our cache. Returns NULL if we can't determine the
+ // icon.
+ SkBitmap* LookupIcon(DownloadItem* download);
+
+ // Determine if we should draw the date beside a particular download
+ bool ShouldDrawDateForDownload(DownloadItem* download);
+
+ virtual int GetPageScrollIncrement(ChromeViews::ScrollView* scroll_view,
+ bool is_horizontal, bool is_positive);
+ virtual int GetLineScrollIncrement(ChromeViews::ScrollView* scroll_view,
+ bool is_horizontal, bool is_positive);
+
+ int start_angle() const { return start_angle_; }
+
+ // Called by a DownloadItemTabView when it becomes selected. Passing a NULL
+ // for 'download' causes any selected download to become unselected.
+ void ItemBecameSelected(const DownloadItem* download);
+ bool ItemIsSelected(DownloadItem* download);
+
+ // The destination view's search box text has changed.
+ void SetSearchText(const std::wstring& search_text);
+
+ private:
+ // Creates and attaches to the view the floating view at |index|.
+ ChromeViews::View* CreateFloatingViewForIndex(int index);
+
+ // Utility functions for operating on DownloadItemTabViews by index.
+ void SchedulePaintForViewAtIndex(int index);
+ int GetYPositionForIndex(int index);
+
+ // Initiates an asynchronous icon extraction.
+ void LoadIcon(DownloadItem* download);
+
+ // Clears the list of "in progress" downloads and removes the this
+ // DownloadTabView from their observer list.
+ void ClearDownloadInProgress();
+
+ // Our model
+ DownloadManager* model_;
+
+ // For drawing individual download items
+ DownloadItemTabView download_renderer_;
+
+ // The current set of visible DownloadItems for this view received from the
+ // DownloadManager. DownloadManager owns the DownloadItems. The vector is
+ // kept in order, sorted by ascending start time.
+ typedef std::vector<DownloadItem*> OrderedDownloads;
+ OrderedDownloads downloads_;
+
+ // Progress animations
+ Timer* progress_timer_;
+ Task* progress_task_;
+
+ // Since this view manages the progress animation timers for all the floating
+ // views, we need to track the current in progress downloads. This container
+ // does not own the DownloadItems.
+ stdext::hash_set<DownloadItem*> in_progress_;
+
+ // Provide a start position for downloads with no known size.
+ int start_angle_;
+
+ ChromeViews::FixedRowHeightScrollHelper scroll_helper_;
+
+ // Keep track of the currently selected view, so that we can inform it when
+ // the user changes the selection.
+ int selected_index_;
+
+ // Text in the download search box input by the user.
+ std::wstring search_text_;
+
+ // For requesting icons from the IconManager.
+ CancelableRequestConsumerT<DownloadItem*, 0> icon_consumer_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(DownloadTabView);
+};
+
+// DownloadTabUI -------------------------------------------------------------
+
+// DownloadTabUI provides the glue to make DownloadTabView available in
+// NativeUIContents.
+
+class DownloadTabUI : public NativeUI,
+ public SearchableUIContainer::Delegate,
+ public NotificationObserver {
+ public:
+ explicit DownloadTabUI(NativeUIContents* contents);
+ virtual ~DownloadTabUI();
+
+ virtual const std::wstring GetTitle() const;
+ virtual const int GetFavIconID() const;
+ virtual const int GetSectionIconID() const;
+ virtual const std::wstring GetSearchButtonText() const;
+ virtual ChromeViews::View* GetView();
+ virtual void WillBecomeVisible(NativeUIContents* parent);
+ virtual void WillBecomeInvisible(NativeUIContents* parent);
+ virtual void Navigate(const PageState& state);
+ virtual bool SetInitialFocus();
+
+ // Return the URL that can be used to show this view in a NativeUIContents.
+ static GURL GetURL();
+
+ // Return the NativeUIFactory object for application views. This object is
+ // owned by the caller.
+ static NativeUIFactory* GetNativeUIFactory();
+
+ private:
+ // Sent from the search box, updates the search text appropriately.
+ virtual void DoSearch(const std::wstring& new_text);
+
+ // NotificationObserver method, updates loading state based on whether
+ // any downloads are in progress.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ Profile* profile() const { return contents_->profile(); }
+
+ // Our host.
+ NativeUIContents* contents_;
+
+ // The view we return from GetView. The contents of this is the
+ // bookmarks_view_
+ SearchableUIContainer searchable_container_;
+
+ DownloadTabView* download_tab_view_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(DownloadTabUI);
+};
+
+#endif // CHROME_BROWSER_DONWLOAD_TAB_VIEW_H__