Commit 9d908830 authored by Matthias Clasen's avatar Matthias Clasen

text view: Improve text rendering

Use the text CSS node for rendering text, and the selection node
for rendering selected text, avoid gtk_style_context_save, update
states of all CSS nodes, and use the proper states when querying
style properties.
parent bb786ac2
......@@ -166,12 +166,14 @@ get_item_appearance (PangoItem *item)
return NULL;
}
extern GtkCssNode *gtk_text_view_get_text_node (GtkTextView *text_view);
extern GtkCssNode *gtk_text_view_get_selection_node (GtkTextView *text_view);
static void
gtk_text_renderer_prepare_run (PangoRenderer *renderer,
PangoLayoutRun *run)
{
GtkStyleContext *context;
GtkStateFlags state;
GtkTextRenderer *text_renderer = GTK_TEXT_RENDERER (renderer);
GdkRGBA *bg_rgba = NULL;
GdkRGBA *fg_rgba = NULL;
......@@ -183,29 +185,30 @@ gtk_text_renderer_prepare_run (PangoRenderer *renderer,
g_assert (appearance != NULL);
context = gtk_widget_get_style_context (text_renderer->widget);
state = gtk_style_context_get_state (context);
if (appearance->draw_bg && text_renderer->state == NORMAL)
bg_rgba = appearance->rgba[0];
else
bg_rgba = NULL;
text_renderer_set_rgba (text_renderer, PANGO_RENDER_PART_BACKGROUND, bg_rgba);
if (text_renderer->state == SELECTED)
{
gtk_style_context_save (context);
GtkCssNode *selection_node;
state |= GTK_STATE_FLAG_SELECTED;
gtk_style_context_set_state (context, state);
selection_node = gtk_text_view_get_selection_node ((GtkTextView *)text_renderer->widget);
gtk_style_context_save_to_node (context, selection_node);
gtk_style_context_get (context, state, "color", &fg_rgba, NULL);
gtk_style_context_get (context, gtk_style_context_get_state (context),
"color", &fg_rgba,
NULL);
gtk_style_context_restore (context);
}
else if (text_renderer->state == CURSOR && gtk_widget_has_focus (text_renderer->widget))
{
gtk_style_context_get (context, state,
gtk_style_context_get (context, gtk_style_context_get_state (context),
"background-color", &fg_rgba,
NULL);
}
......@@ -243,7 +246,7 @@ gtk_text_renderer_prepare_run (PangoRenderer *renderer,
if (color)
{
GdkRGBA rgba;
GdkRGBA rgba;
rgba.red = color->red / 65535.;
rgba.green = color->green / 65535.;
......@@ -519,14 +522,15 @@ text_renderer_begin (GtkTextRenderer *text_renderer,
GtkStyleContext *context;
GtkStateFlags state;
GdkRGBA color;
GtkCssNode *text_node;
text_renderer->widget = widget;
text_renderer->cr = cr;
context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
text_node = gtk_text_view_get_text_node ((GtkTextView *)widget);
gtk_style_context_save_to_node (context, text_node);
state = gtk_style_context_get_state (context);
gtk_style_context_get_color (context, state, &color);
......@@ -596,8 +600,6 @@ get_selected_clip (GtkTextRenderer *text_renderer,
return clip_region;
}
extern GtkCssNode *gtk_text_view_get_selection_node (GtkTextView *text_view);
static void
render_para (GtkTextRenderer *text_renderer,
GtkTextLineDisplay *line_display,
......
......@@ -1747,6 +1747,12 @@ gtk_text_view_init (GtkTextView *text_view)
g_object_unref (priv->selection_node);
}
GtkCssNode *
gtk_text_view_get_text_node (GtkTextView *text_view)
{
return text_view->priv->text_window->css_node;
}
GtkCssNode *
gtk_text_view_get_selection_node (GtkTextView *text_view)
{
......@@ -4854,6 +4860,7 @@ gtk_text_view_state_flags_changed (GtkWidget *widget,
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
GtkTextViewPrivate *priv = text_view->priv;
GdkCursor *cursor;
GtkStateFlags state;
if (gtk_widget_get_realized (widget))
{
......@@ -4876,17 +4883,17 @@ gtk_text_view_state_flags_changed (GtkWidget *widget,
gtk_text_view_unselect (text_view);
}
gtk_css_node_set_state (priv->text_window->css_node, gtk_widget_get_state (widget));
gtk_css_node_set_state (priv->selection_node, gtk_widget_get_state (widget));
state = gtk_widget_get_state_flags (widget);
gtk_css_node_set_state (priv->text_window->css_node, state);
gtk_css_node_set_state (priv->selection_node, state);
if (priv->left_window)
gtk_css_node_set_state (priv->left_window->css_node, gtk_widget_get_state (widget));
gtk_css_node_set_state (priv->left_window->css_node, state);
if (priv->right_window)
gtk_css_node_set_state (priv->right_window->css_node, gtk_widget_get_state (widget));
gtk_css_node_set_state (priv->right_window->css_node, state);
if (priv->top_window)
gtk_css_node_set_state (priv->top_window->css_node, gtk_widget_get_state (widget));
gtk_css_node_set_state (priv->top_window->css_node, state);
if (priv->bottom_window)
gtk_css_node_set_state (priv->bottom_window->css_node, gtk_widget_get_state (widget));
gtk_css_node_set_state (priv->bottom_window->css_node, state);
gtk_widget_queue_draw (widget);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment