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