⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 195401 in webkit


Ignore:
Timestamp:
Jan 20, 2016, 11:16:57 PM (11 years ago)
Author:
bshafiei@apple.com
Message:

Merged r195132. rdar://problem/24154424

Location:
branches/safari-601.1.46-branch/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-601.1.46-branch/Source/WebCore/ChangeLog

    r195400 r195401  
     12016-01-20  Babak Shafiei  <bshafiei@apple.com>
     2
     3        Merge r195132.
     4
     5    2016-01-15  Dave Hyatt  <hyatt@apple.com>
     6
     7            Avoid downloading the wrong image for <picture> elements.
     8            https://bugs.webkit.org/show_bug.cgi?id=153027
     9
     10            Reviewed by Dean Jackson.
     11
     12            No tests, since they are always flaky.
     13
     14            * html/HTMLImageElement.cpp:
     15            (WebCore::HTMLImageElement::HTMLImageElement):
     16            (WebCore::HTMLImageElement::~HTMLImageElement):
     17            (WebCore::HTMLImageElement::createForJSConstructor):
     18            (WebCore::HTMLImageElement::bestFitSourceFromPictureElement):
     19            (WebCore::HTMLImageElement::insertedInto):
     20            (WebCore::HTMLImageElement::removedFrom):
     21            (WebCore::HTMLImageElement::pictureElement):
     22            (WebCore::HTMLImageElement::setPictureElement):
     23            (WebCore::HTMLImageElement::width):
     24            * html/HTMLImageElement.h:
     25            (WebCore::HTMLImageElement::hasShadowControls):
     26            * html/HTMLPictureElement.h:
     27            * html/parser/HTMLConstructionSite.cpp:
     28            (WebCore::HTMLConstructionSite::createHTMLElement):
     29            * html/parser/HTMLPreloadScanner.cpp:
     30            (WebCore::TokenPreloadScanner::StartTagScanner::processAttribute):
     31
     32            Images that are built underneath a <picture> element are now connected
     33            to that picture element via a setPictureNode call from the parser. This
     34            ensures that the correct <source> elements are examined before checking the image.
     35
     36            This connection between images and their picture owners is handled using a static
     37            HashMap in HTMLImageElement. This connection is made both from the parser and from
     38            DOM insertions, and the map is queried now instead of looking directly at the
     39            image's parentNode().
     40
    1412016-01-20  Babak Shafiei  <bshafiei@apple.com>
    242
  • branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.cpp

    r193952 r195401  
    5454using namespace HTMLNames;
    5555
     56typedef HashMap<const HTMLImageElement*, WeakPtr<HTMLPictureElement>> PictureOwnerMap;
     57static PictureOwnerMap* gPictureOwnerMap = nullptr;
     58
    5659HTMLImageElement::HTMLImageElement(const QualifiedName& tagName, Document& document, HTMLFormElement* form)
    5760    : HTMLElement(tagName, document)
     
    8487    if (m_form)
    8588        m_form->removeImgElement(this);
     89    setPictureElement(nullptr);
    8690}
    8791
     
    144148ImageCandidate HTMLImageElement::bestFitSourceFromPictureElement()
    145149{
    146     auto* parent = parentNode();
    147     if (!is<HTMLPictureElement>(parent))
     150    auto* picture = pictureElement();
     151    if (!picture)
    148152        return { };
    149     auto* picture = downcast<HTMLPictureElement>(parent);
    150153    picture->clearViewportDependentResults();
    151154    document().removeViewportDependentPicture(*picture);
    152     for (Node* child = parent->firstChild(); child && child != this; child = child->nextSibling()) {
     155    for (Node* child = picture->firstChild(); child && child != this; child = child->nextSibling()) {
    153156        if (!is<HTMLSourceElement>(*child))
    154157            continue;
     
    167170                continue;
    168171        }
    169         MediaQueryEvaluator evaluator(document().printing() ? "print" : "screen", document().frame(), computedStyle());
     172        MediaQueryEvaluator evaluator(document().printing() ? "print" : "screen", document().frame(), document().documentElement() ? document().documentElement()->computedStyle() : nullptr);
    170173        bool evaluation = evaluator.evalCheckingViewportDependentResults(source.mediaQuerySet(), picture->viewportDependentResults());
    171174        if (picture->hasViewportDependentResults())
     
    312315        document().addImageElementByLowercasedUsemap(*m_lowercasedUsemap.impl(), *this);
    313316   
    314     if (is<HTMLPictureElement>(parentNode()))
     317    if (is<HTMLPictureElement>(parentNode())) {
     318        setPictureElement(&downcast<HTMLPictureElement>(*parentNode()));
    315319        selectImageSource();
    316    
     320    }
     321
    317322    // If we have been inserted from a renderer-less document,
    318323    // our loader may have not fetched the image, so do it now.
     
    330335    if (insertionPoint.inDocument() && !m_lowercasedUsemap.isNull())
    331336        document().removeImageElementByLowercasedUsemap(*m_lowercasedUsemap.impl(), *this);
    332 
     337   
     338    if (is<HTMLPictureElement>(parentNode()))
     339        setPictureElement(nullptr);
     340   
    333341    m_form = 0;
    334342    HTMLElement::removedFrom(insertionPoint);
    335343}
    336344
     345HTMLPictureElement* HTMLImageElement::pictureElement() const
     346{
     347    if (!gPictureOwnerMap || !gPictureOwnerMap->contains(this))
     348        return nullptr;
     349    HTMLPictureElement* result = gPictureOwnerMap->get(this).get();
     350    if (!result)
     351        gPictureOwnerMap->remove(this);
     352    return result;
     353}
     354   
     355void HTMLImageElement::setPictureElement(HTMLPictureElement* pictureElement)
     356{
     357    if (!pictureElement) {
     358        if (gPictureOwnerMap)
     359            gPictureOwnerMap->remove(this);
     360        return;
     361    }
     362   
     363    if (!gPictureOwnerMap)
     364        gPictureOwnerMap = new PictureOwnerMap();
     365    gPictureOwnerMap->add(this, pictureElement->createWeakPtr());
     366}
     367   
    337368int HTMLImageElement::width(bool ignorePendingStylesheets)
    338369{
  • branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.h

    r193565 r195401  
    9090
    9191    bool hasShadowControls() const { return m_experimentalImageMenuEnabled; }
     92   
     93    HTMLPictureElement* pictureElement() const;
     94    void setPictureElement(HTMLPictureElement*);
    9295
    9396protected:
     
    129132    HTMLImageLoader m_imageLoader;
    130133    HTMLFormElement* m_form;
     134
    131135    CompositeOperator m_compositeOperator;
    132136    AtomicString m_bestFitImageURL;
  • branches/safari-601.1.46-branch/Source/WebCore/html/HTMLPictureElement.h

    r193952 r195401  
    4747    bool viewportChangeAffectedPicture();
    4848
     49    WeakPtr<HTMLPictureElement> createWeakPtr() { return m_weakFactory.createWeakPtr(); }
     50
    4951private:
    5052    HTMLPictureElement(const QualifiedName&, Document&);
    5153   
     54    WeakPtrFactory<HTMLPictureElement> m_weakFactory { this };
    5255    Vector<std::unique_ptr<MediaQueryResult>> m_viewportDependentMediaQueryResults;
    5356
  • branches/safari-601.1.46-branch/Source/WebCore/html/parser/HTMLConstructionSite.cpp

    r177952 r195401  
    3737#include "HTMLFormElement.h"
    3838#include "HTMLHtmlElement.h"
     39#include "HTMLImageElement.h"
    3940#include "HTMLOptGroupElement.h"
    4041#include "HTMLOptionElement.h"
    4142#include "HTMLParserIdioms.h"
     43#include "HTMLPictureElement.h"
    4244#include "HTMLScriptElement.h"
    4345#include "HTMLTemplateElement.h"
     
    642644    bool insideTemplateElement = !ownerDocument.frame();
    643645    RefPtr<Element> element = HTMLElementFactory::createElement(tagName, ownerDocument, insideTemplateElement ? nullptr : form(), true);
     646   
     647    // FIXME: This is a hack to connect images to pictures before the image has
     648    // been inserted into the document. It can be removed once asynchronous image
     649    // loading is working.
     650    if (is<HTMLPictureElement>(currentNode()) && is<HTMLImageElement>(*element.get()))
     651        downcast<HTMLImageElement>(*element.get()).setPictureElement(&downcast<HTMLPictureElement>(currentNode()));
     652
    644653    setAttributes(element.get(), token, m_parserContentPolicy);
    645654    ASSERT(element->isHTMLElement());
  • branches/safari-601.1.46-branch/Source/WebCore/html/parser/HTMLPreloadScanner.cpp

    r194992 r195401  
    209209                Ref<MediaQuerySet> mediaSet = MediaQuerySet::createAllowingDescriptionSyntax(attributeValue);
    210210                Vector<std::unique_ptr<MediaQueryResult>> viewportDependentMediaQueryResults;
    211                 MediaQueryEvaluator evaluator(document.printing() ? "print" : "screen", document.frame(), document.documentElement()->computedStyle());
     211                MediaQueryEvaluator evaluator(document.printing() ? "print" : "screen", document.frame(), document.documentElement() ? document.documentElement()->computedStyle() : nullptr);
    212212                m_mediaMatched = evaluator.evalCheckingViewportDependentResults(mediaSet.ptr(), viewportDependentMediaQueryResults);
    213213            }
Note: See TracChangeset for help on using the changeset viewer.