summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-12-20 23:08:47 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-12-20 23:08:47 +0100
commitd6baead6c8bcd90f04d62908bfaf73b369df4e6f (patch)
tree9d042110d977eea7839bc992d736fdfeb0462f44
parentce250e9ccfddff9cae496ed7ad01404fd7135291 (diff)
downloaduxp-d6baead6c8bcd90f04d62908bfaf73b369df4e6f.tar.gz
Issue #1219 - Align computed DOM styles with mainstream behvior.
This updates our behavior for computed DOM styling to no longer return null on elements that have no display, but return a 0-length (empty) style instead and don't throw. For this we stop looking at having a presentation for the style and just look at the document instead. This resolves #1219
-rw-r--r--config/milestone.txt2
-rw-r--r--dom/base/nsGlobalWindow.cpp27
-rw-r--r--dom/smil/nsSMILCSSProperty.cpp8
-rw-r--r--editor/libeditor/CSSEditUtils.cpp5
-rw-r--r--layout/style/nsComputedDOMStyle.cpp67
-rw-r--r--layout/style/nsComputedDOMStyle.h12
6 files changed, 47 insertions, 74 deletions
diff --git a/config/milestone.txt b/config/milestone.txt
index 210727cac2..e74505029c 100644
--- a/config/milestone.txt
+++ b/config/milestone.txt
@@ -10,4 +10,4 @@
# hardcoded milestones in the tree from these two files.
#--------------------------------------------------------
-4.4.2 \ No newline at end of file
+4.5.0 \ No newline at end of file
diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp
index 1288b34353..47b46dda06 100644
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -10950,35 +10950,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.
- auto* parent = nsGlobalWindow::Cast(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);
diff --git a/dom/smil/nsSMILCSSProperty.cpp b/dom/smil/nsSMILCSSProperty.cpp
index 53f3e0fbf7..e745124432 100644
--- a/dom/smil/nsSMILCSSProperty.cpp
+++ b/dom/smil/nsSMILCSSProperty.cpp
@@ -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;
diff --git a/editor/libeditor/CSSEditUtils.cpp b/editor/libeditor/CSSEditUtils.cpp
index 5199838c01..d8146ca654 100644
--- a/editor/libeditor/CSSEditUtils.cpp
+++ b/editor/libeditor/CSSEditUtils.cpp
@@ -569,11 +569,8 @@ CSSEditUtils::GetComputedStyle(Element* aElement)
nsIDocument* doc = aElement->GetUncomposedDoc();
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();
}
diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp
index 65c1d698c6..647f7f6dc5 100644
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -64,13 +64,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();
}
@@ -243,7 +243,7 @@ nsComputedStyleMap::Update()
nsComputedDOMStyle::nsComputedDOMStyle(dom::Element* aElement,
const nsAString& aPseudoElt,
- nsIPresShell* aPresShell,
+ nsIDocument* aDocument,
StyleType aStyleType)
: mDocumentWeak(nullptr)
, mOuterFrame(nullptr)
@@ -254,11 +254,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(':')) {
@@ -285,8 +287,6 @@ nsComputedDOMStyle::nsComputedDOMStyle(dom::Element* aElement,
mPseudo = nullptr;
}
}
-
- MOZ_ASSERT(aPresShell->GetPresContext());
}
nsComputedDOMStyle::~nsComputedDOMStyle()
@@ -297,13 +297,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_END
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsComputedDOMStyle)
@@ -366,8 +366,6 @@ 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
@@ -375,6 +373,8 @@ nsComputedDOMStyle::GetLength(uint32_t* aLength)
UpdateCurrentStyleSources(false);
if (mStyleContext) {
length += StyleVariables()->mVariables.Count();
+ } else {
+ length = 0;
}
*aLength = length;
@@ -616,7 +616,7 @@ nsComputedDOMStyle::ClearStyleContext()
{
if (mResolvedStyleContext) {
mResolvedStyleContext = false;
- mContent->RemoveMutationObserver(this);
+ mElement->RemoveMutationObserver(this);
}
mStyleContext = nullptr;
}
@@ -626,7 +626,7 @@ nsComputedDOMStyle::SetResolvedStyleContext(RefPtr<nsStyleContext>&& aContext)
{
if (!mResolvedStyleContext) {
mResolvedStyleContext = true;
- mContent->AddMutationObserver(this);
+ mElement->AddMutationObserver(this);
}
mStyleContext = aContext;
}
@@ -651,7 +651,7 @@ 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);
@@ -659,7 +659,7 @@ nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush)
mFlushedPendingReflows = aNeedsLayoutFlush;
#endif
- nsCOMPtr<nsIPresShell> presShellForContent = GetPresShellForContent(mContent);
+ nsCOMPtr<nsIPresShell> presShellForContent = GetPresShellForContent(mElement);
if (presShellForContent && presShellForContent != document->GetShell()) {
presShellForContent->FlushPendingNotifications(Flush_Style);
}
@@ -674,7 +674,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;
}
@@ -683,12 +687,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();
@@ -731,7 +735,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);
@@ -824,7 +828,6 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName, ErrorRes
UpdateCurrentStyleSources(needsLayoutFlush);
if (!mStyleContext) {
- aRv.Throw(NS_ERROR_NOT_AVAILABLE);
return nullptr;
}
@@ -2861,7 +2864,7 @@ nsComputedDOMStyle::DoGetGridTemplateColumns()
nsGridContainerFrame* gridFrame =
nsGridContainerFrame::GetGridFrameWithComputedInfo(
- mContent->GetPrimaryFrame());
+ mElement->GetPrimaryFrame());
if (gridFrame) {
info = gridFrame->GetComputedTemplateColumns();
@@ -2877,7 +2880,7 @@ nsComputedDOMStyle::DoGetGridTemplateRows()
nsGridContainerFrame* gridFrame =
nsGridContainerFrame::GetGridFrameWithComputedInfo(
- mContent->GetPrimaryFrame());
+ mElement->GetPrimaryFrame());
if (gridFrame) {
info = gridFrame->GetComputedTemplateRows();
@@ -5214,8 +5217,10 @@ nsComputedDOMStyle::GetLineHeightCoord(nscoord& aCoord)
// lie about font size inflation since we lie about font size (since
// the inflation only applies to text)
- aCoord = ReflowInput::CalcLineHeight(mContent, mStyleContext,
- blockHeight, 1.0f);
+ aCoord = ReflowInput::CalcLineHeight(mElement,
+ mStyleContext,
+ blockHeight,
+ 1.0f);
// CalcLineHeight uses font->mFont.size, but we want to use
// font->mSize as the font size. Adjust for that. Also adjust for
@@ -6642,7 +6647,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");
diff --git a/layout/style/nsComputedDOMStyle.h b/layout/style/nsComputedDOMStyle.h
index 77df71ec89..7fbf49afe7 100644
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -76,12 +76,12 @@ public:
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>
@@ -667,9 +667,9 @@ private:
// 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
@@ -735,7 +735,7 @@ private:
already_AddRefed<nsComputedDOMStyle>
NS_NewComputedDOMStyle(mozilla::dom::Element* aElement,
const nsAString& aPseudoElt,
- nsIPresShell* aPresShell,
+ nsIDocument* aDocument,
nsComputedDOMStyle::StyleType aStyleType =
nsComputedDOMStyle::eAll);