Example #1
0
StyleImage* CSSCursorImageValue::cacheImage(const Document& document,
                                            float deviceScaleFactor) {
  if (m_imageValue->isImageSetValue())
    return toCSSImageSetValue(*m_imageValue)
        .cacheImage(document, deviceScaleFactor);

  if (m_isCachePending) {
    m_isCachePending = false;

    // 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 (hasFragmentInURL()) {
      CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get());
      // FIXME: This will fail if the <cursor> element is in a shadow DOM
      // (http://crbug/59827)
      if (SVGCursorElement* cursorElement =
              resourceReferencedByCursorElement(imageValue->url(), document)) {
        CSSImageValue* svgImageValue =
            CSSImageValue::create(document.completeURL(
                cursorElement->href()->currentValue()->value()));
        svgImageValue->setReferrer(imageValue->referrer());
        m_cachedImage = svgImageValue->cacheImage(document);
        return m_cachedImage.get();
      }
    }

    if (m_imageValue->isImageValue())
      m_cachedImage = toCSSImageValue(*m_imageValue).cacheImage(document);
  }

  if (m_cachedImage && m_cachedImage->isImageResource())
    return toStyleFetchedImage(m_cachedImage);
  return nullptr;
}