[gtk+/gtk-3-22] cssimage: Scale images to contain, not cover



commit 2e7d5c08cbd62cbb49dbec965ecebd6229d6d00a
Author: Benjamin Otte <otte redhat com>
Date:   Fri Jan 13 03:28:34 2017 +0100

    cssimage: Scale images to contain, not cover
    
    Images with just an aspect ratio, but without a size, should be scaled
    to be fully visible in the given area.
    But we scaled them to completely cover the given area, which made them
    partially invisible.
    
    Reftest included.

 gtk/gtkcssimage.c                                |    8 ++++----
 testsuite/reftests/Makefile.am                   |    3 +++
 testsuite/reftests/css-image-aspect-ratio.css    |    8 ++++++++
 testsuite/reftests/css-image-aspect-ratio.ref.ui |   11 +++++++++++
 testsuite/reftests/css-image-aspect-ratio.ui     |   10 ++++++++++
 5 files changed, 36 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkcssimage.c b/gtk/gtkcssimage.c
index 3b9ff41..eebe013 100644
--- a/gtk/gtkcssimage.c
+++ b/gtk/gtkcssimage.c
@@ -307,13 +307,13 @@ _gtk_css_image_get_concrete_size (GtkCssImage *image,
         {
           if (image_aspect * default_height > default_width)
             {
-              *concrete_width = default_height * image_aspect;
-              *concrete_height = default_height;
+              *concrete_width = default_width;
+              *concrete_height = default_width / image_aspect;
             }
           else
             {
-              *concrete_width = default_width;
-              *concrete_height = default_width / image_aspect;
+              *concrete_width = default_height * image_aspect;
+              *concrete_height = default_height;
             }
         }
       else
diff --git a/testsuite/reftests/Makefile.am b/testsuite/reftests/Makefile.am
index 37df3a9..fa968e9 100644
--- a/testsuite/reftests/Makefile.am
+++ b/testsuite/reftests/Makefile.am
@@ -206,6 +206,9 @@ testdata = \
        css-currentcolor-alpha.css \
        css-currentcolor-alpha.ui \
        css-currentcolor-alpha.ref.ui \
+       css-image-aspect-ratio.css \
+       css-image-aspect-ratio.ui \
+       css-image-aspect-ratio.ref.ui \
        css-match-class.css \
        css-match-class.ref.ui \
        css-match-class.ui \
diff --git a/testsuite/reftests/css-image-aspect-ratio.css b/testsuite/reftests/css-image-aspect-ratio.css
new file mode 100644
index 0000000..da054da
--- /dev/null
+++ b/testsuite/reftests/css-image-aspect-ratio.css
@@ -0,0 +1,8 @@
+window {
+  background-image: -gtk-icontheme("edit-delete");
+  background-repeat: no-repeat;
+}
+
+#reference {
+  background-size: 24px 24px;
+}
diff --git a/testsuite/reftests/css-image-aspect-ratio.ref.ui 
b/testsuite/reftests/css-image-aspect-ratio.ref.ui
new file mode 100644
index 0000000..88fbd72
--- /dev/null
+++ b/testsuite/reftests/css-image-aspect-ratio.ref.ui
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkWindow" id="window1">
+    <property name="width_request">48</property>
+    <property name="height_request">24</property>
+    <property name="can_focus">False</property>
+    <property name="type">popup</property>
+    <property name="name">reference</property>
+  </object>
+</interface>
diff --git a/testsuite/reftests/css-image-aspect-ratio.ui b/testsuite/reftests/css-image-aspect-ratio.ui
new file mode 100644
index 0000000..c7f5598
--- /dev/null
+++ b/testsuite/reftests/css-image-aspect-ratio.ui
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkWindow" id="window1">
+    <property name="width_request">48</property>
+    <property name="height_request">24</property>
+    <property name="can_focus">False</property>
+    <property name="type">popup</property>
+  </object>
+</interface>


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