summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-28 00:35:02 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-28 00:35:02 +0000
commitbcef0dc01dad3fff84f0c64389a0ead525181e55 (patch)
tree1d08ea6a05a2adbb44050715acde79771e442f88 /chrome/browser/views
parentdf9d0aa2e3feea5b71e1b3979ba6057238591fe3 (diff)
downloadchromium_src-bcef0dc01dad3fff84f0c64389a0ead525181e55.zip
chromium_src-bcef0dc01dad3fff84f0c64389a0ead525181e55.tar.gz
chromium_src-bcef0dc01dad3fff84f0c64389a0ead525181e55.tar.bz2
Refactor download shelf and prepare for porting.
Side effect of removing some views dependencies from places they don't belong. Review URL: http://codereview.chromium.org/28252 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10657 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/download_shelf_view.cc28
-rw-r--r--chrome/browser/views/download_shelf_view.h58
-rw-r--r--chrome/browser/views/frame/browser_view.cc4
3 files changed, 34 insertions, 56 deletions
diff --git a/chrome/browser/views/download_shelf_view.cc b/chrome/browser/views/download_shelf_view.cc
index ffcb3cd..59f8b6f 100644
--- a/chrome/browser/views/download_shelf_view.cc
+++ b/chrome/browser/views/download_shelf_view.cc
@@ -7,7 +7,6 @@
#include <algorithm>
#include "base/logging.h"
-#include "chrome/browser/browser.h"
#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
@@ -74,8 +73,13 @@ int CenterPosition(int size, int target_size) {
} // namespace
+// static
+DownloadShelf* DownloadShelf::Create(TabContents* tab_contents) {
+ return new DownloadShelfView(tab_contents);
+}
+
DownloadShelfView::DownloadShelfView(TabContents* tab_contents)
- : tab_contents_(tab_contents) {
+ : DownloadShelf(tab_contents) {
Init();
}
@@ -107,6 +111,9 @@ void DownloadShelfView::Init() {
shelf_animation_.reset(new SlideAnimation(this));
shelf_animation_->SetSlideDuration(kShelfAnimationDurationMs);
shelf_animation_->Show();
+
+ // The download shelf view is always owned by its tab contents.
+ SetParentOwned(false);
}
void DownloadShelfView::AddDownloadView(View* view) {
@@ -122,15 +129,9 @@ void DownloadShelfView::AddDownloadView(View* view) {
new_item_animation_->Show();
}
-void DownloadShelfView::ChangeTabContents(TabContents* old_contents,
- TabContents* new_contents) {
- DCHECK(old_contents == tab_contents_);
- tab_contents_ = new_contents;
-}
-
-void DownloadShelfView::AddDownload(DownloadItem* download) {
+void DownloadShelfView::AddDownload(BaseDownloadItemModel* download_model) {
DownloadItemView* view = new DownloadItemView(
- download, this, new DownloadItemModel(download));
+ download_model->download(), this, download_model);
AddDownloadView(view);
}
@@ -259,13 +260,8 @@ void DownloadShelfView::Layout() {
}
}
-// Open the download page.
void DownloadShelfView::LinkActivated(views::Link* source, int event_flags) {
- int index;
- NavigationController* controller = tab_contents_->controller();
- Browser* browser = Browser::GetBrowserForController(controller, &index);
- DCHECK(browser);
- browser->ShowDownloadsTab();
+ ShowAllDownloads();
}
void DownloadShelfView::ButtonPressed(views::BaseButton* button) {
diff --git a/chrome/browser/views/download_shelf_view.h b/chrome/browser/views/download_shelf_view.h
index 3f157a4..9bf9032 100644
--- a/chrome/browser/views/download_shelf_view.h
+++ b/chrome/browser/views/download_shelf_view.h
@@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H__
-#define CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H__
+#ifndef CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H_
+#define CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H_
+#include "chrome/browser/download/download_shelf.h"
#include "chrome/common/slide_animation.h"
#include "chrome/views/button.h"
#include "chrome/views/link.h"
@@ -13,7 +14,7 @@ namespace views {
class ImageView;
}
-class DownloadItem;
+class BaseDownloadItemModel;
class TabContents;
class DownloadAnimation;
@@ -24,71 +25,52 @@ class DownloadAnimation;
// To add a view representing a download to DownloadShelfView, invoke
// AddDownloadView. AddDownloadView takes ownership of the passed in View.
// DownloadShelfView does not hold an infinite number of download views, rather
-// it'll automatically remove views once a certain point is reached. As such,
-// the remove method is private.
-class DownloadShelfView : public views::View,
+// it'll automatically remove views once a certain point is reached.
+class DownloadShelfView : public DownloadShelf,
+ public views::View,
public views::BaseButton::ButtonListener,
public views::LinkController,
public AnimationDelegate {
public:
explicit DownloadShelfView(TabContents* tab_contents);
- // A new download has started, so add it to our shelf.
- void AddDownload(DownloadItem* download);
-
+ // Implementation of View.
virtual gfx::Size GetPreferredSize();
-
virtual void Layout();
-
- // Invokes the following methods to do painting:
- // PaintBackground, PaintBorder and PaintSeparators.
virtual void Paint(ChromeCanvas* canvas);
- // AnimationDelegate implementations
+ // Implementation of AnimationDelegate.
virtual void AnimationProgressed(const Animation* animation);
virtual void AnimationEnded(const Animation* animation);
+ // Implementation of LinkController.
// Invoked when the user clicks the 'show all downloads' link button.
virtual void LinkActivated(views::Link* source, int event_flags);
+ // Implementation of ButtonListener.
// Invoked when the user clicks the close button. Asks the browser to
// hide the download shelf.
virtual void ButtonPressed(views::BaseButton* button);
+ // Implementation of DownloadShelf.
+ virtual void AddDownload(BaseDownloadItemModel* download_model);
+ virtual bool IsShowing() const;
+
// Removes a specified download view. The supplied view is deleted after
// it's removed.
void RemoveDownloadView(views::View* view);
+ private:
+ void Init();
+
// Adds a View representing a download to this DownloadShelfView.
// DownloadShelfView takes ownership of the View, and will delete it as
// necessary.
void AddDownloadView(views::View* view);
- // Invoked when the download shelf is migrated from one tab contents to a new
- // one.
- void ChangeTabContents(TabContents* old_contents, TabContents* new_contents);
-
- // The browser view needs to know when we are going away to properly return
- // the resize corner size to WebKit so that we don't draw on top of it.
- // This returns the showing state of our animation which is set to false at
- // the beginning Show and true at the beginning of a Hide.
- bool IsShowing() const;
-
- private:
- void Init();
-
// Paints the border.
void PaintBorder(ChromeCanvas* canvas);
- // Paints the separators. This invokes PaintSeparator to paint a particular
- // separator.
- void PaintSeparators(ChromeCanvas* canvas);
-
- // Paints the separator between the two views.
- void PaintSeparator(ChromeCanvas* canvas, views::View* v1, views::View* v2);
-
- TabContents* tab_contents_;
-
// The animation for adding new items to the shelf.
scoped_ptr<SlideAnimation> new_item_animation_;
@@ -110,8 +92,8 @@ class DownloadShelfView : public views::View,
// deleted by View.
views::Button* close_button_;
- DISALLOW_EVIL_CONSTRUCTORS(DownloadShelfView);
+ DISALLOW_COPY_AND_ASSIGN(DownloadShelfView);
};
-#endif // CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H__
+#endif // CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H_
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index a8eaa63..e1341f94 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -734,7 +734,7 @@ gfx::Rect BrowserView::GetRootWindowResizerRect() const {
// Other tests should be added here if we add more bottom shelves.
TabContents* current_tab = browser_->GetSelectedTabContents();
if (current_tab && current_tab->IsDownloadShelfVisible()) {
- DownloadShelfView* download_shelf = current_tab->GetDownloadShelfView();
+ DownloadShelf* download_shelf = current_tab->GetDownloadShelf();
if (download_shelf && download_shelf->IsShowing())
return gfx::Rect();
}
@@ -1462,7 +1462,7 @@ bool BrowserView::MaybeShowInfoBar(TabContents* contents) {
bool BrowserView::MaybeShowDownloadShelf(TabContents* contents) {
views::View* new_shelf = NULL;
if (contents && contents->IsDownloadShelfVisible()) {
- new_shelf = contents->GetDownloadShelfView();
+ new_shelf = static_cast<DownloadShelfView*>(contents->GetDownloadShelf());
if (new_shelf != active_download_shelf_)
new_shelf->AddChildView(new ResizeCorner(this));
}