2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef RenderSVGResourceClipper_h
21 #define RenderSVGResourceClipper_h
23 #include "core/rendering/svg/RenderSVGResourceContainer.h"
24 #include "core/svg/SVGClipPathElement.h"
30 struct ClipperContext {
31 WTF_MAKE_FAST_ALLOCATED;
33 enum ClipperState { NotAppliedState, AppliedPathState, AppliedMaskState };
36 : state(NotAppliedState)
43 class RenderSVGResourceClipper FINAL : public RenderSVGResourceContainer {
45 explicit RenderSVGResourceClipper(SVGClipPathElement*);
46 virtual ~RenderSVGResourceClipper();
48 virtual const char* renderName() const OVERRIDE { return "RenderSVGResourceClipper"; }
50 virtual void removeAllClientsFromCache(bool markForInvalidation = true) OVERRIDE;
51 virtual void removeClientFromCache(RenderObject*, bool markForInvalidation = true) OVERRIDE;
53 virtual bool applyResource(RenderObject*, RenderStyle*, GraphicsContext*&, unsigned short resourceMode) OVERRIDE;
54 virtual void postApplyResource(RenderObject*, GraphicsContext*&, unsigned short, const Path*, const RenderSVGShape*) OVERRIDE;
56 // FIXME: Filters are also stateful resources that could benefit from having their state managed
57 // on the caller stack instead of the current hashmap. We should look at refactoring these
58 // into a general interface that can be shared.
59 bool applyStatefulResource(RenderObject*, GraphicsContext*&, ClipperContext&);
60 void postApplyStatefulResource(RenderObject*, GraphicsContext*&, ClipperContext&);
62 // clipPath can be clipped too, but don't have a boundingBox or paintInvalidationRect. So we can't call
63 // applyResource directly and use the rects from the object, since they are empty for RenderSVGResources
64 // FIXME: We made applyClippingToContext public because we cannot call applyResource on HTML elements (it asserts on RenderObject::objectBoundingBox)
65 bool applyClippingToContext(RenderObject*, const FloatRect&, const FloatRect&, GraphicsContext*, ClipperContext&);
67 FloatRect resourceBoundingBox(const RenderObject*);
69 virtual RenderSVGResourceType resourceType() const OVERRIDE { return s_resourceType; }
71 bool hitTestClipContent(const FloatRect&, const FloatPoint&);
73 SVGUnitTypes::SVGUnitType clipPathUnits() const { return toSVGClipPathElement(element())->clipPathUnits()->currentValue()->enumValue(); }
75 static const RenderSVGResourceType s_resourceType;
77 bool tryPathOnlyClipping(GraphicsContext*, const AffineTransform&, const FloatRect&);
78 void drawClipMaskContent(GraphicsContext*, const FloatRect& targetBoundingBox);
79 PassRefPtr<DisplayList> asDisplayList(GraphicsContext*, const AffineTransform&);
80 void calculateClipContentPaintInvalidationRect();
82 RefPtr<DisplayList> m_clipContentDisplayList;
83 FloatRect m_clipBoundaries;
85 // Reference cycle detection.
86 bool m_inClipExpansion;
89 DEFINE_RENDER_SVG_RESOURCE_TYPE_CASTS(RenderSVGResourceClipper, ClipperResourceType);