stylecontext: Move background_is_opaque() function

The new way, it no longer depends on the style context, but on the
CssStyle. This will become relevant in the next commit.
This commit is contained in:
Benjamin Otte 2016-02-25 15:40:04 +01:00
parent 374494b928
commit 71a9fd9d83
5 changed files with 39 additions and 39 deletions

View File

@ -19,6 +19,7 @@
#include "gtkdebug.h"
#include "gtkpixelcacheprivate.h"
#include "gtkrenderbackgroundprivate.h"
#include "gtkstylecontextprivate.h"
#define BLOW_CACHE_TIMEOUT_SEC 20
@ -198,7 +199,7 @@ _gtk_pixel_cache_create_surface_if_needed (GtkPixelCache *cache,
{
content = CAIRO_CONTENT_COLOR_ALPHA;
if (cache->style_context &&
_gtk_style_context_is_background_opaque (cache->style_context))
gtk_css_style_render_background_is_opaque (gtk_style_context_lookup_style (cache->style_context)))
content = CAIRO_CONTENT_COLOR;
}

View File

@ -25,6 +25,7 @@
#include "gtkcssarrayvalueprivate.h"
#include "gtkcssbgsizevalueprivate.h"
#include "gtkcsscornervalueprivate.h"
#include "gtkcssenumvalueprivate.h"
#include "gtkcssimagevalueprivate.h"
#include "gtkcssnumbervalueprivate.h"
@ -344,3 +345,24 @@ gtk_css_style_render_background (GtkCssStyle *style,
cairo_restore (cr);
}
static gboolean
corner_value_is_right_angle (GtkCssValue *value)
{
return _gtk_css_corner_value_get_x (value, 100) <= 0.0 &&
_gtk_css_corner_value_get_y (value, 100) <= 0.0;
}
gboolean
gtk_css_style_render_background_is_opaque (GtkCssStyle *style)
{
const GdkRGBA *color;
color = _gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
return color->alpha >= 1.0
&& corner_value_is_right_angle (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS))
&& corner_value_is_right_angle (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS))
&& corner_value_is_right_angle (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS))
&& corner_value_is_right_angle (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS));
}

View File

@ -28,13 +28,15 @@
G_BEGIN_DECLS
void gtk_css_style_render_background (GtkCssStyle *style,
cairo_t *cr,
gdouble x,
gdouble y,
gdouble width,
gdouble height,
GtkJunctionSides junction);
void gtk_css_style_render_background (GtkCssStyle *style,
cairo_t *cr,
gdouble x,
gdouble y,
gdouble width,
gdouble height,
GtkJunctionSides junction);
gboolean gtk_css_style_render_background_is_opaque (GtkCssStyle *style);
G_END_DECLS

View File

@ -27,7 +27,6 @@
#include "gtkcontainerprivate.h"
#include "gtkcssanimatedstyleprivate.h"
#include "gtkcsscolorvalueprivate.h"
#include "gtkcsscornervalueprivate.h"
#include "gtkcssenumvalueprivate.h"
#include "gtkcssimagevalueprivate.h"
#include "gtkcssnodedeclarationprivate.h"
@ -45,6 +44,7 @@
#include "gtkdebug.h"
#include "gtkintl.h"
#include "gtkprivate.h"
#include "gtkrenderbackgroundprivate.h"
#include "gtkrendericonprivate.h"
#include "gtksettings.h"
#include "gtksettingsprivate.h"
@ -2435,13 +2435,6 @@ gtk_style_context_invalidate (GtkStyleContext *context)
gtk_style_context_validate (context, NULL);
}
static gboolean
corner_value_is_right_angle (GtkCssValue *value)
{
return _gtk_css_corner_value_get_x (value, 100) <= 0.0 &&
_gtk_css_corner_value_get_y (value, 100) <= 0.0;
}
/**
* gtk_style_context_set_background:
* @context: a #GtkStyleContext
@ -2460,8 +2453,6 @@ void
gtk_style_context_set_background (GtkStyleContext *context,
GdkWindow *window)
{
const GdkRGBA *color;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (GDK_IS_WINDOW (window));
@ -2473,10 +2464,12 @@ gtk_style_context_set_background (GtkStyleContext *context,
*
* We could indeed just set black instead of the color we have.
*/
color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
if (_gtk_style_context_is_background_opaque (context))
if (gtk_css_style_render_background_is_opaque (gtk_style_context_lookup_style (context)))
{
const GdkRGBA *color;
color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
gdk_window_set_background_rgba (window, color);
}
else
@ -3188,22 +3181,6 @@ gtk_gradient_resolve_for_context (GtkGradient *gradient,
priv->parent ? gtk_style_context_lookup_style (priv->parent) : NULL);
}
gboolean
_gtk_style_context_is_background_opaque (GtkStyleContext *context)
{
const GdkRGBA *color;
g_return_val_if_fail (context != NULL, FALSE);
color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
return (color->alpha >= 1.0 &&
corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS)) &&
corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS)) &&
corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS)) &&
corner_value_is_right_angle (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS)));
}
/**
* GtkStyleContextPrintFlags:
* @GTK_STYLE_CONTEXT_PRINT_RECURSE: Print the entire tree of

View File

@ -70,8 +70,6 @@ void _gtk_style_context_get_icon_extents (GtkStyleContext
gint width,
gint height);
gboolean _gtk_style_context_is_background_opaque (GtkStyleContext *context);
PangoAttrList *_gtk_style_context_get_pango_attributes (GtkStyleContext *context);
/* Accessibility support */