WebKit Bugzilla
Attachment 346124 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]
Introduce SVGAttributeRegistry
186751-3.patch (text/plain), 9.20 KB, created by
Said Abou-Hallawa
on 2018-07-30 16:44:05 PDT
(
hide
)
Description:
Introduce SVGAttributeRegistry
Filename:
MIME Type:
Creator:
Said Abou-Hallawa
Created:
2018-07-30 16:44:05 PDT
Size:
9.20 KB
patch
obsolete
>diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 0a6c87af7c8..34ba09add61 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,36 @@ >+2018-07-30 Said Abou-Hallawa <sabouhallawa@apple.com> >+ >+ [3] Remove the SVG elements' attributes macros >+ https://bugs.webkit.org/show_bug.cgi?id=186751 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch introduces SVGAttributeRegistry which manages uniformly all the >+ attributes of a given owner. It takes into account the inheritance of the >+ owner by enumerating the SVGAttributeRegistry's of the base types. This >+ class will facilitate registering all common SVG attributes types. Methods >+ for creating the TearOff objects will be added later. >+ >+ * WebCore.xcodeproj/project.pbxproj: >+ * svg/properties/SVGAttributeRegistry.h: Added. >+ (WebCore::SVGAttributeRegistry::isEmpty const): Returns whether the owner >+ has not register any attribute yet. >+ (WebCore::SVGAttributeRegistry::isKnownAttribute const): Checks whether >+ a given attribute is known to the owner or not. It does not loop through >+ the base types. >+ (WebCore::SVGAttributeRegistry::animatedTypes const): >+ (WebCore::SVGAttributeRegistry::synchronizeAttributes const): >+ (WebCore::SVGAttributeRegistry::synchronizeAttribute const): >+ (WebCore::SVGAttributeRegistry::registerAttribute): >+ (WebCore::SVGAttributeRegistry::animatedTypesBaseTypes): Two versions of >+ this method are provided. The first one breaks the recursion which happens >+ when the index I is equal to the number of the base types. The second one >+ is the recursive body which loops through all SVGAttributeRegistry of the >+ base types of the current SVGAttributeRegistry's owner. >+ (WebCore::SVGAttributeRegistry::synchronizeAttributesBaseTypes): Ditto. >+ (WebCore::SVGAttributeRegistry::synchronizeAttributeBaseTypes): Ditto. >+ (WebCore::SVGAttributeRegistry::findAttributeAccessor const): >+ > 2018-07-30 Said Abou-Hallawa <sabouhallawa@apple.com> > > [2] Remove the SVG elements' attributes macros >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index 46452176f1f..ea6a3c11ab6 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -15462,6 +15462,7 @@ > 085A15921289A8DD002710E3 /* SVGAnimatedTransformListPropertyTearOff.h */, > 55FA7FEF210FA386005AEFE7 /* SVGAttribute.h */, > 55FA7FF4210FB688005AEFE7 /* SVGAttributeAccessor.h */, >+ 55FA7FF6210FBE3E005AEFE7 /* SVGAttributeRegistry.h */, > 08FB17C013BC7E9100040086 /* SVGAttributeToPropertyMap.cpp */, > 08FB3F8313BC754C0099FC18 /* SVGAttributeToPropertyMap.h */, > 0810764312828556007C63BA /* SVGListProperty.h */, >@@ -15474,7 +15475,6 @@ > 088A0E03126EF1DB00978F7A /* SVGPropertyTraits.h */, > 0880F70D1282B46D00948505 /* SVGStaticListPropertyTearOff.h */, > 0813A4E91284132600992511 /* SVGStaticPropertyTearOff.h */, >- 55FA7FF6210FBE3E005AEFE7 /* SVGAttributeRegistry.h */, > ); > path = properties; > sourceTree = "<group>"; >diff --git a/Source/WebCore/svg/properties/SVGAttributeRegistry.h b/Source/WebCore/svg/properties/SVGAttributeRegistry.h >index 8b137891791..33e31735d39 100644 >--- a/Source/WebCore/svg/properties/SVGAttributeRegistry.h >+++ b/Source/WebCore/svg/properties/SVGAttributeRegistry.h >@@ -1 +1,133 @@ >+/* >+ * Copyright (C) 2018 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY >+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR >+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY >+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ > >+#pragma once >+ >+#include <wtf/HashMap.h> >+ >+namespace WebCore { >+ >+template<typename OwnerType, typename... BaseTypes> >+class SVGAttributeRegistry { >+public: >+ static SVGAttributeRegistry<OwnerType, BaseTypes...>& singleton() >+ { >+ static NeverDestroyed<SVGAttributeRegistry<OwnerType, BaseTypes...>> map; >+ return map; >+ } >+ >+ bool isEmpty() const { return m_map.isEmpty(); } >+ >+ bool isKnownAttribute(const QualifiedName& attributeName) const >+ { >+ auto it = std::find_if(m_map.begin(), m_map.end(), [&attributeName](const auto& entry) -> bool { >+ return entry.key.matches(attributeName); >+ }); >+ return it != m_map.end(); >+ } >+ >+ Vector<AnimatedPropertyType> animatedTypes(const QualifiedName& attributeName) const >+ { >+ if (const auto* attributeAccessor = findAttributeAccessor(attributeName)) >+ return attributeAccessor->animatedTypes(); >+ return animatedTypesBaseTypes(attributeName); >+ } >+ >+ void synchronizeAttributes(OwnerType& owner, SVGElement& element) const >+ { >+ for (auto* attributeAccessor : m_map.values()) >+ attributeAccessor->synchronizeProperty(owner, element); >+ synchronizeAttributesBaseTypes(owner, element); >+ } >+ >+ bool synchronizeAttribute(OwnerType& owner, SVGElement& element, const QualifiedName& attributeName) const >+ { >+ if (const auto* attributeAccessor = findAttributeAccessor(attributeName)) { >+ attributeAccessor->synchronizeProperty(owner, element); >+ return true; >+ } >+ return synchronizeAttributeBaseTypes(owner, element, attributeName); >+ } >+ >+ void registerAttribute(const SVGAttributeAccessor<OwnerType>& attributeAccessor) >+ { >+ m_map.add(attributeAccessor.attributeName(), &attributeAccessor); >+ } >+ >+private: >+ template<size_t I = 0> >+ static typename std::enable_if<I == sizeof...(BaseTypes), Vector<AnimatedPropertyType>>::type animatedTypesBaseTypes(const QualifiedName&) { return { }; } >+ >+ template<size_t I = 0> >+ static typename std::enable_if<I < sizeof...(BaseTypes), Vector<AnimatedPropertyType>>::type animatedTypesBaseTypes(const QualifiedName& attributeName) >+ { >+ using BaseType = typename std::tuple_element<I, typename std::tuple<BaseTypes...>>::type; >+ auto animatedTypes = BaseType::attributeRegistry().animatedTypes(attributeName); >+ if (!animatedTypes.isEmpty()) >+ return animatedTypes; >+ return animatedTypesBaseTypes<I + 1>(attributeName); >+ } >+ >+ template<size_t I = 0> >+ static typename std::enable_if<I == sizeof...(BaseTypes), void>::type synchronizeAttributesBaseTypes(OwnerType&, Element&) { } >+ >+ template<size_t I = 0> >+ static typename std::enable_if<I < sizeof...(BaseTypes), void>::type synchronizeAttributesBaseTypes(OwnerType& owner, SVGElement& element) >+ { >+ using BaseType = typename std::tuple_element<I, typename std::tuple<BaseTypes...>>::type; >+ BaseType::attributeRegistry().synchronizeAttributes(owner, element); >+ synchronizeAttributesBaseTypes<I + 1>(owner, element); >+ } >+ >+ template<size_t I = 0> >+ static typename std::enable_if<I == sizeof...(BaseTypes), bool>::type synchronizeAttributeBaseTypes(OwnerType&, Element&, const QualifiedName&) { return false; } >+ >+ template<size_t I = 0> >+ static typename std::enable_if<I < sizeof...(BaseTypes), bool>::type synchronizeAttributeBaseTypes(OwnerType& owner, SVGElement& element, const QualifiedName& attributeName) >+ { >+ using BaseType = typename std::tuple_element<I, typename std::tuple<BaseTypes...>>::type; >+ if (BaseType::attributeRegistry().synchronizeAttribute(owner, element, attributeName)) >+ return true; >+ return synchronizeAttributeBaseTypes<I + 1>(owner, element, attributeName); >+ } >+ >+ const SVGAttributeAccessor<OwnerType>* findAttributeAccessor(const OwnerType& owner, const SVGAttribute& attribute) const >+ { >+ for (auto* attributeAccessor : m_map.values()) { >+ if (attributeAccessor->isMatched(owner, attribute)) >+ return attributeAccessor; >+ } >+ return nullptr; >+ } >+ >+ const SVGAttributeAccessor<OwnerType>* findAttributeAccessor(const QualifiedName& attributeName) const >+ { >+ return m_map.get(attributeName); >+ } >+ >+ HashMap<QualifiedName, const SVGAttributeAccessor<OwnerType>*> m_map; >+}; >+ >+}
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