Пример #1
0
IntSize CSSCrossfadeValue::fixedSize(const LayoutObject& layoutObject,
                                     const FloatSize& defaultObjectSize) {
  Image* fromImage =
      renderableImageForCSSValue(m_fromValue.get(), layoutObject);
  Image* toImage = renderableImageForCSSValue(m_toValue.get(), layoutObject);

  if (!fromImage || !toImage)
    return IntSize();

  IntSize fromImageSize = fromImage->size();
  IntSize toImageSize = toImage->size();

  if (fromImage->isSVGImage())
    fromImageSize = roundedIntSize(
        toSVGImage(fromImage)->concreteObjectSize(defaultObjectSize));

  if (toImage->isSVGImage())
    toImageSize = roundedIntSize(
        toSVGImage(toImage)->concreteObjectSize(defaultObjectSize));

  // Rounding issues can cause transitions between images of equal size to
  // return a different fixed size; avoid performing the interpolation if the
  // images are the same size.
  if (fromImageSize == toImageSize)
    return fromImageSize;

  float percentage = m_percentageValue->getFloatValue();
  float inversePercentage = 1 - percentage;

  return IntSize(fromImageSize.width() * inversePercentage +
                     toImageSize.width() * percentage,
                 fromImageSize.height() * inversePercentage +
                     toImageSize.height() * percentage);
}
Пример #2
0
PassRefPtr<Image> CSSCrossfadeValue::image(const LayoutObject& layoutObject,
                                           const IntSize& size) {
  if (size.isEmpty())
    return nullptr;

  Image* fromImage =
      renderableImageForCSSValue(m_fromValue.get(), layoutObject);
  Image* toImage = renderableImageForCSSValue(m_toValue.get(), layoutObject);

  if (!fromImage || !toImage)
    return Image::nullImage();

  RefPtr<Image> fromImageRef(fromImage);
  RefPtr<Image> toImageRef(toImage);

  if (fromImage->isSVGImage())
    fromImageRef = SVGImageForContainer::create(
        toSVGImage(fromImage), size, 1, urlForCSSValue(m_fromValue.get()));

  if (toImage->isSVGImage())
    toImageRef = SVGImageForContainer::create(toSVGImage(toImage), size, 1,
                                              urlForCSSValue(m_toValue.get()));

  return CrossfadeGeneratedImage::create(
      fromImageRef, toImageRef, m_percentageValue->getFloatValue(),
      fixedSize(layoutObject, FloatSize(size)), size);
}
Пример #3
0
PassRefPtr<Image> StyleFetchedImageSet::image(const LayoutObject*, const IntSize& containerSize, float zoom) const
{
    if (!m_bestFitImage->image()->isSVGImage())
        return m_bestFitImage->image();

    return SVGImageForContainer::create(toSVGImage(m_bestFitImage->image()), containerSize, zoom, m_url);
}
Пример #4
0
FloatSize SVGImagePainter::computeImageViewportSize() const {
  DCHECK(m_layoutSVGImage.imageResource()->hasImage());

  if (toSVGImageElement(m_layoutSVGImage.element())
          ->preserveAspectRatio()
          ->currentValue()
          ->align() != SVGPreserveAspectRatio::kSvgPreserveaspectratioNone)
    return m_layoutSVGImage.objectBoundingBox().size();

  ImageResourceContent* cachedImage =
      m_layoutSVGImage.imageResource()->cachedImage();

  // Images with preserveAspectRatio=none should force non-uniform scaling. This
  // can be achieved by setting the image's container size to its viewport size
  // (i.e. concrete object size returned by the default sizing algorithm.)  See
  // https://www.w3.org/TR/SVG/single-page.html#coords-PreserveAspectRatioAttribute
  // and https://drafts.csswg.org/css-images-3/#default-sizing.

  // Avoid returning the size of the broken image.
  if (cachedImage->errorOccurred())
    return FloatSize();

  if (cachedImage->getImage()->isSVGImage())
    return toSVGImage(cachedImage->getImage())
        ->concreteObjectSize(m_layoutSVGImage.objectBoundingBox().size());

  return FloatSize(cachedImage->getImage()->size());
}
Пример #5
0
void StyleFetchedImage::notifyFinished(Resource* resource) {
  if (m_document && m_image && m_image->getImage() &&
      m_image->getImage()->isSVGImage())
    toSVGImage(m_image->getImage())->updateUseCounters(*m_document);
  // Oilpan: do not prolong the Document's lifetime.
  m_document.clear();
}
Пример #6
0
void ImageLoader::imageNotifyFinished(ImageResource* resource) {
    RESOURCE_LOADING_DVLOG(1)
            << "ImageLoader::imageNotifyFinished " << this
            << "; m_hasPendingLoadEvent=" << m_hasPendingLoadEvent;

    DCHECK(m_failedLoadURL.isEmpty());
    DCHECK_EQ(resource, m_image.get());

    m_imageComplete = true;

    // Update ImageAnimationPolicy for m_image.
    if (m_image)
        m_image->updateImageAnimationPolicy();

    updateLayoutObject();

    if (m_image && m_image->getImage() && m_image->getImage()->isSVGImage())
        toSVGImage(m_image->getImage())->updateUseCounters(element()->document());

    if (!m_hasPendingLoadEvent)
        return;

    if (resource->errorOccurred()) {
        loadEventSender().cancelEvent(this);
        m_hasPendingLoadEvent = false;

        if (resource->resourceError().isAccessCheck()) {
            crossSiteOrCSPViolationOccurred(
                AtomicString(resource->resourceError().failingURL()));
        }

        // The error event should not fire if the image data update is a result of
        // environment change.
        // https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element:the-img-element-55
        if (!m_suppressErrorEvents)
            dispatchErrorEvent();

        // Only consider updating the protection ref-count of the Element
        // immediately before returning from this function as doing so might result
        // in the destruction of this ImageLoader.
        updatedHasPendingEvent();
        return;
    }
    if (resource->wasCanceled()) {
        m_hasPendingLoadEvent = false;
        // Only consider updating the protection ref-count of the Element
        // immediately before returning from this function as doing so might result
        // in the destruction of this ImageLoader.
        updatedHasPendingEvent();
        return;
    }
    loadEventSender().dispatchEventSoon(this);
}
Пример #7
0
LayoutSize StyleFetchedImage::imageSize(
    const LayoutObject&,
    float multiplier,
    const LayoutSize& defaultObjectSize) const {
  if (m_image->getImage() && m_image->getImage()->isSVGImage())
    return imageSizeForSVGImage(toSVGImage(m_image->getImage()), multiplier,
                                defaultObjectSize);

  // Image orientation should only be respected for content images,
  // not decorative images such as StyleImage (backgrounds,
  // border-image, etc.)
  //
  // https://drafts.csswg.org/css-images-3/#the-image-orientation
  return m_image->imageSize(DoNotRespectImageOrientation, multiplier);
}
Пример #8
0
PassRefPtr<Image> LayoutImageResource::image(const IntSize& containerSize, float zoom) const
{
    if (!m_cachedImage)
        return Image::nullImage();

    if (!m_cachedImage->image()->isSVGImage())
        return m_cachedImage->image();

    KURL url;
    SVGImage* svgImage = toSVGImage(m_cachedImage->image());
    Node* node = m_layoutObject->node();
    if (node && node->isElementNode()) {
        const AtomicString& urlString = toElement(node)->imageSourceURL();
        url = node->document().completeURL(urlString);
    }
    return SVGImageForContainer::create(svgImage, containerSize, zoom, url);
}
Пример #9
0
void ImageResource::setContainerSizeForLayoutObject(const ImageResourceClient* layoutObject, const IntSize& containerSize, float containerZoom)
{
    if (containerSize.isEmpty())
        return;
    ASSERT(layoutObject);
    ASSERT(containerZoom);
    if (!m_image)
        return;
    if (!m_image->isSVGImage()) {
        m_image->setContainerSize(containerSize);
        return;
    }

    FloatSize containerSizeWithoutZoom(containerSize);
    containerSizeWithoutZoom.scale(1 / containerZoom);
    m_imageForContainerMap->set(layoutObject, SVGImageForContainer::create(toSVGImage(m_image.get()), containerSizeWithoutZoom, containerZoom));
}