tor-browser

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

GeneratedImageContent.h (2264B)


      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 dom_base_GeneratedImageContent_h
      8 #define dom_base_GeneratedImageContent_h
      9 
     10 /* A content node that keeps track of an index in the parent's `content`
     11 * property value, used for url() values in the content of a ::before or ::after
     12 * pseudo-element. */
     13 
     14 #include "mozilla/dom/HTMLElementBinding.h"
     15 #include "mozilla/dom/NameSpaceConstants.h"
     16 #include "mozilla/dom/NodeInfo.h"
     17 #include "nsGenericHTMLElement.h"
     18 
     19 namespace mozilla::dom {
     20 
     21 class GeneratedImageContent final : public nsGenericHTMLElement {
     22 public:
     23  static already_AddRefed<GeneratedImageContent> Create(Document&,
     24                                                        uint32_t aContentIndex);
     25  // An image created from 'list-style-image' for a ::marker pseudo.
     26  static already_AddRefed<GeneratedImageContent> CreateForListStyleImage(
     27      Document&);
     28 
     29  explicit GeneratedImageContent(already_AddRefed<dom::NodeInfo>&& aNodeInfo)
     30      : nsGenericHTMLElement(std::move(aNodeInfo)) {
     31    MOZ_ASSERT(IsInNamespace(kNameSpaceID_XHTML),
     32               "Someone messed up our nodeinfo");
     33  }
     34 
     35  nsresult Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const final;
     36 
     37  nsresult CopyInnerTo(GeneratedImageContent* aDest) {
     38    nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
     39    NS_ENSURE_SUCCESS(rv, rv);
     40    aDest->mIndex = mIndex;
     41    return NS_OK;
     42  }
     43 
     44  // Is this an image created from 'list-style-image'?
     45  bool IsForListStyleImageMarker() const { return Index() == uint32_t(-1); }
     46 
     47  // @note we use -1 for images created from 'list-style-image'
     48  uint32_t Index() const { return mIndex; }
     49 
     50  // Notify this image failed to load.
     51  void NotifyLoadFailed() { SetStates(ElementState::BROKEN, true); }
     52 
     53 protected:
     54  JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
     55 
     56 private:
     57  virtual ~GeneratedImageContent() = default;
     58  uint32_t mIndex = 0;
     59 };
     60 
     61 }  // namespace mozilla::dom
     62 
     63 #endif  // dom_base_GeneratedImageContent_h