Changeset 194865 in webkit


Ignore:
Timestamp:
Jan 11, 2016 1:49:20 PM (8 years ago)
Author:
hyatt@apple.com
Message:

Picture element needs to work with the preload scanner and select the correct
source element instead of loading the image.
https://bugs.webkit.org/show_bug.cgi?id=152983

Reviewed by Dean Jackson.

Source/WebCore:

Added new tests in http/tests/loading.

  • html/parser/HTMLPreloadScanner.cpp:

(WebCore::TokenPreloadScanner::tagIdFor):
(WebCore::TokenPreloadScanner::initiatorFor):
(WebCore::TokenPreloadScanner::StartTagScanner::StartTagScanner):
(WebCore::TokenPreloadScanner::StartTagScanner::processAttributes):
(WebCore::TokenPreloadScanner::StartTagScanner::processImageAndScriptAttribute):
(WebCore::TokenPreloadScanner::StartTagScanner::processAttribute):
(WebCore::TokenPreloadScanner::StartTagScanner::resourceType):
(WebCore::TokenPreloadScanner::scan):

  • html/parser/HTMLPreloadScanner.h:

(WebCore::TokenPreloadScanner::setPredictedBaseElementURL):
(WebCore::TokenPreloadScanner::inPicture):

LayoutTests:

These tests are imported from Blink, although they have been modified slightly to
reflect the fact that we pass the nested <picture> cases that Blink fails.

  • http/tests/loading/hidpi-preload-picture-sizes-expected.txt: Added.
  • http/tests/loading/hidpi-preload-picture-sizes.html: Added.
  • http/tests/loading/preload-picture-invalid-expected.txt: Added.
  • http/tests/loading/preload-picture-invalid.html: Added.
  • http/tests/loading/preload-picture-nested-expected.txt: Added.
  • http/tests/loading/preload-picture-nested.html: Added.
  • http/tests/loading/preload-picture-sizes-expected.txt: Added.
  • http/tests/loading/preload-picture-sizes.html: Added.
  • http/tests/loading/resources/base-image1.png: Added.
  • http/tests/loading/resources/base-image2.png: Added.
  • http/tests/loading/resources/base-image3.png: Added.
  • http/tests/loading/resources/dup-image1.png: Added.
  • http/tests/loading/resources/dup-image2.png: Added.
  • http/tests/loading/resources/dup-image3.png: Added.
  • http/tests/loading/resources/image1.png: Added.
  • http/tests/loading/resources/image2.png: Added.
  • http/tests/loading/resources/picture-preload-helper.js: Added.
Location:
trunk
Files:
17 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r194864 r194865  
     12016-01-11  Dave Hyatt  <hyatt@apple.com>
     2
     3        Picture element needs to work with the preload scanner and select the correct
     4        source element instead of loading the image.
     5        https://bugs.webkit.org/show_bug.cgi?id=152983
     6
     7        Reviewed by Dean Jackson.
     8
     9        These tests are imported from Blink, although they have been modified slightly to
     10        reflect the fact that we pass the nested <picture> cases that Blink fails.
     11
     12        * http/tests/loading/hidpi-preload-picture-sizes-expected.txt: Added.
     13        * http/tests/loading/hidpi-preload-picture-sizes.html: Added.
     14        * http/tests/loading/preload-picture-invalid-expected.txt: Added.
     15        * http/tests/loading/preload-picture-invalid.html: Added.
     16        * http/tests/loading/preload-picture-nested-expected.txt: Added.
     17        * http/tests/loading/preload-picture-nested.html: Added.
     18        * http/tests/loading/preload-picture-sizes-expected.txt: Added.
     19        * http/tests/loading/preload-picture-sizes.html: Added.
     20        * http/tests/loading/resources/base-image1.png: Added.
     21        * http/tests/loading/resources/base-image2.png: Added.
     22        * http/tests/loading/resources/base-image3.png: Added.
     23        * http/tests/loading/resources/dup-image1.png: Added.
     24        * http/tests/loading/resources/dup-image2.png: Added.
     25        * http/tests/loading/resources/dup-image3.png: Added.
     26        * http/tests/loading/resources/image1.png: Added.
     27        * http/tests/loading/resources/image2.png: Added.
     28        * http/tests/loading/resources/picture-preload-helper.js: Added.
     29
    1302016-01-11  Brady Eidson  <beidson@apple.com>
    231
  • trunk/Source/WebCore/ChangeLog

    r194864 r194865  
     12016-01-11  Dave Hyatt  <hyatt@apple.com>
     2
     3        Picture element needs to work with the preload scanner and select the correct
     4        source element instead of loading the image.
     5        https://bugs.webkit.org/show_bug.cgi?id=152983
     6
     7        Reviewed by Dean Jackson.
     8
     9        Added new tests in http/tests/loading.
     10
     11        * html/parser/HTMLPreloadScanner.cpp:
     12        (WebCore::TokenPreloadScanner::tagIdFor):
     13        (WebCore::TokenPreloadScanner::initiatorFor):
     14        (WebCore::TokenPreloadScanner::StartTagScanner::StartTagScanner):
     15        (WebCore::TokenPreloadScanner::StartTagScanner::processAttributes):
     16        (WebCore::TokenPreloadScanner::StartTagScanner::processImageAndScriptAttribute):
     17        (WebCore::TokenPreloadScanner::StartTagScanner::processAttribute):
     18        (WebCore::TokenPreloadScanner::StartTagScanner::resourceType):
     19        (WebCore::TokenPreloadScanner::scan):
     20        * html/parser/HTMLPreloadScanner.h:
     21        (WebCore::TokenPreloadScanner::setPredictedBaseElementURL):
     22        (WebCore::TokenPreloadScanner::inPicture):
     23
    1242016-01-11  Brady Eidson  <beidson@apple.com>
    225
  • trunk/Source/WebCore/html/parser/HTMLPreloadScanner.cpp

    r194496 r194865  
    3535#include "InputTypeNames.h"
    3636#include "LinkRelAttribute.h"
     37#include "MediaList.h"
     38#include "MediaQueryEvaluator.h"
    3739#include "SourceSizeList.h"
    3840#include <wtf/MainThread.h>
     
    6365    if (tagName == metaTag)
    6466        return TagId::Meta;
     67    if (tagName == pictureTag)
     68        return TagId::Picture;
     69    if (tagName == sourceTag)
     70        return TagId::Source;
    6571    return TagId::Unknown;
    6672}
     
    7177    case TagId::Iframe:
    7278        return "iframe";
     79    case TagId::Source:
    7380    case TagId::Img:
    7481        return "img";
     
    8491    case TagId::Template:
    8592    case TagId::Meta:
     93    case TagId::Picture:
    8694        ASSERT_NOT_REACHED();
    8795        return "unknown";
     
    102110    }
    103111
    104     void processAttributes(const HTMLToken::AttributeList& attributes, Document& document)
     112    void processAttributes(const HTMLToken::AttributeList& attributes, Document& document, Vector<bool>& pictureState)
    105113    {
    106114        ASSERT(isMainThread());
    107115        if (m_tagId >= TagId::Unknown)
    108116            return;
    109 
     117       
    110118        for (auto& attribute : attributes) {
    111119            AtomicString attributeName(attribute.name);
    112120            String attributeValue = StringImpl::create8BitIfPossible(attribute.value);
    113             processAttribute(attributeName, attributeValue);
    114         }
    115 
     121            processAttribute(attributeName, attributeValue, document, pictureState);
     122        }
     123       
     124        if (m_tagId == TagId::Source && !pictureState.isEmpty() && !pictureState.last() && m_mediaMatched && !m_srcSetAttribute.isEmpty()) {
     125            float sourceSize = parseSizesAttribute(m_sizesAttribute, document.renderView(), document.frame());
     126            ImageCandidate imageCandidate = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute, sourceSize);
     127            if (!imageCandidate.isEmpty()) {
     128                pictureState.last() = true;
     129                setUrlToLoad(imageCandidate.string.toString(), true);
     130            }
     131        }
     132       
    116133        // Resolve between src and srcSet if we have them and the tag is img.
    117134        if (m_tagId == TagId::Img && !m_srcSetAttribute.isEmpty()) {
    118             float sourceSize = 0;
    119             sourceSize = parseSizesAttribute(m_sizesAttribute, document.renderView(), document.frame());
     135            float sourceSize = parseSizesAttribute(m_sizesAttribute, document.renderView(), document.frame());
    120136            ImageCandidate imageCandidate = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute, sourceSize);
    121137            setUrlToLoad(imageCandidate.string.toString(), true);
     
    155171    }
    156172
    157     void processAttribute(const AtomicString& attributeName, const String& attributeValue)
    158     {
     173    void processAttribute(const AtomicString& attributeName, const String& attributeValue, Document& document, const Vector<bool>& pictureState)
     174    {
     175        bool inPicture = !pictureState.isEmpty();
     176        bool alreadyMatchedSource = inPicture && pictureState.last();
     177
    159178        switch (m_tagId) {
    160179        case TagId::Iframe:
     
    163182            break;
    164183        case TagId::Img:
     184            if (inPicture && alreadyMatchedSource)
     185                break;
    165186            if (match(attributeName, srcsetAttr) && m_srcSetAttribute.isNull()) {
    166187                m_srcSetAttribute = attributeValue;
     
    172193            }
    173194            processImageAndScriptAttribute(attributeName, attributeValue);
     195            break;
     196        case TagId::Source:
     197            if (inPicture && alreadyMatchedSource)
     198                break;
     199            if (match(attributeName, srcsetAttr) && m_srcSetAttribute.isNull()) {
     200                m_srcSetAttribute = attributeValue;
     201                break;
     202            }
     203            if (match(attributeName, sizesAttr) && m_sizesAttribute.isNull()) {
     204                m_sizesAttribute = attributeValue;
     205                break;
     206            }
     207            if (match(attributeName, mediaAttr) && m_mediaAttribute.isNull()) {
     208                m_mediaAttribute = attributeValue;
     209                Ref<MediaQuerySet> mediaSet = MediaQuerySet::createAllowingDescriptionSyntax(attributeValue);
     210                Vector<std::unique_ptr<MediaQueryResult>> viewportDependentMediaQueryResults;
     211                MediaQueryEvaluator evaluator(document.printing() ? "print" : "screen", document.frame(), document.documentElement()->computedStyle());
     212                m_mediaMatched = evaluator.evalCheckingViewportDependentResults(mediaSet.ptr(), viewportDependentMediaQueryResults);
     213            }
    174214            break;
    175215        case TagId::Script:
     
    201241        case TagId::Style:
    202242        case TagId::Template:
     243        case TagId::Picture:
    203244        case TagId::Unknown:
    204245            break;
     
    238279        case TagId::Img:
    239280        case TagId::Input:
     281        case TagId::Source:
    240282            ASSERT(m_tagId != TagId::Input || m_inputIsImage);
    241283            return CachedResource::ImageResource;
     
    248290        case TagId::Base:
    249291        case TagId::Template:
     292        case TagId::Picture:
    250293            break;
    251294        }
     
    280323    String m_srcSetAttribute;
    281324    String m_sizesAttribute;
     325    bool m_mediaMatched { true };
    282326    String m_charset;
    283327    String m_crossOriginMode;
     
    318362                m_cssScanner.reset();
    319363            m_inStyle = false;
    320         }
     364        } else if (tagId == TagId::Picture && !m_pictureSourceState.isEmpty())
     365            m_pictureSourceState.removeLast();
     366
    321367        return;
    322368    }
     
    345391            return;
    346392        }
     393        if (tagId == TagId::Picture) {
     394            m_pictureSourceState.append(false);
     395            return;
     396        }
    347397
    348398        StartTagScanner scanner(tagId, m_deviceScaleFactor);
    349         scanner.processAttributes(token.attributes(), document);
     399        scanner.processAttributes(token.attributes(), document, m_pictureSourceState);
    350400        if (auto request = scanner.createPreloadRequest(m_predictedBaseElementURL))
    351401            requests.append(WTFMove(request));
  • trunk/Source/WebCore/html/parser/HTMLPreloadScanner.h

    r191180 r194865  
    4242
    4343    void setPredictedBaseElementURL(const URL& url) { m_predictedBaseElementURL = url; }
     44   
     45    bool inPicture() { return !m_pictureSourceState.isEmpty(); }
    4446
    4547private:
     
    5254        Script,
    5355        Meta,
     56        Source,
    5457
    5558        // These tags are not scanned by the StartTagScanner.
     
    5861        Base,
    5962        Template,
     63        Picture
    6064    };
    6165
     
    7478    URL m_predictedBaseElementURL;
    7579    bool m_inStyle { false };
     80   
     81    Vector<bool> m_pictureSourceState;
     82
    7683#if ENABLE(TEMPLATE_ELEMENT)
    7784    unsigned m_templateCount { 0 };
Note: See TracChangeset for help on using the changeset viewer.