summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2017-01-13 03:28:34 +0100
committerBenjamin Otte <otte@redhat.com>2017-01-13 03:38:36 +0100
commita06b1ea1baecf6f0211726e901af93995f01a923 (patch)
tree4efa20db1b6fd372ab7113cb5968e7336f42e06f
parentb58de2d16cbb1b4e8fbdb6aac9d73deb887650e9 (diff)
downloadgtk+-a06b1ea1baecf6f0211726e901af93995f01a923.tar.gz
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.
-rw-r--r--gtk/gtkcssimage.c8
-rw-r--r--testsuite/reftests/Makefile.am3
-rw-r--r--testsuite/reftests/css-image-aspect-ratio.css8
-rw-r--r--testsuite/reftests/css-image-aspect-ratio.ref.ui11
-rw-r--r--testsuite/reftests/css-image-aspect-ratio.ui10
5 files changed, 36 insertions, 4 deletions
diff --git a/gtk/gtkcssimage.c b/gtk/gtkcssimage.c
index 29d9959d8b..822ba4726f 100644
--- a/gtk/gtkcssimage.c
+++ b/gtk/gtkcssimage.c
@@ -358,13 +358,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 2dbca1209c..31645d23f0 100644
--- a/testsuite/reftests/Makefile.am
+++ b/testsuite/reftests/Makefile.am
@@ -198,6 +198,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 0000000000..da054daa16
--- /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 0000000000..88fbd72e75
--- /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 0000000000..c7f559893b
--- /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>