st-widget: Add automagic rtl/ltr pseudo classes
At times, RTL locales require different CSS, so always create theme nodes with :ltr/:rtl pseudo classes depending on the widget's text direction, to provide an easy way to handle those cases without requiring a separate stylesheet. https://bugzilla.gnome.org/show_bug.cgi?id=643835
This commit is contained in:
parent
aff9b419cf
commit
fefe2df6b5
@ -554,6 +554,7 @@ st_widget_get_theme_node (StWidget *widget)
|
|||||||
StThemeNode *parent_node = NULL;
|
StThemeNode *parent_node = NULL;
|
||||||
ClutterStage *stage = NULL;
|
ClutterStage *stage = NULL;
|
||||||
ClutterActor *parent;
|
ClutterActor *parent;
|
||||||
|
char *pseudo_class, *direction_pseudo_class;
|
||||||
|
|
||||||
parent = clutter_actor_get_parent (CLUTTER_ACTOR (widget));
|
parent = clutter_actor_get_parent (CLUTTER_ACTOR (widget));
|
||||||
while (parent != NULL)
|
while (parent != NULL)
|
||||||
@ -575,13 +576,31 @@ st_widget_get_theme_node (StWidget *widget)
|
|||||||
if (parent_node == NULL)
|
if (parent_node == NULL)
|
||||||
parent_node = get_root_theme_node (CLUTTER_STAGE (stage));
|
parent_node = get_root_theme_node (CLUTTER_STAGE (stage));
|
||||||
|
|
||||||
|
/* Always append a "magic" pseudo class indicating the text
|
||||||
|
* direction, to allow to adapt the CSS when necessary without
|
||||||
|
* requiring separate style sheets.
|
||||||
|
*/
|
||||||
|
if (st_widget_get_direction (widget) == ST_TEXT_DIRECTION_RTL)
|
||||||
|
direction_pseudo_class = "rtl";
|
||||||
|
else
|
||||||
|
direction_pseudo_class = "ltr";
|
||||||
|
|
||||||
|
if (priv->pseudo_class)
|
||||||
|
pseudo_class = g_strconcat(priv->pseudo_class, " ",
|
||||||
|
direction_pseudo_class, NULL);
|
||||||
|
else
|
||||||
|
pseudo_class = direction_pseudo_class;
|
||||||
|
|
||||||
priv->theme_node = st_theme_node_new (st_theme_context_get_for_stage (stage),
|
priv->theme_node = st_theme_node_new (st_theme_context_get_for_stage (stage),
|
||||||
parent_node, priv->theme,
|
parent_node, priv->theme,
|
||||||
G_OBJECT_TYPE (widget),
|
G_OBJECT_TYPE (widget),
|
||||||
clutter_actor_get_name (CLUTTER_ACTOR (widget)),
|
clutter_actor_get_name (CLUTTER_ACTOR (widget)),
|
||||||
priv->style_class,
|
priv->style_class,
|
||||||
priv->pseudo_class,
|
pseudo_class,
|
||||||
priv->inline_style);
|
priv->inline_style);
|
||||||
|
|
||||||
|
if (pseudo_class != direction_pseudo_class)
|
||||||
|
g_free (pseudo_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
return priv->theme_node;
|
return priv->theme_node;
|
||||||
@ -1438,8 +1457,15 @@ st_widget_get_direction (StWidget *self)
|
|||||||
void
|
void
|
||||||
st_widget_set_direction (StWidget *self, StTextDirection dir)
|
st_widget_set_direction (StWidget *self, StTextDirection dir)
|
||||||
{
|
{
|
||||||
|
StTextDirection old_direction;
|
||||||
|
|
||||||
g_return_if_fail (ST_IS_WIDGET (self));
|
g_return_if_fail (ST_IS_WIDGET (self));
|
||||||
|
|
||||||
|
old_direction = st_widget_get_direction (self);
|
||||||
self->priv->direction = dir;
|
self->priv->direction = dir;
|
||||||
|
|
||||||
|
if (old_direction != st_widget_get_direction (self))
|
||||||
|
st_widget_style_changed (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user