Esempio n. 1
0
StyleImage* CSSCursorImageValue::cachedImage(CachedResourceLoader* loader)
{
#if ENABLE(CSS_IMAGE_SET)
    if (m_imageValue.get().isImageSetValue())
        return toCSSImageSetValue(m_imageValue.get()).cachedImageSet(loader);
#endif

    if (!m_accessedImage) {
        m_accessedImage = true;

        // For SVG images we need to lazily substitute in the correct URL. Rather than attempt
        // to change the URL of the CSSImageValue (which would then change behavior like cssText),
        // we create an alternate CSSImageValue to use.
        if (isSVGCursor() && loader && loader->document()) {
            // FIXME: This will fail if the <cursor> element is in a shadow DOM (bug 59827)
            if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(toCSSImageValue(m_imageValue.get()).url(), *loader->document())) {
                detachPendingImage();
                Ref<CSSImageValue> svgImageValue(CSSImageValue::create(cursorElement->href()));
                StyleCachedImage* cachedImage = svgImageValue->cachedImage(loader);
                m_image = cachedImage;
                return cachedImage;
            }
        }

        if (m_imageValue.get().isImageValue()) {
            detachPendingImage();
            m_image = toCSSImageValue(m_imageValue.get()).cachedImage(loader);
        }
    }

    if (m_image && m_image->isCachedImage())
        return static_cast<StyleCachedImage*>(m_image.get());

    return 0;
}
CSSImageSetValue::~CSSImageSetValue()
{
    detachPendingImage();

    if (is<StyleCachedImage>(m_image.get()))
        downcast<StyleCachedImage>(*m_image).detachFromCSSValue();
}
StyleCachedImage* CSSImageSetValue::bestFitImage(CachedResourceLoader& loader, const ResourceLoaderOptions& options)
{
    Document* document = loader.document();
    if (Page* page = document->page())
        m_scaleFactor = page->deviceScaleFactor();
    else
        m_scaleFactor = 1;

    if (!m_imagesInSet.size())
        fillImageSet();

    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();
        CachedResourceRequest request(ResourceRequest(document->completeURL(image.imageURL)), options);
        request.setInitiator(cachedResourceRequestInitiators().css);
        if (options.mode == FetchOptions::Mode::Cors) {
            ASSERT(document->securityOrigin());
            updateRequestForAccessControl(request.mutableResourceRequest(), *document->securityOrigin(), options.allowCredentials);
        }
        if (CachedResourceHandle<CachedImage> cachedImage = loader.requestImage(request)) {
            detachPendingImage();
            m_image = StyleCachedImage::createForImageSet(cachedImage.get(), image.scaleFactor, *this);
            m_accessedBestFitImage = true;
        }
    }

    return is<StyleCachedImage>(m_image.get()) ? downcast<StyleCachedImage>(m_image.get()) : nullptr;
}
Esempio n. 4
0
CSSImageSetValue::~CSSImageSetValue()
{
    detachPendingImage();

    if (m_imageSet && m_imageSet->isCachedImageSet())
        toStyleCachedImageSet(*m_imageSet).clearImageSetValue();
}
Esempio n. 5
0
StyleCachedImageSet* CSSImageSetValue::cachedImageSet(CachedResourceLoader* loader, const ResourceLoaderOptions& options)
{
    ASSERT(loader);

    Document* document = loader->document();
    if (Page* page = document->page())
        m_scaleFactor = page->deviceScaleFactor();
    else
        m_scaleFactor = 1;

    if (!m_imagesInSet.size())
        fillImageSet();

    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();
        CachedResourceRequest request(ResourceRequest(document->completeURL(image.imageURL)), options);
        request.setInitiator(cachedResourceRequestInitiators().css);
        if (options.requestOriginPolicy() == PotentiallyCrossOriginEnabled)
            updateRequestForAccessControl(request.mutableResourceRequest(), document->securityOrigin(), options.allowCredentials());
        if (CachedResourceHandle<CachedImage> cachedImage = loader->requestImage(request)) {
            detachPendingImage();
            m_imageSet = StyleCachedImageSet::create(cachedImage.get(), image.scaleFactor, this);
            m_accessedBestFitImage = true;
        }
    }

    return (m_imageSet && m_imageSet->isCachedImageSet()) ? toStyleCachedImageSet(m_imageSet.get()) : nullptr;
}
CSSImageSetValue::~CSSImageSetValue()
{
    detachPendingImage();

    if (m_imageSet && m_imageSet->isCachedImageSet())
        static_cast<StyleCachedImageSet*>(m_imageSet.get())->clearImageSetValue();
}
StyleCachedImageSet* CSSImageSetValue::cachedImageSet(CachedResourceLoader* loader)
{
    ASSERT(loader);

    Document* document = loader->document();
    if (Page* page = document->page())
        m_scaleFactor = page->deviceScaleFactor();
    else
        m_scaleFactor = 1;

    if (!m_imagesInSet.size())
        fillImageSet();

    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();
        CachedResourceRequest request(ResourceRequest(document->completeURL(image.imageURL)));
        request.setInitiator(cachedResourceRequestInitiators().css);
        if (CachedResourceHandle<CachedImage> cachedImage = loader->requestImage(request)) {
            detachPendingImage();
            m_imageSet = StyleCachedImageSet::create(cachedImage.get(), image.scaleFactor, this);
            m_accessedBestFitImage = true;
        }
    }

    return (m_imageSet && m_imageSet->isCachedImageSet()) ? static_cast<StyleCachedImageSet*>(m_imageSet.get()) : 0;
}
Esempio n. 8
0
CSSCursorImageValue::~CSSCursorImageValue()
{
    detachPendingImage();

    if (!isSVGCursor())
        return;

    HashSet<SVGElement*>::const_iterator it = m_referencedElements.begin();
    HashSet<SVGElement*>::const_iterator end = m_referencedElements.end();

    for (; it != end; ++it) {
        SVGElement* referencedElement = *it;
        referencedElement->cursorImageValueRemoved();
        if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(toCSSImageValue(m_imageValue.get()).url(), referencedElement->document()))
            cursorElement->removeClient(referencedElement);
    }
}
CSSCursorImageValue::~CSSCursorImageValue()
{
    detachPendingImage();

#if ENABLE(SVG)
    if (!isSVGCursor())
        return;

    HashSet<SVGElement*>::const_iterator it = m_referencedElements.begin();
    HashSet<SVGElement*>::const_iterator end = m_referencedElements.end();
    String url = static_cast<CSSImageValue*>(m_imageValue.get())->url();

    for (; it != end; ++it) {
        SVGElement* referencedElement = *it;
        referencedElement->cursorImageValueRemoved();
        if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url, referencedElement->document()))
            cursorElement->removeClient(referencedElement);
    }
#endif
}
Esempio n. 10
0
StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader* loader, const ResourceLoaderOptions& options)
{
    ASSERT(loader);

    if (!m_accessedImage) {
        m_accessedImage = true;

        CachedResourceRequest request(ResourceRequest(loader->document()->completeURL(m_url)), options);
        if (m_initiatorName.isEmpty())
            request.setInitiator(cachedResourceRequestInitiators().css);
        else
            request.setInitiator(m_initiatorName);
        if (CachedResourceHandle<CachedImage> cachedImage = loader->requestImage(request)) {
            detachPendingImage();
            m_image = StyleCachedImage::create(cachedImage.get());
        }
    }

    return (m_image && m_image->isCachedImage()) ? static_cast<StyleCachedImage*>(m_image.get()) : 0;
}
Esempio n. 11
0
StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader* loader, const ResourceLoaderOptions& options)
{
    ASSERT(loader);

    if (!m_accessedImage) {
        m_accessedImage = true;

        CachedResourceRequest request(ResourceRequest(loader->document()->completeURL(m_url)), options);
        if (m_initiatorName.isEmpty())
            request.setInitiator(cachedResourceRequestInitiators().css);
        else
            request.setInitiator(m_initiatorName);

        if (options.requestOriginPolicy() == PotentiallyCrossOriginEnabled)
            updateRequestForAccessControl(request.mutableResourceRequest(), loader->document()->securityOrigin(), options.allowCredentials());

        if (CachedResourceHandle<CachedImage> cachedImage = loader->requestImage(request)) {
            detachPendingImage();
            m_image = StyleCachedImage::create(cachedImage.get());
        }
    }

    return (m_image && m_image->isCachedImage()) ? toStyleCachedImage(m_image.get()) : nullptr;
}
Esempio n. 12
0
void CSSCursorImageValue::clearCachedImage()
{
    detachPendingImage();
    m_image.clear();
    m_accessedImage = false;
}
Esempio n. 13
0
CSSImageValue::~CSSImageValue()
{
    detachPendingImage();
}