Chromium Code Reviews| Index: Source/core/paint/ContentBoxRadiusClipper.cpp |
| diff --git a/Source/core/paint/ContentBoxRadiusClipper.cpp b/Source/core/paint/ContentBoxRadiusClipper.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..15a836232750cd10fa1af6ffe9f86e117037f7fb |
| --- /dev/null |
| +++ b/Source/core/paint/ContentBoxRadiusClipper.cpp |
| @@ -0,0 +1,96 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "core/paint/ContentBoxRadiusClipper.h" |
| + |
| +#include "core/rendering/PaintInfo.h" |
| +#include "core/rendering/RenderBox.h" |
| +#include "platform/graphics/paint/ClipDisplayItem.h" |
| +#include "platform/graphics/paint/DisplayItemList.h" |
| + |
| +namespace blink { |
| + |
| +ContentBoxRadiusClipper::ContentBoxRadiusClipper(RenderBox& box, const PaintInfo& paintInfo, const LayoutPoint& accumulatedOffset) |
| + : m_box(box) |
| + , m_paintInfo(paintInfo) |
| + , m_pushedClip(false) |
| + , m_completelyClipped(false) |
| +{ |
| + if (!box.style()->hasBorderRadius()) |
| + return; |
| + |
| + LayoutRect borderRect = LayoutRect(accumulatedOffset, m_box.size()); |
| + |
| + FloatRoundedRect roundedContentBox = box.style()->getRoundedInnerBorderFor(borderRect, |
| + box.paddingTop() + box.borderTop(), |
| + box.paddingBottom() + box.borderBottom(), |
| + box.paddingLeft() + box.borderLeft(), |
| + box.paddingRight() + box.borderRight(), true, true); |
| + |
| + if (roundedContentBox.isEmpty()) { |
| + m_completelyClipped = true; |
| + return; |
| + } |
| + |
| + DisplayItem::Type clipType = DisplayItem::ClipBoxForeground; |
| + if (RuntimeEnabledFeatures::slimmingPaintEnabled()) |
| + clipType = m_paintInfo.displayItemTypeForClipping(); |
| + |
| + OwnPtr<ClipDisplayItem> clipDisplayItem = ClipDisplayItem::create(box.displayItemClient(), clipType, pixelSnappedIntRect(borderRect)); |
| + |
| + if (roundedContentBox.isRenderable()) { |
|
chrishtr
2015/01/23 05:07:12
I don't get it. Where is all the logic in this cla
|
| + clipDisplayItem->roundedRectClips().append(roundedContentBox); |
| + } else { |
| + // We create a rounded rect for each of the corners and clip it, while making sure we clip opposing corners together. |
| + if (!roundedContentBox.radii().topLeft().isEmpty() || !roundedContentBox.radii().bottomRight().isEmpty()) { |
| + FloatRect topCorner(roundedContentBox.rect().x(), roundedContentBox.rect().y(), borderRect.maxX() - roundedContentBox.rect().x(), borderRect.maxY() - roundedContentBox.rect().y()); |
| + FloatRoundedRect::Radii topCornerRadii; |
| + topCornerRadii.setTopLeft(roundedContentBox.radii().topLeft()); |
| + clipDisplayItem->roundedRectClips().append(FloatRoundedRect(topCorner, topCornerRadii)); |
| + |
| + FloatRect bottomCorner(borderRect.x().toFloat(), borderRect.y().toFloat(), roundedContentBox.rect().maxX() - borderRect.x().toFloat(), roundedContentBox.rect().maxY() - borderRect.y().toFloat()); |
| + FloatRoundedRect::Radii bottomCornerRadii; |
| + bottomCornerRadii.setBottomRight(roundedContentBox.radii().bottomRight()); |
| + clipDisplayItem->roundedRectClips().append(FloatRoundedRect(bottomCorner, bottomCornerRadii)); |
| + } |
| + |
| + if (!roundedContentBox.radii().topRight().isEmpty() || !roundedContentBox.radii().bottomLeft().isEmpty()) { |
| + FloatRect topCorner(borderRect.x().toFloat(), roundedContentBox.rect().y(), roundedContentBox.rect().maxX() - borderRect.x().toFloat(), borderRect.maxY() - roundedContentBox.rect().y()); |
| + FloatRoundedRect::Radii topCornerRadii; |
| + topCornerRadii.setTopRight(roundedContentBox.radii().topRight()); |
| + clipDisplayItem->roundedRectClips().append(FloatRoundedRect(topCorner, topCornerRadii)); |
| + |
| + FloatRect bottomCorner(roundedContentBox.rect().x(), borderRect.y().toFloat(), borderRect.maxX() - roundedContentBox.rect().x(), roundedContentBox.rect().maxY() - borderRect.y().toFloat()); |
| + FloatRoundedRect::Radii bottomCornerRadii; |
| + bottomCornerRadii.setBottomLeft(roundedContentBox.radii().bottomLeft()); |
| + clipDisplayItem->roundedRectClips().append(FloatRoundedRect(bottomCorner, bottomCornerRadii)); |
| + } |
| + } |
| + |
| + if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
| + ASSERT(m_paintInfo.context->displayItemList()); |
| + m_paintInfo.context->displayItemList()->add(clipDisplayItem.release()); |
| + } else { |
| + clipDisplayItem->replay(paintInfo.context); |
| + } |
| + m_pushedClip = true; |
| +} |
| + |
| +ContentBoxRadiusClipper::~ContentBoxRadiusClipper() |
| +{ |
| + if (!m_pushedClip) |
| + return; |
| + |
| + OwnPtr<EndClipDisplayItem> endClipDisplayItem = EndClipDisplayItem::create(m_box.displayItemClient()); |
| + |
| + if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
| + ASSERT(m_paintInfo.context->displayItemList()); |
| + m_paintInfo.context->displayItemList()->add(endClipDisplayItem.release()); |
| + } else { |
| + endClipDisplayItem->replay(m_paintInfo.context); |
| + } |
| +} |
| + |
| +} // namespace blink |