PassRefPtr<StyleImage> StyleResourceLoader::loadPendingImage(StylePendingImage* pendingImage, float deviceScaleFactor)
{
    if (pendingImage->cssImageValue()) {
        CSSImageValue* imageValue = pendingImage->cssImageValue();
        return imageValue->cachedImage(m_fetcher);
    }

    if (pendingImage->cssImageGeneratorValue()) {
        CSSImageGeneratorValue* imageGeneratorValue = pendingImage->cssImageGeneratorValue();
        imageGeneratorValue->loadSubimages(m_fetcher);
        return StyleGeneratedImage::create(imageGeneratorValue);
    }

    if (pendingImage->cssCursorImageValue()) {
        CSSCursorImageValue* cursorImageValue = pendingImage->cssCursorImageValue();
        return cursorImageValue->cachedImage(m_fetcher, deviceScaleFactor);
    }

    if (pendingImage->cssImageSetValue()) {
        CSSImageSetValue* imageSetValue = pendingImage->cssImageSetValue();
        return imageSetValue->cachedImageSet(m_fetcher, deviceScaleFactor);
    }

    return 0;
}
Пример #2
0
void PageSerializer::retrieveResourcesForCSSDeclaration(StylePropertySet* styleDeclaration, Document* document)
{
    if (!styleDeclaration)
        return;

    // The background-image and list-style-image (for ul or ol) are the CSS properties
    // that make use of images. We iterate to make sure we include any other
    // image properties there might be.
    unsigned propertyCount = styleDeclaration->propertyCount();
    for (unsigned i = 0; i < propertyCount; ++i) {
        RefPtr<CSSValue> cssValue = styleDeclaration->propertyAt(i).value();
        if (!cssValue->isImageValue())
            continue;

        CSSImageValue* imageValue = static_cast<CSSImageValue*>(cssValue.get());
        StyleImage* styleImage = imageValue->cachedOrPendingImage();
        // Non cached-images are just place-holders and do not contain data.
        if (!styleImage || !styleImage->isCachedImage())
            continue;

        CachedImage* image = static_cast<StyleCachedImage*>(styleImage)->cachedImage();

        KURL url = document->completeURL(image->url());
        addImageToResources(image, 0, url);
    }
}
Пример #3
0
void PageSerializer::retrieveResourcesForCSSDeclaration(CSSStyleDeclaration* styleDeclaration)
{
    if (!styleDeclaration)
        return;

    if (!styleDeclaration->stylesheet()->isCSSStyleSheet())
        return;

    CSSStyleSheet* cssStyleSheet = static_cast<CSSStyleSheet*>(styleDeclaration->stylesheet());

    // The background-image and list-style-image (for ul or ol) are the CSS properties
    // that make use of images. We iterate to make sure we include any other
    // image properties there might be.
    for (unsigned i = 0; i < styleDeclaration->length(); ++i) {
        // FIXME: It's kind of ridiculous to get the property name and then get
        // the value out of the name. Ideally we would get the value out of the
        // property ID, but CSSStyleDeclaration only gives access to property
        // names, not IDs.
        RefPtr<CSSValue> cssValue = styleDeclaration->getPropertyCSSValue(styleDeclaration->item(i));
        if (!cssValue->isImageValue())
            continue;

        CSSImageValue* imageValue = static_cast<CSSImageValue*>(cssValue.get());
        StyleImage* styleImage = imageValue->cachedOrPendingImage();
        // Non cached-images are just place-holders and do not contain data.
        if (!styleImage || !styleImage->isCachedImage())
            continue;

        CachedImage* image = static_cast<StyleCachedImage*>(styleImage)->cachedImage();

        KURL url = cssStyleSheet->document()->completeURL(image->url());
        addImageToResources(image, url);
    }
}
Пример #4
0
bool CSSCursorImageValue::hasFragmentInURL() const {
  if (m_imageValue->isImageValue()) {
    CSSImageValue* imageValue = toCSSImageValue(m_imageValue.get());
    KURL kurl(ParsedURLString, imageValue->url());
    return kurl.hasFragmentIdentifier();
  }
  return false;
}
PassRefPtrWillBeRawPtr<StyleImage> ElementStyleResources::cachedOrPendingFromValue(CSSPropertyID property, const CSSImageValue& value)
{
    if (value.isCachePending()) {
        m_pendingImageProperties.add(property);
        return StylePendingImage::create(value);
    }
    value.restoreCachedResourceIfNeeded(*m_document);
    return value.cachedImage();
}
Пример #6
0
void HTMLTablePartElement::collectStyleForPresentationAttribute(
    const QualifiedName& name,
    const AtomicString& value,
    MutableStylePropertySet* style) {
  if (name == bgcolorAttr) {
    addHTMLColorToStyle(style, CSSPropertyBackgroundColor, value);
  } else if (name == backgroundAttr) {
    String url = stripLeadingAndTrailingHTMLSpaces(value);
    if (!url.isEmpty()) {
      CSSImageValue* imageValue =
          CSSImageValue::create(url, document().completeURL(url));
      imageValue->setReferrer(Referrer(document().outgoingReferrer(),
                                       document().getReferrerPolicy()));
      style->setProperty(CSSProperty(CSSPropertyBackgroundImage, *imageValue));
    }
  } else if (name == valignAttr) {
    if (equalIgnoringCase(value, "top"))
      addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign,
                                              CSSValueTop);
    else if (equalIgnoringCase(value, "middle"))
      addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign,
                                              CSSValueMiddle);
    else if (equalIgnoringCase(value, "bottom"))
      addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign,
                                              CSSValueBottom);
    else if (equalIgnoringCase(value, "baseline"))
      addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign,
                                              CSSValueBaseline);
    else
      addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign,
                                              value);
  } else if (name == alignAttr) {
    if (equalIgnoringCase(value, "middle") ||
        equalIgnoringCase(value, "center"))
      addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign,
                                              CSSValueWebkitCenter);
    else if (equalIgnoringCase(value, "absmiddle"))
      addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign,
                                              CSSValueCenter);
    else if (equalIgnoringCase(value, "left"))
      addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign,
                                              CSSValueWebkitLeft);
    else if (equalIgnoringCase(value, "right"))
      addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign,
                                              CSSValueWebkitRight);
    else
      addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign,
                                              value);
  } else if (name == heightAttr) {
    if (!value.isEmpty())
      addHTMLLengthToStyle(style, CSSPropertyHeight, value);
  } else {
    HTMLElement::collectStyleForPresentationAttribute(name, value, style);
  }
}
void StyleResourceLoader::loadPendingShapeImage(RenderStyle* renderStyle, ShapeValue* shapeValue)
{
    if (!shapeValue)
        return;

    StyleImage* image = shapeValue->image();
    if (!image || !image->isPendingImage())
        return;

    StylePendingImage* pendingImage = static_cast<StylePendingImage*>(image);
    CSSImageValue* cssImageValue =  pendingImage->cssImageValue();

    ResourceLoaderOptions options = ResourceFetcher::defaultResourceOptions();
    options.requestOriginPolicy = RestrictToSameOrigin;

    shapeValue->setImage(cssImageValue->cachedImage(m_fetcher, options));
}
void StyleResourceLoader::loadPendingShapeImage(RenderStyle* renderStyle, ShapeValue* shapeValue)
{
    if (!shapeValue)
        return;

    StyleImage* image = shapeValue->image();
    if (!image || !image->isPendingImage())
        return;

    StylePendingImage* pendingImage = static_cast<StylePendingImage*>(image);
    CSSImageValue* cssImageValue =  pendingImage->cssImageValue();

    ResourceLoaderOptions options = ResourceFetcher::defaultResourceOptions();
    options.requestOriginPolicy = PotentiallyCrossOriginEnabled;
    options.allowCredentials = DoNotAllowStoredCredentials;

    shapeValue->setImage(cssImageValue->cachedImage(m_fetcher, options));
}
Пример #9
0
void PageSerializer::retrieveResourcesForCSSValue(CSSValue* cssValue, Document* document)
{
    if (cssValue->isImageValue()) {
        CSSImageValue* imageValue = toCSSImageValue(cssValue);
        StyleImage* styleImage = imageValue->cachedOrPendingImage();
        // Non cached-images are just place-holders and do not contain data.
        if (!styleImage || !styleImage->isImageResource())
            return;

        addImageToResources(styleImage->cachedImage(), 0, styleImage->cachedImage()->url());
    } else if (cssValue->isFontFaceSrcValue()) {
        CSSFontFaceSrcValue* fontFaceSrcValue = toCSSFontFaceSrcValue(cssValue);
        if (fontFaceSrcValue->isLocal()) {
            return;
        }

        addFontToResources(fontFaceSrcValue->fetch(document));
    } else if (cssValue->isValueList()) {
        CSSValueList* cssValueList = toCSSValueList(cssValue);
        for (unsigned i = 0; i < cssValueList->length(); i++)
            retrieveResourcesForCSSValue(cssValueList->item(i), document);
    }
}
Пример #10
0
void CSSImageSetValue::fillImageSet()
{
    size_t length = this->length();
    size_t i = 0;
    while (i < length) {
        CSSImageValue* imageValue = toCSSImageValue(item(i));
        String imageURL = imageValue->url();

        ++i;
        ASSERT_WITH_SECURITY_IMPLICATION(i < length);
        CSSValue* scaleFactorValue = item(i);
        float scaleFactor = toCSSPrimitiveValue(scaleFactorValue)->getFloatValue();

        ImageWithScale image;
        image.imageURL = imageURL;
        image.referrer = imageValue->referrer();
        image.scaleFactor = scaleFactor;
        m_imagesInSet.append(image);
        ++i;
    }

    // Sort the images so that they are stored in order from lowest resolution to highest.
    std::sort(m_imagesInSet.begin(), m_imagesInSet.end(), CSSImageSetValue::compareByScaleFactor);
}
Пример #11
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;
}
Пример #12
0
void HTMLTableElement::collectStyleForPresentationAttribute(
    const QualifiedName& name,
    const AtomicString& value,
    MutableStylePropertySet* style) {
  if (name == widthAttr) {
    addHTMLLengthToStyle(style, CSSPropertyWidth, value);
  } else if (name == heightAttr) {
    addHTMLLengthToStyle(style, CSSPropertyHeight, value);
  } else if (name == borderAttr) {
    addPropertyToPresentationAttributeStyle(
        style, CSSPropertyBorderWidth, parseBorderWidthAttribute(value),
        CSSPrimitiveValue::UnitType::Pixels);
  } else if (name == bordercolorAttr) {
    if (!value.isEmpty())
      addHTMLColorToStyle(style, CSSPropertyBorderColor, value);
  } else if (name == bgcolorAttr) {
    addHTMLColorToStyle(style, CSSPropertyBackgroundColor, value);
  } else if (name == backgroundAttr) {
    String url = stripLeadingAndTrailingHTMLSpaces(value);
    if (!url.isEmpty()) {
      CSSImageValue* imageValue =
          CSSImageValue::create(url, document().completeURL(url));
      imageValue->setReferrer(Referrer(document().outgoingReferrer(),
                                       document().getReferrerPolicy()));
      style->setProperty(CSSProperty(CSSPropertyBackgroundImage, *imageValue));
    }
  } else if (name == valignAttr) {
    if (!value.isEmpty())
      addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign,
                                              value);
  } else if (name == cellspacingAttr) {
    if (!value.isEmpty())
      addHTMLLengthToStyle(style, CSSPropertyBorderSpacing, value);
  } else if (name == alignAttr) {
    if (!value.isEmpty()) {
      if (equalIgnoringCase(value, "center")) {
        addPropertyToPresentationAttributeStyle(
            style, CSSPropertyWebkitMarginStart, CSSValueAuto);
        addPropertyToPresentationAttributeStyle(
            style, CSSPropertyWebkitMarginEnd, CSSValueAuto);
      } else {
        addPropertyToPresentationAttributeStyle(style, CSSPropertyFloat, value);
      }
    }
  } else if (name == rulesAttr) {
    // The presence of a valid rules attribute causes border collapsing to be
    // enabled.
    if (m_rulesAttr != UnsetRules)
      addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderCollapse,
                                              CSSValueCollapse);
  } else if (name == frameAttr) {
    bool borderTop;
    bool borderRight;
    bool borderBottom;
    bool borderLeft;
    if (getBordersFromFrameAttributeValue(value, borderTop, borderRight,
                                          borderBottom, borderLeft)) {
      addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderWidth,
                                              CSSValueThin);
      addPropertyToPresentationAttributeStyle(
          style, CSSPropertyBorderTopStyle,
          borderTop ? CSSValueSolid : CSSValueHidden);
      addPropertyToPresentationAttributeStyle(
          style, CSSPropertyBorderBottomStyle,
          borderBottom ? CSSValueSolid : CSSValueHidden);
      addPropertyToPresentationAttributeStyle(
          style, CSSPropertyBorderLeftStyle,
          borderLeft ? CSSValueSolid : CSSValueHidden);
      addPropertyToPresentationAttributeStyle(
          style, CSSPropertyBorderRightStyle,
          borderRight ? CSSValueSolid : CSSValueHidden);
    }
  } else {
    HTMLElement::collectStyleForPresentationAttribute(name, value, style);
  }
}