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 WebCore {
     27 
     28 class DisplayList;
     29 
     30 struct ClipperContext {
     31     WTF_MAKE_FAST_ALLOCATED;
     32 public:
     33     enum ClipperState { NotAppliedState, AppliedPathState, AppliedMaskState };
     34 
     35     ClipperContext()
     36         : state(NotAppliedState)
     37     {
     38     }
     39 
     40     ClipperState state;
     41 };
     42 
     43 class RenderSVGResourceClipper FINAL : public RenderSVGResourceContainer {
     44 public:
     45     explicit RenderSVGResourceClipper(SVGClipPathElement*);
     46     virtual ~RenderSVGResourceClipper();
     47 
     48     virtual const char* renderName() const OVERRIDE { return "RenderSVGResourceClipper"; }
     49 
     50     virtual void removeAllClientsFromCache(bool markForInvalidation = true) OVERRIDE;
     51     virtual void removeClientFromCache(RenderObject*, bool markForInvalidation = true) OVERRIDE;
     52 
     53     virtual bool applyResource(RenderObject*, RenderStyle*, GraphicsContext*&, unsigned short resourceMode) OVERRIDE;
     54     virtual void postApplyResource(RenderObject*, GraphicsContext*&, unsigned short, const Path*, const RenderSVGShape*) OVERRIDE;
     55 
     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&);
     61 
     62     // clipPath can be clipped too, but don't have a boundingBox or repaintRect. 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&);
     66 
     67     FloatRect resourceBoundingBox(const RenderObject*);
     68 
     69     virtual RenderSVGResourceType resourceType() const OVERRIDE { return s_resourceType; }
     70 
     71     bool hitTestClipContent(const FloatRect&, const FloatPoint&);
     72 
     73     SVGUnitTypes::SVGUnitType clipPathUnits() const { return toSVGClipPathElement(element())->clipPathUnits()->currentValue()->enumValue(); }
     74 
     75     static const RenderSVGResourceType s_resourceType;
     76 private:
     77     bool tryPathOnlyClipping(GraphicsContext*, const AffineTransform&, const FloatRect&);
     78     void drawClipMaskContent(GraphicsContext*, const FloatRect& targetBoundingBox);
     79     PassRefPtr<DisplayList> asDisplayList(GraphicsContext*, const AffineTransform&);
     80     void calculateClipContentRepaintRect();
     81 
     82     RefPtr<DisplayList> m_clipContentDisplayList;
     83     FloatRect m_clipBoundaries;
     84 
     85     // Reference cycle detection.
     86     bool m_inClipExpansion;
     87 };
     88 
     89 DEFINE_RENDER_SVG_RESOURCE_TYPE_CASTS(RenderSVGResourceClipper, ClipperResourceType);
     90 
     91 }
     92 
     93 #endif
     94