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