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 #include "core/rendering/svg/RenderSVGResourceContainer.h" 24 #include "core/svg/SVGClipPathElement.h" 25 26 namespace WebCore { 27 28 struct ClipperData { 29 WTF_MAKE_FAST_ALLOCATED; 30 public: 31 OwnPtr<ImageBuffer> clipMaskImage; 32 }; 33 34 class RenderSVGResourceClipper FINAL : public RenderSVGResourceContainer { 35 public: 36 RenderSVGResourceClipper(SVGClipPathElement*); 37 virtual ~RenderSVGResourceClipper(); 38 39 virtual const char* renderName() const { return "RenderSVGResourceClipper"; } 40 41 virtual void removeAllClientsFromCache(bool markForInvalidation = true); 42 virtual void removeClientFromCache(RenderObject*, bool markForInvalidation = true); 43 44 virtual bool applyResource(RenderObject*, RenderStyle*, GraphicsContext*&, unsigned short resourceMode); 45 // clipPath can be clipped too, but don't have a boundingBox or repaintRect. So we can't call 46 // applyResource directly and use the rects from the object, since they are empty for RenderSVGResources 47 // FIXME: We made applyClippingToContext public because we cannot call applyResource on HTML elements (it asserts on RenderObject::objectBoundingBox) 48 bool applyClippingToContext(RenderObject*, const FloatRect&, const FloatRect&, GraphicsContext*); 49 virtual FloatRect resourceBoundingBox(RenderObject*); 50 51 virtual RenderSVGResourceType resourceType() const { return ClipperResourceType; } 52 53 bool hitTestClipContent(const FloatRect&, const FloatPoint&); 54 55 SVGUnitTypes::SVGUnitType clipPathUnits() const { return static_cast<SVGClipPathElement*>(node())->clipPathUnitsCurrentValue(); } 56 57 static RenderSVGResourceType s_resourceType; 58 private: 59 bool pathOnlyClipping(GraphicsContext*, const AffineTransform&, const FloatRect&); 60 bool drawContentIntoMaskImage(ClipperData*, const FloatRect& objectBoundingBox); 61 void calculateClipContentRepaintRect(); 62 63 FloatRect m_clipBoundaries; 64 HashMap<RenderObject*, ClipperData*> m_clipper; 65 }; 66 67 } 68 69 #endif 70