This source file includes following definitions.
- setSelectionState
- contentChanged
- hasAcceleratedCompositing
- chooseInterpolationQuality
- willBeDestroyed
- updateFromStyle
- accumulateInFlowPositionOffsets
- hasAutoHeightOrContainingBlockWithAutoHeight
- relativePositionOffset
- adjustedPositionRelativeToOffsetParent
- computeStickyPositionConstraints
- stickyPositionOffset
- offsetForInFlowPosition
- offsetLeft
- offsetTop
- pixelSnappedOffsetWidth
- pixelSnappedOffsetHeight
- computedCSSPadding
- getBackgroundRoundedRect
- clipRoundedInnerRect
- shrinkRectByOnePixel
- borderInnerRectAdjustedForBleedAvoidance
- backgroundRoundedRectAdjustedForBleedAvoidance
- applyBoxShadowForBackground
- paintFillLayerExtended
- resolveWidthForRatio
- resolveHeightForRatio
- resolveAgainstIntrinsicWidthOrHeightAndRatio
- resolveAgainstIntrinsicRatio
- calculateImageIntrinsicDimensions
- applySubPixelHeuristicForTileSize
- calculateFillTileSize
- setNoRepeatX
- setNoRepeatY
- useFixedAttachment
- clip
- relativePhase
- fixedBackgroundPaintsInLocalCoordinates
- getSpace
- calculateBackgroundImageGeometry
- computeBorderImageSide
- paintNinePieceImage
- isPresent
- isPresent
- hasVisibleColorAndStyle
- shouldRender
- presentButInvisible
- obscuresBackgroundEdge
- obscuresBackground
- usedWidth
- getDoubleBorderStripeWidths
- allCornersClippedOut
- borderWillArcInnerEdge
- edgeFlagForSide
- includesEdge
- includesAdjacentEdges
- edgesShareColor
- styleRequiresClipPolygon
- borderStyleFillsBorderArea
- borderStyleHasInnerDetail
- borderStyleIsDottedOrDashed
- borderStyleHasUnmatchedColorsAtCorner
- colorsMatchAtCorner
- colorNeedsAntiAliasAtCorner
- willBeOverdrawn
- borderStylesRequireMitre
- joinRequiresMitre
- paintOneBorderSide
- calculateSideRect
- paintBorderSides
- paintTranslucentBorderSides
- paintBorder
- drawBoxSideFromPath
- clipBorderSidePolygon
- calculateSideRectIncludingInner
- calculateAdjustedInnerBorder
- clipBorderSideForComplexInnerPath
- getBorderEdgeInfo
- borderObscuresBackgroundEdge
- borderObscuresBackground
- boxShadowShouldBeAppliedToBackground
- paintBoxShadow
- containingBlockLogicalWidthForContent
- continuation
- setContinuation
- computeLayerHitTestRects
- firstLetterRemainingText
- setFirstLetterRemainingText
- localCaretRectForEmptyElement
- shouldAntialiasLines
- mapAbsoluteToLocalPoint
- pushMappingToContainer
- moveChildTo
- moveChildrenTo
#include "config.h"
#include "core/rendering/RenderBoxModelObject.h"
#include "HTMLNames.h"
#include "core/frame/Settings.h"
#include "core/html/HTMLFrameOwnerElement.h"
#include "core/page/scrolling/ScrollingConstraints.h"
#include "core/rendering/ImageQualityController.h"
#include "core/rendering/RenderBlock.h"
#include "core/rendering/RenderFlowThread.h"
#include "core/rendering/RenderGeometryMap.h"
#include "core/rendering/RenderInline.h"
#include "core/rendering/RenderLayer.h"
#include "core/rendering/RenderRegion.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/compositing/CompositedLayerMapping.h"
#include "core/rendering/compositing/RenderLayerCompositor.h"
#include "core/rendering/style/ShadowList.h"
#include "platform/geometry/TransformState.h"
#include "platform/graphics/DrawLooperBuilder.h"
#include "platform/graphics/GraphicsContextStateSaver.h"
#include "platform/graphics/Path.h"
#include "wtf/CurrentTime.h"
using namespace std;
namespace WebCore {
using namespace HTMLNames;
typedef HashMap<const RenderBoxModelObject*, RenderBoxModelObject*> ContinuationMap;
static ContinuationMap* continuationMap = 0;
typedef HashMap<const RenderBoxModelObject*, RenderTextFragment*> FirstLetterRemainingTextMap;
static FirstLetterRemainingTextMap* firstLetterRemainingTextMap = 0;
void RenderBoxModelObject::setSelectionState(SelectionState state)
{
if (state == SelectionInside && selectionState() != SelectionNone)
return;
if ((state == SelectionStart && selectionState() == SelectionEnd)
|| (state == SelectionEnd && selectionState() == SelectionStart))
RenderObject::setSelectionState(SelectionBoth);
else
RenderObject::setSelectionState(state);
RenderBlock* containingBlock = this->containingBlock();
if (containingBlock && !containingBlock->isRenderView())
containingBlock->setSelectionState(state);
}
void RenderBoxModelObject::contentChanged(ContentChangeType changeType)
{
if (!hasLayer())
return;
layer()->contentChanged(changeType);
}
bool RenderBoxModelObject::hasAcceleratedCompositing() const
{
return view()->compositor()->hasAcceleratedCompositing();
}
InterpolationQuality RenderBoxModelObject::chooseInterpolationQuality(GraphicsContext* context, Image* image, const void* layer, const LayoutSize& size)
{
return ImageQualityController::imageQualityController()->chooseInterpolationQuality(context, this, image, layer, size);
}
RenderBoxModelObject::RenderBoxModelObject(ContainerNode* node)
: RenderLayerModelObject(node)
{
}
RenderBoxModelObject::~RenderBoxModelObject()
{
ImageQualityController::remove(this);
}
void RenderBoxModelObject::willBeDestroyed()
{
ASSERT(!continuation());
if (firstLetterRemainingText())
setFirstLetterRemainingText(0);
RenderLayerModelObject::willBeDestroyed();
}
void RenderBoxModelObject::updateFromStyle()
{
RenderLayerModelObject::updateFromStyle();
RenderStyle* styleToUse = style();
setHasBoxDecorations(hasBackground() || styleToUse->hasBorder() || styleToUse->hasAppearance() || styleToUse->boxShadow());
setInline(styleToUse->isDisplayInlineType());
setPositionState(styleToUse->position());
setHorizontalWritingMode(styleToUse->isHorizontalWritingMode());
}
static LayoutSize accumulateInFlowPositionOffsets(const RenderObject* child)
{
if (!child->isAnonymousBlock() || !child->isInFlowPositioned())
return LayoutSize();
LayoutSize offset;
RenderObject* p = toRenderBlock(child)->inlineElementContinuation();
while (p && p->isRenderInline()) {
if (p->isInFlowPositioned()) {
RenderInline* renderInline = toRenderInline(p);
offset += renderInline->offsetForInFlowPosition();
}
p = p->parent();
}
return offset;
}
bool RenderBoxModelObject::hasAutoHeightOrContainingBlockWithAutoHeight() const
{
Length logicalHeightLength = style()->logicalHeight();
if (logicalHeightLength.isAuto())
return true;
if (!logicalHeightLength.isPercent() || isOutOfFlowPositioned() || document().inQuirksMode())
return false;
RenderBlock* cb = containingBlock();
while (cb->isAnonymous())
cb = cb->containingBlock();
if (cb->isTableCell())
return false;
if (!cb->style()->logicalHeight().isAuto() || (!cb->style()->logicalTop().isAuto() && !cb->style()->logicalBottom().isAuto()))
return false;
return true;
}
LayoutSize RenderBoxModelObject::relativePositionOffset() const
{
LayoutSize offset = accumulateInFlowPositionOffsets(this);
RenderBlock* containingBlock = this->containingBlock();
if (!style()->left().isAuto()) {
if (!style()->right().isAuto() && !containingBlock->style()->isLeftToRightDirection())
offset.setWidth(-valueForLength(style()->right(), containingBlock->availableWidth()));
else
offset.expand(valueForLength(style()->left(), containingBlock->availableWidth()), 0);
} else if (!style()->right().isAuto()) {
offset.expand(-valueForLength(style()->right(), containingBlock->availableWidth()), 0);
}
if (!style()->top().isAuto()
&& (!containingBlock->hasAutoHeightOrContainingBlockWithAutoHeight()
|| !style()->top().isPercent()
|| containingBlock->stretchesToViewport()))
offset.expand(0, valueForLength(style()->top(), containingBlock->availableHeight()));
else if (!style()->bottom().isAuto()
&& (!containingBlock->hasAutoHeightOrContainingBlockWithAutoHeight()
|| !style()->bottom().isPercent()
|| containingBlock->stretchesToViewport()))
offset.expand(0, -valueForLength(style()->bottom(), containingBlock->availableHeight()));
return offset;
}
LayoutPoint RenderBoxModelObject::adjustedPositionRelativeToOffsetParent(const LayoutPoint& startPoint) const
{
if (isBody() || !parent())
return LayoutPoint();
LayoutPoint referencePoint = startPoint;
referencePoint.move(parent()->offsetForColumns(referencePoint));
Element* element = offsetParent();
if (!element)
return referencePoint;
if (const RenderBoxModelObject* offsetParent = element->renderBoxModelObject()) {
if (offsetParent->isBox() && !offsetParent->isBody())
referencePoint.move(-toRenderBox(offsetParent)->borderLeft(), -toRenderBox(offsetParent)->borderTop());
if (!isOutOfFlowPositioned() || flowThreadContainingBlock()) {
if (isRelPositioned())
referencePoint.move(relativePositionOffset());
else if (isStickyPositioned())
referencePoint.move(stickyPositionOffset());
RenderObject* current;
for (current = parent(); current != offsetParent && current->parent(); current = current->parent()) {
if (!isOutOfFlowPositioned()) {
if (current->isBox() && !current->isTableRow())
referencePoint.moveBy(toRenderBox(current)->topLeftLocation());
referencePoint.move(current->parent()->offsetForColumns(referencePoint));
}
}
if (offsetParent->isBox() && offsetParent->isBody() && !offsetParent->isPositioned())
referencePoint.moveBy(toRenderBox(offsetParent)->topLeftLocation());
}
}
return referencePoint;
}
void RenderBoxModelObject::computeStickyPositionConstraints(StickyPositionViewportConstraints& constraints, const FloatRect& constrainingRect) const
{
RenderBlock* containingBlock = this->containingBlock();
LayoutRect containerContentRect = containingBlock->contentBoxRect();
LayoutUnit maxWidth = containingBlock->availableLogicalWidth();
LayoutBoxExtent minMargin(minimumValueForLength(style()->marginTop(), maxWidth),
minimumValueForLength(style()->marginRight(), maxWidth),
minimumValueForLength(style()->marginBottom(), maxWidth),
minimumValueForLength(style()->marginLeft(), maxWidth));
containerContentRect.contract(minMargin);
constraints.setAbsoluteContainingBlockRect(containingBlock->localToContainerQuad(FloatRect(containerContentRect), view()).boundingBox());
LayoutRect stickyBoxRect = frameRectForStickyPositioning();
LayoutRect flippedStickyBoxRect = stickyBoxRect;
containingBlock->flipForWritingMode(flippedStickyBoxRect);
LayoutPoint stickyLocation = flippedStickyBoxRect.location();
FloatRect absContainerFrame = containingBlock->localToContainerQuad(FloatRect(FloatPoint(), containingBlock->size()), view()).boundingBox();
if (containingBlock->hasOverflowClip()) {
IntSize scrollOffset = containingBlock->layer()->scrollableArea()->adjustedScrollOffset();
stickyLocation -= scrollOffset;
}
FloatRect absoluteStickyBoxRect(absContainerFrame.location() + stickyLocation, flippedStickyBoxRect.size());
constraints.setAbsoluteStickyBoxRect(absoluteStickyBoxRect);
if (!style()->left().isAuto()) {
constraints.setLeftOffset(floatValueForLength(style()->left(), constrainingRect.width()));
constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeLeft);
}
if (!style()->right().isAuto()) {
constraints.setRightOffset(floatValueForLength(style()->right(), constrainingRect.width()));
constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeRight);
}
if (!style()->top().isAuto()) {
constraints.setTopOffset(floatValueForLength(style()->top(), constrainingRect.height()));
constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeTop);
}
if (!style()->bottom().isAuto()) {
constraints.setBottomOffset(floatValueForLength(style()->bottom(), constrainingRect.height() ));
constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeBottom);
}
}
LayoutSize RenderBoxModelObject::stickyPositionOffset() const
{
FloatRect constrainingRect;
ASSERT(hasLayer());
RenderLayer* enclosingClippingLayer = layer()->enclosingOverflowClipLayer(ExcludeSelf);
if (enclosingClippingLayer) {
RenderBox* enclosingClippingBox = toRenderBox(enclosingClippingLayer->renderer());
LayoutRect clipRect = enclosingClippingBox->overflowClipRect(LayoutPoint());
clipRect.move(enclosingClippingBox->paddingLeft(), enclosingClippingBox->paddingTop());
clipRect.contract(LayoutSize(enclosingClippingBox->paddingLeft() + enclosingClippingBox->paddingRight(),
enclosingClippingBox->paddingTop() + enclosingClippingBox->paddingBottom()));
constrainingRect = enclosingClippingBox->localToContainerQuad(FloatRect(clipRect), view()).boundingBox();
} else {
LayoutRect viewportRect = view()->frameView()->viewportConstrainedVisibleContentRect();
constrainingRect = viewportRect;
}
StickyPositionViewportConstraints constraints;
computeStickyPositionConstraints(constraints, constrainingRect);
return LayoutSize(constraints.computeStickyOffset(constrainingRect));
}
LayoutSize RenderBoxModelObject::offsetForInFlowPosition() const
{
if (isRelPositioned())
return relativePositionOffset();
if (isStickyPositioned())
return stickyPositionOffset();
return LayoutSize();
}
LayoutUnit RenderBoxModelObject::offsetLeft() const
{
return adjustedPositionRelativeToOffsetParent(LayoutPoint()).x();
}
LayoutUnit RenderBoxModelObject::offsetTop() const
{
return adjustedPositionRelativeToOffsetParent(LayoutPoint()).y();
}
int RenderBoxModelObject::pixelSnappedOffsetWidth() const
{
return snapSizeToPixel(offsetWidth(), offsetLeft());
}
int RenderBoxModelObject::pixelSnappedOffsetHeight() const
{
return snapSizeToPixel(offsetHeight(), offsetTop());
}
LayoutUnit RenderBoxModelObject::computedCSSPadding(Length padding) const
{
LayoutUnit w = 0;
if (padding.isPercent())
w = containingBlockLogicalWidthForContent();
return minimumValueForLength(padding, w);
}
RoundedRect RenderBoxModelObject::getBackgroundRoundedRect(const LayoutRect& borderRect, InlineFlowBox* box, LayoutUnit inlineBoxWidth, LayoutUnit inlineBoxHeight,
bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
{
RoundedRect border = style()->getRoundedBorderFor(borderRect, includeLogicalLeftEdge, includeLogicalRightEdge);
if (box && (box->nextLineBox() || box->prevLineBox())) {
RoundedRect segmentBorder = style()->getRoundedBorderFor(LayoutRect(0, 0, inlineBoxWidth, inlineBoxHeight), includeLogicalLeftEdge, includeLogicalRightEdge);
border.setRadii(segmentBorder.radii());
}
return border;
}
void RenderBoxModelObject::clipRoundedInnerRect(GraphicsContext * context, const LayoutRect& rect, const RoundedRect& clipRect)
{
if (clipRect.isRenderable())
context->clipRoundedRect(clipRect);
else {
if (!clipRect.radii().topLeft().isEmpty() || !clipRect.radii().bottomRight().isEmpty()) {
IntRect topCorner(clipRect.rect().x(), clipRect.rect().y(), rect.maxX() - clipRect.rect().x(), rect.maxY() - clipRect.rect().y());
RoundedRect::Radii topCornerRadii;
topCornerRadii.setTopLeft(clipRect.radii().topLeft());
context->clipRoundedRect(RoundedRect(topCorner, topCornerRadii));
IntRect bottomCorner(rect.x(), rect.y(), clipRect.rect().maxX() - rect.x(), clipRect.rect().maxY() - rect.y());
RoundedRect::Radii bottomCornerRadii;
bottomCornerRadii.setBottomRight(clipRect.radii().bottomRight());
context->clipRoundedRect(RoundedRect(bottomCorner, bottomCornerRadii));
}
if (!clipRect.radii().topRight().isEmpty() || !clipRect.radii().bottomLeft().isEmpty()) {
IntRect topCorner(rect.x(), clipRect.rect().y(), clipRect.rect().maxX() - rect.x(), rect.maxY() - clipRect.rect().y());
RoundedRect::Radii topCornerRadii;
topCornerRadii.setTopRight(clipRect.radii().topRight());
context->clipRoundedRect(RoundedRect(topCorner, topCornerRadii));
IntRect bottomCorner(clipRect.rect().x(), rect.y(), rect.maxX() - clipRect.rect().x(), clipRect.rect().maxY() - rect.y());
RoundedRect::Radii bottomCornerRadii;
bottomCornerRadii.setBottomLeft(clipRect.radii().bottomLeft());
context->clipRoundedRect(RoundedRect(bottomCorner, bottomCornerRadii));
}
}
}
static LayoutRect shrinkRectByOnePixel(GraphicsContext* context, const LayoutRect& rect)
{
LayoutRect shrunkRect = rect;
AffineTransform transform = context->getCTM();
shrunkRect.inflateX(-static_cast<LayoutUnit>(ceil(1 / transform.xScale())));
shrunkRect.inflateY(-static_cast<LayoutUnit>(ceil(1 / transform.yScale())));
return shrunkRect;
}
LayoutRect RenderBoxModelObject::borderInnerRectAdjustedForBleedAvoidance(GraphicsContext* context, const LayoutRect& rect, BackgroundBleedAvoidance bleedAvoidance) const
{
return (bleedAvoidance == BackgroundBleedBackgroundOverBorder) ? shrinkRectByOnePixel(context, rect) : rect;
}
RoundedRect RenderBoxModelObject::backgroundRoundedRectAdjustedForBleedAvoidance(GraphicsContext* context, const LayoutRect& borderRect, BackgroundBleedAvoidance bleedAvoidance, InlineFlowBox* box, const LayoutSize& boxSize, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
{
if (bleedAvoidance == BackgroundBleedShrinkBackground) {
return getBackgroundRoundedRect(shrinkRectByOnePixel(context, borderRect), box, boxSize.width(), boxSize.height(), includeLogicalLeftEdge, includeLogicalRightEdge);
}
if (bleedAvoidance == BackgroundBleedBackgroundOverBorder)
return style()->getRoundedInnerBorderFor(borderRect, includeLogicalLeftEdge, includeLogicalRightEdge);
return getBackgroundRoundedRect(borderRect, box, boxSize.width(), boxSize.height(), includeLogicalLeftEdge, includeLogicalRightEdge);
}
static void applyBoxShadowForBackground(GraphicsContext* context, const RenderObject* renderer)
{
const ShadowList* shadowList = renderer->style()->boxShadow();
ASSERT(shadowList);
for (size_t i = shadowList->shadows().size(); i--; ) {
const ShadowData& boxShadow = shadowList->shadows()[i];
if (boxShadow.style() != Normal)
continue;
FloatSize shadowOffset(boxShadow.x(), boxShadow.y());
context->setShadow(shadowOffset, boxShadow.blur(), boxShadow.color(),
DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::ShadowIgnoresAlpha);
return;
}
}
void RenderBoxModelObject::paintFillLayerExtended(const PaintInfo& paintInfo, const Color& color, const FillLayer* bgLayer, const LayoutRect& rect,
BackgroundBleedAvoidance bleedAvoidance, InlineFlowBox* box, const LayoutSize& boxSize, CompositeOperator op, RenderObject* backgroundObject)
{
GraphicsContext* context = paintInfo.context;
if (context->paintingDisabled() || rect.isEmpty())
return;
bool includeLeftEdge = box ? box->includeLogicalLeftEdge() : true;
bool includeRightEdge = box ? box->includeLogicalRightEdge() : true;
bool hasRoundedBorder = style()->hasBorderRadius() && (includeLeftEdge || includeRightEdge);
bool clippedWithLocalScrolling = hasOverflowClip() && bgLayer->attachment() == LocalBackgroundAttachment;
bool isBorderFill = bgLayer->clip() == BorderFillBox;
bool isRoot = this->isRoot();
Color bgColor = color;
StyleImage* bgImage = bgLayer->image();
bool shouldPaintBackgroundImage = bgImage && bgImage->canRender(this, style()->effectiveZoom());
bool forceBackgroundToWhite = false;
if (document().printing()) {
if (style()->printColorAdjust() == PrintColorAdjustEconomy)
forceBackgroundToWhite = true;
if (document().settings() && document().settings()->shouldPrintBackgrounds())
forceBackgroundToWhite = false;
}
if (forceBackgroundToWhite) {
bool shouldPaintBackgroundColor = !bgLayer->next() && bgColor.alpha();
if (shouldPaintBackgroundImage || shouldPaintBackgroundColor) {
bgColor = Color::white;
shouldPaintBackgroundImage = false;
}
}
bool colorVisible = bgColor.alpha();
if (!isRoot && !clippedWithLocalScrolling && !shouldPaintBackgroundImage && isBorderFill && !bgLayer->next()) {
if (!colorVisible)
return;
bool boxShadowShouldBeAppliedToBackground = this->boxShadowShouldBeAppliedToBackground(bleedAvoidance, box);
GraphicsContextStateSaver shadowStateSaver(*context, boxShadowShouldBeAppliedToBackground);
if (boxShadowShouldBeAppliedToBackground)
applyBoxShadowForBackground(context, this);
if (hasRoundedBorder && bleedAvoidance != BackgroundBleedClipBackground) {
RoundedRect border = backgroundRoundedRectAdjustedForBleedAvoidance(context, rect, bleedAvoidance, box, boxSize, includeLeftEdge, includeRightEdge);
if (border.isRenderable())
context->fillRoundedRect(border, bgColor);
else {
context->save();
clipRoundedInnerRect(context, rect, border);
context->fillRect(border.rect(), bgColor);
context->restore();
}
} else {
context->fillRect(pixelSnappedIntRect(rect), bgColor);
}
return;
}
bool clipToBorderRadius = hasRoundedBorder && !(isBorderFill && bleedAvoidance == BackgroundBleedClipBackground);
GraphicsContextStateSaver clipToBorderStateSaver(*context, clipToBorderRadius);
if (clipToBorderRadius) {
RoundedRect border = isBorderFill ? backgroundRoundedRectAdjustedForBleedAvoidance(context, rect, bleedAvoidance, box, boxSize, includeLeftEdge, includeRightEdge) : getBackgroundRoundedRect(rect, box, boxSize.width(), boxSize.height(), includeLeftEdge, includeRightEdge);
if (bgLayer->clip() == ContentFillBox) {
border = style()->getRoundedInnerBorderFor(border.rect(),
paddingTop() + borderTop(), paddingBottom() + borderBottom(), paddingLeft() + borderLeft(), paddingRight() + borderRight(), includeLeftEdge, includeRightEdge);
} else if (bgLayer->clip() == PaddingFillBox)
border = style()->getRoundedInnerBorderFor(border.rect(), includeLeftEdge, includeRightEdge);
clipRoundedInnerRect(context, rect, border);
}
int bLeft = includeLeftEdge ? borderLeft() : 0;
int bRight = includeRightEdge ? borderRight() : 0;
LayoutUnit pLeft = includeLeftEdge ? paddingLeft() : LayoutUnit();
LayoutUnit pRight = includeRightEdge ? paddingRight() : LayoutUnit();
GraphicsContextStateSaver clipWithScrollingStateSaver(*context, clippedWithLocalScrolling);
LayoutRect scrolledPaintRect = rect;
if (clippedWithLocalScrolling) {
RenderBox* thisBox = toRenderBox(this);
context->clip(thisBox->overflowClipRect(rect.location()));
IntSize offset = thisBox->scrolledContentOffset();
scrolledPaintRect.move(-offset);
scrolledPaintRect.setWidth(bLeft + thisBox->scrollWidth() + bRight);
scrolledPaintRect.setHeight(borderTop() + thisBox->scrollHeight() + borderBottom());
}
GraphicsContextStateSaver backgroundClipStateSaver(*context, false);
IntRect maskRect;
switch (bgLayer->clip()) {
case PaddingFillBox:
case ContentFillBox: {
if (clipToBorderRadius)
break;
bool includePadding = bgLayer->clip() == ContentFillBox;
LayoutRect clipRect = LayoutRect(scrolledPaintRect.x() + bLeft + (includePadding ? pLeft : LayoutUnit()),
scrolledPaintRect.y() + borderTop() + (includePadding ? paddingTop() : LayoutUnit()),
scrolledPaintRect.width() - bLeft - bRight - (includePadding ? pLeft + pRight : LayoutUnit()),
scrolledPaintRect.height() - borderTop() - borderBottom() - (includePadding ? paddingTop() + paddingBottom() : LayoutUnit()));
backgroundClipStateSaver.save();
context->clip(clipRect);
break;
}
case TextFillBox: {
maskRect = pixelSnappedIntRect(rect);
maskRect.intersect(paintInfo.rect);
backgroundClipStateSaver.save();
context->clip(maskRect);
context->beginTransparencyLayer(1);
break;
}
case BorderFillBox:
break;
default:
ASSERT_NOT_REACHED();
break;
}
bool isOpaqueRoot = false;
if (isRoot) {
isOpaqueRoot = true;
if (!bgLayer->next() && bgColor.hasAlpha() && view()->frameView()) {
Element* ownerElement = document().ownerElement();
if (ownerElement) {
if (!isHTMLFrameElement(*ownerElement)) {
HTMLElement* body = document().body();
if (body) {
isOpaqueRoot = body->hasLocalName(framesetTag);
} else {
isOpaqueRoot = !document().hasSVGRootNode();
}
}
} else
isOpaqueRoot = !view()->frameView()->isTransparent();
}
view()->frameView()->setContentIsOpaque(isOpaqueRoot);
}
if (!bgLayer->next()) {
IntRect backgroundRect(pixelSnappedIntRect(scrolledPaintRect));
bool boxShadowShouldBeAppliedToBackground = this->boxShadowShouldBeAppliedToBackground(bleedAvoidance, box);
if (boxShadowShouldBeAppliedToBackground || !shouldPaintBackgroundImage || !bgLayer->hasOpaqueImage(this) || !bgLayer->hasRepeatXY() || (isOpaqueRoot && !toRenderBox(this)->height())) {
if (!boxShadowShouldBeAppliedToBackground)
backgroundRect.intersect(paintInfo.rect);
GraphicsContextStateSaver shadowStateSaver(*context, boxShadowShouldBeAppliedToBackground);
if (boxShadowShouldBeAppliedToBackground)
applyBoxShadowForBackground(context, this);
if (isOpaqueRoot) {
Color baseColor = view()->frameView()->baseBackgroundColor();
bool shouldClearDocumentBackground = document().settings() && document().settings()->shouldClearDocumentBackground();
CompositeOperator operation = shouldClearDocumentBackground ? CompositeCopy : context->compositeOperation();
if (baseColor.alpha()) {
if (bgColor.alpha())
baseColor = baseColor.blend(bgColor);
context->fillRect(backgroundRect, baseColor, operation);
} else if (bgColor.alpha()) {
context->fillRect(backgroundRect, bgColor, operation);
} else if (shouldClearDocumentBackground) {
context->clearRect(backgroundRect);
}
} else if (bgColor.alpha()) {
context->fillRect(backgroundRect, bgColor, context->compositeOperation());
}
}
}
if (shouldPaintBackgroundImage) {
BackgroundImageGeometry geometry;
calculateBackgroundImageGeometry(paintInfo.paintContainer(), bgLayer, scrolledPaintRect, geometry, backgroundObject);
geometry.clip(paintInfo.rect);
if (!geometry.destRect().isEmpty()) {
CompositeOperator compositeOp = op == CompositeSourceOver ? bgLayer->composite() : op;
RenderObject* clientForBackgroundImage = backgroundObject ? backgroundObject : this;
RefPtr<Image> image = bgImage->image(clientForBackgroundImage, geometry.tileSize());
InterpolationQuality interpolationQuality = chooseInterpolationQuality(context, image.get(), bgLayer, geometry.tileSize());
if (bgLayer->maskSourceType() == MaskLuminance)
context->setColorFilter(ColorFilterLuminanceToAlpha);
InterpolationQuality previousInterpolationQuality = context->imageInterpolationQuality();
context->setImageInterpolationQuality(interpolationQuality);
context->drawTiledImage(image.get(), geometry.destRect(), geometry.relativePhase(), geometry.tileSize(),
compositeOp, bgLayer->blendMode(), geometry.spaceSize());
context->setImageInterpolationQuality(previousInterpolationQuality);
}
}
if (bgLayer->clip() == TextFillBox) {
context->setCompositeOperation(CompositeDestinationIn);
context->beginTransparencyLayer(1);
context->clearRect(maskRect);
PaintInfo info(context, maskRect, PaintPhaseTextClip, PaintBehaviorForceBlackText, 0);
context->setCompositeOperation(CompositeSourceOver);
if (box) {
RootInlineBox& root = box->root();
box->paint(info, LayoutPoint(scrolledPaintRect.x() - box->x(), scrolledPaintRect.y() - box->y()), root.lineTop(), root.lineBottom());
} else {
LayoutSize localOffset = isBox() ? toRenderBox(this)->locationOffset() : LayoutSize();
paint(info, scrolledPaintRect.location() - localOffset);
}
context->endLayer();
context->endLayer();
}
}
static inline int resolveWidthForRatio(int height, const FloatSize& intrinsicRatio)
{
return ceilf(height * intrinsicRatio.width() / intrinsicRatio.height());
}
static inline int resolveHeightForRatio(int width, const FloatSize& intrinsicRatio)
{
return ceilf(width * intrinsicRatio.height() / intrinsicRatio.width());
}
static inline IntSize resolveAgainstIntrinsicWidthOrHeightAndRatio(const IntSize& size, const FloatSize& intrinsicRatio, int useWidth, int useHeight)
{
if (intrinsicRatio.isEmpty()) {
if (useWidth)
return IntSize(useWidth, size.height());
return IntSize(size.width(), useHeight);
}
if (useWidth)
return IntSize(useWidth, resolveHeightForRatio(useWidth, intrinsicRatio));
return IntSize(resolveWidthForRatio(useHeight, intrinsicRatio), useHeight);
}
static inline IntSize resolveAgainstIntrinsicRatio(const IntSize& size, const FloatSize& intrinsicRatio)
{
int solutionWidth = resolveWidthForRatio(size.height(), intrinsicRatio);
int solutionHeight = resolveHeightForRatio(size.width(), intrinsicRatio);
if (solutionWidth <= size.width()) {
if (solutionHeight <= size.height()) {
int areaOne = solutionWidth * size.height();
int areaTwo = size.width() * solutionHeight;
if (areaOne < areaTwo)
return IntSize(size.width(), solutionHeight);
return IntSize(solutionWidth, size.height());
}
return IntSize(solutionWidth, size.height());
}
ASSERT(solutionHeight <= size.height());
return IntSize(size.width(), solutionHeight);
}
IntSize RenderBoxModelObject::calculateImageIntrinsicDimensions(StyleImage* image, const IntSize& positioningAreaSize, ScaleByEffectiveZoomOrNot shouldScaleOrNot) const
{
if (image->isGeneratedImage() && image->usesImageContainerSize())
return IntSize(positioningAreaSize.width(), positioningAreaSize.height());
Length intrinsicWidth;
Length intrinsicHeight;
FloatSize intrinsicRatio;
image->computeIntrinsicDimensions(this, intrinsicWidth, intrinsicHeight, intrinsicRatio);
if (intrinsicWidth.isPercent() && intrinsicHeight.isPercent() && intrinsicRatio.isEmpty()) {
int resolvedWidth = static_cast<int>(round(positioningAreaSize.width() * intrinsicWidth.percent() / 100));
int resolvedHeight = static_cast<int>(round(positioningAreaSize.height() * intrinsicHeight.percent() / 100));
return IntSize(resolvedWidth, resolvedHeight);
}
IntSize resolvedSize(intrinsicWidth.isFixed() ? intrinsicWidth.value() : 0, intrinsicHeight.isFixed() ? intrinsicHeight.value() : 0);
IntSize minimumSize(resolvedSize.width() > 0 ? 1 : 0, resolvedSize.height() > 0 ? 1 : 0);
if (shouldScaleOrNot == ScaleByEffectiveZoom)
resolvedSize.scale(style()->effectiveZoom());
resolvedSize.clampToMinimumSize(minimumSize);
if (!resolvedSize.isEmpty())
return resolvedSize;
if (resolvedSize.width() > 0 || resolvedSize.height() > 0)
return resolveAgainstIntrinsicWidthOrHeightAndRatio(positioningAreaSize, intrinsicRatio, resolvedSize.width(), resolvedSize.height());
if (!intrinsicRatio.isEmpty())
return resolveAgainstIntrinsicRatio(positioningAreaSize, intrinsicRatio);
return positioningAreaSize;
}
static inline void applySubPixelHeuristicForTileSize(LayoutSize& tileSize, const IntSize& positioningAreaSize)
{
tileSize.setWidth(positioningAreaSize.width() - tileSize.width() <= 1 ? tileSize.width().ceil() : tileSize.width().floor());
tileSize.setHeight(positioningAreaSize.height() - tileSize.height() <= 1 ? tileSize.height().ceil() : tileSize.height().floor());
}
IntSize RenderBoxModelObject::calculateFillTileSize(const FillLayer* fillLayer, const IntSize& positioningAreaSize) const
{
StyleImage* image = fillLayer->image();
EFillSizeType type = fillLayer->size().type;
IntSize imageIntrinsicSize = calculateImageIntrinsicDimensions(image, positioningAreaSize, ScaleByEffectiveZoom);
imageIntrinsicSize.scale(1 / image->imageScaleFactor(), 1 / image->imageScaleFactor());
switch (type) {
case SizeLength: {
LayoutSize tileSize = positioningAreaSize;
Length layerWidth = fillLayer->size().size.width();
Length layerHeight = fillLayer->size().size.height();
if (layerWidth.isFixed())
tileSize.setWidth(layerWidth.value());
else if (layerWidth.isPercent())
tileSize.setWidth(valueForLength(layerWidth, positioningAreaSize.width()));
if (layerHeight.isFixed())
tileSize.setHeight(layerHeight.value());
else if (layerHeight.isPercent())
tileSize.setHeight(valueForLength(layerHeight, positioningAreaSize.height()));
applySubPixelHeuristicForTileSize(tileSize, positioningAreaSize);
if (layerWidth.isAuto() && !layerHeight.isAuto()) {
if (imageIntrinsicSize.height())
tileSize.setWidth(imageIntrinsicSize.width() * tileSize.height() / imageIntrinsicSize.height());
} else if (!layerWidth.isAuto() && layerHeight.isAuto()) {
if (imageIntrinsicSize.width())
tileSize.setHeight(imageIntrinsicSize.height() * tileSize.width() / imageIntrinsicSize.width());
} else if (layerWidth.isAuto() && layerHeight.isAuto()) {
tileSize = imageIntrinsicSize;
}
tileSize.clampNegativeToZero();
return flooredIntSize(tileSize);
}
case SizeNone: {
if (!imageIntrinsicSize.isEmpty())
return imageIntrinsicSize;
type = Contain;
}
case Contain:
case Cover: {
float horizontalScaleFactor = imageIntrinsicSize.width()
? static_cast<float>(positioningAreaSize.width()) / imageIntrinsicSize.width() : 1;
float verticalScaleFactor = imageIntrinsicSize.height()
? static_cast<float>(positioningAreaSize.height()) / imageIntrinsicSize.height() : 1;
float scaleFactor = type == Contain ? min(horizontalScaleFactor, verticalScaleFactor) : max(horizontalScaleFactor, verticalScaleFactor);
return IntSize(max(1l, lround(imageIntrinsicSize.width() * scaleFactor)), max(1l, lround(imageIntrinsicSize.height() * scaleFactor)));
}
}
ASSERT_NOT_REACHED();
return IntSize();
}
void RenderBoxModelObject::BackgroundImageGeometry::setNoRepeatX(int xOffset)
{
m_destRect.move(max(xOffset, 0), 0);
m_phase.setX(-min(xOffset, 0));
m_destRect.setWidth(m_tileSize.width() + min(xOffset, 0));
}
void RenderBoxModelObject::BackgroundImageGeometry::setNoRepeatY(int yOffset)
{
m_destRect.move(0, max(yOffset, 0));
m_phase.setY(-min(yOffset, 0));
m_destRect.setHeight(m_tileSize.height() + min(yOffset, 0));
}
void RenderBoxModelObject::BackgroundImageGeometry::useFixedAttachment(const IntPoint& attachmentPoint)
{
IntPoint alignedPoint = attachmentPoint;
m_phase.move(max(alignedPoint.x() - m_destRect.x(), 0), max(alignedPoint.y() - m_destRect.y(), 0));
}
void RenderBoxModelObject::BackgroundImageGeometry::clip(const IntRect& clipRect)
{
m_destRect.intersect(clipRect);
}
IntPoint RenderBoxModelObject::BackgroundImageGeometry::relativePhase() const
{
IntPoint phase = m_phase;
phase += m_destRect.location() - m_destOrigin;
return phase;
}
bool RenderBoxModelObject::fixedBackgroundPaintsInLocalCoordinates() const
{
if (!isRoot())
return false;
if (view()->frameView() && view()->frameView()->paintBehavior() & PaintBehaviorFlattenCompositingLayers)
return false;
RenderLayer* rootLayer = view()->layer();
if (!rootLayer || rootLayer->compositingState() == NotComposited)
return false;
return rootLayer->compositedLayerMapping()->backgroundLayerPaintsFixedRootBackground();
}
static inline int getSpace(int areaSize, int tileSize)
{
int numberOfTiles = areaSize / tileSize;
int space = -1;
if (numberOfTiles > 1)
space = lroundf((float)(areaSize - numberOfTiles * tileSize) / (numberOfTiles - 1));
return space;
}
void RenderBoxModelObject::calculateBackgroundImageGeometry(const RenderLayerModelObject* paintContainer, const FillLayer* fillLayer, const LayoutRect& paintRect,
BackgroundImageGeometry& geometry, RenderObject* backgroundObject) const
{
LayoutUnit left = 0;
LayoutUnit top = 0;
IntSize positioningAreaSize;
IntRect snappedPaintRect = pixelSnappedIntRect(paintRect);
bool fixedAttachment = fillLayer->attachment() == FixedBackgroundAttachment;
#if ENABLE(FAST_MOBILE_SCROLLING)
if (view()->frameView() && view()->frameView()->shouldAttemptToScrollUsingFastPath()) {
fixedAttachment = false;
}
#endif
if (!fixedAttachment) {
geometry.setDestRect(snappedPaintRect);
LayoutUnit right = 0;
LayoutUnit bottom = 0;
if (fillLayer->origin() != BorderFillBox) {
left = borderLeft();
right = borderRight();
top = borderTop();
bottom = borderBottom();
if (fillLayer->origin() == ContentFillBox) {
left += paddingLeft();
right += paddingRight();
top += paddingTop();
bottom += paddingBottom();
}
}
if (isRoot()) {
positioningAreaSize = pixelSnappedIntSize(toRenderBox(this)->size() - LayoutSize(left + right, top + bottom), toRenderBox(this)->location());
left += marginLeft();
top += marginTop();
} else
positioningAreaSize = pixelSnappedIntSize(paintRect.size() - LayoutSize(left + right, top + bottom), paintRect.location());
} else {
geometry.setHasNonLocalGeometry();
IntRect viewportRect = pixelSnappedIntRect(viewRect());
if (fixedBackgroundPaintsInLocalCoordinates())
viewportRect.setLocation(IntPoint());
else if (FrameView* frameView = view()->frameView())
viewportRect.setLocation(IntPoint(frameView->scrollOffsetForFixedPosition()));
if (paintContainer) {
IntPoint absoluteContainerOffset = roundedIntPoint(paintContainer->localToAbsolute(FloatPoint()));
viewportRect.moveBy(-absoluteContainerOffset);
}
geometry.setDestRect(pixelSnappedIntRect(viewportRect));
positioningAreaSize = geometry.destRect().size();
}
const RenderObject* clientForBackgroundImage = backgroundObject ? backgroundObject : this;
IntSize fillTileSize = calculateFillTileSize(fillLayer, positioningAreaSize);
fillLayer->image()->setContainerSizeForRenderer(clientForBackgroundImage, fillTileSize, style()->effectiveZoom());
geometry.setTileSize(fillTileSize);
EFillRepeat backgroundRepeatX = fillLayer->repeatX();
EFillRepeat backgroundRepeatY = fillLayer->repeatY();
int availableWidth = positioningAreaSize.width() - geometry.tileSize().width();
int availableHeight = positioningAreaSize.height() - geometry.tileSize().height();
LayoutUnit computedXPosition = roundedMinimumValueForLength(fillLayer->xPosition(), availableWidth);
if (backgroundRepeatX == RoundFill && positioningAreaSize.width() > 0 && fillTileSize.width() > 0) {
long nrTiles = max(1l, lroundf((float)positioningAreaSize.width() / fillTileSize.width()));
if (fillLayer->size().size.height().isAuto() && backgroundRepeatY != RoundFill) {
fillTileSize.setHeight(fillTileSize.height() * positioningAreaSize.width() / (nrTiles * fillTileSize.width()));
}
fillTileSize.setWidth(positioningAreaSize.width() / nrTiles);
geometry.setTileSize(fillTileSize);
geometry.setPhaseX(geometry.tileSize().width() ? geometry.tileSize().width() - roundToInt(computedXPosition + left) % geometry.tileSize().width() : 0);
geometry.setSpaceSize(IntSize());
}
LayoutUnit computedYPosition = roundedMinimumValueForLength(fillLayer->yPosition(), availableHeight);
if (backgroundRepeatY == RoundFill && positioningAreaSize.height() > 0 && fillTileSize.height() > 0) {
long nrTiles = max(1l, lroundf((float)positioningAreaSize.height() / fillTileSize.height()));
if (fillLayer->size().size.width().isAuto() && backgroundRepeatX != RoundFill) {
fillTileSize.setWidth(fillTileSize.width() * positioningAreaSize.height() / (nrTiles * fillTileSize.height()));
}
fillTileSize.setHeight(positioningAreaSize.height() / nrTiles);
geometry.setTileSize(fillTileSize);
geometry.setPhaseY(geometry.tileSize().height() ? geometry.tileSize().height() - roundToInt(computedYPosition + top) % geometry.tileSize().height() : 0);
geometry.setSpaceSize(IntSize());
}
if (backgroundRepeatX == RepeatFill) {
geometry.setPhaseX(geometry.tileSize().width() ? geometry.tileSize().width() - roundToInt(computedXPosition + left) % geometry.tileSize().width() : 0);
geometry.setSpaceSize(IntSize());
} else if (backgroundRepeatX == SpaceFill && fillTileSize.width() > 0) {
int space = getSpace(positioningAreaSize.width(), geometry.tileSize().width());
int actualWidth = geometry.tileSize().width() + space;
if (space >= 0) {
computedXPosition = roundedMinimumValueForLength(Length(), availableWidth);
geometry.setSpaceSize(IntSize(space, 0));
geometry.setPhaseX(actualWidth ? actualWidth - roundToInt(computedXPosition + left) % actualWidth : 0);
} else {
backgroundRepeatX = NoRepeatFill;
}
}
if (backgroundRepeatX == NoRepeatFill) {
int xOffset = fillLayer->backgroundXOrigin() == RightEdge ? availableWidth - computedXPosition : computedXPosition;
geometry.setNoRepeatX(left + xOffset);
geometry.setSpaceSize(IntSize(0, geometry.spaceSize().height()));
}
if (backgroundRepeatY == RepeatFill) {
geometry.setPhaseY(geometry.tileSize().height() ? geometry.tileSize().height() - roundToInt(computedYPosition + top) % geometry.tileSize().height() : 0);
geometry.setSpaceSize(IntSize(geometry.spaceSize().width(), 0));
} else if (backgroundRepeatY == SpaceFill && fillTileSize.height() > 0) {
int space = getSpace(positioningAreaSize.height(), geometry.tileSize().height());
int actualHeight = geometry.tileSize().height() + space;
if (space >= 0) {
computedYPosition = roundedMinimumValueForLength(Length(), availableHeight);
geometry.setSpaceSize(IntSize(geometry.spaceSize().width(), space));
geometry.setPhaseY(actualHeight ? actualHeight - roundToInt(computedYPosition + top) % actualHeight : 0);
} else {
backgroundRepeatY = NoRepeatFill;
}
}
if (backgroundRepeatY == NoRepeatFill) {
int yOffset = fillLayer->backgroundYOrigin() == BottomEdge ? availableHeight - computedYPosition : computedYPosition;
geometry.setNoRepeatY(top + yOffset);
geometry.setSpaceSize(IntSize(geometry.spaceSize().width(), 0));
}
if (fixedAttachment)
geometry.useFixedAttachment(snappedPaintRect.location());
geometry.clip(snappedPaintRect);
geometry.setDestOrigin(geometry.destRect().location());
}
static LayoutUnit computeBorderImageSide(const BorderImageLength& borderSlice, LayoutUnit borderSide, LayoutUnit imageSide, LayoutUnit boxExtent)
{
if (borderSlice.isNumber())
return borderSlice.number() * borderSide;
if (borderSlice.length().isAuto())
return imageSide;
return valueForLength(borderSlice.length(), boxExtent);
}
bool RenderBoxModelObject::paintNinePieceImage(GraphicsContext* graphicsContext, const LayoutRect& rect, const RenderStyle* style,
const NinePieceImage& ninePieceImage, CompositeOperator op)
{
StyleImage* styleImage = ninePieceImage.image();
if (!styleImage)
return false;
if (!styleImage->isLoaded())
return true;
if (!styleImage->canRender(this, style->effectiveZoom()))
return false;
LayoutRect rectWithOutsets = rect;
rectWithOutsets.expand(style->imageOutsets(ninePieceImage));
IntRect borderImageRect = pixelSnappedIntRect(rectWithOutsets);
IntSize imageSize = calculateImageIntrinsicDimensions(styleImage, borderImageRect.size(), DoNotScaleByEffectiveZoom);
styleImage->setContainerSizeForRenderer(this, imageSize, style->effectiveZoom());
int imageWidth = imageSize.width();
int imageHeight = imageSize.height();
float imageScaleFactor = styleImage->imageScaleFactor();
int topSlice = min<int>(imageHeight, valueForLength(ninePieceImage.imageSlices().top(), imageHeight)) * imageScaleFactor;
int rightSlice = min<int>(imageWidth, valueForLength(ninePieceImage.imageSlices().right(), imageWidth)) * imageScaleFactor;
int bottomSlice = min<int>(imageHeight, valueForLength(ninePieceImage.imageSlices().bottom(), imageHeight)) * imageScaleFactor;
int leftSlice = min<int>(imageWidth, valueForLength(ninePieceImage.imageSlices().left(), imageWidth)) * imageScaleFactor;
ENinePieceImageRule hRule = ninePieceImage.horizontalRule();
ENinePieceImageRule vRule = ninePieceImage.verticalRule();
int topWidth = computeBorderImageSide(ninePieceImage.borderSlices().top(), style->borderTopWidth(), topSlice, borderImageRect.height());
int rightWidth = computeBorderImageSide(ninePieceImage.borderSlices().right(), style->borderRightWidth(), rightSlice, borderImageRect.width());
int bottomWidth = computeBorderImageSide(ninePieceImage.borderSlices().bottom(), style->borderBottomWidth(), bottomSlice, borderImageRect.height());
int leftWidth = computeBorderImageSide(ninePieceImage.borderSlices().left(), style->borderLeftWidth(), leftSlice, borderImageRect.width());
int borderSideWidth = max(1, leftWidth + rightWidth);
int borderSideHeight = max(1, topWidth + bottomWidth);
float borderSideScaleFactor = min((float)borderImageRect.width() / borderSideWidth, (float)borderImageRect.height() / borderSideHeight);
if (borderSideScaleFactor < 1) {
topWidth *= borderSideScaleFactor;
rightWidth *= borderSideScaleFactor;
bottomWidth *= borderSideScaleFactor;
leftWidth *= borderSideScaleFactor;
}
bool drawLeft = leftSlice > 0 && leftWidth > 0;
bool drawTop = topSlice > 0 && topWidth > 0;
bool drawRight = rightSlice > 0 && rightWidth > 0;
bool drawBottom = bottomSlice > 0 && bottomWidth > 0;
bool drawMiddle = ninePieceImage.fill() && (imageWidth - leftSlice - rightSlice) > 0 && (borderImageRect.width() - leftWidth - rightWidth) > 0
&& (imageHeight - topSlice - bottomSlice) > 0 && (borderImageRect.height() - topWidth - bottomWidth) > 0;
RefPtr<Image> image = styleImage->image(this, imageSize);
float destinationWidth = borderImageRect.width() - leftWidth - rightWidth;
float destinationHeight = borderImageRect.height() - topWidth - bottomWidth;
float sourceWidth = imageWidth - leftSlice - rightSlice;
float sourceHeight = imageHeight - topSlice - bottomSlice;
float leftSideScale = drawLeft ? (float)leftWidth / leftSlice : 1;
float rightSideScale = drawRight ? (float)rightWidth / rightSlice : 1;
float topSideScale = drawTop ? (float)topWidth / topSlice : 1;
float bottomSideScale = drawBottom ? (float)bottomWidth / bottomSlice : 1;
if (drawLeft) {
if (drawTop)
graphicsContext->drawImage(image.get(), IntRect(borderImageRect.location(), IntSize(leftWidth, topWidth)),
LayoutRect(0, 0, leftSlice, topSlice), op);
if (drawBottom)
graphicsContext->drawImage(image.get(), IntRect(borderImageRect.x(), borderImageRect.maxY() - bottomWidth, leftWidth, bottomWidth),
LayoutRect(0, imageHeight - bottomSlice, leftSlice, bottomSlice), op);
if (sourceHeight > 0)
graphicsContext->drawTiledImage(image.get(), IntRect(borderImageRect.x(), borderImageRect.y() + topWidth, leftWidth, destinationHeight),
IntRect(0, topSlice, leftSlice, sourceHeight),
FloatSize(leftSideScale, leftSideScale), Image::StretchTile, (Image::TileRule)vRule, op);
}
if (drawRight) {
if (drawTop)
graphicsContext->drawImage(image.get(), IntRect(borderImageRect.maxX() - rightWidth, borderImageRect.y(), rightWidth, topWidth),
LayoutRect(imageWidth - rightSlice, 0, rightSlice, topSlice), op);
if (drawBottom)
graphicsContext->drawImage(image.get(), IntRect(borderImageRect.maxX() - rightWidth, borderImageRect.maxY() - bottomWidth, rightWidth, bottomWidth),
LayoutRect(imageWidth - rightSlice, imageHeight - bottomSlice, rightSlice, bottomSlice), op);
if (sourceHeight > 0)
graphicsContext->drawTiledImage(image.get(), IntRect(borderImageRect.maxX() - rightWidth, borderImageRect.y() + topWidth, rightWidth,
destinationHeight),
IntRect(imageWidth - rightSlice, topSlice, rightSlice, sourceHeight),
FloatSize(rightSideScale, rightSideScale),
Image::StretchTile, (Image::TileRule)vRule, op);
}
if (drawTop && sourceWidth > 0)
graphicsContext->drawTiledImage(image.get(), IntRect(borderImageRect.x() + leftWidth, borderImageRect.y(), destinationWidth, topWidth),
IntRect(leftSlice, 0, sourceWidth, topSlice),
FloatSize(topSideScale, topSideScale), (Image::TileRule)hRule, Image::StretchTile, op);
if (drawBottom && sourceWidth > 0)
graphicsContext->drawTiledImage(image.get(), IntRect(borderImageRect.x() + leftWidth, borderImageRect.maxY() - bottomWidth,
destinationWidth, bottomWidth),
IntRect(leftSlice, imageHeight - bottomSlice, sourceWidth, bottomSlice),
FloatSize(bottomSideScale, bottomSideScale),
(Image::TileRule)hRule, Image::StretchTile, op);
if (drawMiddle) {
FloatSize middleScaleFactor(1, 1);
if (drawTop)
middleScaleFactor.setWidth(topSideScale);
else if (drawBottom)
middleScaleFactor.setWidth(bottomSideScale);
if (drawLeft)
middleScaleFactor.setHeight(leftSideScale);
else if (drawRight)
middleScaleFactor.setHeight(rightSideScale);
if (hRule == StretchImageRule)
middleScaleFactor.setWidth(destinationWidth / sourceWidth);
if (vRule == StretchImageRule)
middleScaleFactor.setHeight(destinationHeight / sourceHeight);
graphicsContext->drawTiledImage(image.get(),
IntRect(borderImageRect.x() + leftWidth, borderImageRect.y() + topWidth, destinationWidth, destinationHeight),
IntRect(leftSlice, topSlice, sourceWidth, sourceHeight),
middleScaleFactor, (Image::TileRule)hRule, (Image::TileRule)vRule, op);
}
return true;
}
class BorderEdge {
public:
BorderEdge(int edgeWidth, const Color& edgeColor, EBorderStyle edgeStyle, bool edgeIsTransparent, bool edgeIsPresent = true)
: width(edgeWidth)
, color(edgeColor)
, style(edgeStyle)
, isTransparent(edgeIsTransparent)
, isPresent(edgeIsPresent)
{
if (style == DOUBLE && edgeWidth < 3)
style = SOLID;
}
BorderEdge()
: width(0)
, style(BHIDDEN)
, isTransparent(false)
, isPresent(false)
{
}
bool hasVisibleColorAndStyle() const { return style > BHIDDEN && !isTransparent; }
bool shouldRender() const { return isPresent && width && hasVisibleColorAndStyle(); }
bool presentButInvisible() const { return usedWidth() && !hasVisibleColorAndStyle(); }
bool obscuresBackgroundEdge(float scale) const
{
if (!isPresent || isTransparent || (width * scale) < 2 || color.hasAlpha() || style == BHIDDEN)
return false;
if (style == DOTTED || style == DASHED)
return false;
if (style == DOUBLE)
return width >= 5 * scale;
return true;
}
bool obscuresBackground() const
{
if (!isPresent || isTransparent || color.hasAlpha() || style == BHIDDEN)
return false;
if (style == DOTTED || style == DASHED || style == DOUBLE)
return false;
return true;
}
int usedWidth() const { return isPresent ? width : 0; }
void getDoubleBorderStripeWidths(int& outerWidth, int& innerWidth) const
{
int fullWidth = usedWidth();
outerWidth = fullWidth / 3;
innerWidth = fullWidth * 2 / 3;
if (fullWidth % 3 == 2)
outerWidth += 1;
if (fullWidth % 3 == 1)
innerWidth += 1;
}
int width;
Color color;
EBorderStyle style;
bool isTransparent;
bool isPresent;
};
static bool allCornersClippedOut(const RoundedRect& border, const LayoutRect& clipRect)
{
LayoutRect boundingRect = border.rect();
if (clipRect.contains(boundingRect))
return false;
RoundedRect::Radii radii = border.radii();
LayoutRect topLeftRect(boundingRect.location(), radii.topLeft());
if (clipRect.intersects(topLeftRect))
return false;
LayoutRect topRightRect(boundingRect.location(), radii.topRight());
topRightRect.setX(boundingRect.maxX() - topRightRect.width());
if (clipRect.intersects(topRightRect))
return false;
LayoutRect bottomLeftRect(boundingRect.location(), radii.bottomLeft());
bottomLeftRect.setY(boundingRect.maxY() - bottomLeftRect.height());
if (clipRect.intersects(bottomLeftRect))
return false;
LayoutRect bottomRightRect(boundingRect.location(), radii.bottomRight());
bottomRightRect.setX(boundingRect.maxX() - bottomRightRect.width());
bottomRightRect.setY(boundingRect.maxY() - bottomRightRect.height());
if (clipRect.intersects(bottomRightRect))
return false;
return true;
}
static bool borderWillArcInnerEdge(const LayoutSize& firstRadius, const FloatSize& secondRadius)
{
return !firstRadius.isZero() || !secondRadius.isZero();
}
enum BorderEdgeFlag {
TopBorderEdge = 1 << BSTop,
RightBorderEdge = 1 << BSRight,
BottomBorderEdge = 1 << BSBottom,
LeftBorderEdge = 1 << BSLeft,
AllBorderEdges = TopBorderEdge | BottomBorderEdge | LeftBorderEdge | RightBorderEdge
};
static inline BorderEdgeFlag edgeFlagForSide(BoxSide side)
{
return static_cast<BorderEdgeFlag>(1 << side);
}
static inline bool includesEdge(BorderEdgeFlags flags, BoxSide side)
{
return flags & edgeFlagForSide(side);
}
static inline bool includesAdjacentEdges(BorderEdgeFlags flags)
{
return (flags & (TopBorderEdge | RightBorderEdge)) == (TopBorderEdge | RightBorderEdge)
|| (flags & (RightBorderEdge | BottomBorderEdge)) == (RightBorderEdge | BottomBorderEdge)
|| (flags & (BottomBorderEdge | LeftBorderEdge)) == (BottomBorderEdge | LeftBorderEdge)
|| (flags & (LeftBorderEdge | TopBorderEdge)) == (LeftBorderEdge | TopBorderEdge);
}
inline bool edgesShareColor(const BorderEdge& firstEdge, const BorderEdge& secondEdge)
{
return firstEdge.color == secondEdge.color;
}
inline bool styleRequiresClipPolygon(EBorderStyle style)
{
return style == DOTTED || style == DASHED;
}
static bool borderStyleFillsBorderArea(EBorderStyle style)
{
return !(style == DOTTED || style == DASHED || style == DOUBLE);
}
static bool borderStyleHasInnerDetail(EBorderStyle style)
{
return style == GROOVE || style == RIDGE || style == DOUBLE;
}
static bool borderStyleIsDottedOrDashed(EBorderStyle style)
{
return style == DOTTED || style == DASHED;
}
static inline bool borderStyleHasUnmatchedColorsAtCorner(EBorderStyle style, BoxSide side, BoxSide adjacentSide)
{
if (style == INSET || style == GROOVE || style == RIDGE || style == OUTSET) {
const BorderEdgeFlags topRightFlags = edgeFlagForSide(BSTop) | edgeFlagForSide(BSRight);
const BorderEdgeFlags bottomLeftFlags = edgeFlagForSide(BSBottom) | edgeFlagForSide(BSLeft);
BorderEdgeFlags flags = edgeFlagForSide(side) | edgeFlagForSide(adjacentSide);
return flags == topRightFlags || flags == bottomLeftFlags;
}
return false;
}
static inline bool colorsMatchAtCorner(BoxSide side, BoxSide adjacentSide, const BorderEdge edges[])
{
if (edges[side].shouldRender() != edges[adjacentSide].shouldRender())
return false;
if (!edgesShareColor(edges[side], edges[adjacentSide]))
return false;
return !borderStyleHasUnmatchedColorsAtCorner(edges[side].style, side, adjacentSide);
}
static inline bool colorNeedsAntiAliasAtCorner(BoxSide side, BoxSide adjacentSide, const BorderEdge edges[])
{
if (!edges[side].color.hasAlpha())
return false;
if (edges[side].shouldRender() != edges[adjacentSide].shouldRender())
return false;
if (!edgesShareColor(edges[side], edges[adjacentSide]))
return true;
return borderStyleHasUnmatchedColorsAtCorner(edges[side].style, side, adjacentSide);
}
static inline bool willBeOverdrawn(BoxSide side, BoxSide adjacentSide, const BorderEdge edges[])
{
switch (side) {
case BSTop:
case BSBottom:
if (edges[adjacentSide].presentButInvisible())
return false;
if (!edgesShareColor(edges[side], edges[adjacentSide]) && edges[adjacentSide].color.hasAlpha())
return false;
if (!borderStyleFillsBorderArea(edges[adjacentSide].style))
return false;
return true;
case BSLeft:
case BSRight:
return false;
}
return false;
}
static inline bool borderStylesRequireMitre(BoxSide side, BoxSide adjacentSide, EBorderStyle style, EBorderStyle adjacentStyle)
{
if (style == DOUBLE || adjacentStyle == DOUBLE || adjacentStyle == GROOVE || adjacentStyle == RIDGE)
return true;
if (borderStyleIsDottedOrDashed(style) != borderStyleIsDottedOrDashed(adjacentStyle))
return true;
if (style != adjacentStyle)
return true;
return borderStyleHasUnmatchedColorsAtCorner(style, side, adjacentSide);
}
static bool joinRequiresMitre(BoxSide side, BoxSide adjacentSide, const BorderEdge edges[], bool allowOverdraw)
{
if ((edges[side].isTransparent && edges[adjacentSide].isTransparent) || !edges[adjacentSide].isPresent)
return false;
if (allowOverdraw && willBeOverdrawn(side, adjacentSide, edges))
return false;
if (!edgesShareColor(edges[side], edges[adjacentSide]))
return true;
if (borderStylesRequireMitre(side, adjacentSide, edges[side].style, edges[adjacentSide].style))
return true;
return false;
}
void RenderBoxModelObject::paintOneBorderSide(GraphicsContext* graphicsContext, const RenderStyle* style, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
const IntRect& sideRect, BoxSide side, BoxSide adjacentSide1, BoxSide adjacentSide2, const BorderEdge edges[], const Path* path,
BackgroundBleedAvoidance bleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias, const Color* overrideColor)
{
const BorderEdge& edgeToRender = edges[side];
ASSERT(edgeToRender.width);
const BorderEdge& adjacentEdge1 = edges[adjacentSide1];
const BorderEdge& adjacentEdge2 = edges[adjacentSide2];
bool mitreAdjacentSide1 = joinRequiresMitre(side, adjacentSide1, edges, !antialias);
bool mitreAdjacentSide2 = joinRequiresMitre(side, adjacentSide2, edges, !antialias);
bool adjacentSide1StylesMatch = colorsMatchAtCorner(side, adjacentSide1, edges);
bool adjacentSide2StylesMatch = colorsMatchAtCorner(side, adjacentSide2, edges);
const Color& colorToPaint = overrideColor ? *overrideColor : edgeToRender.color;
if (path) {
GraphicsContextStateSaver stateSaver(*graphicsContext);
if (innerBorder.isRenderable())
clipBorderSidePolygon(graphicsContext, outerBorder, innerBorder, side, adjacentSide1StylesMatch, adjacentSide2StylesMatch);
else
clipBorderSideForComplexInnerPath(graphicsContext, outerBorder, innerBorder, side, edges);
float thickness = max(max(edgeToRender.width, adjacentEdge1.width), adjacentEdge2.width);
drawBoxSideFromPath(graphicsContext, outerBorder.rect(), *path, edges, edgeToRender.width, thickness, side, style,
colorToPaint, edgeToRender.style, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge);
} else {
bool clipForStyle = styleRequiresClipPolygon(edgeToRender.style) && (mitreAdjacentSide1 || mitreAdjacentSide2);
bool clipAdjacentSide1 = colorNeedsAntiAliasAtCorner(side, adjacentSide1, edges) && mitreAdjacentSide1;
bool clipAdjacentSide2 = colorNeedsAntiAliasAtCorner(side, adjacentSide2, edges) && mitreAdjacentSide2;
bool shouldClip = clipForStyle || clipAdjacentSide1 || clipAdjacentSide2;
GraphicsContextStateSaver clipStateSaver(*graphicsContext, shouldClip);
if (shouldClip) {
bool aliasAdjacentSide1 = clipAdjacentSide1 || (clipForStyle && mitreAdjacentSide1);
bool aliasAdjacentSide2 = clipAdjacentSide2 || (clipForStyle && mitreAdjacentSide2);
clipBorderSidePolygon(graphicsContext, outerBorder, innerBorder, side, !aliasAdjacentSide1, !aliasAdjacentSide2);
mitreAdjacentSide1 = false;
mitreAdjacentSide2 = false;
}
drawLineForBoxSide(graphicsContext, sideRect.x(), sideRect.y(), sideRect.maxX(), sideRect.maxY(), side, colorToPaint, edgeToRender.style,
mitreAdjacentSide1 ? adjacentEdge1.width : 0, mitreAdjacentSide2 ? adjacentEdge2.width : 0, antialias);
}
}
static IntRect calculateSideRect(const RoundedRect& outerBorder, const BorderEdge edges[], int side)
{
IntRect sideRect = outerBorder.rect();
int width = edges[side].width;
if (side == BSTop)
sideRect.setHeight(width);
else if (side == BSBottom)
sideRect.shiftYEdgeTo(sideRect.maxY() - width);
else if (side == BSLeft)
sideRect.setWidth(width);
else
sideRect.shiftXEdgeTo(sideRect.maxX() - width);
return sideRect;
}
void RenderBoxModelObject::paintBorderSides(GraphicsContext* graphicsContext, const RenderStyle* style, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
const IntPoint& innerBorderAdjustment, const BorderEdge edges[], BorderEdgeFlags edgeSet, BackgroundBleedAvoidance bleedAvoidance,
bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias, const Color* overrideColor)
{
bool renderRadii = outerBorder.isRounded();
Path roundedPath;
if (renderRadii)
roundedPath.addRoundedRect(outerBorder);
if (edges[BSTop].shouldRender() && includesEdge(edgeSet, BSTop)) {
IntRect sideRect = outerBorder.rect();
sideRect.setHeight(edges[BSTop].width + innerBorderAdjustment.y());
bool usePath = renderRadii && (borderStyleHasInnerDetail(edges[BSTop].style) || borderWillArcInnerEdge(innerBorder.radii().topLeft(), innerBorder.radii().topRight()));
paintOneBorderSide(graphicsContext, style, outerBorder, innerBorder, sideRect, BSTop, BSLeft, BSRight, edges, usePath ? &roundedPath : 0, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, overrideColor);
}
if (edges[BSBottom].shouldRender() && includesEdge(edgeSet, BSBottom)) {
IntRect sideRect = outerBorder.rect();
sideRect.shiftYEdgeTo(sideRect.maxY() - edges[BSBottom].width - innerBorderAdjustment.y());
bool usePath = renderRadii && (borderStyleHasInnerDetail(edges[BSBottom].style) || borderWillArcInnerEdge(innerBorder.radii().bottomLeft(), innerBorder.radii().bottomRight()));
paintOneBorderSide(graphicsContext, style, outerBorder, innerBorder, sideRect, BSBottom, BSLeft, BSRight, edges, usePath ? &roundedPath : 0, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, overrideColor);
}
if (edges[BSLeft].shouldRender() && includesEdge(edgeSet, BSLeft)) {
IntRect sideRect = outerBorder.rect();
sideRect.setWidth(edges[BSLeft].width + innerBorderAdjustment.x());
bool usePath = renderRadii && (borderStyleHasInnerDetail(edges[BSLeft].style) || borderWillArcInnerEdge(innerBorder.radii().bottomLeft(), innerBorder.radii().topLeft()));
paintOneBorderSide(graphicsContext, style, outerBorder, innerBorder, sideRect, BSLeft, BSTop, BSBottom, edges, usePath ? &roundedPath : 0, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, overrideColor);
}
if (edges[BSRight].shouldRender() && includesEdge(edgeSet, BSRight)) {
IntRect sideRect = outerBorder.rect();
sideRect.shiftXEdgeTo(sideRect.maxX() - edges[BSRight].width - innerBorderAdjustment.x());
bool usePath = renderRadii && (borderStyleHasInnerDetail(edges[BSRight].style) || borderWillArcInnerEdge(innerBorder.radii().bottomRight(), innerBorder.radii().topRight()));
paintOneBorderSide(graphicsContext, style, outerBorder, innerBorder, sideRect, BSRight, BSTop, BSBottom, edges, usePath ? &roundedPath : 0, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, overrideColor);
}
}
void RenderBoxModelObject::paintTranslucentBorderSides(GraphicsContext* graphicsContext, const RenderStyle* style, const RoundedRect& outerBorder, const RoundedRect& innerBorder, const IntPoint& innerBorderAdjustment,
const BorderEdge edges[], BorderEdgeFlags edgesToDraw, BackgroundBleedAvoidance bleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias)
{
static const BoxSide paintOrder[] = { BSTop, BSBottom, BSLeft, BSRight };
while (edgesToDraw) {
Color commonColor;
BorderEdgeFlags commonColorEdgeSet = 0;
for (size_t i = 0; i < sizeof(paintOrder) / sizeof(paintOrder[0]); ++i) {
BoxSide currSide = paintOrder[i];
if (!includesEdge(edgesToDraw, currSide))
continue;
bool includeEdge;
if (!commonColorEdgeSet) {
commonColor = edges[currSide].color;
includeEdge = true;
} else
includeEdge = edges[currSide].color == commonColor;
if (includeEdge)
commonColorEdgeSet |= edgeFlagForSide(currSide);
}
bool useTransparencyLayer = includesAdjacentEdges(commonColorEdgeSet) && commonColor.hasAlpha();
if (useTransparencyLayer) {
graphicsContext->beginTransparencyLayer(static_cast<float>(commonColor.alpha()) / 255);
commonColor = Color(commonColor.red(), commonColor.green(), commonColor.blue());
}
paintBorderSides(graphicsContext, style, outerBorder, innerBorder, innerBorderAdjustment, edges, commonColorEdgeSet, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, &commonColor);
if (useTransparencyLayer)
graphicsContext->endLayer();
edgesToDraw &= ~commonColorEdgeSet;
}
}
void RenderBoxModelObject::paintBorder(const PaintInfo& info, const LayoutRect& rect, const RenderStyle* style,
BackgroundBleedAvoidance bleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge)
{
GraphicsContext* graphicsContext = info.context;
if (paintNinePieceImage(graphicsContext, rect, style, style->borderImage()))
return;
if (graphicsContext->paintingDisabled())
return;
BorderEdge edges[4];
getBorderEdgeInfo(edges, style, includeLogicalLeftEdge, includeLogicalRightEdge);
RoundedRect outerBorder = style->getRoundedBorderFor(rect, includeLogicalLeftEdge, includeLogicalRightEdge);
RoundedRect innerBorder = style->getRoundedInnerBorderFor(borderInnerRectAdjustedForBleedAvoidance(graphicsContext, rect, bleedAvoidance), includeLogicalLeftEdge, includeLogicalRightEdge);
bool haveAlphaColor = false;
bool haveAllSolidEdges = true;
bool haveAllDoubleEdges = true;
int numEdgesVisible = 4;
bool allEdgesShareColor = true;
bool allEdgesShareWidth = true;
int firstVisibleEdge = -1;
BorderEdgeFlags edgesToDraw = 0;
for (int i = BSTop; i <= BSLeft; ++i) {
const BorderEdge& currEdge = edges[i];
if (edges[i].shouldRender())
edgesToDraw |= edgeFlagForSide(static_cast<BoxSide>(i));
if (currEdge.presentButInvisible()) {
--numEdgesVisible;
allEdgesShareColor = false;
allEdgesShareWidth = false;
continue;
}
if (!currEdge.shouldRender()) {
--numEdgesVisible;
continue;
}
if (firstVisibleEdge == -1) {
firstVisibleEdge = i;
} else {
if (currEdge.color != edges[firstVisibleEdge].color)
allEdgesShareColor = false;
if (currEdge.width != edges[firstVisibleEdge].width)
allEdgesShareWidth = false;
}
if (currEdge.color.hasAlpha())
haveAlphaColor = true;
if (currEdge.style != SOLID)
haveAllSolidEdges = false;
if (currEdge.style != DOUBLE)
haveAllDoubleEdges = false;
}
if (haveAllSolidEdges && outerBorder.isRounded() && allCornersClippedOut(outerBorder, info.rect))
outerBorder.setRadii(RoundedRect::Radii());
if ((haveAllSolidEdges || haveAllDoubleEdges) && allEdgesShareColor && innerBorder.isRenderable()) {
if (numEdgesVisible == 4 && (outerBorder.isRounded() || haveAlphaColor)
&& (haveAllSolidEdges || (!outerBorder.isRounded() && !innerBorder.isRounded()))) {
Path path;
if (outerBorder.isRounded() && allEdgesShareWidth) {
graphicsContext->fillBetweenRoundedRects(outerBorder, innerBorder, edges[firstVisibleEdge].color);
return;
}
if (outerBorder.isRounded() && bleedAvoidance != BackgroundBleedClipBackground)
path.addRoundedRect(outerBorder);
else
path.addRect(outerBorder.rect());
if (haveAllDoubleEdges) {
IntRect innerThirdRect = outerBorder.rect();
IntRect outerThirdRect = outerBorder.rect();
for (int side = BSTop; side <= BSLeft; ++side) {
int outerWidth;
int innerWidth;
edges[side].getDoubleBorderStripeWidths(outerWidth, innerWidth);
if (side == BSTop) {
innerThirdRect.shiftYEdgeTo(innerThirdRect.y() + innerWidth);
outerThirdRect.shiftYEdgeTo(outerThirdRect.y() + outerWidth);
} else if (side == BSBottom) {
innerThirdRect.setHeight(innerThirdRect.height() - innerWidth);
outerThirdRect.setHeight(outerThirdRect.height() - outerWidth);
} else if (side == BSLeft) {
innerThirdRect.shiftXEdgeTo(innerThirdRect.x() + innerWidth);
outerThirdRect.shiftXEdgeTo(outerThirdRect.x() + outerWidth);
} else {
innerThirdRect.setWidth(innerThirdRect.width() - innerWidth);
outerThirdRect.setWidth(outerThirdRect.width() - outerWidth);
}
}
RoundedRect outerThird = outerBorder;
RoundedRect innerThird = innerBorder;
innerThird.setRect(innerThirdRect);
outerThird.setRect(outerThirdRect);
if (outerThird.isRounded() && bleedAvoidance != BackgroundBleedClipBackground)
path.addRoundedRect(outerThird);
else
path.addRect(outerThird.rect());
if (innerThird.isRounded() && bleedAvoidance != BackgroundBleedClipBackground)
path.addRoundedRect(innerThird);
else
path.addRect(innerThird.rect());
}
if (innerBorder.isRounded())
path.addRoundedRect(innerBorder);
else
path.addRect(innerBorder.rect());
graphicsContext->setFillRule(RULE_EVENODD);
graphicsContext->setFillColor(edges[firstVisibleEdge].color);
graphicsContext->fillPath(path);
return;
}
if (haveAllSolidEdges && numEdgesVisible != 4 && !outerBorder.isRounded() && haveAlphaColor) {
Path path;
for (int i = BSTop; i <= BSLeft; ++i) {
const BorderEdge& currEdge = edges[i];
if (currEdge.shouldRender()) {
IntRect sideRect = calculateSideRect(outerBorder, edges, i);
path.addRect(sideRect);
}
}
graphicsContext->setFillRule(RULE_NONZERO);
graphicsContext->setFillColor(edges[firstVisibleEdge].color);
graphicsContext->fillPath(path);
return;
}
}
bool clipToOuterBorder = outerBorder.isRounded();
GraphicsContextStateSaver stateSaver(*graphicsContext, clipToOuterBorder);
if (clipToOuterBorder) {
if (bleedAvoidance != BackgroundBleedClipBackground)
graphicsContext->clipRoundedRect(outerBorder);
if (innerBorder.isRenderable() && !innerBorder.isEmpty())
graphicsContext->clipOutRoundedRect(innerBorder);
}
bool antialias = shouldAntialiasLines(graphicsContext) || numEdgesVisible == 1;
RoundedRect unadjustedInnerBorder = (bleedAvoidance == BackgroundBleedBackgroundOverBorder) ? style->getRoundedInnerBorderFor(rect, includeLogicalLeftEdge, includeLogicalRightEdge) : innerBorder;
IntPoint innerBorderAdjustment(innerBorder.rect().x() - unadjustedInnerBorder.rect().x(), innerBorder.rect().y() - unadjustedInnerBorder.rect().y());
if (haveAlphaColor)
paintTranslucentBorderSides(graphicsContext, style, outerBorder, unadjustedInnerBorder, innerBorderAdjustment, edges, edgesToDraw, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias);
else
paintBorderSides(graphicsContext, style, outerBorder, unadjustedInnerBorder, innerBorderAdjustment, edges, edgesToDraw, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias);
}
void RenderBoxModelObject::drawBoxSideFromPath(GraphicsContext* graphicsContext, const LayoutRect& borderRect, const Path& borderPath, const BorderEdge edges[],
float thickness, float drawThickness, BoxSide side, const RenderStyle* style, Color color, EBorderStyle borderStyle, BackgroundBleedAvoidance bleedAvoidance,
bool includeLogicalLeftEdge, bool includeLogicalRightEdge)
{
if (thickness <= 0)
return;
if (borderStyle == DOUBLE && thickness < 3)
borderStyle = SOLID;
switch (borderStyle) {
case BNONE:
case BHIDDEN:
return;
case DOTTED:
case DASHED: {
graphicsContext->setStrokeColor(color);
graphicsContext->setStrokeThickness(drawThickness * 2 * 1.1f);
graphicsContext->setStrokeStyle(borderStyle == DASHED ? DashedStroke : DottedStroke);
float dashLength = thickness * ((borderStyle == DASHED) ? 3.0f : 1.0f);
float gapLength = dashLength;
float numberOfDashes = borderPath.length() / dashLength;
if (numberOfDashes >= 4) {
bool evenNumberOfFullDashes = !((int)numberOfDashes % 2);
bool integralNumberOfDashes = !(numberOfDashes - (int)numberOfDashes);
if (!evenNumberOfFullDashes && !integralNumberOfDashes) {
float numberOfGaps = numberOfDashes / 2;
gapLength += (dashLength / numberOfGaps);
}
DashArray lineDash;
lineDash.append(dashLength);
lineDash.append(gapLength);
graphicsContext->setLineDash(lineDash, dashLength);
}
graphicsContext->strokePath(borderPath);
return;
}
case DOUBLE: {
int outerBorderTopWidth;
int innerBorderTopWidth;
edges[BSTop].getDoubleBorderStripeWidths(outerBorderTopWidth, innerBorderTopWidth);
int outerBorderRightWidth;
int innerBorderRightWidth;
edges[BSRight].getDoubleBorderStripeWidths(outerBorderRightWidth, innerBorderRightWidth);
int outerBorderBottomWidth;
int innerBorderBottomWidth;
edges[BSBottom].getDoubleBorderStripeWidths(outerBorderBottomWidth, innerBorderBottomWidth);
int outerBorderLeftWidth;
int innerBorderLeftWidth;
edges[BSLeft].getDoubleBorderStripeWidths(outerBorderLeftWidth, innerBorderLeftWidth);
{
GraphicsContextStateSaver stateSaver(*graphicsContext);
RoundedRect innerClip = style->getRoundedInnerBorderFor(borderRect,
innerBorderTopWidth, innerBorderBottomWidth, innerBorderLeftWidth, innerBorderRightWidth,
includeLogicalLeftEdge, includeLogicalRightEdge);
graphicsContext->clipRoundedRect(innerClip);
drawBoxSideFromPath(graphicsContext, borderRect, borderPath, edges, thickness, drawThickness, side, style, color, SOLID, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge);
}
{
GraphicsContextStateSaver stateSaver(*graphicsContext);
LayoutRect outerRect = borderRect;
if (bleedAvoidance == BackgroundBleedClipBackground) {
outerRect.inflate(1);
++outerBorderTopWidth;
++outerBorderBottomWidth;
++outerBorderLeftWidth;
++outerBorderRightWidth;
}
RoundedRect outerClip = style->getRoundedInnerBorderFor(outerRect,
outerBorderTopWidth, outerBorderBottomWidth, outerBorderLeftWidth, outerBorderRightWidth,
includeLogicalLeftEdge, includeLogicalRightEdge);
graphicsContext->clipOutRoundedRect(outerClip);
drawBoxSideFromPath(graphicsContext, borderRect, borderPath, edges, thickness, drawThickness, side, style, color, SOLID, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge);
}
return;
}
case RIDGE:
case GROOVE:
{
EBorderStyle s1;
EBorderStyle s2;
if (borderStyle == GROOVE) {
s1 = INSET;
s2 = OUTSET;
} else {
s1 = OUTSET;
s2 = INSET;
}
drawBoxSideFromPath(graphicsContext, borderRect, borderPath, edges, thickness, drawThickness, side, style, color, s1, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge);
GraphicsContextStateSaver stateSaver(*graphicsContext);
LayoutUnit topWidth = edges[BSTop].usedWidth() / 2;
LayoutUnit bottomWidth = edges[BSBottom].usedWidth() / 2;
LayoutUnit leftWidth = edges[BSLeft].usedWidth() / 2;
LayoutUnit rightWidth = edges[BSRight].usedWidth() / 2;
RoundedRect clipRect = style->getRoundedInnerBorderFor(borderRect,
topWidth, bottomWidth, leftWidth, rightWidth,
includeLogicalLeftEdge, includeLogicalRightEdge);
graphicsContext->clipRoundedRect(clipRect);
drawBoxSideFromPath(graphicsContext, borderRect, borderPath, edges, thickness, drawThickness, side, style, color, s2, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge);
return;
}
case INSET:
if (side == BSTop || side == BSLeft)
color = color.dark();
break;
case OUTSET:
if (side == BSBottom || side == BSRight)
color = color.dark();
break;
default:
break;
}
graphicsContext->setStrokeStyle(NoStroke);
graphicsContext->setFillColor(color);
graphicsContext->drawRect(pixelSnappedIntRect(borderRect));
}
void RenderBoxModelObject::clipBorderSidePolygon(GraphicsContext* graphicsContext, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
BoxSide side, bool firstEdgeMatches, bool secondEdgeMatches)
{
FloatPoint quad[4];
const LayoutRect& outerRect = outerBorder.rect();
const LayoutRect& innerRect = innerBorder.rect();
FloatPoint centerPoint(innerRect.location().x().toFloat() + innerRect.width().toFloat() / 2, innerRect.location().y().toFloat() + innerRect.height().toFloat() / 2);
switch (side) {
case BSTop:
quad[0] = outerRect.minXMinYCorner();
quad[1] = innerRect.minXMinYCorner();
quad[2] = innerRect.maxXMinYCorner();
quad[3] = outerRect.maxXMinYCorner();
if (!innerBorder.radii().topLeft().isZero()) {
findIntersection(quad[0], quad[1],
FloatPoint(
quad[1].x() + innerBorder.radii().topLeft().width(),
quad[1].y()),
FloatPoint(
quad[1].x(),
quad[1].y() + innerBorder.radii().topLeft().height()),
quad[1]);
}
if (!innerBorder.radii().topRight().isZero()) {
findIntersection(quad[3], quad[2],
FloatPoint(
quad[2].x() - innerBorder.radii().topRight().width(),
quad[2].y()),
FloatPoint(
quad[2].x(),
quad[2].y() + innerBorder.radii().topRight().height()),
quad[2]);
}
break;
case BSLeft:
quad[0] = outerRect.minXMinYCorner();
quad[1] = innerRect.minXMinYCorner();
quad[2] = innerRect.minXMaxYCorner();
quad[3] = outerRect.minXMaxYCorner();
if (!innerBorder.radii().topLeft().isZero()) {
findIntersection(quad[0], quad[1],
FloatPoint(
quad[1].x() + innerBorder.radii().topLeft().width(),
quad[1].y()),
FloatPoint(
quad[1].x(),
quad[1].y() + innerBorder.radii().topLeft().height()),
quad[1]);
}
if (!innerBorder.radii().bottomLeft().isZero()) {
findIntersection(quad[3], quad[2],
FloatPoint(
quad[2].x() + innerBorder.radii().bottomLeft().width(),
quad[2].y()),
FloatPoint(
quad[2].x(),
quad[2].y() - innerBorder.radii().bottomLeft().height()),
quad[2]);
}
break;
case BSBottom:
quad[0] = outerRect.minXMaxYCorner();
quad[1] = innerRect.minXMaxYCorner();
quad[2] = innerRect.maxXMaxYCorner();
quad[3] = outerRect.maxXMaxYCorner();
if (!innerBorder.radii().bottomLeft().isZero()) {
findIntersection(quad[0], quad[1],
FloatPoint(
quad[1].x() + innerBorder.radii().bottomLeft().width(),
quad[1].y()),
FloatPoint(
quad[1].x(),
quad[1].y() - innerBorder.radii().bottomLeft().height()),
quad[1]);
}
if (!innerBorder.radii().bottomRight().isZero()) {
findIntersection(quad[3], quad[2],
FloatPoint(
quad[2].x() - innerBorder.radii().bottomRight().width(),
quad[2].y()),
FloatPoint(
quad[2].x(),
quad[2].y() - innerBorder.radii().bottomRight().height()),
quad[2]);
}
break;
case BSRight:
quad[0] = outerRect.maxXMinYCorner();
quad[1] = innerRect.maxXMinYCorner();
quad[2] = innerRect.maxXMaxYCorner();
quad[3] = outerRect.maxXMaxYCorner();
if (!innerBorder.radii().topRight().isZero()) {
findIntersection(quad[0], quad[1],
FloatPoint(
quad[1].x() - innerBorder.radii().topRight().width(),
quad[1].y()),
FloatPoint(
quad[1].x(),
quad[1].y() + innerBorder.radii().topRight().height()),
quad[1]);
}
if (!innerBorder.radii().bottomRight().isZero()) {
findIntersection(quad[3], quad[2],
FloatPoint(
quad[2].x() - innerBorder.radii().bottomRight().width(),
quad[2].y()),
FloatPoint(
quad[2].x(),
quad[2].y() - innerBorder.radii().bottomRight().height()),
quad[2]);
}
break;
}
if (firstEdgeMatches == secondEdgeMatches) {
graphicsContext->clipConvexPolygon(4, quad, !firstEdgeMatches);
return;
}
float ax = quad[1].x() - quad[0].x();
float ay = quad[1].y() - quad[0].y();
float bx = quad[2].x() - quad[1].x();
float by = quad[2].y() - quad[1].y();
float cx = quad[3].x() - quad[2].x();
float cy = quad[3].y() - quad[2].y();
const static float kEpsilon = 1e-2f;
float r1, r2;
if (fabsf(bx) < kEpsilon && fabsf(by) < kEpsilon) {
r1 = r2 = 1.0f;
} else {
const static float kExtendFill = 1e-2f;
r1 = (-ax * by + ay * bx) / (cx * by - cy * bx) + kExtendFill;
r2 = (-cx * by + cy * bx) / (ax * by - ay * bx) + kExtendFill;
}
FloatPoint firstQuad[4];
firstQuad[0] = quad[0];
firstQuad[1] = quad[1];
firstQuad[2] = FloatPoint(quad[3].x() + r2 * ax, quad[3].y() + r2 * ay);
firstQuad[3] = quad[3];
graphicsContext->clipConvexPolygon(4, firstQuad, !firstEdgeMatches);
FloatPoint secondQuad[4];
secondQuad[0] = quad[0];
secondQuad[1] = FloatPoint(quad[0].x() - r1 * cx, quad[0].y() - r1 * cy);
secondQuad[2] = quad[2];
secondQuad[3] = quad[3];
graphicsContext->clipConvexPolygon(4, secondQuad, !secondEdgeMatches);
}
static IntRect calculateSideRectIncludingInner(const RoundedRect& outerBorder, const BorderEdge edges[], BoxSide side)
{
IntRect sideRect = outerBorder.rect();
int width;
switch (side) {
case BSTop:
width = sideRect.height() - edges[BSBottom].width;
sideRect.setHeight(width);
break;
case BSBottom:
width = sideRect.height() - edges[BSTop].width;
sideRect.shiftYEdgeTo(sideRect.maxY() - width);
break;
case BSLeft:
width = sideRect.width() - edges[BSRight].width;
sideRect.setWidth(width);
break;
case BSRight:
width = sideRect.width() - edges[BSLeft].width;
sideRect.shiftXEdgeTo(sideRect.maxX() - width);
break;
}
return sideRect;
}
static RoundedRect calculateAdjustedInnerBorder(const RoundedRect&innerBorder, BoxSide side)
{
RoundedRect::Radii newRadii = innerBorder.radii();
IntRect newRect = innerBorder.rect();
float overshoot;
float maxRadii;
switch (side) {
case BSTop:
overshoot = newRadii.topLeft().width() + newRadii.topRight().width() - newRect.width();
if (overshoot > 0) {
ASSERT(!(newRadii.topLeft().width() && newRadii.topRight().width()));
newRect.setWidth(newRect.width() + overshoot);
if (!newRadii.topLeft().width())
newRect.move(-overshoot, 0);
}
newRadii.setBottomLeft(IntSize(0, 0));
newRadii.setBottomRight(IntSize(0, 0));
maxRadii = max(newRadii.topLeft().height(), newRadii.topRight().height());
if (maxRadii > newRect.height())
newRect.setHeight(maxRadii);
break;
case BSBottom:
overshoot = newRadii.bottomLeft().width() + newRadii.bottomRight().width() - newRect.width();
if (overshoot > 0) {
ASSERT(!(newRadii.bottomLeft().width() && newRadii.bottomRight().width()));
newRect.setWidth(newRect.width() + overshoot);
if (!newRadii.bottomLeft().width())
newRect.move(-overshoot, 0);
}
newRadii.setTopLeft(IntSize(0, 0));
newRadii.setTopRight(IntSize(0, 0));
maxRadii = max(newRadii.bottomLeft().height(), newRadii.bottomRight().height());
if (maxRadii > newRect.height()) {
newRect.move(0, newRect.height() - maxRadii);
newRect.setHeight(maxRadii);
}
break;
case BSLeft:
overshoot = newRadii.topLeft().height() + newRadii.bottomLeft().height() - newRect.height();
if (overshoot > 0) {
ASSERT(!(newRadii.topLeft().height() && newRadii.bottomLeft().height()));
newRect.setHeight(newRect.height() + overshoot);
if (!newRadii.topLeft().height())
newRect.move(0, -overshoot);
}
newRadii.setTopRight(IntSize(0, 0));
newRadii.setBottomRight(IntSize(0, 0));
maxRadii = max(newRadii.topLeft().width(), newRadii.bottomLeft().width());
if (maxRadii > newRect.width())
newRect.setWidth(maxRadii);
break;
case BSRight:
overshoot = newRadii.topRight().height() + newRadii.bottomRight().height() - newRect.height();
if (overshoot > 0) {
ASSERT(!(newRadii.topRight().height() && newRadii.bottomRight().height()));
newRect.setHeight(newRect.height() + overshoot);
if (!newRadii.topRight().height())
newRect.move(0, -overshoot);
}
newRadii.setTopLeft(IntSize(0, 0));
newRadii.setBottomLeft(IntSize(0, 0));
maxRadii = max(newRadii.topRight().width(), newRadii.bottomRight().width());
if (maxRadii > newRect.width()) {
newRect.move(newRect.width() - maxRadii, 0);
newRect.setWidth(maxRadii);
}
break;
}
return RoundedRect(newRect, newRadii);
}
void RenderBoxModelObject::clipBorderSideForComplexInnerPath(GraphicsContext* graphicsContext, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
BoxSide side, const class BorderEdge edges[])
{
graphicsContext->clip(calculateSideRectIncludingInner(outerBorder, edges, side));
RoundedRect adjustedInnerRect = calculateAdjustedInnerBorder(innerBorder, side);
if (!adjustedInnerRect.isEmpty())
graphicsContext->clipOutRoundedRect(adjustedInnerRect);
}
void RenderBoxModelObject::getBorderEdgeInfo(BorderEdge edges[], const RenderStyle* style, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
{
bool horizontal = style->isHorizontalWritingMode();
edges[BSTop] = BorderEdge(style->borderTopWidth(),
resolveColor(style, CSSPropertyBorderTopColor),
style->borderTopStyle(),
style->borderTopIsTransparent(),
horizontal || includeLogicalLeftEdge);
edges[BSRight] = BorderEdge(style->borderRightWidth(),
resolveColor(style, CSSPropertyBorderRightColor),
style->borderRightStyle(),
style->borderRightIsTransparent(),
!horizontal || includeLogicalRightEdge);
edges[BSBottom] = BorderEdge(style->borderBottomWidth(),
resolveColor(style, CSSPropertyBorderBottomColor),
style->borderBottomStyle(),
style->borderBottomIsTransparent(),
horizontal || includeLogicalRightEdge);
edges[BSLeft] = BorderEdge(style->borderLeftWidth(),
resolveColor(style, CSSPropertyBorderLeftColor),
style->borderLeftStyle(),
style->borderLeftIsTransparent(),
!horizontal || includeLogicalLeftEdge);
}
bool RenderBoxModelObject::borderObscuresBackgroundEdge(const FloatSize& contextScale) const
{
BorderEdge edges[4];
getBorderEdgeInfo(edges, style());
for (int i = BSTop; i <= BSLeft; ++i) {
const BorderEdge& currEdge = edges[i];
float axisScale = (i == BSTop || i == BSBottom) ? contextScale.height() : contextScale.width();
if (!currEdge.obscuresBackgroundEdge(axisScale))
return false;
}
return true;
}
bool RenderBoxModelObject::borderObscuresBackground() const
{
if (!style()->hasBorder())
return false;
if (style()->borderImage().image())
return false;
BorderEdge edges[4];
getBorderEdgeInfo(edges, style());
for (int i = BSTop; i <= BSLeft; ++i) {
const BorderEdge& currEdge = edges[i];
if (!currEdge.obscuresBackground())
return false;
}
return true;
}
bool RenderBoxModelObject::boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance bleedAvoidance, InlineFlowBox* inlineFlowBox) const
{
if (bleedAvoidance != BackgroundBleedNone)
return false;
if (style()->hasAppearance())
return false;
const ShadowList* shadowList = style()->boxShadow();
if (!shadowList)
return false;
bool hasOneNormalBoxShadow = false;
size_t shadowCount = shadowList->shadows().size();
for (size_t i = 0; i < shadowCount; ++i) {
const ShadowData& currentShadow = shadowList->shadows()[i];
if (currentShadow.style() != Normal)
continue;
if (hasOneNormalBoxShadow)
return false;
hasOneNormalBoxShadow = true;
if (currentShadow.spread())
return false;
}
if (!hasOneNormalBoxShadow)
return false;
Color backgroundColor = resolveColor(CSSPropertyBackgroundColor);
if (backgroundColor.hasAlpha())
return false;
const FillLayer* lastBackgroundLayer = style()->backgroundLayers();
for (const FillLayer* next = lastBackgroundLayer->next(); next; next = lastBackgroundLayer->next())
lastBackgroundLayer = next;
if (lastBackgroundLayer->clip() != BorderFillBox)
return false;
if (lastBackgroundLayer->image() && style()->hasBorderRadius())
return false;
if (inlineFlowBox && !inlineFlowBox->boxShadowCanBeAppliedToBackground(*lastBackgroundLayer))
return false;
if (hasOverflowClip() && lastBackgroundLayer->attachment() == LocalBackgroundAttachment)
return false;
return true;
}
void RenderBoxModelObject::paintBoxShadow(const PaintInfo& info, const LayoutRect& paintRect, const RenderStyle* s, ShadowStyle shadowStyle, bool includeLogicalLeftEdge, bool includeLogicalRightEdge)
{
GraphicsContext* context = info.context;
if (context->paintingDisabled() || !s->boxShadow())
return;
RoundedRect border = (shadowStyle == Inset) ? s->getRoundedInnerBorderFor(paintRect, includeLogicalLeftEdge, includeLogicalRightEdge)
: s->getRoundedBorderFor(paintRect, includeLogicalLeftEdge, includeLogicalRightEdge);
bool hasBorderRadius = s->hasBorderRadius();
bool isHorizontal = s->isHorizontalWritingMode();
bool hasOpaqueBackground = s->visitedDependentColor(CSSPropertyBackgroundColor).alpha() == 255;
GraphicsContextStateSaver stateSaver(*context, false);
const ShadowList* shadowList = s->boxShadow();
for (size_t i = shadowList->shadows().size(); i--; ) {
const ShadowData& shadow = shadowList->shadows()[i];
if (shadow.style() != shadowStyle)
continue;
FloatSize shadowOffset(shadow.x(), shadow.y());
float shadowBlur = shadow.blur();
float shadowSpread = shadow.spread();
if (shadowOffset.isZero() && !shadowBlur && !shadowSpread)
continue;
const Color& shadowColor = shadow.color();
if (shadow.style() == Normal) {
FloatRect fillRect = border.rect();
fillRect.inflate(shadowSpread);
if (fillRect.isEmpty())
continue;
FloatRect shadowRect(border.rect());
shadowRect.inflate(shadowBlur + shadowSpread);
shadowRect.move(shadowOffset);
if (!stateSaver.saved()) {
stateSaver.save();
if (hasBorderRadius) {
RoundedRect rectToClipOut = border;
if (hasOpaqueBackground)
rectToClipOut.inflateWithRadii(-1);
if (!rectToClipOut.isEmpty()) {
context->clipOutRoundedRect(rectToClipOut);
}
} else {
IntRect rectToClipOut = border.rect();
if (hasOpaqueBackground) {
AffineTransform transform = context->getCTM();
if (transform.a() != 1 || (transform.d() != 1 && transform.d() != -1) || transform.b() || transform.c())
rectToClipOut.inflate(-1);
}
if (!rectToClipOut.isEmpty()) {
context->clipOut(rectToClipOut);
}
}
}
OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create();
drawLooperBuilder->addShadow(shadowOffset, shadowBlur, shadowColor,
DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::ShadowIgnoresAlpha);
context->setDrawLooper(drawLooperBuilder.release());
if (hasBorderRadius) {
RoundedRect influenceRect(pixelSnappedIntRect(LayoutRect(shadowRect)), border.radii());
influenceRect.expandRadii(2 * shadowBlur + shadowSpread);
if (allCornersClippedOut(influenceRect, info.rect))
context->fillRect(fillRect, Color::black);
else {
RoundedRect roundedFillRect = border;
roundedFillRect.inflate(shadowSpread);
roundedFillRect.expandRadii(shadowSpread);
if (!roundedFillRect.isRenderable())
roundedFillRect.adjustRadii();
context->fillRoundedRect(roundedFillRect, Color::black);
}
} else {
context->fillRect(fillRect, Color::black);
}
} else {
GraphicsContext::Edges clippedEdges = GraphicsContext::NoEdge;
if (!includeLogicalLeftEdge) {
if (isHorizontal)
clippedEdges |= GraphicsContext::LeftEdge;
else
clippedEdges |= GraphicsContext::TopEdge;
}
if (!includeLogicalRightEdge) {
if (isHorizontal)
clippedEdges |= GraphicsContext::RightEdge;
else
clippedEdges |= GraphicsContext::BottomEdge;
}
context->drawInnerShadow(border, shadowColor, flooredIntSize(shadowOffset), shadowBlur, shadowSpread, clippedEdges);
}
}
}
LayoutUnit RenderBoxModelObject::containingBlockLogicalWidthForContent() const
{
return containingBlock()->availableLogicalWidth();
}
RenderBoxModelObject* RenderBoxModelObject::continuation() const
{
if (!continuationMap)
return 0;
return continuationMap->get(this);
}
void RenderBoxModelObject::setContinuation(RenderBoxModelObject* continuation)
{
if (continuation) {
if (!continuationMap)
continuationMap = new ContinuationMap;
continuationMap->set(this, continuation);
} else {
if (continuationMap)
continuationMap->remove(this);
}
}
void RenderBoxModelObject::computeLayerHitTestRects(LayerHitTestRects& rects) const
{
RenderLayerModelObject::computeLayerHitTestRects(rects);
if (continuation())
continuation()->computeLayerHitTestRects(rects);
}
RenderTextFragment* RenderBoxModelObject::firstLetterRemainingText() const
{
if (!firstLetterRemainingTextMap)
return 0;
return firstLetterRemainingTextMap->get(this);
}
void RenderBoxModelObject::setFirstLetterRemainingText(RenderTextFragment* remainingText)
{
if (remainingText) {
if (!firstLetterRemainingTextMap)
firstLetterRemainingTextMap = new FirstLetterRemainingTextMap;
firstLetterRemainingTextMap->set(this, remainingText);
} else if (firstLetterRemainingTextMap)
firstLetterRemainingTextMap->remove(this);
}
LayoutRect RenderBoxModelObject::localCaretRectForEmptyElement(LayoutUnit width, LayoutUnit textIndentOffset)
{
ASSERT(!firstChild());
RenderStyle* currentStyle = firstLineStyle();
LayoutUnit height = lineHeight(true, currentStyle->isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes);
enum CaretAlignment { alignLeft, alignRight, alignCenter };
CaretAlignment alignment = alignLeft;
switch (currentStyle->textAlign()) {
case LEFT:
case WEBKIT_LEFT:
break;
case CENTER:
case WEBKIT_CENTER:
alignment = alignCenter;
break;
case RIGHT:
case WEBKIT_RIGHT:
alignment = alignRight;
break;
case JUSTIFY:
case TASTART:
if (!currentStyle->isLeftToRightDirection())
alignment = alignRight;
break;
case TAEND:
if (currentStyle->isLeftToRightDirection())
alignment = alignRight;
break;
}
LayoutUnit x = borderLeft() + paddingLeft();
LayoutUnit maxX = width - borderRight() - paddingRight();
switch (alignment) {
case alignLeft:
if (currentStyle->isLeftToRightDirection())
x += textIndentOffset;
break;
case alignCenter:
x = (x + maxX) / 2;
if (currentStyle->isLeftToRightDirection())
x += textIndentOffset / 2;
else
x -= textIndentOffset / 2;
break;
case alignRight:
x = maxX - caretWidth;
if (!currentStyle->isLeftToRightDirection())
x -= textIndentOffset;
break;
}
x = min(x, max<LayoutUnit>(maxX - caretWidth, 0));
LayoutUnit y = paddingTop() + borderTop();
return currentStyle->isHorizontalWritingMode() ? LayoutRect(x, y, caretWidth, height) : LayoutRect(y, x, height, caretWidth);
}
bool RenderBoxModelObject::shouldAntialiasLines(GraphicsContext* context)
{
return !context->getCTM().isIdentityOrTranslationOrFlipped();
}
void RenderBoxModelObject::mapAbsoluteToLocalPoint(MapCoordinatesFlags mode, TransformState& transformState) const
{
ASSERT(!view() || !view()->layoutStateEnabled());
RenderObject* o = container();
if (!o)
return;
if (o->isRenderFlowThread() && isRenderBlock()) {
RenderRegion* startRegion;
RenderRegion* ignoredEndRegion;
toRenderFlowThread(o)->getRegionRangeForBox(toRenderBlock(this), startRegion, ignoredEndRegion);
if (startRegion)
o = startRegion;
}
o->mapAbsoluteToLocalPoint(mode, transformState);
LayoutSize containerOffset = offsetFromContainer(o, LayoutPoint());
if (!style()->hasOutOfFlowPosition() && o->hasColumns()) {
RenderBlock* block = toRenderBlock(o);
LayoutPoint point(roundedLayoutPoint(transformState.mappedPoint()));
point -= containerOffset;
block->adjustForColumnRect(containerOffset, point);
}
bool preserve3D = mode & UseTransforms && (o->style()->preserves3D() || style()->preserves3D());
if (mode & UseTransforms && shouldUseTransformFromContainer(o)) {
TransformationMatrix t;
getTransformFromContainer(o, containerOffset, t);
transformState.applyTransform(t, preserve3D ? TransformState::AccumulateTransform : TransformState::FlattenTransform);
} else
transformState.move(containerOffset.width(), containerOffset.height(), preserve3D ? TransformState::AccumulateTransform : TransformState::FlattenTransform);
}
const RenderObject* RenderBoxModelObject::pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
{
ASSERT(ancestorToStopAt != this);
bool ancestorSkipped;
RenderObject* container = this->container(ancestorToStopAt, &ancestorSkipped);
if (!container)
return 0;
bool isInline = isRenderInline();
bool isFixedPos = !isInline && style()->position() == FixedPosition;
bool hasTransform = !isInline && hasLayer() && layer()->transform();
LayoutSize adjustmentForSkippedAncestor;
if (ancestorSkipped) {
adjustmentForSkippedAncestor = -ancestorToStopAt->offsetFromAncestorContainer(container);
}
bool offsetDependsOnPoint = false;
LayoutSize containerOffset = offsetFromContainer(container, LayoutPoint(), &offsetDependsOnPoint);
bool preserve3D = container->style()->preserves3D() || style()->preserves3D();
if (shouldUseTransformFromContainer(container)) {
TransformationMatrix t;
getTransformFromContainer(container, containerOffset, t);
t.translateRight(adjustmentForSkippedAncestor.width().toFloat(), adjustmentForSkippedAncestor.height().toFloat());
geometryMap.push(this, t, preserve3D, offsetDependsOnPoint, isFixedPos, hasTransform);
} else {
containerOffset += adjustmentForSkippedAncestor;
geometryMap.push(this, containerOffset, preserve3D, offsetDependsOnPoint, isFixedPos, hasTransform);
}
return ancestorSkipped ? ancestorToStopAt : container;
}
void RenderBoxModelObject::moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, RenderObject* beforeChild, bool fullRemoveInsert)
{
ASSERT(!fullRemoveInsert || !isRenderBlock() || !toRenderBlock(this)->hasPositionedObjects());
ASSERT(this == child->parent());
ASSERT(!beforeChild || toBoxModelObject == beforeChild->parent());
if (fullRemoveInsert && (toBoxModelObject->isRenderBlock() || toBoxModelObject->isRenderInline())) {
toBoxModelObject->addChild(virtualChildren()->removeChildNode(this, child), beforeChild);
} else
toBoxModelObject->virtualChildren()->insertChildNode(toBoxModelObject, virtualChildren()->removeChildNode(this, child, fullRemoveInsert), beforeChild, fullRemoveInsert);
}
void RenderBoxModelObject::moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, RenderObject* beforeChild, bool fullRemoveInsert)
{
if (fullRemoveInsert && isRenderBlock()) {
RenderBlock* block = toRenderBlock(this);
block->removePositionedObjects(0);
if (block->isRenderBlockFlow())
toRenderBlockFlow(block)->removeFloatingObjects();
}
ASSERT(!beforeChild || toBoxModelObject == beforeChild->parent());
for (RenderObject* child = startChild; child && child != endChild; ) {
RenderObject* nextSibling = child->nextSibling();
moveChildTo(toBoxModelObject, child, beforeChild, fullRemoveInsert);
child = nextSibling;
}
}
}