Bug 1880216 - Migrate Fenix docs into Sphinx. r=owlish,geckoview-reviewers,android...
[gecko.git] / dom / animation / CSSPseudoElement.h
blob4b5fbc917c32582a0cd3280d469d9d164d201ac9
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"
17 namespace mozilla::dom {
19 class Animation;
20 class Element;
21 class UnrestrictedDoubleOrKeyframeAnimationOptions;
23 class CSSPseudoElement final : public nsWrapperCache {
24 public:
25 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CSSPseudoElement)
26 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(CSSPseudoElement)
28 protected:
29 virtual ~CSSPseudoElement();
31 public:
32 ParentObject GetParentObject() const;
34 virtual JSObject* WrapObject(JSContext* aCx,
35 JS::Handle<JSObject*> aGivenProto) override;
37 PseudoStyleType GetType() const { return mPseudoType; }
38 void GetType(nsString& aRetVal) const {
39 MOZ_ASSERT(nsCSSPseudoElements::GetPseudoAtom(mPseudoType),
40 "All pseudo-types allowed by this class should have a"
41 " corresponding atom");
42 // Our atoms use one colon and we would like to return two colons syntax
43 // for the returned pseudo type string, so serialize this to the
44 // non-deprecated two colon syntax.
45 aRetVal.Assign(char16_t(':'));
46 aRetVal.Append(
47 nsDependentAtomString(nsCSSPseudoElements::GetPseudoAtom(mPseudoType)));
49 dom::Element* Element() const { return mOriginatingElement.get(); }
51 // Given an element:pseudoType pair, returns the CSSPseudoElement stored as a
52 // property on |aElement|. If there is no CSSPseudoElement for the specified
53 // pseudo-type on element, a new CSSPseudoElement will be created and stored
54 // on the element.
55 static already_AddRefed<CSSPseudoElement> GetCSSPseudoElement(
56 dom::Element* aElement, PseudoStyleType aType);
58 private:
59 // Only ::before, ::after and ::marker are supported.
60 CSSPseudoElement(dom::Element* aElement, PseudoStyleType aType);
62 static nsAtom* GetCSSPseudoElementPropertyAtom(PseudoStyleType aType);
64 // mOriginatingElement needs to be an owning reference since if script is
65 // holding on to the pseudo-element, it needs to continue to be able to refer
66 // to the originating element.
67 RefPtr<dom::Element> mOriginatingElement;
68 PseudoStyleType mPseudoType;
71 } // namespace mozilla::dom
73 #endif // mozilla_dom_CSSPseudoElement_h