2011-05-19 18:47:17 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2011 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Author: Cosimo Cecchi <cosimoc@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-05-19 18:47:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-28 01:34:19 +00:00
|
|
|
#include "gtkcssshadowvalueprivate.h"
|
2012-01-02 14:44:45 +00:00
|
|
|
|
2012-11-08 16:33:53 +00:00
|
|
|
#include "gtkcsscolorvalueprivate.h"
|
2012-04-03 11:29:29 +00:00
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
2020-01-10 12:02:33 +00:00
|
|
|
#include "gtkcsscolorvalueprivate.h"
|
2018-03-20 03:33:58 +00:00
|
|
|
#include "gtksnapshotprivate.h"
|
2011-05-20 20:05:57 +00:00
|
|
|
#include "gtkpango.h"
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2016-12-18 20:45:15 +00:00
|
|
|
#include "gsk/gskcairoblurprivate.h"
|
2016-12-13 20:00:28 +00:00
|
|
|
#include "gsk/gskroundedrectprivate.h"
|
|
|
|
|
2013-05-03 10:50:18 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
typedef struct {
|
2012-04-03 09:49:46 +00:00
|
|
|
guint inset :1;
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2012-04-03 11:29:29 +00:00
|
|
|
GtkCssValue *hoffset;
|
|
|
|
GtkCssValue *voffset;
|
|
|
|
GtkCssValue *radius;
|
|
|
|
GtkCssValue *spread;
|
2012-04-03 10:07:53 +00:00
|
|
|
GtkCssValue *color;
|
2020-01-14 13:34:15 +00:00
|
|
|
} ShadowValue;
|
|
|
|
|
|
|
|
struct _GtkCssValue {
|
|
|
|
GTK_CSS_VALUE_BASE
|
2021-02-06 14:44:16 +00:00
|
|
|
guint is_filter : 1; /* values stored in radius are std_dev, for drop-shadow */
|
2020-01-14 13:34:15 +00:00
|
|
|
guint n_shadows;
|
|
|
|
ShadowValue shadows[1];
|
2011-05-19 18:47:17 +00:00
|
|
|
};
|
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
static GtkCssValue * gtk_css_shadow_value_new (ShadowValue *shadows,
|
2021-02-06 14:44:16 +00:00
|
|
|
guint n_shadows,
|
|
|
|
gboolean is_filter);
|
2012-04-03 13:33:00 +00:00
|
|
|
|
2012-03-27 23:56:57 +00:00
|
|
|
static void
|
2020-01-14 13:34:15 +00:00
|
|
|
shadow_value_for_transition (ShadowValue *result,
|
|
|
|
gboolean inset)
|
|
|
|
{
|
|
|
|
result->inset = inset;
|
|
|
|
result->hoffset = _gtk_css_number_value_new (0, GTK_CSS_PX);
|
|
|
|
result->voffset = _gtk_css_number_value_new (0, GTK_CSS_PX);
|
|
|
|
result->radius = _gtk_css_number_value_new (0, GTK_CSS_PX);
|
|
|
|
result->spread = _gtk_css_number_value_new (0, GTK_CSS_PX);
|
|
|
|
result->color = gtk_css_color_value_new_transparent ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shadow_value_unref (const ShadowValue *shadow)
|
2011-05-19 18:47:17 +00:00
|
|
|
{
|
2012-04-03 11:29:29 +00:00
|
|
|
_gtk_css_value_unref (shadow->hoffset);
|
|
|
|
_gtk_css_value_unref (shadow->voffset);
|
|
|
|
_gtk_css_value_unref (shadow->spread);
|
2020-01-14 13:34:15 +00:00
|
|
|
_gtk_css_value_unref (shadow->radius);
|
2012-04-03 10:07:53 +00:00
|
|
|
_gtk_css_value_unref (shadow->color);
|
2020-01-14 13:34:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
shadow_value_transition (const ShadowValue *start,
|
|
|
|
const ShadowValue *end,
|
|
|
|
guint property_id,
|
|
|
|
double progress,
|
|
|
|
ShadowValue *result)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (start->inset != end->inset)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
result->inset = start->inset;
|
|
|
|
result->hoffset = _gtk_css_value_transition (start->hoffset, end->hoffset, property_id, progress);
|
|
|
|
result->voffset = _gtk_css_value_transition (start->voffset, end->voffset, property_id, progress);
|
|
|
|
result->radius = _gtk_css_value_transition (start->radius, end->radius, property_id, progress);
|
|
|
|
result->spread = _gtk_css_value_transition (start->spread, end->spread, property_id, progress);
|
|
|
|
result->color = _gtk_css_value_transition (start->color, end->color, property_id, progress);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_value_shadow_free (GtkCssValue *value)
|
|
|
|
{
|
|
|
|
guint i;
|
2012-04-03 09:49:46 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
for (i = 0; i < value->n_shadows; i ++)
|
|
|
|
{
|
|
|
|
const ShadowValue *shadow = &value->shadows[i];
|
|
|
|
|
|
|
|
shadow_value_unref (shadow);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slice_free1 (sizeof (GtkCssValue) + sizeof (ShadowValue) * (value->n_shadows - 1), value);
|
2012-03-27 23:56:57 +00:00
|
|
|
}
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2012-07-11 04:56:07 +00:00
|
|
|
static GtkCssValue *
|
2020-01-14 13:34:15 +00:00
|
|
|
gtk_css_value_shadow_compute (GtkCssValue *value,
|
2017-10-31 03:31:46 +00:00
|
|
|
guint property_id,
|
|
|
|
GtkStyleProvider *provider,
|
|
|
|
GtkCssStyle *style,
|
|
|
|
GtkCssStyle *parent_style)
|
2012-07-11 04:56:07 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
guint i;
|
|
|
|
ShadowValue *shadows;
|
|
|
|
|
|
|
|
shadows = g_alloca (sizeof (ShadowValue) * value->n_shadows);
|
|
|
|
|
|
|
|
for (i = 0; i < value->n_shadows; i++)
|
2016-04-21 20:28:58 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
const ShadowValue *shadow = &value->shadows[i];
|
2016-04-21 20:28:58 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
shadows[i].hoffset = _gtk_css_value_compute (shadow->hoffset, property_id, provider, style, parent_style);
|
|
|
|
shadows[i].voffset = _gtk_css_value_compute (shadow->voffset, property_id, provider, style, parent_style);
|
|
|
|
shadows[i].radius = _gtk_css_value_compute (shadow->radius, property_id, provider, style, parent_style);
|
|
|
|
shadows[i].spread = _gtk_css_value_compute (shadow->spread, property_id, provider, style, parent_style),
|
|
|
|
shadows[i].color = _gtk_css_value_compute (shadow->color, property_id, provider, style, parent_style);
|
2020-01-27 01:16:16 +00:00
|
|
|
shadows[i].inset = shadow->inset;
|
2016-04-21 20:28:58 +00:00
|
|
|
}
|
|
|
|
|
2021-02-06 14:44:16 +00:00
|
|
|
return gtk_css_shadow_value_new (shadows, value->n_shadows, value->is_filter);
|
2012-07-11 04:56:07 +00:00
|
|
|
}
|
|
|
|
|
2012-03-27 23:56:57 +00:00
|
|
|
static gboolean
|
2020-01-14 13:34:15 +00:00
|
|
|
gtk_css_value_shadow_equal (const GtkCssValue *value1,
|
|
|
|
const GtkCssValue *value2)
|
2012-03-27 23:56:57 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (value1->n_shadows != value2->n_shadows)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < value1->n_shadows; i++)
|
|
|
|
{
|
|
|
|
const ShadowValue *shadow1 = &value1->shadows[i];
|
|
|
|
const ShadowValue *shadow2 = &value2->shadows[i];
|
|
|
|
|
|
|
|
if (shadow1->inset != shadow2->inset ||
|
2021-02-03 16:21:23 +00:00
|
|
|
!_gtk_css_value_equal (shadow1->hoffset, shadow2->hoffset) ||
|
|
|
|
!_gtk_css_value_equal (shadow1->voffset, shadow2->voffset) ||
|
|
|
|
!_gtk_css_value_equal (shadow1->radius, shadow2->radius) ||
|
|
|
|
!_gtk_css_value_equal (shadow1->spread, shadow2->spread) ||
|
|
|
|
!_gtk_css_value_equal (shadow1->color, shadow2->color))
|
2020-01-14 13:34:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2011-05-19 18:47:17 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 15:47:26 +00:00
|
|
|
static GtkCssValue *
|
|
|
|
gtk_css_value_shadow_transition (GtkCssValue *start,
|
|
|
|
GtkCssValue *end,
|
2012-08-30 13:51:29 +00:00
|
|
|
guint property_id,
|
2012-03-30 15:47:26 +00:00
|
|
|
double progress)
|
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
|
|
|
|
guint i, len;
|
|
|
|
ShadowValue *shadows;
|
|
|
|
|
|
|
|
if (start->n_shadows > end->n_shadows)
|
|
|
|
len = start->n_shadows;
|
|
|
|
else
|
|
|
|
len = end->n_shadows;
|
|
|
|
|
|
|
|
shadows = g_newa (ShadowValue, len);
|
|
|
|
|
|
|
|
for (i = 0; i < MIN (start->n_shadows, end->n_shadows); i++)
|
|
|
|
{
|
|
|
|
if (!shadow_value_transition (&start->shadows[i], &end->shadows[i],
|
|
|
|
property_id, progress,
|
|
|
|
&shadows[i]))
|
|
|
|
{
|
|
|
|
while (i--)
|
|
|
|
shadow_value_unref (&shadows[i]);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start->n_shadows > end->n_shadows)
|
|
|
|
{
|
|
|
|
for (; i < len; i++)
|
|
|
|
{
|
|
|
|
ShadowValue fill;
|
|
|
|
|
|
|
|
shadow_value_for_transition (&fill, start->shadows[i].inset);
|
|
|
|
if (!shadow_value_transition (&start->shadows[i], &fill, property_id, progress, &shadows[i]))
|
|
|
|
{
|
|
|
|
while (i--)
|
|
|
|
shadow_value_unref (&shadows[i]);
|
|
|
|
shadow_value_unref (&fill);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
shadow_value_unref (&fill);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (; i < len; i++)
|
|
|
|
{
|
|
|
|
ShadowValue fill;
|
|
|
|
|
|
|
|
shadow_value_for_transition (&fill, end->shadows[i].inset);
|
|
|
|
if (!shadow_value_transition (&fill, &end->shadows[i], property_id, progress, &shadows[i]))
|
|
|
|
{
|
|
|
|
while (i--)
|
|
|
|
shadow_value_unref (&shadows[i]);
|
|
|
|
shadow_value_unref (&fill);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
shadow_value_unref (&fill);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-06 14:44:16 +00:00
|
|
|
return gtk_css_shadow_value_new (shadows, len, start->is_filter);
|
2012-03-30 15:47:26 +00:00
|
|
|
}
|
|
|
|
|
2012-03-27 23:56:57 +00:00
|
|
|
static void
|
2020-01-14 13:34:15 +00:00
|
|
|
gtk_css_value_shadow_print (const GtkCssValue *value,
|
2012-03-27 23:56:57 +00:00
|
|
|
GString *string)
|
2011-05-19 18:47:17 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (value->n_shadows == 0)
|
2012-04-03 11:29:29 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
g_string_append (string, "none");
|
|
|
|
return;
|
2012-04-03 11:29:29 +00:00
|
|
|
}
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
for (i = 0; i < value->n_shadows; i ++)
|
2012-04-03 11:29:29 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
const ShadowValue *shadow = &value->shadows[i];
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
g_string_append (string, ", ");
|
|
|
|
|
|
|
|
_gtk_css_value_print (shadow->hoffset, string);
|
2012-04-03 11:29:29 +00:00
|
|
|
g_string_append_c (string, ' ');
|
2020-01-14 13:34:15 +00:00
|
|
|
_gtk_css_value_print (shadow->voffset, string);
|
|
|
|
g_string_append_c (string, ' ');
|
|
|
|
if (_gtk_css_number_value_get (shadow->radius, 100) != 0 ||
|
|
|
|
_gtk_css_number_value_get (shadow->spread, 100) != 0)
|
|
|
|
{
|
|
|
|
_gtk_css_value_print (shadow->radius, string);
|
|
|
|
g_string_append_c (string, ' ');
|
|
|
|
}
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
if (_gtk_css_number_value_get (shadow->spread, 100) != 0)
|
|
|
|
{
|
|
|
|
_gtk_css_value_print (shadow->spread, string);
|
|
|
|
g_string_append_c (string, ' ');
|
|
|
|
}
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
_gtk_css_value_print (shadow->color, string);
|
2011-05-19 18:47:17 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
if (shadow->inset)
|
|
|
|
g_string_append (string, " inset");
|
|
|
|
}
|
2011-05-19 18:47:17 +00:00
|
|
|
}
|
|
|
|
|
2012-03-27 23:56:57 +00:00
|
|
|
static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
|
2020-01-09 10:57:00 +00:00
|
|
|
"GtkCssShadowValue",
|
2012-03-27 23:56:57 +00:00
|
|
|
gtk_css_value_shadow_free,
|
2012-07-11 04:56:07 +00:00
|
|
|
gtk_css_value_shadow_compute,
|
2012-03-27 23:56:57 +00:00
|
|
|
gtk_css_value_shadow_equal,
|
2012-03-30 15:47:26 +00:00
|
|
|
gtk_css_value_shadow_transition,
|
2018-02-13 04:55:33 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2012-03-27 23:56:57 +00:00
|
|
|
gtk_css_value_shadow_print
|
|
|
|
};
|
|
|
|
|
2021-02-06 14:44:16 +00:00
|
|
|
static GtkCssValue shadow_none_singleton = { >K_CSS_VALUE_SHADOW, 1, TRUE, FALSE, 0 };
|
2012-04-03 09:49:46 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
GtkCssValue *
|
|
|
|
gtk_css_shadow_value_new_none (void)
|
|
|
|
{
|
2020-04-18 19:24:13 +00:00
|
|
|
return _gtk_css_value_ref (&shadow_none_singleton);
|
2014-08-29 19:54:01 +00:00
|
|
|
}
|
2012-03-27 23:56:57 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
static GtkCssValue *
|
|
|
|
gtk_css_shadow_value_new (ShadowValue *shadows,
|
2021-02-06 14:44:16 +00:00
|
|
|
guint n_shadows,
|
|
|
|
gboolean is_filter)
|
2012-04-03 13:33:00 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
GtkCssValue *retval;
|
|
|
|
guint i;
|
2020-01-13 07:37:52 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
if (n_shadows == 0)
|
|
|
|
return gtk_css_shadow_value_new_none ();
|
2012-04-03 13:33:00 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
retval = _gtk_css_value_alloc (>K_CSS_VALUE_SHADOW, sizeof (GtkCssValue) + sizeof (ShadowValue) * (n_shadows - 1));
|
|
|
|
retval->n_shadows = n_shadows;
|
2021-02-06 14:44:16 +00:00
|
|
|
retval->is_filter = is_filter;
|
2020-01-14 13:34:15 +00:00
|
|
|
|
|
|
|
memcpy (retval->shadows, shadows, sizeof (ShadowValue) * n_shadows);
|
2020-01-13 07:37:52 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
retval->is_computed = TRUE;
|
|
|
|
for (i = 0; i < n_shadows; i++)
|
2020-01-13 07:37:52 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
const ShadowValue *shadow = &retval->shadows[i];
|
|
|
|
|
|
|
|
if (!gtk_css_value_is_computed (shadow->hoffset) ||
|
|
|
|
!gtk_css_value_is_computed (shadow->voffset) ||
|
|
|
|
!gtk_css_value_is_computed (shadow->spread) ||
|
|
|
|
!gtk_css_value_is_computed (shadow->radius) ||
|
|
|
|
!gtk_css_value_is_computed (shadow->color))
|
|
|
|
{
|
|
|
|
retval->is_computed = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2020-01-13 07:37:52 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
return retval;
|
2012-04-03 13:33:00 +00:00
|
|
|
}
|
|
|
|
|
2021-02-06 02:36:22 +00:00
|
|
|
GtkCssValue *
|
|
|
|
gtk_css_shadow_value_new_filter (void)
|
|
|
|
{
|
|
|
|
ShadowValue value;
|
|
|
|
|
|
|
|
value.inset = FALSE;
|
|
|
|
value.hoffset = _gtk_css_number_value_new (0, GTK_CSS_NUMBER);
|
|
|
|
value.voffset = _gtk_css_number_value_new (0, GTK_CSS_NUMBER);
|
|
|
|
value.radius = _gtk_css_number_value_new (0, GTK_CSS_NUMBER);
|
|
|
|
value.spread = _gtk_css_number_value_new (0, GTK_CSS_NUMBER);
|
|
|
|
value.color = _gtk_css_color_value_new_current_color ();
|
|
|
|
|
2021-02-06 14:44:16 +00:00
|
|
|
return gtk_css_shadow_value_new (&value, 1, TRUE);
|
2021-02-06 02:36:22 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 03:15:45 +00:00
|
|
|
enum {
|
|
|
|
HOFFSET,
|
|
|
|
VOFFSET,
|
|
|
|
RADIUS,
|
|
|
|
SPREAD,
|
|
|
|
N_VALUES
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
has_inset (GtkCssParser *parser,
|
|
|
|
gpointer option_data,
|
|
|
|
gpointer box_shadow_mode)
|
|
|
|
{
|
|
|
|
return box_shadow_mode && gtk_css_parser_has_ident (parser, "inset");
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
parse_inset (GtkCssParser *parser,
|
|
|
|
gpointer option_data,
|
|
|
|
gpointer box_shadow_mode)
|
|
|
|
{
|
|
|
|
gboolean *inset = option_data;
|
|
|
|
|
|
|
|
if (!gtk_css_parser_try_ident (parser, "inset"))
|
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*inset = TRUE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
parse_lengths (GtkCssParser *parser,
|
|
|
|
gpointer option_data,
|
|
|
|
gpointer box_shadow_mode)
|
|
|
|
{
|
|
|
|
GtkCssValue **values = option_data;
|
|
|
|
|
|
|
|
values[HOFFSET] = _gtk_css_number_value_parse (parser,
|
|
|
|
GTK_CSS_PARSE_LENGTH);
|
|
|
|
if (values[HOFFSET] == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
values[VOFFSET] = _gtk_css_number_value_parse (parser,
|
|
|
|
GTK_CSS_PARSE_LENGTH);
|
|
|
|
if (values[VOFFSET] == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gtk_css_number_value_can_parse (parser))
|
|
|
|
{
|
|
|
|
values[RADIUS] = _gtk_css_number_value_parse (parser,
|
|
|
|
GTK_CSS_PARSE_LENGTH
|
|
|
|
| GTK_CSS_POSITIVE_ONLY);
|
|
|
|
if (values[RADIUS] == NULL)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
values[RADIUS] = _gtk_css_number_value_new (0.0, GTK_CSS_PX);
|
|
|
|
|
|
|
|
if (box_shadow_mode && gtk_css_number_value_can_parse (parser))
|
|
|
|
{
|
|
|
|
values[SPREAD] = _gtk_css_number_value_parse (parser,
|
|
|
|
GTK_CSS_PARSE_LENGTH);
|
|
|
|
if (values[SPREAD] == NULL)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
values[SPREAD] = _gtk_css_number_value_new (0.0, GTK_CSS_PX);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-04-03 11:29:29 +00:00
|
|
|
static gboolean
|
2019-04-09 03:15:45 +00:00
|
|
|
parse_color (GtkCssParser *parser,
|
|
|
|
gpointer option_data,
|
|
|
|
gpointer box_shadow_mode)
|
2012-04-03 11:29:29 +00:00
|
|
|
{
|
2019-04-09 03:15:45 +00:00
|
|
|
GtkCssValue **color = option_data;
|
|
|
|
|
|
|
|
*color = _gtk_css_color_value_parse (parser);
|
|
|
|
if (*color == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2012-04-03 11:29:29 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
static gboolean
|
2021-02-06 20:37:04 +00:00
|
|
|
gtk_css_shadow_value_parse_one (GtkCssParser *parser,
|
|
|
|
gboolean box_shadow_mode,
|
|
|
|
ShadowValue *result)
|
2011-05-19 18:47:17 +00:00
|
|
|
{
|
2012-04-03 11:29:29 +00:00
|
|
|
GtkCssValue *values[N_VALUES] = { NULL, };
|
2019-04-09 03:15:45 +00:00
|
|
|
GtkCssValue *color = NULL;
|
|
|
|
gboolean inset = FALSE;
|
|
|
|
GtkCssParseOption options[] =
|
|
|
|
{
|
|
|
|
{ (void *) gtk_css_number_value_can_parse, parse_lengths, values },
|
|
|
|
{ has_inset, parse_inset, &inset },
|
|
|
|
{ (void *) gtk_css_color_value_can_parse, parse_color, &color },
|
|
|
|
};
|
2012-03-28 00:25:22 +00:00
|
|
|
guint i;
|
|
|
|
|
2019-04-09 03:15:45 +00:00
|
|
|
if (!gtk_css_parser_consume_any (parser, options, G_N_ELEMENTS (options), GUINT_TO_POINTER (box_shadow_mode)))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (values[0] == NULL)
|
|
|
|
{
|
|
|
|
gtk_css_parser_error_syntax (parser, "Expected shadow value to contain a length");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (color == NULL)
|
|
|
|
color = _gtk_css_color_value_new_current_color ();
|
2012-04-03 11:29:29 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
result->hoffset = values[HOFFSET];
|
|
|
|
result->voffset = values[VOFFSET];
|
|
|
|
result->spread = values[SPREAD];
|
|
|
|
result->radius = values[RADIUS];
|
|
|
|
result->color = color;
|
|
|
|
result->inset = inset;
|
|
|
|
|
|
|
|
return TRUE;
|
2012-04-03 11:29:29 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
for (i = 0; i < N_VALUES; i++)
|
2012-03-28 00:25:22 +00:00
|
|
|
{
|
2019-04-09 03:15:45 +00:00
|
|
|
g_clear_pointer (&values[i], gtk_css_value_unref);
|
2012-04-03 09:49:46 +00:00
|
|
|
}
|
2019-04-09 03:15:45 +00:00
|
|
|
g_clear_pointer (&color, gtk_css_value_unref);
|
2012-03-28 00:25:22 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
return FALSE;
|
2011-05-19 18:47:17 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
#define MAX_SHADOWS 64
|
|
|
|
GtkCssValue *
|
2021-02-06 20:37:04 +00:00
|
|
|
gtk_css_shadow_value_parse (GtkCssParser *parser,
|
|
|
|
gboolean box_shadow_mode)
|
2013-04-05 09:54:03 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
ShadowValue shadows[MAX_SHADOWS];
|
|
|
|
int n_shadows = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (gtk_css_parser_try_ident (parser, "none"))
|
|
|
|
return gtk_css_shadow_value_new_none ();
|
|
|
|
|
|
|
|
do {
|
2021-03-17 11:49:06 +00:00
|
|
|
if (n_shadows == MAX_SHADOWS)
|
2020-01-14 13:34:15 +00:00
|
|
|
{
|
2021-03-17 11:49:06 +00:00
|
|
|
gtk_css_parser_error_syntax (parser, "Not more than %d shadows supported", MAX_SHADOWS);
|
2020-01-14 13:34:15 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2021-03-17 11:49:06 +00:00
|
|
|
if (gtk_css_shadow_value_parse_one (parser, box_shadow_mode, &shadows[n_shadows]))
|
|
|
|
n_shadows++;
|
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
} while (gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA));
|
2013-04-05 09:54:03 +00:00
|
|
|
|
2021-02-06 14:44:16 +00:00
|
|
|
return gtk_css_shadow_value_new (shadows, n_shadows, FALSE);
|
2020-01-14 13:34:15 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
for (i = 0; i < n_shadows; i++)
|
|
|
|
{
|
|
|
|
const ShadowValue *shadow = &shadows[i];
|
|
|
|
|
|
|
|
shadow_value_unref (shadow);
|
|
|
|
}
|
|
|
|
return NULL;
|
2013-04-05 09:54:03 +00:00
|
|
|
}
|
|
|
|
|
2021-02-06 02:36:22 +00:00
|
|
|
GtkCssValue *
|
2021-02-06 02:36:22 +00:00
|
|
|
gtk_css_shadow_value_parse_filter (GtkCssParser *parser)
|
2021-02-06 02:36:22 +00:00
|
|
|
{
|
2021-02-06 02:36:22 +00:00
|
|
|
ShadowValue shadow;
|
2021-02-06 02:36:22 +00:00
|
|
|
|
2021-02-06 02:36:22 +00:00
|
|
|
if (gtk_css_shadow_value_parse_one (parser, FALSE, &shadow))
|
2021-02-06 14:44:16 +00:00
|
|
|
return gtk_css_shadow_value_new (&shadow, 1, TRUE);
|
2021-02-06 02:36:22 +00:00
|
|
|
else
|
|
|
|
return NULL;
|
2021-02-06 02:36:22 +00:00
|
|
|
}
|
|
|
|
|
2013-04-22 20:50:39 +00:00
|
|
|
void
|
2020-01-14 13:34:15 +00:00
|
|
|
gtk_css_shadow_value_get_extents (const GtkCssValue *value,
|
2016-11-19 19:13:54 +00:00
|
|
|
GtkBorder *border)
|
2013-04-22 20:50:39 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
guint i;
|
2013-04-22 20:50:39 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
memset (border, 0, sizeof (GtkBorder));
|
|
|
|
|
|
|
|
for (i = 0; i < value->n_shadows; i ++)
|
|
|
|
{
|
|
|
|
const ShadowValue *shadow = &value->shadows[i];
|
|
|
|
double hoffset, voffset, spread, radius, clip_radius;
|
|
|
|
|
|
|
|
spread = _gtk_css_number_value_get (shadow->spread, 0);
|
|
|
|
radius = _gtk_css_number_value_get (shadow->radius, 0);
|
2021-08-04 09:24:35 +00:00
|
|
|
if (!value->is_filter)
|
|
|
|
radius = radius / 2.0;
|
2020-01-14 13:34:15 +00:00
|
|
|
clip_radius = gsk_cairo_blur_compute_pixels (radius);
|
|
|
|
hoffset = _gtk_css_number_value_get (shadow->hoffset, 0);
|
|
|
|
voffset = _gtk_css_number_value_get (shadow->voffset, 0);
|
|
|
|
|
|
|
|
border->top = MAX (border->top, ceil (clip_radius + spread - voffset));
|
|
|
|
border->right = MAX (border->right, ceil (clip_radius + spread + hoffset));
|
|
|
|
border->bottom = MAX (border->bottom, ceil (clip_radius + spread + voffset));
|
|
|
|
border->left = MAX (border->left, ceil (clip_radius + spread - hoffset));
|
|
|
|
}
|
2016-12-18 23:45:35 +00:00
|
|
|
}
|
|
|
|
|
2016-11-19 19:38:22 +00:00
|
|
|
void
|
2020-01-14 13:34:15 +00:00
|
|
|
gtk_css_shadow_value_snapshot_outset (const GtkCssValue *value,
|
2016-12-19 14:39:43 +00:00
|
|
|
GtkSnapshot *snapshot,
|
|
|
|
const GskRoundedRect *border_box)
|
2016-11-19 19:38:22 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
guint i;
|
2021-02-06 14:44:16 +00:00
|
|
|
double dx, dy, spread, radius;
|
|
|
|
const GdkRGBA *color;
|
2020-01-14 13:34:15 +00:00
|
|
|
|
|
|
|
g_return_if_fail (value->class == >K_CSS_VALUE_SHADOW);
|
|
|
|
|
|
|
|
for (i = 0; i < value->n_shadows; i ++)
|
|
|
|
{
|
|
|
|
const ShadowValue *shadow = &value->shadows[i];
|
|
|
|
|
|
|
|
if (shadow->inset)
|
|
|
|
continue;
|
|
|
|
|
2021-02-06 14:44:16 +00:00
|
|
|
color = gtk_css_color_value_get_rgba (shadow->color);
|
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
/* We don't need to draw invisible shadows */
|
2021-02-06 14:44:16 +00:00
|
|
|
if (gdk_rgba_is_clear (color))
|
2020-01-14 13:34:15 +00:00
|
|
|
continue;
|
|
|
|
|
2021-02-06 14:44:16 +00:00
|
|
|
dx = _gtk_css_number_value_get (shadow->hoffset, 0);
|
|
|
|
dy = _gtk_css_number_value_get (shadow->voffset, 0);
|
|
|
|
spread = _gtk_css_number_value_get (shadow->spread, 0);
|
|
|
|
radius = _gtk_css_number_value_get (shadow->radius, 0);
|
|
|
|
if (value->is_filter)
|
|
|
|
radius = 2 * radius;
|
|
|
|
|
|
|
|
gtk_snapshot_append_outset_shadow (snapshot, border_box, color, dx, dy, spread, radius);
|
2020-01-14 13:34:15 +00:00
|
|
|
}
|
2016-11-19 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-01-14 13:34:15 +00:00
|
|
|
gtk_css_shadow_value_snapshot_inset (const GtkCssValue *value,
|
2019-11-29 12:34:22 +00:00
|
|
|
GtkSnapshot *snapshot,
|
|
|
|
const GskRoundedRect *padding_box)
|
2016-11-19 19:38:22 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
guint i;
|
2019-11-29 12:34:22 +00:00
|
|
|
double dx, dy, spread, radius;
|
|
|
|
const GdkRGBA *color;
|
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
g_return_if_fail (value->class == >K_CSS_VALUE_SHADOW);
|
2016-11-19 19:38:22 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
for (i = 0; i < value->n_shadows; i ++)
|
|
|
|
{
|
|
|
|
const ShadowValue *shadow = &value->shadows[i];
|
2016-11-19 19:38:22 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
if (!shadow->inset)
|
|
|
|
continue;
|
2019-11-29 12:34:22 +00:00
|
|
|
|
2021-02-06 14:44:16 +00:00
|
|
|
color = gtk_css_color_value_get_rgba (shadow->color);
|
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
/* We don't need to draw invisible shadows */
|
2021-02-06 14:44:16 +00:00
|
|
|
if (gdk_rgba_is_clear (color))
|
2020-01-14 13:34:15 +00:00
|
|
|
continue;
|
2019-11-29 12:34:22 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
dx = _gtk_css_number_value_get (shadow->hoffset, 0);
|
|
|
|
dy = _gtk_css_number_value_get (shadow->voffset, 0);
|
|
|
|
spread = _gtk_css_number_value_get (shadow->spread, 0);
|
|
|
|
radius = _gtk_css_number_value_get (shadow->radius, 0);
|
2021-02-06 14:44:16 +00:00
|
|
|
if (value->is_filter)
|
|
|
|
radius = 2 * radius;
|
2019-11-29 12:34:22 +00:00
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
/* These are trivial to do with a color node */
|
|
|
|
if (spread == 0 && radius == 0 &&
|
|
|
|
gsk_rounded_rect_is_rectilinear (padding_box))
|
2019-11-29 12:34:22 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
const graphene_rect_t *padding_bounds = &padding_box->bounds;
|
|
|
|
|
|
|
|
if (dx > 0)
|
|
|
|
{
|
|
|
|
const float y = dy > 0 ? dy : 0;
|
|
|
|
|
|
|
|
gtk_snapshot_append_color (snapshot, color,
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
padding_bounds->origin.x,
|
|
|
|
padding_bounds->origin.y + y,
|
|
|
|
dx,
|
|
|
|
padding_bounds->size.height - ABS (dy)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
else if (dx < 0)
|
|
|
|
{
|
|
|
|
const float y = dy > 0 ? dy : 0;
|
|
|
|
|
|
|
|
gtk_snapshot_append_color (snapshot, color,
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
padding_bounds->origin.x + padding_bounds->size.width + dx,
|
|
|
|
padding_bounds->origin.y + y,
|
|
|
|
- dx,
|
|
|
|
padding_bounds->size.height - ABS (dy)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dy > 0)
|
|
|
|
{
|
|
|
|
gtk_snapshot_append_color (snapshot, color,
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
padding_bounds->origin.x,
|
|
|
|
padding_bounds->origin.y,
|
|
|
|
padding_bounds->size.width,
|
|
|
|
dy
|
|
|
|
));
|
|
|
|
}
|
|
|
|
else if (dy < 0)
|
|
|
|
{
|
|
|
|
gtk_snapshot_append_color (snapshot, color,
|
|
|
|
&GRAPHENE_RECT_INIT (
|
|
|
|
padding_bounds->origin.x,
|
|
|
|
padding_bounds->origin.y + padding_bounds->size.height + dy,
|
|
|
|
padding_bounds->size.width,
|
|
|
|
- dy
|
|
|
|
));
|
|
|
|
}
|
2019-11-29 12:34:22 +00:00
|
|
|
}
|
2020-01-14 13:34:15 +00:00
|
|
|
else
|
2019-11-29 12:34:22 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
gtk_snapshot_append_inset_shadow (snapshot,
|
|
|
|
padding_box,
|
|
|
|
color,
|
|
|
|
dx, dy, spread, radius);
|
2019-11-29 12:34:22 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-14 13:34:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gtk_css_shadow_value_is_clear (const GtkCssValue *value)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for (i = 0; i < value->n_shadows; i++)
|
2019-11-29 12:34:22 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
const ShadowValue *shadow = &value->shadows[i];
|
|
|
|
|
|
|
|
if (!gdk_rgba_is_clear (gtk_css_color_value_get_rgba (shadow->color)))
|
|
|
|
return FALSE;
|
2019-11-29 12:34:22 +00:00
|
|
|
}
|
2020-01-14 13:34:15 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2016-11-19 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 20:10:46 +00:00
|
|
|
gboolean
|
2020-01-14 13:34:15 +00:00
|
|
|
gtk_css_shadow_value_is_none (const GtkCssValue *shadow)
|
2017-10-28 20:10:46 +00:00
|
|
|
{
|
2020-01-14 13:34:15 +00:00
|
|
|
return !shadow || shadow->n_shadows == 0;
|
2017-10-28 20:10:46 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 13:34:15 +00:00
|
|
|
gboolean
|
|
|
|
gtk_css_shadow_value_push_snapshot (const GtkCssValue *value,
|
|
|
|
GtkSnapshot *snapshot)
|
|
|
|
{
|
|
|
|
gboolean need_shadow = FALSE;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < value->n_shadows; i++)
|
|
|
|
{
|
|
|
|
const ShadowValue *shadow = &value->shadows[i];
|
|
|
|
|
|
|
|
if (!gdk_rgba_is_clear (gtk_css_color_value_get_rgba (shadow->color)))
|
|
|
|
{
|
|
|
|
need_shadow = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_shadow)
|
|
|
|
{
|
|
|
|
GskShadow *shadows = g_newa (GskShadow, value->n_shadows);
|
|
|
|
|
|
|
|
for (i = 0; i < value->n_shadows; i++)
|
|
|
|
{
|
|
|
|
const ShadowValue *shadow = &value->shadows[i];
|
|
|
|
|
|
|
|
shadows[i].dx = _gtk_css_number_value_get (shadow->hoffset, 0);
|
|
|
|
shadows[i].dy = _gtk_css_number_value_get (shadow->voffset, 0);
|
|
|
|
shadows[i].color = *gtk_css_color_value_get_rgba (shadow->color);
|
|
|
|
shadows[i].radius = _gtk_css_number_value_get (shadow->radius, 0);
|
2021-02-06 14:44:16 +00:00
|
|
|
if (value->is_filter)
|
|
|
|
shadows[i].radius *= 2;
|
2020-01-14 13:34:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_snapshot_push_shadow (snapshot, shadows, value->n_shadows);
|
|
|
|
}
|
|
|
|
|
|
|
|
return need_shadow;
|
|
|
|
}
|
2021-02-06 14:00:32 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gtk_css_shadow_value_pop_snapshot (const GtkCssValue *value,
|
|
|
|
GtkSnapshot *snapshot)
|
|
|
|
{
|
|
|
|
gboolean need_shadow = FALSE;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < value->n_shadows; i++)
|
|
|
|
{
|
|
|
|
const ShadowValue *shadow = &value->shadows[i];
|
|
|
|
|
|
|
|
if (!gdk_rgba_is_clear (gtk_css_color_value_get_rgba (shadow->color)))
|
|
|
|
{
|
|
|
|
need_shadow = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_shadow)
|
|
|
|
gtk_snapshot_pop (snapshot);
|
|
|
|
}
|