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 <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <gdk/gdk.h> | 8 #include <gdk/gdk.h> |
9 #include <gdk/gdkx.h> | 9 #include <gdk/gdkx.h> |
10 #include <gtk/gtk.h> | 10 #include <gtk/gtk.h> |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 // Get the color value of the single pixel. | 387 // Get the color value of the single pixel. |
388 SkColor GetPixelValue() { | 388 SkColor GetPixelValue() { |
389 return *reinterpret_cast<SkColor*>(cairo_image_surface_get_data(surface_)); | 389 return *reinterpret_cast<SkColor*>(cairo_image_surface_get_data(surface_)); |
390 } | 390 } |
391 | 391 |
392 private: | 392 private: |
393 cairo_surface_t* surface_; | 393 cairo_surface_t* surface_; |
394 cairo_t* cairo_; | 394 cairo_t* cairo_; |
395 }; | 395 }; |
396 | 396 |
| 397 void RenderBackground(cairo_t* cr, GtkStyleContext* context) { |
| 398 if (!context) |
| 399 return; |
| 400 RenderBackground(cr, gtk_style_context_get_parent(context)); |
| 401 gtk_render_background(context, cr, 0, 0, 1, 1); |
| 402 } |
| 403 |
397 SkColor GetBgColor(const char* css_selector) { | 404 SkColor GetBgColor(const char* css_selector) { |
398 // Backgrounds are more general than solid colors (eg. gradients), | 405 // Backgrounds are more general than solid colors (eg. gradients), |
399 // but chromium requires us to boil this down to one color. We | 406 // but chromium requires us to boil this down to one color. We |
400 // cannot use the background-color here because some themes leave it | 407 // cannot use the background-color here because some themes leave it |
401 // set to a garbage color because a background-image will cover it | 408 // set to a garbage color because a background-image will cover it |
402 // anyway. So we instead render the background into a single pixel, | 409 // anyway. So we instead render the background into a single pixel, |
403 // removing any borders, and hope that we get a good color. | 410 // removing any borders, and hope that we get a good color. |
404 auto context = GetStyleContextFromCss(css_selector); | 411 auto context = GetStyleContextFromCss(css_selector); |
405 RemoveBorders(context); | 412 RemoveBorders(context); |
406 PixelSurface surface; | 413 PixelSurface surface; |
407 gtk_render_background(context, surface.cairo(), 0, 0, 1, 1); | 414 RenderBackground(surface.cairo(), context); |
408 return surface.GetPixelValue(); | 415 return surface.GetPixelValue(); |
409 } | 416 } |
410 | 417 |
411 SkColor GetBorderColor(const char* css_selector) { | 418 SkColor GetBorderColor(const char* css_selector) { |
412 // Borders have the same issue as backgrounds, due to the | 419 // Borders have the same issue as backgrounds, due to the |
413 // border-image property. | 420 // border-image property. |
414 auto context = GetStyleContextFromCss(css_selector); | 421 auto context = GetStyleContextFromCss(css_selector); |
415 GtkStateFlags state = gtk_style_context_get_state(context); | 422 GtkStateFlags state = gtk_style_context_get_state(context); |
416 GtkBorderStyle border_style = GTK_BORDER_STYLE_NONE; | 423 GtkBorderStyle border_style = GTK_BORDER_STYLE_NONE; |
417 gtk_style_context_get(context, state, GTK_STYLE_PROPERTY_BORDER_STYLE, | 424 gtk_style_context_get(context, state, GTK_STYLE_PROPERTY_BORDER_STYLE, |
418 &border_style, nullptr); | 425 &border_style, nullptr); |
419 GtkBorder border; | 426 GtkBorder border; |
420 gtk_style_context_get_border(context, state, &border); | 427 gtk_style_context_get_border(context, state, &border); |
421 if ((border_style == GTK_BORDER_STYLE_NONE || | 428 if ((border_style == GTK_BORDER_STYLE_NONE || |
422 border_style == GTK_BORDER_STYLE_HIDDEN) || | 429 border_style == GTK_BORDER_STYLE_HIDDEN) || |
423 (!border.left && !border.right && !border.top && !border.bottom)) { | 430 (!border.left && !border.right && !border.top && !border.bottom)) { |
424 return SK_ColorTRANSPARENT; | 431 return SK_ColorTRANSPARENT; |
425 } | 432 } |
426 | 433 |
427 AddBorders(context); | 434 AddBorders(context); |
428 PixelSurface surface; | 435 PixelSurface surface; |
| 436 RenderBackground(surface.cairo(), context); |
429 gtk_render_frame(context, surface.cairo(), 0, 0, 1, 1); | 437 gtk_render_frame(context, surface.cairo(), 0, 0, 1, 1); |
430 return surface.GetPixelValue(); | 438 return surface.GetPixelValue(); |
431 } | 439 } |
432 #endif | 440 #endif |
433 | 441 |
434 } // namespace libgtkui | 442 } // namespace libgtkui |
OLD | NEW |