Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/style/CachedInheritingStyles.cpp
Line
Count
Source (jump to first uncovered line)
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
#include "mozilla/CachedInheritingStyles.h"
8
9
#include "mozilla/ComputedStyle.h"
10
#include "nsCOMPtr.h"
11
#include "nsIMemoryReporter.h"
12
#include "nsWindowSizes.h"
13
14
namespace mozilla {
15
16
void
17
CachedInheritingStyles::Insert(ComputedStyle* aStyle)
18
0
{
19
0
  MOZ_ASSERT(aStyle);
20
0
  MOZ_ASSERT(aStyle->IsInheritingAnonBox() || aStyle->IsLazilyCascadedPseudoElement());
21
0
22
0
  if (IsEmpty()) {
23
0
    RefPtr<ComputedStyle> s = aStyle;
24
0
    mBits = reinterpret_cast<uintptr_t>(s.forget().take());
25
0
    MOZ_ASSERT(!IsEmpty() && !IsIndirect());
26
0
  } else if (IsIndirect()) {
27
0
    AsIndirect()->AppendElement(aStyle);
28
0
  } else {
29
0
    IndirectCache* cache = new IndirectCache();
30
0
    cache->AppendElement(dont_AddRef(AsDirect()));
31
0
    cache->AppendElement(aStyle);
32
0
    mBits = reinterpret_cast<uintptr_t>(cache) | 1;
33
0
    MOZ_ASSERT(IsIndirect());
34
0
  }
35
0
}
36
37
ComputedStyle*
38
CachedInheritingStyles::Lookup(nsAtom* aPseudoTag) const
39
0
{
40
0
  MOZ_ASSERT(nsCSSAnonBoxes::IsInheritingAnonBox(aPseudoTag) ||
41
0
             nsCSSPseudoElements::IsPseudoElement(aPseudoTag));
42
0
  if (IsIndirect()) {
43
0
    for (auto& style : *AsIndirect()) {
44
0
      if (style->GetPseudo() == aPseudoTag) {
45
0
        return style;
46
0
      }
47
0
    }
48
0
49
0
    return nullptr;
50
0
  }
51
0
52
0
  ComputedStyle* direct = AsDirect();
53
0
  return direct && direct->GetPseudo() == aPseudoTag ? direct : nullptr;
54
0
}
55
56
void
57
CachedInheritingStyles::AddSizeOfIncludingThis(nsWindowSizes& aSizes, size_t* aCVsSize) const
58
0
{
59
0
  if (IsIndirect()) {
60
0
    for (auto& style : *AsIndirect()) {
61
0
      if (!aSizes.mState.HaveSeenPtr(style)) {
62
0
        style->AddSizeOfIncludingThis(aSizes, aCVsSize);
63
0
      }
64
0
    }
65
0
66
0
    return;
67
0
  }
68
0
69
0
  ComputedStyle* direct = AsDirect();
70
0
  if (direct && !aSizes.mState.HaveSeenPtr(direct)) {
71
0
    direct->AddSizeOfIncludingThis(aSizes, aCVsSize);
72
0
  }
73
0
}
74
75
} // namespace mozilla