Warning, file /frameworks/khtml/src/rendering/SVGRenderStyle.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
0003                   2004, 2005 Rob Buis <buis@kde.org>
0004     Copyright (C) 2005, 2006 Apple Computer, Inc.
0005 
0006      This file is part of the KDE project
0007 
0008     This library is free software; you can redistribute it and/or
0009     modify it under the terms of the GNU Library General Public
0010     License as published by the Free Software Foundation; either
0011     version 2 of the License, or (at your option) any later version.
0012 
0013     This library is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     Library General Public License for more details.
0017 
0018     You should have received a copy of the GNU Library General Public License
0019     along with this library; see the file COPYING.LIB.  If not, write to
0020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0021     Boston, MA 02110-1301, USA.
0022 */
0023 
0024 #ifndef SVGRenderStyle_h
0025 #define SVGRenderStyle_h
0026 
0027 #include "css/css_svgvalueimpl.h"
0028 #include "platform/graphics/GraphicsTypes.h"
0029 #include "platform/graphics/Path.h"
0030 #include "rendering/DataRef.h"
0031 #include "SVGRenderStyleDefs.h"
0032 
0033 #include <stdint.h>
0034 
0035 using DOM::DOMString;
0036 
0037 namespace khtml
0038 {
0039 class SVGRenderStyle : public RefCounted<SVGRenderStyle>
0040 {
0041 public:
0042     static PassRefPtr<SVGRenderStyle> create()
0043     {
0044         return adoptRef(new SVGRenderStyle);
0045     }
0046     PassRefPtr<SVGRenderStyle> copy() const
0047     {
0048         return adoptRef(new SVGRenderStyle(*this));
0049     }
0050     ~SVGRenderStyle();
0051 
0052     bool inheritedNotEqual(const SVGRenderStyle *) const;
0053     void inheritFrom(const SVGRenderStyle *);
0054 
0055     bool operator==(const SVGRenderStyle &) const;
0056     bool operator!=(const SVGRenderStyle &o) const
0057     {
0058         return !(*this == o);
0059     }
0060 
0061     // SVG CSS Properties
0062     SVG_RS_DEFINE_ATTRIBUTE(EAlignmentBaseline, AlignmentBaseline, alignmentBaseline, AB_AUTO)
0063     SVG_RS_DEFINE_ATTRIBUTE(EDominantBaseline, DominantBaseline, dominantBaseline, DB_AUTO)
0064     SVG_RS_DEFINE_ATTRIBUTE(EBaselineShift, BaselineShift, baselineShift, BS_BASELINE)
0065 
0066     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(LineCap, CapStyle, capStyle, ButtCap)
0067     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(WindRule, ClipRule, clipRule, RULE_NONZERO)
0068     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorInterpolation, ColorInterpolation, colorInterpolation, CI_SRGB)
0069     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorInterpolation, ColorInterpolationFilters, colorInterpolationFilters, CI_LINEARRGB)
0070     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorRendering, ColorRendering, colorRendering, CR_AUTO)
0071     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(WindRule, FillRule, fillRule, RULE_NONZERO)
0072     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EImageRendering, ImageRendering, imageRendering, IR_AUTO)
0073     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(LineJoin, JoinStyle, joinStyle, MiterJoin)
0074     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EPointerEvents, PointerEvents, pointerEvents, PE_VISIBLE_PAINTED)
0075     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EShapeRendering, ShapeRendering, shapeRendering, SR_AUTO)
0076     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(ETextAnchor, TextAnchor, textAnchor, TA_START)
0077     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(ETextRendering, TextRendering, textRendering, TR_AUTO)
0078     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EWritingMode, WritingMode, writingMode, WM_LRTB)
0079     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EGlyphOrientation, GlyphOrientationHorizontal, glyphOrientationHorizontal, GO_0DEG)
0080     SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EGlyphOrientation, GlyphOrientationVertical, glyphOrientationVertical, GO_AUTO)
0081 
0082     // SVG CSS Properties (using DataRef's)
0083     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, fill, opacity, FillOpacity, fillOpacity, 1.0f)
0084     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(SVGPaintImpl, fill, paint, FillPaint, fillPaint, SVGPaintImpl::defaultFill())
0085 
0086     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stroke, opacity, StrokeOpacity, strokeOpacity, 1.0f)
0087     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(SVGPaintImpl, stroke, paint, StrokePaint, strokePaint, SVGPaintImpl::defaultStroke())
0088     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValueListImpl, stroke, dashArray, StrokeDashArray, strokeDashArray, nullptr)
0089     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stroke, miterLimit, StrokeMiterLimit, strokeMiterLimit, 4.0f)
0090 
0091     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValueImpl, stroke, width, StrokeWidth, strokeWidth, nullptr)
0092     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValueImpl, stroke, dashOffset, StrokeDashOffset, strokeDashOffset, nullptr);
0093 
0094     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValueImpl, text, kerning, Kerning, kerning, nullptr)
0095 
0096     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stops, opacity, StopOpacity, stopOpacity, 1.0f)
0097     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(QColor, stops, color, StopColor, stopColor, QColor(0, 0, 0))
0098 
0099     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(DOMString, clip, clipPath, ClipPath, clipPath, DOMString())
0100     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(DOMString, mask, maskElement, MaskElement, maskElement, DOMString())
0101     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(DOMString, markers, startMarker, StartMarker, startMarker, DOMString())
0102     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(DOMString, markers, midMarker, MidMarker, midMarker, DOMString())
0103     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(DOMString, markers, endMarker, EndMarker, endMarker, DOMString())
0104 
0105     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(DOMString, misc, filter, Filter, filter, DOMString())
0106     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, misc, floodOpacity, FloodOpacity, floodOpacity, 1.0f)
0107     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(QColor, misc, floodColor, FloodColor, floodColor, QColor(0, 0, 0))
0108     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(QColor, misc, lightingColor, LightingColor, lightingColor, QColor(255, 255, 255))
0109     SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValueImpl, misc, baselineShiftValue, BaselineShiftValue, baselineShiftValue, nullptr)
0110 
0111     // convenience
0112     bool hasStroke() const
0113     {
0114         return (strokePaint()->paintType() != SVGPaintImpl::SVG_PAINTTYPE_NONE);
0115     }
0116     bool hasFill() const
0117     {
0118         return (fillPaint()->paintType() != SVGPaintImpl::SVG_PAINTTYPE_NONE);
0119     }
0120 
0121     static float cssPrimitiveToLength(const RenderObject *, CSSValueImpl *, float defaultValue = 0.0f);
0122 
0123 protected:
0124     // inherit
0125     struct InheritedFlags {
0126         bool operator==(const InheritedFlags &other) const
0127         {
0128             return (_colorRendering == other._colorRendering) &&
0129                    (_imageRendering == other._imageRendering) &&
0130                    (_shapeRendering == other._shapeRendering) &&
0131                    (_textRendering == other._textRendering) &&
0132                    (_clipRule == other._clipRule) &&
0133                    (_fillRule == other._fillRule) &&
0134                    (_capStyle == other._capStyle) &&
0135                    (_joinStyle == other._joinStyle) &&
0136                    (_textAnchor == other._textAnchor) &&
0137                    (_colorInterpolation == other._colorInterpolation) &&
0138                    (_colorInterpolationFilters == other._colorInterpolationFilters) &&
0139                    (_pointerEvents == other._pointerEvents) &&
0140                    (_writingMode == other._writingMode) &&
0141                    (_glyphOrientationHorizontal == other._glyphOrientationHorizontal) &&
0142                    (_glyphOrientationVertical == other._glyphOrientationVertical);
0143         }
0144 
0145         bool operator!=(const InheritedFlags &other) const
0146         {
0147             return !(*this == other);
0148         }
0149 
0150         unsigned _colorRendering : 2; // EColorRendering
0151         unsigned _imageRendering : 2; // EImageRendering
0152         unsigned _shapeRendering : 2; // EShapeRendering
0153         unsigned _textRendering : 2; // ETextRendering
0154         unsigned _clipRule : 1; // WindRule
0155         unsigned _fillRule : 1; // WindRule
0156         unsigned _capStyle : 2; // LineCap
0157         unsigned _joinStyle : 2; // LineJoin
0158         unsigned _textAnchor : 2; // ETextAnchor
0159         unsigned _colorInterpolation : 2; // EColorInterpolation
0160         unsigned _colorInterpolationFilters : 2; // EColorInterpolation
0161         unsigned _pointerEvents : 4; // EPointerEvents
0162         unsigned _writingMode : 3; // EWritingMode
0163         unsigned _glyphOrientationHorizontal : 3; // EGlyphOrientation
0164         unsigned _glyphOrientationVertical : 3; // EGlyphOrientation
0165     } svg_inherited_flags;
0166 
0167     // don't inherit
0168     struct NonInheritedFlags {
0169         // 32 bit non-inherited, don't add to the struct, or the operator will break.
0170         bool operator==(const NonInheritedFlags &other) const
0171         {
0172             return _niflags == other._niflags;
0173         }
0174         bool operator!=(const NonInheritedFlags &other) const
0175         {
0176             return _niflags != other._niflags;
0177         }
0178 
0179         union {
0180             struct {
0181                 unsigned _alignmentBaseline : 4; // EAlignmentBaseline
0182                 unsigned _dominantBaseline : 4; // EDominantBaseline
0183                 unsigned _baselineShift : 2; // EBaselineShift
0184                 // 22 bits unused
0185             } f;
0186             uint32_t _niflags;
0187         };
0188     } svg_noninherited_flags;
0189 
0190     // inherited attributes
0191     khtml::DataRef<StyleFillData> fill;
0192     DataRef<StyleStrokeData> stroke;
0193     DataRef<StyleMarkerData> markers;
0194     DataRef<StyleTextData> text;
0195 
0196     // non-inherited attributes
0197     DataRef<StyleStopData> stops;
0198     DataRef<StyleClipData> clip;
0199     DataRef<StyleMaskData> mask;
0200     DataRef<StyleMiscData> misc;
0201 
0202 private:
0203     enum CreateDefaultType { CreateDefault };
0204 
0205 public:
0206     SVGRenderStyle();
0207     SVGRenderStyle(const SVGRenderStyle &);
0208 private:
0209     SVGRenderStyle(CreateDefaultType); // Used to create the default style.
0210 
0211     void setBitDefaults()
0212     {
0213         svg_inherited_flags._clipRule = initialClipRule();
0214         svg_inherited_flags._colorRendering = initialColorRendering();
0215         svg_inherited_flags._fillRule = initialFillRule();
0216         svg_inherited_flags._imageRendering = initialImageRendering();
0217         svg_inherited_flags._shapeRendering = initialShapeRendering();
0218         svg_inherited_flags._textRendering = initialTextRendering();
0219         svg_inherited_flags._textAnchor = initialTextAnchor();
0220         svg_inherited_flags._capStyle = initialCapStyle();
0221         svg_inherited_flags._joinStyle = initialJoinStyle();
0222         svg_inherited_flags._colorInterpolation = initialColorInterpolation();
0223         svg_inherited_flags._colorInterpolationFilters = initialColorInterpolationFilters();
0224         svg_inherited_flags._pointerEvents = initialPointerEvents();
0225         svg_inherited_flags._writingMode = initialWritingMode();
0226         svg_inherited_flags._glyphOrientationHorizontal = initialGlyphOrientationHorizontal();
0227         svg_inherited_flags._glyphOrientationVertical = initialGlyphOrientationVertical();
0228 
0229         svg_noninherited_flags._niflags = 0;
0230         svg_noninherited_flags.f._alignmentBaseline = initialAlignmentBaseline();
0231         svg_noninherited_flags.f._dominantBaseline = initialDominantBaseline();
0232         svg_noninherited_flags.f._baselineShift = initialBaselineShift();
0233     }
0234 };
0235 
0236 } // namespace khtml
0237 
0238 #endif // SVGRenderStyle_h
0239