2018-01-09 03:44:55 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2018-01-10 21:57:12 +03:00
|
|
|
#ifndef mozilla_CachedInheritingStyles_h
|
|
|
|
#define mozilla_CachedInheritingStyles_h
|
2018-01-09 03:44:55 +03:00
|
|
|
|
|
|
|
#include "nsAtom.h"
|
2018-02-13 03:53:44 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2018-01-09 03:44:55 +03:00
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
class nsWindowSizes;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
enum class PseudoStyleType : uint8_t;
|
2018-03-22 21:20:41 +03:00
|
|
|
class ComputedStyle;
|
2018-01-09 03:44:55 +03:00
|
|
|
|
2018-01-10 21:57:12 +03:00
|
|
|
// Cache of anonymous box and lazy pseudo styles that inherit from a given
|
|
|
|
// style.
|
2018-01-09 03:44:55 +03:00
|
|
|
//
|
|
|
|
// To minimize memory footprint, the cache is word-sized with a tagged pointer
|
|
|
|
// If there is only one entry, it's stored inline. If there are more, they're
|
|
|
|
// stored in an out-of-line buffer. See bug 1429126 comment 0 and comment 1 for
|
|
|
|
// the measurements and rationale that influenced the design.
|
2018-01-10 21:57:12 +03:00
|
|
|
class CachedInheritingStyles {
|
2018-01-09 03:44:55 +03:00
|
|
|
public:
|
2018-03-22 21:20:41 +03:00
|
|
|
void Insert(ComputedStyle* aStyle);
|
2019-02-19 16:44:33 +03:00
|
|
|
ComputedStyle* Lookup(PseudoStyleType) const;
|
2018-01-09 03:44:55 +03:00
|
|
|
|
2018-01-10 21:57:12 +03:00
|
|
|
CachedInheritingStyles() : mBits(0) {}
|
|
|
|
~CachedInheritingStyles() {
|
2018-01-09 03:44:55 +03:00
|
|
|
if (IsIndirect()) {
|
|
|
|
delete AsIndirect();
|
|
|
|
} else if (!IsEmpty()) {
|
2018-03-22 21:20:41 +03:00
|
|
|
RefPtr<ComputedStyle> ref = dont_AddRef(AsDirect());
|
2018-01-09 03:44:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddSizeOfIncludingThis(nsWindowSizes& aSizes, size_t* aCVsSize) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// See bug 1429126 comment 1 for the choice of four here.
|
2018-03-22 21:20:41 +03:00
|
|
|
typedef AutoTArray<RefPtr<ComputedStyle>, 4> IndirectCache;
|
2018-01-09 03:44:55 +03:00
|
|
|
|
|
|
|
bool IsEmpty() const { return !mBits; }
|
|
|
|
bool IsIndirect() const { return (mBits & 1); }
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* AsDirect() const {
|
2018-01-09 03:44:55 +03:00
|
|
|
MOZ_ASSERT(!IsIndirect());
|
2018-03-22 21:20:41 +03:00
|
|
|
return reinterpret_cast<ComputedStyle*>(mBits);
|
2018-01-09 03:44:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
IndirectCache* AsIndirect() const {
|
|
|
|
MOZ_ASSERT(IsIndirect());
|
|
|
|
return reinterpret_cast<IndirectCache*>(mBits & ~1);
|
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t mBits;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-01-10 21:57:12 +03:00
|
|
|
#endif // mozilla_CachedInheritingStyles_h
|