1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/gtk/titlebar_throb_animation.h"
6 #include "grit/theme_resources.h"
7 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/skbitmap_operations.h"
13 // We don't bother to clean up these or the pixbufs they contain when we exit.
14 std::vector
<GdkPixbuf
*>* g_throbber_frames
= NULL
;
15 std::vector
<GdkPixbuf
*>* g_throbber_waiting_frames
= NULL
;
17 // Load |resource_id| from the ResourceBundle and split it into a series of
18 // square GdkPixbufs that get stored in |frames|.
19 void MakeThrobberFrames(int resource_id
, std::vector
<GdkPixbuf
*>* frames
) {
20 ui::ResourceBundle
&rb
= ui::ResourceBundle::GetSharedInstance();
21 SkBitmap frame_strip
= rb
.GetImageNamed(resource_id
).AsBitmap();
23 // Each frame of the animation is a square, so we use the height as the
25 int frame_size
= frame_strip
.height();
26 size_t num_frames
= frame_strip
.width() / frame_size
;
28 // Make a separate GdkPixbuf for each frame of the animation.
29 for (size_t i
= 0; i
< num_frames
; ++i
) {
30 SkBitmap frame
= SkBitmapOperations::CreateTiledBitmap(frame_strip
,
31 i
* frame_size
, 0, frame_size
, frame_size
);
32 frames
->push_back(gfx::GdkPixbufFromSkBitmap(frame
));
38 // TODO(tc): Handle anti-clockwise spinning when waiting for a connection.
40 TitlebarThrobAnimation::TitlebarThrobAnimation()
42 current_waiting_frame_(0) {
45 GdkPixbuf
* TitlebarThrobAnimation::GetNextFrame(bool is_waiting
) {
48 return (*g_throbber_waiting_frames
)[current_waiting_frame_
++ %
49 g_throbber_waiting_frames
->size()];
51 return (*g_throbber_frames
)[current_frame_
++ % g_throbber_frames
->size()];
55 void TitlebarThrobAnimation::Reset() {
57 current_waiting_frame_
= 0;
61 void TitlebarThrobAnimation::InitFrames() {
62 if (g_throbber_frames
)
65 // We load the light version of the throbber since it'll be in the titlebar.
66 g_throbber_frames
= new std::vector
<GdkPixbuf
*>;
67 MakeThrobberFrames(IDR_THROBBER_LIGHT
, g_throbber_frames
);
69 g_throbber_waiting_frames
= new std::vector
<GdkPixbuf
*>;
70 MakeThrobberFrames(IDR_THROBBER_WAITING_LIGHT
, g_throbber_waiting_frames
);