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

Side by Side Diff: chrome/browser/gtk/tabs/tab_renderer_gtk.cc

Issue 155601: GTK Themes: Tint throbbers like we tint all other buttons in the interface. (Closed)
Patch Set: Created 11 years, 5 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/tabs/tab_renderer_gtk.h" 5 #include "chrome/browser/gtk/tabs/tab_renderer_gtk.h"
6 6
7 #include "app/gfx/canvas_paint.h" 7 #include "app/gfx/canvas_paint.h"
8 #include "app/gfx/favicon_size.h" 8 #include "app/gfx/favicon_size.h"
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
11 #include "chrome/browser/browser.h" 11 #include "chrome/browser/browser.h"
12 #include "chrome/browser/browser_theme_provider.h" 12 #include "chrome/browser/browser_theme_provider.h"
13 #include "chrome/browser/gtk/custom_button.h" 13 #include "chrome/browser/gtk/custom_button.h"
14 #include "chrome/browser/profile.h" 14 #include "chrome/browser/profile.h"
15 #include "chrome/browser/tab_contents/tab_contents.h" 15 #include "chrome/browser/tab_contents/tab_contents.h"
16 #include "chrome/common/gtk_util.h" 16 #include "chrome/common/gtk_util.h"
17 #include "chrome/common/notification_service.h"
17 #include "grit/app_resources.h" 18 #include "grit/app_resources.h"
18 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
19 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
20 #include "skia/ext/image_operations.h" 21 #include "skia/ext/image_operations.h"
21 22
22 namespace { 23 namespace {
23 24
24 const int kLeftPadding = 16; 25 const int kLeftPadding = 16;
25 const int kTopPadding = 6; 26 const int kTopPadding = 6;
26 const int kRightPadding = 15; 27 const int kRightPadding = 15;
(...skipping 17 matching lines...) Expand all
44 const SkScalar kTabTopCurveWidth = 4; 45 const SkScalar kTabTopCurveWidth = 4;
45 const SkScalar kTabBottomCurveWidth = 3; 46 const SkScalar kTabBottomCurveWidth = 3;
46 47
47 // The vertical and horizontal offset used to position the close button 48 // The vertical and horizontal offset used to position the close button
48 // in the tab. TODO(jhawkins): Ask pkasting what the Fuzz is about. 49 // in the tab. TODO(jhawkins): Ask pkasting what the Fuzz is about.
49 const int kCloseButtonVertFuzz = 0; 50 const int kCloseButtonVertFuzz = 0;
50 const int kCloseButtonHorzFuzz = 5; 51 const int kCloseButtonHorzFuzz = 5;
51 52
52 SkBitmap* crashed_fav_icon = NULL; 53 SkBitmap* crashed_fav_icon = NULL;
53 54
54 TabRendererGtk::LoadingAnimation::Data loading_animation_data; 55 } // namespace
55 56
56 // Loads the loading animation images and data. 57 TabRendererGtk::LoadingAnimation::Data::Data(ThemeProvider* theme_provider) {
57 void InitializeLoadingAnimationData(
58 ResourceBundle* rb, TabRendererGtk::LoadingAnimation::Data* data) {
59 // The loading animation image is a strip of states. Each state must be 58 // The loading animation image is a strip of states. Each state must be
60 // square, so the height must divide the width evenly. 59 // square, so the height must divide the width evenly.
61 data->loading_animation_frames = rb->GetBitmapNamed(IDR_THROBBER); 60 loading_animation_frames = theme_provider->GetBitmapNamed(IDR_THROBBER);
62 DCHECK(data->loading_animation_frames); 61 DCHECK(loading_animation_frames);
63 DCHECK_EQ(data->loading_animation_frames->width() % 62 DCHECK_EQ(loading_animation_frames->width() %
64 data->loading_animation_frames->height(), 0); 63 loading_animation_frames->height(), 0);
65 data->loading_animation_frame_count = 64 loading_animation_frame_count =
66 data->loading_animation_frames->width() / 65 loading_animation_frames->width() /
67 data->loading_animation_frames->height(); 66 loading_animation_frames->height();
68 67
69 data->waiting_animation_frames = 68 waiting_animation_frames =
70 rb->GetBitmapNamed(IDR_THROBBER_WAITING); 69 theme_provider->GetBitmapNamed(IDR_THROBBER_WAITING);
71 DCHECK(data->waiting_animation_frames); 70 DCHECK(waiting_animation_frames);
72 DCHECK_EQ(data->waiting_animation_frames->width() % 71 DCHECK_EQ(waiting_animation_frames->width() %
73 data->waiting_animation_frames->height(), 0); 72 waiting_animation_frames->height(), 0);
74 data->waiting_animation_frame_count = 73 waiting_animation_frame_count =
75 data->waiting_animation_frames->width() / 74 waiting_animation_frames->width() /
76 data->waiting_animation_frames->height(); 75 waiting_animation_frames->height();
77 76
78 data->waiting_to_loading_frame_count_ratio = 77 waiting_to_loading_frame_count_ratio =
79 data->waiting_animation_frame_count / 78 waiting_animation_frame_count /
80 data->loading_animation_frame_count; 79 loading_animation_frame_count;
81 // TODO(beng): eventually remove this when we have a proper themeing system. 80 // TODO(beng): eventually remove this when we have a proper themeing system.
82 // themes not supporting IDR_THROBBER_WAITING are causing this 81 // themes not supporting IDR_THROBBER_WAITING are causing this
83 // value to be 0 which causes DIV0 crashes. The value of 5 82 // value to be 0 which causes DIV0 crashes. The value of 5
84 // matches the current bitmaps in our source. 83 // matches the current bitmaps in our source.
85 if (data->waiting_to_loading_frame_count_ratio == 0) 84 if (waiting_to_loading_frame_count_ratio == 0)
86 data->waiting_to_loading_frame_count_ratio = 5; 85 waiting_to_loading_frame_count_ratio = 5;
87 } 86 }
88 87
89 } // namespace 88 TabRendererGtk::LoadingAnimation::Data::Data(
89 int loading, int waiting, int waiting_to_loading)
90 : waiting_animation_frames(NULL),
91 loading_animation_frames(NULL),
92 loading_animation_frame_count(loading),
93 waiting_animation_frame_count(waiting),
94 waiting_to_loading_frame_count_ratio(waiting_to_loading) {
95 }
90 96
91 bool TabRendererGtk::initialized_ = false; 97 bool TabRendererGtk::initialized_ = false;
92 TabRendererGtk::TabImage TabRendererGtk::tab_active_ = {0}; 98 TabRendererGtk::TabImage TabRendererGtk::tab_active_ = {0};
93 TabRendererGtk::TabImage TabRendererGtk::tab_inactive_ = {0}; 99 TabRendererGtk::TabImage TabRendererGtk::tab_inactive_ = {0};
94 TabRendererGtk::TabImage TabRendererGtk::tab_alpha = {0}; 100 TabRendererGtk::TabImage TabRendererGtk::tab_alpha = {0};
95 gfx::Font* TabRendererGtk::title_font_ = NULL; 101 gfx::Font* TabRendererGtk::title_font_ = NULL;
96 int TabRendererGtk::title_font_height_ = 0; 102 int TabRendererGtk::title_font_height_ = 0;
97 int TabRendererGtk::close_button_width_ = 0; 103 int TabRendererGtk::close_button_width_ = 0;
98 int TabRendererGtk::close_button_height_ = 0; 104 int TabRendererGtk::close_button_height_ = 0;
99 SkColor TabRendererGtk::selected_title_color_ = SK_ColorBLACK; 105 SkColor TabRendererGtk::selected_title_color_ = SK_ColorBLACK;
100 SkColor TabRendererGtk::unselected_title_color_ = SkColorSetRGB(64, 64, 64); 106 SkColor TabRendererGtk::unselected_title_color_ = SkColorSetRGB(64, 64, 64);
101 int TabRendererGtk::pinned_tab_renderer_as_tab_width_ = 0; 107 int TabRendererGtk::pinned_tab_renderer_as_tab_width_ = 0;
102 int TabRendererGtk::pinned_tab_pref_width_ = 0; 108 int TabRendererGtk::pinned_tab_pref_width_ = 0;
103 109
104 //////////////////////////////////////////////////////////////////////////////// 110 ////////////////////////////////////////////////////////////////////////////////
105 // TabRendererGtk::LoadingAnimation, public: 111 // TabRendererGtk::LoadingAnimation, public:
106 // 112 //
107 TabRendererGtk::LoadingAnimation::LoadingAnimation(const Data* data) 113 TabRendererGtk::LoadingAnimation::LoadingAnimation(
108 : data_(data), animation_state_(ANIMATION_NONE), animation_frame_(0) { 114 ThemeProvider* theme_provider)
115 : data_(new Data(theme_provider)),
116 theme_provider_(theme_provider),
117 animation_state_(ANIMATION_NONE),
118 animation_frame_(0) {
119 registrar_.Add(this,
120 NotificationType::BROWSER_THEME_CHANGED,
121 NotificationService::AllSources());
122 }
123
124 TabRendererGtk::LoadingAnimation::LoadingAnimation(
125 const LoadingAnimation::Data& data)
126 : data_(new Data(data)),
127 theme_provider_(NULL),
128 animation_state_(ANIMATION_NONE),
129 animation_frame_(0) {
109 } 130 }
110 131
111 void TabRendererGtk::LoadingAnimation::ValidateLoadingAnimation( 132 void TabRendererGtk::LoadingAnimation::ValidateLoadingAnimation(
112 AnimationState animation_state) { 133 AnimationState animation_state) {
113 if (animation_state_ != animation_state) { 134 if (animation_state_ != animation_state) {
114 // The waiting animation is the reverse of the loading animation, but at a 135 // The waiting animation is the reverse of the loading animation, but at a
115 // different rate - the following reverses and scales the animation_frame_ 136 // different rate - the following reverses and scales the animation_frame_
116 // so that the frame is at an equivalent position when going from one 137 // so that the frame is at an equivalent position when going from one
117 // animation to the other. 138 // animation to the other.
118 if (animation_state_ == ANIMATION_WAITING && 139 if (animation_state_ == ANIMATION_WAITING &&
119 animation_state == ANIMATION_LOADING) { 140 animation_state == ANIMATION_LOADING) {
120 animation_frame_ = data_->loading_animation_frame_count - 141 animation_frame_ = data_->loading_animation_frame_count -
121 (animation_frame_ / data_->waiting_to_loading_frame_count_ratio); 142 (animation_frame_ / data_->waiting_to_loading_frame_count_ratio);
122 } 143 }
123 animation_state_ = animation_state; 144 animation_state_ = animation_state;
124 } 145 }
125 146
126 if (animation_state_ != ANIMATION_NONE) { 147 if (animation_state_ != ANIMATION_NONE) {
127 animation_frame_ = ++animation_frame_ % 148 animation_frame_ = ++animation_frame_ %
128 ((animation_state_ == ANIMATION_WAITING) ? 149 ((animation_state_ == ANIMATION_WAITING) ?
129 data_->waiting_animation_frame_count : 150 data_->waiting_animation_frame_count :
130 data_->loading_animation_frame_count); 151 data_->loading_animation_frame_count);
131 } else { 152 } else {
132 animation_frame_ = 0; 153 animation_frame_ = 0;
133 } 154 }
134 } 155 }
135 156
157 void TabRendererGtk::LoadingAnimation::Observe(
158 NotificationType type,
159 const NotificationSource& source,
160 const NotificationDetails& details) {
161 DCHECK(type == NotificationType::BROWSER_THEME_CHANGED);
162 data_.reset(new Data(theme_provider_));
163 }
164
136 //////////////////////////////////////////////////////////////////////////////// 165 ////////////////////////////////////////////////////////////////////////////////
137 // FaviconCrashAnimation 166 // FaviconCrashAnimation
138 // 167 //
139 // A custom animation subclass to manage the favicon crash animation. 168 // A custom animation subclass to manage the favicon crash animation.
140 class TabRendererGtk::FavIconCrashAnimation : public Animation, 169 class TabRendererGtk::FavIconCrashAnimation : public Animation,
141 public AnimationDelegate { 170 public AnimationDelegate {
142 public: 171 public:
143 explicit FavIconCrashAnimation(TabRendererGtk* target) 172 explicit FavIconCrashAnimation(TabRendererGtk* target)
144 : ALLOW_THIS_IN_INITIALIZER_LIST(Animation(1000, 25, this)), 173 : ALLOW_THIS_IN_INITIALIZER_LIST(Animation(1000, 25, this)),
145 target_(target) { 174 target_(target) {
(...skipping 22 matching lines...) Expand all
168 197
169 private: 198 private:
170 TabRendererGtk* target_; 199 TabRendererGtk* target_;
171 200
172 DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation); 201 DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation);
173 }; 202 };
174 203
175 //////////////////////////////////////////////////////////////////////////////// 204 ////////////////////////////////////////////////////////////////////////////////
176 // TabRendererGtk, public: 205 // TabRendererGtk, public:
177 206
178 TabRendererGtk::TabRendererGtk() 207 TabRendererGtk::TabRendererGtk(ThemeProvider* theme_provider)
179 : showing_icon_(false), 208 : showing_icon_(false),
180 showing_close_button_(false), 209 showing_close_button_(false),
181 fav_icon_hiding_offset_(0), 210 fav_icon_hiding_offset_(0),
182 should_display_crashed_favicon_(false), 211 should_display_crashed_favicon_(false),
183 loading_animation_(&loading_animation_data) { 212 loading_animation_(theme_provider) {
184 InitResources(); 213 InitResources();
185 214
186 data_.pinned = false; 215 data_.pinned = false;
187 216
188 tab_.Own(gtk_fixed_new()); 217 tab_.Own(gtk_fixed_new());
189 gtk_widget_set_app_paintable(tab_.get(), TRUE); 218 gtk_widget_set_app_paintable(tab_.get(), TRUE);
190 g_signal_connect(G_OBJECT(tab_.get()), "expose-event", 219 g_signal_connect(G_OBJECT(tab_.get()), "expose-event",
191 G_CALLBACK(OnExpose), this); 220 G_CALLBACK(OnExpose), this);
192 close_button_.reset(MakeCloseButton()); 221 close_button_.reset(MakeCloseButton());
193 gtk_widget_show(tab_.get()); 222 gtk_widget_show(tab_.get());
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 return; 817 return;
789 818
790 LoadTabImages(); 819 LoadTabImages();
791 820
792 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 821 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
793 // Force the font size to 10pt. 822 // Force the font size to 10pt.
794 gfx::Font base_font = rb.GetFont(ResourceBundle::BaseFont); 823 gfx::Font base_font = rb.GetFont(ResourceBundle::BaseFont);
795 title_font_ = new gfx::Font(gfx::Font::CreateFont(base_font.FontName(), 10)); 824 title_font_ = new gfx::Font(gfx::Font::CreateFont(base_font.FontName(), 10));
796 title_font_height_ = title_font_->height(); 825 title_font_height_ = title_font_->height();
797 826
798 InitializeLoadingAnimationData(&rb, &loading_animation_data);
799
800 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON); 827 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON);
801 828
802 initialized_ = true; 829 initialized_ = true;
803 } 830 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/tabs/tab_renderer_gtk.h ('k') | chrome/browser/gtk/tabs/tab_renderer_gtk_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698