Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
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_CSSPseudoElement_h
8 : #define mozilla_dom_CSSPseudoElement_h
9 :
10 : #include "js/TypeDecls.h"
11 : #include "mozilla/Attributes.h"
12 : #include "mozilla/ErrorResult.h"
13 : #include "mozilla/dom/BindingDeclarations.h"
14 : #include "mozilla/dom/Element.h"
15 : #include "mozilla/RefPtr.h"
16 : #include "nsCSSPseudoElements.h"
17 : #include "nsWrapperCache.h"
18 :
19 : namespace mozilla {
20 : namespace dom {
21 :
22 : class Animation;
23 : class Element;
24 : class UnrestrictedDoubleOrKeyframeAnimationOptions;
25 :
26 : class CSSPseudoElement final : public nsWrapperCache
27 : {
28 : public:
29 0 : NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CSSPseudoElement)
30 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(CSSPseudoElement)
31 :
32 : protected:
33 : virtual ~CSSPseudoElement();
34 :
35 : public:
36 : ParentObject GetParentObject() const;
37 :
38 : virtual JSObject* WrapObject(JSContext* aCx,
39 : JS::Handle<JSObject*> aGivenProto) override;
40 :
41 0 : CSSPseudoElementType GetType() const { return mPseudoType; }
42 0 : void GetType(nsString& aRetVal) const
43 : {
44 0 : MOZ_ASSERT(nsCSSPseudoElements::GetPseudoAtom(mPseudoType),
45 : "All pseudo-types allowed by this class should have a"
46 : " corresponding atom");
47 : // Our atoms use one colon and we would like to return two colons syntax
48 : // for the returned pseudo type string, so serialize this to the
49 : // non-deprecated two colon syntax.
50 0 : aRetVal.Assign(char16_t(':'));
51 0 : aRetVal.Append(
52 0 : nsDependentAtomString(nsCSSPseudoElements::GetPseudoAtom(mPseudoType)));
53 0 : }
54 0 : already_AddRefed<Element> ParentElement() const
55 : {
56 0 : RefPtr<Element> retVal(mParentElement);
57 0 : return retVal.forget();
58 : }
59 :
60 : void GetAnimations(const AnimationFilter& filter,
61 : nsTArray<RefPtr<Animation>>& aRetVal);
62 : already_AddRefed<Animation>
63 : Animate(JSContext* aContext,
64 : JS::Handle<JSObject*> aKeyframes,
65 : const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
66 : ErrorResult& aError);
67 :
68 : // Given an element:pseudoType pair, returns the CSSPseudoElement stored as a
69 : // property on |aElement|. If there is no CSSPseudoElement for the specified
70 : // pseudo-type on element, a new CSSPseudoElement will be created and stored
71 : // on the element.
72 : static already_AddRefed<CSSPseudoElement>
73 : GetCSSPseudoElement(Element* aElement, CSSPseudoElementType aType);
74 :
75 : private:
76 : // Only ::before and ::after are supported.
77 : CSSPseudoElement(Element* aElement, CSSPseudoElementType aType);
78 :
79 : static nsIAtom* GetCSSPseudoElementPropertyAtom(CSSPseudoElementType aType);
80 :
81 : // mParentElement needs to be an owning reference since if script is holding
82 : // on to the pseudo-element, it needs to continue to be able to refer to
83 : // the parent element.
84 : RefPtr<Element> mParentElement;
85 : CSSPseudoElementType mPseudoType;
86 : };
87 :
88 : } // namespace dom
89 : } // namespace mozilla
90 :
91 : #endif // mozilla_dom_CSSPseudoElement_h
|