mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-31 14:15:30 +00:00
3836b7c35b
The basic idea here is as follows: * Rule nodes are reference-counted, but releasing them adds them to a linked list rather than freeing them. This allows for the reuse that motivated the original GC scheme. * We get rid of the marking, and instead rely on the reference count. * Sweeping no longer requires a complicated traversal. We just pop items off the free list until it's empty. When a child is destroyed, its parent may go onto the free list. * We remove special handling for the root node, and use a regular reference-counted edge from the style set. * The free list automatically asserts that it's empty (meaning all nodes have been freed) in its destructor, which runs when the style set is destroyed. * We get rid of the list of style context roots on the style set. We still need a count though, because of the HasCachedStyleData check.
262 lines
7.4 KiB
C++
262 lines
7.4 KiB
C++
/* -*- 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/. */
|
|
|
|
#ifndef mozilla_StyleSetHandleInlines_h
|
|
#define mozilla_StyleSetHandleInlines_h
|
|
|
|
#include "mozilla/CSSStyleSheet.h"
|
|
#include "mozilla/ServoStyleSet.h"
|
|
#include "mozilla/ServoStyleSheet.h"
|
|
#include "nsStyleSet.h"
|
|
|
|
#define FORWARD_CONCRETE(method_, geckoargs_, servoargs_) \
|
|
if (IsGecko()) { \
|
|
return AsGecko()->method_ geckoargs_; \
|
|
} else { \
|
|
return AsServo()->method_ servoargs_; \
|
|
}
|
|
|
|
#define FORWARD(method_, args_) FORWARD_CONCRETE(method_, args_, args_)
|
|
|
|
namespace mozilla {
|
|
|
|
void
|
|
StyleSetHandle::Ptr::Delete()
|
|
{
|
|
if (mValue) {
|
|
if (IsGecko()) {
|
|
delete AsGecko();
|
|
} else {
|
|
delete AsServo();
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
StyleSetHandle::Ptr::Init(nsPresContext* aPresContext)
|
|
{
|
|
FORWARD(Init, (aPresContext));
|
|
}
|
|
|
|
void
|
|
StyleSetHandle::Ptr::BeginShutdown()
|
|
{
|
|
FORWARD(BeginShutdown, ());
|
|
}
|
|
|
|
void
|
|
StyleSetHandle::Ptr::Shutdown()
|
|
{
|
|
FORWARD(Shutdown, ());
|
|
}
|
|
|
|
bool
|
|
StyleSetHandle::Ptr::GetAuthorStyleDisabled() const
|
|
{
|
|
FORWARD(GetAuthorStyleDisabled, ());
|
|
}
|
|
|
|
nsresult
|
|
StyleSetHandle::Ptr::SetAuthorStyleDisabled(bool aStyleDisabled)
|
|
{
|
|
FORWARD(SetAuthorStyleDisabled, (aStyleDisabled));
|
|
}
|
|
|
|
void
|
|
StyleSetHandle::Ptr::BeginUpdate()
|
|
{
|
|
FORWARD(BeginUpdate, ());
|
|
}
|
|
|
|
nsresult
|
|
StyleSetHandle::Ptr::EndUpdate()
|
|
{
|
|
FORWARD(EndUpdate, ());
|
|
}
|
|
|
|
// resolve a style context
|
|
already_AddRefed<nsStyleContext>
|
|
StyleSetHandle::Ptr::ResolveStyleFor(dom::Element* aElement,
|
|
nsStyleContext* aParentContext)
|
|
{
|
|
FORWARD(ResolveStyleFor, (aElement, aParentContext));
|
|
}
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
StyleSetHandle::Ptr::ResolveStyleFor(dom::Element* aElement,
|
|
nsStyleContext* aParentContext,
|
|
TreeMatchContext& aTreeMatchContext)
|
|
{
|
|
FORWARD(ResolveStyleFor, (aElement, aParentContext, aTreeMatchContext));
|
|
}
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
StyleSetHandle::Ptr::ResolveStyleForNonElement(nsStyleContext* aParentContext)
|
|
{
|
|
FORWARD(ResolveStyleForNonElement, (aParentContext));
|
|
}
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
StyleSetHandle::Ptr::ResolvePseudoElementStyle(dom::Element* aParentElement,
|
|
CSSPseudoElementType aType,
|
|
nsStyleContext* aParentContext,
|
|
dom::Element* aPseudoElement)
|
|
{
|
|
FORWARD(ResolvePseudoElementStyle, (aParentElement, aType, aParentContext,
|
|
aPseudoElement));
|
|
}
|
|
|
|
// aFlags is an nsStyleSet flags bitfield
|
|
already_AddRefed<nsStyleContext>
|
|
StyleSetHandle::Ptr::ResolveAnonymousBoxStyle(nsIAtom* aPseudoTag,
|
|
nsStyleContext* aParentContext,
|
|
uint32_t aFlags)
|
|
{
|
|
FORWARD(ResolveAnonymousBoxStyle, (aPseudoTag, aParentContext, aFlags));
|
|
}
|
|
|
|
// manage the set of style sheets in the style set
|
|
nsresult
|
|
StyleSetHandle::Ptr::AppendStyleSheet(SheetType aType, StyleSheetHandle aSheet)
|
|
{
|
|
FORWARD_CONCRETE(AppendStyleSheet, (aType, aSheet->AsGecko()),
|
|
(aType, aSheet->AsServo()));
|
|
}
|
|
|
|
nsresult
|
|
StyleSetHandle::Ptr::PrependStyleSheet(SheetType aType, StyleSheetHandle aSheet)
|
|
{
|
|
FORWARD_CONCRETE(PrependStyleSheet, (aType, aSheet->AsGecko()),
|
|
(aType, aSheet->AsServo()));
|
|
}
|
|
|
|
nsresult
|
|
StyleSetHandle::Ptr::RemoveStyleSheet(SheetType aType, StyleSheetHandle aSheet)
|
|
{
|
|
FORWARD_CONCRETE(RemoveStyleSheet, (aType, aSheet->AsGecko()),
|
|
(aType, aSheet->AsServo()));
|
|
}
|
|
|
|
nsresult
|
|
StyleSetHandle::Ptr::ReplaceSheets(SheetType aType,
|
|
const nsTArray<StyleSheetHandle::RefPtr>& aNewSheets)
|
|
{
|
|
if (IsGecko()) {
|
|
nsTArray<RefPtr<CSSStyleSheet>> newSheets(aNewSheets.Length());
|
|
for (auto& sheet : aNewSheets) {
|
|
newSheets.AppendElement(sheet->AsGecko());
|
|
}
|
|
return AsGecko()->ReplaceSheets(aType, newSheets);
|
|
} else {
|
|
nsTArray<RefPtr<ServoStyleSheet>> newSheets(aNewSheets.Length());
|
|
for (auto& sheet : aNewSheets) {
|
|
newSheets.AppendElement(sheet->AsServo());
|
|
}
|
|
return AsServo()->ReplaceSheets(aType, newSheets);
|
|
}
|
|
}
|
|
|
|
nsresult
|
|
StyleSetHandle::Ptr::InsertStyleSheetBefore(SheetType aType,
|
|
StyleSheetHandle aNewSheet,
|
|
StyleSheetHandle aReferenceSheet)
|
|
{
|
|
FORWARD_CONCRETE(
|
|
InsertStyleSheetBefore,
|
|
(aType, aNewSheet->AsGecko(), aReferenceSheet->AsGecko()),
|
|
(aType, aReferenceSheet->AsServo(), aReferenceSheet->AsServo()));
|
|
}
|
|
|
|
int32_t
|
|
StyleSetHandle::Ptr::SheetCount(SheetType aType) const
|
|
{
|
|
FORWARD(SheetCount, (aType));
|
|
}
|
|
|
|
StyleSheetHandle
|
|
StyleSetHandle::Ptr::StyleSheetAt(SheetType aType, int32_t aIndex) const
|
|
{
|
|
FORWARD(StyleSheetAt, (aType, aIndex));
|
|
}
|
|
|
|
nsresult
|
|
StyleSetHandle::Ptr::RemoveDocStyleSheet(StyleSheetHandle aSheet)
|
|
{
|
|
FORWARD_CONCRETE(RemoveDocStyleSheet, (aSheet->AsGecko()),
|
|
(aSheet->AsServo()));
|
|
}
|
|
|
|
nsresult
|
|
StyleSetHandle::Ptr::AddDocStyleSheet(StyleSheetHandle aSheet,
|
|
nsIDocument* aDocument)
|
|
{
|
|
FORWARD_CONCRETE(AddDocStyleSheet, (aSheet->AsGecko(), aDocument),
|
|
(aSheet->AsServo(), aDocument));
|
|
}
|
|
|
|
// check whether there is ::before/::after style for an element
|
|
already_AddRefed<nsStyleContext>
|
|
StyleSetHandle::Ptr::ProbePseudoElementStyle(dom::Element* aParentElement,
|
|
CSSPseudoElementType aType,
|
|
nsStyleContext* aParentContext)
|
|
{
|
|
FORWARD(ProbePseudoElementStyle, (aParentElement, aType, aParentContext));
|
|
}
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
StyleSetHandle::Ptr::ProbePseudoElementStyle(dom::Element* aParentElement,
|
|
CSSPseudoElementType aType,
|
|
nsStyleContext* aParentContext,
|
|
TreeMatchContext& aTreeMatchContext,
|
|
dom::Element* aPseudoElement)
|
|
{
|
|
FORWARD(ProbePseudoElementStyle, (aParentElement, aType, aParentContext,
|
|
aTreeMatchContext, aPseudoElement));
|
|
}
|
|
|
|
nsRestyleHint
|
|
StyleSetHandle::Ptr::HasStateDependentStyle(dom::Element* aElement,
|
|
EventStates aStateMask)
|
|
{
|
|
FORWARD(HasStateDependentStyle, (aElement, aStateMask));
|
|
}
|
|
|
|
nsRestyleHint
|
|
StyleSetHandle::Ptr::HasStateDependentStyle(dom::Element* aElement,
|
|
CSSPseudoElementType aPseudoType,
|
|
dom::Element* aPseudoElement,
|
|
EventStates aStateMask)
|
|
{
|
|
FORWARD(HasStateDependentStyle, (aElement, aPseudoType, aPseudoElement,
|
|
aStateMask));
|
|
}
|
|
|
|
void
|
|
StyleSetHandle::Ptr::RootStyleContextAdded()
|
|
{
|
|
if (IsGecko()) {
|
|
AsGecko()->RootStyleContextAdded();
|
|
} else {
|
|
// Not needed.
|
|
}
|
|
}
|
|
|
|
void
|
|
StyleSetHandle::Ptr::RootStyleContextRemoved()
|
|
{
|
|
if (IsGecko()) {
|
|
RootStyleContextAdded();
|
|
} else {
|
|
// Not needed.
|
|
}
|
|
}
|
|
|
|
} // namespace mozilla
|
|
|
|
#undef FORWARD
|
|
|
|
#endif // mozilla_StyleSetHandleInlines_h
|