Bug 1864419 - Part 1: Factor out ArgumentsData array into container class r=jandem
[gecko.git] / layout / style / CachedInheritingStyles.cpp
blobda6e4d24e66ff917bb4acf33d75cdb7011650a8f
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 #include "mozilla/CachedInheritingStyles.h"
9 #include "mozilla/ComputedStyle.h"
10 #include "nsCOMPtr.h"
11 #include "nsWindowSizes.h"
13 namespace mozilla {
15 void CachedInheritingStyles::Insert(ComputedStyle* aStyle) {
16 MOZ_ASSERT(aStyle);
17 MOZ_ASSERT(aStyle->IsInheritingAnonBox() ||
18 aStyle->IsLazilyCascadedPseudoElement());
20 if (IsEmpty()) {
21 RefPtr<ComputedStyle> s = aStyle;
22 mBits = reinterpret_cast<uintptr_t>(s.forget().take());
23 MOZ_ASSERT(!IsEmpty() && !IsIndirect());
24 } else if (IsIndirect()) {
25 AsIndirect()->AppendElement(aStyle);
26 } else {
27 IndirectCache* cache = new IndirectCache();
28 cache->AppendElement(dont_AddRef(AsDirect()));
29 cache->AppendElement(aStyle);
30 mBits = reinterpret_cast<uintptr_t>(cache) | 1;
31 MOZ_ASSERT(IsIndirect());
35 ComputedStyle* CachedInheritingStyles::Lookup(PseudoStyleType aType) const {
36 MOZ_ASSERT(PseudoStyle::IsPseudoElement(aType) ||
37 PseudoStyle::IsInheritingAnonBox(aType));
38 if (IsIndirect()) {
39 for (auto& style : *AsIndirect()) {
40 if (style->GetPseudoType() == aType) {
41 return style;
45 return nullptr;
48 ComputedStyle* direct = AsDirect();
49 return direct && direct->GetPseudoType() == aType ? direct : nullptr;
52 void CachedInheritingStyles::AddSizeOfIncludingThis(nsWindowSizes& aSizes,
53 size_t* aCVsSize) const {
54 if (IsIndirect()) {
55 for (auto& style : *AsIndirect()) {
56 if (!aSizes.mState.HaveSeenPtr(style)) {
57 style->AddSizeOfIncludingThis(aSizes, aCVsSize);
61 return;
64 ComputedStyle* direct = AsDirect();
65 if (direct && !aSizes.mState.HaveSeenPtr(direct)) {
66 direct->AddSizeOfIncludingThis(aSizes, aCVsSize);
70 } // namespace mozilla