1 /* 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 3 * 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. 8 * 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. 13 * 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. 18 */ 19 20 #ifndef RenderSVGResourceClipper_h 21 #define RenderSVGResourceClipper_h 22 23 #if ENABLE(SVG) 24 #include "FloatRect.h" 25 #include "GraphicsContext.h" 26 #include "ImageBuffer.h" 27 #include "IntSize.h" 28 #include "Path.h" 29 #include "RenderSVGResourceContainer.h" 30 #include "SVGClipPathElement.h" 31 #include "SVGUnitTypes.h" 32 33 #include <wtf/HashMap.h> 34 #include <wtf/OwnPtr.h> 35 36 namespace WebCore { 37 38 struct ClipperData { 39 WTF_MAKE_FAST_ALLOCATED; 40 public: 41 OwnPtr<ImageBuffer> clipMaskImage; 42 }; 43 44 class RenderSVGResourceClipper : public RenderSVGResourceContainer { 45 public: 46 RenderSVGResourceClipper(SVGClipPathElement*); 47 virtual ~RenderSVGResourceClipper(); 48 renderName()49 virtual const char* renderName() const { return "RenderSVGResourceClipper"; } 50 51 virtual void removeAllClientsFromCache(bool markForInvalidation = true); 52 virtual void removeClientFromCache(RenderObject*, bool markForInvalidation = true); 53 54 virtual bool applyResource(RenderObject*, RenderStyle*, GraphicsContext*&, unsigned short resourceMode); 55 virtual FloatRect resourceBoundingBox(RenderObject*); 56 resourceType()57 virtual RenderSVGResourceType resourceType() const { return ClipperResourceType; } 58 59 bool hitTestClipContent(const FloatRect&, const FloatPoint&); 60 clipPathUnits()61 SVGUnitTypes::SVGUnitType clipPathUnits() const { return toUnitType(static_cast<SVGClipPathElement*>(node())->clipPathUnits()); } 62 63 static RenderSVGResourceType s_resourceType; 64 private: 65 // clipPath can be clipped too, but don't have a boundingBox or repaintRect. So we can't call 66 // applyResource directly and use the rects from the object, since they are empty for RenderSVGResources 67 bool applyClippingToContext(RenderObject*, const FloatRect&, const FloatRect&, GraphicsContext*); 68 bool pathOnlyClipping(GraphicsContext*, const FloatRect&); 69 bool drawContentIntoMaskImage(ClipperData*, const FloatRect& objectBoundingBox); 70 void calculateClipContentRepaintRect(); 71 72 bool m_invalidationBlocked; 73 FloatRect m_clipBoundaries; 74 HashMap<RenderObject*, ClipperData*> m_clipper; 75 }; 76 77 } 78 79 #endif 80 #endif 81