Line data Source code
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 mozilla_dom_SVGTests_h
8 : #define mozilla_dom_SVGTests_h
9 :
10 : #include "nsStringFwd.h"
11 : #include "SVGStringList.h"
12 : #include "nsCOMPtr.h"
13 :
14 : class nsAttrValue;
15 : class nsIAtom;
16 : class nsString;
17 :
18 : namespace mozilla {
19 : class DOMSVGStringList;
20 :
21 : #define MOZILLA_DOMSVGTESTS_IID \
22 : { 0x92370da8, 0xda28, 0x4895, \
23 : {0x9b, 0x1b, 0xe0, 0x06, 0x0d, 0xb7, 0x3f, 0xc3 } }
24 :
25 : namespace dom {
26 :
27 : class SVGTests : public nsISupports
28 : {
29 : public:
30 : NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOMSVGTESTS_IID)
31 :
32 : SVGTests();
33 :
34 : friend class mozilla::DOMSVGStringList;
35 : typedef mozilla::SVGStringList SVGStringList;
36 :
37 : /**
38 : * Compare the language name(s) in a systemLanguage attribute to the
39 : * user's language preferences, as defined in
40 : * http://www.w3.org/TR/SVG11/struct.html#SystemLanguageAttribute
41 : * We have a match if a language name in the users language preferences
42 : * exactly equals one of the language names or exactly equals a prefix of
43 : * one of the language names in the systemLanguage attribute.
44 : * @returns 2 * the lowest index in the aAcceptLangs that matches + 1
45 : * if only the prefix matches, -2 if there's no systemLanguage attribute,
46 : * or -1 if no indices match.
47 : * XXX This algorithm is O(M*N).
48 : */
49 : int32_t GetBestLanguagePreferenceRank(const nsAString& aAcceptLangs) const;
50 :
51 : /**
52 : * Special value to pass to PassesConditionalProcessingTests to ignore systemLanguage
53 : * attributes
54 : */
55 : static const nsString * const kIgnoreSystemLanguage;
56 :
57 : /**
58 : * Check whether the conditional processing attributes requiredFeatures,
59 : * requiredExtensions and systemLanguage all "return true" if they apply to
60 : * and are specified on the given element. Returns true if this element
61 : * should be rendered, false if it should not.
62 : *
63 : * @param aAcceptLangs Optional parameter to pass in the value of the
64 : * intl.accept_languages preference if the caller has it cached.
65 : * Alternatively, pass in kIgnoreSystemLanguage to skip the systemLanguage
66 : * check if the caller is giving that special treatment.
67 : */
68 : bool PassesConditionalProcessingTests(
69 : const nsString *aAcceptLangs = nullptr) const;
70 :
71 : /**
72 : * Returns true if the attribute is one of the conditional processing
73 : * attributes.
74 : */
75 : bool IsConditionalProcessingAttribute(const nsIAtom* aAttribute) const;
76 :
77 : bool ParseConditionalProcessingAttribute(
78 : nsIAtom* aAttribute,
79 : const nsAString& aValue,
80 : nsAttrValue& aResult);
81 :
82 : /**
83 : * Unsets a conditional processing attribute.
84 : */
85 : void UnsetAttr(const nsIAtom* aAttribute);
86 :
87 : nsIAtom* GetAttrName(uint8_t aAttrEnum) const;
88 : void GetAttrValue(uint8_t aAttrEnum, nsAttrValue &aValue) const;
89 :
90 : void MaybeInvalidate();
91 :
92 : // WebIDL
93 : already_AddRefed<DOMSVGStringList> RequiredFeatures();
94 : already_AddRefed<DOMSVGStringList> RequiredExtensions();
95 : already_AddRefed<DOMSVGStringList> SystemLanguage();
96 : bool HasExtension(const nsAString& aExtension);
97 :
98 : virtual bool IsInChromeDoc() const = 0;
99 :
100 : protected:
101 0 : virtual ~SVGTests() {}
102 :
103 : private:
104 : enum { FEATURES, EXTENSIONS, LANGUAGE };
105 : SVGStringList mStringListAttributes[3];
106 : static nsIAtom** sStringListNames[3];
107 : };
108 :
109 : NS_DEFINE_STATIC_IID_ACCESSOR(SVGTests, MOZILLA_DOMSVGTESTS_IID)
110 :
111 : } // namespace dom
112 : } // namespace mozilla
113 :
114 : #endif // mozilla_dom_SVGTests_h
|