Bug 1812499 [wpt PR 38184] - Simplify handling of name-to-subdir mapping in canvas...
[gecko.git] / dom / base / GeneratedImageContent.h
blob28132c3c4312650c27a752d3d41241ba55947b9b
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 dom_base_GeneratedImageContent_h
8 #define dom_base_GeneratedImageContent_h
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. */
14 #include "mozilla/dom/HTMLElementBinding.h"
15 #include "mozilla/dom/NameSpaceConstants.h"
16 #include "mozilla/dom/NodeInfo.h"
17 #include "nsGenericHTMLElement.h"
19 namespace mozilla::dom {
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&);
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");
35 ElementState IntrinsicState() const override {
36 ElementState state = nsGenericHTMLElement::IntrinsicState();
37 if (mBroken) {
38 state |= ElementState::BROKEN;
40 return state;
42 nsresult Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const final;
44 nsresult CopyInnerTo(GeneratedImageContent* aDest) {
45 nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
46 NS_ENSURE_SUCCESS(rv, rv);
47 aDest->mIndex = mIndex;
48 return NS_OK;
51 // Is this an image created from 'list-style-image'?
52 bool IsForListStyleImageMarker() const { return Index() == uint32_t(-1); }
54 // @note we use -1 for images created from 'list-style-image'
55 uint32_t Index() const { return mIndex; }
57 // Notify this image failed to load.
58 void NotifyLoadFailed() {
59 mBroken = true;
60 UpdateState(true);
63 protected:
64 JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
66 private:
67 virtual ~GeneratedImageContent() = default;
68 uint32_t mIndex = 0;
69 bool mBroken = false;
72 } // namespace mozilla::dom
74 #endif // dom_base_GeneratedImageContent_h