OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/paint/RoundedInnerRectClipper.h" | 6 #include "core/paint/RoundedInnerRectClipper.h" |
7 | 7 |
8 #include "core/layout/LayoutBox.h" | 8 #include "core/layout/LayoutBox.h" |
9 #include "core/paint/PaintInfo.h" | 9 #include "core/paint/PaintInfo.h" |
10 #include "platform/graphics/paint/ClipDisplayItem.h" | 10 #include "platform/graphics/paint/ClipDisplayItem.h" |
11 #include "platform/graphics/paint/DisplayItemList.h" | 11 #include "platform/graphics/paint/DisplayItemList.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 RoundedInnerRectClipper::RoundedInnerRectClipper(LayoutObject& layoutObject, con
st PaintInfo& paintInfo, const LayoutRect& rect, const FloatRoundedRect& clipRec
t, RoundedInnerRectClipperBehavior behavior) | 15 RoundedInnerRectClipper::RoundedInnerRectClipper(LayoutObject& layoutObject, con
st PaintInfo& paintInfo, const LayoutRect& rect, const FloatRoundedRect& clipRec
t, RoundedInnerRectClipperBehavior behavior) |
16 : m_layoutObject(layoutObject) | 16 : m_layoutObject(layoutObject) |
17 , m_paintInfo(paintInfo) | 17 , m_paintInfo(paintInfo) |
18 , m_useDisplayItemList(RuntimeEnabledFeatures::slimmingPaintEnabled() && beh
avior == ApplyToDisplayListIfEnabled) | 18 , m_useDisplayItemList(RuntimeEnabledFeatures::slimmingPaintEnabled() && beh
avior == ApplyToDisplayListIfEnabled) |
19 , m_clipType(m_useDisplayItemList ? m_paintInfo.displayItemTypeForClipping()
: DisplayItem::ClipBoxPaintPhaseFirst) | 19 , m_clipType(m_useDisplayItemList ? m_paintInfo.displayItemTypeForClipping()
: DisplayItem::ClipBoxPaintPhaseFirst) |
20 { | 20 { |
21 OwnPtr<ClipDisplayItem> clipDisplayItem = ClipDisplayItem::create(layoutObje
ct, m_clipType, LayoutRect::infiniteIntRect()); | 21 ClipDisplayItem clipDisplayItem(layoutObject, m_clipType, LayoutRect::infini
teIntRect()); |
22 | 22 |
23 if (clipRect.isRenderable()) { | 23 if (clipRect.isRenderable()) { |
24 clipDisplayItem->roundedRectClips().append(clipRect); | 24 clipDisplayItem.roundedRectClips().append(clipRect); |
25 } else { | 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. | 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()) { | 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()); | 28 FloatRect topCorner(clipRect.rect().x(), clipRect.rect().y(), rect.m
axX() - clipRect.rect().x(), rect.maxY() - clipRect.rect().y()); |
29 FloatRoundedRect::Radii topCornerRadii; | 29 FloatRoundedRect::Radii topCornerRadii; |
30 topCornerRadii.setTopLeft(clipRect.radii().topLeft()); | 30 topCornerRadii.setTopLeft(clipRect.radii().topLeft()); |
31 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(topCorne
r, topCornerRadii)); | 31 clipDisplayItem.roundedRectClips().append(FloatRoundedRect(topCorner
, topCornerRadii)); |
32 | 32 |
33 FloatRect bottomCorner(rect.x().toFloat(), rect.y().toFloat(), clipR
ect.rect().maxX() - rect.x().toFloat(), clipRect.rect().maxY() - rect.y().toFloa
t()); | 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; | 34 FloatRoundedRect::Radii bottomCornerRadii; |
35 bottomCornerRadii.setBottomRight(clipRect.radii().bottomRight()); | 35 bottomCornerRadii.setBottomRight(clipRect.radii().bottomRight()); |
36 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(bottomCo
rner, bottomCornerRadii)); | 36 clipDisplayItem.roundedRectClips().append(FloatRoundedRect(bottomCor
ner, bottomCornerRadii)); |
37 } | 37 } |
38 | 38 |
39 if (!clipRect.radii().topRight().isEmpty() || !clipRect.radii().bottomLe
ft().isEmpty()) { | 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()); | 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; | 41 FloatRoundedRect::Radii topCornerRadii; |
42 topCornerRadii.setTopRight(clipRect.radii().topRight()); | 42 topCornerRadii.setTopRight(clipRect.radii().topRight()); |
43 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(topCorne
r, topCornerRadii)); | 43 clipDisplayItem.roundedRectClips().append(FloatRoundedRect(topCorner
, topCornerRadii)); |
44 | 44 |
45 FloatRect bottomCorner(clipRect.rect().x(), rect.y().toFloat(), rect
.maxX() - clipRect.rect().x(), clipRect.rect().maxY() - rect.y().toFloat()); | 45 FloatRect bottomCorner(clipRect.rect().x(), rect.y().toFloat(), rect
.maxX() - clipRect.rect().x(), clipRect.rect().maxY() - rect.y().toFloat()); |
46 FloatRoundedRect::Radii bottomCornerRadii; | 46 FloatRoundedRect::Radii bottomCornerRadii; |
47 bottomCornerRadii.setBottomLeft(clipRect.radii().bottomLeft()); | 47 bottomCornerRadii.setBottomLeft(clipRect.radii().bottomLeft()); |
48 clipDisplayItem->roundedRectClips().append(FloatRoundedRect(bottomCo
rner, bottomCornerRadii)); | 48 clipDisplayItem.roundedRectClips().append(FloatRoundedRect(bottomCor
ner, bottomCornerRadii)); |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
52 if (m_useDisplayItemList) { | 52 if (m_useDisplayItemList) { |
53 ASSERT(m_paintInfo.context->displayItemList()); | 53 ASSERT(m_paintInfo.context->displayItemList()); |
54 if (m_paintInfo.context->displayItemList()->displayItemConstructionIsDis
abled()) | 54 if (m_paintInfo.context->displayItemList()->displayItemConstructionIsDis
abled()) |
55 return; | 55 return; |
56 m_paintInfo.context->displayItemList()->add(clipDisplayItem.release()); | 56 m_paintInfo.context->displayItemList()->add(clipDisplayItem); |
57 } else { | 57 } else { |
58 clipDisplayItem->replay(*paintInfo.context); | 58 clipDisplayItem.replay(*paintInfo.context); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 RoundedInnerRectClipper::~RoundedInnerRectClipper() | 62 RoundedInnerRectClipper::~RoundedInnerRectClipper() |
63 { | 63 { |
64 DisplayItem::Type endType = DisplayItem::clipTypeToEndClipType(m_clipType); | 64 DisplayItem::Type endType = DisplayItem::clipTypeToEndClipType(m_clipType); |
| 65 EndClipDisplayItem endClipDisplayItem(m_layoutObject, endType); |
65 if (m_useDisplayItemList) { | 66 if (m_useDisplayItemList) { |
66 ASSERT(m_paintInfo.context->displayItemList()); | 67 ASSERT(m_paintInfo.context->displayItemList()); |
67 if (m_paintInfo.context->displayItemList()->displayItemConstructionIsDis
abled()) | 68 if (m_paintInfo.context->displayItemList()->displayItemConstructionIsDis
abled()) |
68 return; | 69 return; |
69 OwnPtr<EndClipDisplayItem> endClipDisplayItem = EndClipDisplayItem::crea
te(m_layoutObject, endType); | 70 m_paintInfo.context->displayItemList()->add(endClipDisplayItem); |
70 m_paintInfo.context->displayItemList()->add(endClipDisplayItem.release()
); | |
71 } else { | 71 } else { |
72 EndClipDisplayItem endClipDisplayItem(m_layoutObject, endType); | |
73 endClipDisplayItem.replay(*m_paintInfo.context); | 72 endClipDisplayItem.replay(*m_paintInfo.context); |
74 } | 73 } |
75 } | 74 } |
76 | 75 |
77 } // namespace blink | 76 } // namespace blink |
OLD | NEW |