<commit_before>/* GTK - The GIMP Toolkit
 * Copyright (C) 2014 <NAME> <<EMAIL>>
 *
 * 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 "gtkcsspathnodeprivate.h"
#include "gtkprivate.h"
#include "gtkstylecontextprivate.h"

G_DEFINE_TYPE (GtkCssPathNode, gtk_css_path_node, GTK_TYPE_CSS_NODE)

static void
gtk_css_path_node_finalize (GObject *object)
{
  GtkCssPathNode *node = GTK_CSS_PATH_NODE (object);

  if (node->path)
    gtk_widget_path_unref (node->path);

  G_OBJECT_CLASS (gtk_css_path_node_parent_class)->finalize (object);
}

static void
gtk_css_path_node_invalidate (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);

  if (path_node->context)
    {
      G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
      gtk_style_context_invalidate (path_node->context);
      G_GNUC_END_IGNORE_DEPRECATIONS;
    }
}

static GtkWidgetPath *
gtk_css_path_node_real_create_widget_path (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);
  GtkWidgetPath *path;
  guint length;

  if (path_node->path == NULL)
    path = gtk_widget_path_new ();
  else
    path = gtk_widget_path_copy (path_node->path);

  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;
}

static const GtkWidgetPath *
gtk_css_path_node_real_get_widget_path (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);

  return path_node->path;
}

static GtkStyleProviderPrivate *
gtk_css_path_node_get_style_provider (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);

  if (path_node->context == NULL)
    return GTK_CSS_NODE_CLASS (gtk_css_path_node_parent_class)->get_style_provider (node);

  return gtk_style_context_get_style_provider (path_node->context);
}

static void
gtk_css_path_node_class_init (GtkCssPathNodeClass *klass)
{
  GtkCssNodeClass *node_class = GTK_CSS_NODE_CLASS (klass);
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->finalize = gtk_css_path_node_finalize;

  node_class->invalidate = gtk_css_path_node_invalidate;
  node_class->create_widget_path = gtk_css_path_node_real_create_widget_path;
  node_class->get_widget_path = gtk_css_path_node_real_get_widget_path;
  node_class->get_style_provider = gtk_css_path_node_get_style_provider;
}

static void
gtk_css_path_node_init (GtkCssPathNode *cssnode)
{
}

GtkCssNode *
gtk_css_path_node_new (GtkStyleContext *context)
{<commit_msg>cssnode: Make path node create matcher without copying<commit_after>/* GTK - The GIMP Toolkit
 * Copyright (C) 2014 <NAME> <<EMAIL>>
 *
 * 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 "gtkcsspathnodeprivate.h"
#include "gtkprivate.h"
#include "gtkstylecontextprivate.h"

G_DEFINE_TYPE (GtkCssPathNode, gtk_css_path_node, GTK_TYPE_CSS_NODE)

static void
gtk_css_path_node_finalize (GObject *object)
{
  GtkCssPathNode *node = GTK_CSS_PATH_NODE (object);

  if (node->path)
    gtk_widget_path_unref (node->path);

  G_OBJECT_CLASS (gtk_css_path_node_parent_class)->finalize (object);
}

static void
gtk_css_path_node_invalidate (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);

  if (path_node->context)
    {
      G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
      gtk_style_context_invalidate (path_node->context);
      G_GNUC_END_IGNORE_DEPRECATIONS;
    }
}

gboolean
gtk_css_path_node_real_init_matcher (GtkCssNode     *node,
                                     GtkCssMatcher  *matcher,
                                     GtkWidgetPath **path_out)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);

  if (path_node->path == NULL ||
      gtk_widget_path_length (path_node->path) == 0)
    return FALSE;

  return _gtk_css_matcher_init (matcher,
                                path_node->path,
                                gtk_css_node_get_declaration (node));
}

static GtkWidgetPath *
gtk_css_path_node_real_create_widget_path (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);
  GtkWidgetPath *path;
  guint length;

  if (path_node->path == NULL)
    path = gtk_widget_path_new ();
  else
    path = gtk_widget_path_copy (path_node->path);

  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;
}

static const GtkWidgetPath *
gtk_css_path_node_real_get_widget_path (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);

  return path_node->path;
}

static GtkStyleProviderPrivate *
gtk_css_path_node_get_style_provider (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);

  if (path_node->context == NULL)
    return GTK_CSS_NODE_CLASS (gtk_css_path_node_parent_class)->get_style_provider (node);

  return gtk_style_context_get_style_provider (path_node->context);
}

static void
gtk_css_path_node_class_init (GtkCssPathNodeClass *klass)
{
  GtkCssNodeClass *node_class = GTK_CSS_NODE_CLASS (klass);
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->finalize = gtk_css_path_node_finalize;

  node_class->invalidate = gtk_css_path_node_invalidate;
  node_class->init_matcher = gtk_css_path_node_real_init_matcher;
  node_class->create_widget_path = gtk_css_path_node_real_create_widget_path;
  node_class->get_widget_path = gtk_css_path_node_real_get_widget_path;
  node_class->get_style_provider = gtk_css_path_node_get_style_provider;
}

static void
gtk_css_path_node_init (GtkCssPathNode *cssnode)
{
}

GtkCssNode *
gtk_css_path_node_new (GtkStyleContext *context)
{
{'fraction_non_alphanumeric': 0.07800529321632539, 'fraction_numerical': 0.002089427496865859, 'mean_word_length': 4.132237312365976, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2930398', 'n_tokens_mistral': 2549, 'n_tokens_neox': 2456, 'n_words': 543}