summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-22 18:54:11 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-22 18:54:11 +0000
commit1aab6b89de5989369e1ceecda0a3b6af056e2f89 (patch)
tree2f0c32501a24a81ea94702f4f1c83144959bbc9e /chrome
parent501093ab1b859c11d1a89b286e46f7fc12eeb9c3 (diff)
downloadchromium_src-1aab6b89de5989369e1ceecda0a3b6af056e2f89.zip
chromium_src-1aab6b89de5989369e1ceecda0a3b6af056e2f89.tar.gz
chromium_src-1aab6b89de5989369e1ceecda0a3b6af056e2f89.tar.bz2
Add new item animation to download shelf.
Also, fix duration and tween type for download shelf open animation. Review URL: http://codereview.chromium.org/88064 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14220 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/gtk/download_item_gtk.cc36
-rw-r--r--chrome/browser/gtk/download_item_gtk.h16
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.cc7
-rw-r--r--chrome/browser/gtk/infobar_gtk.cc2
-rw-r--r--chrome/browser/gtk/slide_animator_gtk.cc8
-rw-r--r--chrome/browser/gtk/slide_animator_gtk.h6
6 files changed, 60 insertions, 15 deletions
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc
index 43fec48..38260e8 100644
--- a/chrome/browser/gtk/download_item_gtk.cc
+++ b/chrome/browser/gtk/download_item_gtk.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/gtk/nine_box.h"
#include "chrome/common/gfx/chrome_font.h"
#include "chrome/common/gfx/text_elider.h"
+#include "chrome/common/slide_animation.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -30,6 +31,9 @@ const char* kLabelColorMarkup = "<span color='#%s'>%s</span>";
const char* kFilenameColor = "576C95"; // 87, 108, 149
const char* kStatusColor = "7B8DAE"; // 123, 141, 174
+// New download item animation speed in milliseconds.
+static const int kNewItemAnimationDurationMs = 800;
+
} // namespace
// DownloadShelfContextMenuGtk -------------------------------------------------
@@ -135,35 +139,33 @@ DownloadItemGtk::DownloadItemGtk(BaseDownloadItemModel* download_model,
InitNineBoxes();
body_ = gtk_button_new();
- // Eventually we will show an icon and graphical download progress, but for
- // now the only contents of body_ is text, so to make its size request the
- // same as the width of the text (plus a little padding: see below).
- gtk_widget_set_size_request(body_, kTextWidth + 50, -1);
gtk_widget_set_app_paintable(body_, TRUE);
g_signal_connect(G_OBJECT(body_), "expose-event",
G_CALLBACK(OnExpose), this);
GTK_WIDGET_UNSET_FLAGS(body_, GTK_CAN_FOCUS);
- GtkWidget* name_label = gtk_label_new(NULL);
+ name_label_ = gtk_label_new(NULL);
+
// TODO(estade): This is at best an educated guess, since we don't actually
// use ChromeFont() to draw the text. This is why we need to add so
// much padding when we set the size request. We need to either use ChromeFont
// or somehow extend TextElider.
std::wstring elided_filename = gfx::ElideFilename(
- download_model->download()->GetFileName().ToWStringHack(),
+ download_model_->download()->GetFileName().ToWStringHack(),
ChromeFont(), kTextWidth);
gchar* label_markup =
g_markup_printf_escaped(kLabelColorMarkup, kFilenameColor,
WideToUTF8(elided_filename).c_str());
- gtk_label_set_markup(GTK_LABEL(name_label), label_markup);
+ gtk_label_set_markup(GTK_LABEL(name_label_), label_markup);
g_free(label_markup);
+
status_label_ = gtk_label_new(NULL);
// Left align and vertically center the labels.
- gtk_misc_set_alignment(GTK_MISC(name_label), 0, 0.5);
+ gtk_misc_set_alignment(GTK_MISC(name_label_), 0, 0.5);
gtk_misc_set_alignment(GTK_MISC(status_label_), 0, 0.5);
// Stack the labels on top of one another.
GtkWidget* text_stack = gtk_vbox_new(FALSE, 0);
- gtk_box_pack_start(GTK_BOX(text_stack), name_label, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(text_stack), name_label_, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(text_stack), status_label_, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(body_), text_stack);
@@ -184,12 +186,16 @@ DownloadItemGtk::DownloadItemGtk(BaseDownloadItemModel* download_model,
gtk_box_pack_start(GTK_BOX(parent_shelf), hbox_, FALSE, FALSE, 0);
// Insert as the leftmost item.
gtk_box_reorder_child(GTK_BOX(parent_shelf), hbox_, 1);
- gtk_widget_show_all(hbox_);
g_signal_connect(G_OBJECT(parent_shelf_), "size-allocate",
G_CALLBACK(OnShelfResized), this);
download_model_->download()->AddObserver(this);
+
+ new_item_animation_.reset(new SlideAnimation(this));
+ new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs);
+ gtk_widget_show_all(hbox_);
+ new_item_animation_->Show();
}
DownloadItemGtk::~DownloadItemGtk() {
@@ -217,6 +223,16 @@ void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) {
g_free(label_markup);
}
+void DownloadItemGtk::AnimationProgressed(const Animation* animation) {
+ // Eventually we will show an icon and graphical download progress, but for
+ // now the only contents of body_ is text, so to make its size request the
+ // same as the width of the text. See above TODO for explanation of the
+ // extra 50.
+ int showing_width = (kTextWidth + 50) *
+ new_item_animation_->GetCurrentValue();
+ gtk_widget_set_size_request(body_, showing_width, -1);
+}
+
// static
void DownloadItemGtk::InitNineBoxes() {
if (body_nine_box_normal_)
diff --git a/chrome/browser/gtk/download_item_gtk.h b/chrome/browser/gtk/download_item_gtk.h
index 4c6bd76..a57fcbb 100644
--- a/chrome/browser/gtk/download_item_gtk.h
+++ b/chrome/browser/gtk/download_item_gtk.h
@@ -9,12 +9,15 @@
#include "base/scoped_ptr.h"
#include "chrome/browser/download/download_manager.h"
+#include "chrome/common/animation.h"
class BaseDownloadItemModel;
class DownloadShelfContextMenuGtk;
class NineBox;
+class SlideAnimation;
-class DownloadItemGtk : DownloadItem::Observer {
+class DownloadItemGtk : public DownloadItem::Observer,
+ public AnimationDelegate {
public:
// DownloadItemGtk takes ownership of |download_item_model|.
DownloadItemGtk(BaseDownloadItemModel* download_item_model,
@@ -24,10 +27,13 @@ class DownloadItemGtk : DownloadItem::Observer {
// destroying its children. Hence we do nothing in the destructor.
~DownloadItemGtk();
- // DownloadItem::Observer implementation
+ // DownloadItem::Observer implementation.
virtual void OnDownloadUpdated(DownloadItem* download);
virtual void OnDownloadOpened(DownloadItem* download) { }
+ // AnimationDelegate implementation.
+ virtual void AnimationProgressed(const Animation* animation);
+
private:
static void InitNineBoxes();
@@ -59,6 +65,9 @@ class DownloadItemGtk : DownloadItem::Observer {
// animation.
GtkWidget* body_;
+ // The GtkLabel that holds the download title text.
+ GtkWidget* name_label_;
+
// The GtkLabel that holds the status text.
GtkWidget* status_label_;
@@ -78,6 +87,9 @@ class DownloadItemGtk : DownloadItem::Observer {
// This is the leftmost widget on |parent_shelf_| that is not a download item.
// We do not want to overlap it.
GtkWidget* bounding_widget_;
+
+ // The animation when this item is first added to the shelf.
+ scoped_ptr<SlideAnimation> new_item_animation_;
};
#endif // CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_
diff --git a/chrome/browser/gtk/download_shelf_gtk.cc b/chrome/browser/gtk/download_shelf_gtk.cc
index 9e5d8b9..96c6819 100644
--- a/chrome/browser/gtk/download_shelf_gtk.cc
+++ b/chrome/browser/gtk/download_shelf_gtk.cc
@@ -41,6 +41,9 @@ static GdkColor kBackgroundColor = GDK_COLOR_RGB(230, 237, 244);
// Border color (the top pixel of the shelf).
static GdkColor kBorderColor = GDK_COLOR_RGB(214, 214, 214);
+// Speed of the shelf show/hide animation.
+static const int kShelfAnimationDurationMs = 120;
+
} // namespace
// static
@@ -107,7 +110,9 @@ DownloadShelfGtk::DownloadShelfGtk(TabContents* tab_contents)
gtk_box_pack_end(GTK_BOX(hbox_), link_hbox_, FALSE, FALSE, 0);
slide_widget_.reset(new SlideAnimatorGtk(shelf_.get(),
- SlideAnimatorGtk::UP, NULL));
+ SlideAnimatorGtk::UP,
+ kShelfAnimationDurationMs,
+ false, NULL));
// Stick ourselves at the bottom of the parent tab contents.
GtkWidget* parent_contents = tab_contents->GetNativeView();
gtk_box_pack_end(GTK_BOX(parent_contents), slide_widget_->widget(),
diff --git a/chrome/browser/gtk/infobar_gtk.cc b/chrome/browser/gtk/infobar_gtk.cc
index 0e4046e..ca5d7126 100644
--- a/chrome/browser/gtk/infobar_gtk.cc
+++ b/chrome/browser/gtk/infobar_gtk.cc
@@ -68,7 +68,7 @@ InfoBar::InfoBar(InfoBarDelegate* delegate)
slide_widget_.reset(new SlideAnimatorGtk(border_bin_.get(),
SlideAnimatorGtk::DOWN,
- this));
+ 0, true, this));
// We store a pointer back to |this| so we can refer to it from the infobar
// container.
g_object_set_data(G_OBJECT(slide_widget_->widget()), "info-bar", this);
diff --git a/chrome/browser/gtk/slide_animator_gtk.cc b/chrome/browser/gtk/slide_animator_gtk.cc
index e77756e..083d1e2 100644
--- a/chrome/browser/gtk/slide_animator_gtk.cc
+++ b/chrome/browser/gtk/slide_animator_gtk.cc
@@ -26,6 +26,8 @@ void OnSizeAllocate(GtkWidget* fixed,
SlideAnimatorGtk::SlideAnimatorGtk(GtkWidget* child,
Direction direction,
+ int duration,
+ bool linear,
Delegate* delegate)
: child_(child),
direction_(direction),
@@ -42,7 +44,11 @@ SlideAnimatorGtk::SlideAnimatorGtk(GtkWidget* child,
G_CALLBACK(OnSizeAllocate), child_);
animation_.reset(new SlideAnimation(this));
- animation_->SetTweenType(SlideAnimation::NONE);
+ // Default tween type is EASE_OUT.
+ if (linear)
+ animation_->SetTweenType(SlideAnimation::NONE);
+ if (duration != 0)
+ animation_->SetSlideDuration(duration);
}
SlideAnimatorGtk::~SlideAnimatorGtk() {
diff --git a/chrome/browser/gtk/slide_animator_gtk.h b/chrome/browser/gtk/slide_animator_gtk.h
index f884913..054e9ec 100644
--- a/chrome/browser/gtk/slide_animator_gtk.h
+++ b/chrome/browser/gtk/slide_animator_gtk.h
@@ -32,9 +32,15 @@ class SlideAnimatorGtk : public AnimationDelegate {
// |child| is the widget we pack into |widget_|.
// |direction| indicates which side the contents will appear to come from.
+ // |duration| is the duration of the slide in milliseconds, or 0 for default.
+ // |linear| controls how the animation progresses. If true, the
+ // velocity of the slide is constant over time, otherwise it goes a bit faster
+ // at the beginning and slows to a halt.
// |delegate| may be NULL.
SlideAnimatorGtk(GtkWidget* child,
Direction direction,
+ int duration,
+ bool linear,
Delegate* delegate);
virtual ~SlideAnimatorGtk();