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/. */
7 #ifndef mozilla_dom_CSSPseudoElement_h
8 #define mozilla_dom_CSSPseudoElement_h
10 #include "js/TypeDecls.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/dom/BindingDeclarations.h"
13 #include "mozilla/RefPtr.h"
14 #include "nsCSSPseudoElements.h"
15 #include "nsWrapperCache.h"
22 class UnrestrictedDoubleOrKeyframeAnimationOptions
;
24 class CSSPseudoElement final
: public nsWrapperCache
{
26 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CSSPseudoElement
)
27 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(CSSPseudoElement
)
30 virtual ~CSSPseudoElement();
33 ParentObject
GetParentObject() const;
35 virtual JSObject
* WrapObject(JSContext
* aCx
,
36 JS::Handle
<JSObject
*> aGivenProto
) override
;
38 PseudoStyleType
GetType() const { return mPseudoType
; }
39 void GetType(nsString
& aRetVal
) const {
40 MOZ_ASSERT(nsCSSPseudoElements::GetPseudoAtom(mPseudoType
),
41 "All pseudo-types allowed by this class should have a"
42 " corresponding atom");
43 // Our atoms use one colon and we would like to return two colons syntax
44 // for the returned pseudo type string, so serialize this to the
45 // non-deprecated two colon syntax.
46 aRetVal
.Assign(char16_t(':'));
48 nsDependentAtomString(nsCSSPseudoElements::GetPseudoAtom(mPseudoType
)));
50 dom::Element
* Element() const { return mOriginatingElement
.get(); }
52 // Given an element:pseudoType pair, returns the CSSPseudoElement stored as a
53 // property on |aElement|. If there is no CSSPseudoElement for the specified
54 // pseudo-type on element, a new CSSPseudoElement will be created and stored
56 static already_AddRefed
<CSSPseudoElement
> GetCSSPseudoElement(
57 dom::Element
* aElement
, PseudoStyleType aType
);
60 // Only ::before, ::after and ::marker are supported.
61 CSSPseudoElement(dom::Element
* aElement
, PseudoStyleType aType
);
63 static nsAtom
* GetCSSPseudoElementPropertyAtom(PseudoStyleType aType
);
65 // mOriginatingElement needs to be an owning reference since if script is
66 // holding on to the pseudo-element, it needs to continue to be able to refer
67 // to the originating element.
68 RefPtr
<dom::Element
> mOriginatingElement
;
69 PseudoStyleType mPseudoType
;
73 } // namespace mozilla
75 #endif // mozilla_dom_CSSPseudoElement_h