OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/paint/ClipPathClipper.h" |
| 6 |
| 7 #include "core/layout/svg/LayoutSVGResourceClipper.h" |
| 8 #include "core/style/ClipPathOperation.h" |
| 9 #include "platform/graphics/paint/ClipPathRecorder.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 ClipPathClipper::ClipPathClipper( |
| 14 GraphicsContext& context, |
| 15 const LayoutObject& layoutObject, |
| 16 const FloatRect& referenceBox, |
| 17 const FloatRect& visualOverflowRect, |
| 18 const FloatPoint& origin) |
| 19 : m_resourceClipper(nullptr) |
| 20 , m_clipperState(SVGClipPainter::ClipperNotApplied) |
| 21 , m_layoutObject(layoutObject) |
| 22 , m_context(context) |
| 23 { |
| 24 DCHECK(layoutObject.styleRef().clipPath()); |
| 25 ClipPathOperation* clipPathOperation = layoutObject.styleRef().clipPath(); |
| 26 if (clipPathOperation->type() == ClipPathOperation::SHAPE) { |
| 27 ShapeClipPathOperation* shape = toShapeClipPathOperation(clipPathOperati
on); |
| 28 if (shape->isValid()) |
| 29 m_clipPathRecorder.emplace(context, layoutObject, shape->path(refere
nceBox)); |
| 30 } else { |
| 31 DCHECK_EQ(clipPathOperation->type(), ClipPathOperation::REFERENCE); |
| 32 ReferenceClipPathOperation* referenceClipPathOperation = toReferenceClip
PathOperation(clipPathOperation); |
| 33 Document& document = layoutObject.document(); |
| 34 // TODO(fs): It doesn't work with forward or external SVG references (ht
tps://bugs.webkit.org/show_bug.cgi?id=90405) |
| 35 Element* element = document.getElementById(referenceClipPathOperation->f
ragment()); |
| 36 if (isSVGClipPathElement(element) && element->layoutObject()) { |
| 37 m_resourceClipper = toLayoutSVGResourceClipper(toLayoutSVGResourceCo
ntainer(element->layoutObject())); |
| 38 // When SVG applies the clip, and the coordinate system is "userspac
e on use", we must explicitly pass in |
| 39 // the offset to have the clip paint in the correct location. When t
he coordinate system is |
| 40 // "object bounding box" the offset should already be accounted for
in the visualOverflowRect. |
| 41 FloatPoint originTranslation = m_resourceClipper->clipPathUnits() ==
SVGUnitTypes::kSvgUnitTypeUserspaceonuse ? |
| 42 origin : FloatPoint(); |
| 43 if (!SVGClipPainter(*m_resourceClipper).prepareEffect(layoutObject,
referenceBox, |
| 44 visualOverflowRect, originTranslation, context, m_clipperState))
{ |
| 45 // No need to "finish" the clipper if this failed. |
| 46 m_resourceClipper = nullptr; |
| 47 } |
| 48 } |
| 49 } |
| 50 } |
| 51 |
| 52 ClipPathClipper::~ClipPathClipper() |
| 53 { |
| 54 if (m_resourceClipper) |
| 55 SVGClipPainter(*m_resourceClipper).finishEffect(m_layoutObject, m_contex
t, m_clipperState); |
| 56 } |
| 57 |
| 58 } // namespace blink |
OLD | NEW |