OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/paint/RoundedInnerRectClipper.h" |
| 7 |
| 8 #include "core/rendering/PaintInfo.h" |
| 9 #include "core/rendering/RenderBox.h" |
| 10 #include "platform/graphics/paint/ClipDisplayItem.h" |
| 11 #include "platform/graphics/paint/DisplayItemList.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 RoundedInnerRectClipper::RoundedInnerRectClipper(RenderObject& renderer, const P
aintInfo& paintInfo, const LayoutRect& rect, const FloatRoundedRect& clipRect, R
oundedInnerRectClipperBehavior behavior) |
| 16 : m_renderer(renderer) |
| 17 , m_paintInfo(paintInfo) |
| 18 , m_useDisplayItemList(RuntimeEnabledFeatures::slimmingPaintEnabled() && beh
avior == ApplyToDisplayListIfEnabled) |
| 19 { |
| 20 DisplayItem::Type clipType = m_useDisplayItemList ? m_paintInfo.displayItemT
ypeForClipping() : DisplayItem::ClipBoxForeground; |
| 21 OwnPtr<ClipDisplayItem> clipDisplayItem = ClipDisplayItem::create(renderer.d
isplayItemClient(), clipType, LayoutRect::infiniteIntRect()); |
| 22 |
| 23 if (clipRect.isRenderable()) { |
| 24 clipDisplayItem->roundedRectClips().append(clipRect); |
| 25 } else { |
| 26 // We create a rounded rect for each of the corners and clip it, while m
aking sure we clip opposing corners together. |
| 27 if (!clipRect.radii().topLeft().isEmpty() || !clipRect.radii().bottomRig
ht().isEmpty()) { |
| 28 FloatRect topCorner(clipRect.rect().x(), clipRect.rect().y(), rect.m
axX() - clipRect.rect().x(), rect.maxY() - clipRect.rect().y()); |
| 29 FloatRoundedRect::Radii topCornerRadii; |
| 30 topCornerRadii.setTopLeft(clipRect.radii().topLeft()); |
| 31 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(topCorne
r, topCornerRadii)); |
| 32 |
| 33 FloatRect bottomCorner(rect.x().toFloat(), rect.y().toFloat(), clipR
ect.rect().maxX() - rect.x().toFloat(), clipRect.rect().maxY() - rect.y().toFloa
t()); |
| 34 FloatRoundedRect::Radii bottomCornerRadii; |
| 35 bottomCornerRadii.setBottomRight(clipRect.radii().bottomRight()); |
| 36 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(bottomCo
rner, bottomCornerRadii)); |
| 37 } |
| 38 |
| 39 if (!clipRect.radii().topRight().isEmpty() || !clipRect.radii().bottomLe
ft().isEmpty()) { |
| 40 FloatRect topCorner(rect.x().toFloat(), clipRect.rect().y(), clipRec
t.rect().maxX() - rect.x().toFloat(), rect.maxY() - clipRect.rect().y()); |
| 41 FloatRoundedRect::Radii topCornerRadii; |
| 42 topCornerRadii.setTopRight(clipRect.radii().topRight()); |
| 43 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(topCorne
r, topCornerRadii)); |
| 44 |
| 45 FloatRect bottomCorner(clipRect.rect().x(), rect.y().toFloat(), rect
.maxX() - clipRect.rect().x(), clipRect.rect().maxY() - rect.y().toFloat()); |
| 46 FloatRoundedRect::Radii bottomCornerRadii; |
| 47 bottomCornerRadii.setBottomLeft(clipRect.radii().bottomLeft()); |
| 48 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(bottomCo
rner, bottomCornerRadii)); |
| 49 } |
| 50 } |
| 51 |
| 52 if (m_useDisplayItemList) { |
| 53 ASSERT(m_paintInfo.context->displayItemList()); |
| 54 m_paintInfo.context->displayItemList()->add(clipDisplayItem.release()); |
| 55 } else { |
| 56 clipDisplayItem->replay(paintInfo.context); |
| 57 } |
| 58 } |
| 59 |
| 60 RoundedInnerRectClipper::~RoundedInnerRectClipper() |
| 61 { |
| 62 OwnPtr<EndClipDisplayItem> endClipDisplayItem = EndClipDisplayItem::create(m
_renderer.displayItemClient()); |
| 63 |
| 64 if (m_useDisplayItemList) { |
| 65 ASSERT(m_paintInfo.context->displayItemList()); |
| 66 m_paintInfo.context->displayItemList()->add(endClipDisplayItem.release()
); |
| 67 } else { |
| 68 endClipDisplayItem->replay(m_paintInfo.context); |
| 69 } |
| 70 } |
| 71 |
| 72 } // namespace blink |
OLD | NEW |