diff options
-rw-r--r-- | chrome/browser/browser.vcproj | 4 | ||||
-rw-r--r-- | chrome/browser/download/download_started_animation.h | 18 | ||||
-rw-r--r-- | chrome/browser/gtk/download_started_animation_gtk.cc | 194 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 17 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_gtk.cc | 6 | ||||
-rw-r--r-- | chrome/browser/views/browser_views.vcproj | 6 | ||||
-rw-r--r-- | chrome/browser/views/download_started_animation.h | 63 | ||||
-rw-r--r-- | chrome/browser/views/download_started_animation_win.cc (renamed from chrome/browser/views/download_started_animation.cc) | 79 | ||||
-rw-r--r-- | chrome/chrome.gyp | 5 | ||||
-rw-r--r-- | chrome/common/platform_util.h | 5 | ||||
-rw-r--r-- | chrome/common/platform_util_linux.cc | 4 | ||||
-rw-r--r-- | chrome/common/platform_util_mac.mm | 5 | ||||
-rw-r--r-- | chrome/common/platform_util_win.cc | 5 |
13 files changed, 322 insertions, 89 deletions
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index b712615..07b0fb27c 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -1870,6 +1870,10 @@ > </File> <File + RelativePath=".\download\download_started_animation.h" + > + </File> + <File RelativePath=".\download\download_util.cc" > </File> diff --git a/chrome/browser/download/download_started_animation.h b/chrome/browser/download/download_started_animation.h new file mode 100644 index 0000000..92f18a1 --- /dev/null +++ b/chrome/browser/download/download_started_animation.h @@ -0,0 +1,18 @@ +// 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_DOWNLOAD_STARTED_ANIMATION_FACTORY_H_ +#define CHROME_BROWSER_DOWNLOAD_STARTED_ANIMATION_FACTORY_H_ + +class TabContents; + +class DownloadStartedAnimation { + public: + static void Show(TabContents* tab_contents); + + private: + DownloadStartedAnimation() { } +}; + +#endif // CHROME_BROWSER_DOWNLOAD_STARTED_ANIMATION_FACTORY_H_ diff --git a/chrome/browser/gtk/download_started_animation_gtk.cc b/chrome/browser/gtk/download_started_animation_gtk.cc new file mode 100644 index 0000000..8913141 --- /dev/null +++ b/chrome/browser/gtk/download_started_animation_gtk.cc @@ -0,0 +1,194 @@ +// 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/download/download_started_animation.h" + +#include <gtk/gtk.h> + +#include "app/animation.h" +#include "app/resource_bundle.h" +#include "base/gfx/rect.h" +#include "base/message_loop.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/notification_service.h" +#include "grit/theme_resources.h" + +namespace { + +// How long to spend moving downwards and fading out after waiting. +const int kMoveTimeMs = 600; + +// The animation framerate. +const int kFrameRateHz = 60; + +// What fraction of the frame height to move downward from the frame center. +// Note that setting this greater than 0.5 will mean moving past the bottom of +// the frame. +const double kMoveFraction = 1.0 / 3.0; + +class DownloadStartedAnimationGtk : public Animation, + public NotificationObserver { + public: + DownloadStartedAnimationGtk(TabContents* tab_contents); + + // DownloadStartedAnimation will delete itself, but this is public so + // that we can use DeleteSoon(). + virtual ~DownloadStartedAnimationGtk(); + + private: + // Move the arrow to wherever it should currently be. + void Reposition(); + + // Shut down cleanly. + void Close(); + + // Animation implementation. + virtual void AnimateToState(double state); + + // NotificationObserver + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // The top level window that floats over the browser and displays the + // image. + GtkWidget* popup_; + + // Dimensions of the image. + int width_; + int height_; + + // The content area holding us. + TabContents* tab_contents_; + + // The content area at the start of the animation. We store this so that the + // download shelf's resizing of the content area doesn't cause the animation + // to move around. This means that once started, the animation won't move + // with the parent window, but it's so fast that this shouldn't cause too + // much heartbreak. + gfx::Rect tab_contents_bounds_; + + // A scoped container for notification registries. + NotificationRegistrar registrar_; + + DISALLOW_COPY_AND_ASSIGN(DownloadStartedAnimationGtk); +}; + +DownloadStartedAnimationGtk::DownloadStartedAnimationGtk( + TabContents* tab_contents) + : Animation(kMoveTimeMs, kFrameRateHz, NULL), + tab_contents_(tab_contents) { + static GdkPixbuf* kDownloadImage = NULL; + if (!kDownloadImage) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + kDownloadImage = rb.GetPixbufNamed(IDR_DOWNLOAD_ANIMATION_BEGIN); + } + + width_ = gdk_pixbuf_get_width(kDownloadImage); + height_ = gdk_pixbuf_get_height(kDownloadImage); + + // If we're too small to show the download image, then don't bother - + // the shelf will be enough. + tab_contents_->GetContainerBounds(&tab_contents_bounds_); + if (tab_contents_bounds_.height() < height_) + return; + + registrar_.Add( + this, + NotificationType::TAB_CONTENTS_HIDDEN, + Source<TabContents>(tab_contents_)); + registrar_.Add( + this, + NotificationType::TAB_CONTENTS_DESTROYED, + Source<TabContents>(tab_contents_)); + + // TODO(estade): don't show up on the wrong virtual desktop. + + popup_ = gtk_window_new(GTK_WINDOW_POPUP); + GtkWidget* image = gtk_image_new_from_pixbuf(kDownloadImage); + gtk_container_add(GTK_CONTAINER(popup_), image); + + // Set the shape of the window to that of the arrow. Areas with + // opacity less than 0xff (i.e. <100% opacity) will be transparent. + GdkBitmap* mask = gdk_pixmap_new(NULL, width_, height_, 1); + gdk_pixbuf_render_threshold_alpha(kDownloadImage, mask, + 0, 0, + 0, 0, -1, -1, + 0xff); + gtk_widget_shape_combine_mask(popup_, mask, 0, 0); + g_object_unref(mask); + + Reposition(); + gtk_widget_show_all(popup_); + // Make sure our window has focus, is brought to the top, etc. + gtk_window_present(GTK_WINDOW(popup_)); + + Start(); +} + +DownloadStartedAnimationGtk::~DownloadStartedAnimationGtk() { +} + +void DownloadStartedAnimationGtk::Reposition() { + if (!tab_contents_) + return; + + // Align the image with the bottom left of the web contents (so that it + // points to the newly created download). + gtk_window_move(GTK_WINDOW(popup_), + tab_contents_bounds_.x(), + static_cast<int>(tab_contents_bounds_.bottom() - + height_ - height_ * (1 - GetCurrentValue()))); +} + +void DownloadStartedAnimationGtk::Close() { + if (!tab_contents_) + return; + + registrar_.Remove( + this, + NotificationType::TAB_CONTENTS_HIDDEN, + Source<TabContents>(tab_contents_)); + registrar_.Remove( + this, + NotificationType::TAB_CONTENTS_DESTROYED, + Source<TabContents>(tab_contents_)); + + tab_contents_ = NULL; + gtk_widget_destroy(popup_); + MessageLoop::current()->DeleteSoon(FROM_HERE, this); +} + +void DownloadStartedAnimationGtk::AnimateToState(double state) { + if (!tab_contents_) + return; + + if (state >= 1.0) { + Close(); + } else { + Reposition(); + + // Start at zero, peak halfway and end at zero. + double opacity = std::min(1.0 - pow(GetCurrentValue() - 0.5, 2) * 4.0, + static_cast<double>(1.0)); + + // This only works when there's a compositing manager running. Oh well. + gtk_window_set_opacity(GTK_WINDOW(popup_), opacity); + } +} + +void DownloadStartedAnimationGtk::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + Close(); +} + +} // namespace + +// static +void DownloadStartedAnimation::Show(TabContents* tab_contents) { + // The animation will delete itself. + new DownloadStartedAnimationGtk(tab_contents); +} diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index af83bfd..9e74eaf 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -22,6 +22,7 @@ #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_request_manager.h" #include "chrome/browser/download/download_shelf.h" +#include "chrome/browser/download/download_started_animation.h" #include "chrome/browser/gears_integration.h" #include "chrome/browser/google_util.h" #include "chrome/browser/hung_renderer_dialog.h" @@ -32,6 +33,7 @@ #include "chrome/browser/plugin_installer.h" #include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/browser/renderer_host/web_cache_manager.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/browser/tab_contents/tab_contents_view.h" @@ -40,6 +42,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" #include "chrome/common/page_action.h" +#include "chrome/common/platform_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/render_messages.h" @@ -53,9 +56,7 @@ #if defined(OS_WIN) // TODO(port): some of these headers should be ported. #include "chrome/browser/modal_html_dialog_delegate.h" -#include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/views/blocked_popup_container.h" -#include "chrome/browser/views/download_started_animation.h" #include "views/controls/scrollbar/native_scroll_bar.h" #endif @@ -955,13 +956,11 @@ void TabContents::OnStartDownload(DownloadItem* download) { 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); +// TODO(port): port for mac. +#if defined(OS_WIN) || defined(OS_LINUX) + // We make this check for the case of minimized windows, unit tests, etc. + if (platform_util::IsVisible(GetNativeView())) { + DownloadStartedAnimation::Show(tab_contents); } #endif } diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc index 59065ed..0449847 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc @@ -151,7 +151,11 @@ void TabContentsViewGtk::GetContainerBounds(gfx::Rect* out) const { // as well as sizing some other widgets in Windows. In GTK the size is // managed for us, so it appears to be only used for the download shelf // animation. - out->SetRect(vbox_.get()->allocation.x, vbox_.get()->allocation.y, + int x = 0; + int y = 0; + if (vbox_.get()->window) + gdk_window_get_origin(vbox_.get()->window, &x, &y); + out->SetRect(x + vbox_.get()->allocation.x, y + vbox_.get()->allocation.y, vbox_.get()->allocation.width, vbox_.get()->allocation.height); } diff --git a/chrome/browser/views/browser_views.vcproj b/chrome/browser/views/browser_views.vcproj index d2594d0..75e2939 100644 --- a/chrome/browser/views/browser_views.vcproj +++ b/chrome/browser/views/browser_views.vcproj @@ -546,11 +546,7 @@ > </File> <File - RelativePath=".\download_started_animation.cc" - > - </File> - <File - RelativePath=".\download_started_animation.h" + RelativePath=".\download_started_animation_win.cc" > </File> <File diff --git a/chrome/browser/views/download_started_animation.h b/chrome/browser/views/download_started_animation.h deleted file mode 100644 index ec84244..0000000 --- a/chrome/browser/views/download_started_animation.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2006-2008 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_STARTED_ANIMATION_H_ -#define CHROME_BROWSER_VIEWS_DOWNLOAD_STARTED_ANIMATION_H_ - -#include "app/animation.h" -#include "base/gfx/rect.h" -#include "chrome/common/notification_registrar.h" -#include "views/controls/image_view.h" - -namespace views { -class WidgetWin; -}; -class TabContents; - -// DownloadStartAnimation creates an animation (which begins running -// immediately) that animates an image downward from the center of the frame -// provided on the constructor, while simultaneously fading it out. To use, -// simply call "new DownloadStartAnimation"; the class cleans itself up when it -// finishes animating. -class DownloadStartedAnimation : public Animation, - public NotificationObserver, - public views::ImageView { - public: - DownloadStartedAnimation(TabContents* tab_contents); - - private: - // Move the animation to wherever it should currently be. - void Reposition(); - - // Shut down the animation cleanly. - void Close(); - - // Animation - virtual void AnimateToState(double state); - - // NotificationObserver - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - // We use a HWND for the popup so that it may float above any HWNDs in our UI. - views::WidgetWin* popup_; - - // The content area holding us. - TabContents* tab_contents_; - - // The content area at the start of the animation. We store this so that the - // download shelf's resizing of the content area doesn't cause the animation - // to move around. This means that once started, the animation won't move - // with the parent window, but it's so fast that this shouldn't cause too - // much heartbreak. - gfx::Rect tab_contents_bounds_; - - // A scoped container for notification registries. - NotificationRegistrar registrar_; - - DISALLOW_COPY_AND_ASSIGN(DownloadStartedAnimation); -}; - -#endif // CHROME_BROWSER_VIEWS_DOWNLOAD_STARTED_ANIMATION_H_ diff --git a/chrome/browser/views/download_started_animation.cc b/chrome/browser/views/download_started_animation_win.cc index 3fddcd4..6ae160b 100644 --- a/chrome/browser/views/download_started_animation.cc +++ b/chrome/browser/views/download_started_animation_win.cc @@ -1,13 +1,17 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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/views/download_started_animation.h" +#include "chrome/browser/download/download_started_animation.h" +#include "app/animation.h" #include "app/resource_bundle.h" +#include "base/gfx/rect.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/notification_registrar.h" #include "chrome/common/notification_service.h" #include "grit/theme_resources.h" +#include "views/controls/image_view.h" #include "views/widget/widget_win.h" // How long to spend moving downwards and fading out after waiting. @@ -21,7 +25,55 @@ static const int kFrameRateHz = 60; // the frame. static const double kMoveFraction = 1.0 / 3.0; -DownloadStartedAnimation::DownloadStartedAnimation(TabContents* tab_contents) +namespace { + +// DownloadStartAnimation creates an animation (which begins running +// immediately) that animates an image downward from the center of the frame +// provided on the constructor, while simultaneously fading it out. To use, +// simply call "new DownloadStartAnimation"; the class cleans itself up when it +// finishes animating. +class DownloadStartedAnimationWin : public Animation, + public NotificationObserver, + public views::ImageView { + public: + DownloadStartedAnimationWin(TabContents* tab_contents); + + private: + // Move the animation to wherever it should currently be. + void Reposition(); + + // Shut down the animation cleanly. + void Close(); + + // Animation + virtual void AnimateToState(double state); + + // NotificationObserver + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // We use a HWND for the popup so that it may float above any HWNDs in our UI. + views::WidgetWin* popup_; + + // The content area holding us. + TabContents* tab_contents_; + + // The content area at the start of the animation. We store this so that the + // download shelf's resizing of the content area doesn't cause the animation + // to move around. This means that once started, the animation won't move + // with the parent window, but it's so fast that this shouldn't cause too + // much heartbreak. + gfx::Rect tab_contents_bounds_; + + // A scoped container for notification registries. + NotificationRegistrar registrar_; + + DISALLOW_COPY_AND_ASSIGN(DownloadStartedAnimationWin); +}; + +DownloadStartedAnimationWin::DownloadStartedAnimationWin( + TabContents* tab_contents) : Animation(kMoveTimeMs, kFrameRateHz, NULL), popup_(NULL), tab_contents_(tab_contents) { @@ -62,7 +114,7 @@ DownloadStartedAnimation::DownloadStartedAnimation(TabContents* tab_contents) Start(); } -void DownloadStartedAnimation::Reposition() { +void DownloadStartedAnimationWin::Reposition() { if (!tab_contents_) return; @@ -77,7 +129,7 @@ void DownloadStartedAnimation::Reposition() { size.height()); } -void DownloadStartedAnimation::Close() { +void DownloadStartedAnimationWin::Close() { if (!tab_contents_) return; @@ -93,7 +145,7 @@ void DownloadStartedAnimation::Close() { popup_->Close(); } -void DownloadStartedAnimation::AnimateToState(double state) { +void DownloadStartedAnimationWin::AnimateToState(double state) { if (state >= 1.0) { Close(); } else { @@ -110,8 +162,17 @@ void DownloadStartedAnimation::AnimateToState(double state) { } } -void DownloadStartedAnimation::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { +void DownloadStartedAnimationWin::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { Close(); } + +} // namespace + +// static +void DownloadStartedAnimation::Show(TabContents* tab_contents) { + // The animation will delete itself when it's finished or when the tab + // contents is hidden or destroyed. + new DownloadStartedAnimationWin(tab_contents); +} diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 4eab0fb..a8f6947 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -861,6 +861,7 @@ 'browser/download/download_request_manager.h', 'browser/download/download_shelf.cc', 'browser/download/download_shelf.h', + 'browser/download/download_started_animation.h', 'browser/download/download_util.cc', 'browser/download/download_util.h', 'browser/download/save_file.cc', @@ -956,6 +957,7 @@ 'browser/gtk/download_item_gtk.h', 'browser/gtk/download_shelf_gtk.cc', 'browser/gtk/download_shelf_gtk.h', + 'browser/gtk/download_started_animation_gtk.cc', 'browser/gtk/go_button_gtk.cc', 'browser/gtk/go_button_gtk.h', 'browser/gtk/gtk_chrome_button.cc', @@ -1424,8 +1426,7 @@ 'browser/views/download_item_view.h', 'browser/views/download_shelf_view.cc', 'browser/views/download_shelf_view.h', - 'browser/views/download_started_animation.cc', - 'browser/views/download_started_animation.h', + 'browser/views/download_started_animation_win.cc', 'browser/views/edit_keyword_controller.cc', 'browser/views/edit_keyword_controller.h', 'browser/views/event_utils.cc', diff --git a/chrome/common/platform_util.h b/chrome/common/platform_util.h index bb10140..c4a46b7 100644 --- a/chrome/common/platform_util.h +++ b/chrome/common/platform_util.h @@ -24,6 +24,11 @@ string16 GetWindowTitle(gfx::NativeWindow window); // Returns true if |window| is the foreground top level window. bool IsWindowActive(gfx::NativeWindow window); +// Returns true if the view is visible. The exact definition of this is +// platform-specific, but it is generally not "visible to the user", rather +// whether the view has the visible attribute set. +bool IsVisible(gfx::NativeView view); + } #endif // CHROME_COMMON_PLATFORM_UTIL_H_ diff --git a/chrome/common/platform_util_linux.cc b/chrome/common/platform_util_linux.cc index 3fd033f..7458978 100644 --- a/chrome/common/platform_util_linux.cc +++ b/chrome/common/platform_util_linux.cc @@ -41,4 +41,8 @@ bool IsWindowActive(gfx::NativeWindow window) { return gtk_window_is_active(window); } +bool IsVisible(gfx::NativeView view) { + return GTK_WIDGET_VISIBLE(view); +} + } // namespace platform_util diff --git a/chrome/common/platform_util_mac.mm b/chrome/common/platform_util_mac.mm index a75ea4b..2586d1f 100644 --- a/chrome/common/platform_util_mac.mm +++ b/chrome/common/platform_util_mac.mm @@ -44,4 +44,9 @@ bool IsWindowActive(gfx::NativeWindow window) { return false; } +bool IsVisible(gfx::NativeView view) { + NOTIMPLEMENTED(); + return true; +} + } // namespace platform_util diff --git a/chrome/common/platform_util_win.cc b/chrome/common/platform_util_win.cc index e0ee665..f1af709 100644 --- a/chrome/common/platform_util_win.cc +++ b/chrome/common/platform_util_win.cc @@ -97,4 +97,9 @@ bool IsWindowActive(gfx::NativeWindow window) { return ::GetForegroundWindow() == window; } +bool IsVisible(gfx::NativeView view) { + // MSVC complains if we don't include != 0. + return ::IsWindowVisible(view) != 0; +} + } // namespace platform_util |