| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/ui/libgtkui/gtk_util.h" | 5 #include "chrome/browser/ui/libgtkui/gtk_util.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 context = AppendNode(context, widget_type); | 287 context = AppendNode(context, widget_type); |
| 288 } | 288 } |
| 289 return context; | 289 return context; |
| 290 } | 290 } |
| 291 | 291 |
| 292 SkColor GdkRgbaToSkColor(const GdkRGBA& color) { | 292 SkColor GdkRgbaToSkColor(const GdkRGBA& color) { |
| 293 return SkColorSetARGB(color.alpha * 255, color.red * 255, color.green * 255, | 293 return SkColorSetARGB(color.alpha * 255, color.red * 255, color.green * 255, |
| 294 color.blue * 255); | 294 color.blue * 255); |
| 295 } | 295 } |
| 296 | 296 |
| 297 SkColor GetFGColor(const char* css_selector) { | 297 SkColor GetFgColor(const char* css_selector) { |
| 298 auto context = GetStyleContextFromCss(css_selector); | 298 auto context = GetStyleContextFromCss(css_selector); |
| 299 GdkRGBA color; | 299 GdkRGBA color; |
| 300 gtk_style_context_get_color(context, gtk_style_context_get_state(context), | 300 gtk_style_context_get_color(context, gtk_style_context_get_state(context), |
| 301 &color); | 301 &color); |
| 302 return GdkRgbaToSkColor(color); | 302 return GdkRgbaToSkColor(color); |
| 303 } | 303 } |
| 304 | 304 |
| 305 GtkCssProvider* GetCssProvider(const char* css) { | 305 GtkCssProvider* GetCssProvider(const char* css) { |
| 306 GtkCssProvider* provider = gtk_css_provider_new(); | 306 GtkCssProvider* provider = gtk_css_provider_new(); |
| 307 GError* error = nullptr; | 307 GError* error = nullptr; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 // Get the color value of the single pixel. | 361 // Get the color value of the single pixel. |
| 362 SkColor GetPixelValue() { | 362 SkColor GetPixelValue() { |
| 363 return *reinterpret_cast<SkColor*>(cairo_image_surface_get_data(surface_)); | 363 return *reinterpret_cast<SkColor*>(cairo_image_surface_get_data(surface_)); |
| 364 } | 364 } |
| 365 | 365 |
| 366 private: | 366 private: |
| 367 cairo_surface_t* surface_; | 367 cairo_surface_t* surface_; |
| 368 cairo_t* cairo_; | 368 cairo_t* cairo_; |
| 369 }; | 369 }; |
| 370 | 370 |
| 371 SkColor GetBGColor(const char* css_selector) { | 371 SkColor GetBgColor(const char* css_selector) { |
| 372 // Backgrounds are more general than solid colors (eg. gradients), | 372 // Backgrounds are more general than solid colors (eg. gradients), |
| 373 // but chromium requires us to boil this down to one color. We | 373 // but chromium requires us to boil this down to one color. We |
| 374 // cannot use the background-color here because some themes leave it | 374 // cannot use the background-color here because some themes leave it |
| 375 // set to a garbage color because a background-image will cover it | 375 // set to a garbage color because a background-image will cover it |
| 376 // anyway. So we instead render the background into a single pixel, | 376 // anyway. So we instead render the background into a single pixel, |
| 377 // removing any borders, and hope that we get a good color. | 377 // removing any borders, and hope that we get a good color. |
| 378 auto context = GetStyleContextFromCss(css_selector); | 378 auto context = GetStyleContextFromCss(css_selector); |
| 379 RemoveBorders(context); | 379 RemoveBorders(context); |
| 380 PixelSurface surface; | 380 PixelSurface surface; |
| 381 gtk_render_background(context, surface.cairo(), 0, 0, 1, 1); | 381 gtk_render_background(context, surface.cairo(), 0, 0, 1, 1); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 399 } | 399 } |
| 400 | 400 |
| 401 AddBorders(context); | 401 AddBorders(context); |
| 402 PixelSurface surface; | 402 PixelSurface surface; |
| 403 gtk_render_frame(context, surface.cairo(), 0, 0, 1, 1); | 403 gtk_render_frame(context, surface.cairo(), 0, 0, 1, 1); |
| 404 return surface.GetPixelValue(); | 404 return surface.GetPixelValue(); |
| 405 } | 405 } |
| 406 #endif | 406 #endif |
| 407 | 407 |
| 408 } // namespace libgtkui | 408 } // namespace libgtkui |
| OLD | NEW |