Skip to content

Commit

Permalink
Bug 1524328 - Pass a document instead of a pres context to FinishStyl…
Browse files Browse the repository at this point in the history
…e. r=xidorn

Differential Revision: https://phabricator.services.mozilla.com/D18491
  • Loading branch information
emilio committed Feb 3, 2019
1 parent 30de825 commit b8d7c15
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 84 deletions.
41 changes: 22 additions & 19 deletions layout/style/ComputedStyleInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "mozilla/ComputedStyle.h"
#include "mozilla/ServoComputedDataInlines.h"
#include "mozilla/ServoUtils.h"
#include "nsPresContext.h"

namespace mozilla {

Expand All @@ -37,24 +38,25 @@ namespace mozilla {
#undef STYLE_STRUCT

// Helper functions for GetStyle* and PeekStyle*
#define STYLE_STRUCT(name_) \
template <bool aComputeData> \
const nsStyle##name_* ComputedStyle::DoGetStyle##name_() { \
const auto kStructID = StyleStructID::name_; \
const bool needToCompute = !HasRequestedStruct(kStructID); \
if (!aComputeData && needToCompute) { \
return nullptr; \
} \
const nsStyle##name_* data = ComputedData()->GetStyle##name_(); \
/* perform any remaining main thread work on the struct */ \
if (needToCompute) { \
MOZ_ASSERT(NS_IsMainThread()); \
MOZ_ASSERT(!mozilla::IsInServoTraversal()); \
const_cast<nsStyle##name_*>(data)->FinishStyle(mPresContext, nullptr); \
/* the ComputedStyle owns the struct */ \
SetRequestedStruct(kStructID); \
} \
return data; \
#define STYLE_STRUCT(name_) \
template <bool aComputeData> \
const nsStyle##name_* ComputedStyle::DoGetStyle##name_() { \
const auto kStructID = StyleStructID::name_; \
const bool needToCompute = !HasRequestedStruct(kStructID); \
if (!aComputeData && needToCompute) { \
return nullptr; \
} \
const nsStyle##name_* data = ComputedData()->GetStyle##name_(); \
/* perform any remaining main thread work on the struct */ \
if (needToCompute) { \
MOZ_ASSERT(NS_IsMainThread()); \
MOZ_ASSERT(!mozilla::IsInServoTraversal()); \
const_cast<nsStyle##name_*>(data)->FinishStyle( \
*mPresContext->Document(), nullptr); \
/* the ComputedStyle owns the struct */ \
SetRequestedStruct(kStructID); \
} \
return data; \
}
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
Expand All @@ -73,7 +75,8 @@ void ComputedStyle::ResolveSameStructsAs(const ComputedStyle* aOther) {
(newBits & StyleStructConstants::BitFor(StyleStructID::name_))) { \
const nsStyle##name_* data = ComputedData()->GetStyle##name_(); \
const nsStyle##name_* oldData = aOther->ComputedData()->GetStyle##name_(); \
const_cast<nsStyle##name_*>(data)->FinishStyle(mPresContext, oldData); \
const_cast<nsStyle##name_*>(data)->FinishStyle(*mPresContext->Document(), \
oldData); \
}
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
Expand Down
59 changes: 28 additions & 31 deletions layout/style/nsStyleStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ nsStyleBorder::nsStyleBorder(const nsStyleBorder& aSrc)

nsStyleBorder::~nsStyleBorder() { MOZ_COUNT_DTOR(nsStyleBorder); }

void nsStyleBorder::FinishStyle(nsPresContext* aPresContext,
void nsStyleBorder::FinishStyle(Document& aDocument,
const nsStyleBorder* aOldStyle) {
MOZ_ASSERT(NS_IsMainThread());

mBorderImageSource.ResolveImage(
aPresContext, aOldStyle ? &aOldStyle->mBorderImageSource : nullptr);
aDocument, aOldStyle ? &aOldStyle->mBorderImageSource : nullptr);
}

nsMargin nsStyleBorder::GetImageOutset() const {
Expand Down Expand Up @@ -474,13 +474,13 @@ nsStyleList::nsStyleList(const nsStyleList& aSource)
MOZ_COUNT_CTOR(nsStyleList);
}

void nsStyleList::FinishStyle(nsPresContext* aPresContext,
void nsStyleList::FinishStyle(Document& aDocument,
const nsStyleList* aOldStyle) {
MOZ_ASSERT(NS_IsMainThread());

if (mListStyleImage && !mListStyleImage->IsResolved()) {
mListStyleImage->Resolve(
aPresContext, aOldStyle ? aOldStyle->mListStyleImage.get() : nullptr);
aDocument, aOldStyle ? aOldStyle->mListStyleImage.get() : nullptr);
}
}

Expand Down Expand Up @@ -888,7 +888,7 @@ void StyleShapeSource::SetPath(UniquePtr<StyleSVGPath> aPath) {
mType = StyleShapeSourceType::Path;
}

void StyleShapeSource::FinishStyle(nsPresContext* aPresContext,
void StyleShapeSource::FinishStyle(Document& aDocument,
const StyleShapeSource* aOldShapeSource) {
if (GetType() != StyleShapeSourceType::Image) {
return;
Expand All @@ -898,7 +898,7 @@ void StyleShapeSource::FinishStyle(nsPresContext* aPresContext,
StyleShapeSourceType::Image)
? &aOldShapeSource->ShapeImage()
: nullptr;
mShapeImage->ResolveImage(aPresContext, oldShapeImage);
mShapeImage->ResolveImage(aDocument, oldShapeImage);
}

void StyleShapeSource::SetReferenceBox(StyleGeometryBox aReferenceBox) {
Expand Down Expand Up @@ -1083,7 +1083,7 @@ nsStyleSVGReset::nsStyleSVGReset(const nsStyleSVGReset& aSource)
MOZ_COUNT_CTOR(nsStyleSVGReset);
}

void nsStyleSVGReset::FinishStyle(nsPresContext* aPresContext,
void nsStyleSVGReset::FinishStyle(Document& aDocument,
const nsStyleSVGReset* aOldStyle) {
MOZ_ASSERT(NS_IsMainThread());

Expand Down Expand Up @@ -1113,7 +1113,7 @@ void nsStyleSVGReset::FinishStyle(nsPresContext* aPresContext,
? &aOldStyle->mMask.mLayers[i].mImage
: nullptr;

image.ResolveImage(aPresContext, oldImage);
image.ResolveImage(aDocument, oldImage);
}
}
}
Expand Down Expand Up @@ -1851,16 +1851,14 @@ nsStyleImageRequest::~nsStyleImageRequest() {
MOZ_ASSERT(!mImageTracker);
}

bool nsStyleImageRequest::Resolve(nsPresContext* aPresContext,
bool nsStyleImageRequest::Resolve(Document& aDocument,
const nsStyleImageRequest* aOldImageRequest) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!IsResolved(), "already resolved");
MOZ_ASSERT(aPresContext);

mResolved = true;

Document* doc = aPresContext->Document();
nsIURI* docURI = doc->GetDocumentURI();
nsIURI* docURI = aDocument.GetDocumentURI();
if (GetImageValue()->HasRef()) {
bool isEqualExceptRef = false;
RefPtr<nsIURI> imageURI = GetImageURI();
Expand All @@ -1881,21 +1879,22 @@ bool nsStyleImageRequest::Resolve(nsPresContext* aPresContext,
// 1440305, but that seems too risky, and a lot of work to do before 60.
//
// Once that's fixed, the "old style" argument to FinishStyle can go away.
if (aPresContext->IsChrome() && aOldImageRequest &&
if (nsContentUtils::IsChromeDoc(&aDocument) && aOldImageRequest &&
aOldImageRequest->IsResolved() && DefinitelyEquals(*aOldImageRequest)) {
MOZ_ASSERT(aOldImageRequest->mDocGroup == doc->GetDocGroup());
MOZ_ASSERT(aOldImageRequest->mDocGroup == aDocument.GetDocGroup());
MOZ_ASSERT(mModeFlags == aOldImageRequest->mModeFlags);

mDocGroup = aOldImageRequest->mDocGroup;
mImageValue = aOldImageRequest->mImageValue;
mRequestProxy = aOldImageRequest->mRequestProxy;
} else {
mDocGroup = doc->GetDocGroup();
imgRequestProxy* request = mImageValue->LoadImage(doc);
if (aPresContext->IsDynamic()) {
mDocGroup = aDocument.GetDocGroup();
imgRequestProxy* request = mImageValue->LoadImage(&aDocument);
bool isPrint = !!aDocument.GetOriginalDocument();
if (!isPrint) {
mRequestProxy = request;
} else if (request) {
request->GetStaticRequest(doc, getter_AddRefs(mRequestProxy));
request->GetStaticRequest(&aDocument, getter_AddRefs(mRequestProxy));
}
}

Expand All @@ -1905,7 +1904,7 @@ bool nsStyleImageRequest::Resolve(nsPresContext* aPresContext,
}

if (mModeFlags & Mode::Track) {
mImageTracker = doc->ImageTracker();
mImageTracker = aDocument.ImageTracker();
}

MaybeTrackAndLock();
Expand Down Expand Up @@ -2858,11 +2857,10 @@ nsStyleBackground::nsStyleBackground(const nsStyleBackground& aSource)

nsStyleBackground::~nsStyleBackground() { MOZ_COUNT_DTOR(nsStyleBackground); }

void nsStyleBackground::FinishStyle(nsPresContext* aPresContext,
void nsStyleBackground::FinishStyle(Document& aDocument,
const nsStyleBackground* aOldStyle) {
MOZ_ASSERT(NS_IsMainThread());

mImage.ResolveImages(aPresContext, aOldStyle ? &aOldStyle->mImage : nullptr);
mImage.ResolveImages(aDocument, aOldStyle ? &aOldStyle->mImage : nullptr);
}

nsChangeHint nsStyleBackground::CalcDifference(
Expand Down Expand Up @@ -3134,11 +3132,11 @@ nsStyleDisplay::~nsStyleDisplay() {
MOZ_COUNT_DTOR(nsStyleDisplay);
}

void nsStyleDisplay::FinishStyle(nsPresContext* aPresContext,
void nsStyleDisplay::FinishStyle(Document& aDocument,
const nsStyleDisplay* aOldStyle) {
MOZ_ASSERT(NS_IsMainThread());

mShapeOutside.FinishStyle(aPresContext,
mShapeOutside.FinishStyle(aDocument,
aOldStyle ? &aOldStyle->mShapeOutside : nullptr);
GenerateCombinedIndividualTransform();
}
Expand Down Expand Up @@ -3634,7 +3632,7 @@ bool nsStyleContentData::operator==(const nsStyleContentData& aOther) const {
return true;
}

void nsStyleContentData::Resolve(nsPresContext* aPresContext,
void nsStyleContentData::Resolve(Document& aDocument,
const nsStyleContentData* aOldStyle) {
if (mType != StyleContentType::Image) {
return;
Expand All @@ -3644,7 +3642,7 @@ void nsStyleContentData::Resolve(nsPresContext* aPresContext,
(aOldStyle && aOldStyle->mType == StyleContentType::Image)
? aOldStyle->mContent.mImage
: nullptr;
mContent.mImage->Resolve(aPresContext, oldRequest);
mContent.mImage->Resolve(aDocument, oldRequest);
}
}

Expand All @@ -3658,14 +3656,14 @@ nsStyleContent::nsStyleContent(const Document& aDocument) {

nsStyleContent::~nsStyleContent() { MOZ_COUNT_DTOR(nsStyleContent); }

void nsStyleContent::FinishStyle(nsPresContext* aPresContext,
void nsStyleContent::FinishStyle(Document& aDocument,
const nsStyleContent* aOldStyle) {
for (size_t i = 0; i < mContents.Length(); ++i) {
const nsStyleContentData* oldData =
(aOldStyle && aOldStyle->mContents.Length() > i)
? &aOldStyle->mContents[i]
: nullptr;
mContents[i].Resolve(aPresContext, oldData);
mContents[i].Resolve(aDocument, oldData);
}
}

Expand Down Expand Up @@ -3992,8 +3990,7 @@ nsStyleUI::nsStyleUI(const nsStyleUI& aSource)
nsStyleUI::~nsStyleUI() { MOZ_COUNT_DTOR(nsStyleUI); }
void nsStyleUI::FinishStyle(nsPresContext* aPresContext,
const nsStyleUI* aOldStyle) {
void nsStyleUI::FinishStyle(Document& aDocument, const nsStyleUI* aOldStyle) {
MOZ_ASSERT(NS_IsMainThread());
for (size_t i = 0; i < mCursorImages.Length(); ++i) {
Expand All @@ -4004,7 +4001,7 @@ void nsStyleUI::FinishStyle(nsPresContext* aPresContext,
(aOldStyle && aOldStyle->mCursorImages.Length() > i)
? &aOldStyle->mCursorImages[i]
: nullptr;
cursor.mImage->Resolve(aPresContext,
cursor.mImage->Resolve(aDocument,
oldCursor ? oldCursor->mImage.get() : nullptr);
}
}
Expand Down
Loading

0 comments on commit b8d7c15

Please sign in to comment.