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

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

Issue 155588: GTK Themes: Tint throbbers like we tint all other buttons in the interface. (Closed)
Patch Set: Changes for tony 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
« no previous file with comments | « chrome/browser/gtk/tabs/tab_renderer_gtk.h ('k') | chrome/browser/gtk/tabs/tab_strip_gtk.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
90
91 bool TabRendererGtk::initialized_ = false; 88 bool TabRendererGtk::initialized_ = false;
92 TabRendererGtk::TabImage TabRendererGtk::tab_active_ = {0}; 89 TabRendererGtk::TabImage TabRendererGtk::tab_active_ = {0};
93 TabRendererGtk::TabImage TabRendererGtk::tab_inactive_ = {0}; 90 TabRendererGtk::TabImage TabRendererGtk::tab_inactive_ = {0};
94 TabRendererGtk::TabImage TabRendererGtk::tab_alpha = {0}; 91 TabRendererGtk::TabImage TabRendererGtk::tab_alpha = {0};
95 gfx::Font* TabRendererGtk::title_font_ = NULL; 92 gfx::Font* TabRendererGtk::title_font_ = NULL;
96 int TabRendererGtk::title_font_height_ = 0; 93 int TabRendererGtk::title_font_height_ = 0;
97 int TabRendererGtk::close_button_width_ = 0; 94 int TabRendererGtk::close_button_width_ = 0;
98 int TabRendererGtk::close_button_height_ = 0; 95 int TabRendererGtk::close_button_height_ = 0;
99 SkColor TabRendererGtk::selected_title_color_ = SK_ColorBLACK; 96 SkColor TabRendererGtk::selected_title_color_ = SK_ColorBLACK;
100 SkColor TabRendererGtk::unselected_title_color_ = SkColorSetRGB(64, 64, 64); 97 SkColor TabRendererGtk::unselected_title_color_ = SkColorSetRGB(64, 64, 64);
101 int TabRendererGtk::pinned_tab_renderer_as_tab_width_ = 0; 98 int TabRendererGtk::pinned_tab_renderer_as_tab_width_ = 0;
102 int TabRendererGtk::pinned_tab_pref_width_ = 0; 99 int TabRendererGtk::pinned_tab_pref_width_ = 0;
103 100
104 //////////////////////////////////////////////////////////////////////////////// 101 ////////////////////////////////////////////////////////////////////////////////
105 // TabRendererGtk::LoadingAnimation, public: 102 // TabRendererGtk::LoadingAnimation, public:
106 // 103 //
107 TabRendererGtk::LoadingAnimation::LoadingAnimation(const Data* data) 104 TabRendererGtk::LoadingAnimation::LoadingAnimation(
108 : data_(data), animation_state_(ANIMATION_NONE), animation_frame_(0) { 105 ThemeProvider* theme_provider)
106 : data_(new Data(theme_provider)),
107 theme_provider_(theme_provider),
108 animation_state_(ANIMATION_NONE),
109 animation_frame_(0) {
110 registrar_.Add(this,
111 NotificationType::BROWSER_THEME_CHANGED,
112 NotificationService::AllSources());
109 } 113 }
110 114
111 void TabRendererGtk::LoadingAnimation::ValidateLoadingAnimation( 115 void TabRendererGtk::LoadingAnimation::ValidateLoadingAnimation(
112 AnimationState animation_state) { 116 AnimationState animation_state) {
113 if (animation_state_ != animation_state) { 117 if (animation_state_ != animation_state) {
114 // The waiting animation is the reverse of the loading animation, but at a 118 // The waiting animation is the reverse of the loading animation, but at a
115 // different rate - the following reverses and scales the animation_frame_ 119 // different rate - the following reverses and scales the animation_frame_
116 // so that the frame is at an equivalent position when going from one 120 // so that the frame is at an equivalent position when going from one
117 // animation to the other. 121 // animation to the other.
118 if (animation_state_ == ANIMATION_WAITING && 122 if (animation_state_ == ANIMATION_WAITING &&
119 animation_state == ANIMATION_LOADING) { 123 animation_state == ANIMATION_LOADING) {
120 animation_frame_ = data_->loading_animation_frame_count - 124 animation_frame_ = data_->loading_animation_frame_count -
121 (animation_frame_ / data_->waiting_to_loading_frame_count_ratio); 125 (animation_frame_ / data_->waiting_to_loading_frame_count_ratio);
122 } 126 }
123 animation_state_ = animation_state; 127 animation_state_ = animation_state;
124 } 128 }
125 129
126 if (animation_state_ != ANIMATION_NONE) { 130 if (animation_state_ != ANIMATION_NONE) {
127 animation_frame_ = ++animation_frame_ % 131 animation_frame_ = ++animation_frame_ %
128 ((animation_state_ == ANIMATION_WAITING) ? 132 ((animation_state_ == ANIMATION_WAITING) ?
129 data_->waiting_animation_frame_count : 133 data_->waiting_animation_frame_count :
130 data_->loading_animation_frame_count); 134 data_->loading_animation_frame_count);
131 } else { 135 } else {
132 animation_frame_ = 0; 136 animation_frame_ = 0;
133 } 137 }
134 } 138 }
135 139
140 void TabRendererGtk::LoadingAnimation::Observe(
141 NotificationType type,
142 const NotificationSource& source,
143 const NotificationDetails& details) {
144 DCHECK(type == NotificationType::BROWSER_THEME_CHANGED);
145 data_.reset(new Data(theme_provider_));
146 }
147
136 //////////////////////////////////////////////////////////////////////////////// 148 ////////////////////////////////////////////////////////////////////////////////
137 // FaviconCrashAnimation 149 // FaviconCrashAnimation
138 // 150 //
139 // A custom animation subclass to manage the favicon crash animation. 151 // A custom animation subclass to manage the favicon crash animation.
140 class TabRendererGtk::FavIconCrashAnimation : public Animation, 152 class TabRendererGtk::FavIconCrashAnimation : public Animation,
141 public AnimationDelegate { 153 public AnimationDelegate {
142 public: 154 public:
143 explicit FavIconCrashAnimation(TabRendererGtk* target) 155 explicit FavIconCrashAnimation(TabRendererGtk* target)
144 : ALLOW_THIS_IN_INITIALIZER_LIST(Animation(1000, 25, this)), 156 : ALLOW_THIS_IN_INITIALIZER_LIST(Animation(1000, 25, this)),
145 target_(target) { 157 target_(target) {
(...skipping 22 matching lines...) Expand all
168 180
169 private: 181 private:
170 TabRendererGtk* target_; 182 TabRendererGtk* target_;
171 183
172 DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation); 184 DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation);
173 }; 185 };
174 186
175 //////////////////////////////////////////////////////////////////////////////// 187 ////////////////////////////////////////////////////////////////////////////////
176 // TabRendererGtk, public: 188 // TabRendererGtk, public:
177 189
178 TabRendererGtk::TabRendererGtk() 190 TabRendererGtk::TabRendererGtk(ThemeProvider* theme_provider)
179 : showing_icon_(false), 191 : showing_icon_(false),
180 showing_close_button_(false), 192 showing_close_button_(false),
181 fav_icon_hiding_offset_(0), 193 fav_icon_hiding_offset_(0),
182 should_display_crashed_favicon_(false), 194 should_display_crashed_favicon_(false),
183 loading_animation_(&loading_animation_data) { 195 loading_animation_(theme_provider) {
184 InitResources(); 196 InitResources();
185 197
186 data_.pinned = false; 198 data_.pinned = false;
187 199
188 tab_.Own(gtk_fixed_new()); 200 tab_.Own(gtk_fixed_new());
189 gtk_widget_set_app_paintable(tab_.get(), TRUE); 201 gtk_widget_set_app_paintable(tab_.get(), TRUE);
190 g_signal_connect(G_OBJECT(tab_.get()), "expose-event", 202 g_signal_connect(G_OBJECT(tab_.get()), "expose-event",
191 G_CALLBACK(OnExpose), this); 203 G_CALLBACK(OnExpose), this);
192 close_button_.reset(MakeCloseButton()); 204 close_button_.reset(MakeCloseButton());
193 gtk_widget_show(tab_.get()); 205 gtk_widget_show(tab_.get());
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 return; 800 return;
789 801
790 LoadTabImages(); 802 LoadTabImages();
791 803
792 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 804 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
793 // Force the font size to 10pt. 805 // Force the font size to 10pt.
794 gfx::Font base_font = rb.GetFont(ResourceBundle::BaseFont); 806 gfx::Font base_font = rb.GetFont(ResourceBundle::BaseFont);
795 title_font_ = new gfx::Font(gfx::Font::CreateFont(base_font.FontName(), 10)); 807 title_font_ = new gfx::Font(gfx::Font::CreateFont(base_font.FontName(), 10));
796 title_font_height_ = title_font_->height(); 808 title_font_height_ = title_font_->height();
797 809
798 InitializeLoadingAnimationData(&rb, &loading_animation_data);
799
800 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON); 810 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON);
801 811
802 initialized_ = true; 812 initialized_ = true;
803 } 813 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/tabs/tab_renderer_gtk.h ('k') | chrome/browser/gtk/tabs/tab_strip_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698