| 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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 SkColor GetBorderColor(const char* css_selector) { | 485 SkColor GetBorderColor(const char* css_selector) { |
| 486 // Borders have the same issue as backgrounds, due to the | 486 // Borders have the same issue as backgrounds, due to the |
| 487 // border-image property. | 487 // border-image property. |
| 488 auto context = GetStyleContextFromCss(css_selector); | 488 auto context = GetStyleContextFromCss(css_selector); |
| 489 gfx::Size size(24, 24); | 489 gfx::Size size(24, 24); |
| 490 CairoSurface surface(size); | 490 CairoSurface surface(size); |
| 491 gtk_render_frame(context, surface.cairo(), 0, 0, size.width(), size.height()); | 491 gtk_render_frame(context, surface.cairo(), 0, 0, size.width(), size.height()); |
| 492 return surface.GetAveragePixelValue(true); | 492 return surface.GetAveragePixelValue(true); |
| 493 } | 493 } |
| 494 | 494 |
| 495 ScopedStyleContext GetSelectedStyleContext(const char* css_selector) { | 495 SkColor GetSelectionBgColor(const char* css_selector) { |
| 496 auto context = GetStyleContextFromCss(css_selector); | 496 auto context = GetStyleContextFromCss(css_selector); |
| 497 if (GtkVersionCheck(3, 20)) { | |
| 498 context = AppendCssNodeToStyleContext(context, "#selection"); | |
| 499 } else { | |
| 500 GtkStateFlags state = gtk_style_context_get_state(context); | |
| 501 state = static_cast<GtkStateFlags>(state | GTK_STATE_FLAG_SELECTED); | |
| 502 gtk_style_context_set_state(context, state); | |
| 503 } | |
| 504 return context; | |
| 505 } | |
| 506 | |
| 507 SkColor GetSelectedTextColor(const char* css_selector) { | |
| 508 return GetFgColorFromStyleContext(GetSelectedStyleContext(css_selector)); | |
| 509 } | |
| 510 | |
| 511 SkColor GetSelectedBgColor(const char* css_selector) { | |
| 512 auto context = GetSelectedStyleContext(css_selector); | |
| 513 if (GtkVersionCheck(3, 20)) | 497 if (GtkVersionCheck(3, 20)) |
| 514 return GetBgColorFromStyleContext(context); | 498 return GetBgColorFromStyleContext(context); |
| 515 // This is verbatim how Gtk gets the selection color on versions before 3.20. | 499 // This is verbatim how Gtk gets the selection color on versions before 3.20. |
| 516 GdkRGBA selection_color; | 500 GdkRGBA selection_color; |
| 517 G_GNUC_BEGIN_IGNORE_DEPRECATIONS; | 501 G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 518 gtk_style_context_get_background_color( | 502 gtk_style_context_get_background_color( |
| 519 context, gtk_style_context_get_state(context), &selection_color); | 503 context, gtk_style_context_get_state(context), &selection_color); |
| 520 G_GNUC_END_IGNORE_DEPRECATIONS; | 504 G_GNUC_END_IGNORE_DEPRECATIONS; |
| 521 return GdkRgbaToSkColor(selection_color); | 505 return GdkRgbaToSkColor(selection_color); |
| 522 } | 506 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 547 } | 531 } |
| 548 | 532 |
| 549 CairoSurface surface(gfx::Size(w, h)); | 533 CairoSurface surface(gfx::Size(w, h)); |
| 550 gtk_render_background(context, surface.cairo(), 0, 0, w, h); | 534 gtk_render_background(context, surface.cairo(), 0, 0, w, h); |
| 551 gtk_render_frame(context, surface.cairo(), 0, 0, w, h); | 535 gtk_render_frame(context, surface.cairo(), 0, 0, w, h); |
| 552 return surface.GetAveragePixelValue(false); | 536 return surface.GetAveragePixelValue(false); |
| 553 } | 537 } |
| 554 #endif | 538 #endif |
| 555 | 539 |
| 556 } // namespace libgtkui | 540 } // namespace libgtkui |
| OLD | NEW |