Title: [113490] trunk
Revision
113490
Author
[email protected]
Date
2012-04-06 13:20:19 -0700 (Fri, 06 Apr 2012)

Log Message

https://bugs.webkit.org/show_bug.cgi?id=81939
-webkit-image-set should update dynamically when the device scale factor 
changes
-and corresponding-
<rdar://problem/11101108> 

Reviewed by Darin Adler.

Source/WebCore: 

New member variable to keep track of the scale factor.
* css/CSSImageSetValue.cpp:
(WebCore::CSSImageSetValue::CSSImageSetValue):
(WebCore::CSSImageSetValue::bestImageForScaleFactor):

 Merge the two cachedImageSet functions. There was no need for two functions here.
(WebCore::CSSImageSetValue::cachedImageSet):

cachedOrPendingImageSet() now takes a Document as a parameter so that it can 
access the deviceScaleFactor. If there is a cached image already and the 
Document's deviceScaleFactor doesn't match m_scaleFactor, then m_imageSet is set 
to a pending image so that the best fit image will be reassessed and then 
loaded.
(WebCore::CSSImageSetValue::cachedOrPendingImageSet):
* css/CSSImageSetValue.h:
(WebCore):
(CSSImageSetValue):

cachedOrPendingImageSet() now takes a Document.
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::collectMatchingRulesForList):

StyleCachedImageSet should inherit from CachedImageClient just like 
StyleCachedImage. It should add and remove itself as a client upon creation 
and destruction, respectively.
* rendering/style/StyleCachedImageSet.cpp:
(WebCore::StyleCachedImageSet::StyleCachedImageSet):
(WebCore):
(WebCore::StyleCachedImageSet::~StyleCachedImageSet):
* rendering/style/StyleCachedImageSet.h:
(StyleCachedImageSet):

LayoutTests: 

* fast/hidpi/image-set-background-dynamic.html: Added.
* fast/hidpi/image-set-border-image-dynamic.html: Added.
* fast/hidpi/image-set-in-content-dynamic.html: Added.
* platform/mac/fast/hidpi/image-set-background-dynamic-expected.png: Added.
* platform/mac/fast/hidpi/image-set-background-dynamic-expected.txt: Added.
* platform/mac/fast/hidpi/image-set-border-image-dynamic-expected.png: Added.
* platform/mac/fast/hidpi/image-set-border-image-dynamic-expected.txt: Added.
* platform/mac/fast/hidpi/image-set-in-content-dynamic-expected.png: Added.
* platform/mac/fast/hidpi/image-set-in-content-dynamic-expected.txt: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (113489 => 113490)


--- trunk/LayoutTests/ChangeLog	2012-04-06 20:12:41 UTC (rev 113489)
+++ trunk/LayoutTests/ChangeLog	2012-04-06 20:20:19 UTC (rev 113490)
@@ -1,3 +1,23 @@
+2012-04-06  Beth Dakin  <[email protected]>
+
+        https://bugs.webkit.org/show_bug.cgi?id=81939
+        -webkit-image-set should update dynamically when the device scale factor 
+        changes
+        -and corresponding-
+        <rdar://problem/11101108> 
+
+        Reviewed by Darin Adler.
+
+        * fast/hidpi/image-set-background-dynamic.html: Added.
+        * fast/hidpi/image-set-border-image-dynamic.html: Added.
+        * fast/hidpi/image-set-in-content-dynamic.html: Added.
+        * platform/mac/fast/hidpi/image-set-background-dynamic-expected.png: Added.
+        * platform/mac/fast/hidpi/image-set-background-dynamic-expected.txt: Added.
+        * platform/mac/fast/hidpi/image-set-border-image-dynamic-expected.png: Added.
+        * platform/mac/fast/hidpi/image-set-border-image-dynamic-expected.txt: Added.
+        * platform/mac/fast/hidpi/image-set-in-content-dynamic-expected.png: Added.
+        * platform/mac/fast/hidpi/image-set-in-content-dynamic-expected.txt: Added.
+
 2012-04-06  Stephen Chenney  <[email protected]>
 
         [Chromium} Rebaseline some failing Leopard tests

Added: trunk/LayoutTests/fast/hidpi/image-set-background-dynamic.html (0 => 113490)


--- trunk/LayoutTests/fast/hidpi/image-set-background-dynamic.html	                        (rev 0)
+++ trunk/LayoutTests/fast/hidpi/image-set-background-dynamic.html	2012-04-06 20:20:19 UTC (rev 113490)
@@ -0,0 +1,32 @@
+<html>
+<head>
+    <head>
+    <script>
+        function startTest() {
+            if (window.layoutTestController) {
+                layoutTestController.waitUntilDone();
+                layoutTestController.setBackingScaleFactor(2, finishTest);
+            }
+        }
+
+        function finishTest() {
+            var test = document.getElementById("foo");
+            test.innerHTML = window.devicePixelRatio;
+            setTimeout(function() { layoutTestController.notifyDone(); }, 0);
+        }
+    </script>
+    
+<style>
+    #foo {
+        width:100px;
+        height:100px;
+        background-image: -webkit-image-set(url('resources/blue-100-px-square.png') 1x, url('resources/green-200-px-square.png') 2x);
+    }
+</style>
+</head>
+
+<body _onload_="startTest();">
+    <div>This test passes if the div below is a blue 100px square when the deviceScaleFactor is 1, and if it is a 100px green square when the deviceScaleFactor is 2. When run in the test harness, this test is distinct from image-set-as-background, because it ensures that the green image loads dynamically when the scale factor changes.</div>
+    <div id=foo></div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/hidpi/image-set-border-image-dynamic.html (0 => 113490)


--- trunk/LayoutTests/fast/hidpi/image-set-border-image-dynamic.html	                        (rev 0)
+++ trunk/LayoutTests/fast/hidpi/image-set-border-image-dynamic.html	2012-04-06 20:20:19 UTC (rev 113490)
@@ -0,0 +1,32 @@
+<html>
+<head>
+    <head>
+    <script>
+        function startTest() {
+            if (window.layoutTestController) {
+                layoutTestController.waitUntilDone();
+                layoutTestController.setBackingScaleFactor(2, finishTest);
+            }
+        }
+
+        function finishTest() {
+            var test = document.getElementById("foo");
+            test.innerHTML = window.devicePixelRatio;
+            setTimeout(function() { layoutTestController.notifyDone(); }, 0);
+        }
+    </script>
+    
+<style>
+    #foo {
+        width:100px;
+        height:100px;
+        -webkit-border-image: -webkit-image-set(url('resources/blue-100-px-square.png') 1x, url('resources/green-200-px-square.png') 2x) 10 10 10 10 stretch stretch;
+    }
+</style>
+</head>
+
+<body _onload_="startTest();">
+    <div>This test passes if the div below is a blue 100px square when the deviceScaleFactor is 1, and if it is a 100px green square when the deviceScaleFactor is 2. When run in the test harness, this test is distinct from image-set-as-background, because it ensures that the green image loads dynamically when the scale factor changes.</div>
+    <div id=foo></div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/hidpi/image-set-in-content-dynamic.html (0 => 113490)


--- trunk/LayoutTests/fast/hidpi/image-set-in-content-dynamic.html	                        (rev 0)
+++ trunk/LayoutTests/fast/hidpi/image-set-in-content-dynamic.html	2012-04-06 20:20:19 UTC (rev 113490)
@@ -0,0 +1,32 @@
+<html>
+<head>
+    <head>
+    <script>
+        function startTest() {
+            if (window.layoutTestController) {
+                layoutTestController.waitUntilDone();
+                layoutTestController.setBackingScaleFactor(2, finishTest);
+            }
+        }
+
+        function finishTest() {
+            var test = document.getElementById("foo");
+            test.innerHTML = window.devicePixelRatio;
+            setTimeout(function() { layoutTestController.notifyDone(); }, 0);
+        }
+    </script>
+    
+<style>
+    #foo {
+        width:100px;
+        height:100px;
+        content: -webkit-image-set(url('resources/blue-100-px-square.png') 1x, url('resources/green-200-px-square.png') 2x);
+    }
+</style>
+</head>
+
+<body _onload_="startTest();">
+    <div>This test passes if the div below is a blue 100px square when the deviceScaleFactor is 1, and if it is a 100px green square when the deviceScaleFactor is 2. When run in the test harness, this test is distinct from image-set-as-background, because it ensures that the green image loads dynamically when the scale factor changes.</div>
+    <div id=foo></div>
+</body>
+</html>

Added: trunk/LayoutTests/platform/mac/fast/hidpi/image-set-background-dynamic-expected.png


(Binary files differ)
Property changes on: trunk/LayoutTests/platform/mac/fast/hidpi/image-set-background-dynamic-expected.png ___________________________________________________________________

Added: svn:mime-type

Added: trunk/LayoutTests/platform/mac/fast/hidpi/image-set-background-dynamic-expected.txt (0 => 113490)


--- trunk/LayoutTests/platform/mac/fast/hidpi/image-set-background-dynamic-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/fast/hidpi/image-set-background-dynamic-expected.txt	2012-04-06 20:20:19 UTC (rev 113490)
@@ -0,0 +1,13 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x54
+        RenderText {#text} at (0,0) size 773x54
+          text run at (0,0) width 761: "This test passes if the div below is a blue 100px square when the deviceScaleFactor is 1, and if it is a 100px green square"
+          text run at (0,18) width 773: "when the deviceScaleFactor is 2. When run in the test harness, this test is distinct from image-set-as-background, because it"
+          text run at (0,36) width 492: "ensures that the green image loads dynamically when the scale factor changes."
+      RenderBlock {DIV} at (0,54) size 100x100
+        RenderText {#text} at (0,0) size 8x18
+          text run at (0,0) width 8: "2"

Added: trunk/LayoutTests/platform/mac/fast/hidpi/image-set-border-image-dynamic-expected.png


(Binary files differ)
Property changes on: trunk/LayoutTests/platform/mac/fast/hidpi/image-set-border-image-dynamic-expected.png ___________________________________________________________________

Added: svn:mime-type

Added: trunk/LayoutTests/platform/mac/fast/hidpi/image-set-border-image-dynamic-expected.txt (0 => 113490)


--- trunk/LayoutTests/platform/mac/fast/hidpi/image-set-border-image-dynamic-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/fast/hidpi/image-set-border-image-dynamic-expected.txt	2012-04-06 20:20:19 UTC (rev 113490)
@@ -0,0 +1,13 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x54
+        RenderText {#text} at (0,0) size 773x54
+          text run at (0,0) width 761: "This test passes if the div below is a blue 100px square when the deviceScaleFactor is 1, and if it is a 100px green square"
+          text run at (0,18) width 773: "when the deviceScaleFactor is 2. When run in the test harness, this test is distinct from image-set-as-background, because it"
+          text run at (0,36) width 492: "ensures that the green image loads dynamically when the scale factor changes."
+      RenderBlock {DIV} at (0,54) size 106x106 [border:]
+        RenderText {#text} at (3,3) size 8x18
+          text run at (3,3) width 8: "2"

Added: trunk/LayoutTests/platform/mac/fast/hidpi/image-set-in-content-dynamic-expected.png


(Binary files differ)
Property changes on: trunk/LayoutTests/platform/mac/fast/hidpi/image-set-in-content-dynamic-expected.png ___________________________________________________________________

Added: svn:mime-type

Added: trunk/LayoutTests/platform/mac/fast/hidpi/image-set-in-content-dynamic-expected.txt (0 => 113490)


--- trunk/LayoutTests/platform/mac/fast/hidpi/image-set-in-content-dynamic-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/fast/hidpi/image-set-in-content-dynamic-expected.txt	2012-04-06 20:20:19 UTC (rev 113490)
@@ -0,0 +1,11 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x54
+        RenderText {#text} at (0,0) size 773x54
+          text run at (0,0) width 761: "This test passes if the div below is a blue 100px square when the deviceScaleFactor is 1, and if it is a 100px green square"
+          text run at (0,18) width 773: "when the deviceScaleFactor is 2. When run in the test harness, this test is distinct from image-set-as-background, because it"
+          text run at (0,36) width 492: "ensures that the green image loads dynamically when the scale factor changes."
+      RenderImage {DIV} at (0,54) size 100x100

Modified: trunk/Source/WebCore/ChangeLog (113489 => 113490)


--- trunk/Source/WebCore/ChangeLog	2012-04-06 20:12:41 UTC (rev 113489)
+++ trunk/Source/WebCore/ChangeLog	2012-04-06 20:20:19 UTC (rev 113490)
@@ -1,3 +1,45 @@
+2012-04-06  Beth Dakin  <[email protected]>
+
+        https://bugs.webkit.org/show_bug.cgi?id=81939
+        -webkit-image-set should update dynamically when the device scale factor 
+        changes
+        -and corresponding-
+        <rdar://problem/11101108> 
+
+        Reviewed by Darin Adler.
+
+        New member variable to keep track of the scale factor.
+        * css/CSSImageSetValue.cpp:
+        (WebCore::CSSImageSetValue::CSSImageSetValue):
+        (WebCore::CSSImageSetValue::bestImageForScaleFactor):
+
+         Merge the two cachedImageSet functions. There was no need for two functions here.
+        (WebCore::CSSImageSetValue::cachedImageSet):
+
+        cachedOrPendingImageSet() now takes a Document as a parameter so that it can 
+        access the deviceScaleFactor. If there is a cached image already and the 
+        Document's deviceScaleFactor doesn't match m_scaleFactor, then m_imageSet is set 
+        to a pending image so that the best fit image will be reassessed and then 
+        loaded.
+        (WebCore::CSSImageSetValue::cachedOrPendingImageSet):
+        * css/CSSImageSetValue.h:
+        (WebCore):
+        (CSSImageSetValue):
+
+        cachedOrPendingImageSet() now takes a Document.
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::collectMatchingRulesForList):
+
+        StyleCachedImageSet should inherit from CachedImageClient just like 
+        StyleCachedImage. It should add and remove itself as a client upon creation 
+        and destruction, respectively.
+        * rendering/style/StyleCachedImageSet.cpp:
+        (WebCore::StyleCachedImageSet::StyleCachedImageSet):
+        (WebCore):
+        (WebCore::StyleCachedImageSet::~StyleCachedImageSet):
+        * rendering/style/StyleCachedImageSet.h:
+        (StyleCachedImageSet):
+
 2012-04-06  Levi Weintraub  <[email protected]>
 
         Update LayoutUnit usage in RenderView

Modified: trunk/Source/WebCore/css/CSSImageSetValue.cpp (113489 => 113490)


--- trunk/Source/WebCore/css/CSSImageSetValue.cpp	2012-04-06 20:12:41 UTC (rev 113489)
+++ trunk/Source/WebCore/css/CSSImageSetValue.cpp	2012-04-06 20:20:19 UTC (rev 113490)
@@ -41,6 +41,7 @@
 CSSImageSetValue::CSSImageSetValue()
     : CSSValueList(ImageSetClass, CommaSeparator)
     , m_accessedBestFitImage(false)
+    , m_scaleFactor(1)
 {
 }
 
@@ -74,13 +75,13 @@
     std::sort(m_imagesInSet.begin(), m_imagesInSet.end(), CSSImageSetValue::compareByScaleFactor);
 }
 
-CSSImageSetValue::ImageWithScale CSSImageSetValue::bestImageForScaleFactor(float scaleFactor)
+CSSImageSetValue::ImageWithScale CSSImageSetValue::bestImageForScaleFactor()
 {
     ImageWithScale image;
     size_t numberOfImages = m_imagesInSet.size();
     for (size_t i = 0; i < numberOfImages; ++i) {
         image = m_imagesInSet.at(i);
-        if (image.scaleFactor >= scaleFactor)
+        if (image.scaleFactor >= m_scaleFactor)
             return image;
     }
     return image;
@@ -88,25 +89,22 @@
 
 StyleCachedImageSet* CSSImageSetValue::cachedImageSet(CachedResourceLoader* loader)
 {
+    ASSERT(loader);
+
     Document* document = loader->document();
-    float deviceScaleFactor = 1;
     if (Page* page = document->page())
-        deviceScaleFactor = page->deviceScaleFactor();
+        m_scaleFactor = page->deviceScaleFactor();
+    else
+        m_scaleFactor = 1;
 
     if (!m_imagesInSet.size())
         fillImageSet();
 
-    // FIXME: In the future, we want to take much more than deviceScaleFactor into acount here. 
-    // All forms of scale should be included: Page::pageScaleFactor(), Frame::pageZoomFactor(), 
-    // and any CSS transforms. https://bugs.webkit.org/show_bug.cgi?id=81698
-    return cachedImageSet(loader, bestImageForScaleFactor(deviceScaleFactor));
-}
-
-StyleCachedImageSet* CSSImageSetValue::cachedImageSet(CachedResourceLoader* loader, ImageWithScale image)
-{
-    ASSERT(loader);
-
     if (!m_accessedBestFitImage) {
+        // FIXME: In the future, we want to take much more than deviceScaleFactor into acount here. 
+        // All forms of scale should be included: Page::pageScaleFactor(), Frame::pageZoomFactor(),
+        // and any CSS transforms. https://bugs.webkit.org/show_bug.cgi?id=81698
+        ImageWithScale image = bestImageForScaleFactor();
         ResourceRequest request(loader->document()->completeURL(image.imageURL));
         if (CachedImage* cachedImage = loader->requestImage(request)) {
             m_imageSet = StyleCachedImageSet::create(cachedImage, image.scaleFactor, this);
@@ -117,11 +115,22 @@
     return (m_imageSet && m_imageSet->isCachedImageSet()) ? static_cast<StyleCachedImageSet*>(m_imageSet.get()) : 0;
 }
 
-StyleImage* CSSImageSetValue::cachedOrPendingImageSet()
+StyleImage* CSSImageSetValue::cachedOrPendingImageSet(Document* document)
 {
     if (!m_imageSet)
         m_imageSet = StylePendingImage::create(this);
+    else if (document && !m_imageSet->isPendingImage()) {
+        float deviceScaleFactor = 1;
+        if (Page* page = document->page())
+            deviceScaleFactor = page->deviceScaleFactor();
 
+        // If the deviceScaleFactor has changed, we may not have the best image loaded, so we have to re-assess.
+        if (deviceScaleFactor != m_scaleFactor) {
+            m_accessedBestFitImage = false;
+            m_imageSet = StylePendingImage::create(this);
+        }
+    }
+
     return m_imageSet.get();
 }
 

Modified: trunk/Source/WebCore/css/CSSImageSetValue.h (113489 => 113490)


--- trunk/Source/WebCore/css/CSSImageSetValue.h	2012-04-06 20:12:41 UTC (rev 113489)
+++ trunk/Source/WebCore/css/CSSImageSetValue.h	2012-04-06 20:20:19 UTC (rev 113490)
@@ -33,6 +33,7 @@
 namespace WebCore {
 
 class CachedResourceLoader;
+class Document;
 class StyleCachedImageSet;
 class StyleImage;
 
@@ -48,7 +49,7 @@
     StyleCachedImageSet* cachedImageSet(CachedResourceLoader*);
 
     // Returns a StyleCachedImageSet if the best fit image has been cached already, otherwise a StylePendingImage.
-    StyleImage* cachedOrPendingImageSet();
+    StyleImage* cachedOrPendingImageSet(Document*);
 
     String customCssText() const;
 
@@ -60,8 +61,7 @@
     };
 
 protected:
-    ImageWithScale bestImageForScaleFactor(float);
-    StyleCachedImageSet* cachedImageSet(CachedResourceLoader*, ImageWithScale);
+    ImageWithScale bestImageForScaleFactor();
 
 private:
     CSSImageSetValue();
@@ -72,6 +72,10 @@
     RefPtr<StyleImage> m_imageSet;
     bool m_accessedBestFitImage;
 
+    // This represents the scale factor that we used to find the best fit image. It does not necessarily
+    // correspond to the scale factor of the best fit image.
+    float m_scaleFactor;
+
     Vector<ImageWithScale> m_imagesInSet;
 };
 

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (113489 => 113490)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2012-04-06 20:12:41 UTC (rev 113489)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2012-04-06 20:20:19 UTC (rev 113490)
@@ -4243,7 +4243,7 @@
 #if ENABLE(CSS_IMAGE_SET)
 PassRefPtr<StyleImage> CSSStyleSelector::setOrPendingFromValue(CSSPropertyID property, CSSImageSetValue* value)
 {
-    RefPtr<StyleImage> image = value->cachedOrPendingImageSet();
+    RefPtr<StyleImage> image = value->cachedOrPendingImageSet(document());
     if (image && image->isPendingImage())
         m_pendingImageProperties.add(property);
     return image.release();

Modified: trunk/Source/WebCore/rendering/style/StyleCachedImageSet.cpp (113489 => 113490)


--- trunk/Source/WebCore/rendering/style/StyleCachedImageSet.cpp	2012-04-06 20:12:41 UTC (rev 113489)
+++ trunk/Source/WebCore/rendering/style/StyleCachedImageSet.cpp	2012-04-06 20:20:19 UTC (rev 113490)
@@ -40,8 +40,15 @@
     , m_imageSetValue(value)  
 {
     m_isCachedImageSet = true;
+    m_bestFitImage->addClient(this);
 }
 
+
+StyleCachedImageSet::~StyleCachedImageSet()
+{
+    m_bestFitImage->removeClient(this);
+}
+
 PassRefPtr<CSSValue> StyleCachedImageSet::cssValue() const
 {
     return m_imageSetValue;

Modified: trunk/Source/WebCore/rendering/style/StyleCachedImageSet.h (113489 => 113490)


--- trunk/Source/WebCore/rendering/style/StyleCachedImageSet.h	2012-04-06 20:12:41 UTC (rev 113489)
+++ trunk/Source/WebCore/rendering/style/StyleCachedImageSet.h	2012-04-06 20:20:19 UTC (rev 113490)
@@ -28,6 +28,7 @@
 
 #if ENABLE(CSS_IMAGE_SET)
 
+#include "CachedImage.h"
 #include "CachedResourceHandle.h"
 #include "StyleImage.h"
 
@@ -38,12 +39,14 @@
 
 // This class keeps one cached image and has access to a set of alternatives.
 
-class StyleCachedImageSet : public StyleImage {
+class StyleCachedImageSet : public StyleImage, private CachedImageClient {
+    WTF_MAKE_FAST_ALLOCATED;
 public:
     static PassRefPtr<StyleCachedImageSet> create(CachedImage* image, float imageScaleFactor, CSSImageSetValue* value)
     {
         return adoptRef(new StyleCachedImageSet(image, imageScaleFactor, value));
     }
+    virtual ~StyleCachedImageSet();
 
     virtual PassRefPtr<CSSValue> cssValue() const;
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to