[gnome-software: 1/2] gs-feature-tile: Support RTL CSS for banners




commit 675d67c99601adb5772b912e8670e0366830bb58
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Dec 15 11:38:53 2020 +0000

    gs-feature-tile: Support RTL CSS for banners
    
    If the feature tile is displayed in RTL mode, load any RTL CSS from the
    `GnomeSoftware::FeatureTile-css-rtl` metadata key in preference to the
    normal `GnomeSoftware::FeatureTile-css` key.
    
    Reload the feature tile if the text direction changes.
    
    This is a simpler approach than supporting `.class` and
    `.class:dir(rtl)` CSS selectors in the same block of CSS. The problem
    with allowing arbitrary blocks of CSS is that it’s very hard to validate
    that they only do what they’re meant to, and don’t include CSS rules to
    change the style of things they’re not meant to.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #773

 src/gs-feature-tile.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-feature-tile.c b/src/gs-feature-tile.c
index 9cc5f7ce1..44318eb81 100644
--- a/src/gs-feature-tile.c
+++ b/src/gs-feature-tile.c
@@ -48,7 +48,7 @@ gs_feature_tile_refresh (GsAppTile *self)
        GsFeatureTile *tile = GS_FEATURE_TILE (self);
        GsApp *app = gs_app_tile_get_app (self);
        AtkObject *accessible;
-       const gchar *markup;
+       const gchar *markup = NULL;
        g_autofree gchar *name = NULL;
 
        if (app == NULL)
@@ -61,8 +61,14 @@ gs_feature_tile_refresh (GsAppTile *self)
        gtk_label_set_label (GTK_LABEL (tile->subtitle), gs_app_get_summary (app));
 
        /* perhaps set custom css; cache it so that images don’t get reloaded
-        * unnecessarily */
-       markup = gs_app_get_metadata_item (app, "GnomeSoftware::FeatureTile-css");
+        * unnecessarily. The custom CSS is direction-dependent, and will be
+        * reloaded when the direction changes. If RTL CSS isn’t set, fall back
+        * to the LTR CSS. */
+       if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL)
+               markup = gs_app_get_metadata_item (app, "GnomeSoftware::FeatureTile-css-rtl");
+       if (markup == NULL)
+               markup = gs_app_get_metadata_item (app, "GnomeSoftware::FeatureTile-css");
+
        if (tile->markup_cache != markup) {
                g_autoptr(GsCss) css = gs_css_new ();
                if (markup != NULL)
@@ -100,6 +106,14 @@ gs_feature_tile_refresh (GsAppTile *self)
        }
 }
 
+static void
+gs_feature_tile_direction_changed (GtkWidget *widget, GtkTextDirection previous_direction)
+{
+       GsFeatureTile *tile = GS_FEATURE_TILE (widget);
+
+       gs_feature_tile_refresh (GS_APP_TILE (tile));
+}
+
 static void
 gs_feature_tile_init (GsFeatureTile *tile)
 {
@@ -116,6 +130,8 @@ gs_feature_tile_class_init (GsFeatureTileClass *klass)
 
        object_class->dispose = gs_feature_tile_dispose;
 
+       widget_class->direction_changed = gs_feature_tile_direction_changed;
+
        app_tile_class->refresh = gs_feature_tile_refresh;
 
        gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-feature-tile.ui");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]