diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-05 21:09:45 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-05 21:09:45 +0000 |
commit | e1e4b6e8810a0fc7193ac9a55ad14588a2fff4d1 (patch) | |
tree | 73b6b47b1507e14f6aaa12793f0663ed29a913c4 /chrome/browser/gtk | |
parent | c256c0b0e7a2ca6401528b33b325cb19a981762b (diff) | |
download | chromium_src-e1e4b6e8810a0fc7193ac9a55ad14588a2fff4d1.zip chromium_src-e1e4b6e8810a0fc7193ac9a55ad14588a2fff4d1.tar.gz chromium_src-e1e4b6e8810a0fc7193ac9a55ad14588a2fff4d1.tar.bz2 |
Add the anti-clockwise waiting throbber to app mode/popup windows.
BUG=18181
Review URL: http://codereview.chromium.org/160653
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22537 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/browser_titlebar.cc | 58 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_titlebar.h | 13 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 2 |
3 files changed, 49 insertions, 24 deletions
diff --git a/chrome/browser/gtk/browser_titlebar.cc b/chrome/browser/gtk/browser_titlebar.cc index 26a57d1..594d673 100644 --- a/chrome/browser/gtk/browser_titlebar.cc +++ b/chrome/browser/gtk/browser_titlebar.cc @@ -22,6 +22,7 @@ #include "chrome/browser/gtk/standard_menus.h" #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" #include "chrome/browser/profile.h" +#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "grit/app_resources.h" @@ -271,11 +272,12 @@ void BrowserTitlebar::UpdateTitle() { g_free(label_markup); } -void BrowserTitlebar::UpdateThrobber(bool is_loading) { +void BrowserTitlebar::UpdateThrobber(TabContents* tab_contents) { DCHECK(app_mode_favicon_); - if (is_loading) { - GdkPixbuf* icon_pixbuf = throbber_.GetNextFrame(); + if (tab_contents && tab_contents->is_loading()) { + GdkPixbuf* icon_pixbuf = + throbber_.GetNextFrame(tab_contents->waiting_for_response()); gtk_image_set_from_pixbuf(GTK_IMAGE(app_mode_favicon_), icon_pixbuf); } else { if (browser_window_->browser()->type() == Browser::TYPE_APP) { @@ -453,16 +455,43 @@ void BrowserTitlebar::ExecuteCommand(int command_id) { // BrowserTitlebar::Throbber implementation // TODO(tc): Handle anti-clockwise spinning when waiting for a connection. -// We don't bother to clean this or the pixbufs it contains when we exit. +// We don't bother to clean up these or the pixbufs they contain when we exit. static std::vector<GdkPixbuf*>* g_throbber_frames = NULL; +static std::vector<GdkPixbuf*>* g_throbber_waiting_frames = NULL; -GdkPixbuf* BrowserTitlebar::Throbber::GetNextFrame() { +// Load |resource_id| from the ResourceBundle and split it into a series of +// square GdkPixbufs that get stored in |frames|. +static void MakeThrobberFrames(int resource_id, + std::vector<GdkPixbuf*>* frames) { + ResourceBundle &rb = ResourceBundle::GetSharedInstance(); + SkBitmap* frame_strip = rb.GetBitmapNamed(resource_id); + + // Each frame of the animation is a square, so we use the height as the + // frame size. + int frame_size = frame_strip->height(); + size_t num_frames = frame_strip->width() / frame_size; + + // Make a separate GdkPixbuf for each frame of the animation. + for (size_t i = 0; i < num_frames; ++i) { + SkBitmap frame = skia::ImageOperations::CreateTiledBitmap(*frame_strip, + i * frame_size, 0, frame_size, frame_size); + frames->push_back(gfx::GdkPixbufFromSkBitmap(&frame)); + } +} + +GdkPixbuf* BrowserTitlebar::Throbber::GetNextFrame(bool is_waiting) { Throbber::InitFrames(); - return (*g_throbber_frames)[current_frame_++ % g_throbber_frames->size()]; + if (is_waiting) { + return (*g_throbber_waiting_frames)[current_waiting_frame_++ % + g_throbber_waiting_frames->size()]; + } else { + return (*g_throbber_frames)[current_frame_++ % g_throbber_frames->size()]; + } } void BrowserTitlebar::Throbber::Reset() { current_frame_ = 0; + current_waiting_frame_ = 0; } // static @@ -470,19 +499,10 @@ void BrowserTitlebar::Throbber::InitFrames() { if (g_throbber_frames) return; - ResourceBundle &rb = ResourceBundle::GetSharedInstance(); - SkBitmap* frame_strip = rb.GetBitmapNamed(IDR_THROBBER_LIGHT); - - // Each frame of the animation is a square, so we use the height as the - // frame size. - int frame_size = frame_strip->height(); - size_t num_frames = frame_strip->width() / frame_size; + // We load the light version of the throbber since it'll be in the titlebar. g_throbber_frames = new std::vector<GdkPixbuf*>; + MakeThrobberFrames(IDR_THROBBER_LIGHT, g_throbber_frames); - // Make a separate GdkPixbuf for each frame of the animation. - for (size_t i = 0; i < num_frames; ++i) { - SkBitmap frame = skia::ImageOperations::CreateTiledBitmap(*frame_strip, - i * frame_size, 0, frame_size, frame_size); - g_throbber_frames->push_back(gfx::GdkPixbufFromSkBitmap(&frame)); - } + g_throbber_waiting_frames = new std::vector<GdkPixbuf*>; + MakeThrobberFrames(IDR_THROBBER_WAITING_LIGHT, g_throbber_waiting_frames); } diff --git a/chrome/browser/gtk/browser_titlebar.h b/chrome/browser/gtk/browser_titlebar.h index 98a56ab..29b3cb2 100644 --- a/chrome/browser/gtk/browser_titlebar.h +++ b/chrome/browser/gtk/browser_titlebar.h @@ -17,6 +17,7 @@ class BrowserWindowGtk; class CustomDrawButton; +class TabContents; class TabStripGtk; class BrowserTitlebar : public MenuGtk::Delegate { @@ -37,7 +38,9 @@ class BrowserTitlebar : public MenuGtk::Delegate { void UpdateTitle(); // Called by the browser asking us to update the loading throbber. - void UpdateThrobber(bool is_loading); + // |tab_contents| is the tab that is associated with the window throbber. + // |tab_contents| can be null. + void UpdateThrobber(TabContents* tab_contents); // On Windows, right clicking in the titlebar background brings up the system // menu. There's no such thing on linux, so we just show the menu items we @@ -49,11 +52,12 @@ class BrowserTitlebar : public MenuGtk::Delegate { // we're showing. class Throbber { public: - Throbber() : current_frame_(0) {} + Throbber() : current_frame_(0), current_waiting_frame_(0) {} // Get the next frame in the animation. The image is owned by the throbber - // so the caller doesn't need to unref. - GdkPixbuf* GetNextFrame(); + // so the caller doesn't need to unref. |is_waiting| is true if we're + // still waiting for a response. + GdkPixbuf* GetNextFrame(bool is_waiting); // Reset back to the first frame. void Reset(); @@ -62,6 +66,7 @@ class BrowserTitlebar : public MenuGtk::Delegate { static void InitFrames(); int current_frame_; + int current_waiting_frame_; }; // Build the titlebar, the space above the tab diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index c962fbb..b005664 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -758,7 +758,7 @@ void BrowserWindowGtk::LoadingAnimationCallback() { // GetSelectedTabContents can return NULL for example under Purify when // the animations are running slowly and this function is called on // a timer through LoadingAnimationCallback. - titlebar_->UpdateThrobber(tab_contents && tab_contents->is_loading()); + titlebar_->UpdateThrobber(tab_contents); } } |