Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/ui/gtk/throbber_gtk.cc

Issue 9837011: [Web Intents] CWS inline install for GTK (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/ui/gtk/throbber_gtk.h"
6
7 #include "base/logging.h"
8 #include "chrome/browser/ui/gtk/theme_service_gtk.h"
9 #include "chrome/common/chrome_notification_types.h"
10 #include "content/public/browser/notification_source.h"
11 #include "grit/ui_resources.h"
12 #include "ui/base/animation/tween.h"
13 #include "ui/gfx/image/cairo_cached_surface.h"
14
15 namespace {
16
17 // The length of a single cycle of the animation in milliseconds.
18 const int kThrobberDurationMs = 750;
19
20 }
James Hawkins 2012/03/30 21:35:02 } // namespace
binji 2012/03/30 23:03:51 Done.
21
22 ThrobberGtk::ThrobberGtk(ThemeServiceGtk* theme_service)
23 : theme_service_(theme_service),
24 ALLOW_THIS_IN_INITIALIZER_LIST(animation_(this)),
25 frames_(NULL),
26 num_frames_(0) {
27 Init();
28 theme_service_->InitThemesFor(this);
James Hawkins 2012/03/30 21:35:02 Move these two to Init()?
binji 2012/03/30 23:03:51 Done.
29 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
30 content::Source<ThemeService>(theme_service_));
31 }
32
33 ThrobberGtk::~ThrobberGtk() {
34 widget_.Destroy();
35 }
36
37 void ThrobberGtk::Start() {
38 animation_.Show();
39 }
40
41 void ThrobberGtk::Stop() {
42 animation_.Reset();
43 }
44
45 void ThrobberGtk::AnimationEnded(const ui::Animation* animation) {
46 animation_.Reset();
47 animation_.Show();
48 }
49
50 void ThrobberGtk::AnimationProgressed(const ui::Animation* animation) {
51 gtk_widget_queue_draw(widget_.get());
52 }
53
54 void ThrobberGtk::Observe(int type,
55 const content::NotificationSource& source,
56 const content::NotificationDetails& details) {
57 DCHECK(chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type);
James Hawkins 2012/03/30 21:35:02 nit: DCHECK_EQ
binji 2012/03/30 23:03:51 Done.
58 LoadFrames();
59 gtk_widget_queue_draw(widget_.get());
60 }
61
62 gboolean ThrobberGtk::OnExpose(GtkWidget* widget, GdkEventExpose* expose) {
63 cairo_t* cairo_context =
64 gdk_cairo_create(GDK_DRAWABLE(gtk_widget_get_window(widget)));
65 GtkAllocation allocation;
66 gtk_widget_get_allocation(widget, &allocation);
67 cairo_translate(cairo_context, allocation.x, allocation.y);
68
69 gfx::CairoCachedSurface* ccs = frames_->ToCairo();
Evan Stade 2012/03/30 21:38:25 no opaque variable name abbreviations
binji 2012/03/30 23:03:51 Done.
70 const int frame =
71 static_cast<int>(animation_.GetCurrentValue() * (num_frames_ - 1));
72 const int image_size = ccs->Height();
73 const int image_offset = frame * image_size;
74
75 ccs->SetSource(cairo_context, widget, -image_offset, 0);
76 cairo_rectangle(cairo_context, 0, 0, image_size, image_size);
77 cairo_fill(cairo_context);
78 cairo_destroy(cairo_context);
79
80 return TRUE;
81 }
82
83 void ThrobberGtk::Init() {
84 animation_.SetSlideDuration(kThrobberDurationMs);
85 animation_.SetTweenType(ui::Tween::LINEAR);
86 widget_.Own(gtk_image_new());
87 gtk_widget_set_can_focus(widget_.get(), FALSE);
88 g_signal_connect(widget_.get(), "expose-event", G_CALLBACK(OnExposeThunk),
89 this);
90 }
91
92 void ThrobberGtk::LoadFrames() {
93 frames_ = theme_service_->GetImageNamed(IDR_THROBBER);
94 DCHECK(frames_);
95 const int width = frames_->ToCairo()->Width();
96 const int height = frames_->ToCairo()->Height();
97 DCHECK_EQ(width % height, 0);
James Hawkins 2012/03/30 21:35:02 nit: Constant value should be the first parameter.
binji 2012/03/30 23:03:51 Done.
98 num_frames_ = width / height;
99
100 gtk_widget_set_size_request(widget_.get(), width, height);
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698