Bug 1877662 - expose mozconfig as an artifact from build-fat-aar. r=glandium,geckovie...
[gecko.git] / layout / base / ContainStyleScopeManager.h
blob890344c93e76c8289e0b65fd44ccd7853aadc871
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 ContainStyleScopeManager_h_
8 #define ContainStyleScopeManager_h_
10 #include "nsClassHashtable.h"
11 #include "nsTHashSet.h"
12 #include "nsQuoteList.h"
13 #include "nsCounterManager.h"
14 #include <memory>
16 class nsIContent;
17 class nsAtom;
19 namespace mozilla {
21 namespace dom {
22 class Element;
25 class ContainStyleScopeManager;
27 /* Implementation of a self-contained `contain: style` scope which manages its
28 * own counters and quotes. Since the `counters()` function has read access to
29 * other `contain: style` scopes, USE counter nodes may link across `contain:
30 * style` scopes. */
31 class ContainStyleScope final {
32 public:
33 ContainStyleScope(ContainStyleScopeManager* aManager,
34 ContainStyleScope* aParent, nsIContent* aContent)
35 : mQuoteList(this),
36 mCounterManager(this),
37 mScopeManager(aManager),
38 mParent(aParent),
39 mContent(aContent) {
40 MOZ_ASSERT(aManager);
41 if (mParent) {
42 mParent->AddChild(this);
46 ~ContainStyleScope() {
47 if (mParent) {
48 mParent->RemoveChild(this);
52 nsQuoteList& GetQuoteList() { return mQuoteList; }
53 nsCounterManager& GetCounterManager() { return mCounterManager; }
54 ContainStyleScopeManager& GetScopeManager() { return *mScopeManager; }
55 ContainStyleScope* GetParent() { return mParent; }
56 nsIContent* GetContent() { return mContent; }
58 void AddChild(ContainStyleScope* aScope) { mChildren.AppendElement(aScope); }
59 void RemoveChild(ContainStyleScope* aScope) {
60 mChildren.RemoveElement(aScope);
62 const nsTArray<ContainStyleScope*>& GetChildren() const { return mChildren; }
64 void RecalcAllCounters();
65 void RecalcAllQuotes();
67 // Find the element in the given nsGenConList that directly precedes
68 // the mContent node of this ContainStyleScope in the flat tree. Can
69 // return null if no element in the list precedes the content.
70 nsGenConNode* GetPrecedingElementInGenConList(nsGenConList*);
72 private:
73 nsQuoteList mQuoteList;
74 nsCounterManager mCounterManager;
76 // We are owned by the |mScopeManager|, so this is guaranteed to be a live
77 // pointer as long as we are alive as well.
78 ContainStyleScopeManager* mScopeManager;
80 // Although parent and child relationships are represented as raw pointers
81 // here, |mScopeManager| is responsible for managing creation and deletion of
82 // all these data structures and also that it happens in the correct order.
83 ContainStyleScope* mParent;
84 nsTArray<ContainStyleScope*> mChildren;
86 // |mContent| is guaranteed to outlive this scope because mScopeManager will
87 // delete the scope when the corresponding frame for |mContent| is destroyed.
88 nsIContent* mContent;
91 /* Management of the tree `contain: style` scopes. This class ensures that
92 * recalculation is done top-down, so that nodes that rely on other nodes in
93 * ancestor `contain: style` scopes are calculated properly. */
94 class ContainStyleScopeManager {
95 public:
96 ContainStyleScopeManager() : mRootScope(this, nullptr, nullptr) {}
97 ContainStyleScope& GetRootScope() { return mRootScope; }
98 ContainStyleScope& GetOrCreateScopeForContent(nsIContent*);
99 ContainStyleScope& GetScopeForContent(nsIContent*);
101 void Clear();
103 // If this frame creates a `contain: style` scope, destroy that scope and
104 // all of its child scopes.
105 void DestroyScopesFor(nsIFrame*);
107 // Destroy this scope and all its children starting from the leaf nodes.
108 void DestroyScope(ContainStyleScope*);
110 bool DestroyCounterNodesFor(nsIFrame*);
111 bool AddCounterChanges(nsIFrame* aNewFrame);
112 nsCounterList* GetOrCreateCounterList(dom::Element&, nsAtom* aCounterName);
114 bool CounterDirty(nsAtom* aCounterName);
115 void SetCounterDirty(nsAtom* aCounterName);
116 void RecalcAllCounters();
117 void SetAllCountersDirty();
119 bool DestroyQuoteNodesFor(nsIFrame*);
120 nsQuoteList* QuoteListFor(dom::Element&);
121 void RecalcAllQuotes();
123 #if defined(DEBUG) || defined(MOZ_LAYOUT_DEBUGGER)
124 void DumpCounters();
125 #endif
127 #ifdef ACCESSIBILITY
128 void GetSpokenCounterText(nsIFrame* aFrame, nsAString& aText);
129 #endif
131 private:
132 ContainStyleScope mRootScope;
133 nsClassHashtable<nsPtrHashKey<nsIContent>, ContainStyleScope> mScopes;
134 nsTHashSet<RefPtr<nsAtom>> mDirtyCounters;
137 } // namespace mozilla
139 #endif /* ContainStyleScopeManager_h_ */