Title: [164804] trunk
Revision
164804
Author
grao...@webkit.org
Date
2014-02-27 07:52:28 -0800 (Thu, 27 Feb 2014)

Log Message

Respect SVG fragment identifiers in <img> src attribute
https://bugs.webkit.org/show_bug.cgi?id=129387

Reviewed by Antti Koivisto.

Source/WebCore:

Test: svg/css/svg-resource-fragment-identifier-img-src.html

When providing an SVG image for a given renderer, check that the URL used to load
that image is taken into account in case it featured a fragment identifier, ensuring
that the CSS :target pseudo-class is correctly handled for SVG resources. This patch
is specific to <img> elements, specific support will also need to be added for various
CSS properties that support SVG images.

* svg/graphics/SVGImageCache.cpp:
(WebCore::SVGImageCache::imageForRenderer):
Check if the provided renderer is attached to an <img> element and, if so, pass the
resolved <img> source URL, taking into account srcset, to the SVGImageForContainer.

* svg/graphics/SVGImageForContainer.cpp:
(WebCore::SVGImageForContainer::setURL):
Trigger the FrameView machinery to ensure that the :target pseudo-class is respected
should the provided URL feature a fragment identifier.

* svg/graphics/SVGImageForContainer.h:
Declare the new setURL() method.

LayoutTests:

Test that we correctly handle the fragment identifier used in SVG URLs in <img> elements,
checking for correct srcset handling as well.

* svg/css/resources/fragment-identifiers.svg: Added.
* svg/css/svg-resource-fragment-identifier-img-src-expected.html: Added.
* svg/css/svg-resource-fragment-identifier-img-src.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (164803 => 164804)


--- trunk/LayoutTests/ChangeLog	2014-02-27 15:50:24 UTC (rev 164803)
+++ trunk/LayoutTests/ChangeLog	2014-02-27 15:52:28 UTC (rev 164804)
@@ -1,3 +1,17 @@
+2014-02-27  Antoine Quint  <grao...@webkit.org>
+
+        Respect SVG fragment identifiers in <img> src attribute
+        https://bugs.webkit.org/show_bug.cgi?id=129387
+
+        Reviewed by Antti Koivisto.
+
+        Test that we correctly handle the fragment identifier used in SVG URLs in <img> elements,
+        checking for correct srcset handling as well.
+
+        * svg/css/resources/fragment-identifiers.svg: Added.
+        * svg/css/svg-resource-fragment-identifier-img-src-expected.html: Added.
+        * svg/css/svg-resource-fragment-identifier-img-src.html: Added.
+
 2014-02-27  Mihai Tica  <mit...@adobe.com>
 
         [CSS Blending] Parse and implement the -webkit-isolation CSS property.

Added: trunk/LayoutTests/svg/css/resources/fragment-identifiers.svg (0 => 164804)


--- trunk/LayoutTests/svg/css/resources/fragment-identifiers.svg	                        (rev 0)
+++ trunk/LayoutTests/svg/css/resources/fragment-identifiers.svg	2014-02-27 15:52:28 UTC (rev 164804)
@@ -0,0 +1,9 @@
+<svg xmlns="http://www.w3.org/2000/svg">
+    <style type="text/css">
+        rect { display: none }
+        rect:target { display: inline }
+    </style>
+    <rect id="red" width="100%" height="100%" fill="red" />
+    <rect id="green" width="100%" height="100%" fill="green" />
+    <rect id="blue" width="100%" height="100%" fill="blue" />
+</svg>

Added: trunk/LayoutTests/svg/css/svg-resource-fragment-identifier-img-src-expected.html (0 => 164804)


--- trunk/LayoutTests/svg/css/svg-resource-fragment-identifier-img-src-expected.html	                        (rev 0)
+++ trunk/LayoutTests/svg/css/svg-resource-fragment-identifier-img-src-expected.html	2014-02-27 15:52:28 UTC (rev 164804)
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <style type="text/css" media="screen">
+        
+        div {
+            width: 100px;
+            height: 100px;
+            margin: 10px;
+            display: inline-block;
+        }
+
+        .red {
+            background-color: red;
+        }
+
+        .green {
+            background-color: green;
+        }
+
+        .blue {
+            background-color: blue;
+        }
+
+    </style>
+
+</head>
+<body>
+
+    <div class="red"></div>
+    <div class="green"></div>
+    <div class="blue"></div>
+    <div class="green"></div>
+
+</body>
+</html>

Added: trunk/LayoutTests/svg/css/svg-resource-fragment-identifier-img-src.html (0 => 164804)


--- trunk/LayoutTests/svg/css/svg-resource-fragment-identifier-img-src.html	                        (rev 0)
+++ trunk/LayoutTests/svg/css/svg-resource-fragment-identifier-img-src.html	2014-02-27 15:52:28 UTC (rev 164804)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script>
+        window.targetScaleFactor = 2;
+    </script>
+    <script src=""
+    <style type="text/css" media="screen">
+        
+        div, img {
+            width: 100px;
+            height: 100px;
+            margin: 10px;
+            display: inline-block;
+        }
+
+    </style>
+
+</head>
+<body>
+
+    <img src=""
+    <img src=""
+    <img src=""
+    <img src="" srcset="resources/fragment-identifiers.svg#green 2x">
+
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (164803 => 164804)


--- trunk/Source/WebCore/ChangeLog	2014-02-27 15:50:24 UTC (rev 164803)
+++ trunk/Source/WebCore/ChangeLog	2014-02-27 15:52:28 UTC (rev 164804)
@@ -1,3 +1,31 @@
+2014-02-27  Antoine Quint  <grao...@webkit.org>
+
+        Respect SVG fragment identifiers in <img> src attribute
+        https://bugs.webkit.org/show_bug.cgi?id=129387
+
+        Reviewed by Antti Koivisto.
+
+        Test: svg/css/svg-resource-fragment-identifier-img-src.html
+
+        When providing an SVG image for a given renderer, check that the URL used to load
+        that image is taken into account in case it featured a fragment identifier, ensuring
+        that the CSS :target pseudo-class is correctly handled for SVG resources. This patch
+        is specific to <img> elements, specific support will also need to be added for various
+        CSS properties that support SVG images.
+
+        * svg/graphics/SVGImageCache.cpp:
+        (WebCore::SVGImageCache::imageForRenderer):
+        Check if the provided renderer is attached to an <img> element and, if so, pass the
+        resolved <img> source URL, taking into account srcset, to the SVGImageForContainer.
+
+        * svg/graphics/SVGImageForContainer.cpp:
+        (WebCore::SVGImageForContainer::setURL):
+        Trigger the FrameView machinery to ensure that the :target pseudo-class is respected
+        should the provided URL feature a fragment identifier.
+
+        * svg/graphics/SVGImageForContainer.h:
+        Declare the new setURL() method.
+
 2014-02-27  Krzysztof Czech  <k.cz...@samsung.com>
 
         [ATK] Fix style errors in enum members

Modified: trunk/Source/WebCore/svg/graphics/SVGImageCache.cpp (164803 => 164804)


--- trunk/Source/WebCore/svg/graphics/SVGImageCache.cpp	2014-02-27 15:50:24 UTC (rev 164803)
+++ trunk/Source/WebCore/svg/graphics/SVGImageCache.cpp	2014-02-27 15:52:28 UTC (rev 164804)
@@ -23,6 +23,7 @@
 
 #include "FrameView.h"
 #include "GraphicsContext.h"
+#include "HTMLImageElement.h"
 #include "ImageBuffer.h"
 #include "Page.h"
 #include "RenderSVGRoot.h"
@@ -88,6 +89,14 @@
         return Image::nullImage();
 
     RefPtr<SVGImageForContainer> imageForContainer = it->value;
+    
+    Node* node = renderer->node();
+    if (node && isHTMLImageElement(node)) {
+        const AtomicString& urlString = toHTMLImageElement(node)->imageSourceURL();
+        URL url = ""
+        imageForContainer->setURL(url);
+    }
+        
     ASSERT(!imageForContainer->size().isEmpty());
     return imageForContainer.get();
 }

Modified: trunk/Source/WebCore/svg/graphics/SVGImageForContainer.cpp (164803 => 164804)


--- trunk/Source/WebCore/svg/graphics/SVGImageForContainer.cpp	2014-02-27 15:50:24 UTC (rev 164803)
+++ trunk/Source/WebCore/svg/graphics/SVGImageForContainer.cpp	2014-02-27 15:52:28 UTC (rev 164804)
@@ -23,6 +23,7 @@
 #include "AffineTransform.h"
 #include "FloatRect.h"
 #include "FloatSize.h"
+#include "FrameView.h"
 #include "Image.h"
 #include "SVGImage.h"
 
@@ -53,4 +54,9 @@
     return m_image->nativeImageForCurrentFrame();
 }
 
+void SVGImageForContainer::setURL(const URL& url)
+{ 
+    m_image->frameView()->scrollToFragment(url);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/svg/graphics/SVGImageForContainer.h (164803 => 164804)


--- trunk/Source/WebCore/svg/graphics/SVGImageForContainer.h	2014-02-27 15:50:24 UTC (rev 164803)
+++ trunk/Source/WebCore/svg/graphics/SVGImageForContainer.h	2014-02-27 15:52:28 UTC (rev 164804)
@@ -31,6 +31,7 @@
 #include "FloatSize.h"
 #include "Image.h"
 #include "SVGImage.h"
+#include "URL.h"
 
 namespace WebCore {
 
@@ -45,6 +46,8 @@
 
     virtual IntSize size() const override;
 
+    void setURL(const URL&);
+
     virtual bool usesContainerSize() const override { return m_image->usesContainerSize(); }
     virtual bool hasRelativeWidth() const override { return m_image->hasRelativeWidth(); }
     virtual bool hasRelativeHeight() const override { return m_image->hasRelativeHeight(); }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to