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/ContentBoxRadiusClipper.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 ContentBoxRadiusClipper::ContentBoxRadiusClipper(RenderBox& box, const PaintInfo & paintInfo, const LayoutPoint& accumulatedOffset) | |
16 : m_box(box) | |
17 , m_paintInfo(paintInfo) | |
18 , m_pushedClip(false) | |
19 , m_completelyClipped(false) | |
20 { | |
21 if (!box.style()->hasBorderRadius()) | |
22 return; | |
23 | |
24 LayoutRect borderRect = LayoutRect(accumulatedOffset, m_box.size()); | |
25 | |
26 FloatRoundedRect roundedContentBox = box.style()->getRoundedInnerBorderFor(b orderRect, | |
27 box.paddingTop() + box.borderTop(), | |
28 box.paddingBottom() + box.borderBottom(), | |
29 box.paddingLeft() + box.borderLeft(), | |
30 box.paddingRight() + box.borderRight(), true, true); | |
31 | |
32 if (roundedContentBox.isEmpty()) { | |
33 m_completelyClipped = true; | |
34 return; | |
35 } | |
36 | |
37 DisplayItem::Type clipType = DisplayItem::ClipBoxForeground; | |
38 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) | |
39 clipType = m_paintInfo.displayItemTypeForClipping(); | |
40 | |
41 OwnPtr<ClipDisplayItem> clipDisplayItem = ClipDisplayItem::create(box.displa yItemClient(), clipType, pixelSnappedIntRect(borderRect)); | |
42 | |
43 if (roundedContentBox.isRenderable()) { | |
chrishtr
2015/01/23 05:07:12
I don't get it. Where is all the logic in this cla
| |
44 clipDisplayItem->roundedRectClips().append(roundedContentBox); | |
45 } else { | |
46 // We create a rounded rect for each of the corners and clip it, while m aking sure we clip opposing corners together. | |
47 if (!roundedContentBox.radii().topLeft().isEmpty() || !roundedContentBox .radii().bottomRight().isEmpty()) { | |
48 FloatRect topCorner(roundedContentBox.rect().x(), roundedContentBox. rect().y(), borderRect.maxX() - roundedContentBox.rect().x(), borderRect.maxY() - roundedContentBox.rect().y()); | |
49 FloatRoundedRect::Radii topCornerRadii; | |
50 topCornerRadii.setTopLeft(roundedContentBox.radii().topLeft()); | |
51 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(topCorne r, topCornerRadii)); | |
52 | |
53 FloatRect bottomCorner(borderRect.x().toFloat(), borderRect.y().toFl oat(), roundedContentBox.rect().maxX() - borderRect.x().toFloat(), roundedConten tBox.rect().maxY() - borderRect.y().toFloat()); | |
54 FloatRoundedRect::Radii bottomCornerRadii; | |
55 bottomCornerRadii.setBottomRight(roundedContentBox.radii().bottomRig ht()); | |
56 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(bottomCo rner, bottomCornerRadii)); | |
57 } | |
58 | |
59 if (!roundedContentBox.radii().topRight().isEmpty() || !roundedContentBo x.radii().bottomLeft().isEmpty()) { | |
60 FloatRect topCorner(borderRect.x().toFloat(), roundedContentBox.rect ().y(), roundedContentBox.rect().maxX() - borderRect.x().toFloat(), borderRect.m axY() - roundedContentBox.rect().y()); | |
61 FloatRoundedRect::Radii topCornerRadii; | |
62 topCornerRadii.setTopRight(roundedContentBox.radii().topRight()); | |
63 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(topCorne r, topCornerRadii)); | |
64 | |
65 FloatRect bottomCorner(roundedContentBox.rect().x(), borderRect.y(). toFloat(), borderRect.maxX() - roundedContentBox.rect().x(), roundedContentBox.r ect().maxY() - borderRect.y().toFloat()); | |
66 FloatRoundedRect::Radii bottomCornerRadii; | |
67 bottomCornerRadii.setBottomLeft(roundedContentBox.radii().bottomLeft ()); | |
68 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(bottomCo rner, bottomCornerRadii)); | |
69 } | |
70 } | |
71 | |
72 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | |
73 ASSERT(m_paintInfo.context->displayItemList()); | |
74 m_paintInfo.context->displayItemList()->add(clipDisplayItem.release()); | |
75 } else { | |
76 clipDisplayItem->replay(paintInfo.context); | |
77 } | |
78 m_pushedClip = true; | |
79 } | |
80 | |
81 ContentBoxRadiusClipper::~ContentBoxRadiusClipper() | |
82 { | |
83 if (!m_pushedClip) | |
84 return; | |
85 | |
86 OwnPtr<EndClipDisplayItem> endClipDisplayItem = EndClipDisplayItem::create(m _box.displayItemClient()); | |
87 | |
88 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | |
89 ASSERT(m_paintInfo.context->displayItemList()); | |
90 m_paintInfo.context->displayItemList()->add(endClipDisplayItem.release() ); | |
91 } else { | |
92 endClipDisplayItem->replay(m_paintInfo.context); | |
93 } | |
94 } | |
95 | |
96 } // namespace blink | |
OLD | NEW |