tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CSSPseudoElement.h (2700B)


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