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

Side by Side Diff: chrome/browser/gtk/gtk_theme_provider.cc

Issue 479006: re-apply r34183... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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
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/gtk_theme_provider.h" 5 #include "chrome/browser/gtk/gtk_theme_provider.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "app/gfx/color_utils.h" 9 #include "app/gfx/color_utils.h"
10 #include "app/gfx/gtk_util.h" 10 #include "app/gfx/gtk_util.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // the base color counts more than once. 169 // the base color counts more than once.
170 GdkColor color; 170 GdkColor color;
171 color.pixel = 0; 171 color.pixel = 0;
172 color.red = (text.red + (bg.red * kBgWeight)) / (1 + kBgWeight); 172 color.red = (text.red + (bg.red * kBgWeight)) / (1 + kBgWeight);
173 color.green = (text.green + (bg.green * kBgWeight)) / (1 + kBgWeight); 173 color.green = (text.green + (bg.green * kBgWeight)) / (1 + kBgWeight);
174 color.blue = (text.blue + (bg.blue * kBgWeight)) / (1 + kBgWeight); 174 color.blue = (text.blue + (bg.blue * kBgWeight)) / (1 + kBgWeight);
175 175
176 return color; 176 return color;
177 } 177 }
178 178
179 void GtkThemeProvider::GetScrollbarColors(GdkColor* thumb_active_color,
180 GdkColor* thumb_inactive_color,
181 GdkColor* track_color,
182 bool use_gtk_theme) {
183 if (!use_gtk_theme) {
184 // If using the default non-GTK colors, pick some reasonable choices of
185 // different greys.
186 thumb_active_color->pixel = 0;
187 thumb_active_color->red = 64250;
188 thumb_active_color->green = 63736;
189 thumb_active_color->blue = 62965;
190 thumb_inactive_color->pixel = 0;
191 thumb_inactive_color->red = 61680;
192 thumb_inactive_color->green = 60395;
193 thumb_inactive_color->blue = 58853;
194 track_color->pixel = 0;
195 track_color->red = 58339;
196 track_color->green = 56797;
197 track_color->blue = 55512;
198 return;
199 }
200
201 // Create window containing scrollbar elements
202 GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP);
203 GtkWidget* fixed = gtk_fixed_new();
204 GtkWidget* scrollbar = gtk_hscrollbar_new(NULL);
205 gtk_container_add(GTK_CONTAINER(window), fixed);
206 gtk_container_add(GTK_CONTAINER(fixed), scrollbar);
207 gtk_widget_realize(window);
208 gtk_widget_realize(scrollbar);
209
210 // Draw scrollbar thumb part and track into offscreen image
211 int kWidth = 100;
212 int kHeight = 20;
213 GtkStyle* style = gtk_rc_get_style(scrollbar);
214 GdkPixmap* pm = gdk_pixmap_new(window->window, kWidth, kHeight, -1);
215 GdkRectangle rect = { 0, 0, kWidth, kHeight };
216 unsigned char data[3*kWidth*kHeight];
217 for (int i = 0; i < 3; ++i) {
218 if (i < 2) {
219 // Thumb part
220 gtk_paint_slider(style, pm,
221 i == 0 ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
222 GTK_SHADOW_OUT, &rect, scrollbar, "slider", 0, 0,
223 kWidth, kHeight, GTK_ORIENTATION_HORIZONTAL);
224 } else {
225 // Track
226 gtk_paint_box(style, pm, GTK_STATE_ACTIVE, GTK_SHADOW_IN, &rect,
227 scrollbar, "trough-upper", 0, 0, kWidth, kHeight);
228 }
229 GdkPixbuf* pb = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB,
230 FALSE, 8, kWidth, kHeight,
231 3*kWidth, 0, 0);
232 gdk_pixbuf_get_from_drawable(pb, pm, NULL, 0, 0, 0, 0, kWidth, kHeight);
233
234 // Sample pixels
235 int components[3] = { 0 };
236 for (int y = 2; y < kHeight-2; ++y) {
237 for (int c = 0; c < 3; ++c) {
238 // Sample a vertical slice of pixels at about one-thirds from the
239 // left edge. This allows us to avoid any fixed graphics that might be
240 // located at the edges or in the center of the scrollbar.
241 // Each pixel is made up of a red, green, and blue component; taking up
242 // a total of three bytes.
243 components[c] += data[3*(kWidth/3 + y*kWidth) + c];
244 }
245 }
246 GdkColor* color = i == 0 ? thumb_active_color :
247 i == 1 ? thumb_inactive_color :
248 track_color;
249 color->pixel = 0;
250 // We sampled pixels across the full height of the image, ignoring a two
251 // pixel border. In some themes, the border has a completely different
252 // color which we do not want to factor into our average color computation.
253 //
254 // We now need to scale the colors from the 0..255 range, to the wider
255 // 0..65535 range, and we need to actually compute the average color; so,
256 // we divide by the total number of pixels in the sample.
257 color->red = components[0] * 65535 / (255*(kHeight-4));
258 color->green = components[1] * 65535 / (255*(kHeight-4));
259 color->blue = components[2] * 65535 / (255*(kHeight-4));
260
261 g_object_unref(pb);
262 }
263 g_object_unref(pm);
264
265 gtk_widget_destroy(window);
266 }
267
179 CairoCachedSurface* GtkThemeProvider::GetSurfaceNamed( 268 CairoCachedSurface* GtkThemeProvider::GetSurfaceNamed(
180 int id, GtkWidget* widget_on_display) { 269 int id, GtkWidget* widget_on_display) {
181 GdkDisplay* display = gtk_widget_get_display(widget_on_display); 270 GdkDisplay* display = gtk_widget_get_display(widget_on_display);
182 CairoCachedSurfaceMap& surface_map = per_display_surfaces_[display]; 271 CairoCachedSurfaceMap& surface_map = per_display_surfaces_[display];
183 272
184 // Check to see if we already have the pixbuf in the cache. 273 // Check to see if we already have the pixbuf in the cache.
185 CairoCachedSurfaceMap::const_iterator found = surface_map.find(id); 274 CairoCachedSurfaceMap::const_iterator found = surface_map.find(id);
186 if (found != surface_map.end()) 275 if (found != surface_map.end())
187 return found->second; 276 return found->second;
188 277
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 } 562 }
474 563
475 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button, 564 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button,
476 GtkThemeProvider* provider) { 565 GtkThemeProvider* provider) {
477 std::vector<GtkWidget*>::iterator it = 566 std::vector<GtkWidget*>::iterator it =
478 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(), 567 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(),
479 button); 568 button);
480 if (it != provider->chrome_buttons_.end()) 569 if (it != provider->chrome_buttons_.end())
481 provider->chrome_buttons_.erase(it); 570 provider->chrome_buttons_.erase(it);
482 } 571 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/gtk_theme_provider.h ('k') | chrome/browser/renderer_host/render_view_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698