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/rendering/svg/RenderSVGModelObject.h" 30 #include "core/rendering/svg/SVGMarkerData.h" 31 #include "platform/geometry/FloatRect.h" 32 #include "platform/transforms/AffineTransform.h" 33 #include "wtf/OwnPtr.h" 34 #include "wtf/Vector.h" 35 36 namespace WebCore { 37 38 class FloatPoint; 39 class GraphicsContextStateSaver; 40 class PointerEventsHitRules; 41 class RenderSVGContainer; 42 class RenderSVGPath; 43 class RenderSVGResource; 44 class SVGGraphicsElement; 45 46 class RenderSVGShape : public RenderSVGModelObject { 47 public: 48 explicit RenderSVGShape(SVGGraphicsElement*); 49 RenderSVGShape(SVGGraphicsElement*, Path*, bool); 50 virtual ~RenderSVGShape(); 51 52 void setNeedsShapeUpdate() { m_needsShapeUpdate = true; } 53 virtual void setNeedsBoundariesUpdate() OVERRIDE FINAL { m_needsBoundariesUpdate = true; } 54 virtual bool needsBoundariesUpdate() OVERRIDE FINAL { return m_needsBoundariesUpdate; } 55 virtual void setNeedsTransformUpdate() OVERRIDE FINAL { m_needsTransformUpdate = true; } 56 virtual void fillShape(GraphicsContext*) const; 57 virtual void strokeShape(GraphicsContext*) const; 58 59 bool nodeAtFloatPointInternal(const HitTestRequest&, const FloatPoint&, PointerEventsHitRules); 60 61 Path& path() const 62 { 63 ASSERT(m_path); 64 return *m_path; 65 } 66 67 protected: 68 virtual void updateShapeFromElement(); 69 virtual bool isEmpty() const; 70 virtual bool shapeDependentStrokeContains(const FloatPoint&); 71 virtual bool shapeDependentFillContains(const FloatPoint&, const WindRule) const; 72 float strokeWidth() const; 73 bool hasPath() const { return m_path.get(); } 74 bool hasSmoothStroke() const; 75 76 bool hasNonScalingStroke() const { return style()->svgStyle()->vectorEffect() == VE_NON_SCALING_STROKE; } 77 AffineTransform nonScalingStrokeTransform() const; 78 Path* nonScalingStrokePath(const Path*, const AffineTransform&) const; 79 80 FloatRect m_fillBoundingBox; 81 FloatRect m_strokeBoundingBox; 82 83 private: 84 // Hit-detection separated for the fill and the stroke 85 bool fillContains(const FloatPoint&, bool requiresFill = true, const WindRule fillRule = RULE_NONZERO); 86 bool strokeContains(const FloatPoint&, bool requiresStroke = true); 87 88 virtual FloatRect repaintRectInLocalCoordinates() const OVERRIDE FINAL { return m_repaintBoundingBox; } 89 virtual const AffineTransform& localToParentTransform() const OVERRIDE FINAL { return m_localTransform; } 90 virtual AffineTransform localTransform() const OVERRIDE FINAL { return m_localTransform; } 91 92 virtual bool isSVGShape() const OVERRIDE FINAL { return true; } 93 virtual const char* renderName() const { return "RenderSVGShape"; } 94 95 virtual void layout() OVERRIDE FINAL; 96 virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE FINAL; 97 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE FINAL; 98 99 virtual bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction) OVERRIDE FINAL; 100 101 virtual FloatRect objectBoundingBox() const OVERRIDE FINAL { return m_fillBoundingBox; } 102 virtual FloatRect strokeBoundingBox() const OVERRIDE FINAL { return m_strokeBoundingBox; } 103 FloatRect calculateObjectBoundingBox() const; 104 FloatRect calculateStrokeBoundingBox() const; 105 void updateRepaintBoundingBox(); 106 107 bool setupNonScalingStrokeContext(AffineTransform&, GraphicsContextStateSaver&); 108 109 bool shouldGenerateMarkerPositions() const; 110 FloatRect markerRect(float strokeWidth) const; 111 void processMarkerPositions(); 112 113 void fillShape(RenderStyle*, GraphicsContext*); 114 void strokeShape(RenderStyle*, GraphicsContext*); 115 void drawMarkers(PaintInfo&); 116 117 private: 118 FloatRect m_repaintBoundingBox; 119 FloatRect m_repaintBoundingBoxExcludingShadow; 120 AffineTransform m_localTransform; 121 OwnPtr<Path> m_path; 122 Vector<MarkerPosition> m_markerPositions; 123 124 bool m_needsBoundariesUpdate : 1; 125 bool m_needsShapeUpdate : 1; 126 bool m_needsTransformUpdate : 1; 127 }; 128 129 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderSVGShape, isSVGShape()); 130 131 } 132 133 #endif 134