WebKit Bugzilla
Attachment 346520 Details for
Bug 186751
: Remove the SVG elements' attributes macros
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Register SVGFitToViewBox attributes into SVGAttributeRegistry
186751-70.patch (text/plain), 12.85 KB, created by
Said Abou-Hallawa
on 2018-08-03 12:37:37 PDT
(
hide
)
Description:
Register SVGFitToViewBox attributes into SVGAttributeRegistry
Filename:
MIME Type:
Creator:
Said Abou-Hallawa
Created:
2018-08-03 12:37:37 PDT
Size:
12.85 KB
patch
obsolete
>diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 923f5babccf..17c7c321a0a 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,49 @@ >+2018-08-02 Said Abou-Hallawa <sabouhallawa@apple.com> >+ >+ [70] Remove the SVG elements' attributes macros >+ https://bugs.webkit.org/show_bug.cgi?id=186751 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Register SVGFitToViewBox attributes into SVGAttributeRegistry >+ >+ -- Add a constructor and pass a reference to an SVGElement to it. This >+ is a reference to the owner element. We will keep a reference to this >+ SVGElement in the owner proxy. >+ -- Add registerAttributes() which registers the attributes and call it from >+ the constructor. >+ -- Remove the template function parseAttribute() and replace it with a >+ none template one. This function will be called form the super classes. >+ -- Add the member m_isViewBoxValid which keep tracks of whether m_viewBox >+ is set or not. This is the only attribute that was using >+ SVGSynchronizableAnimatedProperty::isValid. >+ >+ * svg/SVGFitToViewBox.cpp: >+ (WebCore::SVGFitToViewBox::SVGFitToViewBox): >+ (WebCore::SVGFitToViewBox::registerAttributes): >+ (WebCore::SVGFitToViewBox::setViewBox): >+ (WebCore::SVGFitToViewBox::resetViewBox): >+ (WebCore::SVGFitToViewBox::reset): >+ (WebCore::SVGFitToViewBox::parseAttribute): >+ (WebCore::SVGFitToViewBox::parseViewBox): >+ (WebCore::SVGFitToViewBox::svgAttributeChanged): >+ (WebCore::SVGFitToViewBox::isKnownAttribute): Deleted. >+ (WebCore::SVGFitToViewBox::addSupportedAttributes): Deleted. >+ * svg/SVGFitToViewBox.h: >+ (WebCore::SVGFitToViewBox::attributeRegistry): >+ (WebCore::SVGFitToViewBox::viewBox const): >+ (WebCore::SVGFitToViewBox::preserveAspectRatio const): >+ (WebCore::SVGFitToViewBox::viewBoxAnimated): >+ (WebCore::SVGFitToViewBox::preserveAspectRatioAnimated): >+ (WebCore::SVGFitToViewBox::setPreserveAspectRatio): >+ (WebCore::SVGFitToViewBox::resetPreserveAspectRatio): >+ (WebCore::SVGFitToViewBox::viewBoxString const): >+ (WebCore::SVGFitToViewBox::preserveAspectRatioString const): >+ (WebCore::SVGFitToViewBox::hasValidViewBox const): >+ (WebCore::SVGFitToViewBox::hasEmptyViewBox const): >+ (WebCore::SVGFitToViewBox::isKnownAttribute): >+ (WebCore::SVGFitToViewBox::parseAttribute): Deleted. >+ > 2018-08-02 Said Abou-Hallawa <sabouhallawa@apple.com> > > [69] Remove the SVG elements' attributes macros >diff --git a/Source/WebCore/svg/SVGFitToViewBox.cpp b/Source/WebCore/svg/SVGFitToViewBox.cpp >index 770f1f41966..321de6d950d 100644 >--- a/Source/WebCore/svg/SVGFitToViewBox.cpp >+++ b/Source/WebCore/svg/SVGFitToViewBox.cpp >@@ -1,6 +1,7 @@ > /* > * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> > * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@kde.org> >+ * Copyright (C) 2018 Apple Inc. 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 >@@ -32,14 +33,69 @@ > > namespace WebCore { > >-bool SVGFitToViewBox::parseViewBox(Document* doc, const String& s, FloatRect& viewBox) >+SVGFitToViewBox::SVGFitToViewBox(SVGElement& contextElement, AnimatedPropertyState animatedState) >+ : m_contextElement(contextElement) >+ , m_attributeOwnerProxy(*this, contextElement, animatedState) > { >- auto upconvertedCharacters = StringView(s).upconvertedCharacters(); >+ registerAttributes(); >+} >+ >+void SVGFitToViewBox::registerAttributes() >+{ >+ auto& registry = attributeRegistry(); >+ if (!registry.isEmpty()) >+ return; >+ registry.registerAttribute<SVGNames::viewBoxAttr, &SVGFitToViewBox::m_viewBox>(); >+ registry.registerAttribute<SVGNames::preserveAspectRatioAttr, &SVGFitToViewBox::m_preserveAspectRatio>(); >+} >+ >+void SVGFitToViewBox::setViewBox(const FloatRect& viewBox) >+{ >+ m_viewBox.setValue(viewBox); >+ m_isViewBoxValid = true; >+} >+ >+void SVGFitToViewBox::resetViewBox() >+{ >+ m_viewBox.resetValue(); >+ m_isViewBoxValid = false; >+} >+ >+void SVGFitToViewBox::reset() >+{ >+ resetViewBox(); >+ resetPreserveAspectRatio(); >+} >+ >+bool SVGFitToViewBox::parseAttribute(const QualifiedName& name, const AtomicString& value) >+{ >+ if (name == SVGNames::viewBoxAttr) { >+ FloatRect viewBox; >+ if (!value.isNull() && parseViewBox(value, viewBox)) >+ setViewBox(viewBox); >+ else >+ resetViewBox(); >+ return true; >+ } >+ >+ if (name == SVGNames::preserveAspectRatioAttr) { >+ SVGPreserveAspectRatioValue preserveAspectRatio; >+ preserveAspectRatio.parse(value); >+ setPreserveAspectRatio(preserveAspectRatio); >+ return true; >+ } >+ >+ return false; >+} >+ >+bool SVGFitToViewBox::parseViewBox(const AtomicString& value, FloatRect& viewBox) >+{ >+ auto upconvertedCharacters = StringView(value).upconvertedCharacters(); > const UChar* characters = upconvertedCharacters; >- return parseViewBox(doc, characters, characters + s.length(), viewBox, true); >+ return parseViewBox(characters, characters + value.length(), viewBox); > } > >-bool SVGFitToViewBox::parseViewBox(Document* doc, const UChar*& c, const UChar* end, FloatRect& viewBox, bool validate) >+bool SVGFitToViewBox::parseViewBox(const UChar*& c, const UChar* end, FloatRect& viewBox, bool validate) > { > String str(c, end - c); > >@@ -50,33 +106,44 @@ bool SVGFitToViewBox::parseViewBox(Document* doc, const UChar*& c, const UChar* > float width = 0.0f; > float height = 0.0f; > bool valid = parseNumber(c, end, x) && parseNumber(c, end, y) && parseNumber(c, end, width) && parseNumber(c, end, height, false); >- if (!validate) { >- viewBox = FloatRect(x, y, width, height); >- return true; >- } >- if (!valid) { >- doc->accessSVGExtensions().reportWarning("Problem parsing viewBox=\"" + str + "\""); >- return false; >- } > >- if (width < 0.0) { // check that width is positive >- doc->accessSVGExtensions().reportError("A negative value for ViewBox width is not allowed"); >- return false; >- } >- if (height < 0.0) { // check that height is positive >- doc->accessSVGExtensions().reportError("A negative value for ViewBox height is not allowed"); >- return false; >- } >- skipOptionalSVGSpaces(c, end); >- if (c < end) { // nothing should come after the last, fourth number >- doc->accessSVGExtensions().reportWarning("Problem parsing viewBox=\"" + str + "\""); >- return false; >+ if (validate) { >+ Document& document = m_contextElement.document(); >+ >+ if (!valid) { >+ document.accessSVGExtensions().reportWarning("Problem parsing viewBox=\"" + str + "\""); >+ return false; >+ } >+ >+ if (width < 0.0) { // check that width is positive >+ document.accessSVGExtensions().reportError("A negative value for ViewBox width is not allowed"); >+ return false; >+ } >+ >+ if (height < 0.0) { // check that height is positive >+ document.accessSVGExtensions().reportError("A negative value for ViewBox height is not allowed"); >+ return false; >+ } >+ >+ skipOptionalSVGSpaces(c, end); >+ if (c < end) { // nothing should come after the last, fourth number >+ document.accessSVGExtensions().reportWarning("Problem parsing viewBox=\"" + str + "\""); >+ return false; >+ } > } > >- viewBox = FloatRect(x, y, width, height); >+ viewBox = { x, y, width, height }; > return true; > } > >+void SVGFitToViewBox::svgAttributeChanged(const QualifiedName& attrName) >+{ >+ if (attrName == SVGNames::viewBoxAttr) { >+ InstanceInvalidationGuard guard(m_contextElement); >+ updateRelativeLengthsInformation(); >+ } >+} >+ > AffineTransform SVGFitToViewBox::viewBoxToViewTransform(const FloatRect& viewBoxRect, const SVGPreserveAspectRatioValue& preserveAspectRatio, float viewWidth, float viewHeight) > { > if (!viewBoxRect.width() || !viewBoxRect.height() || !viewWidth || !viewHeight) >@@ -85,15 +152,4 @@ AffineTransform SVGFitToViewBox::viewBoxToViewTransform(const FloatRect& viewBox > return preserveAspectRatio.getCTM(viewBoxRect.x(), viewBoxRect.y(), viewBoxRect.width(), viewBoxRect.height(), viewWidth, viewHeight); > } > >-bool SVGFitToViewBox::isKnownAttribute(const QualifiedName& attrName) >-{ >- return attrName == SVGNames::viewBoxAttr || attrName == SVGNames::preserveAspectRatioAttr; >-} >- >-void SVGFitToViewBox::addSupportedAttributes(HashSet<QualifiedName>& supportedAttributes) >-{ >- supportedAttributes.add(SVGNames::viewBoxAttr); >- supportedAttributes.add(SVGNames::preserveAspectRatioAttr); >-} >- > } >diff --git a/Source/WebCore/svg/SVGFitToViewBox.h b/Source/WebCore/svg/SVGFitToViewBox.h >index 10cd608f58e..70ab59ea556 100644 >--- a/Source/WebCore/svg/SVGFitToViewBox.h >+++ b/Source/WebCore/svg/SVGFitToViewBox.h >@@ -1,6 +1,7 @@ > /* > * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> > * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@kde.org> >+ * Copyright (C) 2018 Apple Inc. 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 >@@ -22,6 +23,7 @@ > > #include "FloatRect.h" > #include "QualifiedName.h" >+#include "SVGAttributeRegistry.h" > #include "SVGNames.h" > #include "SVGPreserveAspectRatio.h" > #include <wtf/HashSet.h> >@@ -35,34 +37,46 @@ class SVGFitToViewBox { > public: > static AffineTransform viewBoxToViewTransform(const FloatRect& viewBoxRect, const SVGPreserveAspectRatioValue&, float viewWidth, float viewHeight); > >- static bool isKnownAttribute(const QualifiedName&); >- static void addSupportedAttributes(HashSet<QualifiedName>&); >+ using AttributeOwnerProxy = SVGAttributeOwnerProxyImpl<SVGFitToViewBox>; >+ static AttributeOwnerProxy::AttributeRegistry& attributeRegistry() { return AttributeOwnerProxy::attributeRegistry(); } > >- template<class SVGElementTarget> >- static bool parseAttribute(SVGElementTarget* target, const QualifiedName& name, const AtomicString& value) >- { >- ASSERT(target); >- if (name == SVGNames::viewBoxAttr) { >- FloatRect viewBox; >- bool valueIsValid = !value.isNull() && parseViewBox(&target->document(), value, viewBox); >- target->setViewBoxBaseValue(viewBox, valueIsValid); >- return true; >- } >+ const FloatRect& viewBox() const { return m_viewBox.currentValue(); } >+ const SVGPreserveAspectRatioValue& preserveAspectRatio() const { return m_preserveAspectRatio.currentValue(); } > >- if (name == SVGNames::preserveAspectRatioAttr) { >- SVGPreserveAspectRatioValue preserveAspectRatio; >- preserveAspectRatio.parse(value); >- target->setPreserveAspectRatioBaseValue(preserveAspectRatio); >- return true; >- } >+ RefPtr<SVGAnimatedRect> viewBoxAnimated() { return m_viewBox.animatedProperty(); } >+ RefPtr<SVGAnimatedPreserveAspectRatio> preserveAspectRatioAnimated() { return m_preserveAspectRatio.animatedProperty(); } > >- return false; >- } >+ void setViewBox(const FloatRect&); >+ void resetViewBox(); > >- static bool parseViewBox(Document*, const UChar*& start, const UChar* end, FloatRect& viewBox, bool validate = true); >+ void setPreserveAspectRatio(const SVGPreserveAspectRatioValue& preserveAspectRatio) { m_preserveAspectRatio.setValue(preserveAspectRatio); } >+ void resetPreserveAspectRatio() { m_preserveAspectRatio.resetValue(); } >+ >+ String viewBoxString() const { return m_viewBox.toString(); } >+ String preserveAspectRatioString() const { return m_preserveAspectRatio.toString(); } >+ >+ bool hasValidViewBox() const { return m_isViewBoxValid; } >+ bool hasEmptyViewBox() const { return m_isViewBoxValid && viewBox().isEmpty(); } >+ >+protected: >+ SVGFitToViewBox(SVGElement& contextElement, AnimatedPropertyState = PropertyIsReadWrite); >+ >+ static bool isKnownAttribute(const QualifiedName& attributeName) { return AttributeOwnerProxy::isKnownAttribute(attributeName); } >+ >+ void reset(); >+ bool parseAttribute(const QualifiedName&, const AtomicString&); >+ bool parseViewBox(const AtomicString& value, FloatRect& viewBox); >+ bool parseViewBox(const UChar*& start, const UChar* end, FloatRect& viewBox, bool validate = true); >+ void svgAttributeChanged(const QualifiedName&); > > private: >- static bool parseViewBox(Document*, const String&, FloatRect&); >+ static void registerAttributes(); >+ >+ SVGElement& m_contextElement; >+ AttributeOwnerProxy m_attributeOwnerProxy; >+ SVGAnimatedRectAttribute m_viewBox { m_attributeOwnerProxy }; >+ SVGAnimatedPreserveAspectRatioAttribute m_preserveAspectRatio { m_attributeOwnerProxy }; >+ bool m_isViewBoxValid { false }; > }; > > } // namespace WebCore
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 186751
:
342916
|
342917
|
342985
|
343001
|
343114
|
343123
|
343124
|
343127
|
343129
|
343162
|
343167
|
343169
|
343171
|
343174
|
343213
|
343217
|
343327
|
343335
|
343338
|
343339
|
343343
|
343415
|
343979
|
343989
|
344002
|
344513
|
344516
|
344523
|
344534
|
344536
|
344988
|
344990
|
346097
|
346103
|
346124
|
346129
|
346177
|
346179
|
346180
|
346182
|
346185
|
346188
|
346190
|
346192
|
346193
|
346197
|
346199
|
346201
|
346202
|
346203
|
346204
|
346205
|
346206
|
346207
|
346211
|
346212
|
346217
|
346224
|
346230
|
346233
|
346241
|
346244
|
346245
|
346315
|
346316
|
346317
|
346318
|
346319
|
346320
|
346322
|
346323
|
346324
|
346325
|
346326
|
346327
|
346328
|
346329
|
346330
|
346331
|
346332
|
346333
|
346334
|
346335
|
346336
|
346337
|
346338
|
346339
|
346340
|
346341
|
346342
|
346343
|
346344
|
346345
|
346346
|
346347
|
346348
|
346349
|
346350
|
346518
|
346519
|
346520
|
346521
|
346522
|
346524
|
346525
|
346526
|
346527
|
346528
|
346529
|
346530
|
346531
|
346532
|
346533
|
346534
|
346535
|
346536
|
346537
|
346538
|
346539
|
346540
|
346541
|
346545
|
346546
|
346549
|
346551
|
346552
|
346601
|
346602
|
346611
|
346636
|
346642