Home | History | Annotate | Download | only in svg
      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 blink {
     27 
     28 class DisplayList;
     29 
     30 class RenderSVGResourceClipper FINAL : public RenderSVGResourceContainer {
     31 public:
     32     enum ClipperState {
     33         ClipperNotApplied,
     34         ClipperAppliedPath,
     35         ClipperAppliedMask
     36     };
     37 
     38     explicit RenderSVGResourceClipper(SVGClipPathElement*);
     39     virtual ~RenderSVGResourceClipper();
     40 
     41     virtual const char* renderName() const OVERRIDE { return "RenderSVGResourceClipper"; }
     42 
     43     virtual void removeAllClientsFromCache(bool markForInvalidation = true) OVERRIDE;
     44     virtual void removeClientFromCache(RenderObject*, bool markForInvalidation = true) OVERRIDE;
     45 
     46     virtual bool applyResource(RenderObject*, RenderStyle*, GraphicsContext*&, unsigned short resourceMode) OVERRIDE;
     47     virtual void postApplyResource(RenderObject*, GraphicsContext*&) OVERRIDE;
     48 
     49     // FIXME: Filters are also stateful resources that could benefit from having their state managed
     50     //        on the caller stack instead of the current hashmap. We should look at refactoring these
     51     //        into a general interface that can be shared.
     52     bool applyStatefulResource(RenderObject*, GraphicsContext*&, ClipperState&);
     53     void postApplyStatefulResource(RenderObject*, GraphicsContext*&, ClipperState&);
     54 
     55     // clipPath can be clipped too, but don't have a boundingBox or paintInvalidationRect. So we can't call
     56     // applyResource directly and use the rects from the object, since they are empty for RenderSVGResources
     57     // FIXME: We made applyClippingToContext public because we cannot call applyResource on HTML elements (it asserts on RenderObject::objectBoundingBox)
     58     bool applyClippingToContext(RenderObject*, const FloatRect&, const FloatRect&, GraphicsContext*, ClipperState&);
     59 
     60     FloatRect resourceBoundingBox(const RenderObject*);
     61 
     62     virtual RenderSVGResourceType resourceType() const OVERRIDE { return s_resourceType; }
     63 
     64     bool hitTestClipContent(const FloatRect&, const FloatPoint&);
     65 
     66     SVGUnitTypes::SVGUnitType clipPathUnits() const { return toSVGClipPathElement(element())->clipPathUnits()->currentValue()->enumValue(); }
     67 
     68     static const RenderSVGResourceType s_resourceType;
     69 private:
     70     bool tryPathOnlyClipping(GraphicsContext*, const AffineTransform&, const FloatRect&);
     71     void drawClipMaskContent(GraphicsContext*, const FloatRect& targetBoundingBox);
     72     void createDisplayList(GraphicsContext*, const AffineTransform&);
     73     void calculateClipContentPaintInvalidationRect();
     74 
     75     RefPtr<DisplayList> m_clipContentDisplayList;
     76     FloatRect m_clipBoundaries;
     77 
     78     // Reference cycle detection.
     79     bool m_inClipExpansion;
     80 };
     81 
     82 DEFINE_RENDER_SVG_RESOURCE_TYPE_CASTS(RenderSVGResourceClipper, ClipperResourceType);
     83 
     84 }
     85 
     86 #endif
     87