summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/browser.scons3
-rw-r--r--chrome/browser/download/download_manager.cc1
-rw-r--r--chrome/browser/download/download_shelf.cc5
-rw-r--r--chrome/browser/download/save_package.cc6
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.cc91
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.h45
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc46
-rw-r--r--chrome/common/temp_scaffolding_stubs.cc37
-rw-r--r--chrome/common/temp_scaffolding_stubs.h13
9 files changed, 200 insertions, 47 deletions
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons
index bb765f6..951ebce 100644
--- a/chrome/browser/browser.scons
+++ b/chrome/browser/browser.scons
@@ -471,6 +471,8 @@ input_files = ChromeFileList([
'download/download_request_dialog_delegate.h',
'download/download_request_manager.cc',
'download/download_request_manager.h',
+ 'download/download_shelf.cc',
+ 'download/download_shelf.h',
'download/download_util.cc',
'download/download_util.h',
]),
@@ -738,6 +740,7 @@ if env.Bit('linux'):
'gtk/browser_window_factory_gtk.cc',
'gtk/browser_window_gtk.cc',
'gtk/custom_button.cc',
+ 'gtk/download_shelf_gtk.cc',
'gtk/menu_gtk.cc',
'gtk/nine_box.cc',
'gtk/standard_menus.cc',
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index 50f2910..b50e039 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -1360,7 +1360,6 @@ void DownloadManager::OnQueryDownloadEntriesComplete(
FOR_EACH_OBSERVER(Observer, observers_, ModelChanged());
}
-
// Once the new DownloadItem's creation info has been committed to the history
// service, we associate the DownloadItem with the db handle, update our
// 'downloads_' map and inform observers.
diff --git a/chrome/browser/download/download_shelf.cc b/chrome/browser/download/download_shelf.cc
index 7cce198..826dc4e 100644
--- a/chrome/browser/download/download_shelf.cc
+++ b/chrome/browser/download/download_shelf.cc
@@ -14,12 +14,17 @@
#endif
void DownloadShelf::ShowAllDownloads() {
+#if defined(OS_WIN)
Profile* profile = tab_contents_->profile();
if (profile)
UserMetrics::RecordAction(L"ShowDownloads", profile);
GURL url = DownloadsUI::GetBaseURL();
tab_contents_->OpenURL(url, GURL(), NEW_FOREGROUND_TAB,
PageTransition::AUTO_BOOKMARK);
+#else
+ // TODO(port): After we port DownloadsUI, enable this function.
+ NOTIMPLEMENTED();
+#endif
}
void DownloadShelf::ChangeTabContents(TabContents* old_contents,
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc
index 9f01bd8..d8ceb41 100644
--- a/chrome/browser/download/save_package.cc
+++ b/chrome/browser/download/save_package.cc
@@ -264,12 +264,12 @@ bool SavePackage::Init() {
download_ = new DownloadItem(1, saved_main_file_path_, 0, page_url_,
FilePath(), Time::Now(), 0, -1, -1, false);
download_->set_manager(web_contents_->profile()->GetDownloadManager());
-#if defined(OS_WIN)
+#if !defined(OS_MACOSX)
DownloadShelf* shelf = web_contents_->GetDownloadShelf();
shelf->AddDownload(new SavePageModel(this, download_));
web_contents_->SetDownloadShelfVisible(true);
-#elif defined(OS_POSIX)
- // TODO(port): Create a download shelf for linux and mac.
+#else
+ // TODO(port): Create a download shelf for mac.
NOTIMPLEMENTED();
#endif
diff --git a/chrome/browser/gtk/download_shelf_gtk.cc b/chrome/browser/gtk/download_shelf_gtk.cc
new file mode 100644
index 0000000..86a51b2
--- /dev/null
+++ b/chrome/browser/gtk/download_shelf_gtk.cc
@@ -0,0 +1,91 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/gtk/download_shelf_gtk.h"
+
+#include "base/logging.h"
+#include "chrome/browser/download/download_item_model.h"
+#include "chrome/common/l10n_util.h"
+#include "chrome/common/resource_bundle.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+
+// TODO(port): remove this after tab_contents.h is ported.
+#include "chrome/common/temp_scaffolding_stubs.h"
+
+namespace {
+
+// Total height of the shelf.
+const int kShelfHeight = 30;
+
+// Padding between the download widgets.
+const int kDownloadItemPadding = 10;
+
+// Padding between the top/bottom of the download widgets and the edge of the
+// shelf.
+const int kTopBottomPadding = 2;
+
+// Padding from right edge and close button/show downloads link.
+const int kRightPadding = 10;
+
+}
+
+// static
+DownloadShelf* DownloadShelf::Create(TabContents* tab_contents) {
+ return new DownloadShelfGtk(tab_contents);
+}
+
+DownloadShelfGtk::DownloadShelfGtk(TabContents* tab_contents)
+ : DownloadShelf(tab_contents),
+ is_showing_(false) {
+ shelf_ = gtk_hbox_new(FALSE, 0);
+ gtk_widget_set_size_request(shelf_, -1, kShelfHeight);
+
+ // Create and pack the close button.
+ close_button_.reset(new CustomDrawButton(IDR_CLOSE_BAR,
+ IDR_CLOSE_BAR_P, IDR_CLOSE_BAR_H, 0));
+ g_signal_connect(G_OBJECT(close_button_->widget()), "clicked",
+ G_CALLBACK(OnCloseButtonClick), this);
+ GTK_WIDGET_UNSET_FLAGS(close_button_->widget(), GTK_CAN_FOCUS);
+ GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), close_button_->widget(), TRUE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(shelf_), vbox, FALSE, FALSE, kRightPadding);
+
+ // Stick ourselves at the bottom of the parent tab contents.
+ GtkWidget* parent_contents = tab_contents->GetNativeView();
+ gtk_box_pack_end(GTK_BOX(parent_contents), shelf_, FALSE, FALSE, 0);
+ Show();
+}
+
+void DownloadShelfGtk::AddDownload(BaseDownloadItemModel* download_model_) {
+ NOTIMPLEMENTED();
+ Show();
+}
+
+bool DownloadShelfGtk::IsShowing() const {
+ return is_showing_;
+}
+
+void DownloadShelfGtk::Show() {
+ if (is_showing_)
+ return;
+
+ gtk_widget_show_all(shelf_);
+ is_showing_ = true;
+}
+
+void DownloadShelfGtk::Hide() {
+ if (!is_showing_)
+ return;
+
+ gtk_widget_hide_all(shelf_);
+ is_showing_ = false;
+}
+
+// static
+void DownloadShelfGtk::OnCloseButtonClick(GtkWidget* button,
+ DownloadShelfGtk* shelf) {
+ shelf->Hide();
+}
+
diff --git a/chrome/browser/gtk/download_shelf_gtk.h b/chrome/browser/gtk/download_shelf_gtk.h
new file mode 100644
index 0000000..9cbf5bc
--- /dev/null
+++ b/chrome/browser/gtk/download_shelf_gtk.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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_
+
+#include <gtk/gtk.h>
+
+#include "base/scoped_ptr.h"
+#include "chrome/browser/download/download_shelf.h"
+#include "chrome/browser/gtk/custom_button.h"
+
+class BaseDownloadItemModel;
+
+class DownloadShelfGtk : public DownloadShelf {
+ public:
+ explicit DownloadShelfGtk(TabContents* tab_contents);
+
+ // DownloadShelf implementation.
+ virtual void AddDownload(BaseDownloadItemModel* download_model);
+ virtual bool IsShowing() const;
+
+ private:
+ // Show the shelf.
+ void Show();
+
+ // Hide the shelf.
+ void Hide();
+
+ static void OnCloseButtonClick(GtkWidget* button,
+ DownloadShelfGtk* toolbar);
+
+ // |bar_| is the highest level widget of the download shelf. It is an hbox.
+ GtkWidget* shelf_;
+
+ // The 'x' that the user can press to hide the download shelf.
+ scoped_ptr<CustomDrawButton> close_button_;
+
+ // Keeps track of our current hide/show state.
+ bool is_showing_;
+};
+
+#endif // CHROME_BROWSER_VIEWS_DOWNLOAD_SHELF_VIEW_H_
+
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 7905364..1df337c 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -464,6 +464,13 @@ void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
}
}
}
+#endif // defined(OS_WIN)
+
+void TabContents::ToolbarSizeChanged(bool is_animating) {
+ TabContentsDelegate* d = delegate();
+ if (d)
+ d->ToolbarSizeChanged(this, is_animating);
+}
void TabContents::SetDownloadShelfVisible(bool visible) {
if (shelf_visible_ != visible) {
@@ -483,32 +490,33 @@ void TabContents::SetDownloadShelfVisible(bool visible) {
ToolbarSizeChanged(false);
}
-void TabContents::ToolbarSizeChanged(bool is_animating) {
- TabContentsDelegate* d = delegate();
- if (d)
- d->ToolbarSizeChanged(this, is_animating);
-}
-
+#if defined(OS_WIN) || defined(OS_LINUX)
void TabContents::OnStartDownload(DownloadItem* download) {
DCHECK(download);
TabContents* tab_contents = this;
+// TODO(port): port contraining contents.
+#if defined(OS_WIN)
// Download in a constrained popup is shown in the tab that opened it.
TabContents* constraining_tab = delegate()->GetConstrainingContents(this);
if (constraining_tab)
tab_contents = constraining_tab;
+#endif
// GetDownloadShelf creates the download shelf if it was not yet created.
tab_contents->GetDownloadShelf()->AddDownload(
new DownloadItemModel(download));
tab_contents->SetDownloadShelfVisible(true);
+// TODO(port): port animatinos.
+#if defined(OS_WIN)
// This animation will delete itself when it finishes, or if we become hidden
// or destroyed.
if (IsWindowVisible(GetNativeView())) { // For minimized windows, unit
// tests, etc.
new DownloadStartedAnimation(tab_contents);
}
+#endif
}
DownloadShelf* TabContents::GetDownloadShelf() {
@@ -523,6 +531,20 @@ void TabContents::MigrateShelfFrom(TabContents* tab_contents) {
tab_contents->ReleaseDownloadShelf();
}
+void TabContents::ReleaseDownloadShelf() {
+ download_shelf_.release();
+}
+
+// static
+void TabContents::MigrateShelf(TabContents* from, TabContents* to) {
+ bool was_shelf_visible = from->IsDownloadShelfVisible();
+ if (was_shelf_visible)
+ to->MigrateShelfFrom(from);
+ to->SetDownloadShelfVisible(was_shelf_visible);
+}
+#endif // defined(OS_WIN) || defined(OS_LINUX)
+
+#if defined(OS_WIN)
void TabContents::WillClose(ConstrainedWindow* window) {
ConstrainedWindowList::iterator it =
find(child_windows_.begin(), child_windows_.end(), window);
@@ -555,14 +577,6 @@ void TabContents::Observe(NotificationType type,
ExpireInfoBars(committed_details);
}
-// static
-void TabContents::MigrateShelf(TabContents* from, TabContents* to) {
- bool was_shelf_visible = from->IsDownloadShelfVisible();
- if (was_shelf_visible)
- to->MigrateShelfFrom(from);
- to->SetDownloadShelfVisible(was_shelf_visible);
-}
-
void TabContents::SetIsLoading(bool is_loading,
LoadNotificationDetails* details) {
if (is_loading == is_loading_)
@@ -604,10 +618,6 @@ void TabContents::RepositionSupressedPopupsToFit(const gfx::Size& new_size) {
blocked_popups_->RepositionConstrainedWindowTo(anchor_position);
}
-void TabContents::ReleaseDownloadShelf() {
- download_shelf_.release();
-}
-
bool TabContents::ShowingBlockedPopupNotification() const {
return blocked_popups_ != NULL &&
blocked_popups_->GetTabContentsCount() != 0;
diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc
index c8f570b..5cd4428 100644
--- a/chrome/common/temp_scaffolding_stubs.cc
+++ b/chrome/common/temp_scaffolding_stubs.cc
@@ -379,30 +379,29 @@ void TabContents::SetIsCrashed(bool state) {
delegate_->ContentsStateChanged(this);
}
-void TabContents::SetDownloadShelfVisible(bool visible) {
- if (shelf_visible_ != visible) {
- if (visible) {
- // Invoke GetDownloadShelf to force the shelf to be created.
- GetDownloadShelf();
- }
- shelf_visible_ = visible;
-
- if (delegate_)
- delegate_->ContentsStateChanged(this);
- }
+#if defined(OS_MACOSX)
+void TabContents::OnStartDownload(DownloadItem* download){
+ NOTIMPLEMENTED();
+}
+
+DownloadShelf* TabContents::GetDownloadShelf(){
+ NOTIMPLEMENTED();
+ return NULL;
+}
- // SetShelfVisible can force-close the shelf, so make sure we lay out
- // everything correctly, as if the animation had finished. This doesn't
- // matter for showing the shelf, as the show animation will do it.
- ToolbarSizeChanged(false);
+void TabContents::ReleaseDownloadShelf() {
+ NOTIMPLEMENTED();
}
-void TabContents::ToolbarSizeChanged(bool is_animating) {
- TabContentsDelegate* d = delegate();
- if (d)
- d->ToolbarSizeChanged(this, is_animating);
+void TabContents::MigrateShelf(TabContents* from, TabContents* to){
+ NOTIMPLEMENTED();
}
+void TabContents::MigrateShelfFrom(TabContents* tab_contents){
+ NOTIMPLEMENTED();
+}
+#endif
+
//--------------------------------------------------------------------------
void RLZTracker::CleanupRlz() {
diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h
index 20e93d4..ca7cf64 100644
--- a/chrome/common/temp_scaffolding_stubs.h
+++ b/chrome/common/temp_scaffolding_stubs.h
@@ -25,6 +25,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/cache_manager_host.h"
#include "chrome/browser/cancelable_request.h"
+#include "chrome/browser/download/download_shelf.h"
#include "chrome/browser/download/save_types.h"
#include "chrome/browser/history/download_types.h"
#include "chrome/browser/history/history.h"
@@ -63,7 +64,6 @@ class CPCommandInterface;
class DOMUIHost;
class DownloadItem;
class DownloadManager;
-class DownloadShelf;
class HistoryService;
class LoginHandler;
class MetricsService;
@@ -488,24 +488,25 @@ class TabContents : public PageNavigator, public NotificationObserver {
static void RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kBlockPopups, false);
}
- static void MigrateShelf(TabContents* from, TabContents* to) {
- NOTIMPLEMENTED();
- }
virtual void CreateView() {}
virtual gfx::NativeView GetNativeView() const { return NULL; }
static TabContentsFactory* RegisterFactory(TabContentsType type,
TabContentsFactory* factory);
- void OnStartDownload(DownloadItem* download) { NOTIMPLEMENTED(); }
void RemoveInfoBar(InfoBarDelegate* delegate) { NOTIMPLEMENTED(); }
virtual bool ShouldDisplayURL() { return true; }
void ToolbarSizeChanged(bool is_animating);
- DownloadShelf* GetDownloadShelf() { NOTIMPLEMENTED(); return NULL; }
+ void OnStartDownload(DownloadItem* download);
+ DownloadShelf* GetDownloadShelf();
+ static void MigrateShelf(TabContents* from, TabContents* to);
+ void MigrateShelfFrom(TabContents* tab_contents);
protected:
typedef std::vector<ConstrainedWindow*> ConstrainedWindowList;
ConstrainedWindowList child_windows_;
private:
+ virtual void ReleaseDownloadShelf();
friend class AutomationProvider;
+ scoped_ptr<DownloadShelf> download_shelf_;
TabContentsType type_;
bool is_crashed_;
bool is_active_;