Make the search entry behave better in RTL locales

It is expected that the primary and secondary icons in entries
change places in RTL locales. When doing so, the edit-clear
icon must be replaced by an rtl variant too.

http://bugzilla.gnome.org/show_bug.cgi?id=705779
This commit is contained in:
Matthias Clasen 2013-08-26 18:24:26 -04:00 committed by Florian Müllner
parent f8234b07f8
commit 1b6090fe13
2 changed files with 26 additions and 18 deletions

View File

@ -85,8 +85,12 @@ const ViewSelector = new Lang.Class({
this._entry.set_primary_icon(new St.Icon({ style_class: 'search-entry-icon',
icon_name: 'edit-find-symbolic' }));
this._clearIcon = new St.Icon({ style_class: 'search-entry-icon',
icon_name: 'edit-clear-symbolic' });
if (this._entry.get_text_direction() == Clutter.TextDirection.RTL)
this._clearIcon = new St.Icon({ style_class: 'search-entry-icon',
icon_name: 'edit-clear-rtl-symbolic' });
else
this._clearIcon = new St.Icon({ style_class: 'search-entry-icon',
icon_name: 'edit-clear-symbolic' });
this._iconClickedId = 0;
this._capturedEventId = 0;

View File

@ -416,6 +416,18 @@ st_entry_allocate (ClutterActor *actor,
ClutterActorBox content_box, child_box, icon_box;
gfloat icon_w, icon_h;
gfloat entry_h, min_h, pref_h, avail_h;
ClutterActor *left_icon, *right_icon;
if (clutter_actor_get_text_direction (actor) == CLUTTER_TEXT_DIRECTION_RTL)
{
right_icon = priv->primary_icon;
left_icon = priv->secondary_icon;
}
else
{
left_icon = priv->primary_icon;
right_icon = priv->secondary_icon;
}
clutter_actor_set_allocation (actor, box, flags);
@ -426,12 +438,10 @@ st_entry_allocate (ClutterActor *actor,
child_box.x1 = content_box.x1;
child_box.x2 = content_box.x2;
if (priv->primary_icon)
if (left_icon)
{
clutter_actor_get_preferred_width (priv->primary_icon,
-1, NULL, &icon_w);
clutter_actor_get_preferred_height (priv->primary_icon,
-1, NULL, &icon_h);
clutter_actor_get_preferred_width (left_icon, -1, NULL, &icon_w);
clutter_actor_get_preferred_height (left_icon, -1, NULL, &icon_h);
icon_box.x1 = content_box.x1;
icon_box.x2 = icon_box.x1 + icon_w;
@ -439,20 +449,16 @@ st_entry_allocate (ClutterActor *actor,
icon_box.y1 = (int) (content_box.y1 + avail_h / 2 - icon_h / 2);
icon_box.y2 = icon_box.y1 + icon_h;
clutter_actor_allocate (priv->primary_icon,
&icon_box,
flags);
clutter_actor_allocate (left_icon, &icon_box, flags);
/* reduce the size for the entry */
child_box.x1 += icon_w + priv->spacing;
}
if (priv->secondary_icon)
if (right_icon)
{
clutter_actor_get_preferred_width (priv->secondary_icon,
-1, NULL, &icon_w);
clutter_actor_get_preferred_height (priv->secondary_icon,
-1, NULL, &icon_h);
clutter_actor_get_preferred_width (right_icon, -1, NULL, &icon_w);
clutter_actor_get_preferred_height (right_icon, -1, NULL, &icon_h);
icon_box.x2 = content_box.x2;
icon_box.x1 = icon_box.x2 - icon_w;
@ -460,9 +466,7 @@ st_entry_allocate (ClutterActor *actor,
icon_box.y1 = (int) (content_box.y1 + avail_h / 2 - icon_h / 2);
icon_box.y2 = icon_box.y1 + icon_h;
clutter_actor_allocate (priv->secondary_icon,
&icon_box,
flags);
clutter_actor_allocate (right_icon, &icon_box, flags);
/* reduce the size for the entry */
child_box.x2 -= icon_w - priv->spacing;