SVGTests.h (3028B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef DOM_SVG_SVGTESTS_H_ 8 #define DOM_SVG_SVGTESTS_H_ 9 10 #include "mozilla/AlreadyAddRefed.h" 11 #include "mozilla/SVGStringList.h" 12 #include "nsStringFwd.h" 13 14 class nsAttrValue; 15 class nsAtom; 16 class nsIContent; 17 class nsStaticAtom; 18 19 namespace mozilla { 20 21 namespace dom { 22 class DOMSVGStringList; 23 class SVGSwitchElement; 24 } // namespace dom 25 26 #define MOZILLA_DOMSVGTESTS_IID \ 27 {0x92370da8, 0xda28, 0x4895, {0x9b, 0x1b, 0xe0, 0x06, 0x0d, 0xb7, 0x3f, 0xc3}} 28 29 namespace dom { 30 31 class SVGElement; 32 33 class SVGTests : public nsISupports { 34 public: 35 NS_INLINE_DECL_STATIC_IID(MOZILLA_DOMSVGTESTS_IID) 36 37 SVGTests(); 38 39 friend class dom::DOMSVGStringList; 40 using SVGStringList = mozilla::SVGStringList; 41 42 /** 43 * Find the active switch child using BCP 47 rules. 44 */ 45 static nsIContent* FindActiveSwitchChild( 46 const dom::SVGSwitchElement* aSwitch); 47 48 /** 49 * Check whether the conditional processing attributes requiredExtensions 50 * and systemLanguage both "return true" if they apply to 51 * and are specified on the given element. Returns true if this element 52 * should be rendered, false if it should not. 53 */ 54 bool PassesConditionalProcessingTests() const; 55 56 /** 57 * Returns true if the attribute is one of the conditional processing 58 * attributes. 59 */ 60 bool IsConditionalProcessingAttribute(const nsAtom* aAttribute) const; 61 62 bool ParseConditionalProcessingAttribute(nsAtom* aAttribute, 63 const nsAString& aValue, 64 nsAttrValue& aResult); 65 66 /** 67 * Unsets a conditional processing attribute. 68 */ 69 void UnsetAttr(const nsAtom* aAttribute); 70 71 nsStaticAtom* GetAttrName(uint8_t aAttrEnum) const; 72 void GetAttrValue(uint8_t aAttrEnum, nsAttrValue& aValue) const; 73 74 void MaybeInvalidate(); 75 76 // WebIDL 77 already_AddRefed<DOMSVGStringList> RequiredExtensions(); 78 already_AddRefed<DOMSVGStringList> SystemLanguage(); 79 80 bool HasExtension(const nsAString& aExtension) const; 81 82 virtual SVGElement* AsSVGElement() = 0; 83 84 const SVGElement* AsSVGElement() const { 85 return const_cast<SVGTests*>(this)->AsSVGElement(); 86 } 87 88 protected: 89 virtual ~SVGTests() = default; 90 91 private: 92 /** 93 * Check whether the extensions processing attribute applies to and is 94 * specified on the given element. Returns true if this element should be 95 * rendered, false if it should not. 96 */ 97 bool PassesRequiredExtensionsTests() const; 98 99 enum { EXTENSIONS, LANGUAGE }; 100 SVGStringList mStringListAttributes[2]; 101 static nsStaticAtom* const sStringListNames[2]; 102 mutable Maybe<bool> mPassesConditionalProcessingTests = Some(true); 103 }; 104 105 } // namespace dom 106 } // namespace mozilla 107 108 #endif // DOM_SVG_SVGTESTS_H_