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