Compare commits

...

4 Commits

Author SHA1 Message Date
Matthias Clasen
a3eccdd272 Document caret CSS properties 2016-01-07 23:56:03 -05:00
Matthias Clasen
2a23b13630 Deprecate cursor-color style properties
These have been replaced by CSS properties.
2016-01-07 23:47:08 -05:00
Matthias Clasen
97bfc84649 Use the caret-color properties for drawing carets
Replace the cursor-color and secondary-cursor-color style
properties with the caret-color and -gtk-secondary-caret-color
CSS properties.

For the 'auto' value of these properties, we keep the same
behavior that we used to have when the style properties are
not explicitly set.
2016-01-07 23:47:08 -05:00
Matthias Clasen
8335b89b37 Add the caret-color CSS property
This property is defined in http://www.w3.org/TR/css3-ui/#caret-color.
We also add a -gtk-secondary-caret-color property, since GTK+ has
supported differently colored split cursors in the past. Unlike
CSS, we don't support the weakly defined auto keyword, and just
use currentColor as the initial value.
2016-01-07 23:47:07 -05:00
6 changed files with 90 additions and 51 deletions

View File

@@ -1185,6 +1185,42 @@ entry {
these properties.
</para>
<table pgwide="1">
<title>Text caret properties</title>
<tgroup cols="7">
<colspec colnum="4" align="center"/>
<colspec colnum="5" align="center"/>
<thead>
<row><entry>Name</entry><entry>Value</entry><entry>Initial</entry><entry>Inh.</entry><entry>Ani.</entry><entry>Reference</entry><entry>Notes</entry></row>
</thead>
<tbody>
<row>
<entry>caret-color</entry>
<entry>〈color〉</entry>
<entry>currentColor</entry>
<entry></entry>
<entry></entry>
<entry><ulink url="http://www.w3.org/TR/css3-ui/#caret-color">CSS3</ulink></entry>
<entry>CSS allows an auto value</entry>
</row>
<row>
<entry>-gtk-secondary-caret-color</entry>
<entry>〈color〉</entry>
<entry>currentColor</entry>
<entry></entry>
<entry></entry>
<entry></entry>
<entry>Used for the secondary caret in bidirectional text</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
The caret properties provide a way to change the appearance of the insertion
caret in editable text.
</para>
<table pgwide="1">
<title>Text decoration properties</title>
<tgroup cols="7">

View File

@@ -122,6 +122,8 @@ gtk_css_value_color_get_fallback (guint property_id,
case GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR:
case GTK_CSS_PROPERTY_BORDER_LEFT_COLOR:
case GTK_CSS_PROPERTY_OUTLINE_COLOR:
case GTK_CSS_PROPERTY_CARET_COLOR:
case GTK_CSS_PROPERTY_SECONDARY_CARET_COLOR:
return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)),
property_id,
provider,

View File

@@ -1801,5 +1801,23 @@ G_GNUC_END_IGNORE_DEPRECATIONS
bindings_value_assign,
_gtk_css_array_value_new (_gtk_css_string_value_new (NULL)));
_gtk_style_property_add_alias ("-gtk-key-bindings", "gtk-key-bindings");
}
gtk_css_style_property_register ("caret-color",
GTK_CSS_PROPERTY_CARET_COLOR,
GDK_TYPE_RGBA,
GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_ANIMATED,
GTK_CSS_AFFECTS_TEXT,
color_parse,
color_query,
color_assign,
_gtk_css_color_value_new_current_color ());
gtk_css_style_property_register ("-gtk-secondary-caret-color",
GTK_CSS_PROPERTY_SECONDARY_CARET_COLOR,
GDK_TYPE_RGBA,
GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_ANIMATED,
GTK_CSS_AFFECTS_TEXT,
color_parse,
color_query,
color_assign,
_gtk_css_color_value_new_current_color ());
}

View File

@@ -222,6 +222,8 @@ enum { /*< skip >*/
GTK_CSS_PROPERTY_ICON_PALETTE,
GTK_CSS_PROPERTY_ENGINE,
GTK_CSS_PROPERTY_GTK_KEY_BINDINGS,
GTK_CSS_PROPERTY_CARET_COLOR,
GTK_CSS_PROPERTY_SECONDARY_CARET_COLOR,
/* add more */
GTK_CSS_PROPERTY_N_PROPERTIES
};

View File

@@ -35,6 +35,7 @@
#include "gtkcssnumbervalueprivate.h"
#include "gtkcsspathnodeprivate.h"
#include "gtkcssrgbavalueprivate.h"
#include "gtkcsscolorvalueprivate.h"
#include "gtkcssshadowsvalueprivate.h"
#include "gtkcssstaticstyleprivate.h"
#include "gtkcssstylepropertyprivate.h"
@@ -2754,62 +2755,26 @@ gtk_style_context_get_font (GtkStyleContext *context,
return description;
}
static void
get_cursor_color (GtkStyleContext *context,
gboolean primary,
GdkRGBA *color)
{
GdkColor *style_color;
gtk_style_context_get_style (context,
primary ? "cursor-color" : "secondary-cursor-color",
&style_color,
NULL);
if (style_color)
{
color->red = style_color->red / 65535.0;
color->green = style_color->green / 65535.0;
color->blue = style_color->blue / 65535.0;
color->alpha = 1;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_color_free (style_color);
G_GNUC_END_IGNORE_DEPRECATIONS
}
else
{
GtkStateFlags state;
state = gtk_style_context_get_state (context);
gtk_style_context_get_color (context, state, color);
if (!primary)
{
GdkRGBA bg;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_style_context_get_background_color (context, state, &bg);
G_GNUC_END_IGNORE_DEPRECATIONS
color->red = (color->red + bg.red) * 0.5;
color->green = (color->green + bg.green) * 0.5;
color->blue = (color->blue + bg.blue) * 0.5;
}
}
}
void
_gtk_style_context_get_cursor_color (GtkStyleContext *context,
GdkRGBA *primary_color,
GdkRGBA *secondary_color)
{
GdkRGBA *pc, *sc;
gtk_style_context_get (context,
gtk_style_context_get_state (context),
"caret-color", &pc,
"-gtk-secondary-caret-color", &sc,
NULL);
if (primary_color)
get_cursor_color (context, TRUE, primary_color);
*primary_color = *pc;
if (secondary_color)
get_cursor_color (context, FALSE, secondary_color);
*secondary_color = *sc;
gdk_rgba_free (pc);
gdk_rgba_free (sc);
}
static void

View File

@@ -3496,18 +3496,34 @@ G_GNUC_END_IGNORE_DEPRECATIONS
0, G_MAXINT, 1,
GTK_PARAM_READABLE | G_PARAM_DEPRECATED));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkWidget:cursor-color:
*
* The color with which to draw the insertion cursor in entries and
* text views.
*
* Deprecated: 3.20: Use the caret-color CSS property
*/
gtk_widget_class_install_style_property (klass,
g_param_spec_boxed ("cursor-color",
P_("Cursor color"),
P_("Color with which to draw insertion cursor"),
GDK_TYPE_COLOR,
GTK_PARAM_READABLE));
GTK_PARAM_READABLE|G_PARAM_DEPRECATED));
/**
* GtkWidget:secondary-cursor-color:
*
* The color with which to draw the secondary insertion cursor in entries and
* text views when editing mixed right-to-left and left-to-right text.
*
* Deprecated: 3.20: Use the -gtk-secondary-caret-color CSS property
*/
gtk_widget_class_install_style_property (klass,
g_param_spec_boxed ("secondary-cursor-color",
P_("Secondary cursor color"),
P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
GDK_TYPE_COLOR,
GTK_PARAM_READABLE));
GTK_PARAM_READABLE|G_PARAM_DEPRECATED));
G_GNUC_END_IGNORE_DEPRECATIONS
gtk_widget_class_install_style_property (klass,
g_param_spec_float ("cursor-aspect-ratio",