Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005 Rob Buis <buis (at) kde.org>
      4  * Copyright (C) 2005 Eric Seidel <eric (at) webkit.org>
      5  * Copyright (C) 2006 Apple Computer, Inc
      6  * Copyright (C) 2009 Google, Inc.
      7  * Copyright (C) 2011 Renata Hodovan <reni (at) webkit.org>
      8  * Copyright (C) 2011 University of Szeged
      9  *
     10  * This library is free software; you can redistribute it and/or
     11  * modify it under the terms of the GNU Library General Public
     12  * License as published by the Free Software Foundation; either
     13  * version 2 of the License, or (at your option) any later version.
     14  *
     15  * This library is distributed in the hope that it will be useful,
     16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     18  * Library General Public License for more details.
     19  *
     20  * You should have received a copy of the GNU Library General Public License
     21  * along with this library; see the file COPYING.LIB.  If not, write to
     22  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     23  * Boston, MA 02110-1301, USA.
     24  */
     25 
     26 #ifndef RenderSVGShape_h
     27 #define RenderSVGShape_h
     28 
     29 #include "core/platform/graphics/FloatRect.h"
     30 #include "core/platform/graphics/transforms/AffineTransform.h"
     31 #include "core/rendering/svg/RenderSVGModelObject.h"
     32 #include "core/rendering/svg/SVGMarkerData.h"
     33 #include "wtf/OwnPtr.h"
     34 #include "wtf/Vector.h"
     35 
     36 namespace WebCore {
     37 
     38 class FloatPoint;
     39 class GraphicsContextStateSaver;
     40 class RenderSVGContainer;
     41 class RenderSVGPath;
     42 class RenderSVGResource;
     43 class SVGGraphicsElement;
     44 
     45 class RenderSVGShape : public RenderSVGModelObject {
     46 public:
     47     explicit RenderSVGShape(SVGGraphicsElement*);
     48     RenderSVGShape(SVGGraphicsElement*, Path*, bool);
     49     virtual ~RenderSVGShape();
     50 
     51     void setNeedsShapeUpdate() { m_needsShapeUpdate = true; }
     52     virtual void setNeedsBoundariesUpdate() OVERRIDE FINAL { m_needsBoundariesUpdate = true; }
     53     virtual bool needsBoundariesUpdate() OVERRIDE FINAL { return m_needsBoundariesUpdate; }
     54     virtual void setNeedsTransformUpdate() OVERRIDE FINAL { m_needsTransformUpdate = true; }
     55     virtual void fillShape(GraphicsContext*) const;
     56     virtual void strokeShape(GraphicsContext*) const;
     57 
     58     Path& path() const
     59     {
     60         ASSERT(m_path);
     61         return *m_path;
     62     }
     63 
     64 protected:
     65     virtual void updateShapeFromElement();
     66     virtual bool isEmpty() const;
     67     virtual bool shapeDependentStrokeContains(const FloatPoint&);
     68     virtual bool shapeDependentFillContains(const FloatPoint&, const WindRule) const;
     69     float strokeWidth() const;
     70     bool hasPath() const { return m_path.get(); }
     71     bool hasSmoothStroke() const;
     72 
     73     bool hasNonScalingStroke() const { return style()->svgStyle()->vectorEffect() == VE_NON_SCALING_STROKE; }
     74     AffineTransform nonScalingStrokeTransform() const;
     75     Path* nonScalingStrokePath(const Path*, const AffineTransform&) const;
     76 
     77     FloatRect m_fillBoundingBox;
     78     FloatRect m_strokeBoundingBox;
     79 
     80 private:
     81     // Hit-detection separated for the fill and the stroke
     82     bool fillContains(const FloatPoint&, bool requiresFill = true, const WindRule fillRule = RULE_NONZERO);
     83     bool strokeContains(const FloatPoint&, bool requiresStroke = true);
     84 
     85     virtual FloatRect repaintRectInLocalCoordinates() const OVERRIDE FINAL { return m_repaintBoundingBox; }
     86     virtual const AffineTransform& localToParentTransform() const OVERRIDE FINAL { return m_localTransform; }
     87     virtual AffineTransform localTransform() const OVERRIDE FINAL { return m_localTransform; }
     88 
     89     virtual bool isSVGShape() const OVERRIDE FINAL { return true; }
     90     virtual const char* renderName() const { return "RenderSVGShape"; }
     91 
     92     virtual void layout() OVERRIDE FINAL;
     93     virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE FINAL;
     94     virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE FINAL;
     95 
     96     virtual bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction) OVERRIDE FINAL;
     97 
     98     virtual FloatRect objectBoundingBox() const OVERRIDE FINAL { return m_fillBoundingBox; }
     99     virtual FloatRect strokeBoundingBox() const OVERRIDE FINAL { return m_strokeBoundingBox; }
    100     FloatRect calculateObjectBoundingBox() const;
    101     FloatRect calculateStrokeBoundingBox() const;
    102     void updateRepaintBoundingBox();
    103 
    104     bool setupNonScalingStrokeContext(AffineTransform&, GraphicsContextStateSaver&);
    105 
    106     bool shouldGenerateMarkerPositions() const;
    107     FloatRect markerRect(float strokeWidth) const;
    108     void processMarkerPositions();
    109 
    110     void fillShape(RenderStyle*, GraphicsContext*);
    111     void strokeShape(RenderStyle*, GraphicsContext*);
    112     void fillAndStrokeShape(GraphicsContext*);
    113     void drawMarkers(PaintInfo&);
    114 
    115 private:
    116     FloatRect m_repaintBoundingBox;
    117     FloatRect m_repaintBoundingBoxExcludingShadow;
    118     AffineTransform m_localTransform;
    119     OwnPtr<Path> m_path;
    120     Vector<MarkerPosition> m_markerPositions;
    121 
    122     bool m_needsBoundariesUpdate : 1;
    123     bool m_needsShapeUpdate : 1;
    124     bool m_needsTransformUpdate : 1;
    125 };
    126 
    127 inline RenderSVGShape* toRenderSVGShape(RenderObject* object)
    128 {
    129     ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isSVGShape());
    130     return static_cast<RenderSVGShape*>(object);
    131 }
    132 
    133 inline const RenderSVGShape* toRenderSVGShape(const RenderObject* object)
    134 {
    135     ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isSVGShape());
    136     return static_cast<const RenderSVGShape*>(object);
    137 }
    138 
    139 // This will catch anyone doing an unnecessary cast.
    140 void toRenderSVGShape(const RenderSVGShape*);
    141 
    142 }
    143 
    144 #endif
    145