| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/paint/ClipPathClipper.h" | 5 #include "core/paint/ClipPathClipper.h" |
| 6 | 6 |
| 7 #include "core/layout/svg/LayoutSVGResourceClipper.h" | 7 #include "core/layout/svg/LayoutSVGResourceClipper.h" |
| 8 #include "core/layout/svg/SVGResources.h" | 8 #include "core/layout/svg/SVGResources.h" |
| 9 #include "core/layout/svg/SVGResourcesCache.h" | 9 #include "core/layout/svg/SVGResourcesCache.h" |
| 10 #include "core/paint/SVGClipPainter.h" | 10 #include "core/paint/SVGClipPainter.h" |
| 11 #include "core/style/ClipPathOperation.h" | 11 #include "core/style/ClipPathOperation.h" |
| 12 #include "platform/graphics/paint/ClipPathRecorder.h" | 12 #include "platform/graphics/paint/ClipPathRecorder.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 LayoutSVGResourceClipper* resolveElementReference( | 18 LayoutSVGResourceClipper* resolveElementReference( |
| 19 const LayoutObject& layoutObject, | 19 const LayoutObject& layoutObject, |
| 20 const ReferenceClipPathOperation& referenceClipPathOperation) { | 20 const ReferenceClipPathOperation& referenceClipPathOperation) { |
| 21 if (layoutObject.isSVG() && !layoutObject.isSVGRoot()) { | 21 if (layoutObject.isSVG() && !layoutObject.isSVGRoot()) { |
| 22 // The reference will have been resolved in | 22 // The reference will have been resolved in |
| 23 // SVGResources::buildResources, so we can just use the LayoutObject's | 23 // SVGResources::buildResources, so we can just use the LayoutObject's |
| 24 // SVGResources. | 24 // SVGResources. |
| 25 SVGResources* resources = | 25 SVGResources* resources = |
| 26 SVGResourcesCache::cachedResourcesForLayoutObject(&layoutObject); | 26 SVGResourcesCache::cachedResourcesForLayoutObject(&layoutObject); |
| 27 return resources ? resources->clipper() : nullptr; | 27 return resources ? resources->clipper() : nullptr; |
| 28 } | 28 } |
| 29 // TODO(fs): It doesn't work with forward or external SVG references (https://
bugs.webkit.org/show_bug.cgi?id=90405) | 29 // TODO(fs): It doesn't work with forward or external SVG references |
| 30 // (https://bugs.webkit.org/show_bug.cgi?id=90405) |
| 30 Element* element = layoutObject.document().getElementById( | 31 Element* element = layoutObject.document().getElementById( |
| 31 referenceClipPathOperation.fragment()); | 32 referenceClipPathOperation.fragment()); |
| 32 if (!isSVGClipPathElement(element) || !element->layoutObject()) | 33 if (!isSVGClipPathElement(element) || !element->layoutObject()) |
| 33 return nullptr; | 34 return nullptr; |
| 34 return toLayoutSVGResourceClipper( | 35 return toLayoutSVGResourceClipper( |
| 35 toLayoutSVGResourceContainer(element->layoutObject())); | 36 toLayoutSVGResourceContainer(element->layoutObject())); |
| 36 } | 37 } |
| 37 | 38 |
| 38 } // namespace | 39 } // namespace |
| 39 | 40 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 53 m_clipPathRecorder.emplace(context, layoutObject, shape.path(referenceBox)); | 54 m_clipPathRecorder.emplace(context, layoutObject, shape.path(referenceBox)); |
| 54 m_clipperState = ClipperState::AppliedPath; | 55 m_clipperState = ClipperState::AppliedPath; |
| 55 } else { | 56 } else { |
| 56 DCHECK_EQ(clipPathOperation.type(), ClipPathOperation::REFERENCE); | 57 DCHECK_EQ(clipPathOperation.type(), ClipPathOperation::REFERENCE); |
| 57 LayoutSVGResourceClipper* clipper = resolveElementReference( | 58 LayoutSVGResourceClipper* clipper = resolveElementReference( |
| 58 layoutObject, toReferenceClipPathOperation(clipPathOperation)); | 59 layoutObject, toReferenceClipPathOperation(clipPathOperation)); |
| 59 if (!clipper) | 60 if (!clipper) |
| 60 return; | 61 return; |
| 61 // Compute the (conservative) bounds of the clip-path. | 62 // Compute the (conservative) bounds of the clip-path. |
| 62 FloatRect clipPathBounds = clipper->resourceBoundingBox(referenceBox); | 63 FloatRect clipPathBounds = clipper->resourceBoundingBox(referenceBox); |
| 63 // When SVG applies the clip, and the coordinate system is "userspace on use
", we must explicitly pass in | 64 // When SVG applies the clip, and the coordinate system is "userspace on |
| 64 // the offset to have the clip paint in the correct location. When the coord
inate system is | 65 // use", we must explicitly pass in the offset to have the clip paint in the |
| 65 // "object bounding box" the offset should already be accounted for in the r
eference box. | 66 // correct location. When the coordinate system is "object bounding box" the |
| 67 // offset should already be accounted for in the reference box. |
| 66 FloatPoint originTranslation; | 68 FloatPoint originTranslation; |
| 67 if (clipper->clipPathUnits() == SVGUnitTypes::kSvgUnitTypeUserspaceonuse) { | 69 if (clipper->clipPathUnits() == SVGUnitTypes::kSvgUnitTypeUserspaceonuse) { |
| 68 clipPathBounds.moveBy(origin); | 70 clipPathBounds.moveBy(origin); |
| 69 originTranslation = origin; | 71 originTranslation = origin; |
| 70 } | 72 } |
| 71 if (!SVGClipPainter(*clipper).prepareEffect( | 73 if (!SVGClipPainter(*clipper).prepareEffect( |
| 72 layoutObject, referenceBox, clipPathBounds, originTranslation, | 74 layoutObject, referenceBox, clipPathBounds, originTranslation, |
| 73 context, m_clipperState)) | 75 context, m_clipperState)) |
| 74 return; | 76 return; |
| 75 m_resourceClipper = clipper; | 77 m_resourceClipper = clipper; |
| 76 } | 78 } |
| 77 } | 79 } |
| 78 | 80 |
| 79 ClipPathClipper::~ClipPathClipper() { | 81 ClipPathClipper::~ClipPathClipper() { |
| 80 if (m_resourceClipper) | 82 if (m_resourceClipper) |
| 81 SVGClipPainter(*m_resourceClipper) | 83 SVGClipPainter(*m_resourceClipper) |
| 82 .finishEffect(m_layoutObject, m_context, m_clipperState); | 84 .finishEffect(m_layoutObject, m_context, m_clipperState); |
| 83 } | 85 } |
| 84 | 86 |
| 85 } // namespace blink | 87 } // namespace blink |
| OLD | NEW |