1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
|
/*
Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
2004, 2005 Rob Buis <buis@kde.org>
Copyright (C) 2005, 2006 Apple Computer, Inc.
Copyright (C) Research In Motion Limited 2010. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef SVGComputedStyle_h
#define SVGComputedStyle_h
#include "core/CoreExport.h"
#include "core/style/DataRef.h"
#include "core/style/ComputedStyleConstants.h"
#include "core/style/SVGComputedStyleDefs.h"
#include "core/style/StyleDifference.h"
#include "platform/Length.h"
#include "platform/graphics/GraphicsTypes.h"
#include "wtf/Forward.h"
#include "wtf/RefCounted.h"
namespace blink {
// TODO(sashab): Move this into a private class on ComputedStyle, and remove
// all methods on it, merging them into copy/creation methods on ComputedStyle
// instead. Keep the allocation logic, only allocating a new object if needed.
class CORE_EXPORT SVGComputedStyle : public RefCounted<SVGComputedStyle> {
public:
static PassRefPtr<SVGComputedStyle> create() {
return adoptRef(new SVGComputedStyle);
}
PassRefPtr<SVGComputedStyle> copy() const {
return adoptRef(new SVGComputedStyle(*this));
}
~SVGComputedStyle();
bool inheritedEqual(const SVGComputedStyle&) const;
bool nonInheritedEqual(const SVGComputedStyle&) const;
void inheritFrom(const SVGComputedStyle*);
void copyNonInheritedFromCached(const SVGComputedStyle*);
StyleDifference diff(const SVGComputedStyle*) const;
bool operator==(const SVGComputedStyle&) const;
bool operator!=(const SVGComputedStyle& o) const { return !(*this == o); }
// Initial values for all the properties
static EAlignmentBaseline initialAlignmentBaseline() { return AB_AUTO; }
static EDominantBaseline initialDominantBaseline() { return DB_AUTO; }
static EBaselineShift initialBaselineShift() { return BS_LENGTH; }
static Length initialBaselineShiftValue() { return Length(Fixed); }
static EVectorEffect initialVectorEffect() { return VE_NONE; }
static EBufferedRendering initialBufferedRendering() { return BR_AUTO; }
static LineCap initialCapStyle() { return ButtCap; }
static WindRule initialClipRule() { return RULE_NONZERO; }
static EColorInterpolation initialColorInterpolation() { return CI_SRGB; }
static EColorInterpolation initialColorInterpolationFilters() {
return CI_LINEARRGB;
}
static EColorRendering initialColorRendering() { return CR_AUTO; }
static WindRule initialFillRule() { return RULE_NONZERO; }
static LineJoin initialJoinStyle() { return MiterJoin; }
static EShapeRendering initialShapeRendering() { return SR_AUTO; }
static ETextAnchor initialTextAnchor() { return TA_START; }
static float initialFillOpacity() { return 1; }
static SVGPaintType initialFillPaintType() { return SVG_PAINTTYPE_RGBCOLOR; }
static Color initialFillPaintColor() { return Color::black; }
static String initialFillPaintUri() { return String(); }
static float initialStrokeOpacity() { return 1; }
static SVGPaintType initialStrokePaintType() { return SVG_PAINTTYPE_NONE; }
static Color initialStrokePaintColor() { return Color(); }
static String initialStrokePaintUri() { return String(); }
static PassRefPtr<SVGDashArray> initialStrokeDashArray();
static Length initialStrokeDashOffset() { return Length(Fixed); }
static float initialStrokeMiterLimit() { return 4; }
static UnzoomedLength initialStrokeWidth() {
return UnzoomedLength(Length(1, Fixed));
}
static float initialStopOpacity() { return 1; }
static Color initialStopColor() { return Color(0, 0, 0); }
static float initialFloodOpacity() { return 1; }
static Color initialFloodColor() { return Color(0, 0, 0); }
static Color initialLightingColor() { return Color(255, 255, 255); }
static const AtomicString& initialMaskerResource() { return nullAtom; }
static const AtomicString& initialMarkerStartResource() { return nullAtom; }
static const AtomicString& initialMarkerMidResource() { return nullAtom; }
static const AtomicString& initialMarkerEndResource() { return nullAtom; }
static EMaskType initialMaskType() { return MT_LUMINANCE; }
static EPaintOrder initialPaintOrder() { return PaintOrderNormal; }
static StylePath* initialD() { return nullptr; }
static Length initialCx() { return Length(Fixed); }
static Length initialCy() { return Length(Fixed); }
static Length initialX() { return Length(Fixed); }
static Length initialY() { return Length(Fixed); }
static Length initialR() { return Length(Fixed); }
static Length initialRx() { return Length(Auto); }
static Length initialRy() { return Length(Auto); }
// SVG CSS Property setters
void setAlignmentBaseline(EAlignmentBaseline val) {
svg_noninherited_flags.f.alignmentBaseline = val;
}
void setDominantBaseline(EDominantBaseline val) {
svg_inherited_flags.dominantBaseline = val;
}
void setBaselineShift(EBaselineShift val) {
svg_noninherited_flags.f.baselineShift = val;
}
void setVectorEffect(EVectorEffect val) {
svg_noninherited_flags.f.vectorEffect = val;
}
void setBufferedRendering(EBufferedRendering val) {
svg_noninherited_flags.f.bufferedRendering = val;
}
void setCapStyle(LineCap val) { svg_inherited_flags.capStyle = val; }
void setClipRule(WindRule val) { svg_inherited_flags.clipRule = val; }
void setColorInterpolation(EColorInterpolation val) {
svg_inherited_flags.colorInterpolation = val;
}
void setColorInterpolationFilters(EColorInterpolation val) {
svg_inherited_flags.colorInterpolationFilters = val;
}
void setColorRendering(EColorRendering val) {
svg_inherited_flags.colorRendering = val;
}
void setFillRule(WindRule val) { svg_inherited_flags.fillRule = val; }
void setJoinStyle(LineJoin val) { svg_inherited_flags.joinStyle = val; }
void setShapeRendering(EShapeRendering val) {
svg_inherited_flags.shapeRendering = val;
}
void setTextAnchor(ETextAnchor val) { svg_inherited_flags.textAnchor = val; }
void setMaskType(EMaskType val) { svg_noninherited_flags.f.maskType = val; }
void setPaintOrder(EPaintOrder val) {
svg_inherited_flags.paintOrder = (int)val;
}
void setD(PassRefPtr<StylePath> d) {
if (!(geometry->d == d))
geometry.access()->d = d;
}
void setCx(const Length& obj) {
if (!(geometry->cx == obj))
geometry.access()->cx = obj;
}
void setCy(const Length& obj) {
if (!(geometry->cy == obj))
geometry.access()->cy = obj;
}
void setX(const Length& obj) {
if (!(geometry->x == obj))
geometry.access()->x = obj;
}
void setY(const Length& obj) {
if (!(geometry->y == obj))
geometry.access()->y = obj;
}
void setR(const Length& obj) {
if (!(geometry->r == obj))
geometry.access()->r = obj;
}
void setRx(const Length& obj) {
if (!(geometry->rx == obj))
geometry.access()->rx = obj;
}
void setRy(const Length& obj) {
if (!(geometry->ry == obj))
geometry.access()->ry = obj;
}
void setFillOpacity(float obj) {
if (!(fill->opacity == obj))
fill.access()->opacity = obj;
}
void setFillPaint(SVGPaintType type,
const Color& color,
const String& uri,
bool applyToRegularStyle = true,
bool applyToVisitedLinkStyle = false) {
if (applyToRegularStyle) {
if (!(fill->paintType == type))
fill.access()->paintType = type;
if (!(fill->paintColor == color))
fill.access()->paintColor = color;
if (!(fill->paintUri == uri))
fill.access()->paintUri = uri;
}
if (applyToVisitedLinkStyle) {
if (!(fill->visitedLinkPaintType == type))
fill.access()->visitedLinkPaintType = type;
if (!(fill->visitedLinkPaintColor == color))
fill.access()->visitedLinkPaintColor = color;
if (!(fill->visitedLinkPaintUri == uri))
fill.access()->visitedLinkPaintUri = uri;
}
}
void setStrokeOpacity(float obj) {
if (!(stroke->opacity == obj))
stroke.access()->opacity = obj;
}
void setStrokePaint(SVGPaintType type,
const Color& color,
const String& uri,
bool applyToRegularStyle = true,
bool applyToVisitedLinkStyle = false) {
if (applyToRegularStyle) {
if (!(stroke->paintType == type))
stroke.access()->paintType = type;
if (!(stroke->paintColor == color))
stroke.access()->paintColor = color;
if (!(stroke->paintUri == uri))
stroke.access()->paintUri = uri;
}
if (applyToVisitedLinkStyle) {
if (!(stroke->visitedLinkPaintType == type))
stroke.access()->visitedLinkPaintType = type;
if (!(stroke->visitedLinkPaintColor == color))
stroke.access()->visitedLinkPaintColor = color;
if (!(stroke->visitedLinkPaintUri == uri))
stroke.access()->visitedLinkPaintUri = uri;
}
}
void setStrokeDashArray(PassRefPtr<SVGDashArray> dashArray) {
if (*stroke->dashArray != *dashArray)
stroke.access()->dashArray = dashArray;
}
void setStrokeMiterLimit(float obj) {
if (!(stroke->miterLimit == obj))
stroke.access()->miterLimit = obj;
}
void setStrokeWidth(const UnzoomedLength& strokeWidth) {
if (!(stroke->width == strokeWidth))
stroke.access()->width = strokeWidth;
}
void setStrokeDashOffset(const Length& dashOffset) {
if (!(stroke->dashOffset == dashOffset))
stroke.access()->dashOffset = dashOffset;
}
void setStopOpacity(float obj) {
if (!(stops->opacity == obj))
stops.access()->opacity = obj;
}
void setStopColor(const Color& obj) {
if (!(stops->color == obj))
stops.access()->color = obj;
}
void setFloodOpacity(float obj) {
if (!(misc->floodOpacity == obj))
misc.access()->floodOpacity = obj;
}
void setFloodColor(const Color& obj) {
if (!(misc->floodColor == obj))
misc.access()->floodColor = obj;
}
void setLightingColor(const Color& obj) {
if (!(misc->lightingColor == obj))
misc.access()->lightingColor = obj;
}
void setBaselineShiftValue(const Length& baselineShiftValue) {
if (!(misc->baselineShiftValue == baselineShiftValue))
misc.access()->baselineShiftValue = baselineShiftValue;
}
// Setters for non-inherited resources
void setMaskerResource(const AtomicString& obj) {
if (!(resources->masker == obj))
resources.access()->masker = obj;
}
// Setters for inherited resources
void setMarkerStartResource(const AtomicString& obj) {
if (!(inheritedResources->markerStart == obj))
inheritedResources.access()->markerStart = obj;
}
void setMarkerMidResource(const AtomicString& obj) {
if (!(inheritedResources->markerMid == obj))
inheritedResources.access()->markerMid = obj;
}
void setMarkerEndResource(const AtomicString& obj) {
if (!(inheritedResources->markerEnd == obj))
inheritedResources.access()->markerEnd = obj;
}
// Read accessors for all the properties
EAlignmentBaseline alignmentBaseline() const {
return (EAlignmentBaseline)svg_noninherited_flags.f.alignmentBaseline;
}
EDominantBaseline dominantBaseline() const {
return (EDominantBaseline)svg_inherited_flags.dominantBaseline;
}
EBaselineShift baselineShift() const {
return (EBaselineShift)svg_noninherited_flags.f.baselineShift;
}
EVectorEffect vectorEffect() const {
return (EVectorEffect)svg_noninherited_flags.f.vectorEffect;
}
EBufferedRendering bufferedRendering() const {
return (EBufferedRendering)svg_noninherited_flags.f.bufferedRendering;
}
LineCap capStyle() const { return (LineCap)svg_inherited_flags.capStyle; }
WindRule clipRule() const { return (WindRule)svg_inherited_flags.clipRule; }
EColorInterpolation colorInterpolation() const {
return (EColorInterpolation)svg_inherited_flags.colorInterpolation;
}
EColorInterpolation colorInterpolationFilters() const {
return (EColorInterpolation)svg_inherited_flags.colorInterpolationFilters;
}
EColorRendering colorRendering() const {
return (EColorRendering)svg_inherited_flags.colorRendering;
}
WindRule fillRule() const { return (WindRule)svg_inherited_flags.fillRule; }
LineJoin joinStyle() const { return (LineJoin)svg_inherited_flags.joinStyle; }
EShapeRendering shapeRendering() const {
return (EShapeRendering)svg_inherited_flags.shapeRendering;
}
ETextAnchor textAnchor() const {
return (ETextAnchor)svg_inherited_flags.textAnchor;
}
float fillOpacity() const { return fill->opacity; }
const SVGPaintType& fillPaintType() const { return fill->paintType; }
const Color& fillPaintColor() const { return fill->paintColor; }
const String& fillPaintUri() const { return fill->paintUri; }
float strokeOpacity() const { return stroke->opacity; }
const SVGPaintType& strokePaintType() const { return stroke->paintType; }
const Color& strokePaintColor() const { return stroke->paintColor; }
const String& strokePaintUri() const { return stroke->paintUri; }
SVGDashArray* strokeDashArray() const { return stroke->dashArray.get(); }
float strokeMiterLimit() const { return stroke->miterLimit; }
const UnzoomedLength& strokeWidth() const { return stroke->width; }
const Length& strokeDashOffset() const { return stroke->dashOffset; }
float stopOpacity() const { return stops->opacity; }
const Color& stopColor() const { return stops->color; }
float floodOpacity() const { return misc->floodOpacity; }
const Color& floodColor() const { return misc->floodColor; }
const Color& lightingColor() const { return misc->lightingColor; }
const Length& baselineShiftValue() const { return misc->baselineShiftValue; }
StylePath* d() const { return geometry->d.get(); }
const Length& cx() const { return geometry->cx; }
const Length& cy() const { return geometry->cy; }
const Length& x() const { return geometry->x; }
const Length& y() const { return geometry->y; }
const Length& r() const { return geometry->r; }
const Length& rx() const { return geometry->rx; }
const Length& ry() const { return geometry->ry; }
const AtomicString& maskerResource() const { return resources->masker; }
const AtomicString& markerStartResource() const {
return inheritedResources->markerStart;
}
const AtomicString& markerMidResource() const {
return inheritedResources->markerMid;
}
const AtomicString& markerEndResource() const {
return inheritedResources->markerEnd;
}
EMaskType maskType() const {
return (EMaskType)svg_noninherited_flags.f.maskType;
}
EPaintOrder paintOrder() const {
return (EPaintOrder)svg_inherited_flags.paintOrder;
}
EPaintOrderType paintOrderType(unsigned index) const;
const SVGPaintType& visitedLinkFillPaintType() const {
return fill->visitedLinkPaintType;
}
const Color& visitedLinkFillPaintColor() const {
return fill->visitedLinkPaintColor;
}
const String& visitedLinkFillPaintUri() const {
return fill->visitedLinkPaintUri;
}
const SVGPaintType& visitedLinkStrokePaintType() const {
return stroke->visitedLinkPaintType;
}
const Color& visitedLinkStrokePaintColor() const {
return stroke->visitedLinkPaintColor;
}
const String& visitedLinkStrokePaintUri() const {
return stroke->visitedLinkPaintUri;
}
bool isFillColorCurrentColor() const {
return fillPaintType() == SVG_PAINTTYPE_CURRENTCOLOR ||
visitedLinkFillPaintType() == SVG_PAINTTYPE_CURRENTCOLOR ||
fillPaintType() == SVG_PAINTTYPE_URI_CURRENTCOLOR ||
visitedLinkFillPaintType() == SVG_PAINTTYPE_URI_CURRENTCOLOR;
}
bool isStrokeColorCurrentColor() const {
return strokePaintType() == SVG_PAINTTYPE_CURRENTCOLOR ||
visitedLinkStrokePaintType() == SVG_PAINTTYPE_CURRENTCOLOR ||
strokePaintType() == SVG_PAINTTYPE_URI_CURRENTCOLOR ||
visitedLinkStrokePaintType() == SVG_PAINTTYPE_URI_CURRENTCOLOR;
}
// convenience
bool hasMasker() const { return !maskerResource().isEmpty(); }
bool hasMarkers() const {
return !markerStartResource().isEmpty() || !markerMidResource().isEmpty() ||
!markerEndResource().isEmpty();
}
bool hasStroke() const { return strokePaintType() != SVG_PAINTTYPE_NONE; }
bool hasVisibleStroke() const {
return hasStroke() && !strokeWidth().isZero();
}
bool hasSquareCapStyle() const { return capStyle() == SquareCap; }
bool hasMiterJoinStyle() const { return joinStyle() == MiterJoin; }
bool hasFill() const { return fillPaintType() != SVG_PAINTTYPE_NONE; }
protected:
// inherit
struct InheritedFlags {
bool operator==(const InheritedFlags& other) const {
return (colorRendering == other.colorRendering) &&
(shapeRendering == other.shapeRendering) &&
(clipRule == other.clipRule) && (fillRule == other.fillRule) &&
(capStyle == other.capStyle) && (joinStyle == other.joinStyle) &&
(textAnchor == other.textAnchor) &&
(colorInterpolation == other.colorInterpolation) &&
(colorInterpolationFilters == other.colorInterpolationFilters) &&
(paintOrder == other.paintOrder) &&
(dominantBaseline == other.dominantBaseline);
}
bool operator!=(const InheritedFlags& other) const {
return !(*this == other);
}
unsigned colorRendering : 2; // EColorRendering
unsigned shapeRendering : 2; // EShapeRendering
unsigned clipRule : 1; // WindRule
unsigned fillRule : 1; // WindRule
unsigned capStyle : 2; // LineCap
unsigned joinStyle : 2; // LineJoin
unsigned textAnchor : 2; // ETextAnchor
unsigned colorInterpolation : 2; // EColorInterpolation
unsigned colorInterpolationFilters : 2; // EColorInterpolation_
unsigned paintOrder : 3; // EPaintOrder
unsigned dominantBaseline : 4; // EDominantBaseline
} svg_inherited_flags;
// don't inherit
struct NonInheritedFlags {
// 32 bit non-inherited, don't add to the struct, or the operator will
// break.
bool operator==(const NonInheritedFlags& other) const {
return niflags == other.niflags;
}
bool operator!=(const NonInheritedFlags& other) const {
return niflags != other.niflags;
}
union {
struct {
unsigned alignmentBaseline : 4; // EAlignmentBaseline
unsigned baselineShift : 2; // EBaselineShift
unsigned vectorEffect : 1; // EVectorEffect
unsigned bufferedRendering : 2; // EBufferedRendering
unsigned maskType : 1; // EMaskType
// 18 bits unused
} f;
uint32_t niflags;
};
} svg_noninherited_flags;
// inherited attributes
DataRef<StyleFillData> fill;
DataRef<StyleStrokeData> stroke;
DataRef<StyleInheritedResourceData> inheritedResources;
// non-inherited attributes
DataRef<StyleStopData> stops;
DataRef<StyleMiscData> misc;
DataRef<StyleGeometryData> geometry;
DataRef<StyleResourceData> resources;
private:
enum CreateInitialType { CreateInitial };
SVGComputedStyle();
SVGComputedStyle(const SVGComputedStyle&);
SVGComputedStyle(
CreateInitialType); // Used to create the initial style singleton.
bool diffNeedsLayoutAndPaintInvalidation(const SVGComputedStyle* other) const;
bool diffNeedsPaintInvalidation(const SVGComputedStyle* other) const;
void setBitDefaults() {
svg_inherited_flags.clipRule = initialClipRule();
svg_inherited_flags.colorRendering = initialColorRendering();
svg_inherited_flags.fillRule = initialFillRule();
svg_inherited_flags.shapeRendering = initialShapeRendering();
svg_inherited_flags.textAnchor = initialTextAnchor();
svg_inherited_flags.capStyle = initialCapStyle();
svg_inherited_flags.joinStyle = initialJoinStyle();
svg_inherited_flags.colorInterpolation = initialColorInterpolation();
svg_inherited_flags.colorInterpolationFilters =
initialColorInterpolationFilters();
svg_inherited_flags.paintOrder = initialPaintOrder();
svg_inherited_flags.dominantBaseline = initialDominantBaseline();
svg_noninherited_flags.niflags = 0;
svg_noninherited_flags.f.alignmentBaseline = initialAlignmentBaseline();
svg_noninherited_flags.f.baselineShift = initialBaselineShift();
svg_noninherited_flags.f.vectorEffect = initialVectorEffect();
svg_noninherited_flags.f.bufferedRendering = initialBufferedRendering();
svg_noninherited_flags.f.maskType = initialMaskType();
}
};
} // namespace blink
#endif // SVGComputedStyle_h
|