Example #1
0
std::unique_ptr<Shape> ShapeOutsideInfo::createShapeForImage(
    StyleImage* styleImage,
    float shapeImageThreshold,
    WritingMode writingMode,
    float margin) const {
  const LayoutSize& imageSize =
      styleImage->imageSize(m_layoutBox, m_layoutBox.style()->effectiveZoom(),
                            m_referenceBoxLogicalSize);

  const LayoutRect& marginRect =
      getShapeImageMarginRect(m_layoutBox, m_referenceBoxLogicalSize);
  const LayoutRect& imageRect =
      (m_layoutBox.isLayoutImage())
          ? toLayoutImage(m_layoutBox).replacedContentRect()
          : LayoutRect(LayoutPoint(), imageSize);

  if (!isValidRasterShapeRect(marginRect) ||
      !isValidRasterShapeRect(imageRect)) {
    m_layoutBox.document().addConsoleMessage(
        ConsoleMessage::create(RenderingMessageSource, ErrorMessageLevel,
                               "The shape-outside image is too large."));
    return Shape::createEmptyRasterShape(writingMode, margin);
  }

  ASSERT(!styleImage->isPendingImage());
  RefPtr<Image> image =
      styleImage->image(m_layoutBox, flooredIntSize(imageSize),
                        m_layoutBox.style()->effectiveZoom());

  return Shape::createRasterShape(image.get(), shapeImageThreshold, imageRect,
                                  marginRect, writingMode, margin);
}
Example #2
0
std::unique_ptr<Shape> ShapeOutsideInfo::createShapeForImage(StyleImage* styleImage, float shapeImageThreshold, WritingMode writingMode, float margin) const
{
    LayoutSize imageSize = m_renderer.calculateImageIntrinsicDimensions(styleImage, m_referenceBoxLogicalSize, RenderImage::ScaleByEffectiveZoom);
    styleImage->setContainerSizeForRenderer(&m_renderer, imageSize, m_renderer.style().effectiveZoom());

    const LayoutRect& marginRect = getShapeImageMarginRect(m_renderer, m_referenceBoxLogicalSize);
    const LayoutRect& imageRect = is<RenderImage>(m_renderer)
        ? downcast<RenderImage>(m_renderer).replacedContentRect(m_renderer.intrinsicSize())
        : LayoutRect(LayoutPoint(), imageSize);

    ASSERT(!styleImage->isPendingImage());
    RefPtr<Image> image = styleImage->image(const_cast<RenderBox*>(&m_renderer), imageSize);
    return Shape::createRasterShape(image.get(), shapeImageThreshold, imageRect, marginRect, writingMode, margin);
}
Example #3
0
PassOwnPtr<Shape> ShapeOutsideInfo::createShapeForImage(StyleImage* styleImage, float shapeImageThreshold, WritingMode writingMode, float margin) const
{
    const IntSize& imageSize = m_layoutBox.calculateImageIntrinsicDimensions(styleImage, roundedIntSize(m_referenceBoxLogicalSize), LayoutImage::ScaleByEffectiveZoom);
    styleImage->setContainerSizeForLayoutObject(&m_layoutBox, imageSize, m_layoutBox.style()->effectiveZoom());

    const LayoutRect& marginRect = getShapeImageMarginRect(m_layoutBox, m_referenceBoxLogicalSize);
    const LayoutRect& imageRect = (m_layoutBox.isLayoutImage())
        ? toLayoutImage(m_layoutBox).replacedContentRect()
        : LayoutRect(LayoutPoint(), LayoutSize(imageSize));

    if (!isValidRasterShapeRect(marginRect) || !isValidRasterShapeRect(imageRect)) {
        m_layoutBox.document().addConsoleMessage(ConsoleMessage::create(RenderingMessageSource, ErrorMessageLevel, "The shape-outside image is too large."));
        return Shape::createEmptyRasterShape(writingMode, margin);
    }

    ASSERT(!styleImage->isPendingImage());
    RefPtr<Image> image = styleImage->image(const_cast<LayoutBox*>(&m_layoutBox), imageSize);

    return Shape::createRasterShape(image.get(), shapeImageThreshold, imageRect, marginRect, writingMode, margin);
}
Example #4
0
const Shape& ShapeInfo<RenderType>::computedShape() const
{
    if (Shape* shape = m_shape.get())
        return *shape;

    WritingMode writingMode = this->styleForWritingMode().writingMode();
    Length margin = m_renderer.style().shapeMargin();
    Length padding = m_renderer.style().shapePadding();
    float shapeImageThreshold = m_renderer.style().shapeImageThreshold();
    const ShapeValue* shapeValue = this->shapeValue();
    ASSERT(shapeValue);

    switch (shapeValue->type()) {
    case ShapeValue::Shape:
        ASSERT(shapeValue->shape());
        m_shape = Shape::createShape(shapeValue->shape(), m_referenceBoxLogicalSize, writingMode, margin, padding);
        break;
    case ShapeValue::Image: {
        ASSERT(shapeValue->image());
        const StyleImage& styleImage = *(shapeValue->image());
        const LayoutRect& imageRect = getShapeImageReplacedRect(m_renderer, styleImage);
        const LayoutRect& marginRect = getShapeImageMarginRect(m_renderer, m_referenceBoxLogicalSize);
        m_shape = Shape::createRasterShape(styleImage, shapeImageThreshold, imageRect, marginRect, writingMode, margin, padding);
        break;
    }
    case ShapeValue::Box: {
        // FIXME This does not properly compute the rounded corners as specified in all conditions.
        // https://bugs.webkit.org/show_bug.cgi?id=127982
        const RoundedRect& shapeRect = m_renderer.style().getRoundedBorderFor(LayoutRect(LayoutPoint(), m_referenceBoxLogicalSize), &(m_renderer.view()));
        m_shape = Shape::createLayoutBoxShape(shapeRect, writingMode, margin, padding);
        break;
    }
    case ShapeValue::Outside:
        // Outside should have already resolved to a different shape value
        ASSERT_NOT_REACHED();
    }

    ASSERT(m_shape);
    return *m_shape;
}
Example #5
0
const Shape& ShapeOutsideInfo::computedShape() const
{
    if (Shape* shape = m_shape.get())
        return *shape;

    const RenderStyle& style = *m_renderer.style();
    ASSERT(m_renderer.containingBlock());
    const RenderStyle& containingBlockStyle = *m_renderer.containingBlock()->style();

    WritingMode writingMode = containingBlockStyle.writingMode();
    LayoutUnit maximumValue = m_renderer.containingBlock() ? m_renderer.containingBlock()->contentWidth() : LayoutUnit();
    float margin = floatValueForLength(m_renderer.style()->shapeMargin(), maximumValue.toFloat());

    float shapeImageThreshold = style.shapeImageThreshold();
    ASSERT(style.shapeOutside());
    const ShapeValue& shapeValue = *style.shapeOutside();

    switch (shapeValue.type()) {
    case ShapeValue::Shape:
        ASSERT(shapeValue.shape());
        m_shape = Shape::createShape(shapeValue.shape(), m_referenceBoxLogicalSize, writingMode, margin);
        break;
    case ShapeValue::Image: {
        Image* image;
        LayoutRect imageRect;
        getShapeImageAndRect(shapeValue, m_renderer, m_referenceBoxLogicalSize, image, imageRect);
        const LayoutRect& marginRect = getShapeImageMarginRect(m_renderer, m_referenceBoxLogicalSize);
        m_shape = Shape::createRasterShape(image, shapeImageThreshold, imageRect, marginRect, writingMode, margin);
        break;
    }
    case ShapeValue::Box: {
        const RoundedRect& shapeRect = style.getRoundedBorderFor(LayoutRect(LayoutPoint(), m_referenceBoxLogicalSize), m_renderer.view());
        m_shape = Shape::createLayoutBoxShape(shapeRect, writingMode, margin);
        break;
    }
    }

    ASSERT(m_shape);
    return *m_shape;
}