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"
11 #include "nsWindowSizes.h"
15 void CachedInheritingStyles::Insert(ComputedStyle
* aStyle
) {
17 MOZ_ASSERT(aStyle
->IsInheritingAnonBox() ||
18 aStyle
->IsLazilyCascadedPseudoElement());
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
);
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
));
39 for (auto& style
: *AsIndirect()) {
40 if (style
->GetPseudoType() == aType
) {
48 ComputedStyle
* direct
= AsDirect();
49 return direct
&& direct
->GetPseudoType() == aType
? direct
: nullptr;
52 void CachedInheritingStyles::AddSizeOfIncludingThis(nsWindowSizes
& aSizes
,
53 size_t* aCVsSize
) const {
55 for (auto& style
: *AsIndirect()) {
56 if (!aSizes
.mState
.HaveSeenPtr(style
)) {
57 style
->AddSizeOfIncludingThis(aSizes
, aCVsSize
);
64 ComputedStyle
* direct
= AsDirect();
65 if (direct
&& !aSizes
.mState
.HaveSeenPtr(direct
)) {
66 direct
->AddSizeOfIncludingThis(aSizes
, aCVsSize
);
70 } // namespace mozilla