Issue #2112 - Part 5: Remove Servo from forwarding code used by magic pointer classes

This commit is contained in:
FranklinDM 2024-03-25 02:02:08 +08:00 committed by roytam1
commit a93a7bed47
52 changed files with 274 additions and 1116 deletions

View file

@ -3877,9 +3877,6 @@ RestyleManager::ComputeAndProcessStyleChange(nsStyleContext* aNewContext,
nsStyleSet*
ElementRestyler::StyleSet() const
{
MOZ_ASSERT(mPresContext->StyleSet()->IsGecko(),
"ElementRestyler should only be used with a Gecko-flavored "
"style backend");
return mPresContext->StyleSet()->AsGecko();
}

View file

@ -458,9 +458,6 @@ public:
private:
inline nsStyleSet* StyleSet() const {
MOZ_ASSERT(PresContext()->StyleSet()->IsGecko(),
"RestyleManager should only be used with a Gecko-flavored "
"style backend");
return PresContext()->StyleSet()->AsGecko();
}

View file

@ -115,14 +115,6 @@ protected:
return PresContext()->FrameConstructor();
}
inline bool IsGecko() const {
return !IsServo();
}
inline bool IsServo() const {
return false;
}
private:
nsPresContext* mPresContext; // weak, can be null after Disconnect().
uint32_t mRestyleGeneration;

View file

@ -48,47 +48,24 @@ public:
public:
friend class ::mozilla::RestyleManagerHandle;
bool IsGecko() const { return !IsServo(); }
bool IsServo() const
{
MOZ_ASSERT(mValue, "RestyleManagerHandle null pointer dereference");
return false;
}
StyleBackendType BackendType() const
{
return IsGecko() ? StyleBackendType::Gecko :
StyleBackendType::Servo;
return StyleBackendType::Gecko;
}
RestyleManager* AsGecko()
{
MOZ_ASSERT(IsGecko());
return reinterpret_cast<RestyleManager*>(mValue);
}
ServoRestyleManager* AsServo()
{
MOZ_ASSERT(IsServo());
return reinterpret_cast<ServoRestyleManager*>(mValue & ~SERVO_BIT);
}
RestyleManager* GetAsGecko() { return IsGecko() ? AsGecko() : nullptr; }
ServoRestyleManager* GetAsServo() { return IsServo() ? AsServo() : nullptr; }
RestyleManager* GetAsGecko() { return AsGecko(); }
const RestyleManager* AsGecko() const
{
return const_cast<Ptr*>(this)->AsGecko();
}
const ServoRestyleManager* AsServo() const
{
MOZ_ASSERT(IsServo());
return const_cast<Ptr*>(this)->AsServo();
}
const RestyleManager* GetAsGecko() const { return IsGecko() ? AsGecko() : nullptr; }
const ServoRestyleManager* GetAsServo() const { return IsServo() ? AsServo() : nullptr; }
const RestyleManager* GetAsGecko() const { return AsGecko(); }
// These inline methods are defined in RestyleManagerHandleInlines.h.
inline MozExternalRefCountType AddRef();

View file

@ -7,35 +7,25 @@
#define mozilla_RestyleManagerHandleInlines_h
#include "mozilla/RestyleManager.h"
#include "mozilla/ServoRestyleManager.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 {
MozExternalRefCountType
RestyleManagerHandle::Ptr::AddRef()
{
FORWARD(AddRef, ());
return AsGecko()->AddRef();
}
MozExternalRefCountType
RestyleManagerHandle::Ptr::Release()
{
FORWARD(Release, ());
return AsGecko()->Release();
}
void
RestyleManagerHandle::Ptr::Disconnect()
{
FORWARD(Disconnect, ());
AsGecko()->Disconnect();
}
void
@ -43,20 +33,20 @@ RestyleManagerHandle::Ptr::PostRestyleEvent(dom::Element* aElement,
nsRestyleHint aRestyleHint,
nsChangeHint aMinChangeHint)
{
FORWARD(PostRestyleEvent, (aElement, aRestyleHint, aMinChangeHint));
AsGecko()->PostRestyleEvent(aElement, aRestyleHint, aMinChangeHint);
}
void
RestyleManagerHandle::Ptr::PostRestyleEventForLazyConstruction()
{
FORWARD(PostRestyleEventForLazyConstruction, ());
AsGecko()->PostRestyleEventForLazyConstruction();
}
void
RestyleManagerHandle::Ptr::RebuildAllStyleData(nsChangeHint aExtraHint,
nsRestyleHint aRestyleHint)
{
FORWARD(RebuildAllStyleData, (aExtraHint, aRestyleHint));
AsGecko()->RebuildAllStyleData(aExtraHint, aRestyleHint);
}
void
@ -64,39 +54,39 @@ RestyleManagerHandle::Ptr::PostRebuildAllStyleDataEvent(
nsChangeHint aExtraHint,
nsRestyleHint aRestyleHint)
{
FORWARD(PostRebuildAllStyleDataEvent, (aExtraHint, aRestyleHint));
AsGecko()->PostRebuildAllStyleDataEvent(aExtraHint, aRestyleHint);
}
void
RestyleManagerHandle::Ptr::ProcessPendingRestyles()
{
FORWARD(ProcessPendingRestyles, ());
AsGecko()->ProcessPendingRestyles();
}
nsresult
RestyleManagerHandle::Ptr::ProcessRestyledFrames(nsStyleChangeList& aChangeList)
{
FORWARD(ProcessRestyledFrames, (aChangeList));
return AsGecko()->ProcessRestyledFrames(aChangeList);
}
void
RestyleManagerHandle::Ptr::FlushOverflowChangedTracker()
{
FORWARD(FlushOverflowChangedTracker, ());
AsGecko()->FlushOverflowChangedTracker();
}
void
RestyleManagerHandle::Ptr::ContentInserted(nsINode* aContainer,
nsIContent* aChild)
{
FORWARD(ContentInserted, (aContainer, aChild));
AsGecko()->ContentInserted(aContainer, aChild);
}
void
RestyleManagerHandle::Ptr::ContentAppended(nsIContent* aContainer,
nsIContent* aFirstNewContent)
{
FORWARD(ContentAppended, (aContainer, aFirstNewContent));
AsGecko()->ContentAppended(aContainer, aFirstNewContent);
}
void
@ -104,28 +94,28 @@ RestyleManagerHandle::Ptr::ContentRemoved(nsINode* aContainer,
nsIContent* aOldChild,
nsIContent* aFollowingSibling)
{
FORWARD(ContentRemoved, (aContainer, aOldChild, aFollowingSibling));
AsGecko()->ContentRemoved(aContainer, aOldChild, aFollowingSibling);
}
void
RestyleManagerHandle::Ptr::RestyleForInsertOrChange(nsINode* aContainer,
nsIContent* aChild)
{
FORWARD(RestyleForInsertOrChange, (aContainer, aChild));
AsGecko()->RestyleForInsertOrChange(aContainer, aChild);
}
void
RestyleManagerHandle::Ptr::RestyleForAppend(nsIContent* aContainer,
nsIContent* aFirstNewContent)
{
FORWARD(RestyleForAppend, (aContainer, aFirstNewContent));
AsGecko()->RestyleForAppend(aContainer, aFirstNewContent);
}
void
RestyleManagerHandle::Ptr::ContentStateChanged(nsIContent* aContent,
EventStates aStateMask)
{
FORWARD(ContentStateChanged, (aContent, aStateMask));
AsGecko()->ContentStateChanged(aContent, aStateMask);
}
void
@ -135,8 +125,8 @@ RestyleManagerHandle::Ptr::AttributeWillChange(dom::Element* aElement,
int32_t aModType,
const nsAttrValue* aNewValue)
{
FORWARD(AttributeWillChange, (aElement, aNameSpaceID, aAttribute, aModType,
aNewValue));
AsGecko()->AttributeWillChange(aElement, aNameSpaceID, aAttribute, aModType,
aNewValue);
}
void
@ -146,49 +136,46 @@ RestyleManagerHandle::Ptr::AttributeChanged(dom::Element* aElement,
int32_t aModType,
const nsAttrValue* aOldValue)
{
FORWARD(AttributeChanged, (aElement, aNameSpaceID, aAttribute, aModType,
aOldValue));
AsGecko()->AttributeChanged(aElement, aNameSpaceID, aAttribute, aModType,
aOldValue);
}
nsresult
RestyleManagerHandle::Ptr::ReparentStyleContext(nsIFrame* aFrame)
{
FORWARD(ReparentStyleContext, (aFrame));
return AsGecko()->ReparentStyleContext(aFrame);
}
bool
RestyleManagerHandle::Ptr::HasPendingRestyles()
{
FORWARD(HasPendingRestyles, ());
return AsGecko()->HasPendingRestyles();
}
uint64_t
RestyleManagerHandle::Ptr::GetRestyleGeneration() const
{
FORWARD(GetRestyleGeneration, ());
return AsGecko()->GetRestyleGeneration();
}
uint32_t
RestyleManagerHandle::Ptr::GetHoverGeneration() const
{
FORWARD(GetHoverGeneration, ());
return AsGecko()->GetHoverGeneration();
}
void
RestyleManagerHandle::Ptr::SetObservingRefreshDriver(bool aObserving)
{
FORWARD(SetObservingRefreshDriver, (aObserving));
AsGecko()->SetObservingRefreshDriver(aObserving);
}
void
RestyleManagerHandle::Ptr::NotifyDestroyingFrame(nsIFrame* aFrame)
{
FORWARD(NotifyDestroyingFrame, (aFrame));
AsGecko()->NotifyDestroyingFrame(aFrame);
}
} // namespace mozilla
#undef FORWARD
#undef FORWARD_CONCRETE
#endif // mozilla_RestyleManagerHandleInlines_h

View file

@ -2698,13 +2698,7 @@ nsCSSFrameConstructor::ConstructRootFrame()
// Set up our style rule observer.
// XXXbz wouldn't this make more sense as part of presshell init?
if (styleSet->IsGecko()) {
// XXXheycam We don't support XBL bindings providing style to
// ServoStyleSets yet.
styleSet->AsGecko()->SetBindingManager(mDocument->BindingManager());
} else {
NS_WARNING("stylo: cannot get ServoStyleSheets from XBL bindings yet. See bug 1290276.");
}
styleSet->AsGecko()->SetBindingManager(mDocument->BindingManager());
// --------- BUILD VIEWPORT -----------
RefPtr<nsStyleContext> viewportPseudoStyle =
@ -4246,15 +4240,6 @@ nsCSSFrameConstructor::GetAnonymousContent(nsIContent* aParent,
}
}
if (ServoStyleSet* styleSet = mPresShell->StyleSet()->GetAsServo()) {
// Eagerly compute styles for the anonymous content tree.
for (auto& info : aContent) {
if (info.mContent->IsElement()) {
styleSet->StyleNewSubtree(info.mContent);
}
}
}
return NS_OK;
}
@ -10537,11 +10522,6 @@ nsCSSFrameConstructor::AddFCItemsForAnonymousContent(
TreeMatchContext::AutoParentDisplayBasedStyleFixupSkipper
parentDisplayBasedStyleFixupSkipper(aState.mTreeMatchContext);
// Make sure we eagerly performed the servo cascade when the anonymous
// nodes were created.
MOZ_ASSERT_IF(content->IsStyledByServo() && content->IsElement(),
content->AsElement()->HasServoData());
// Determine whether this NAC is pseudo-implementing.
nsIAtom* pseudo = nullptr;
if (content->IsElement()) {

View file

@ -5,7 +5,6 @@
/* container for a document and its presentation */
#include "mozilla/ServoStyleSet.h"
#include "nsAutoPtr.h"
#include "nscore.h"
#include "nsCOMPtr.h"
@ -2279,12 +2278,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument)
StyleBackendType backendType = aDocument->GetStyleBackendType();
StyleSetHandle styleSet;
if (backendType == StyleBackendType::Gecko) {
styleSet = new nsStyleSet();
} else {
styleSet = new ServoStyleSet();
}
StyleSetHandle styleSet = new nsStyleSet();
styleSet->BeginUpdate();
@ -2440,19 +2434,14 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument)
}
}
if (styleSet->IsGecko()) {
nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance();
if (sheetService) {
for (StyleSheet* sheet : *sheetService->AgentStyleSheets()) {
styleSet->AppendStyleSheet(SheetType::Agent, sheet);
}
for (StyleSheet* sheet : Reversed(*sheetService->UserStyleSheets())) {
styleSet->PrependStyleSheet(SheetType::User, sheet);
}
nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance();
if (sheetService) {
for (StyleSheet* sheet : *sheetService->AgentStyleSheets()) {
styleSet->AppendStyleSheet(SheetType::Agent, sheet);
}
for (StyleSheet* sheet : Reversed(*sheetService->UserStyleSheets())) {
styleSet->PrependStyleSheet(SheetType::User, sheet);
}
} else {
NS_WARNING("stylo: Not yet checking nsStyleSheetService for Servo-backed "
"documents. See bug 1290224");
}
// Caller will handle calling EndUpdate, per contract.

View file

@ -894,14 +894,10 @@ nsPresContext::AttachShell(nsIPresShell* aShell, StyleBackendType aBackendType)
MOZ_ASSERT(!mShell);
mShell = aShell;
if (aBackendType == StyleBackendType::Servo) {
mRestyleManager = new ServoRestyleManager(this);
} else {
// Since RestyleManager is also the name of a method of nsPresContext,
// it is necessary to prefix the class with the mozilla namespace
// here.
mRestyleManager = new mozilla::RestyleManager(this);
}
// Since RestyleManager is also the name of a method of nsPresContext,
// it is necessary to prefix the class with the mozilla namespace
// here.
mRestyleManager = new mozilla::RestyleManager(this);
// Since CounterStyleManager is also the name of a method of
// nsPresContext, it is necessary to prefix the class with the mozilla
@ -1886,15 +1882,8 @@ nsPresContext::MediaFeatureValuesChanged(nsRestyleHint aRestyleHint,
// MediumFeaturesChanged updates the applied rules, so it always gets called.
if (mShell) {
// XXXheycam ServoStyleSets don't support responding to medium
// changes yet.
if (mShell->StyleSet()->IsGecko()) {
if (mShell->StyleSet()->AsGecko()->MediumFeaturesChanged()) {
aRestyleHint |= eRestyle_Subtree;
}
} else {
NS_WARNING("stylo: ServoStyleSets don't support responding to medium "
"changes yet. See bug 1290228.");
if (mShell->StyleSet()->AsGecko()->MediumFeaturesChanged()) {
aRestyleHint |= eRestyle_Subtree;
}
}

View file

@ -569,10 +569,6 @@ static void
VerifyStyleTree(nsPresContext* aPresContext, nsFrameManager* aFrameManager)
{
if (nsFrame::GetVerifyStyleTreeEnable()) {
if (aPresContext->RestyleManager()->IsServo()) {
NS_ERROR("stylo: cannot verify style tree with a ServoRestyleManager");
return;
}
nsIFrame* rootFrame = aFrameManager->GetRootFrame();
aPresContext->RestyleManager()->AsGecko()->DebugVerifyStyleTree(rootFrame);
}
@ -893,8 +889,7 @@ PresShell::Init(nsIDocument* aDocument,
// Bind the context to the presentation shell.
mPresContext = aPresContext;
StyleBackendType backend = aStyleSet->IsServo() ? StyleBackendType::Servo
: StyleBackendType::Gecko;
StyleBackendType backend = StyleBackendType::Gecko;
aPresContext->AttachShell(this, backend);
// Now we can initialize the style set. Make sure to set the member before
@ -1425,11 +1420,6 @@ PresShell::RemovePreferenceStyles()
void
PresShell::AddUserSheet(nsISupports* aSheet)
{
if (mStyleSet->IsServo()) {
NS_ERROR("stylo: nsStyleSheetService doesn't handle ServoStyleSheets yet");
return;
}
// Make sure this does what nsDocumentViewer::CreateStyleSet does wrt
// ordering. We want this new sheet to come after all the existing stylesheet
// service sheets, but before other user sheets; see nsIStyleSheetService.idl
@ -1692,17 +1682,6 @@ PresShell::Initialize(nscoord aWidth, nscoord aHeight)
mPresContext->SetVisibleArea(nsRect(0, 0, aWidth, aHeight));
if (mStyleSet->IsServo() && mDocument->GetRootElement()) {
// If we have the root element already, go ahead style it along with any
// descendants.
//
// Some things, like nsDocumentViewer::GetPageMode, recreate the PresShell
// while keeping the content tree alive (see bug 1292280) - so we
// unconditionally mark the root as dirty.
mDocument->GetRootElement()->SetIsDirtyForServo();
mStyleSet->AsServo()->StyleDocument(/* aLeaveDirtyBits = */ false);
}
// Get the root frame from the frame manager
// XXXbz it would be nice to move this somewhere else... like frame manager
// Init(), say. But we need to make sure our views are all set up by the
@ -4508,15 +4487,9 @@ PresShell::RecordStyleSheetChange(StyleSheet* aStyleSheet)
if (mStylesHaveChanged)
return;
if (aStyleSheet->IsGecko()) {
// XXXheycam ServoStyleSheets don't support <style scoped> yet.
Element* scopeElement = aStyleSheet->AsGecko()->GetScopeElement();
if (scopeElement) {
mChangedScopeStyleRoots.AppendElement(scopeElement);
return;
}
} else {
NS_WARNING("stylo: ServoStyleSheets don't support <style scoped>");
Element* scopeElement = aStyleSheet->AsGecko()->GetScopeElement();
if (scopeElement) {
mChangedScopeStyleRoots.AppendElement(scopeElement);
return;
}
@ -6773,10 +6746,7 @@ FlushThrottledStyles(nsIDocument *aDocument, void *aData)
if (shell && shell->IsVisible()) {
nsPresContext* presContext = shell->GetPresContext();
if (presContext) {
if (presContext->RestyleManager()->IsGecko()) {
// XXX stylo: ServoRestyleManager doesn't support animations yet.
presContext->RestyleManager()->AsGecko()->UpdateOnlyAnimationStyles();
}
presContext->RestyleManager()->AsGecko()->UpdateOnlyAnimationStyles();
}
}
@ -9519,10 +9489,6 @@ PresShell::Observe(nsISupports* aSubject,
nsAutoScriptBlocker scriptBlocker;
++mChangeNestCount;
RestyleManagerHandle restyleManager = mPresContext->RestyleManager();
if (restyleManager->IsServo()) {
MOZ_CRASH("stylo: PresShell::Observe(\"chrome-flush-skin-caches\") "
"not implemented for Servo-backed style system");
}
restyleManager->AsGecko()->ProcessRestyledFrames(changeList);
restyleManager->AsGecko()->FlushOverflowChangedTracker();
--mChangeNestCount;
@ -10004,10 +9970,6 @@ PresShell::VerifyIncrementalReflow()
// Create a new presentation shell to view the document. Use the
// exact same style information that this document has.
if (mStyleSet->IsServo()) {
NS_WARNING("VerifyIncrementalReflow cannot handle ServoStyleSets");
return true;
}
nsAutoPtr<nsStyleSet> newSet(CloneStyleSet(mStyleSet->AsGecko()));
nsCOMPtr<nsIPresShell> sh = mDocument->CreateShell(cx, vm, newSet.get());
NS_ENSURE_TRUE(sh, false);

View file

@ -176,16 +176,10 @@ nsStyleSheetService::LoadAndRegisterSheet(nsIURI *aSheetURI,
// We're guaranteed that the new sheet is the last sheet in
// mSheets[aSheetType]
// XXXheycam Once the nsStyleSheetService can hold ServoStyleSheets too,
// we'll need to include them in the notification.
StyleSheet* sheet = mSheets[aSheetType].LastElement();
if (sheet->IsGecko()) {
CSSStyleSheet* cssSheet = sheet->AsGecko();
serv->NotifyObservers(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, cssSheet),
message, nullptr);
} else {
NS_ERROR("stylo: can't notify observers of ServoStyleSheets");
}
CSSStyleSheet* cssSheet = sheet->AsGecko();
serv->NotifyObservers(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, cssSheet),
message, nullptr);
}
if (XRE_IsParentProcess()) {
@ -294,9 +288,6 @@ nsStyleSheetService::PreloadSheet(nsIURI *aSheetURI, uint32_t aSheetType,
nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, &sheet);
NS_ENSURE_SUCCESS(rv, rv);
MOZ_ASSERT(sheet->IsGecko(),
"stylo: didn't expect Loader to create a ServoStyleSheet");
RefPtr<CSSStyleSheet> cssSheet = sheet->AsGecko();
cssSheet.forget(aSheet);
@ -331,15 +322,9 @@ nsStyleSheetService::UnregisterSheet(nsIURI *aSheetURI, uint32_t aSheetType)
nsCOMPtr<nsIObserverService> serv = services::GetObserverService();
if (serv) {
// XXXheycam Once the nsStyleSheetService can hold ServoStyleSheets too,
// we'll need to include them in the notification.
if (sheet->IsGecko()) {
CSSStyleSheet* cssSheet = sheet->AsGecko();
serv->NotifyObservers(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, cssSheet),
message, nullptr);
} else {
NS_ERROR("stylo: can't notify observers of ServoStyleSheets");
}
CSSStyleSheet* cssSheet = sheet->AsGecko();
serv->NotifyObservers(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, cssSheet),
message, nullptr);
}
if (XRE_IsParentProcess()) {