2015-01-12 02:58:21 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2014 Benjamin Otte <otte@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
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkcsswidgetnodeprivate.h"
|
2015-01-28 04:14:47 +00:00
|
|
|
|
|
|
|
#include "gtkcontainerprivate.h"
|
2015-02-02 14:35:08 +00:00
|
|
|
#include "gtkcssanimatedstyleprivate.h"
|
2015-01-12 02:58:21 +00:00
|
|
|
#include "gtkprivate.h"
|
2015-03-05 05:23:35 +00:00
|
|
|
#include "gtksettingsprivate.h"
|
2015-01-25 01:40:40 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
2015-01-12 02:58:21 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2015-02-09 21:51:28 +00:00
|
|
|
/* widgets for special casing go here */
|
|
|
|
#include "gtkbox.h"
|
2015-01-12 02:58:21 +00:00
|
|
|
|
2015-02-02 14:35:08 +00:00
|
|
|
/* When these change we do a full restyling. Otherwise we try to figure out
|
|
|
|
* if we need to change things. */
|
2015-10-31 22:02:36 +00:00
|
|
|
#define GTK_CSS_RADICAL_CHANGE (GTK_CSS_CHANGE_ID | GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE | GTK_CSS_CHANGE_PARENT_STYLE)
|
2015-02-02 14:35:08 +00:00
|
|
|
|
2015-01-12 02:58:21 +00:00
|
|
|
G_DEFINE_TYPE (GtkCssWidgetNode, gtk_css_widget_node, GTK_TYPE_CSS_NODE)
|
|
|
|
|
2015-02-22 22:11:22 +00:00
|
|
|
static void
|
|
|
|
gtk_css_widget_node_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkCssWidgetNode *node = GTK_CSS_WIDGET_NODE (object);
|
|
|
|
|
2015-12-13 03:08:44 +00:00
|
|
|
g_object_unref (node->last_updated_style);
|
2015-02-22 22:11:22 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_css_widget_node_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2015-03-05 16:51:23 +00:00
|
|
|
static void
|
2015-12-12 01:02:04 +00:00
|
|
|
gtk_css_widget_node_style_changed (GtkCssNode *cssnode,
|
|
|
|
GtkCssStyleChange *change)
|
2015-02-04 03:43:55 +00:00
|
|
|
{
|
2015-02-22 22:11:22 +00:00
|
|
|
GtkCssWidgetNode *node;
|
|
|
|
|
|
|
|
node = GTK_CSS_WIDGET_NODE (cssnode);
|
|
|
|
|
2015-03-24 03:14:28 +00:00
|
|
|
if (node->widget)
|
|
|
|
gtk_widget_clear_path (node->widget);
|
|
|
|
|
2015-12-12 01:02:04 +00:00
|
|
|
GTK_CSS_NODE_CLASS (gtk_css_widget_node_parent_class)->style_changed (cssnode, change);
|
2015-02-04 03:43:55 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 23:54:14 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_widget_node_queue_callback (GtkWidget *widget,
|
|
|
|
GdkFrameClock *frame_clock,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkCssNode *node = user_data;
|
2015-09-28 05:43:03 +00:00
|
|
|
|
2015-02-18 23:54:14 +00:00
|
|
|
gtk_css_node_invalidate_frame_clock (node, TRUE);
|
|
|
|
_gtk_container_queue_restyle (GTK_CONTAINER (widget));
|
|
|
|
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2015-04-27 17:15:43 +00:00
|
|
|
static GtkCssStyle *
|
|
|
|
gtk_css_widget_node_update_style (GtkCssNode *cssnode,
|
|
|
|
GtkCssChange change,
|
|
|
|
gint64 timestamp,
|
|
|
|
GtkCssStyle *style)
|
|
|
|
{
|
|
|
|
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (cssnode);
|
|
|
|
|
|
|
|
if (widget_node->widget != NULL)
|
|
|
|
{
|
|
|
|
GtkStyleContext *context = _gtk_widget_peek_style_context (widget_node->widget);
|
|
|
|
if (context)
|
|
|
|
gtk_style_context_clear_property_cache (context);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_CSS_NODE_CLASS (gtk_css_widget_node_parent_class)->update_style (cssnode, change, timestamp, style);
|
|
|
|
}
|
|
|
|
|
2015-01-28 04:14:47 +00:00
|
|
|
static void
|
2015-02-07 16:19:07 +00:00
|
|
|
gtk_css_widget_node_queue_validate (GtkCssNode *node)
|
2015-01-28 04:14:47 +00:00
|
|
|
{
|
|
|
|
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
|
|
|
|
|
2016-10-25 14:52:27 +00:00
|
|
|
if (widget_node->widget && _gtk_widget_is_toplevel (widget_node->widget) &&
|
|
|
|
GTK_IS_CONTAINER (widget_node->widget))
|
2015-02-07 17:53:07 +00:00
|
|
|
widget_node->validate_cb_id = gtk_widget_add_tick_callback (widget_node->widget,
|
2015-02-18 23:54:14 +00:00
|
|
|
gtk_css_widget_node_queue_callback,
|
|
|
|
node,
|
2015-02-07 17:53:07 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_widget_node_dequeue_validate (GtkCssNode *node)
|
|
|
|
{
|
|
|
|
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
|
|
|
|
|
2016-10-25 14:52:27 +00:00
|
|
|
if (widget_node->widget && _gtk_widget_is_toplevel (widget_node->widget) &&
|
|
|
|
GTK_IS_CONTAINER (widget_node->widget))
|
2015-02-07 17:53:07 +00:00
|
|
|
gtk_widget_remove_tick_callback (widget_node->widget,
|
|
|
|
widget_node->validate_cb_id);
|
2015-01-25 01:40:40 +00:00
|
|
|
}
|
|
|
|
|
2015-02-22 22:28:04 +00:00
|
|
|
static void
|
|
|
|
gtk_css_widget_node_validate (GtkCssNode *node)
|
2015-01-30 15:27:17 +00:00
|
|
|
{
|
|
|
|
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
|
2015-12-13 03:08:44 +00:00
|
|
|
GtkCssStyleChange change;
|
|
|
|
GtkCssStyle *style;
|
2015-01-30 15:27:17 +00:00
|
|
|
|
|
|
|
if (widget_node->widget == NULL)
|
2015-02-22 22:28:04 +00:00
|
|
|
return;
|
2015-01-30 15:27:17 +00:00
|
|
|
|
2015-12-13 03:08:44 +00:00
|
|
|
style = gtk_css_node_get_style (node);
|
|
|
|
|
|
|
|
gtk_css_style_change_init (&change, widget_node->last_updated_style, style);
|
|
|
|
if (gtk_css_style_change_has_change (&change))
|
|
|
|
{
|
|
|
|
GtkStyleContext *context;
|
|
|
|
|
|
|
|
context = _gtk_widget_peek_style_context (widget_node->widget);
|
|
|
|
if (context)
|
|
|
|
gtk_style_context_validate (context, &change);
|
|
|
|
else
|
|
|
|
_gtk_widget_style_context_invalidated (widget_node->widget);
|
2016-05-04 02:15:17 +00:00
|
|
|
g_set_object (&widget_node->last_updated_style, style);
|
2015-12-13 03:08:44 +00:00
|
|
|
}
|
|
|
|
gtk_css_style_change_finish (&change);
|
2015-01-30 15:27:17 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 20:29:45 +00:00
|
|
|
static gboolean
|
2015-02-09 14:21:48 +00:00
|
|
|
gtk_css_widget_node_init_matcher (GtkCssNode *node,
|
2015-02-09 16:26:07 +00:00
|
|
|
GtkCssMatcher *matcher)
|
2015-02-09 14:21:48 +00:00
|
|
|
{
|
|
|
|
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
|
|
|
|
|
|
|
|
if (widget_node->widget == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-11-19 17:06:50 +00:00
|
|
|
return GTK_CSS_NODE_CLASS (gtk_css_widget_node_parent_class)->init_matcher (node, matcher);
|
2015-02-09 14:21:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 02:58:21 +00:00
|
|
|
static GtkWidgetPath *
|
|
|
|
gtk_css_widget_node_create_widget_path (GtkCssNode *node)
|
|
|
|
{
|
|
|
|
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
|
2015-01-24 19:57:17 +00:00
|
|
|
GtkWidgetPath *path;
|
|
|
|
guint length;
|
2015-01-12 02:58:21 +00:00
|
|
|
|
|
|
|
if (widget_node->widget == NULL)
|
2015-01-24 19:57:17 +00:00
|
|
|
path = gtk_widget_path_new ();
|
|
|
|
else
|
|
|
|
path = _gtk_widget_create_path (widget_node->widget);
|
|
|
|
|
|
|
|
length = gtk_widget_path_length (path);
|
|
|
|
if (length > 0)
|
|
|
|
{
|
|
|
|
gtk_css_node_declaration_add_to_widget_path (gtk_css_node_get_declaration (node),
|
|
|
|
path,
|
|
|
|
length - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
2015-01-12 02:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const GtkWidgetPath *
|
|
|
|
gtk_css_widget_node_get_widget_path (GtkCssNode *node)
|
|
|
|
{
|
|
|
|
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
|
|
|
|
|
|
|
|
if (widget_node->widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return gtk_widget_get_path (widget_node->widget);
|
|
|
|
}
|
|
|
|
|
2015-01-31 15:30:05 +00:00
|
|
|
static GtkStyleProviderPrivate *
|
|
|
|
gtk_css_widget_node_get_style_provider (GtkCssNode *node)
|
|
|
|
{
|
|
|
|
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
|
2015-03-05 05:23:35 +00:00
|
|
|
GtkStyleContext *context;
|
|
|
|
GtkStyleCascade *cascade;
|
2015-01-31 15:30:05 +00:00
|
|
|
|
|
|
|
if (widget_node->widget == NULL)
|
2015-02-17 14:18:32 +00:00
|
|
|
return NULL;
|
2015-01-31 15:30:05 +00:00
|
|
|
|
2015-03-05 05:23:35 +00:00
|
|
|
context = _gtk_widget_peek_style_context (widget_node->widget);
|
|
|
|
if (context)
|
|
|
|
return gtk_style_context_get_style_provider (context);
|
|
|
|
|
|
|
|
cascade = _gtk_settings_get_style_cascade (gtk_widget_get_settings (widget_node->widget),
|
|
|
|
gtk_widget_get_scale_factor (widget_node->widget));
|
|
|
|
return GTK_STYLE_PROVIDER_PRIVATE (cascade);
|
2015-01-31 15:30:05 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 23:54:14 +00:00
|
|
|
static GdkFrameClock *
|
|
|
|
gtk_css_widget_node_get_frame_clock (GtkCssNode *node)
|
|
|
|
{
|
|
|
|
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
|
|
|
|
|
|
|
|
if (widget_node->widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2016-05-01 02:00:35 +00:00
|
|
|
if (!gtk_settings_get_enable_animations (gtk_widget_get_settings (widget_node->widget)))
|
2015-02-20 23:16:58 +00:00
|
|
|
return NULL;
|
|
|
|
|
2015-02-18 23:54:14 +00:00
|
|
|
return gtk_widget_get_frame_clock (widget_node->widget);
|
|
|
|
}
|
|
|
|
|
2015-01-12 02:58:21 +00:00
|
|
|
static void
|
|
|
|
gtk_css_widget_node_class_init (GtkCssWidgetNodeClass *klass)
|
|
|
|
{
|
|
|
|
GtkCssNodeClass *node_class = GTK_CSS_NODE_CLASS (klass);
|
2015-02-22 22:11:22 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2015-01-12 02:58:21 +00:00
|
|
|
|
2015-02-22 22:11:22 +00:00
|
|
|
object_class->finalize = gtk_css_widget_node_finalize;
|
2015-04-27 17:15:43 +00:00
|
|
|
node_class->update_style = gtk_css_widget_node_update_style;
|
2015-01-30 15:27:17 +00:00
|
|
|
node_class->validate = gtk_css_widget_node_validate;
|
2015-02-07 16:19:07 +00:00
|
|
|
node_class->queue_validate = gtk_css_widget_node_queue_validate;
|
2015-02-07 17:53:07 +00:00
|
|
|
node_class->dequeue_validate = gtk_css_widget_node_dequeue_validate;
|
2015-02-09 14:21:48 +00:00
|
|
|
node_class->init_matcher = gtk_css_widget_node_init_matcher;
|
2015-01-12 02:58:21 +00:00
|
|
|
node_class->create_widget_path = gtk_css_widget_node_create_widget_path;
|
|
|
|
node_class->get_widget_path = gtk_css_widget_node_get_widget_path;
|
2015-01-31 15:30:05 +00:00
|
|
|
node_class->get_style_provider = gtk_css_widget_node_get_style_provider;
|
2015-02-18 23:54:14 +00:00
|
|
|
node_class->get_frame_clock = gtk_css_widget_node_get_frame_clock;
|
2015-03-05 16:51:23 +00:00
|
|
|
node_class->style_changed = gtk_css_widget_node_style_changed;
|
2015-01-12 02:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-02-22 22:11:22 +00:00
|
|
|
gtk_css_widget_node_init (GtkCssWidgetNode *node)
|
2015-01-12 02:58:21 +00:00
|
|
|
{
|
2015-12-13 03:08:44 +00:00
|
|
|
node->last_updated_style = g_object_ref (gtk_css_static_style_get_default ());
|
2015-01-12 02:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkCssNode *
|
|
|
|
gtk_css_widget_node_new (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkCssWidgetNode *result;
|
|
|
|
|
|
|
|
gtk_internal_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
|
|
|
|
|
|
|
|
result = g_object_new (GTK_TYPE_CSS_WIDGET_NODE, NULL);
|
|
|
|
result->widget = widget;
|
2015-02-10 01:50:57 +00:00
|
|
|
gtk_css_node_set_visible (GTK_CSS_NODE (result),
|
2015-09-06 23:58:03 +00:00
|
|
|
_gtk_widget_get_visible (widget));
|
2015-01-12 02:58:21 +00:00
|
|
|
|
|
|
|
return GTK_CSS_NODE (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_css_widget_node_widget_destroyed (GtkCssWidgetNode *node)
|
|
|
|
{
|
|
|
|
gtk_internal_return_if_fail (GTK_IS_CSS_WIDGET_NODE (node));
|
|
|
|
gtk_internal_return_if_fail (node->widget != NULL);
|
|
|
|
|
|
|
|
node->widget = NULL;
|
|
|
|
/* Contents of this node are now undefined.
|
|
|
|
* So we don't clear the style or anything.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gtk_css_widget_node_get_widget (GtkCssWidgetNode *node)
|
|
|
|
{
|
|
|
|
gtk_internal_return_val_if_fail (GTK_IS_CSS_WIDGET_NODE (node), NULL);
|
|
|
|
|
|
|
|
return node->widget;
|
|
|
|
}
|
2015-01-25 05:14:48 +00:00
|
|
|
|