Skip to content

Commit

Permalink
#591: M1467722
Browse files Browse the repository at this point in the history
  • Loading branch information
classilla committed Feb 18, 2020
1 parent fae264c commit cfb4339
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 72 deletions.
28 changes: 2 additions & 26 deletions dom/base/nsGlobalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10005,36 +10005,12 @@ nsGlobalWindow::GetComputedStyleHelperOuter(Element& aElt,
{
MOZ_RELEASE_ASSERT(IsOuterWindow());

if (!mDocShell) {
if (!mDoc) {
return nullptr;
}

nsCOMPtr<nsIPresShell> presShell = mDocShell->GetPresShell();

if (!presShell) {
// Try flushing frames on our parent in case there's a pending
// style change that will create the presshell.
nsGlobalWindow *parent =
static_cast<nsGlobalWindow *>(GetPrivateParent());
if (!parent) {
return nullptr;
}

parent->FlushPendingNotifications(Flush_Frames);

// Might have killed mDocShell
if (!mDocShell) {
return nullptr;
}

presShell = mDocShell->GetPresShell();
if (!presShell) {
return nullptr;
}
}

RefPtr<nsComputedDOMStyle> compStyle =
NS_NewComputedDOMStyle(&aElt, aPseudoElt, presShell,
NS_NewComputedDOMStyle(&aElt, aPseudoElt, mDoc,
aDefaultStylesOnly ? nsComputedDOMStyle::eDefaultOnly :
nsComputedDOMStyle::eAll);

Expand Down
8 changes: 1 addition & 7 deletions dom/smil/nsSMILCSSProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ GetCSSComputedValue(Element* aElem,
return false;
}

nsIPresShell* shell = doc->GetShell();
if (!shell) {
NS_WARNING("Unable to look up computed style -- no pres shell");
return false;
}

RefPtr<nsComputedDOMStyle> computedStyle =
NS_NewComputedDOMStyle(aElem, EmptyString(), shell);
NS_NewComputedDOMStyle(aElem, EmptyString(), doc);

computedStyle->GetPropertyValue(aPropID, aResult);
return true;
Expand Down
5 changes: 1 addition & 4 deletions editor/libeditor/nsHTMLCSSUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,8 @@ nsHTMLCSSUtils::GetComputedStyle(dom::Element* aElement)
nsIDocument* doc = aElement->GetCurrentDoc();
NS_ENSURE_TRUE(doc, nullptr);

nsIPresShell* presShell = doc->GetShell();
NS_ENSURE_TRUE(presShell, nullptr);

RefPtr<nsComputedDOMStyle> style =
NS_NewComputedDOMStyle(aElement, EmptyString(), presShell);
NS_NewComputedDOMStyle(aElement, EmptyString(), doc);

return style.forget();
}
Expand Down
60 changes: 31 additions & 29 deletions layout/style/nsComputedDOMStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ using namespace mozilla::dom;
*/

already_AddRefed<nsComputedDOMStyle>
NS_NewComputedDOMStyle(dom::Element* aElement, const nsAString& aPseudoElt,
nsIPresShell* aPresShell,
NS_NewComputedDOMStyle(dom::Element* aElement,
const nsAString& aPseudoElt,
nsIDocument* aDocument,
nsComputedDOMStyle::StyleType aStyleType)
{
RefPtr<nsComputedDOMStyle> computedStyle;
computedStyle = new nsComputedDOMStyle(aElement, aPseudoElt, aPresShell,
aStyleType);
computedStyle = new nsComputedDOMStyle(aElement, aPseudoElt, aDocument, aStyleType);
return computedStyle.forget();
}

Expand Down Expand Up @@ -219,7 +219,7 @@ nsComputedStyleMap::Update()

nsComputedDOMStyle::nsComputedDOMStyle(dom::Element* aElement,
const nsAString& aPseudoElt,
nsIPresShell* aPresShell,
nsIDocument* aDocument,
StyleType aStyleType)
: mDocumentWeak(nullptr), mOuterFrame(nullptr),
mInnerFrame(nullptr), mPresShell(nullptr),
Expand All @@ -228,11 +228,13 @@ nsComputedDOMStyle::nsComputedDOMStyle(dom::Element* aElement,
mExposeVisitedStyle(false),
mResolvedStyleContext(false)
{
MOZ_ASSERT(aElement && aPresShell);
MOZ_ASSERT(aElement);
MOZ_ASSERT(aDocument);
// TODO(emilio, bug 548397, https://github.com/w3c/csswg-drafts/issues/2403):
// Should use aElement->OwnerDoc() instead.
mDocumentWeak = do_GetWeakReference(aDocument);

mDocumentWeak = do_GetWeakReference(aPresShell->GetDocument());

mContent = aElement;
mElement = aElement;

if (!DOMStringIsNull(aPseudoElt) && !aPseudoElt.IsEmpty() &&
aPseudoElt.First() == char16_t(':')) {
Expand All @@ -259,11 +261,8 @@ nsComputedDOMStyle::nsComputedDOMStyle(dom::Element* aElement,
mPseudo = nullptr;
}
}

MOZ_ASSERT(aPresShell->GetPresContext());
}


nsComputedDOMStyle::~nsComputedDOMStyle()
{
ClearStyleContext();
Expand All @@ -272,13 +271,13 @@ nsComputedDOMStyle::~nsComputedDOMStyle()
NS_IMPL_CYCLE_COLLECTION_CLASS(nsComputedDOMStyle)

NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsComputedDOMStyle)
tmp->ClearStyleContext(); // remove observer before clearing mContent
NS_IMPL_CYCLE_COLLECTION_UNLINK(mContent)
tmp->ClearStyleContext(); // remove observer before clearing mElement
NS_IMPL_CYCLE_COLLECTION_UNLINK(mElement)
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END

NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsComputedDOMStyle)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContent)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END

Expand Down Expand Up @@ -345,15 +344,15 @@ nsComputedDOMStyle::SetCssText(const nsAString& aCssText)
NS_IMETHODIMP
nsComputedDOMStyle::GetLength(uint32_t* aLength)
{
NS_PRECONDITION(aLength, "Null aLength! Prepare to die!");

uint32_t length = GetComputedStyleMap()->Length();

// Make sure we have up to date style so that we can include custom
// properties.
UpdateCurrentStyleSources(false);
if (mStyleContext) {
length += StyleVariables()->mVariables.Count();
} else {
length = 0;
}

*aLength = length;
Expand Down Expand Up @@ -599,7 +598,7 @@ nsComputedDOMStyle::ClearStyleContext()
{
if (mResolvedStyleContext) {
mResolvedStyleContext = false;
mContent->RemoveMutationObserver(this);
mElement->RemoveMutationObserver(this);
}
mStyleContext = nullptr;
}
Expand All @@ -609,7 +608,7 @@ nsComputedDOMStyle::SetResolvedStyleContext(RefPtr<nsStyleContext>&& aContext)
{
if (!mResolvedStyleContext) {
mResolvedStyleContext = true;
mContent->AddMutationObserver(this);
mElement->AddMutationObserver(this);
}
mStyleContext = aContext;
}
Expand All @@ -634,15 +633,15 @@ nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush)

// Flush _before_ getting the presshell, since that could create a new
// presshell. Also note that we want to flush the style on the document
// we're computing style in, not on the document mContent is in -- the two
// we're computing style in, not on the document mElement is in -- the two
// may be different.
document->FlushPendingNotifications(
aNeedsLayoutFlush ? Flush_Layout : Flush_Style);
#ifdef DEBUG
mFlushedPendingReflows = aNeedsLayoutFlush;
#endif

nsCOMPtr<nsIPresShell> presShellForContent = GetPresShellForContent(mContent);
nsCOMPtr<nsIPresShell> presShellForContent = GetPresShellForContent(mElement);
if (presShellForContent && presShellForContent != mPresShell) {
presShellForContent->FlushPendingNotifications(Flush_Style);
}
Expand All @@ -657,7 +656,11 @@ nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush)
mPresShell->GetPresContext()->GetRestyleGeneration();

if (mStyleContext) {
if (mStyleContextGeneration == currentGeneration) {
// We can't rely on the undisplayed restyle generation if mElement is
// out-of-document, since that generation is not incremented for DOM changes
// on out-of-document elements.
if (mStyleContextGeneration == currentGeneration &&
mElement->IsInComposedDoc()) {
// Our cached style context is still valid.
return;
}
Expand All @@ -666,12 +669,12 @@ nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush)
mStyleContext = nullptr;
}

// XXX the !mContent->IsHTMLElement(nsGkAtoms::area)
// XXX the !mElement->IsHTMLElement(nsGkAtoms::area)
// check is needed due to bug 135040 (to avoid using
// mPrimaryFrame). Remove it once that's fixed.
if (!mPseudo && mStyleType == eAll &&
!mContent->IsHTMLElement(nsGkAtoms::area)) {
mOuterFrame = mContent->GetPrimaryFrame();
!mElement->IsHTMLElement(nsGkAtoms::area)) {
mOuterFrame = mElement->GetPrimaryFrame();
mInnerFrame = mOuterFrame;
if (mOuterFrame) {
nsIAtom* type = mOuterFrame->GetType();
Expand Down Expand Up @@ -715,7 +718,7 @@ nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush)
// Need to resolve a style context
RefPtr<nsStyleContext> resolvedStyleContext =
nsComputedDOMStyle::GetStyleContextForElementNoFlush(
mContent->AsElement(),
mElement,
mPseudo,
presShellForContent ? presShellForContent.get() : mPresShell,
mStyleType);
Expand Down Expand Up @@ -808,7 +811,6 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName, ErrorRes

UpdateCurrentStyleSources(needsLayoutFlush);
if (!mStyleContext) {
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
return nullptr;
}

Expand Down Expand Up @@ -4866,7 +4868,7 @@ nsComputedDOMStyle::GetLineHeightCoord(nscoord& aCoord)

// lie about font size inflation since we lie about font size (since
// the inflation only applies to text)
aCoord = nsHTMLReflowState::CalcLineHeight(mContent, mStyleContext,
aCoord = nsHTMLReflowState::CalcLineHeight(mElement, mStyleContext,
blockHeight, 1.0f);

// CalcLineHeight uses font->mFont.size, but we want to use
Expand Down Expand Up @@ -6228,7 +6230,7 @@ nsComputedDOMStyle::DoGetCustomProperty(const nsAString& aPropertyName)
void
nsComputedDOMStyle::ParentChainChanged(nsIContent* aContent)
{
NS_ASSERTION(mContent == aContent, "didn't we register mContent?");
NS_ASSERTION(mElement == aContent, "didn't we register mElement?");
NS_ASSERTION(mResolvedStyleContext,
"should have only registered an observer when "
"mResolvedStyleContext is true");
Expand Down
12 changes: 6 additions & 6 deletions layout/style/nsComputedDOMStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ class nsComputedDOMStyle final : public nsDOMCSSDeclaration

nsComputedDOMStyle(mozilla::dom::Element* aElement,
const nsAString& aPseudoElt,
nsIPresShell* aPresShell,
nsIDocument* aDocument,
StyleType aStyleType);

virtual nsINode *GetParentObject() override
nsINode *GetParentObject() override
{
return mContent;
return mElement;
}

static already_AddRefed<nsStyleContext>
Expand Down Expand Up @@ -614,9 +614,9 @@ class nsComputedDOMStyle final : public nsDOMCSSDeclaration

// We don't really have a good immutable representation of "presentation".
// Given the way GetComputedStyle is currently used, we should just grab the
// 0th presshell, if any, from the document.
// presshell, if any, from the document.
nsWeakPtr mDocumentWeak;
nsCOMPtr<nsIContent> mContent;
RefPtr<mozilla::dom::Element> mElement;

/**
* Strong reference to the style context we access data from. This can be
Expand Down Expand Up @@ -682,7 +682,7 @@ class nsComputedDOMStyle final : public nsDOMCSSDeclaration
already_AddRefed<nsComputedDOMStyle>
NS_NewComputedDOMStyle(mozilla::dom::Element* aElement,
const nsAString& aPseudoElt,
nsIPresShell* aPresShell,
nsIDocument* aDocument,
nsComputedDOMStyle::StyleType aStyleType =
nsComputedDOMStyle::eAll);

Expand Down

0 comments on commit cfb4339

Please sign in to comment.