2016-07-08 10:08:46 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
2017-02-13 06:21:31 +03:00
|
|
|
#include "mozilla/RestyleManager.h"
|
2018-04-07 16:48:43 +03:00
|
|
|
|
|
|
|
#include "mozilla/AutoRestyleTimelineMarker.h"
|
|
|
|
#include "mozilla/AutoTimelineMarker.h"
|
|
|
|
#include "mozilla/ComputedStyle.h"
|
|
|
|
#include "mozilla/ComputedStyleInlines.h"
|
|
|
|
#include "mozilla/DocumentStyleRootIterator.h"
|
2018-10-14 03:05:48 +03:00
|
|
|
#include "mozilla/GeckoBindings.h"
|
2018-07-30 05:20:53 +03:00
|
|
|
#include "mozilla/LayerAnimationInfo.h"
|
2018-11-13 01:20:52 +03:00
|
|
|
#include "mozilla/layers/AnimationInfo.h"
|
2018-11-28 00:39:53 +03:00
|
|
|
#include "mozilla/layout/ScrollAnchorContainer.h"
|
2018-04-07 16:48:43 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
|
|
|
#include "mozilla/ServoStyleSetInlines.h"
|
|
|
|
#include "mozilla/Unused.h"
|
|
|
|
#include "mozilla/ViewportFrame.h"
|
|
|
|
#include "mozilla/dom/ChildIterator.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/DocumentInlines.h"
|
2018-04-07 16:48:43 +03:00
|
|
|
#include "mozilla/dom/ElementInlines.h"
|
2018-07-26 08:37:10 +03:00
|
|
|
#include "mozilla/dom/HTMLBodyElement.h"
|
2017-05-02 09:03:16 +03:00
|
|
|
|
|
|
|
#include "Layers.h"
|
2018-02-13 20:08:42 +03:00
|
|
|
#include "nsAnimationManager.h"
|
2018-04-07 16:48:43 +03:00
|
|
|
#include "nsBlockFrame.h"
|
|
|
|
#include "nsBulletFrame.h"
|
|
|
|
#include "nsContentUtils.h"
|
2018-02-13 20:08:42 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
|
|
|
#include "nsCSSRendering.h"
|
2016-07-08 10:08:46 +03:00
|
|
|
#include "nsIFrame.h"
|
2018-02-14 01:38:20 +03:00
|
|
|
#include "nsIFrameInlines.h"
|
2018-04-07 16:48:43 +03:00
|
|
|
#include "nsImageFrame.h"
|
2017-02-10 05:42:27 +03:00
|
|
|
#include "nsIPresShellInlines.h"
|
2018-02-13 20:08:42 +03:00
|
|
|
#include "nsPlaceholderFrame.h"
|
2018-04-07 16:48:43 +03:00
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
#include "nsRefreshDriver.h"
|
2018-02-13 20:08:42 +03:00
|
|
|
#include "nsStyleChangeList.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
#include "nsStyleUtil.h"
|
2018-03-08 00:40:58 +03:00
|
|
|
#include "nsTransitionManager.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
#include "StickyScrollContainer.h"
|
|
|
|
#include "mozilla/EffectSet.h"
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
#include "mozilla/IntegerRange.h"
|
2018-02-13 20:08:42 +03:00
|
|
|
#include "SVGObserverUtils.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
#include "SVGTextFrame.h"
|
|
|
|
#include "ActiveLayerTracker.h"
|
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2017-05-02 09:03:16 +03:00
|
|
|
|
2018-04-07 16:48:43 +03:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
# include "nsAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
|
2018-11-13 01:20:52 +03:00
|
|
|
using mozilla::layers::AnimationInfo;
|
2019-02-05 22:47:29 +03:00
|
|
|
using mozilla::layout::ScrollAnchorContainer;
|
2018-11-13 01:20:52 +03:00
|
|
|
|
2018-02-13 20:08:42 +03:00
|
|
|
using namespace mozilla::dom;
|
2018-11-27 01:07:03 +03:00
|
|
|
using namespace mozilla::layers;
|
2018-02-13 20:08:42 +03:00
|
|
|
|
2016-07-08 10:08:46 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2018-03-28 18:34:34 +03:00
|
|
|
RestyleManager::RestyleManager(nsPresContext* aPresContext)
|
2016-07-08 10:08:46 +03:00
|
|
|
: mPresContext(aPresContext),
|
|
|
|
mRestyleGeneration(1),
|
2017-05-23 09:13:47 +03:00
|
|
|
mUndisplayedRestyleGeneration(1),
|
2016-08-04 04:58:06 +03:00
|
|
|
mInStyleRefresh(false),
|
2017-03-09 12:15:08 +03:00
|
|
|
mAnimationGeneration(0) {
|
2016-07-08 10:08:46 +03:00
|
|
|
MOZ_ASSERT(mPresContext);
|
|
|
|
}
|
|
|
|
|
2018-04-02 06:30:51 +03:00
|
|
|
void RestyleManager::ContentInserted(nsIContent* aChild) {
|
|
|
|
MOZ_ASSERT(aChild->GetParentNode());
|
|
|
|
RestyleForInsertOrChange(aChild);
|
2017-02-13 06:21:33 +03:00
|
|
|
}
|
|
|
|
|
2018-04-02 06:30:51 +03:00
|
|
|
void RestyleManager::ContentAppended(nsIContent* aFirstNewContent) {
|
|
|
|
MOZ_ASSERT(aFirstNewContent->GetParent());
|
|
|
|
|
2017-02-13 06:21:33 +03:00
|
|
|
// The container cannot be a document, but might be a ShadowRoot.
|
2018-04-02 06:30:51 +03:00
|
|
|
if (!aFirstNewContent->GetParentNode()->IsElement()) {
|
2017-02-13 06:21:33 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-04-02 06:30:51 +03:00
|
|
|
Element* container = aFirstNewContent->GetParentNode()->AsElement();
|
2017-02-13 06:21:33 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
for (nsIContent* cur = aFirstNewContent; cur; cur = cur->GetNextSibling()) {
|
|
|
|
NS_ASSERTION(!cur->IsRootOfAnonymousSubtree(),
|
|
|
|
"anonymous nodes should not be in child lists");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
uint32_t selectorFlags =
|
|
|
|
container->GetFlags() &
|
|
|
|
(NODE_ALL_SELECTOR_FLAGS & ~NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS);
|
|
|
|
if (selectorFlags == 0) return;
|
|
|
|
|
|
|
|
if (selectorFlags & NODE_HAS_EMPTY_SELECTOR) {
|
|
|
|
// see whether we need to restyle the container
|
|
|
|
bool wasEmpty = true; // :empty or :-moz-only-whitespace
|
|
|
|
for (nsIContent* cur = container->GetFirstChild(); cur != aFirstNewContent;
|
|
|
|
cur = cur->GetNextSibling()) {
|
|
|
|
// We don't know whether we're testing :empty or :-moz-only-whitespace,
|
|
|
|
// so be conservative and assume :-moz-only-whitespace (i.e., make
|
|
|
|
// IsSignificantChild less likely to be true, and thus make us more
|
|
|
|
// likely to restyle).
|
2018-02-28 04:54:01 +03:00
|
|
|
if (nsStyleUtil::IsSignificantChild(cur, false)) {
|
2017-02-13 06:21:33 +03:00
|
|
|
wasEmpty = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wasEmpty) {
|
|
|
|
RestyleForEmptyChange(container);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectorFlags & NODE_HAS_SLOW_SELECTOR) {
|
2019-03-14 14:47:50 +03:00
|
|
|
PostRestyleEvent(container, RestyleHint::RestyleSubtree(), nsChangeHint(0));
|
2017-02-13 06:21:33 +03:00
|
|
|
// Restyling the container is the most we can do here, so we're done.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectorFlags & NODE_HAS_EDGE_CHILD_SELECTOR) {
|
|
|
|
// restyle the last element child before this node
|
|
|
|
for (nsIContent* cur = aFirstNewContent->GetPreviousSibling(); cur;
|
|
|
|
cur = cur->GetPreviousSibling()) {
|
|
|
|
if (cur->IsElement()) {
|
2019-03-14 14:47:50 +03:00
|
|
|
PostRestyleEvent(cur->AsElement(), RestyleHint::RestyleSubtree(),
|
|
|
|
nsChangeHint(0));
|
2017-02-13 06:21:33 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-14 14:47:50 +03:00
|
|
|
static void RestyleSiblingsStartingWith(RestyleManager& aRM,
|
|
|
|
nsIContent* aStartingSibling) {
|
|
|
|
for (nsIContent* sibling = aStartingSibling; sibling;
|
|
|
|
sibling = sibling->GetNextSibling()) {
|
|
|
|
if (auto* element = Element::FromNode(sibling)) {
|
|
|
|
aRM.PostRestyleEvent(element, RestyleHint::RestyleSubtree(),
|
|
|
|
nsChangeHint(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
void RestyleManager::RestyleForEmptyChange(Element* aContainer) {
|
2019-03-14 14:47:50 +03:00
|
|
|
PostRestyleEvent(aContainer, RestyleHint::RestyleSubtree(), nsChangeHint(0));
|
|
|
|
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
// In some cases (:empty + E, :empty ~ E), a change in the content of
|
|
|
|
// an element requires restyling its parent's siblings.
|
|
|
|
nsIContent* grandparent = aContainer->GetParent();
|
2019-03-14 14:47:50 +03:00
|
|
|
if (!grandparent ||
|
|
|
|
!(grandparent->GetFlags() & NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS)) {
|
|
|
|
return;
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
}
|
2019-03-14 14:47:50 +03:00
|
|
|
RestyleSiblingsStartingWith(*this, aContainer->GetNextSibling());
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::MaybeRestyleForEdgeChildChange(Element* aContainer,
|
|
|
|
nsIContent* aChangedChild) {
|
|
|
|
MOZ_ASSERT(aContainer->GetFlags() & NODE_HAS_EDGE_CHILD_SELECTOR);
|
|
|
|
MOZ_ASSERT(aChangedChild->GetParent() == aContainer);
|
|
|
|
// restyle the previously-first element child if it is after this node
|
|
|
|
bool passedChild = false;
|
|
|
|
for (nsIContent* content = aContainer->GetFirstChild(); content;
|
|
|
|
content = content->GetNextSibling()) {
|
|
|
|
if (content == aChangedChild) {
|
|
|
|
passedChild = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (content->IsElement()) {
|
|
|
|
if (passedChild) {
|
2019-03-14 14:47:50 +03:00
|
|
|
PostRestyleEvent(content->AsElement(), RestyleHint::RestyleSubtree(),
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
nsChangeHint(0));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// restyle the previously-last element child if it is before this node
|
|
|
|
passedChild = false;
|
|
|
|
for (nsIContent* content = aContainer->GetLastChild(); content;
|
|
|
|
content = content->GetPreviousSibling()) {
|
|
|
|
if (content == aChangedChild) {
|
|
|
|
passedChild = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (content->IsElement()) {
|
|
|
|
if (passedChild) {
|
2019-03-14 14:47:50 +03:00
|
|
|
PostRestyleEvent(content->AsElement(), RestyleHint::RestyleSubtree(),
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
nsChangeHint(0));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename CharT>
|
|
|
|
bool WhitespaceOnly(const CharT* aBuffer, size_t aUpTo) {
|
|
|
|
for (auto index : IntegerRange(aUpTo)) {
|
|
|
|
if (!dom::IsSpaceCharacter(aBuffer[index])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename CharT>
|
|
|
|
bool WhitespaceOnlyChangedOnAppend(const CharT* aBuffer, size_t aOldLength,
|
|
|
|
size_t aNewLength) {
|
2018-03-02 14:07:24 +03:00
|
|
|
MOZ_ASSERT(aOldLength <= aNewLength);
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
if (!WhitespaceOnly(aBuffer, aOldLength)) {
|
|
|
|
// The old text was already not whitespace-only.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !WhitespaceOnly(aBuffer + aOldLength, aNewLength - aOldLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool HasAnySignificantSibling(Element* aContainer, nsIContent* aChild) {
|
|
|
|
MOZ_ASSERT(aChild->GetParent() == aContainer);
|
|
|
|
for (nsIContent* child = aContainer->GetFirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
if (child == aChild) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// We don't know whether we're testing :empty or :-moz-only-whitespace,
|
|
|
|
// so be conservative and assume :-moz-only-whitespace (i.e., make
|
|
|
|
// IsSignificantChild less likely to be true, and thus make us more
|
|
|
|
// likely to restyle).
|
2018-02-28 04:54:01 +03:00
|
|
|
if (nsStyleUtil::IsSignificantChild(child, false)) {
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::CharacterDataChanged(
|
|
|
|
nsIContent* aContent, const CharacterDataChangeInfo& aInfo) {
|
|
|
|
nsINode* parent = aContent->GetParentNode();
|
|
|
|
MOZ_ASSERT(parent, "How were we notified of a stray node?");
|
|
|
|
|
|
|
|
uint32_t slowSelectorFlags = parent->GetFlags() & NODE_ALL_SELECTOR_FLAGS;
|
|
|
|
if (!(slowSelectorFlags &
|
|
|
|
(NODE_HAS_EMPTY_SELECTOR | NODE_HAS_EDGE_CHILD_SELECTOR))) {
|
|
|
|
// Nothing to do, no other slow selector can change as a result of this.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-13 01:41:00 +03:00
|
|
|
if (!aContent->IsText()) {
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
// Doesn't matter to styling (could be a processing instruction or a
|
|
|
|
// comment), it can't change whether any selectors match or don't.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MOZ_UNLIKELY(!parent->IsElement())) {
|
|
|
|
MOZ_ASSERT(parent->IsShadowRoot());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MOZ_UNLIKELY(aContent->IsRootOfAnonymousSubtree())) {
|
|
|
|
// This is an anonymous node and thus isn't in child lists, so isn't taken
|
|
|
|
// into account for selector matching the relevant selectors here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle appends specially since they're common and we can know both the old
|
|
|
|
// and the new text exactly.
|
|
|
|
//
|
|
|
|
// TODO(emilio): This could be made much more general if :-moz-only-whitespace
|
|
|
|
// / :-moz-first-node and :-moz-last-node didn't exist. In that case we only
|
|
|
|
// need to know whether we went from empty to non-empty, and that's trivial to
|
|
|
|
// know, with CharacterDataChangeInfo...
|
|
|
|
if (!aInfo.mAppend) {
|
|
|
|
// FIXME(emilio): This restyles unnecessarily if the text node is the only
|
|
|
|
// child of the parent element. Fortunately, it's uncommon to have such
|
|
|
|
// nodes and this not being an append.
|
|
|
|
//
|
|
|
|
// See the testcase in bug 1427625 for a test-case that triggers this.
|
2018-04-02 06:30:51 +03:00
|
|
|
RestyleForInsertOrChange(aContent);
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsTextFragment* text = aContent->GetText();
|
|
|
|
|
|
|
|
const size_t oldLength = aInfo.mChangeStart;
|
|
|
|
const size_t newLength = text->GetLength();
|
|
|
|
|
|
|
|
const bool emptyChanged = !oldLength && newLength;
|
|
|
|
|
|
|
|
const bool whitespaceOnlyChanged =
|
|
|
|
text->Is2b()
|
|
|
|
? WhitespaceOnlyChangedOnAppend(text->Get2b(), oldLength, newLength)
|
|
|
|
: WhitespaceOnlyChangedOnAppend(text->Get1b(), oldLength, newLength);
|
|
|
|
|
|
|
|
if (!emptyChanged && !whitespaceOnlyChanged) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slowSelectorFlags & NODE_HAS_EMPTY_SELECTOR) {
|
|
|
|
if (!HasAnySignificantSibling(parent->AsElement(), aContent)) {
|
|
|
|
// We used to be empty, restyle the parent.
|
|
|
|
RestyleForEmptyChange(parent->AsElement());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slowSelectorFlags & NODE_HAS_EDGE_CHILD_SELECTOR) {
|
|
|
|
MaybeRestyleForEdgeChildChange(parent->AsElement(), aContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 06:21:33 +03:00
|
|
|
// Restyling for a ContentInserted or CharacterDataChanged notification.
|
|
|
|
// This could be used for ContentRemoved as well if we got the
|
|
|
|
// notification before the removal happened (and sometimes
|
|
|
|
// CharacterDataChanged is more like a removal than an addition).
|
|
|
|
// The comments are written and variables are named in terms of it being
|
|
|
|
// a ContentInserted notification.
|
2018-04-02 06:30:51 +03:00
|
|
|
void RestyleManager::RestyleForInsertOrChange(nsIContent* aChild) {
|
|
|
|
nsINode* parentNode = aChild->GetParentNode();
|
|
|
|
|
|
|
|
MOZ_ASSERT(parentNode);
|
2017-02-13 06:21:33 +03:00
|
|
|
// The container might be a document or a ShadowRoot.
|
2018-04-02 06:30:51 +03:00
|
|
|
if (!parentNode->IsElement()) {
|
2017-02-13 06:21:33 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-04-02 06:30:51 +03:00
|
|
|
Element* container = parentNode->AsElement();
|
2017-02-13 06:21:33 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(!aChild->IsRootOfAnonymousSubtree(),
|
|
|
|
"anonymous nodes should not be in child lists");
|
2017-07-09 01:02:47 +03:00
|
|
|
uint32_t selectorFlags = container->GetFlags() & NODE_ALL_SELECTOR_FLAGS;
|
2017-02-13 06:21:33 +03:00
|
|
|
if (selectorFlags == 0) return;
|
|
|
|
|
|
|
|
if (selectorFlags & NODE_HAS_EMPTY_SELECTOR) {
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
// See whether we need to restyle the container due to :empty /
|
|
|
|
// :-moz-only-whitespace.
|
|
|
|
const bool wasEmpty = !HasAnySignificantSibling(container, aChild);
|
2017-02-13 06:21:33 +03:00
|
|
|
if (wasEmpty) {
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
// FIXME(emilio): When coming from CharacterDataChanged this can restyle
|
|
|
|
// unnecessarily. Also can restyle unnecessarily if aChild is not
|
|
|
|
// significant anyway, though that's more unlikely.
|
2017-02-13 06:21:33 +03:00
|
|
|
RestyleForEmptyChange(container);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectorFlags & NODE_HAS_SLOW_SELECTOR) {
|
2019-03-14 14:47:50 +03:00
|
|
|
PostRestyleEvent(container, RestyleHint::RestyleSubtree(), nsChangeHint(0));
|
2017-02-13 06:21:33 +03:00
|
|
|
// Restyling the container is the most we can do here, so we're done.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectorFlags & NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS) {
|
|
|
|
// Restyle all later siblings.
|
2019-03-14 14:47:50 +03:00
|
|
|
RestyleSiblingsStartingWith(*this, aChild->GetNextSibling());
|
2017-02-13 06:21:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (selectorFlags & NODE_HAS_EDGE_CHILD_SELECTOR) {
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
MaybeRestyleForEdgeChildChange(container, aChild);
|
2017-02-13 06:21:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 06:30:51 +03:00
|
|
|
void RestyleManager::ContentRemoved(nsIContent* aOldChild,
|
2017-02-13 06:21:33 +03:00
|
|
|
nsIContent* aFollowingSibling) {
|
2018-04-02 06:30:51 +03:00
|
|
|
MOZ_ASSERT(aOldChild->GetParentNode());
|
|
|
|
|
2018-02-19 16:46:38 +03:00
|
|
|
// Computed style data isn't useful for detached nodes, and we'll need to
|
|
|
|
// recompute it anyway if we ever insert the nodes back into a document.
|
2018-03-23 19:01:34 +03:00
|
|
|
if (aOldChild->IsElement()) {
|
2018-04-07 16:48:43 +03:00
|
|
|
RestyleManager::ClearServoDataFromSubtree(aOldChild->AsElement());
|
2018-02-19 16:46:38 +03:00
|
|
|
}
|
|
|
|
|
2017-02-13 06:21:33 +03:00
|
|
|
// The container might be a document or a ShadowRoot.
|
2018-04-02 06:30:51 +03:00
|
|
|
if (!aOldChild->GetParentNode()->IsElement()) {
|
2017-02-13 06:21:33 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-04-02 06:30:51 +03:00
|
|
|
Element* container = aOldChild->GetParentNode()->AsElement();
|
2017-02-13 06:21:33 +03:00
|
|
|
|
|
|
|
if (aOldChild->IsRootOfAnonymousSubtree()) {
|
|
|
|
// This should be an assert, but this is called incorrectly in
|
|
|
|
// HTMLEditor::DeleteRefToAnonymousNode and the assertions were clogging
|
|
|
|
// up the logs. Make it an assert again when that's fixed.
|
|
|
|
MOZ_ASSERT(aOldChild->GetProperty(nsGkAtoms::restylableAnonymousNode),
|
|
|
|
"anonymous nodes should not be in child lists (bug 439258)");
|
|
|
|
}
|
2017-07-09 01:02:47 +03:00
|
|
|
uint32_t selectorFlags = container->GetFlags() & NODE_ALL_SELECTOR_FLAGS;
|
2017-02-13 06:21:33 +03:00
|
|
|
if (selectorFlags == 0) return;
|
|
|
|
|
|
|
|
if (selectorFlags & NODE_HAS_EMPTY_SELECTOR) {
|
|
|
|
// see whether we need to restyle the container
|
|
|
|
bool isEmpty = true; // :empty or :-moz-only-whitespace
|
|
|
|
for (nsIContent* child = container->GetFirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
// We don't know whether we're testing :empty or :-moz-only-whitespace,
|
|
|
|
// so be conservative and assume :-moz-only-whitespace (i.e., make
|
|
|
|
// IsSignificantChild less likely to be true, and thus make us more
|
|
|
|
// likely to restyle).
|
2018-02-28 04:54:01 +03:00
|
|
|
if (nsStyleUtil::IsSignificantChild(child, false)) {
|
2017-02-13 06:21:33 +03:00
|
|
|
isEmpty = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isEmpty) {
|
|
|
|
RestyleForEmptyChange(container);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectorFlags & NODE_HAS_SLOW_SELECTOR) {
|
2019-03-14 14:47:50 +03:00
|
|
|
PostRestyleEvent(container, RestyleHint::RestyleSubtree(), nsChangeHint(0));
|
2017-02-13 06:21:33 +03:00
|
|
|
// Restyling the container is the most we can do here, so we're done.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectorFlags & NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS) {
|
|
|
|
// Restyle all later siblings.
|
2019-03-14 14:47:50 +03:00
|
|
|
RestyleSiblingsStartingWith(*this, aFollowingSibling);
|
2017-02-13 06:21:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (selectorFlags & NODE_HAS_EDGE_CHILD_SELECTOR) {
|
|
|
|
// restyle the now-first element child if it was after aOldChild
|
|
|
|
bool reachedFollowingSibling = false;
|
|
|
|
for (nsIContent* content = container->GetFirstChild(); content;
|
|
|
|
content = content->GetNextSibling()) {
|
|
|
|
if (content == aFollowingSibling) {
|
|
|
|
reachedFollowingSibling = true;
|
|
|
|
// do NOT continue here; we might want to restyle this node
|
|
|
|
}
|
|
|
|
if (content->IsElement()) {
|
|
|
|
if (reachedFollowingSibling) {
|
2019-03-14 14:47:50 +03:00
|
|
|
PostRestyleEvent(content->AsElement(), RestyleHint::RestyleSubtree(),
|
2017-02-13 06:21:33 +03:00
|
|
|
nsChangeHint(0));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// restyle the now-last element child if it was before aOldChild
|
|
|
|
reachedFollowingSibling = (aFollowingSibling == nullptr);
|
|
|
|
for (nsIContent* content = container->GetLastChild(); content;
|
|
|
|
content = content->GetPreviousSibling()) {
|
|
|
|
if (content->IsElement()) {
|
|
|
|
if (reachedFollowingSibling) {
|
2019-03-14 14:47:50 +03:00
|
|
|
PostRestyleEvent(content->AsElement(), RestyleHint::RestyleSubtree(),
|
2017-02-13 06:21:33 +03:00
|
|
|
nsChangeHint(0));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (content == aFollowingSibling) {
|
|
|
|
reachedFollowingSibling = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-08 10:08:46 +03:00
|
|
|
/**
|
|
|
|
* Calculates the change hint and the restyle hint for a given content state
|
|
|
|
* change.
|
|
|
|
*/
|
2019-03-01 05:04:12 +03:00
|
|
|
static nsChangeHint ChangeForContentStateChange(const Element& aElement,
|
|
|
|
EventStates aStateMask) {
|
|
|
|
auto changeHint = nsChangeHint(0);
|
2016-07-08 10:08:46 +03:00
|
|
|
|
|
|
|
// Any change to a content state that affects which frames we construct
|
|
|
|
// must lead to a frame reconstruct here if we already have a frame.
|
|
|
|
// Note that we never decide through non-CSS means to not create frames
|
|
|
|
// based on content states, so if we already don't have a frame we don't
|
|
|
|
// need to force a reframe -- if it's needed, the HasStateDependentStyle
|
|
|
|
// call will handle things.
|
2019-03-01 05:04:12 +03:00
|
|
|
if (nsIFrame* primaryFrame = aElement.GetPrimaryFrame()) {
|
2016-07-08 10:08:46 +03:00
|
|
|
// If it's generated content, ignore LOADING/etc state changes on it.
|
|
|
|
if (!primaryFrame->IsGeneratedContentFrame() &&
|
|
|
|
aStateMask.HasAtLeastOneOfStates(
|
|
|
|
NS_EVENT_STATE_BROKEN | NS_EVENT_STATE_USERDISABLED |
|
|
|
|
NS_EVENT_STATE_SUPPRESSED | NS_EVENT_STATE_LOADING)) {
|
2019-03-01 05:04:12 +03:00
|
|
|
return nsChangeHint_ReconstructFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* disp = primaryFrame->StyleDisplay();
|
|
|
|
if (disp->HasAppearance()) {
|
|
|
|
nsPresContext* pc = primaryFrame->PresContext();
|
|
|
|
nsITheme* theme = pc->GetTheme();
|
|
|
|
if (theme &&
|
|
|
|
theme->ThemeSupportsWidget(pc, primaryFrame, disp->mAppearance)) {
|
|
|
|
bool repaint = false;
|
|
|
|
theme->WidgetStateChanged(primaryFrame, disp->mAppearance, nullptr,
|
|
|
|
&repaint, nullptr);
|
|
|
|
if (repaint) {
|
|
|
|
changeHint |= nsChangeHint_RepaintFrame;
|
2016-07-08 10:08:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
primaryFrame->ContentStatesChanged(aStateMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aStateMask.HasState(NS_EVENT_STATE_VISITED)) {
|
|
|
|
// Exposing information to the page about whether the link is
|
|
|
|
// visited or not isn't really something we can worry about here.
|
|
|
|
// FIXME: We could probably do this a bit better.
|
2019-03-01 05:04:12 +03:00
|
|
|
changeHint |= nsChangeHint_RepaintFrame;
|
2016-07-08 10:08:46 +03:00
|
|
|
}
|
2019-03-01 05:04:12 +03:00
|
|
|
|
|
|
|
return changeHint;
|
2016-07-08 10:08:46 +03:00
|
|
|
}
|
|
|
|
|
2016-08-05 21:54:22 +03:00
|
|
|
#ifdef DEBUG
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
nsCString RestyleManager::ChangeHintToString(nsChangeHint aHint) {
|
2016-08-05 21:54:22 +03:00
|
|
|
nsCString result;
|
|
|
|
bool any = false;
|
|
|
|
const char* names[] = {"RepaintFrame",
|
|
|
|
"NeedReflow",
|
|
|
|
"ClearAncestorIntrinsics",
|
|
|
|
"ClearDescendantIntrinsics",
|
|
|
|
"NeedDirtyReflow",
|
|
|
|
"SyncFrameView",
|
|
|
|
"UpdateCursor",
|
|
|
|
"UpdateEffects",
|
|
|
|
"UpdateOpacityLayer",
|
|
|
|
"UpdateTransformLayer",
|
|
|
|
"ReconstructFrame",
|
|
|
|
"UpdateOverflow",
|
|
|
|
"UpdateSubtreeOverflow",
|
|
|
|
"UpdatePostTransformOverflow",
|
|
|
|
"UpdateParentOverflow",
|
2017-03-07 03:10:38 +03:00
|
|
|
"ChildrenOnlyTransform",
|
|
|
|
"RecomputePosition",
|
|
|
|
"UpdateContainingBlock",
|
2016-08-05 21:54:22 +03:00
|
|
|
"BorderStyleNoneChange",
|
|
|
|
"UpdateTextPath",
|
|
|
|
"SchedulePaint",
|
|
|
|
"NeutralChange",
|
|
|
|
"InvalidateRenderingObservers",
|
|
|
|
"ReflowChangesSizeOrPosition",
|
|
|
|
"UpdateComputedBSize",
|
2016-09-30 00:15:32 +03:00
|
|
|
"UpdateUsesOpacity",
|
|
|
|
"UpdateBackgroundPosition",
|
2018-08-03 09:42:33 +03:00
|
|
|
"AddOrRemoveTransform",
|
|
|
|
"ScrollbarChange",
|
2018-02-09 04:43:10 +03:00
|
|
|
"UpdateWidgetProperties",
|
|
|
|
"UpdateTableCellSpans",
|
|
|
|
"VisibilityChange"};
|
|
|
|
static_assert(nsChangeHint_AllHints ==
|
|
|
|
static_cast<uint32_t>((1ull << ArrayLength(names)) - 1),
|
2016-08-15 13:52:05 +03:00
|
|
|
"Name list doesn't match change hints.");
|
2018-02-09 04:43:10 +03:00
|
|
|
uint32_t hint =
|
|
|
|
aHint & static_cast<uint32_t>((1ull << ArrayLength(names)) - 1);
|
|
|
|
uint32_t rest =
|
|
|
|
aHint & ~static_cast<uint32_t>((1ull << ArrayLength(names)) - 1);
|
2017-03-21 11:33:05 +03:00
|
|
|
if ((hint & NS_STYLE_HINT_REFLOW) == NS_STYLE_HINT_REFLOW) {
|
|
|
|
result.AppendLiteral("NS_STYLE_HINT_REFLOW");
|
|
|
|
hint = hint & ~NS_STYLE_HINT_REFLOW;
|
|
|
|
any = true;
|
|
|
|
} else if ((hint & nsChangeHint_AllReflowHints) ==
|
|
|
|
nsChangeHint_AllReflowHints) {
|
|
|
|
result.AppendLiteral("nsChangeHint_AllReflowHints");
|
|
|
|
hint = hint & ~nsChangeHint_AllReflowHints;
|
|
|
|
any = true;
|
|
|
|
} else if ((hint & NS_STYLE_HINT_VISUAL) == NS_STYLE_HINT_VISUAL) {
|
|
|
|
result.AppendLiteral("NS_STYLE_HINT_VISUAL");
|
|
|
|
hint = hint & ~NS_STYLE_HINT_VISUAL;
|
2016-08-05 21:54:22 +03:00
|
|
|
any = true;
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(names); i++) {
|
2018-02-09 04:43:10 +03:00
|
|
|
if (hint & (1u << i)) {
|
2016-08-05 21:54:22 +03:00
|
|
|
if (any) {
|
|
|
|
result.AppendLiteral(" | ");
|
|
|
|
}
|
|
|
|
result.AppendPrintf("nsChangeHint_%s", names[i]);
|
|
|
|
any = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rest) {
|
|
|
|
if (any) {
|
|
|
|
result.AppendLiteral(" | ");
|
|
|
|
}
|
|
|
|
result.AppendPrintf("0x%0x", rest);
|
|
|
|
} else {
|
|
|
|
if (!any) {
|
|
|
|
result.AppendLiteral("nsChangeHint(0)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-01 23:31:57 +03:00
|
|
|
/**
|
|
|
|
* Frame construction helpers follow.
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG
|
|
|
|
static bool gInApplyRenderingChangeToTree = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sync views on aFrame and all of aFrame's descendants (following
|
|
|
|
* placeholders), if aChange has nsChangeHint_SyncFrameView. Calls
|
|
|
|
* DoApplyRenderingChangeToTree on all aFrame's out-of-flow descendants
|
|
|
|
* (following placeholders), if aChange has nsChangeHint_RepaintFrame.
|
|
|
|
* aFrame should be some combination of nsChangeHint_SyncFrameView,
|
|
|
|
* nsChangeHint_RepaintFrame, nsChangeHint_UpdateOpacityLayer and
|
|
|
|
* nsChangeHint_SchedulePaint, nothing else.
|
|
|
|
*/
|
2016-08-01 23:40:27 +03:00
|
|
|
static void SyncViewsAndInvalidateDescendants(nsIFrame* aFrame,
|
|
|
|
nsChangeHint aChange);
|
2016-08-01 23:31:57 +03:00
|
|
|
|
2016-08-01 23:40:27 +03:00
|
|
|
static void StyleChangeReflow(nsIFrame* aFrame, nsChangeHint aHint);
|
2016-08-01 23:31:57 +03:00
|
|
|
|
|
|
|
/**
|
2018-11-23 18:58:27 +03:00
|
|
|
* This helper function is used to find the correct SVG frame to target when we
|
|
|
|
* encounter nsChangeHint_ChildrenOnlyTransform; needed since sometimes we end
|
|
|
|
* up handling that hint while processing hints for one of the SVG frame's
|
2016-08-01 23:31:57 +03:00
|
|
|
* ancestor frames.
|
|
|
|
*
|
|
|
|
* The reason that we sometimes end up trying to process the hint for an
|
|
|
|
* ancestor of the SVG frame that the hint is intended for is due to the way we
|
|
|
|
* process restyle events. ApplyRenderingChangeToTree adjusts the frame from
|
|
|
|
* the restyled element's principle frame to one of its ancestor frames based
|
|
|
|
* on what nsCSSRendering::FindBackground returns, since the background style
|
|
|
|
* may have been propagated up to an ancestor frame. Processing hints using an
|
|
|
|
* ancestor frame is fine in general, but nsChangeHint_ChildrenOnlyTransform is
|
2018-11-23 18:58:27 +03:00
|
|
|
* a special case since it is intended to update a specific frame.
|
2016-08-01 23:31:57 +03:00
|
|
|
*/
|
|
|
|
static nsIFrame* GetFrameForChildrenOnlyTransformHint(nsIFrame* aFrame) {
|
2017-04-30 18:30:08 +03:00
|
|
|
if (aFrame->IsViewportFrame()) {
|
2016-08-01 23:31:57 +03:00
|
|
|
// This happens if the root-<svg> is fixed positioned, in which case we
|
|
|
|
// can't use aFrame->GetContent() to find the primary frame, since
|
|
|
|
// GetContent() returns nullptr for ViewportFrame.
|
|
|
|
aFrame = aFrame->PrincipalChildList().FirstChild();
|
|
|
|
}
|
|
|
|
// For an nsHTMLScrollFrame, this will get the SVG frame that has the
|
|
|
|
// children-only transforms:
|
|
|
|
aFrame = aFrame->GetContent()->GetPrimaryFrame();
|
2017-04-30 18:30:08 +03:00
|
|
|
if (aFrame->IsSVGOuterSVGFrame()) {
|
2016-08-01 23:31:57 +03:00
|
|
|
aFrame = aFrame->PrincipalChildList().FirstChild();
|
2017-04-30 18:30:08 +03:00
|
|
|
MOZ_ASSERT(aFrame->IsSVGOuterSVGAnonChildFrame(),
|
2016-08-01 23:31:57 +03:00
|
|
|
"Where is the nsSVGOuterSVGFrame's anon child??");
|
|
|
|
}
|
2016-08-01 23:40:27 +03:00
|
|
|
MOZ_ASSERT(aFrame->IsFrameOfType(nsIFrame::eSVG | nsIFrame::eSVGContainer),
|
2016-08-01 23:31:57 +03:00
|
|
|
"Children-only transforms only expected on SVG frames");
|
|
|
|
return aFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if this function managed to successfully move a frame, and
|
|
|
|
// false if it could not process the position change, and a reflow should
|
|
|
|
// be performed instead.
|
|
|
|
static bool RecomputePosition(nsIFrame* aFrame) {
|
|
|
|
// Don't process position changes on table frames, since we already handle
|
|
|
|
// the dynamic position change on the table wrapper frame, and the
|
|
|
|
// reflow-based fallback code path also ignores positions on inner table
|
|
|
|
// frames.
|
2017-04-30 18:30:08 +03:00
|
|
|
if (aFrame->IsTableFrame()) {
|
2016-08-01 23:31:57 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsStyleDisplay* display = aFrame->StyleDisplay();
|
|
|
|
// Changes to the offsets of a non-positioned element can safely be ignored.
|
|
|
|
if (display->mPosition == NS_STYLE_POSITION_STATIC) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't process position changes on frames which have views or the ones which
|
|
|
|
// have a view somewhere in their descendants, because the corresponding view
|
|
|
|
// needs to be repositioned properly as well.
|
|
|
|
if (aFrame->HasView() ||
|
|
|
|
(aFrame->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW)) {
|
2018-11-14 13:16:01 +03:00
|
|
|
StyleChangeReflow(aFrame, nsChangeHint_NeedReflow |
|
|
|
|
nsChangeHint_ReflowChangesSizeOrPosition);
|
2016-08-01 23:31:57 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-09 05:00:47 +03:00
|
|
|
// Flexbox and Grid layout supports CSS Align and the optimizations below
|
|
|
|
// don't support that yet.
|
|
|
|
if (aFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
|
|
|
|
nsIFrame* ph = aFrame->GetPlaceholderFrame();
|
|
|
|
if (ph && ph->HasAnyStateBits(PLACEHOLDER_STATICPOS_NEEDS_CSSALIGN)) {
|
2018-11-14 13:16:01 +03:00
|
|
|
StyleChangeReflow(aFrame, nsChangeHint_NeedReflow |
|
|
|
|
nsChangeHint_ReflowChangesSizeOrPosition);
|
2017-11-09 05:00:47 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 23:31:57 +03:00
|
|
|
aFrame->SchedulePaint();
|
|
|
|
|
|
|
|
// For relative positioning, we can simply update the frame rect
|
|
|
|
if (display->IsRelativelyPositionedStyle()) {
|
|
|
|
// Move the frame
|
|
|
|
if (display->mPosition == NS_STYLE_POSITION_STICKY) {
|
|
|
|
// Update sticky positioning for an entire element at once, starting with
|
|
|
|
// the first continuation or ib-split sibling.
|
|
|
|
// It's rare that the frame we already have isn't already the first
|
|
|
|
// continuation or ib-split sibling, but it can happen when styles differ
|
|
|
|
// across continuations such as ::first-line or ::first-letter, and in
|
|
|
|
// those cases we will generally (but maybe not always) do the work twice.
|
|
|
|
nsIFrame* firstContinuation =
|
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
|
|
|
|
|
|
|
StickyScrollContainer::ComputeStickyOffsets(firstContinuation);
|
|
|
|
StickyScrollContainer* ssc =
|
2016-08-01 23:40:27 +03:00
|
|
|
StickyScrollContainer::GetStickyScrollContainerForFrame(
|
|
|
|
firstContinuation);
|
2016-08-01 23:31:57 +03:00
|
|
|
if (ssc) {
|
|
|
|
ssc->PositionContinuations(firstContinuation);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(NS_STYLE_POSITION_RELATIVE == display->mPosition,
|
|
|
|
"Unexpected type of positioning");
|
|
|
|
for (nsIFrame* cont = aFrame; cont;
|
|
|
|
cont = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(cont)) {
|
|
|
|
nsIFrame* cb = cont->GetContainingBlock();
|
|
|
|
nsMargin newOffsets;
|
|
|
|
WritingMode wm = cb->GetWritingMode();
|
|
|
|
const LogicalSize size(wm, cb->GetContentRectRelativeToSelf().Size());
|
|
|
|
|
|
|
|
ReflowInput::ComputeRelativeOffsets(wm, cont, size, newOffsets);
|
|
|
|
NS_ASSERTION(newOffsets.left == -newOffsets.right &&
|
|
|
|
newOffsets.top == -newOffsets.bottom,
|
|
|
|
"ComputeRelativeOffsets should return valid results");
|
|
|
|
|
|
|
|
// ReflowInput::ApplyRelativePositioning would work here, but
|
|
|
|
// since we've already checked mPosition and aren't changing the frame's
|
|
|
|
// normal position, go ahead and add the offsets directly.
|
2016-08-19 20:56:20 +03:00
|
|
|
// First, we need to ensure that the normal position is stored though.
|
2017-05-28 15:16:55 +03:00
|
|
|
bool hasProperty;
|
|
|
|
nsPoint normalPosition = cont->GetNormalPosition(&hasProperty);
|
|
|
|
if (!hasProperty) {
|
|
|
|
cont->AddProperty(nsIFrame::NormalPositionProperty(),
|
2017-05-27 14:36:00 +03:00
|
|
|
new nsPoint(normalPosition));
|
2016-08-19 20:56:20 +03:00
|
|
|
}
|
|
|
|
cont->SetPosition(normalPosition +
|
2016-08-01 23:31:57 +03:00
|
|
|
nsPoint(newOffsets.left, newOffsets.top));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-21 19:26:10 +03:00
|
|
|
if (aFrame->IsInScrollAnchorChain()) {
|
|
|
|
ScrollAnchorContainer* container = ScrollAnchorContainer::FindFor(aFrame);
|
2019-01-13 09:54:05 +03:00
|
|
|
aFrame->PresShell()->PostPendingScrollAnchorAdjustment(container);
|
2018-12-21 19:26:10 +03:00
|
|
|
}
|
2016-08-01 23:31:57 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For the absolute positioning case, set up a fake HTML reflow state for
|
|
|
|
// the frame, and then get the offsets and size from it. If the frame's size
|
|
|
|
// doesn't need to change, we can simply update the frame position. Otherwise
|
|
|
|
// we fall back to a reflow.
|
2017-06-09 22:14:53 +03:00
|
|
|
RefPtr<gfxContext> rc =
|
2017-11-09 05:00:48 +03:00
|
|
|
aFrame->PresShell()->CreateReferenceRenderingContext();
|
2016-08-01 23:31:57 +03:00
|
|
|
|
|
|
|
// Construct a bogus parent reflow state so that there's a usable
|
|
|
|
// containing block reflow state.
|
|
|
|
nsIFrame* parentFrame = aFrame->GetParent();
|
|
|
|
WritingMode parentWM = parentFrame->GetWritingMode();
|
|
|
|
WritingMode frameWM = aFrame->GetWritingMode();
|
|
|
|
LogicalSize parentSize = parentFrame->GetLogicalSize();
|
|
|
|
|
|
|
|
nsFrameState savedState = parentFrame->GetStateBits();
|
2017-06-09 22:14:53 +03:00
|
|
|
ReflowInput parentReflowInput(aFrame->PresContext(), parentFrame, rc,
|
2016-08-01 23:40:27 +03:00
|
|
|
parentSize);
|
2016-08-01 23:31:57 +03:00
|
|
|
parentFrame->RemoveStateBits(~nsFrameState(0));
|
|
|
|
parentFrame->AddStateBits(savedState);
|
|
|
|
|
|
|
|
// The bogus parent state here was created with no parent state of its own,
|
|
|
|
// and therefore it won't have an mCBReflowInput set up.
|
|
|
|
// But we may need one (for InitCBReflowInput in a child state), so let's
|
|
|
|
// try to create one here for the cases where it will be needed.
|
|
|
|
Maybe<ReflowInput> cbReflowInput;
|
|
|
|
nsIFrame* cbFrame = parentFrame->GetContainingBlock();
|
|
|
|
if (cbFrame && (aFrame->GetContainingBlock() != parentFrame ||
|
2017-04-30 18:30:08 +03:00
|
|
|
parentFrame->IsTableFrame())) {
|
2016-08-01 23:31:57 +03:00
|
|
|
LogicalSize cbSize = cbFrame->GetLogicalSize();
|
2017-06-09 22:14:53 +03:00
|
|
|
cbReflowInput.emplace(cbFrame->PresContext(), cbFrame, rc, cbSize);
|
2016-08-01 23:31:57 +03:00
|
|
|
cbReflowInput->ComputedPhysicalMargin() = cbFrame->GetUsedMargin();
|
|
|
|
cbReflowInput->ComputedPhysicalPadding() = cbFrame->GetUsedPadding();
|
|
|
|
cbReflowInput->ComputedPhysicalBorderPadding() =
|
|
|
|
cbFrame->GetUsedBorderAndPadding();
|
|
|
|
parentReflowInput.mCBReflowInput = cbReflowInput.ptr();
|
|
|
|
}
|
|
|
|
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(parentSize.ISize(parentWM) != NS_INTRINSICSIZE &&
|
|
|
|
parentSize.BSize(parentWM) != NS_INTRINSICSIZE,
|
|
|
|
"parentSize should be valid");
|
2016-08-01 23:31:57 +03:00
|
|
|
parentReflowInput.SetComputedISize(std::max(parentSize.ISize(parentWM), 0));
|
|
|
|
parentReflowInput.SetComputedBSize(std::max(parentSize.BSize(parentWM), 0));
|
|
|
|
parentReflowInput.ComputedPhysicalMargin().SizeTo(0, 0, 0, 0);
|
|
|
|
|
|
|
|
parentReflowInput.ComputedPhysicalPadding() = parentFrame->GetUsedPadding();
|
|
|
|
parentReflowInput.ComputedPhysicalBorderPadding() =
|
|
|
|
parentFrame->GetUsedBorderAndPadding();
|
|
|
|
LogicalSize availSize = parentSize.ConvertTo(frameWM, parentWM);
|
|
|
|
availSize.BSize(frameWM) = NS_INTRINSICSIZE;
|
|
|
|
|
|
|
|
ViewportFrame* viewport = do_QueryFrame(parentFrame);
|
|
|
|
nsSize cbSize =
|
|
|
|
viewport
|
|
|
|
? viewport->AdjustReflowInputAsContainingBlock(&parentReflowInput)
|
|
|
|
.Size()
|
|
|
|
: aFrame->GetContainingBlock()->GetSize();
|
|
|
|
const nsMargin& parentBorder =
|
|
|
|
parentReflowInput.mStyleBorder->GetComputedBorder();
|
|
|
|
cbSize -= nsSize(parentBorder.LeftRight(), parentBorder.TopBottom());
|
|
|
|
LogicalSize lcbSize(frameWM, cbSize);
|
2016-08-01 23:40:27 +03:00
|
|
|
ReflowInput reflowInput(aFrame->PresContext(), parentReflowInput, aFrame,
|
|
|
|
availSize, &lcbSize);
|
|
|
|
nsSize computedSize(reflowInput.ComputedWidth(),
|
|
|
|
reflowInput.ComputedHeight());
|
2016-08-01 23:31:57 +03:00
|
|
|
computedSize.width += reflowInput.ComputedPhysicalBorderPadding().LeftRight();
|
|
|
|
if (computedSize.height != NS_INTRINSICSIZE) {
|
2016-08-01 23:40:27 +03:00
|
|
|
computedSize.height +=
|
|
|
|
reflowInput.ComputedPhysicalBorderPadding().TopBottom();
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
nsSize size = aFrame->GetSize();
|
|
|
|
// The RecomputePosition hint is not used if any offset changed between auto
|
|
|
|
// and non-auto. If computedSize.height == NS_INTRINSICSIZE then the new
|
|
|
|
// element height will be its intrinsic height, and since 'top' and 'bottom''s
|
|
|
|
// auto-ness hasn't changed, the old height must also be its intrinsic
|
|
|
|
// height, which we can assume hasn't changed (or reflow would have
|
|
|
|
// been triggered).
|
|
|
|
if (computedSize.width == size.width &&
|
|
|
|
(computedSize.height == NS_INTRINSICSIZE ||
|
|
|
|
computedSize.height == size.height)) {
|
|
|
|
// If we're solving for 'left' or 'top', then compute it here, in order to
|
|
|
|
// match the reflow code path.
|
|
|
|
if (NS_AUTOOFFSET == reflowInput.ComputedPhysicalOffsets().left) {
|
|
|
|
reflowInput.ComputedPhysicalOffsets().left =
|
|
|
|
cbSize.width - reflowInput.ComputedPhysicalOffsets().right -
|
|
|
|
reflowInput.ComputedPhysicalMargin().right - size.width -
|
|
|
|
reflowInput.ComputedPhysicalMargin().left;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_AUTOOFFSET == reflowInput.ComputedPhysicalOffsets().top) {
|
|
|
|
reflowInput.ComputedPhysicalOffsets().top =
|
|
|
|
cbSize.height - reflowInput.ComputedPhysicalOffsets().bottom -
|
|
|
|
reflowInput.ComputedPhysicalMargin().bottom - size.height -
|
|
|
|
reflowInput.ComputedPhysicalMargin().top;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move the frame
|
|
|
|
nsPoint pos(parentBorder.left + reflowInput.ComputedPhysicalOffsets().left +
|
|
|
|
reflowInput.ComputedPhysicalMargin().left,
|
|
|
|
parentBorder.top + reflowInput.ComputedPhysicalOffsets().top +
|
|
|
|
reflowInput.ComputedPhysicalMargin().top);
|
|
|
|
aFrame->SetPosition(pos);
|
|
|
|
|
2018-12-21 19:26:10 +03:00
|
|
|
if (aFrame->IsInScrollAnchorChain()) {
|
|
|
|
ScrollAnchorContainer* container = ScrollAnchorContainer::FindFor(aFrame);
|
2019-01-13 09:54:05 +03:00
|
|
|
aFrame->PresShell()->PostPendingScrollAnchorAdjustment(container);
|
2018-12-21 19:26:10 +03:00
|
|
|
}
|
2016-08-01 23:31:57 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall back to a reflow
|
2018-11-14 13:16:01 +03:00
|
|
|
StyleChangeReflow(aFrame, nsChangeHint_NeedReflow |
|
|
|
|
nsChangeHint_ReflowChangesSizeOrPosition);
|
2016-08-01 23:31:57 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool HasBoxAncestor(nsIFrame* aFrame) {
|
|
|
|
for (nsIFrame* f = aFrame; f; f = f->GetParent()) {
|
|
|
|
if (f->IsXULBoxFrame()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if aFrame's subtree has placeholders for out-of-flow content
|
2019-01-18 00:00:34 +03:00
|
|
|
* whose 'position' style's bit in aPositionMask is set that would be affected
|
|
|
|
* due to the change to `aPossiblyChangingContainingBlock` (and thus would need
|
|
|
|
* to get reframed).
|
|
|
|
*
|
|
|
|
* In particular, this function returns true if there are placeholders whose OOF
|
|
|
|
* frames may need to be reparented (via reframing) as a result of whatever
|
|
|
|
* change actually happened.
|
|
|
|
*
|
|
|
|
* `aIsContainingBlock` represents whether `aPossiblyChangingContainingBlock` is
|
|
|
|
* a containing block with the _new_ style it just got, for any of the sorts of
|
|
|
|
* positioned descendants in aPositionMask.
|
2016-08-01 23:31:57 +03:00
|
|
|
*/
|
2019-01-18 00:00:34 +03:00
|
|
|
static bool ContainingBlockChangeAffectsDescendants(
|
|
|
|
nsIFrame* aPossiblyChangingContainingBlock, nsIFrame* aFrame,
|
|
|
|
uint32_t aPositionMask, bool aIsContainingBlock) {
|
2016-08-26 22:38:16 +03:00
|
|
|
MOZ_ASSERT(aPositionMask & (1 << NS_STYLE_POSITION_FIXED));
|
|
|
|
|
2016-08-01 23:31:57 +03:00
|
|
|
for (nsIFrame::ChildListIterator lists(aFrame); !lists.IsDone();
|
|
|
|
lists.Next()) {
|
2016-08-26 22:38:16 +03:00
|
|
|
for (nsIFrame* f : lists.CurrentList()) {
|
2017-04-30 18:30:08 +03:00
|
|
|
if (f->IsPlaceholderFrame()) {
|
2016-08-26 22:38:16 +03:00
|
|
|
nsIFrame* outOfFlow = nsPlaceholderFrame::GetRealFrameForPlaceholder(f);
|
|
|
|
// If SVG text frames could appear here, they could confuse us since
|
|
|
|
// they ignore their position style ... but they can't.
|
2017-03-23 10:29:11 +03:00
|
|
|
NS_ASSERTION(!nsSVGUtils::IsInSVGTextSubtree(outOfFlow),
|
2016-08-26 22:38:16 +03:00
|
|
|
"SVG text frames can't be out of flow");
|
|
|
|
if (aPositionMask & (1 << outOfFlow->StyleDisplay()->mPosition)) {
|
2019-01-18 00:00:34 +03:00
|
|
|
// NOTE(emilio): aPossiblyChangingContainingBlock is guaranteed to be
|
|
|
|
// a first continuation, see the assertion in the caller.
|
|
|
|
nsIFrame* parent = outOfFlow->GetParent()->FirstContinuation();
|
|
|
|
if (aIsContainingBlock) {
|
|
|
|
// If we are becoming a containing block, we only need to reframe if
|
|
|
|
// this oof's current containing block is an ancestor of the new
|
|
|
|
// frame.
|
|
|
|
if (parent != aPossiblyChangingContainingBlock &&
|
|
|
|
nsLayoutUtils::IsProperAncestorFrame(
|
|
|
|
parent, aPossiblyChangingContainingBlock)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If we are not a containing block anymore, we only need to reframe
|
|
|
|
// if we are the current containing block of the oof frame.
|
|
|
|
if (parent == aPossiblyChangingContainingBlock) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
}
|
2016-10-04 21:39:36 +03:00
|
|
|
// NOTE: It's tempting to check f->IsAbsPosContainingBlock() or
|
|
|
|
// f->IsFixedPosContainingBlock() here. However, that would only
|
|
|
|
// be testing the *new* style of the frame, which might exclude
|
|
|
|
// descendants that currently have this frame as an abs-pos
|
|
|
|
// containing block. Taking the codepath where we don't reframe
|
|
|
|
// could lead to an unsafe call to
|
|
|
|
// cont->MarkAsNotAbsoluteContainingBlock() before we've reframed
|
|
|
|
// the descendant and taken it off the absolute list.
|
2019-01-18 00:00:34 +03:00
|
|
|
if (ContainingBlockChangeAffectsDescendants(
|
|
|
|
aPossiblyChangingContainingBlock, f, aPositionMask,
|
|
|
|
aIsContainingBlock)) {
|
2016-08-26 22:38:16 +03:00
|
|
|
return true;
|
|
|
|
}
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-18 00:00:34 +03:00
|
|
|
static bool NeedToReframeToUpdateContainingBlock(nsIFrame* aFrame) {
|
2016-08-01 23:31:57 +03:00
|
|
|
static_assert(
|
|
|
|
0 <= NS_STYLE_POSITION_ABSOLUTE && NS_STYLE_POSITION_ABSOLUTE < 32,
|
|
|
|
"Style constant out of range");
|
|
|
|
static_assert(0 <= NS_STYLE_POSITION_FIXED && NS_STYLE_POSITION_FIXED < 32,
|
|
|
|
"Style constant out of range");
|
|
|
|
|
|
|
|
uint32_t positionMask;
|
2019-01-18 00:00:34 +03:00
|
|
|
bool isContainingBlock;
|
2016-08-01 23:31:57 +03:00
|
|
|
// Don't call aFrame->IsPositioned here, since that returns true if
|
|
|
|
// the frame already has a transform, and we want to ignore that here
|
2016-08-01 23:40:27 +03:00
|
|
|
if (aFrame->IsAbsolutelyPositioned() || aFrame->IsRelativelyPositioned()) {
|
2019-01-18 00:00:34 +03:00
|
|
|
// This frame is a container for abs-pos descendants whether or not its
|
|
|
|
// containing-block-ness could change for some other reasons (since we
|
|
|
|
// reframe for position changes).
|
2016-08-01 23:31:57 +03:00
|
|
|
// So abs-pos descendants are no problem; we only need to reframe if
|
|
|
|
// we have fixed-pos descendants.
|
|
|
|
positionMask = 1 << NS_STYLE_POSITION_FIXED;
|
2019-01-18 00:00:34 +03:00
|
|
|
isContainingBlock = aFrame->IsFixedPosContainingBlock();
|
2016-08-01 23:31:57 +03:00
|
|
|
} else {
|
|
|
|
// This frame may not be a container for abs-pos descendants already.
|
|
|
|
// So reframe if we have abs-pos or fixed-pos descendants.
|
2016-08-01 23:40:27 +03:00
|
|
|
positionMask =
|
|
|
|
(1 << NS_STYLE_POSITION_FIXED) | (1 << NS_STYLE_POSITION_ABSOLUTE);
|
2019-01-18 00:00:34 +03:00
|
|
|
isContainingBlock = aFrame->IsAbsPosContainingBlock() ||
|
|
|
|
aFrame->IsFixedPosContainingBlock();
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
2019-01-18 00:00:34 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(!aFrame->GetPrevContinuation(),
|
|
|
|
"We only process change hints on first continuations");
|
|
|
|
|
2016-08-01 23:31:57 +03:00
|
|
|
for (nsIFrame* f = aFrame; f;
|
|
|
|
f = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(f)) {
|
2019-01-18 00:00:34 +03:00
|
|
|
if (ContainingBlockChangeAffectsDescendants(aFrame, f, positionMask,
|
|
|
|
isContainingBlock)) {
|
2016-08-01 23:31:57 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DoApplyRenderingChangeToTree(nsIFrame* aFrame,
|
|
|
|
nsChangeHint aChange) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(gInApplyRenderingChangeToTree,
|
|
|
|
"should only be called within ApplyRenderingChangeToTree");
|
2016-08-01 23:31:57 +03:00
|
|
|
|
|
|
|
for (; aFrame;
|
|
|
|
aFrame = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(aFrame)) {
|
|
|
|
// Invalidate and sync views on all descendant frames, following
|
|
|
|
// placeholders. We don't need to update transforms in
|
|
|
|
// SyncViewsAndInvalidateDescendants, because there can't be any
|
|
|
|
// out-of-flows or popups that need to be transformed; all out-of-flow
|
|
|
|
// descendants of the transformed element must also be descendants of the
|
|
|
|
// transformed frame.
|
|
|
|
SyncViewsAndInvalidateDescendants(
|
|
|
|
aFrame, nsChangeHint(aChange & (nsChangeHint_RepaintFrame |
|
|
|
|
nsChangeHint_SyncFrameView |
|
|
|
|
nsChangeHint_UpdateOpacityLayer |
|
|
|
|
nsChangeHint_SchedulePaint)));
|
|
|
|
// This must be set to true if the rendering change needs to
|
|
|
|
// invalidate content. If it's false, a composite-only paint
|
|
|
|
// (empty transaction) will be scheduled.
|
|
|
|
bool needInvalidatingPaint = false;
|
|
|
|
|
|
|
|
// if frame has view, will already be invalidated
|
|
|
|
if (aChange & nsChangeHint_RepaintFrame) {
|
|
|
|
// Note that this whole block will be skipped when painting is suppressed
|
|
|
|
// (due to our caller ApplyRendingChangeToTree() discarding the
|
|
|
|
// nsChangeHint_RepaintFrame hint). If you add handling for any other
|
|
|
|
// hints within this block, be sure that they too should be ignored when
|
|
|
|
// painting is suppressed.
|
|
|
|
needInvalidatingPaint = true;
|
|
|
|
aFrame->InvalidateFrameSubtree();
|
|
|
|
if ((aChange & nsChangeHint_UpdateEffects) &&
|
|
|
|
aFrame->IsFrameOfType(nsIFrame::eSVG) &&
|
|
|
|
!(aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG)) {
|
|
|
|
// Need to update our overflow rects:
|
|
|
|
nsSVGUtils::ScheduleReflowSVG(aFrame);
|
|
|
|
}
|
2018-06-07 21:44:03 +03:00
|
|
|
|
|
|
|
ActiveLayerTracker::NotifyNeedsRepaint(aFrame);
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
if (aChange & nsChangeHint_UpdateTextPath) {
|
2017-03-23 10:29:11 +03:00
|
|
|
if (nsSVGUtils::IsInSVGTextSubtree(aFrame)) {
|
2016-08-01 23:31:57 +03:00
|
|
|
// Invalidate and reflow the entire SVGTextFrame:
|
|
|
|
NS_ASSERTION(aFrame->GetContent()->IsSVGElement(nsGkAtoms::textPath),
|
|
|
|
"expected frame for a <textPath> element");
|
2017-05-01 20:32:52 +03:00
|
|
|
nsIFrame* text = nsLayoutUtils::GetClosestFrameOfType(
|
|
|
|
aFrame, LayoutFrameType::SVGText);
|
2016-08-01 23:31:57 +03:00
|
|
|
NS_ASSERTION(text, "expected to find an ancestor SVGTextFrame");
|
|
|
|
static_cast<SVGTextFrame*>(text)->NotifyGlyphMetricsChange();
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(false, "unexpected frame got nsChangeHint_UpdateTextPath");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aChange & nsChangeHint_UpdateOpacityLayer) {
|
|
|
|
// FIXME/bug 796697: we can get away with empty transactions for
|
|
|
|
// opacity updates in many cases.
|
|
|
|
needInvalidatingPaint = true;
|
|
|
|
|
2018-05-24 18:44:44 +03:00
|
|
|
ActiveLayerTracker::NotifyRestyle(aFrame, eCSSProperty_opacity);
|
2016-08-01 23:31:57 +03:00
|
|
|
if (nsSVGIntegrationUtils::UsingEffectsForFrame(aFrame)) {
|
|
|
|
// SVG effects paints the opacity without using
|
|
|
|
// nsDisplayOpacity. We need to invalidate manually.
|
|
|
|
aFrame->InvalidateFrameSubtree();
|
|
|
|
}
|
|
|
|
}
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
nsIFrame* primaryFrame =
|
|
|
|
nsLayoutUtils::GetPrimaryFrameFromStyleFrame(aFrame);
|
2016-08-01 23:31:57 +03:00
|
|
|
if ((aChange & nsChangeHint_UpdateTransformLayer) &&
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
primaryFrame->IsTransformed()) {
|
2019-02-23 02:36:19 +03:00
|
|
|
// Note: All the transform-like properties should map to the same
|
|
|
|
// layer activity index, so does the restyle count. Therefore, using
|
|
|
|
// eCSSProperty_transform should be fine.
|
2016-08-01 23:31:57 +03:00
|
|
|
ActiveLayerTracker::NotifyRestyle(aFrame, eCSSProperty_transform);
|
|
|
|
// If we're not already going to do an invalidating paint, see
|
|
|
|
// if we can get away with only updating the transform on a
|
|
|
|
// layer for this frame, and not scheduling an invalidating
|
|
|
|
// paint.
|
|
|
|
if (!needInvalidatingPaint) {
|
2018-02-13 20:08:42 +03:00
|
|
|
nsDisplayItem::Layer* layer;
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
needInvalidatingPaint |= !primaryFrame->TryUpdateTransformOnly(&layer);
|
2016-08-01 23:31:57 +03:00
|
|
|
|
|
|
|
if (!needInvalidatingPaint) {
|
|
|
|
// Since we're not going to paint, we need to resend animation
|
|
|
|
// data to the layer.
|
|
|
|
MOZ_ASSERT(layer, "this can't happen if there's no layer");
|
2016-08-01 23:40:27 +03:00
|
|
|
nsDisplayListBuilder::AddAnimationsAndTransitionsToLayer(
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
layer, nullptr, nullptr, primaryFrame,
|
|
|
|
DisplayItemType::TYPE_TRANSFORM);
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aChange & nsChangeHint_ChildrenOnlyTransform) {
|
|
|
|
needInvalidatingPaint = true;
|
|
|
|
nsIFrame* childFrame = GetFrameForChildrenOnlyTransformHint(aFrame)
|
|
|
|
->PrincipalChildList()
|
|
|
|
.FirstChild();
|
|
|
|
for (; childFrame; childFrame = childFrame->GetNextSibling()) {
|
2019-02-23 02:36:19 +03:00
|
|
|
// Note: All the transform-like properties should map to the same
|
|
|
|
// layer activity index, so does the restyle count. Therefore, using
|
|
|
|
// eCSSProperty_transform should be fine.
|
2016-08-01 23:31:57 +03:00
|
|
|
ActiveLayerTracker::NotifyRestyle(childFrame, eCSSProperty_transform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aChange & nsChangeHint_SchedulePaint) {
|
|
|
|
needInvalidatingPaint = true;
|
|
|
|
}
|
2016-08-01 23:40:27 +03:00
|
|
|
aFrame->SchedulePaint(needInvalidatingPaint
|
|
|
|
? nsIFrame::PAINT_DEFAULT
|
|
|
|
: nsIFrame::PAINT_COMPOSITE_ONLY);
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 23:40:27 +03:00
|
|
|
static void SyncViewsAndInvalidateDescendants(nsIFrame* aFrame,
|
|
|
|
nsChangeHint aChange) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(gInApplyRenderingChangeToTree,
|
|
|
|
"should only be called within ApplyRenderingChangeToTree");
|
|
|
|
|
2016-08-01 23:31:57 +03:00
|
|
|
NS_ASSERTION(
|
|
|
|
nsChangeHint_size_t(aChange) ==
|
|
|
|
(aChange &
|
|
|
|
(nsChangeHint_RepaintFrame | nsChangeHint_SyncFrameView |
|
|
|
|
nsChangeHint_UpdateOpacityLayer | nsChangeHint_SchedulePaint)),
|
|
|
|
"Invalid change flag");
|
|
|
|
|
2017-03-21 03:22:13 +03:00
|
|
|
if (aChange & nsChangeHint_SyncFrameView) {
|
|
|
|
aFrame->SyncFrameViewProperties();
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame::ChildListIterator lists(aFrame);
|
|
|
|
for (; !lists.IsDone(); lists.Next()) {
|
|
|
|
for (nsIFrame* child : lists.CurrentList()) {
|
|
|
|
if (!(child->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) {
|
|
|
|
// only do frames that don't have placeholders
|
2017-04-30 18:30:08 +03:00
|
|
|
if (child->IsPlaceholderFrame()) {
|
2016-08-01 23:31:57 +03:00
|
|
|
// do the out-of-flow frame and its continuations
|
|
|
|
nsIFrame* outOfFlowFrame =
|
|
|
|
nsPlaceholderFrame::GetRealFrameForPlaceholder(child);
|
|
|
|
DoApplyRenderingChangeToTree(outOfFlowFrame, aChange);
|
|
|
|
} else if (lists.CurrentID() == nsIFrame::kPopupList) {
|
|
|
|
DoApplyRenderingChangeToTree(child, aChange);
|
2016-08-01 23:40:27 +03:00
|
|
|
} else { // regular frame
|
2016-08-01 23:31:57 +03:00
|
|
|
SyncViewsAndInvalidateDescendants(child, aChange);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 08:37:10 +03:00
|
|
|
static bool IsPrimaryFrameOfRootOrBodyElement(nsIFrame* aFrame) {
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
if (!content) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* document = content->OwnerDoc();
|
2018-07-26 08:37:10 +03:00
|
|
|
Element* root = document->GetRootElement();
|
|
|
|
if (!root) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsIFrame* rootFrame = root->GetPrimaryFrame();
|
|
|
|
if (!rootFrame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (aFrame == rootFrame) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Element* body = document->GetBodyElement();
|
|
|
|
if (!body) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsIFrame* bodyFrame = body->GetPrimaryFrame();
|
|
|
|
if (!bodyFrame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (aFrame == bodyFrame) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-01 23:31:57 +03:00
|
|
|
static void ApplyRenderingChangeToTree(nsIPresShell* aPresShell,
|
|
|
|
nsIFrame* aFrame, nsChangeHint aChange) {
|
|
|
|
// We check StyleDisplay()->HasTransformStyle() in addition to checking
|
|
|
|
// IsTransformed() since we can get here for some frames that don't support
|
|
|
|
// CSS transforms.
|
|
|
|
NS_ASSERTION(!(aChange & nsChangeHint_UpdateTransformLayer) ||
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
nsLayoutUtils::GetPrimaryFrameFromStyleFrame(aFrame)
|
|
|
|
->IsTransformed() ||
|
2016-08-01 23:31:57 +03:00
|
|
|
aFrame->StyleDisplay()->HasTransformStyle(),
|
|
|
|
"Unexpected UpdateTransformLayer hint");
|
|
|
|
|
|
|
|
if (aPresShell->IsPaintingSuppressed()) {
|
|
|
|
// Don't allow synchronous rendering changes when painting is turned off.
|
|
|
|
aChange &= ~nsChangeHint_RepaintFrame;
|
|
|
|
if (!aChange) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 23:40:27 +03:00
|
|
|
// Trigger rendering updates by damaging this frame and any
|
|
|
|
// continuations of this frame.
|
2016-08-01 23:31:57 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
gInApplyRenderingChangeToTree = true;
|
|
|
|
#endif
|
|
|
|
if (aChange & nsChangeHint_RepaintFrame) {
|
2018-07-26 08:37:10 +03:00
|
|
|
// If the frame is the primary frame of either the body element or
|
|
|
|
// the html element, we propagate the repaint change hint to the
|
|
|
|
// viewport. This is necessary for background and scrollbar colors
|
|
|
|
// propagation.
|
|
|
|
if (IsPrimaryFrameOfRootOrBodyElement(aFrame)) {
|
|
|
|
nsIFrame* rootFrame =
|
|
|
|
aFrame->PresShell()->FrameConstructor()->GetRootFrame();
|
|
|
|
MOZ_ASSERT(rootFrame, "No root frame?");
|
|
|
|
DoApplyRenderingChangeToTree(rootFrame, nsChangeHint_RepaintFrame);
|
2016-08-01 23:31:57 +03:00
|
|
|
aChange &= ~nsChangeHint_RepaintFrame;
|
|
|
|
if (!aChange) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DoApplyRenderingChangeToTree(aFrame, aChange);
|
|
|
|
#ifdef DEBUG
|
|
|
|
gInApplyRenderingChangeToTree = false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void AddSubtreeToOverflowTracker(
|
|
|
|
nsIFrame* aFrame, OverflowChangedTracker& aOverflowChangedTracker) {
|
|
|
|
if (aFrame->FrameMaintainsOverflow()) {
|
|
|
|
aOverflowChangedTracker.AddFrame(aFrame,
|
|
|
|
OverflowChangedTracker::CHILDREN_CHANGED);
|
|
|
|
}
|
|
|
|
nsIFrame::ChildListIterator lists(aFrame);
|
|
|
|
for (; !lists.IsDone(); lists.Next()) {
|
|
|
|
for (nsIFrame* child : lists.CurrentList()) {
|
|
|
|
AddSubtreeToOverflowTracker(child, aOverflowChangedTracker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void StyleChangeReflow(nsIFrame* aFrame, nsChangeHint aHint) {
|
|
|
|
nsIPresShell::IntrinsicDirty dirtyType;
|
|
|
|
if (aHint & nsChangeHint_ClearDescendantIntrinsics) {
|
|
|
|
NS_ASSERTION(aHint & nsChangeHint_ClearAncestorIntrinsics,
|
|
|
|
"Please read the comments in nsChangeHint.h");
|
|
|
|
NS_ASSERTION(aHint & nsChangeHint_NeedDirtyReflow,
|
|
|
|
"ClearDescendantIntrinsics requires NeedDirtyReflow");
|
|
|
|
dirtyType = nsIPresShell::eStyleChange;
|
|
|
|
} else if ((aHint & nsChangeHint_UpdateComputedBSize) &&
|
2016-08-01 23:40:27 +03:00
|
|
|
aFrame->HasAnyStateBits(
|
|
|
|
NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE)) {
|
2016-08-01 23:31:57 +03:00
|
|
|
dirtyType = nsIPresShell::eStyleChange;
|
|
|
|
} else if (aHint & nsChangeHint_ClearAncestorIntrinsics) {
|
|
|
|
dirtyType = nsIPresShell::eTreeChange;
|
|
|
|
} else if ((aHint & nsChangeHint_UpdateComputedBSize) &&
|
|
|
|
HasBoxAncestor(aFrame)) {
|
|
|
|
// The frame's computed BSize is changing, and we have a box ancestor
|
|
|
|
// whose cached intrinsic height may need to be updated.
|
|
|
|
dirtyType = nsIPresShell::eTreeChange;
|
|
|
|
} else {
|
|
|
|
dirtyType = nsIPresShell::eResize;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFrameState dirtyBits;
|
|
|
|
if (aFrame->GetStateBits() & NS_FRAME_FIRST_REFLOW) {
|
|
|
|
dirtyBits = nsFrameState(0);
|
|
|
|
} else if ((aHint & nsChangeHint_NeedDirtyReflow) ||
|
|
|
|
dirtyType == nsIPresShell::eStyleChange) {
|
|
|
|
dirtyBits = NS_FRAME_IS_DIRTY;
|
|
|
|
} else {
|
|
|
|
dirtyBits = NS_FRAME_HAS_DIRTY_CHILDREN;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're not going to clear any intrinsic sizes on the frames, and
|
|
|
|
// there are no dirty bits to set, then there's nothing to do.
|
|
|
|
if (dirtyType == nsIPresShell::eResize && !dirtyBits) return;
|
|
|
|
|
|
|
|
nsIPresShell::ReflowRootHandling rootHandling;
|
|
|
|
if (aHint & nsChangeHint_ReflowChangesSizeOrPosition) {
|
|
|
|
rootHandling = nsIPresShell::ePositionOrSizeChange;
|
|
|
|
} else {
|
|
|
|
rootHandling = nsIPresShell::eNoPositionOrSizeChange;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2017-11-09 05:00:48 +03:00
|
|
|
aFrame->PresShell()->FrameNeedsReflow(aFrame, dirtyType, dirtyBits,
|
2016-08-01 23:40:27 +03:00
|
|
|
rootHandling);
|
2016-08-01 23:31:57 +03:00
|
|
|
aFrame = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(aFrame);
|
|
|
|
} while (aFrame);
|
|
|
|
}
|
|
|
|
|
2017-08-11 07:17:07 +03:00
|
|
|
// Get the next sibling which might have a frame. This only considers siblings
|
|
|
|
// that stylo post-traversal looks at, so only elements and text. In
|
|
|
|
// particular, it ignores comments.
|
|
|
|
static nsIContent* NextSiblingWhichMayHaveFrame(nsIContent* aContent) {
|
|
|
|
for (nsIContent* next = aContent->GetNextSibling(); next;
|
|
|
|
next = next->GetNextSibling()) {
|
2018-04-13 01:41:00 +03:00
|
|
|
if (next->IsElement() || next->IsText()) {
|
2017-08-11 07:17:07 +03:00
|
|
|
return next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-02-13 06:21:32 +03:00
|
|
|
void RestyleManager::ProcessRestyledFrames(nsStyleChangeList& aChangeList) {
|
2016-08-01 23:31:57 +03:00
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Someone forgot a script blocker");
|
2017-07-19 11:13:43 +03:00
|
|
|
|
|
|
|
// See bug 1378219 comment 9:
|
|
|
|
// Recursive calls here are a bit worrying, but apparently do happen in the
|
|
|
|
// wild (although not currently in any of our automated tests). Try to get a
|
|
|
|
// stack from Nightly/Dev channel to figure out what's going on and whether
|
|
|
|
// it's OK.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mDestroyedFrames, "ProcessRestyledFrames recursion");
|
2017-05-27 14:36:00 +03:00
|
|
|
|
|
|
|
if (aChangeList.IsEmpty()) {
|
2017-02-17 22:25:56 +03:00
|
|
|
return;
|
2017-05-27 14:36:00 +03:00
|
|
|
}
|
|
|
|
|
2017-07-19 11:13:43 +03:00
|
|
|
// If mDestroyedFrames is null, we want to create a new hashtable here
|
|
|
|
// and destroy it on exit; but if it is already non-null (because we're in
|
|
|
|
// a recursive call), we will continue to use the existing table to
|
|
|
|
// accumulate destroyed frames, and NOT clear mDestroyedFrames on exit.
|
|
|
|
// We use a MaybeClearDestroyedFrames helper to conditionally reset the
|
|
|
|
// mDestroyedFrames pointer when this method returns.
|
|
|
|
typedef decltype(mDestroyedFrames) DestroyedFramesT;
|
|
|
|
class MOZ_RAII MaybeClearDestroyedFrames {
|
|
|
|
private:
|
|
|
|
DestroyedFramesT& mDestroyedFramesRef; // ref to caller's mDestroyedFrames
|
|
|
|
const bool mResetOnDestruction;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-19 11:13:43 +03:00
|
|
|
public:
|
|
|
|
explicit MaybeClearDestroyedFrames(DestroyedFramesT& aTarget)
|
|
|
|
: mDestroyedFramesRef(aTarget),
|
|
|
|
mResetOnDestruction(!aTarget) // reset only if target starts out null
|
|
|
|
{}
|
|
|
|
~MaybeClearDestroyedFrames() {
|
|
|
|
if (mResetOnDestruction) {
|
|
|
|
mDestroyedFramesRef.reset(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MaybeClearDestroyedFrames maybeClear(mDestroyedFrames);
|
|
|
|
if (!mDestroyedFrames) {
|
|
|
|
mDestroyedFrames = MakeUnique<nsTHashtable<nsPtrHashKey<const nsIFrame>>>();
|
|
|
|
}
|
2016-08-01 23:31:57 +03:00
|
|
|
|
2018-05-19 00:40:52 +03:00
|
|
|
AUTO_PROFILER_LABEL("RestyleManager::ProcessRestyledFrames", LAYOUT);
|
2016-08-01 23:31:57 +03:00
|
|
|
|
2016-08-03 01:47:19 +03:00
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
nsCSSFrameConstructor* frameConstructor = presContext->FrameConstructor();
|
2016-08-01 23:31:57 +03:00
|
|
|
|
2018-08-03 09:42:33 +03:00
|
|
|
// Handle nsChangeHint_ScrollbarChange, by either updating the
|
2017-05-10 23:53:27 +03:00
|
|
|
// scrollbars on the viewport, or upgrading the change hint to
|
|
|
|
// frame-reconstruct.
|
|
|
|
for (nsStyleChangeData& data : aChangeList) {
|
2018-08-03 09:42:33 +03:00
|
|
|
if (data.mHint & nsChangeHint_ScrollbarChange) {
|
|
|
|
data.mHint &= ~nsChangeHint_ScrollbarChange;
|
2017-05-10 23:53:27 +03:00
|
|
|
bool doReconstruct = true; // assume the worst
|
|
|
|
|
|
|
|
// Only bother with this if we're html/body, since:
|
|
|
|
// (a) It'd be *expensive* to reframe these particular nodes. They're
|
|
|
|
// at the root, so reframing would mean rebuilding the world.
|
|
|
|
// (b) It's often *unnecessary* to reframe for "overflow" changes on
|
|
|
|
// these particular nodes. In general, the only reason we reframe
|
|
|
|
// for "overflow" changes is so we can construct (or destroy) a
|
|
|
|
// scrollframe & scrollbars -- and the html/body nodes often don't
|
|
|
|
// need their own scrollframe/scrollbars because they coopt the ones
|
|
|
|
// on the viewport (which always exist). So depending on whether
|
|
|
|
// that's happening, we can skip the reframe for these nodes.
|
|
|
|
if (data.mContent->IsAnyOfHTMLElements(nsGkAtoms::body,
|
|
|
|
nsGkAtoms::html)) {
|
|
|
|
// If the restyled element provided/provides the scrollbar styles for
|
|
|
|
// the viewport before and/or after this restyle, AND it's not coopting
|
|
|
|
// that responsibility from some other element (which would need
|
|
|
|
// reconstruction to make its own scrollframe now), THEN: we don't need
|
|
|
|
// to reconstruct - we can just reflow, because no scrollframe is being
|
|
|
|
// added/removed.
|
|
|
|
nsIContent* prevOverrideNode =
|
2018-08-01 09:14:26 +03:00
|
|
|
presContext->GetViewportScrollStylesOverrideElement();
|
2017-05-10 23:53:27 +03:00
|
|
|
nsIContent* newOverrideNode =
|
2018-08-01 09:14:26 +03:00
|
|
|
presContext->UpdateViewportScrollStylesOverride();
|
2017-05-10 23:53:27 +03:00
|
|
|
|
|
|
|
if (data.mContent == prevOverrideNode ||
|
|
|
|
data.mContent == newOverrideNode) {
|
|
|
|
// If we get here, the restyled element provided the scrollbar styles
|
|
|
|
// for viewport before this restyle, OR it will provide them after.
|
|
|
|
if (!prevOverrideNode || !newOverrideNode ||
|
|
|
|
prevOverrideNode == newOverrideNode) {
|
|
|
|
// If we get here, the restyled element is NOT replacing (or being
|
|
|
|
// replaced by) some other element as the viewport's
|
|
|
|
// scrollbar-styles provider. (If it were, we'd potentially need to
|
|
|
|
// reframe to create a dedicated scrollframe for whichever element
|
|
|
|
// is being booted from providing viewport scrollbar styles.)
|
|
|
|
//
|
|
|
|
// Under these conditions, we're OK to assume that this "overflow"
|
|
|
|
// change only impacts the root viewport's scrollframe, which
|
|
|
|
// already exists, so we can simply reflow instead of reframing.
|
2017-05-26 00:53:27 +03:00
|
|
|
// When requesting this reflow, we send the exact same change hints
|
|
|
|
// that "width" and "height" would send (since conceptually,
|
|
|
|
// adding/removing scrollbars is like changing the available
|
|
|
|
// space).
|
|
|
|
data.mHint |= (nsChangeHint_ReflowHintsForISizeChange |
|
|
|
|
nsChangeHint_ReflowHintsForBSizeChange);
|
2017-05-10 23:53:27 +03:00
|
|
|
doReconstruct = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (doReconstruct) {
|
|
|
|
data.mHint |= nsChangeHint_ReconstructFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 23:31:57 +03:00
|
|
|
bool didUpdateCursor = false;
|
|
|
|
|
2017-03-03 09:51:39 +03:00
|
|
|
for (size_t i = 0; i < aChangeList.Length(); ++i) {
|
|
|
|
// Collect and coalesce adjacent siblings for lazy frame construction.
|
|
|
|
// Eventually it would be even better to make RecreateFramesForContent
|
|
|
|
// accept a range and coalesce all adjacent reconstructs (bug 1344139).
|
|
|
|
size_t lazyRangeStart = i;
|
|
|
|
while (i < aChangeList.Length() && aChangeList[i].mContent &&
|
|
|
|
aChangeList[i].mContent->HasFlag(NODE_NEEDS_FRAME) &&
|
|
|
|
(i == lazyRangeStart ||
|
2017-08-11 07:17:07 +03:00
|
|
|
NextSiblingWhichMayHaveFrame(aChangeList[i - 1].mContent) ==
|
|
|
|
aChangeList[i].mContent)) {
|
2017-03-03 09:51:39 +03:00
|
|
|
MOZ_ASSERT(aChangeList[i].mHint & nsChangeHint_ReconstructFrame);
|
|
|
|
MOZ_ASSERT(!aChangeList[i].mFrame);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (i != lazyRangeStart) {
|
|
|
|
nsIContent* start = aChangeList[lazyRangeStart].mContent;
|
2017-08-11 07:17:07 +03:00
|
|
|
nsIContent* end =
|
|
|
|
NextSiblingWhichMayHaveFrame(aChangeList[i - 1].mContent);
|
2017-03-03 09:51:39 +03:00
|
|
|
if (!end) {
|
2017-09-07 14:39:20 +03:00
|
|
|
frameConstructor->ContentAppended(
|
2017-09-07 18:02:20 +03:00
|
|
|
start, nsCSSFrameConstructor::InsertionKind::Sync);
|
2017-03-03 09:51:39 +03:00
|
|
|
} else {
|
2017-09-07 14:39:20 +03:00
|
|
|
frameConstructor->ContentRangeInserted(
|
2017-09-07 18:02:20 +03:00
|
|
|
start, end, nullptr, nsCSSFrameConstructor::InsertionKind::Sync);
|
2017-03-03 09:51:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (size_t j = lazyRangeStart; j < i; ++j) {
|
2017-06-07 08:27:17 +03:00
|
|
|
MOZ_ASSERT(!aChangeList[j].mContent->GetPrimaryFrame() ||
|
|
|
|
!aChangeList[j].mContent->HasFlag(NODE_NEEDS_FRAME));
|
2017-03-03 09:51:39 +03:00
|
|
|
}
|
|
|
|
if (i == aChangeList.Length()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-09-28 10:03:00 +03:00
|
|
|
const nsStyleChangeData& data = aChangeList[i];
|
2016-08-17 03:15:29 +03:00
|
|
|
nsIFrame* frame = data.mFrame;
|
|
|
|
nsIContent* content = data.mContent;
|
|
|
|
nsChangeHint hint = data.mHint;
|
2016-08-01 23:31:57 +03:00
|
|
|
bool didReflowThisFrame = false;
|
|
|
|
|
|
|
|
NS_ASSERTION(!(hint & nsChangeHint_AllReflowHints) ||
|
|
|
|
(hint & nsChangeHint_NeedReflow),
|
|
|
|
"Reflow hint bits set without actually asking for a reflow");
|
|
|
|
|
|
|
|
// skip any frame that has been destroyed due to a ripple effect
|
2017-05-27 14:36:00 +03:00
|
|
|
if (frame && mDestroyedFrames->Contains(frame)) {
|
2016-08-01 23:31:57 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame && frame->GetContent() != content) {
|
|
|
|
// XXXbz this is due to image maps messing with the primary frame of
|
|
|
|
// <area>s. See bug 135040. Remove this block once that's fixed.
|
|
|
|
frame = nullptr;
|
|
|
|
if (!(hint & nsChangeHint_ReconstructFrame)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hint & nsChangeHint_UpdateContainingBlock) && frame &&
|
|
|
|
!(hint & nsChangeHint_ReconstructFrame)) {
|
2019-01-18 00:00:34 +03:00
|
|
|
if (NeedToReframeToUpdateContainingBlock(frame) ||
|
2017-04-30 18:30:08 +03:00
|
|
|
frame->IsFieldSetFrame() ||
|
2016-08-01 23:31:57 +03:00
|
|
|
frame->GetContentInsertionFrame() != frame) {
|
|
|
|
// The frame has positioned children that need to be reparented, or
|
2018-04-02 06:30:51 +03:00
|
|
|
// it can't easily be converted to/from being an abs-pos container
|
|
|
|
// correctly.
|
2016-08-01 23:31:57 +03:00
|
|
|
hint |= nsChangeHint_ReconstructFrame;
|
|
|
|
} else {
|
|
|
|
for (nsIFrame* cont = frame; cont;
|
|
|
|
cont = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(cont)) {
|
|
|
|
// Normally frame construction would set state bits as needed,
|
|
|
|
// but we're not going to reconstruct the frame so we need to set
|
|
|
|
// them. It's because we need to set this state on each affected frame
|
|
|
|
// that we can't coalesce nsChangeHint_UpdateContainingBlock hints up
|
2016-09-30 00:15:32 +03:00
|
|
|
// to ancestors (i.e. it can't be an change hint that is handled for
|
|
|
|
// descendants).
|
2016-08-13 04:39:45 +03:00
|
|
|
if (cont->IsAbsPosContainingBlock()) {
|
2016-08-01 23:31:57 +03:00
|
|
|
if (!cont->IsAbsoluteContainer() &&
|
|
|
|
(cont->GetStateBits() & NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN)) {
|
|
|
|
cont->MarkAsAbsoluteContainingBlock();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (cont->IsAbsoluteContainer()) {
|
2016-10-04 21:39:36 +03:00
|
|
|
if (cont->HasAbsolutelyPositionedChildren()) {
|
|
|
|
// If |cont| still has absolutely positioned children,
|
|
|
|
// we can't call MarkAsNotAbsoluteContainingBlock. This
|
|
|
|
// will remove a frame list that still has children in
|
|
|
|
// it that we need to keep track of.
|
|
|
|
// The optimization of removing it isn't particularly
|
|
|
|
// important, although it does mean we skip some tests.
|
|
|
|
NS_WARNING("skipping removal of absolute containing block");
|
|
|
|
} else {
|
|
|
|
cont->MarkAsNotAbsoluteContainingBlock();
|
|
|
|
}
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-30 00:15:32 +03:00
|
|
|
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
// Transforms are applied to the primary frame only but transform-related
|
|
|
|
// change hints (e.g. those due to animation) are generally only applied to
|
|
|
|
// the style frame. As a result, we need to look up the primary frame so we
|
|
|
|
// can apply the appropriate frame bits there.
|
|
|
|
nsIFrame* primaryFrame = content ? content->GetPrimaryFrame() : nullptr;
|
|
|
|
|
|
|
|
if (primaryFrame && (hint & nsChangeHint_AddOrRemoveTransform) &&
|
2016-09-30 00:15:32 +03:00
|
|
|
!(hint & nsChangeHint_ReconstructFrame)) {
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
for (nsIFrame* cont = primaryFrame; cont;
|
2016-09-30 00:15:32 +03:00
|
|
|
cont = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(cont)) {
|
|
|
|
if (cont->StyleDisplay()->HasTransform(cont)) {
|
|
|
|
cont->AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
|
|
|
|
}
|
|
|
|
// Don't remove NS_FRAME_MAY_BE_TRANSFORMED since it may still be
|
|
|
|
// transformed by other means. It's OK to have the bit even if it's
|
|
|
|
// not needed.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 23:31:57 +03:00
|
|
|
if (hint & nsChangeHint_ReconstructFrame) {
|
2018-11-28 00:39:53 +03:00
|
|
|
// Record whether this frame was absolutely positioned before and after
|
|
|
|
// frame construction, to detect changes for scroll anchor adjustment
|
|
|
|
// suppression.
|
|
|
|
bool wasAbsPosStyle = false;
|
|
|
|
ScrollAnchorContainer* previousAnchorContainer = nullptr;
|
|
|
|
AutoWeakFrame previousAnchorContainerFrame;
|
|
|
|
if (frame) {
|
|
|
|
wasAbsPosStyle = frame->StyleDisplay()->IsAbsolutelyPositionedStyle();
|
|
|
|
previousAnchorContainer = ScrollAnchorContainer::FindFor(frame);
|
|
|
|
|
|
|
|
// It's possible for the scroll anchor container to be destroyed by
|
|
|
|
// frame construction, so use a weak frame to detect this.
|
|
|
|
if (previousAnchorContainer) {
|
|
|
|
previousAnchorContainerFrame = previousAnchorContainer->Frame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 23:31:57 +03:00
|
|
|
// If we ever start passing true here, be careful of restyles
|
|
|
|
// that involve a reframe and animations. In particular, if the
|
|
|
|
// restyle we're processing here is an animation restyle, but
|
|
|
|
// the style resolution we will do for the frame construction
|
|
|
|
// happens async when we're not in an animation restyle already,
|
|
|
|
// problems could arise.
|
|
|
|
// We could also have problems with triggering of CSS transitions
|
|
|
|
// on elements whose frames are reconstructed, since we depend on
|
|
|
|
// the reconstruction happening synchronously.
|
Bug 1389743: Only reconstruct frames synchronously from ContentRemoved when called from frame construction. r=mats
There's only one case of sync frame construction from ContentRemoved now, and
it's not on the element being removed, but on the whitespace siblings if needed,
and _only_ when they don't support lazy frame construction.
Basically, this switches all the RecreateFramesForContent calls to use
`aAsyncInsert` (which I changed to an enum class for readability), except when
we're already reframing.
Also, it switches ReframeTextIfNeeded to opt-in into lazy frame construction,
since it's used only when aFlags == CONTENT_REMOVED.
This allows to simplify the DestroyFramesFor API (which I'm happy to rename to
something more meaningful, since now it's something like
DestroyFramesForAndRecreateThemAsync), and do some other consistency cleanups.
A bunch of the ContentRemoved callsites were pretty random at passing
aAsyncInsert, and that was some kind of a mess. This patch ensures consistency,
and makes it impossible to do O(n^2) work when removing DOM nodes, which is
nice.
The underlying reason for this is explained in the description of bug 1377848,
and basically allows us to remove a bunch of Servo hacks on the longer term (a
few of them are going away already, yay!).
MozReview-Commit-ID: 2DrUTxGV8RX
--HG--
extra : rebase_source : f428d839a5482477dea22c0fea600d54f3e8799c
2017-08-23 10:58:57 +03:00
|
|
|
frameConstructor->RecreateFramesForContent(
|
Bug 1396018: Don't pass aFlags all the way through RecreateFramesForContent. r=bz
We currently use the aFlags argument of ContentRemoved for two purposes:
(1) To determine when a frame is being removed due to its element being removed
from the DOM, so we reframe its now-possibly-no-longer-suppressed
whitespace siblings as needed.
In other cases, our ContentRemoved call will be followed by a
ContentInserted call, which will end up doing AddTextItemIfNeeded() to
generate the relevant textframes if they're necessary.
Since we only need to tell apart the "DOM removal" and "anything else"
cases, we don't need to thread the aFlags argument through all the ways
ContentRemoved can call itself (on an ancestor).
All those cases should just be treated as "not DOM removal". In particular,
even if the original call _was_ for a DOM removal, if we convert it to an
ancestor reframe, which will call ContentInserted on the ancestor as well,
we don't need to do anything with text siblings of the ancestor.
(2) To save the frame tree state from DestroyFramesFor, but the frame tree
state is unconditionally captured on RecreateFramesForContent, so we only
need to care about it in the original ContentRemoved call.
Because of that, we can move that to the callsite, patch incoming for that.
MozReview-Commit-ID: Gy5IhUysBlz
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
2017-09-01 17:10:49 +03:00
|
|
|
content, nsCSSFrameConstructor::InsertionKind::Sync);
|
2018-11-28 00:39:53 +03:00
|
|
|
frame = content->GetPrimaryFrame();
|
|
|
|
|
|
|
|
// See the check above for absolutely positioned style.
|
|
|
|
bool isAbsPosStyle = false;
|
|
|
|
ScrollAnchorContainer* newAnchorContainer = nullptr;
|
|
|
|
if (frame) {
|
|
|
|
isAbsPosStyle = frame->StyleDisplay()->IsAbsolutelyPositionedStyle();
|
|
|
|
newAnchorContainer = ScrollAnchorContainer::FindFor(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this frame construction was due to a change in absolute
|
|
|
|
// positioning, then suppress scroll anchor adjustments in the scroll
|
|
|
|
// anchor container the frame was in, and the one it moved into.
|
|
|
|
//
|
|
|
|
// This isn't entirely accurate to the specification, which requires us
|
|
|
|
// to do this for all frames that change being absolutely positioned. It's
|
|
|
|
// possible for multiple style changes to cause frame reconstruction and
|
|
|
|
// coalesce, which could cause a suppression trigger to be missed. It's
|
|
|
|
// unclear whether this will be an issue as suppression triggers are just
|
|
|
|
// heuristics.
|
|
|
|
if (wasAbsPosStyle != isAbsPosStyle) {
|
|
|
|
if (previousAnchorContainerFrame) {
|
|
|
|
previousAnchorContainer->SuppressAdjustments();
|
|
|
|
}
|
|
|
|
if (newAnchorContainer) {
|
|
|
|
newAnchorContainer->SuppressAdjustments();
|
|
|
|
}
|
|
|
|
}
|
2016-08-01 23:31:57 +03:00
|
|
|
} else {
|
|
|
|
NS_ASSERTION(frame, "This shouldn't happen");
|
|
|
|
|
|
|
|
if (!frame->FrameMaintainsOverflow()) {
|
|
|
|
// frame does not maintain overflow rects, so avoid calling
|
|
|
|
// FinishAndStoreOverflow on it:
|
|
|
|
hint &=
|
|
|
|
~(nsChangeHint_UpdateOverflow | nsChangeHint_ChildrenOnlyTransform |
|
|
|
|
nsChangeHint_UpdatePostTransformOverflow |
|
2019-03-09 19:01:31 +03:00
|
|
|
nsChangeHint_UpdateParentOverflow |
|
|
|
|
nsChangeHint_UpdateSubtreeOverflow);
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
if (primaryFrame &&
|
|
|
|
!(primaryFrame->GetStateBits() & NS_FRAME_MAY_BE_TRANSFORMED)) {
|
2016-08-01 23:31:57 +03:00
|
|
|
// Frame can not be transformed, and thus a change in transform will
|
|
|
|
// have no effect and we should not use the
|
|
|
|
// nsChangeHint_UpdatePostTransformOverflow hint.
|
|
|
|
hint &= ~nsChangeHint_UpdatePostTransformOverflow;
|
|
|
|
}
|
|
|
|
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
if ((hint & nsChangeHint_UpdateTransformLayer) && primaryFrame &&
|
|
|
|
!(primaryFrame->GetStateBits() & NS_FRAME_MAY_BE_TRANSFORMED) &&
|
|
|
|
primaryFrame->HasAnimationOfTransform()) {
|
Bug 1524480 - Set NS_FRAME_MAY_BE_TRANSFORMED bit when we have nsChangeHint_UpdateTransformLayer; r=hiro
Typically we set the NS_FRAME_MAY_BE_TRANSFORMED bit on a frame when one of the
following situations arises:
a. We update the keyframes of a KeyframeEffect to include transforms or we
create a new KeyframeEffect that animates transforms (in
KeyframeEffect::SetKeyframes), or
b. We retarget a KeyframeEffect with transforms at a new element (in
KeyframeEffect::SetTarget), or
c. We create an nsFrame with transform animations applied to it (in
nsFrame::Init), or
d. We get a nsChangeHint_AddOrRemoveTransform hint in
RestyleManager::ProcessRestyledFrames and decide to update the frame bit on
the frame and its continuations accordingly.
However, there are some situations where we can have a transform animation on
a frame where none of the above are triggered.
For example, if the style frame is not unavailable (e.g. a display:none
element) when the KeyframeEffect is initialized we will fail to the frame bit in
(a) and if we never retarget the effect we will never set reach (b).
Furthermore, if we have an animation that is "not relevant" (e.g. idle) and
hence not registered with the EffectSet when the frame is initialized we will
fail to set the frame bit in (c).
Finally, if the the animation does not produce a style change that causes the
nsChangeHint_AddOrRemoveTransform bit to be set (e.g. the transform animation
begins at 'none') we will not set the frame bit in (d).
As a result, we can end up failing to set the NS_FRAME_MAY_BE_TRANSFORMED bit
for some content.
The crashtest included in this patch produces such a case and, without the code
changes in this patch, will fail the assertion in ApplyRenderingChangeToTree[1]:
NS_ASSERTION(!(aChange & nsChangeHint_UpdateTransformLayer) ||
aFrame->IsTransformed() ||
aFrame->StyleDisplay()->HasTransformStyle(),
"Unexpected UpdateTransformLayer hint");
That is because although the nsChangeHint_UpdateTransformLayer bit will be set,
aFrame->IsTransformed() will return false because the frame bit has not been
set, and aFrame->StyleDisplay()->HasTransformStyle() will return false because
the animation sets the transform to 'none'.
Not only will this assertion fail, but once we cease flushing style as part of
triggering an animation later in this patch, the reftest
layout/reftests/web-animations/stacking-context-transform-changing-effect.html
will begin to fail. That reftest produces a similar situation to the crashtest
but it currently does not fail because the style flush that happens as part of
creating an animation ensures the style frame is available at the point when the
animation is triggered and hence case (a) from above is hit.
This patch addresses this by detecting the case where we have this change hint
set but not the corresponding frame bit, and setting the frame bit.
[1] https://searchfox.org/mozilla-central/rev/9eb30227b21e0aa40d51d9f9b08bb0b113c5fadb/layout/base/RestyleManager.cpp#1191-1199
Differential Revision: https://phabricator.services.mozilla.com/D18911
--HG--
extra : moz-landing-system : lando
2019-02-15 09:35:55 +03:00
|
|
|
// If we have an nsChangeHint_UpdateTransformLayer hint but no
|
2019-03-05 06:09:48 +03:00
|
|
|
// corresponding frame bit, we most likely have a transform animation
|
|
|
|
// that was added or updated after this frame was created (otherwise
|
|
|
|
// we would have set the frame bit when we initialized the frame)
|
|
|
|
// and which sets the transform to 'none' (otherwise we would have set
|
|
|
|
// the frame bit when we got the nsChangeHint_AddOrRemoveTransform
|
|
|
|
// hint).
|
Bug 1524480 - Set NS_FRAME_MAY_BE_TRANSFORMED bit when we have nsChangeHint_UpdateTransformLayer; r=hiro
Typically we set the NS_FRAME_MAY_BE_TRANSFORMED bit on a frame when one of the
following situations arises:
a. We update the keyframes of a KeyframeEffect to include transforms or we
create a new KeyframeEffect that animates transforms (in
KeyframeEffect::SetKeyframes), or
b. We retarget a KeyframeEffect with transforms at a new element (in
KeyframeEffect::SetTarget), or
c. We create an nsFrame with transform animations applied to it (in
nsFrame::Init), or
d. We get a nsChangeHint_AddOrRemoveTransform hint in
RestyleManager::ProcessRestyledFrames and decide to update the frame bit on
the frame and its continuations accordingly.
However, there are some situations where we can have a transform animation on
a frame where none of the above are triggered.
For example, if the style frame is not unavailable (e.g. a display:none
element) when the KeyframeEffect is initialized we will fail to the frame bit in
(a) and if we never retarget the effect we will never set reach (b).
Furthermore, if we have an animation that is "not relevant" (e.g. idle) and
hence not registered with the EffectSet when the frame is initialized we will
fail to set the frame bit in (c).
Finally, if the the animation does not produce a style change that causes the
nsChangeHint_AddOrRemoveTransform bit to be set (e.g. the transform animation
begins at 'none') we will not set the frame bit in (d).
As a result, we can end up failing to set the NS_FRAME_MAY_BE_TRANSFORMED bit
for some content.
The crashtest included in this patch produces such a case and, without the code
changes in this patch, will fail the assertion in ApplyRenderingChangeToTree[1]:
NS_ASSERTION(!(aChange & nsChangeHint_UpdateTransformLayer) ||
aFrame->IsTransformed() ||
aFrame->StyleDisplay()->HasTransformStyle(),
"Unexpected UpdateTransformLayer hint");
That is because although the nsChangeHint_UpdateTransformLayer bit will be set,
aFrame->IsTransformed() will return false because the frame bit has not been
set, and aFrame->StyleDisplay()->HasTransformStyle() will return false because
the animation sets the transform to 'none'.
Not only will this assertion fail, but once we cease flushing style as part of
triggering an animation later in this patch, the reftest
layout/reftests/web-animations/stacking-context-transform-changing-effect.html
will begin to fail. That reftest produces a similar situation to the crashtest
but it currently does not fail because the style flush that happens as part of
creating an animation ensures the style frame is available at the point when the
animation is triggered and hence case (a) from above is hit.
This patch addresses this by detecting the case where we have this change hint
set but not the corresponding frame bit, and setting the frame bit.
[1] https://searchfox.org/mozilla-central/rev/9eb30227b21e0aa40d51d9f9b08bb0b113c5fadb/layout/base/RestyleManager.cpp#1191-1199
Differential Revision: https://phabricator.services.mozilla.com/D18911
--HG--
extra : moz-landing-system : lando
2019-02-15 09:35:55 +03:00
|
|
|
//
|
|
|
|
// In that case we should set the frame bit.
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
for (nsIFrame* cont = primaryFrame; cont;
|
Bug 1524480 - Set NS_FRAME_MAY_BE_TRANSFORMED bit when we have nsChangeHint_UpdateTransformLayer; r=hiro
Typically we set the NS_FRAME_MAY_BE_TRANSFORMED bit on a frame when one of the
following situations arises:
a. We update the keyframes of a KeyframeEffect to include transforms or we
create a new KeyframeEffect that animates transforms (in
KeyframeEffect::SetKeyframes), or
b. We retarget a KeyframeEffect with transforms at a new element (in
KeyframeEffect::SetTarget), or
c. We create an nsFrame with transform animations applied to it (in
nsFrame::Init), or
d. We get a nsChangeHint_AddOrRemoveTransform hint in
RestyleManager::ProcessRestyledFrames and decide to update the frame bit on
the frame and its continuations accordingly.
However, there are some situations where we can have a transform animation on
a frame where none of the above are triggered.
For example, if the style frame is not unavailable (e.g. a display:none
element) when the KeyframeEffect is initialized we will fail to the frame bit in
(a) and if we never retarget the effect we will never set reach (b).
Furthermore, if we have an animation that is "not relevant" (e.g. idle) and
hence not registered with the EffectSet when the frame is initialized we will
fail to set the frame bit in (c).
Finally, if the the animation does not produce a style change that causes the
nsChangeHint_AddOrRemoveTransform bit to be set (e.g. the transform animation
begins at 'none') we will not set the frame bit in (d).
As a result, we can end up failing to set the NS_FRAME_MAY_BE_TRANSFORMED bit
for some content.
The crashtest included in this patch produces such a case and, without the code
changes in this patch, will fail the assertion in ApplyRenderingChangeToTree[1]:
NS_ASSERTION(!(aChange & nsChangeHint_UpdateTransformLayer) ||
aFrame->IsTransformed() ||
aFrame->StyleDisplay()->HasTransformStyle(),
"Unexpected UpdateTransformLayer hint");
That is because although the nsChangeHint_UpdateTransformLayer bit will be set,
aFrame->IsTransformed() will return false because the frame bit has not been
set, and aFrame->StyleDisplay()->HasTransformStyle() will return false because
the animation sets the transform to 'none'.
Not only will this assertion fail, but once we cease flushing style as part of
triggering an animation later in this patch, the reftest
layout/reftests/web-animations/stacking-context-transform-changing-effect.html
will begin to fail. That reftest produces a similar situation to the crashtest
but it currently does not fail because the style flush that happens as part of
creating an animation ensures the style frame is available at the point when the
animation is triggered and hence case (a) from above is hit.
This patch addresses this by detecting the case where we have this change hint
set but not the corresponding frame bit, and setting the frame bit.
[1] https://searchfox.org/mozilla-central/rev/9eb30227b21e0aa40d51d9f9b08bb0b113c5fadb/layout/base/RestyleManager.cpp#1191-1199
Differential Revision: https://phabricator.services.mozilla.com/D18911
--HG--
extra : moz-landing-system : lando
2019-02-15 09:35:55 +03:00
|
|
|
cont = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(cont)) {
|
|
|
|
cont->AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 06:05:47 +03:00
|
|
|
if (hint & nsChangeHint_AddOrRemoveTransform) {
|
|
|
|
// When dropping a running transform animation we will first add an
|
|
|
|
// nsChangeHint_UpdateTransformLayer hint as part of the animation-only
|
|
|
|
// restyle. During the subsequent regular restyle, if the animation was
|
|
|
|
// the only reason the element had any transform applied, we will add
|
|
|
|
// nsChangeHint_AddOrRemoveTransform as part of the regular restyle.
|
|
|
|
//
|
|
|
|
// With the Gecko backend, these two change hints are processed
|
|
|
|
// after each restyle but when using the Servo backend they accumulate
|
|
|
|
// and are processed together after we have already removed the
|
|
|
|
// transform as part of the regular restyle. Since we don't actually
|
|
|
|
// need the nsChangeHint_UpdateTransformLayer hint if we already have
|
|
|
|
// a nsChangeHint_AddOrRemoveTransform hint, and since we
|
|
|
|
// will fail an assertion in ApplyRenderingChangeToTree if we try
|
|
|
|
// specify nsChangeHint_UpdateTransformLayer but don't have any
|
|
|
|
// transform style, we just drop the unneeded hint here.
|
|
|
|
hint &= ~nsChangeHint_UpdateTransformLayer;
|
|
|
|
}
|
|
|
|
|
2018-09-19 13:30:03 +03:00
|
|
|
if ((hint & nsChangeHint_UpdateEffects) &&
|
|
|
|
frame == nsLayoutUtils::FirstContinuationOrIBSplitSibling(frame)) {
|
|
|
|
SVGObserverUtils::UpdateEffects(frame);
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
if ((hint & nsChangeHint_InvalidateRenderingObservers) ||
|
|
|
|
((hint & nsChangeHint_UpdateOpacityLayer) &&
|
|
|
|
frame->IsFrameOfType(nsIFrame::eSVG) &&
|
|
|
|
!(frame->GetStateBits() & NS_STATE_IS_OUTER_SVG))) {
|
2017-08-30 17:58:31 +03:00
|
|
|
SVGObserverUtils::InvalidateRenderingObservers(frame);
|
2017-09-29 00:51:49 +03:00
|
|
|
frame->SchedulePaint();
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
if (hint & nsChangeHint_NeedReflow) {
|
|
|
|
StyleChangeReflow(frame, hint);
|
|
|
|
didReflowThisFrame = true;
|
|
|
|
}
|
|
|
|
|
2017-09-21 02:58:21 +03:00
|
|
|
// Here we need to propagate repaint frame change hint instead of update
|
|
|
|
// opacity layer change hint when we do opacity optimization for SVG.
|
|
|
|
// We can't do it in nsStyleEffects::CalcDifference() just like we do
|
|
|
|
// for the optimization for 0.99 over opacity values since we have no way
|
|
|
|
// to call nsSVGUtils::CanOptimizeOpacity() there.
|
|
|
|
if ((hint & nsChangeHint_UpdateOpacityLayer) &&
|
|
|
|
nsSVGUtils::CanOptimizeOpacity(frame) &&
|
|
|
|
frame->IsFrameOfType(nsIFrame::eSVGGeometry)) {
|
|
|
|
hint &= ~nsChangeHint_UpdateOpacityLayer;
|
|
|
|
hint |= nsChangeHint_RepaintFrame;
|
|
|
|
}
|
|
|
|
|
2016-08-01 23:31:57 +03:00
|
|
|
if ((hint & nsChangeHint_UpdateUsesOpacity) &&
|
|
|
|
frame->IsFrameOfType(nsIFrame::eTablePart)) {
|
|
|
|
NS_ASSERTION(hint & nsChangeHint_UpdateOpacityLayer,
|
|
|
|
"should only return UpdateUsesOpacity hint "
|
|
|
|
"when also returning UpdateOpacityLayer hint");
|
|
|
|
// When an internal table part (including cells) changes between
|
|
|
|
// having opacity 1 and non-1, it changes whether its
|
|
|
|
// backgrounds (and those of table parts inside of it) are
|
|
|
|
// painted as part of the table's nsDisplayTableBorderBackground
|
|
|
|
// display item, or part of its own display item. That requires
|
|
|
|
// invalidation, so change UpdateOpacityLayer to RepaintFrame.
|
|
|
|
hint &= ~nsChangeHint_UpdateOpacityLayer;
|
|
|
|
hint |= nsChangeHint_RepaintFrame;
|
|
|
|
}
|
|
|
|
|
2017-02-13 03:09:17 +03:00
|
|
|
// Opacity disables preserve-3d, so if we toggle it, then we also need
|
|
|
|
// to update the overflow areas of all potentially affected frames.
|
|
|
|
if ((hint & nsChangeHint_UpdateUsesOpacity) &&
|
|
|
|
frame->StyleDisplay()->mTransformStyle ==
|
|
|
|
NS_STYLE_TRANSFORM_STYLE_PRESERVE_3D) {
|
|
|
|
hint |= nsChangeHint_UpdateSubtreeOverflow;
|
|
|
|
}
|
|
|
|
|
2016-08-01 23:31:57 +03:00
|
|
|
if (hint & nsChangeHint_UpdateBackgroundPosition) {
|
|
|
|
// For most frame types, DLBI can detect background position changes,
|
|
|
|
// so we only need to schedule a paint.
|
|
|
|
hint |= nsChangeHint_SchedulePaint;
|
|
|
|
if (frame->IsFrameOfType(nsIFrame::eTablePart) ||
|
|
|
|
frame->IsFrameOfType(nsIFrame::eMathML)) {
|
|
|
|
// Table parts and MathML frames don't build display items for their
|
|
|
|
// backgrounds, so DLBI can't detect background-position changes for
|
|
|
|
// these frames. Repaint the whole frame.
|
|
|
|
hint |= nsChangeHint_RepaintFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hint &
|
|
|
|
(nsChangeHint_RepaintFrame | nsChangeHint_SyncFrameView |
|
|
|
|
nsChangeHint_UpdateOpacityLayer | nsChangeHint_UpdateTransformLayer |
|
|
|
|
nsChangeHint_ChildrenOnlyTransform | nsChangeHint_SchedulePaint)) {
|
2016-08-03 01:47:19 +03:00
|
|
|
ApplyRenderingChangeToTree(presContext->PresShell(), frame, hint);
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
if ((hint & nsChangeHint_RecomputePosition) && !didReflowThisFrame) {
|
|
|
|
ActiveLayerTracker::NotifyOffsetRestyle(frame);
|
|
|
|
// It is possible for this to fall back to a reflow
|
|
|
|
if (!RecomputePosition(frame)) {
|
|
|
|
didReflowThisFrame = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(!(hint & nsChangeHint_ChildrenOnlyTransform) ||
|
|
|
|
(hint & nsChangeHint_UpdateOverflow),
|
|
|
|
"nsChangeHint_UpdateOverflow should be passed too");
|
|
|
|
if (!didReflowThisFrame &&
|
|
|
|
(hint & (nsChangeHint_UpdateOverflow |
|
|
|
|
nsChangeHint_UpdatePostTransformOverflow |
|
|
|
|
nsChangeHint_UpdateParentOverflow |
|
|
|
|
nsChangeHint_UpdateSubtreeOverflow))) {
|
|
|
|
if (hint & nsChangeHint_UpdateSubtreeOverflow) {
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
for (nsIFrame* cont = primaryFrame; cont;
|
2016-08-01 23:31:57 +03:00
|
|
|
cont =
|
|
|
|
nsLayoutUtils::GetNextContinuationOrIBSplitSibling(cont)) {
|
2016-08-03 01:47:19 +03:00
|
|
|
AddSubtreeToOverflowTracker(cont, mOverflowChangedTracker);
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
// The work we just did in AddSubtreeToOverflowTracker
|
|
|
|
// subsumes some of the other hints:
|
|
|
|
hint &= ~(nsChangeHint_UpdateOverflow |
|
|
|
|
nsChangeHint_UpdatePostTransformOverflow);
|
|
|
|
}
|
|
|
|
if (hint & nsChangeHint_ChildrenOnlyTransform) {
|
2018-11-23 18:58:27 +03:00
|
|
|
// We need to update overflows. The correct frame(s) to update depends
|
|
|
|
// on whether the ChangeHint came from an outer or an inner svg.
|
2016-08-01 23:31:57 +03:00
|
|
|
nsIFrame* hintFrame = GetFrameForChildrenOnlyTransformHint(frame);
|
|
|
|
NS_ASSERTION(
|
|
|
|
!nsLayoutUtils::GetNextContinuationOrIBSplitSibling(frame),
|
|
|
|
"SVG frames should not have continuations "
|
|
|
|
"or ib-split siblings");
|
|
|
|
NS_ASSERTION(
|
|
|
|
!nsLayoutUtils::GetNextContinuationOrIBSplitSibling(hintFrame),
|
|
|
|
"SVG frames should not have continuations "
|
|
|
|
"or ib-split siblings");
|
2018-11-23 18:58:27 +03:00
|
|
|
if (hintFrame->IsSVGOuterSVGAnonChildFrame()) {
|
|
|
|
// The children only transform of an outer svg frame is applied to
|
|
|
|
// the outer svg's anonymous child frame (instead of to the
|
|
|
|
// anonymous child's children).
|
|
|
|
|
|
|
|
// If |hintFrame| is dirty or has dirty children, we don't bother
|
2016-08-01 23:31:57 +03:00
|
|
|
// updating overflows since that will happen when it's reflowed.
|
2018-11-23 18:58:27 +03:00
|
|
|
if (!(hintFrame->GetStateBits() &
|
2016-08-01 23:31:57 +03:00
|
|
|
(NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN))) {
|
2018-11-23 18:58:27 +03:00
|
|
|
mOverflowChangedTracker.AddFrame(
|
|
|
|
hintFrame, OverflowChangedTracker::CHILDREN_CHANGED);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The children only transform is applied to the child frames of an
|
|
|
|
// inner svg frame, so update the child overflows.
|
|
|
|
nsIFrame* childFrame = hintFrame->PrincipalChildList().FirstChild();
|
|
|
|
for (; childFrame; childFrame = childFrame->GetNextSibling()) {
|
|
|
|
MOZ_ASSERT(childFrame->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"Not expecting non-SVG children");
|
|
|
|
// If |childFrame| is dirty or has dirty children, we don't bother
|
|
|
|
// updating overflows since that will happen when it's reflowed.
|
|
|
|
if (!(childFrame->GetStateBits() &
|
|
|
|
(NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN))) {
|
|
|
|
mOverflowChangedTracker.AddFrame(
|
|
|
|
childFrame, OverflowChangedTracker::CHILDREN_CHANGED);
|
|
|
|
}
|
|
|
|
NS_ASSERTION(!nsLayoutUtils::GetNextContinuationOrIBSplitSibling(
|
|
|
|
childFrame),
|
|
|
|
"SVG frames should not have continuations "
|
|
|
|
"or ib-split siblings");
|
|
|
|
NS_ASSERTION(
|
|
|
|
childFrame->GetParent() == hintFrame,
|
|
|
|
"SVG child frame not expected to have different parent");
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If |frame| is dirty or has dirty children, we don't bother updating
|
|
|
|
// overflows since that will happen when it's reflowed.
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
if (primaryFrame &&
|
|
|
|
!(primaryFrame->GetStateBits() &
|
2016-08-01 23:31:57 +03:00
|
|
|
(NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN))) {
|
|
|
|
if (hint & (nsChangeHint_UpdateOverflow |
|
|
|
|
nsChangeHint_UpdatePostTransformOverflow)) {
|
|
|
|
OverflowChangedTracker::ChangeKind changeKind;
|
|
|
|
// If we have both nsChangeHint_UpdateOverflow and
|
|
|
|
// nsChangeHint_UpdatePostTransformOverflow,
|
|
|
|
// CHILDREN_CHANGED is selected as it is
|
|
|
|
// strictly stronger.
|
|
|
|
if (hint & nsChangeHint_UpdateOverflow) {
|
|
|
|
changeKind = OverflowChangedTracker::CHILDREN_CHANGED;
|
|
|
|
} else {
|
|
|
|
changeKind = OverflowChangedTracker::TRANSFORM_CHANGED;
|
|
|
|
}
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
for (nsIFrame* cont = primaryFrame; cont;
|
2016-08-01 23:31:57 +03:00
|
|
|
cont =
|
|
|
|
nsLayoutUtils::GetNextContinuationOrIBSplitSibling(cont)) {
|
2016-08-03 01:47:19 +03:00
|
|
|
mOverflowChangedTracker.AddFrame(cont, changeKind);
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// UpdateParentOverflow hints need to be processed in addition
|
|
|
|
// to the above, since if the processing of the above hints
|
|
|
|
// yields no change, the update will not propagate to the
|
|
|
|
// parent.
|
|
|
|
if (hint & nsChangeHint_UpdateParentOverflow) {
|
|
|
|
MOZ_ASSERT(frame->GetParent(),
|
|
|
|
"shouldn't get style hints for the root frame");
|
Bug 1527210 - Be more consistent about only applying transforms to primary frames; r=hiro
For display:table content we generate two frames: a table wrapper frame and an
inner table frame. The styles are applied to the inner frame (referred to as the
style frame), whilst the wrapper frame is the primary frame for the content.
However, in order to make tables with transforms behave as a container for
abspos/fixed-pos content as required by the spec, we apply the transform to the
wrapper frame (bug 722777) by inheriting the transform from inner to wrapper and
then ignoring the transform on the inner frame (bug 722777 and bug 816458).
When handling animations on table elements we need to be careful of this
distinction. in particular, css animations[1] and web animations[2] require that
when we have an unfinished transform animation targetting an element, the
element acts as if it had `will-change: transform` applied and therefore
generates a stacking context. As a result we need to accurately detect when
a frame should be considered as having transform animations applied to it or not
for the purpose of creating a stacking context.
Previously our handling of display:table content was quite inconsistent and
contradictory. For example, `nsIFrame::HasAnimationOfTransform` would check for
a primary frame AND for animations on that frame, despite the fact that we only
ever store animations on the style frame. As a result it could never return true
for either a table wrapper or inner table frame.
This patch attempts to make this handling at least a little more consistent,
producing the following result:
Outer table frame (primary frame):
nsIFrame::IsTransformed → true
nsIFrame::IsCSSTransformed → true
nsIFrame::HasAnimationOfTransform → true
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → false
Inner table frame (style frame):
nsIFrame::IsTransformed → false
nsIFrame::IsCSSTransformed → false
nsIFrame::HasAnimationOfTransform → false
nsLayoutUtils::HasAnimationOfProperty(frame, eCSSProperty_transform) → true
We maintain that the NS_FRAME_MAY_BE_TRANSFORMED bit is only set on the primary
frame whilst the mMayHaveTransformAnimation flag is only set on the style frame.
Note that we don't simply always put everything on the primary frame because for
other property types (e.g. opacity) the default setup of putting all styles and
animations on the style frame is simpler and correct. So far it is only
transforms that require special handling to apply the effect to the wrapper
frame.
This patch adds a reftest that fails without the code changes included in this
patch.
[1] https://drafts.csswg.org/css-animations/#animations
[2] https://drafts.csswg.org/web-animations-1/#side-effects-section
Differential Revision: https://phabricator.services.mozilla.com/D21883
--HG--
extra : moz-landing-system : lando
2019-03-05 06:09:19 +03:00
|
|
|
for (nsIFrame* cont = primaryFrame; cont;
|
2016-08-01 23:31:57 +03:00
|
|
|
cont =
|
|
|
|
nsLayoutUtils::GetNextContinuationOrIBSplitSibling(cont)) {
|
2016-08-03 01:47:19 +03:00
|
|
|
mOverflowChangedTracker.AddFrame(
|
2016-08-01 23:31:57 +03:00
|
|
|
cont->GetParent(), OverflowChangedTracker::CHILDREN_CHANGED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((hint & nsChangeHint_UpdateCursor) && !didUpdateCursor) {
|
2016-08-03 01:47:19 +03:00
|
|
|
presContext->PresShell()->SynthesizeMouseMove(false);
|
2016-08-01 23:31:57 +03:00
|
|
|
didUpdateCursor = true;
|
|
|
|
}
|
2017-06-19 04:04:40 +03:00
|
|
|
if (hint & nsChangeHint_UpdateWidgetProperties) {
|
|
|
|
frame->UpdateWidgetProperties();
|
|
|
|
}
|
2017-09-05 23:30:40 +03:00
|
|
|
if (hint & nsChangeHint_UpdateTableCellSpans) {
|
|
|
|
frameConstructor->UpdateTableCellSpans(content);
|
|
|
|
}
|
2018-02-09 04:43:10 +03:00
|
|
|
if (hint & nsChangeHint_VisibilityChange) {
|
|
|
|
frame->UpdateVisibleDescendantsState();
|
|
|
|
}
|
2016-08-01 23:31:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aChangeList.Clear();
|
|
|
|
}
|
2016-07-23 01:27:05 +03:00
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
uint64_t RestyleManager::GetAnimationGenerationForFrame(nsIFrame* aFrame) {
|
2017-03-09 12:15:08 +03:00
|
|
|
EffectSet* effectSet = EffectSet::GetEffectSet(aFrame);
|
|
|
|
return effectSet ? effectSet->GetAnimationGeneration() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::IncrementAnimationGeneration() {
|
|
|
|
// We update the animation generation at start of each call to
|
|
|
|
// ProcessPendingRestyles so we should ignore any subsequent (redundant)
|
|
|
|
// calls that occur while we are still processing restyles.
|
2018-03-23 19:01:34 +03:00
|
|
|
if (!mInStyleRefresh) {
|
|
|
|
++mAnimationGeneration;
|
2017-03-09 12:15:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void RestyleManager::AddLayerChangesForAnimation(
|
2019-03-07 08:40:51 +03:00
|
|
|
nsIFrame* aStyleFrame, nsIContent* aContent, nsChangeHint aHintForThisFrame,
|
2017-05-02 09:03:16 +03:00
|
|
|
nsStyleChangeList& aChangeListToProcess) {
|
2019-03-07 08:40:51 +03:00
|
|
|
if (!aStyleFrame || !aContent) {
|
2017-05-02 09:03:16 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t frameGeneration =
|
2019-03-07 08:40:51 +03:00
|
|
|
RestyleManager::GetAnimationGenerationForFrame(aStyleFrame);
|
2017-05-02 09:03:16 +03:00
|
|
|
|
2018-11-13 13:22:26 +03:00
|
|
|
Maybe<nsCSSPropertyIDSet> effectiveAnimationProperties;
|
|
|
|
|
2017-05-02 09:03:16 +03:00
|
|
|
nsChangeHint hint = nsChangeHint(0);
|
2018-11-13 13:23:20 +03:00
|
|
|
auto maybeApplyChangeHint = [&](const Maybe<uint64_t>& aGeneration,
|
|
|
|
DisplayItemType aDisplayItemType) -> bool {
|
|
|
|
if (aGeneration && frameGeneration != *aGeneration) {
|
2018-11-22 07:03:02 +03:00
|
|
|
// If we have a transform layer but don't have any transform style, we
|
2017-05-02 09:03:16 +03:00
|
|
|
// probably just removed the transform but haven't destroyed the layer
|
2018-07-30 05:13:54 +03:00
|
|
|
// yet. In this case we will typically add the appropriate change hint
|
|
|
|
// (nsChangeHint_UpdateContainingBlock) when we compare styles so in
|
|
|
|
// theory we could skip adding any change hint here.
|
|
|
|
//
|
|
|
|
// However, sometimes when we compare styles we'll get no change. For
|
|
|
|
// example, if the transform style was 'none' when we sent the transform
|
|
|
|
// animation to the compositor and the current transform style is now
|
|
|
|
// 'none' we'll think nothing changed but actually we still need to
|
|
|
|
// trigger an update to clear whatever style the transform animation set
|
|
|
|
// on the compositor. To handle this case we simply set all the change
|
|
|
|
// hints relevant to removing transform style (since we don't know exactly
|
|
|
|
// what changes happened while the animation was running on the
|
|
|
|
// compositor).
|
|
|
|
//
|
|
|
|
// Note that we *don't* add nsChangeHint_UpdateTransformLayer since if we
|
|
|
|
// did, ApplyRenderingChangeToTree would complain that we're updating a
|
|
|
|
// transform layer without a transform.
|
2018-11-13 13:23:20 +03:00
|
|
|
if (aDisplayItemType == DisplayItemType::TYPE_TRANSFORM &&
|
2019-03-07 08:40:51 +03:00
|
|
|
!aStyleFrame->StyleDisplay()->HasTransformStyle()) {
|
2018-07-30 05:13:54 +03:00
|
|
|
// Add all the hints for a removing a transform if they are not already
|
|
|
|
// set for this frame.
|
|
|
|
if (!(NS_IsHintSubset(nsChangeHint_ComprehensiveAddOrRemoveTransform,
|
|
|
|
aHintForThisFrame))) {
|
|
|
|
hint |= nsChangeHint_ComprehensiveAddOrRemoveTransform;
|
|
|
|
}
|
2018-11-13 13:23:20 +03:00
|
|
|
return true;
|
2017-05-02 09:03:16 +03:00
|
|
|
}
|
2018-11-13 13:23:20 +03:00
|
|
|
hint |= LayerAnimationInfo::GetChangeHintFor(aDisplayItemType);
|
2017-05-02 09:03:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// We consider it's the first paint for the frame if we have an animation
|
2018-07-30 05:20:53 +03:00
|
|
|
// for the property but have no layer, for the case of WebRender, no
|
|
|
|
// corresponding animation info.
|
2017-05-02 09:03:16 +03:00
|
|
|
// Note that in case of animations which has properties preventing running
|
|
|
|
// on the compositor, e.g., width or height, corresponding layer is not
|
|
|
|
// created at all, but even in such cases, we normally set valid change
|
|
|
|
// hint for such animations in each tick, i.e. restyles in each tick. As
|
|
|
|
// a result, we usually do restyles for such animations in every tick on
|
|
|
|
// the main-thread. The only animations which will be affected by this
|
|
|
|
// explicit change hint are animations that have opacity/transform but did
|
|
|
|
// not have those properies just before. e.g, setting transform by
|
|
|
|
// setKeyframes or changing target element from other target which prevents
|
|
|
|
// running on the compositor, etc.
|
2018-11-14 14:47:10 +03:00
|
|
|
if (!aGeneration) {
|
2018-11-22 07:03:02 +03:00
|
|
|
nsChangeHint hintForDisplayItem =
|
|
|
|
LayerAnimationInfo::GetChangeHintFor(aDisplayItemType);
|
|
|
|
// We don't need to apply the corresponding change hint if we already have
|
|
|
|
// it.
|
|
|
|
if (NS_IsHintSubset(hintForDisplayItem, aHintForThisFrame)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-13 13:22:26 +03:00
|
|
|
if (!effectiveAnimationProperties) {
|
|
|
|
effectiveAnimationProperties.emplace(
|
2019-03-07 08:40:51 +03:00
|
|
|
nsLayoutUtils::GetAnimationPropertiesForCompositor(aStyleFrame));
|
2018-11-13 13:22:26 +03:00
|
|
|
}
|
|
|
|
const nsCSSPropertyIDSet& propertiesForDisplayItem =
|
2018-11-13 13:23:20 +03:00
|
|
|
LayerAnimationInfo::GetCSSPropertiesFor(aDisplayItemType);
|
2018-11-13 13:22:26 +03:00
|
|
|
if (effectiveAnimationProperties->Intersects(propertiesForDisplayItem)) {
|
2018-11-22 07:03:02 +03:00
|
|
|
hint |= hintForDisplayItem;
|
2018-11-13 13:22:26 +03:00
|
|
|
}
|
2017-05-02 09:03:16 +03:00
|
|
|
}
|
2018-11-13 13:23:20 +03:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
AnimationInfo::EnumerateGenerationOnFrame(
|
2019-03-07 08:40:51 +03:00
|
|
|
aStyleFrame, aContent, LayerAnimationInfo::sDisplayItemTypes,
|
2018-11-13 13:23:20 +03:00
|
|
|
maybeApplyChangeHint);
|
2017-05-02 09:03:16 +03:00
|
|
|
|
|
|
|
if (hint) {
|
2019-03-07 08:40:51 +03:00
|
|
|
aChangeListToProcess.AppendChange(aStyleFrame, aContent, hint);
|
2017-05-02 09:03:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 06:21:32 +03:00
|
|
|
RestyleManager::AnimationsWithDestroyedFrame::AnimationsWithDestroyedFrame(
|
|
|
|
RestyleManager* aRestyleManager)
|
2017-01-26 12:05:53 +03:00
|
|
|
: mRestyleManager(aRestyleManager),
|
|
|
|
mRestorePointer(mRestyleManager->mAnimationsWithDestroyedFrame) {
|
|
|
|
MOZ_ASSERT(!mRestyleManager->mAnimationsWithDestroyedFrame,
|
|
|
|
"shouldn't construct recursively");
|
|
|
|
mRestyleManager->mAnimationsWithDestroyedFrame = this;
|
|
|
|
}
|
|
|
|
|
2017-02-13 06:21:32 +03:00
|
|
|
void RestyleManager::AnimationsWithDestroyedFrame ::
|
|
|
|
StopAnimationsForElementsWithoutFrames() {
|
2019-02-19 16:44:33 +03:00
|
|
|
StopAnimationsWithoutFrame(mContents, PseudoStyleType::NotPseudo);
|
|
|
|
StopAnimationsWithoutFrame(mBeforeContents, PseudoStyleType::before);
|
|
|
|
StopAnimationsWithoutFrame(mAfterContents, PseudoStyleType::after);
|
2017-01-26 12:05:53 +03:00
|
|
|
}
|
|
|
|
|
2017-02-13 06:21:32 +03:00
|
|
|
void RestyleManager::AnimationsWithDestroyedFrame ::StopAnimationsWithoutFrame(
|
2019-02-19 16:44:33 +03:00
|
|
|
nsTArray<RefPtr<nsIContent>>& aArray, PseudoStyleType aPseudoType) {
|
2017-01-26 12:05:53 +03:00
|
|
|
nsAnimationManager* animationManager =
|
|
|
|
mRestyleManager->PresContext()->AnimationManager();
|
|
|
|
nsTransitionManager* transitionManager =
|
|
|
|
mRestyleManager->PresContext()->TransitionManager();
|
|
|
|
for (nsIContent* content : aArray) {
|
2019-02-19 16:44:33 +03:00
|
|
|
if (aPseudoType == PseudoStyleType::NotPseudo) {
|
2017-07-24 03:20:22 +03:00
|
|
|
if (content->GetPrimaryFrame()) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-02-19 16:44:33 +03:00
|
|
|
} else if (aPseudoType == PseudoStyleType::before) {
|
2017-07-24 03:20:22 +03:00
|
|
|
if (nsLayoutUtils::GetBeforeFrame(content)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-02-19 16:44:33 +03:00
|
|
|
} else if (aPseudoType == PseudoStyleType::after) {
|
2017-07-24 03:20:22 +03:00
|
|
|
if (nsLayoutUtils::GetAfterFrame(content)) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-01-26 12:05:53 +03:00
|
|
|
}
|
|
|
|
dom::Element* element = content->AsElement();
|
|
|
|
|
|
|
|
animationManager->StopAnimationsForElement(element, aPseudoType);
|
2017-03-06 07:19:09 +03:00
|
|
|
transitionManager->StopAnimationsForElement(element, aPseudoType);
|
2017-01-26 12:05:53 +03:00
|
|
|
|
|
|
|
// All other animations should keep running but not running on the
|
|
|
|
// *compositor* at this point.
|
|
|
|
EffectSet* effectSet = EffectSet::GetEffectSet(element, aPseudoType);
|
|
|
|
if (effectSet) {
|
2018-05-07 05:08:59 +03:00
|
|
|
for (KeyframeEffect* effect : *effectSet) {
|
2017-01-26 12:05:53 +03:00
|
|
|
effect->ResetIsRunningOnCompositor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-07 16:48:43 +03:00
|
|
|
#ifdef DEBUG
|
2018-09-21 20:45:49 +03:00
|
|
|
static bool IsAnonBox(const nsIFrame* aFrame) {
|
|
|
|
return aFrame->Style()->IsAnonBox();
|
2018-04-07 16:48:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const nsIFrame* FirstContinuationOrPartOfIBSplit(
|
|
|
|
const nsIFrame* aFrame) {
|
|
|
|
if (!aFrame) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
|
|
|
}
|
|
|
|
|
2018-09-21 20:45:49 +03:00
|
|
|
static const nsIFrame* ExpectedOwnerForChild(const nsIFrame* aFrame) {
|
|
|
|
const nsIFrame* parent = aFrame->GetParent();
|
|
|
|
if (aFrame->IsTableFrame()) {
|
2018-04-07 16:48:43 +03:00
|
|
|
MOZ_ASSERT(parent->IsTableWrapperFrame());
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
2018-09-21 20:45:49 +03:00
|
|
|
if (IsAnonBox(aFrame) && !aFrame->IsTextFrame()) {
|
2018-04-07 16:48:43 +03:00
|
|
|
if (parent->IsLineFrame()) {
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
return parent->IsViewportFrame() ? nullptr
|
|
|
|
: FirstContinuationOrPartOfIBSplit(parent);
|
|
|
|
}
|
|
|
|
|
2018-09-21 20:45:49 +03:00
|
|
|
if (aFrame->IsBulletFrame()) {
|
2018-04-07 16:48:43 +03:00
|
|
|
return FirstContinuationOrPartOfIBSplit(parent);
|
|
|
|
}
|
|
|
|
|
2018-09-21 20:45:49 +03:00
|
|
|
if (aFrame->IsLineFrame()) {
|
2018-04-07 16:48:43 +03:00
|
|
|
// A ::first-line always ends up here via its block, which is therefore the
|
|
|
|
// right expected owner. That block can be an
|
|
|
|
// anonymous box. For example, we could have a ::first-line on a columnated
|
|
|
|
// block; the blockframe is the column-content anonymous box in that case.
|
|
|
|
// So we don't want to end up in the code below, which steps out of anon
|
|
|
|
// boxes. Just return the parent of the line frame, which is the block.
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2018-09-21 20:45:49 +03:00
|
|
|
if (aFrame->IsLetterFrame()) {
|
2018-04-07 16:48:43 +03:00
|
|
|
// Ditto for ::first-letter. A first-letter always arrives here via its
|
|
|
|
// direct parent, except when it's parented to a ::first-line.
|
|
|
|
if (parent->IsLineFrame()) {
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
return FirstContinuationOrPartOfIBSplit(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent->IsLetterFrame()) {
|
|
|
|
// Things never have ::first-letter as their expected parent. Go
|
|
|
|
// on up to the ::first-letter's parent.
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = FirstContinuationOrPartOfIBSplit(parent);
|
|
|
|
|
|
|
|
// We've handled already anon boxes and bullet frames, so now we're looking at
|
|
|
|
// a frame of a DOM element or pseudo. Hop through anon and line-boxes
|
|
|
|
// generated by our DOM parent, and go find the owner frame for it.
|
2018-09-21 20:45:49 +03:00
|
|
|
while (parent && (IsAnonBox(parent) || parent->IsLineFrame())) {
|
2019-02-19 16:44:33 +03:00
|
|
|
auto pseudo = parent->Style()->GetPseudoType();
|
|
|
|
if (pseudo == PseudoStyleType::tableWrapper) {
|
2018-04-07 16:48:43 +03:00
|
|
|
const nsIFrame* tableFrame = parent->PrincipalChildList().FirstChild();
|
|
|
|
MOZ_ASSERT(tableFrame->IsTableFrame());
|
|
|
|
// Handle :-moz-table and :-moz-inline-table.
|
2018-09-21 20:45:49 +03:00
|
|
|
parent = IsAnonBox(tableFrame) ? parent->GetParent() : tableFrame;
|
2018-04-07 16:48:43 +03:00
|
|
|
} else {
|
|
|
|
// We get the in-flow parent here so that we can handle the OOF anonymous
|
|
|
|
// boxed to get the correct parent.
|
|
|
|
parent = parent->GetInFlowParent();
|
|
|
|
}
|
|
|
|
parent = FirstContinuationOrPartOfIBSplit(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServoRestyleState::AssertOwner(const ServoRestyleState& aParent) const {
|
|
|
|
MOZ_ASSERT(mOwner);
|
|
|
|
MOZ_ASSERT(!mOwner->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW));
|
2018-11-08 22:11:55 +03:00
|
|
|
MOZ_ASSERT(!mOwner->IsColumnSpanInMulticolSubtree());
|
2018-04-07 16:48:43 +03:00
|
|
|
// We allow aParent.mOwner to be null, for cases when we're not starting at
|
|
|
|
// the root of the tree. We also allow aParent.mOwner to be somewhere up our
|
|
|
|
// expected owner chain not our immediate owner, which allows us creating long
|
|
|
|
// chains of ServoRestyleStates in some cases where it's just not worth it.
|
|
|
|
if (aParent.mOwner) {
|
2018-09-21 20:45:49 +03:00
|
|
|
const nsIFrame* owner = ExpectedOwnerForChild(mOwner);
|
2018-04-07 16:48:43 +03:00
|
|
|
if (owner != aParent.mOwner) {
|
2018-09-21 20:45:49 +03:00
|
|
|
MOZ_ASSERT(IsAnonBox(owner),
|
2018-04-07 16:48:43 +03:00
|
|
|
"Should only have expected owner weirdness when anon boxes "
|
|
|
|
"are involved");
|
|
|
|
bool found = false;
|
2018-09-21 20:45:49 +03:00
|
|
|
for (; owner; owner = ExpectedOwnerForChild(owner)) {
|
2018-04-07 16:48:43 +03:00
|
|
|
if (owner == aParent.mOwner) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(found, "Must have aParent.mOwner on our expected owner chain");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-21 20:45:49 +03:00
|
|
|
nsChangeHint ServoRestyleState::ChangesHandledFor(
|
|
|
|
const nsIFrame* aFrame) const {
|
2018-04-07 16:48:43 +03:00
|
|
|
if (!mOwner) {
|
|
|
|
MOZ_ASSERT(!mChangesHandled);
|
|
|
|
return mChangesHandled;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mOwner == ExpectedOwnerForChild(aFrame),
|
|
|
|
"Missed some frame in the hierarchy?");
|
|
|
|
return mChangesHandled;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void ServoRestyleState::AddPendingWrapperRestyle(nsIFrame* aWrapperFrame) {
|
|
|
|
MOZ_ASSERT(aWrapperFrame->Style()->IsWrapperAnonBox(),
|
|
|
|
"All our wrappers are anon boxes, and why would we restyle "
|
|
|
|
"non-inheriting ones?");
|
|
|
|
MOZ_ASSERT(aWrapperFrame->Style()->IsInheritingAnonBox(),
|
|
|
|
"All our wrappers are anon boxes, and why would we restyle "
|
|
|
|
"non-inheriting ones?");
|
|
|
|
MOZ_ASSERT(
|
2019-02-19 16:44:33 +03:00
|
|
|
aWrapperFrame->Style()->GetPseudoType() != PseudoStyleType::cellContent,
|
2018-04-07 16:48:43 +03:00
|
|
|
"Someone should be using TableAwareParentFor");
|
|
|
|
MOZ_ASSERT(
|
2019-02-19 16:44:33 +03:00
|
|
|
aWrapperFrame->Style()->GetPseudoType() != PseudoStyleType::tableWrapper,
|
2018-04-07 16:48:43 +03:00
|
|
|
"Someone should be using TableAwareParentFor");
|
|
|
|
// Make sure we only add first continuations.
|
|
|
|
aWrapperFrame = aWrapperFrame->FirstContinuation();
|
|
|
|
nsIFrame* last = mPendingWrapperRestyles.SafeLastElement(nullptr);
|
|
|
|
if (last == aWrapperFrame) {
|
|
|
|
// Already queued up, nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure to queue up parents before children. But don't queue up
|
|
|
|
// ancestors of non-anonymous boxes here; those are handled when we traverse
|
|
|
|
// their non-anonymous kids.
|
|
|
|
if (aWrapperFrame->ParentIsWrapperAnonBox()) {
|
|
|
|
AddPendingWrapperRestyle(TableAwareParentFor(aWrapperFrame));
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the append fails, we'll fail to restyle properly, but that's probably
|
|
|
|
// better than crashing.
|
|
|
|
if (mPendingWrapperRestyles.AppendElement(aWrapperFrame, fallible)) {
|
|
|
|
aWrapperFrame->SetIsWrapperAnonBoxNeedingRestyle(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServoRestyleState::ProcessWrapperRestyles(nsIFrame* aParentFrame) {
|
|
|
|
size_t i = mPendingWrapperRestyleOffset;
|
|
|
|
while (i < mPendingWrapperRestyles.Length()) {
|
|
|
|
i += ProcessMaybeNestedWrapperRestyle(aParentFrame, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
mPendingWrapperRestyles.TruncateLength(mPendingWrapperRestyleOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t ServoRestyleState::ProcessMaybeNestedWrapperRestyle(nsIFrame* aParent,
|
|
|
|
size_t aIndex) {
|
|
|
|
// The frame at index aIndex is something we should restyle ourselves, but
|
|
|
|
// following frames may need separate ServoRestyleStates to restyle.
|
|
|
|
MOZ_ASSERT(aIndex < mPendingWrapperRestyles.Length());
|
|
|
|
|
|
|
|
nsIFrame* cur = mPendingWrapperRestyles[aIndex];
|
|
|
|
MOZ_ASSERT(cur->Style()->IsWrapperAnonBox());
|
|
|
|
|
|
|
|
// Where is cur supposed to inherit from? From its parent frame, except in
|
|
|
|
// the case when cur is a table, in which case it should be its grandparent.
|
|
|
|
// Also, not in the case when the resulting frame would be a first-line; in
|
|
|
|
// that case we should be inheriting from the block, and the first-line will
|
|
|
|
// do its fixup later if needed.
|
|
|
|
//
|
|
|
|
// Note that after we do all that fixup the parent we get might still not be
|
|
|
|
// aParent; for example aParent could be a scrollframe, in which case we
|
|
|
|
// should inherit from the scrollcontent frame. Or the parent might be some
|
|
|
|
// continuation of aParent.
|
|
|
|
//
|
|
|
|
// Try to assert as much as we can about the parent we actually end up using
|
|
|
|
// without triggering bogus asserts in all those various edge cases.
|
|
|
|
nsIFrame* parent = cur->GetParent();
|
|
|
|
if (cur->IsTableFrame()) {
|
|
|
|
MOZ_ASSERT(parent->IsTableWrapperFrame());
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
if (parent->IsLineFrame()) {
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(FirstContinuationOrPartOfIBSplit(parent) == aParent ||
|
|
|
|
(parent->Style()->IsInheritingAnonBox() &&
|
|
|
|
parent->GetContent() == aParent->GetContent()));
|
|
|
|
|
|
|
|
// Now "this" is a ServoRestyleState for aParent, so if parent is not a next
|
|
|
|
// continuation (possibly across ib splits) of aParent we need a new
|
|
|
|
// ServoRestyleState for the kid.
|
|
|
|
Maybe<ServoRestyleState> parentRestyleState;
|
|
|
|
nsIFrame* parentForRestyle =
|
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(parent);
|
|
|
|
if (parentForRestyle != aParent) {
|
|
|
|
parentRestyleState.emplace(*parentForRestyle, *this, nsChangeHint_Empty,
|
|
|
|
Type::InFlow);
|
|
|
|
}
|
|
|
|
ServoRestyleState& curRestyleState =
|
|
|
|
parentRestyleState ? *parentRestyleState : *this;
|
|
|
|
|
|
|
|
// This frame may already have been restyled. Even if it has, we can't just
|
|
|
|
// return, because the next frame may be a kid of it that does need restyling.
|
|
|
|
if (cur->IsWrapperAnonBoxNeedingRestyle()) {
|
|
|
|
parentForRestyle->UpdateStyleOfChildAnonBox(cur, curRestyleState);
|
|
|
|
cur->SetIsWrapperAnonBoxNeedingRestyle(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t numProcessed = 1;
|
|
|
|
|
|
|
|
// Note: no overflow possible here, since aIndex < length.
|
|
|
|
if (aIndex + 1 < mPendingWrapperRestyles.Length()) {
|
|
|
|
nsIFrame* next = mPendingWrapperRestyles[aIndex + 1];
|
|
|
|
if (TableAwareParentFor(next) == cur &&
|
|
|
|
next->IsWrapperAnonBoxNeedingRestyle()) {
|
|
|
|
// It might be nice if we could do better than nsChangeHint_Empty. On
|
|
|
|
// the other hand, presumably our mChangesHandled already has the bits
|
|
|
|
// we really want here so in practice it doesn't matter.
|
|
|
|
ServoRestyleState childState(*cur, curRestyleState, nsChangeHint_Empty,
|
|
|
|
Type::InFlow,
|
|
|
|
/* aAssertWrapperRestyleLength = */ false);
|
|
|
|
numProcessed +=
|
|
|
|
childState.ProcessMaybeNestedWrapperRestyle(cur, aIndex + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numProcessed;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* ServoRestyleState::TableAwareParentFor(const nsIFrame* aChild) {
|
|
|
|
// We want to get the anon box parent for aChild. where aChild has
|
|
|
|
// ParentIsWrapperAnonBox().
|
|
|
|
//
|
|
|
|
// For the most part this is pretty straightforward, but there are two
|
|
|
|
// wrinkles. First, if aChild is a table, then we really want the parent of
|
|
|
|
// its table wrapper.
|
|
|
|
if (aChild->IsTableFrame()) {
|
|
|
|
aChild = aChild->GetParent();
|
|
|
|
MOZ_ASSERT(aChild->IsTableWrapperFrame());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* parent = aChild->GetParent();
|
|
|
|
// Now if parent is a cell-content frame, we actually want the cellframe.
|
2019-02-19 16:44:33 +03:00
|
|
|
if (parent->Style()->GetPseudoType() == PseudoStyleType::cellContent) {
|
2018-04-07 16:48:43 +03:00
|
|
|
parent = parent->GetParent();
|
|
|
|
} else if (parent->IsTableWrapperFrame()) {
|
|
|
|
// Must be a caption. In that case we want the table here.
|
|
|
|
MOZ_ASSERT(aChild->StyleDisplay()->mDisplay == StyleDisplay::TableCaption);
|
|
|
|
parent = parent->PrincipalChildList().FirstChild();
|
|
|
|
}
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::PostRestyleEvent(Element* aElement,
|
2019-03-14 14:47:50 +03:00
|
|
|
RestyleHint aRestyleHint,
|
2018-08-07 02:44:56 +03:00
|
|
|
nsChangeHint aMinChangeHint) {
|
2018-04-07 16:48:43 +03:00
|
|
|
MOZ_ASSERT(!(aMinChangeHint & nsChangeHint_NeutralChange),
|
|
|
|
"Didn't expect explicit change hints to be neutral!");
|
|
|
|
if (MOZ_UNLIKELY(IsDisconnected()) ||
|
|
|
|
MOZ_UNLIKELY(PresContext()->PresShell()->IsDestroying())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We allow posting restyles from within change hint handling, but not from
|
|
|
|
// within the restyle algorithm itself.
|
|
|
|
MOZ_ASSERT(!ServoStyleSet::IsInServoTraversal());
|
|
|
|
|
2019-03-14 14:47:50 +03:00
|
|
|
if (!aRestyleHint && !aMinChangeHint) {
|
|
|
|
// FIXME(emilio): we should assert against this instead.
|
2018-04-07 16:48:43 +03:00
|
|
|
return; // Nothing to do.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assuming the restyle hints will invalidate cached style for
|
|
|
|
// getComputedStyle, since we don't know if any of the restyling that we do
|
|
|
|
// would affect undisplayed elements.
|
|
|
|
if (aRestyleHint) {
|
2019-03-14 14:47:50 +03:00
|
|
|
if (!(aRestyleHint & RestyleHint::ForAnimations())) {
|
|
|
|
mHaveNonAnimationRestyles = true;
|
|
|
|
}
|
|
|
|
|
2018-04-07 16:48:43 +03:00
|
|
|
IncrementUndisplayedRestyleGeneration();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Processing change hints sometimes causes new change hints to be generated,
|
|
|
|
// and very occasionally, additional restyle hints. We collect the change
|
|
|
|
// hints manually to avoid re-traversing the DOM to find them.
|
|
|
|
if (mReentrantChanges && !aRestyleHint) {
|
|
|
|
mReentrantChanges->AppendElement(ReentrantChange{aElement, aMinChangeHint});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRestyleHint || aMinChangeHint) {
|
|
|
|
Servo_NoteExplicitHints(aElement, aRestyleHint, aMinChangeHint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
void RestyleManager::PostRestyleEventForAnimations(Element* aElement,
|
|
|
|
PseudoStyleType aPseudoType,
|
2019-03-14 14:47:50 +03:00
|
|
|
RestyleHint aRestyleHint) {
|
2018-04-07 16:48:43 +03:00
|
|
|
Element* elementToRestyle =
|
|
|
|
EffectCompositor::GetElementToRestyle(aElement, aPseudoType);
|
|
|
|
|
|
|
|
if (!elementToRestyle) {
|
|
|
|
// FIXME: Bug 1371107: When reframing happens,
|
2018-06-05 18:16:17 +03:00
|
|
|
// EffectCompositor::mElementsToRestyle still has unbound old pseudo
|
2018-04-07 16:48:43 +03:00
|
|
|
// element. We should drop it.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoRestyleTimelineMarker marker(mPresContext->GetDocShell(),
|
|
|
|
true /* animation-only */);
|
|
|
|
Servo_NoteExplicitHints(elementToRestyle, aRestyleHint, nsChangeHint(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint,
|
2019-03-14 14:47:50 +03:00
|
|
|
RestyleHint aRestyleHint) {
|
2018-06-05 18:16:17 +03:00
|
|
|
// NOTE(emilio): GeckoRestlyeManager does a sync style flush, which seems not
|
|
|
|
// to be needed in my testing.
|
2018-04-07 16:48:43 +03:00
|
|
|
PostRebuildAllStyleDataEvent(aExtraHint, aRestyleHint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
|
2019-03-14 14:47:50 +03:00
|
|
|
RestyleHint aRestyleHint) {
|
2018-04-07 16:48:43 +03:00
|
|
|
// NOTE(emilio): The semantics of these methods are quite funny, in the sense
|
|
|
|
// that we're not supposed to need to rebuild the actual stylist data.
|
|
|
|
//
|
|
|
|
// That's handled as part of the MediumFeaturesChanged stuff, if needed.
|
|
|
|
StyleSet()->ClearCachedStyleData();
|
|
|
|
|
|
|
|
DocumentStyleRootIterator iter(mPresContext->Document());
|
|
|
|
while (Element* root = iter.GetNextStyleRoot()) {
|
|
|
|
PostRestyleEvent(root, aRestyleHint, aExtraHint);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(emilio, bz): Extensions can add/remove stylesheets that can affect
|
|
|
|
// non-inheriting anon boxes. It's not clear if we want to support that, but
|
|
|
|
// if we do, we need to re-selector-match them here.
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void RestyleManager::ClearServoDataFromSubtree(Element* aElement,
|
|
|
|
IncludeRoot aIncludeRoot) {
|
2018-04-07 16:48:43 +03:00
|
|
|
if (aElement->HasServoData()) {
|
|
|
|
StyleChildrenIterator it(aElement);
|
|
|
|
for (nsIContent* n = it.GetNextChild(); n; n = it.GetNextChild()) {
|
|
|
|
if (n->IsElement()) {
|
|
|
|
ClearServoDataFromSubtree(n->AsElement(), IncludeRoot::Yes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MOZ_LIKELY(aIncludeRoot == IncludeRoot::Yes)) {
|
|
|
|
aElement->ClearServoData();
|
|
|
|
MOZ_ASSERT(!aElement->HasAnyOfFlags(Element::kAllServoDescendantBits |
|
|
|
|
NODE_NEEDS_FRAME));
|
|
|
|
MOZ_ASSERT(aElement != aElement->OwnerDoc()->GetServoRestyleRoot());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void RestyleManager::ClearRestyleStateFromSubtree(Element* aElement) {
|
2018-04-07 16:48:43 +03:00
|
|
|
if (aElement->HasAnyOfFlags(Element::kAllServoDescendantBits)) {
|
|
|
|
StyleChildrenIterator it(aElement);
|
|
|
|
for (nsIContent* n = it.GetNextChild(); n; n = it.GetNextChild()) {
|
|
|
|
if (n->IsElement()) {
|
|
|
|
ClearRestyleStateFromSubtree(n->AsElement());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wasRestyled;
|
|
|
|
Unused << Servo_TakeChangeHint(aElement, &wasRestyled);
|
|
|
|
aElement->UnsetFlags(Element::kAllServoDescendantBits);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This struct takes care of encapsulating some common state that text nodes may
|
|
|
|
* need to track during the post-traversal.
|
|
|
|
*
|
|
|
|
* This is currently used to properly compute change hints when the parent
|
|
|
|
* element of this node is a display: contents node, and also to avoid computing
|
|
|
|
* the style for text children more than once per element.
|
|
|
|
*/
|
|
|
|
struct RestyleManager::TextPostTraversalState {
|
|
|
|
public:
|
|
|
|
TextPostTraversalState(Element& aParentElement, ComputedStyle* aParentContext,
|
|
|
|
bool aDisplayContentsParentStyleChanged,
|
|
|
|
ServoRestyleState& aParentRestyleState)
|
|
|
|
: mParentElement(aParentElement),
|
|
|
|
mParentContext(aParentContext),
|
|
|
|
mParentRestyleState(aParentRestyleState),
|
|
|
|
mStyle(nullptr),
|
|
|
|
mShouldPostHints(aDisplayContentsParentStyleChanged),
|
|
|
|
mShouldComputeHints(aDisplayContentsParentStyleChanged),
|
|
|
|
mComputedHint(nsChangeHint_Empty) {}
|
|
|
|
|
|
|
|
nsStyleChangeList& ChangeList() { return mParentRestyleState.ChangeList(); }
|
|
|
|
|
|
|
|
ComputedStyle& ComputeStyle(nsIContent* aTextNode) {
|
|
|
|
if (!mStyle) {
|
|
|
|
mStyle = mParentRestyleState.StyleSet().ResolveStyleForText(
|
|
|
|
aTextNode, &ParentStyle());
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(mStyle);
|
|
|
|
return *mStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComputeHintIfNeeded(nsIContent* aContent, nsIFrame* aTextFrame,
|
|
|
|
ComputedStyle& aNewStyle) {
|
|
|
|
MOZ_ASSERT(aTextFrame);
|
2019-02-19 16:44:33 +03:00
|
|
|
MOZ_ASSERT(aNewStyle.GetPseudoType() == PseudoStyleType::mozText);
|
2018-04-07 16:48:43 +03:00
|
|
|
|
|
|
|
if (MOZ_LIKELY(!mShouldPostHints)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ComputedStyle* oldStyle = aTextFrame->Style();
|
2019-02-19 16:44:33 +03:00
|
|
|
MOZ_ASSERT(oldStyle->GetPseudoType() == PseudoStyleType::mozText);
|
2018-04-07 16:48:43 +03:00
|
|
|
|
|
|
|
// We rely on the fact that all the text children for the same element share
|
|
|
|
// style to avoid recomputing style differences for all of them.
|
|
|
|
//
|
|
|
|
// TODO(emilio): The above may not be true for ::first-{line,letter}, but
|
|
|
|
// we'll cross that bridge when we support those in stylo.
|
|
|
|
if (mShouldComputeHints) {
|
|
|
|
mShouldComputeHints = false;
|
|
|
|
uint32_t equalStructs;
|
2019-02-05 22:47:29 +03:00
|
|
|
mComputedHint = oldStyle->CalcStyleDifference(aNewStyle, &equalStructs);
|
2018-04-07 16:48:43 +03:00
|
|
|
mComputedHint = NS_RemoveSubsumedHints(
|
2018-09-21 20:45:49 +03:00
|
|
|
mComputedHint, mParentRestyleState.ChangesHandledFor(aTextFrame));
|
2018-04-07 16:48:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mComputedHint) {
|
|
|
|
mParentRestyleState.ChangeList().AppendChange(aTextFrame, aContent,
|
|
|
|
mComputedHint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ComputedStyle& ParentStyle() {
|
|
|
|
if (!mParentContext) {
|
|
|
|
mLazilyResolvedParentContext =
|
2018-07-24 19:15:01 +03:00
|
|
|
mParentRestyleState.StyleSet().ResolveServoStyle(mParentElement);
|
2018-04-07 16:48:43 +03:00
|
|
|
mParentContext = mLazilyResolvedParentContext;
|
|
|
|
}
|
|
|
|
return *mParentContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
Element& mParentElement;
|
|
|
|
ComputedStyle* mParentContext;
|
|
|
|
RefPtr<ComputedStyle> mLazilyResolvedParentContext;
|
|
|
|
ServoRestyleState& mParentRestyleState;
|
|
|
|
RefPtr<ComputedStyle> mStyle;
|
|
|
|
bool mShouldPostHints;
|
|
|
|
bool mShouldComputeHints;
|
|
|
|
nsChangeHint mComputedHint;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void UpdateBackdropIfNeeded(nsIFrame* aFrame, ServoStyleSet& aStyleSet,
|
|
|
|
nsStyleChangeList& aChangeList) {
|
|
|
|
const nsStyleDisplay* display = aFrame->Style()->StyleDisplay();
|
|
|
|
if (display->mTopLayer != NS_STYLE_TOP_LAYER_TOP) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Elements in the top layer are guaranteed to have absolute or fixed
|
|
|
|
// position per https://fullscreen.spec.whatwg.org/#new-stacking-layer.
|
|
|
|
MOZ_ASSERT(display->IsAbsolutelyPositionedStyle());
|
|
|
|
|
|
|
|
nsIFrame* backdropPlaceholder =
|
|
|
|
aFrame->GetChildList(nsIFrame::kBackdropList).FirstChild();
|
|
|
|
if (!backdropPlaceholder) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(backdropPlaceholder->IsPlaceholderFrame());
|
|
|
|
nsIFrame* backdropFrame =
|
|
|
|
nsPlaceholderFrame::GetRealFrameForPlaceholder(backdropPlaceholder);
|
|
|
|
MOZ_ASSERT(backdropFrame->IsBackdropFrame());
|
|
|
|
MOZ_ASSERT(backdropFrame->Style()->GetPseudoType() ==
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType::backdrop);
|
2018-04-07 16:48:43 +03:00
|
|
|
|
|
|
|
RefPtr<ComputedStyle> newStyle = aStyleSet.ResolvePseudoElementStyle(
|
2019-02-19 16:44:33 +03:00
|
|
|
aFrame->GetContent()->AsElement(), PseudoStyleType::backdrop,
|
2018-04-07 16:48:43 +03:00
|
|
|
aFrame->Style(),
|
|
|
|
/* aPseudoElement = */ nullptr);
|
|
|
|
|
|
|
|
// NOTE(emilio): We can't use the changes handled for the owner of the
|
|
|
|
// backdrop frame, since it's out of flow, and parented to the viewport or
|
|
|
|
// canvas frame (depending on the `position` value).
|
|
|
|
MOZ_ASSERT(backdropFrame->GetParent()->IsViewportFrame() ||
|
|
|
|
backdropFrame->GetParent()->IsCanvasFrame());
|
|
|
|
nsTArray<nsIFrame*> wrappersToRestyle;
|
|
|
|
ServoRestyleState state(aStyleSet, aChangeList, wrappersToRestyle);
|
|
|
|
nsIFrame::UpdateStyleOfOwnedChildFrame(backdropFrame, newStyle, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UpdateFirstLetterIfNeeded(nsIFrame* aFrame,
|
|
|
|
ServoRestyleState& aRestyleState) {
|
|
|
|
MOZ_ASSERT(
|
2019-02-21 00:18:14 +03:00
|
|
|
!aFrame->IsBlockFrameOrSubclass(),
|
2018-04-07 16:48:43 +03:00
|
|
|
"You're probably duplicating work with UpdatePseudoElementStyles!");
|
|
|
|
if (!aFrame->HasFirstLetterChild()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to find the block the first-letter is associated with so we can
|
|
|
|
// find the right element for the first-letter's style resolution. Might as
|
|
|
|
// well just delegate the whole thing to that block.
|
|
|
|
nsIFrame* block = aFrame->GetParent();
|
2019-02-21 00:18:14 +03:00
|
|
|
while (!block->IsBlockFrameOrSubclass()) {
|
2018-04-07 16:48:43 +03:00
|
|
|
block = block->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
static_cast<nsBlockFrame*>(block->FirstContinuation())
|
|
|
|
->UpdateFirstLetterStyle(aRestyleState);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UpdateOneAdditionalComputedStyle(nsIFrame* aFrame, uint32_t aIndex,
|
|
|
|
ComputedStyle& aOldContext,
|
|
|
|
ServoRestyleState& aRestyleState) {
|
|
|
|
auto pseudoType = aOldContext.GetPseudoType();
|
2019-02-19 16:44:33 +03:00
|
|
|
MOZ_ASSERT(pseudoType != PseudoStyleType::NotPseudo);
|
2018-04-07 16:48:43 +03:00
|
|
|
MOZ_ASSERT(
|
|
|
|
!nsCSSPseudoElements::PseudoElementSupportsUserActionState(pseudoType));
|
|
|
|
|
|
|
|
RefPtr<ComputedStyle> newStyle =
|
|
|
|
aRestyleState.StyleSet().ResolvePseudoElementStyle(
|
|
|
|
aFrame->GetContent()->AsElement(), pseudoType, aFrame->Style(),
|
|
|
|
/* aPseudoElement = */ nullptr);
|
|
|
|
|
|
|
|
uint32_t equalStructs; // Not used, actually.
|
|
|
|
nsChangeHint childHint =
|
2019-02-05 22:47:29 +03:00
|
|
|
aOldContext.CalcStyleDifference(*newStyle, &equalStructs);
|
2018-04-07 16:48:43 +03:00
|
|
|
if (!aFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
|
|
|
|
childHint = NS_RemoveSubsumedHints(childHint,
|
2018-09-21 20:45:49 +03:00
|
|
|
aRestyleState.ChangesHandledFor(aFrame));
|
2018-04-07 16:48:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (childHint) {
|
|
|
|
if (childHint & nsChangeHint_ReconstructFrame) {
|
|
|
|
// If we generate a reconstruct here, remove any non-reconstruct hints we
|
|
|
|
// may have already generated for this content.
|
|
|
|
aRestyleState.ChangeList().PopChangesForContent(aFrame->GetContent());
|
|
|
|
}
|
|
|
|
aRestyleState.ChangeList().AppendChange(aFrame, aFrame->GetContent(),
|
|
|
|
childHint);
|
|
|
|
}
|
|
|
|
|
|
|
|
aFrame->SetAdditionalComputedStyle(aIndex, newStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UpdateAdditionalComputedStyles(nsIFrame* aFrame,
|
|
|
|
ServoRestyleState& aRestyleState) {
|
|
|
|
MOZ_ASSERT(aFrame);
|
|
|
|
MOZ_ASSERT(aFrame->GetContent() && aFrame->GetContent()->IsElement());
|
|
|
|
|
|
|
|
// FIXME(emilio): Consider adding a bit or something to avoid the initial
|
|
|
|
// virtual call?
|
|
|
|
uint32_t index = 0;
|
|
|
|
while (auto* oldStyle = aFrame->GetAdditionalComputedStyle(index)) {
|
|
|
|
UpdateOneAdditionalComputedStyle(aFrame, index++, *oldStyle, aRestyleState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UpdateFramePseudoElementStyles(nsIFrame* aFrame,
|
|
|
|
ServoRestyleState& aRestyleState) {
|
2019-02-21 00:18:14 +03:00
|
|
|
if (nsBlockFrame* blockFrame = do_QueryFrame(aFrame)) {
|
|
|
|
blockFrame->UpdatePseudoElementStyles(aRestyleState);
|
2018-04-07 16:48:43 +03:00
|
|
|
} else {
|
|
|
|
UpdateFirstLetterIfNeeded(aFrame, aRestyleState);
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateBackdropIfNeeded(aFrame, aRestyleState.StyleSet(),
|
|
|
|
aRestyleState.ChangeList());
|
|
|
|
}
|
|
|
|
|
|
|
|
enum class ServoPostTraversalFlags : uint32_t {
|
|
|
|
Empty = 0,
|
|
|
|
// Whether parent was restyled.
|
|
|
|
ParentWasRestyled = 1 << 0,
|
|
|
|
// Skip sending accessibility notifications for all descendants.
|
|
|
|
SkipA11yNotifications = 1 << 1,
|
|
|
|
// Always send accessibility notifications if the element is shown.
|
|
|
|
// The SkipA11yNotifications flag above overrides this flag.
|
|
|
|
SendA11yNotificationsIfShown = 1 << 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(ServoPostTraversalFlags)
|
|
|
|
|
|
|
|
// Send proper accessibility notifications and return post traversal
|
|
|
|
// flags for kids.
|
|
|
|
static ServoPostTraversalFlags SendA11yNotifications(
|
|
|
|
nsPresContext* aPresContext, Element* aElement,
|
|
|
|
ComputedStyle* aOldComputedStyle, ComputedStyle* aNewComputedStyle,
|
|
|
|
ServoPostTraversalFlags aFlags) {
|
|
|
|
using Flags = ServoPostTraversalFlags;
|
|
|
|
MOZ_ASSERT(!(aFlags & Flags::SkipA11yNotifications) ||
|
|
|
|
!(aFlags & Flags::SendA11yNotificationsIfShown),
|
|
|
|
"The two a11y flags should never be set together");
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
nsAccessibilityService* accService = GetAccService();
|
|
|
|
if (!accService) {
|
|
|
|
// If we don't have accessibility service, accessibility is not
|
|
|
|
// enabled. Just skip everything.
|
|
|
|
return Flags::Empty;
|
|
|
|
}
|
|
|
|
if (aFlags & Flags::SkipA11yNotifications) {
|
|
|
|
// Propogate the skipping flag to descendants.
|
|
|
|
return Flags::SkipA11yNotifications;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool needsNotify = false;
|
|
|
|
bool isVisible = aNewComputedStyle->StyleVisibility()->IsVisible();
|
|
|
|
if (aFlags & Flags::SendA11yNotificationsIfShown) {
|
|
|
|
if (!isVisible) {
|
|
|
|
// Propagate the sending-if-shown flag to descendants.
|
|
|
|
return Flags::SendA11yNotificationsIfShown;
|
|
|
|
}
|
|
|
|
// We have asked accessibility service to remove the whole subtree
|
|
|
|
// of element which becomes invisible from the accessible tree, but
|
|
|
|
// this element is visible, so we need to add it back.
|
|
|
|
needsNotify = true;
|
|
|
|
} else {
|
|
|
|
// If we shouldn't skip in any case, we need to check whether our
|
|
|
|
// own visibility has changed.
|
|
|
|
bool wasVisible = aOldComputedStyle->StyleVisibility()->IsVisible();
|
|
|
|
needsNotify = wasVisible != isVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needsNotify) {
|
|
|
|
nsIPresShell* presShell = aPresContext->PresShell();
|
|
|
|
if (isVisible) {
|
|
|
|
accService->ContentRangeInserted(presShell, aElement,
|
|
|
|
aElement->GetNextSibling());
|
|
|
|
// We are adding the subtree. Accessibility service would handle
|
|
|
|
// descendants, so we should just skip them from notifying.
|
|
|
|
return Flags::SkipA11yNotifications;
|
|
|
|
}
|
|
|
|
// Remove the subtree of this invisible element, and ask any shown
|
|
|
|
// descendant to add themselves back.
|
|
|
|
accService->ContentRemoved(presShell, aElement);
|
|
|
|
return Flags::SendA11yNotificationsIfShown;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return Flags::Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RestyleManager::ProcessPostTraversal(Element* aElement,
|
|
|
|
ComputedStyle* aParentContext,
|
|
|
|
ServoRestyleState& aRestyleState,
|
|
|
|
ServoPostTraversalFlags aFlags) {
|
|
|
|
nsIFrame* styleFrame = nsLayoutUtils::GetStyleFrame(aElement);
|
|
|
|
nsIFrame* primaryFrame = aElement->GetPrimaryFrame();
|
|
|
|
|
2018-05-05 13:52:56 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aElement->HasServoData(),
|
|
|
|
"Element without Servo data on a post-traversal? How?");
|
2018-04-23 22:28:01 +03:00
|
|
|
|
2018-04-07 16:48:43 +03:00
|
|
|
// NOTE(emilio): This is needed because for table frames the bit is set on the
|
|
|
|
// table wrapper (which is the primary frame), not on the table itself.
|
|
|
|
const bool isOutOfFlow =
|
|
|
|
primaryFrame && primaryFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW);
|
|
|
|
|
2018-11-08 22:11:55 +03:00
|
|
|
// We need this because any column-spanner's parent frame is not its DOM
|
|
|
|
// parent's primary frame. We need some special check similar to out-of-flow
|
|
|
|
// frames.
|
|
|
|
const bool isColumnSpan =
|
|
|
|
primaryFrame && primaryFrame->IsColumnSpanInMulticolSubtree();
|
|
|
|
|
2018-04-07 16:48:43 +03:00
|
|
|
// Grab the change hint from Servo.
|
|
|
|
bool wasRestyled;
|
|
|
|
nsChangeHint changeHint =
|
|
|
|
static_cast<nsChangeHint>(Servo_TakeChangeHint(aElement, &wasRestyled));
|
|
|
|
|
|
|
|
// We should really fix the weird primary frame mapping for image maps
|
|
|
|
// (bug 135040)...
|
|
|
|
if (styleFrame && styleFrame->GetContent() != aElement) {
|
|
|
|
MOZ_ASSERT(static_cast<nsImageFrame*>(do_QueryFrame(styleFrame)));
|
|
|
|
styleFrame = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle lazy frame construction by posting a reconstruct for any lazily-
|
|
|
|
// constructed roots.
|
|
|
|
if (aElement->HasFlag(NODE_NEEDS_FRAME)) {
|
|
|
|
changeHint |= nsChangeHint_ReconstructFrame;
|
|
|
|
MOZ_ASSERT(!styleFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (styleFrame) {
|
|
|
|
MOZ_ASSERT(primaryFrame);
|
|
|
|
|
|
|
|
nsIFrame* maybeAnonBoxChild;
|
|
|
|
if (isOutOfFlow) {
|
|
|
|
maybeAnonBoxChild = primaryFrame->GetPlaceholderFrame();
|
|
|
|
} else {
|
|
|
|
maybeAnonBoxChild = primaryFrame;
|
2018-11-08 22:11:55 +03:00
|
|
|
// Do not subsume change hints for the column-spanner.
|
|
|
|
if (!isColumnSpan) {
|
|
|
|
changeHint = NS_RemoveSubsumedHints(
|
|
|
|
changeHint, aRestyleState.ChangesHandledFor(styleFrame));
|
|
|
|
}
|
2018-04-07 16:48:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the parent wasn't restyled, the styles of our anon box parents won't
|
|
|
|
// change either.
|
|
|
|
if ((aFlags & ServoPostTraversalFlags::ParentWasRestyled) &&
|
|
|
|
maybeAnonBoxChild->ParentIsWrapperAnonBox()) {
|
|
|
|
aRestyleState.AddPendingWrapperRestyle(
|
|
|
|
ServoRestyleState::TableAwareParentFor(maybeAnonBoxChild));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Although we shouldn't generate non-ReconstructFrame hints for elements with
|
|
|
|
// no frames, we can still get them here if they were explicitly posted by
|
|
|
|
// PostRestyleEvent, such as a RepaintFrame hint when a :link changes to be
|
|
|
|
// :visited. Skip processing these hints if there is no frame.
|
|
|
|
if ((styleFrame || (changeHint & nsChangeHint_ReconstructFrame)) &&
|
|
|
|
changeHint) {
|
|
|
|
aRestyleState.ChangeList().AppendChange(styleFrame, aElement, changeHint);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If our change hint is reconstruct, we delegate to the frame constructor,
|
|
|
|
// which consumes the new style and expects the old style to be on the frame.
|
|
|
|
//
|
|
|
|
// XXXbholley: We should teach the frame constructor how to clear the dirty
|
|
|
|
// descendants bit to avoid the traversal here.
|
|
|
|
if (changeHint & nsChangeHint_ReconstructFrame) {
|
|
|
|
ClearRestyleStateFromSubtree(aElement);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(emilio): We could avoid some refcount traffic here, specially in the
|
|
|
|
// ComputedStyle case, which uses atomic refcounting.
|
|
|
|
//
|
|
|
|
// Hold the ComputedStyle alive, because it could become a dangling pointer
|
|
|
|
// during the replacement. In practice it's not a huge deal, but better not
|
|
|
|
// playing with dangling pointers if not needed.
|
|
|
|
//
|
|
|
|
// NOTE(emilio): We could keep around the old computed style for display:
|
|
|
|
// contents elements too, but we don't really need it right now.
|
|
|
|
RefPtr<ComputedStyle> oldOrDisplayContentsStyle =
|
|
|
|
styleFrame ? styleFrame->Style() : nullptr;
|
|
|
|
|
|
|
|
MOZ_ASSERT(!(styleFrame && Servo_Element_IsDisplayContents(aElement)),
|
|
|
|
"display: contents node has a frame, yet we didn't reframe it"
|
|
|
|
" above?");
|
2018-06-13 03:21:29 +03:00
|
|
|
const bool isDisplayContents = !styleFrame && aElement->HasServoData() &&
|
|
|
|
Servo_Element_IsDisplayContents(aElement);
|
2018-04-07 16:48:43 +03:00
|
|
|
if (isDisplayContents) {
|
|
|
|
oldOrDisplayContentsStyle =
|
2018-07-24 19:15:01 +03:00
|
|
|
aRestyleState.StyleSet().ResolveServoStyle(*aElement);
|
2018-04-07 16:48:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<ServoRestyleState> thisFrameRestyleState;
|
|
|
|
if (styleFrame) {
|
2018-11-08 22:11:55 +03:00
|
|
|
auto type = isOutOfFlow || isColumnSpan ? ServoRestyleState::Type::OutOfFlow
|
2018-04-07 16:48:43 +03:00
|
|
|
: ServoRestyleState::Type::InFlow;
|
|
|
|
|
|
|
|
thisFrameRestyleState.emplace(*styleFrame, aRestyleState, changeHint, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can't really assume as used changes from display: contents elements (or
|
|
|
|
// other elements without frames).
|
|
|
|
ServoRestyleState& childrenRestyleState =
|
|
|
|
thisFrameRestyleState ? *thisFrameRestyleState : aRestyleState;
|
|
|
|
|
|
|
|
RefPtr<ComputedStyle> upToDateContext =
|
2018-07-24 19:15:01 +03:00
|
|
|
wasRestyled ? aRestyleState.StyleSet().ResolveServoStyle(*aElement)
|
2018-04-07 16:48:43 +03:00
|
|
|
: oldOrDisplayContentsStyle;
|
|
|
|
|
|
|
|
ServoPostTraversalFlags childrenFlags =
|
|
|
|
wasRestyled ? ServoPostTraversalFlags::ParentWasRestyled
|
|
|
|
: ServoPostTraversalFlags::Empty;
|
|
|
|
|
|
|
|
if (wasRestyled && oldOrDisplayContentsStyle) {
|
|
|
|
MOZ_ASSERT(styleFrame || isDisplayContents);
|
|
|
|
|
|
|
|
// We want to walk all the continuations here, even the ones with different
|
|
|
|
// styles. In practice, the only reason we get continuations with different
|
|
|
|
// styles here is ::first-line (::first-letter never affects element
|
|
|
|
// styles). But in that case, newStyle is the right context for the
|
|
|
|
// _later_ continuations anyway (the ones not affected by ::first-line), not
|
|
|
|
// the earlier ones, so there is no point stopping right at the point when
|
|
|
|
// we'd actually be setting the right ComputedStyle.
|
|
|
|
//
|
|
|
|
// This does mean that we may be setting the wrong ComputedStyle on our
|
|
|
|
// initial continuations; ::first-line fixes that up after the fact.
|
|
|
|
for (nsIFrame* f = styleFrame; f; f = f->GetNextContinuation()) {
|
|
|
|
MOZ_ASSERT_IF(f != styleFrame, !f->GetAdditionalComputedStyle(0));
|
|
|
|
f->SetComputedStyle(upToDateContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (styleFrame) {
|
|
|
|
UpdateAdditionalComputedStyles(styleFrame, aRestyleState);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aElement->GetParent()) {
|
|
|
|
// This is the root. Update styles on the viewport as needed.
|
|
|
|
ViewportFrame* viewport =
|
|
|
|
do_QueryFrame(mPresContext->PresShell()->GetRootFrame());
|
|
|
|
if (viewport) {
|
|
|
|
// NB: The root restyle state, not the one for our children!
|
|
|
|
viewport->UpdateStyle(aRestyleState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some changes to animations don't affect the computed style and yet still
|
|
|
|
// require the layer to be updated. For example, pausing an animation via
|
|
|
|
// the Web Animations API won't affect an element's style but still
|
|
|
|
// requires to update the animation on the layer.
|
|
|
|
//
|
|
|
|
// We can sometimes reach this when the animated style is being removed.
|
|
|
|
// Since AddLayerChangesForAnimation checks if |styleFrame| has a transform
|
|
|
|
// style or not, we need to call it *after* setting |newStyle| to
|
|
|
|
// |styleFrame| to ensure the animated transform has been removed first.
|
2018-07-30 05:13:54 +03:00
|
|
|
AddLayerChangesForAnimation(styleFrame, aElement, changeHint,
|
|
|
|
aRestyleState.ChangeList());
|
2018-04-07 16:48:43 +03:00
|
|
|
|
|
|
|
childrenFlags |=
|
|
|
|
SendA11yNotifications(mPresContext, aElement, oldOrDisplayContentsStyle,
|
|
|
|
upToDateContext, aFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool traverseElementChildren =
|
|
|
|
aElement->HasAnyOfFlags(Element::kAllServoDescendantBits);
|
|
|
|
const bool traverseTextChildren =
|
|
|
|
wasRestyled || aElement->HasFlag(NODE_DESCENDANTS_NEED_FRAMES);
|
|
|
|
bool recreatedAnyContext = wasRestyled;
|
|
|
|
if (traverseElementChildren || traverseTextChildren) {
|
|
|
|
StyleChildrenIterator it(aElement);
|
|
|
|
TextPostTraversalState textState(*aElement, upToDateContext,
|
|
|
|
isDisplayContents && wasRestyled,
|
|
|
|
childrenRestyleState);
|
|
|
|
for (nsIContent* n = it.GetNextChild(); n; n = it.GetNextChild()) {
|
|
|
|
if (traverseElementChildren && n->IsElement()) {
|
|
|
|
recreatedAnyContext |=
|
|
|
|
ProcessPostTraversal(n->AsElement(), upToDateContext,
|
|
|
|
childrenRestyleState, childrenFlags);
|
2018-04-13 01:41:00 +03:00
|
|
|
} else if (traverseTextChildren && n->IsText()) {
|
2018-04-07 16:48:43 +03:00
|
|
|
recreatedAnyContext |= ProcessPostTraversalForText(
|
|
|
|
n, textState, childrenRestyleState, childrenFlags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We want to update frame pseudo-element styles after we've traversed our
|
|
|
|
// kids, because some of those updates (::first-line/::first-letter) need to
|
|
|
|
// modify the styles of the kids, and the child traversal above would just
|
|
|
|
// clobber those modifications.
|
|
|
|
if (styleFrame) {
|
|
|
|
if (wasRestyled) {
|
|
|
|
// Make sure to update anon boxes and pseudo bits after updating text,
|
|
|
|
// otherwise ProcessPostTraversalForText could clobber first-letter
|
|
|
|
// styles, for example.
|
|
|
|
styleFrame->UpdateStyleOfOwnedAnonBoxes(childrenRestyleState);
|
|
|
|
}
|
|
|
|
// Process anon box wrapper frames before ::first-line bits, but _after_
|
|
|
|
// owned anon boxes, since the children wrapper anon boxes could be
|
|
|
|
// inheriting from our own owned anon boxes.
|
|
|
|
childrenRestyleState.ProcessWrapperRestyles(styleFrame);
|
|
|
|
if (wasRestyled) {
|
|
|
|
UpdateFramePseudoElementStyles(styleFrame, childrenRestyleState);
|
|
|
|
} else if (traverseElementChildren &&
|
2019-02-21 00:18:14 +03:00
|
|
|
styleFrame->IsBlockFrameOrSubclass()) {
|
2018-04-07 16:48:43 +03:00
|
|
|
// Even if we were not restyled, if we're a block with a first-line and
|
|
|
|
// one of our descendant elements which is on the first line was restyled,
|
|
|
|
// we need to update the styles of things on the first line, because
|
|
|
|
// they're wrong now.
|
|
|
|
//
|
|
|
|
// FIXME(bz) Could we do better here? For example, could we keep track of
|
|
|
|
// frames that are "block with a ::first-line so we could avoid
|
|
|
|
// IsFrameOfType() and digging about for the first-line frame if not?
|
|
|
|
// Could we keep track of whether the element children we actually restyle
|
|
|
|
// are affected by first-line? Something else? Bug 1385443 tracks making
|
|
|
|
// this better.
|
|
|
|
nsIFrame* firstLineFrame =
|
|
|
|
static_cast<nsBlockFrame*>(styleFrame)->GetFirstLineFrame();
|
|
|
|
if (firstLineFrame) {
|
|
|
|
for (nsIFrame* kid : firstLineFrame->PrincipalChildList()) {
|
2018-04-06 04:14:09 +03:00
|
|
|
ReparentComputedStyleForFirstLine(kid);
|
2018-04-07 16:48:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aElement->UnsetFlags(Element::kAllServoDescendantBits);
|
|
|
|
return recreatedAnyContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RestyleManager::ProcessPostTraversalForText(
|
|
|
|
nsIContent* aTextNode, TextPostTraversalState& aPostTraversalState,
|
|
|
|
ServoRestyleState& aRestyleState, ServoPostTraversalFlags aFlags) {
|
|
|
|
// Handle lazy frame construction.
|
|
|
|
if (aTextNode->HasFlag(NODE_NEEDS_FRAME)) {
|
|
|
|
aPostTraversalState.ChangeList().AppendChange(
|
|
|
|
nullptr, aTextNode, nsChangeHint_ReconstructFrame);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle restyle.
|
|
|
|
nsIFrame* primaryFrame = aTextNode->GetPrimaryFrame();
|
|
|
|
if (!primaryFrame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the parent wasn't restyled, the styles of our anon box parents won't
|
|
|
|
// change either.
|
|
|
|
if ((aFlags & ServoPostTraversalFlags::ParentWasRestyled) &&
|
|
|
|
primaryFrame->ParentIsWrapperAnonBox()) {
|
|
|
|
aRestyleState.AddPendingWrapperRestyle(
|
|
|
|
ServoRestyleState::TableAwareParentFor(primaryFrame));
|
|
|
|
}
|
|
|
|
|
|
|
|
ComputedStyle& newStyle = aPostTraversalState.ComputeStyle(aTextNode);
|
|
|
|
aPostTraversalState.ComputeHintIfNeeded(aTextNode, primaryFrame, newStyle);
|
|
|
|
|
|
|
|
// We want to walk all the continuations here, even the ones with different
|
|
|
|
// styles. In practice, the only reasons we get continuations with different
|
|
|
|
// styles are ::first-line and ::first-letter. But in those cases,
|
|
|
|
// newStyle is the right context for the _later_ continuations anyway (the
|
|
|
|
// ones not affected by ::first-line/::first-letter), not the earlier ones,
|
|
|
|
// so there is no point stopping right at the point when we'd actually be
|
|
|
|
// setting the right ComputedStyle.
|
|
|
|
//
|
|
|
|
// This does mean that we may be setting the wrong ComputedStyle on our
|
|
|
|
// initial continuations; ::first-line/::first-letter fix that up after the
|
|
|
|
// fact.
|
|
|
|
for (nsIFrame* f = primaryFrame; f; f = f->GetNextContinuation()) {
|
|
|
|
f->SetComputedStyle(&newStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::ClearSnapshots() {
|
|
|
|
for (auto iter = mSnapshots.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
iter.Key()->UnsetFlags(ELEMENT_HAS_SNAPSHOT | ELEMENT_HANDLED_SNAPSHOT);
|
|
|
|
iter.Remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 02:44:56 +03:00
|
|
|
ServoElementSnapshot& RestyleManager::SnapshotFor(Element& aElement) {
|
2019-02-19 12:25:55 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mInStyleRefresh);
|
2018-04-07 16:48:43 +03:00
|
|
|
|
|
|
|
// NOTE(emilio): We can handle snapshots from a one-off restyle of those that
|
|
|
|
// we do to restyle stuff for reconstruction, for example.
|
|
|
|
//
|
|
|
|
// It seems to be the case that we always flush in between that happens and
|
|
|
|
// the next attribute change, so we can assert that we haven't handled the
|
|
|
|
// snapshot here yet. If this assertion didn't hold, we'd need to unset that
|
|
|
|
// flag from here too.
|
|
|
|
//
|
|
|
|
// Can't wait to make ProcessPendingRestyles the only entry-point for styling,
|
|
|
|
// so this becomes much easier to reason about. Today is not that day though.
|
2018-08-07 02:44:56 +03:00
|
|
|
MOZ_ASSERT(aElement.HasServoData());
|
|
|
|
MOZ_ASSERT(!aElement.HasFlag(ELEMENT_HANDLED_SNAPSHOT));
|
2018-04-07 16:48:43 +03:00
|
|
|
|
2018-08-07 02:44:56 +03:00
|
|
|
ServoElementSnapshot* snapshot = mSnapshots.LookupOrAdd(&aElement, aElement);
|
|
|
|
aElement.SetFlags(ELEMENT_HAS_SNAPSHOT);
|
2018-04-07 16:48:43 +03:00
|
|
|
|
|
|
|
// Now that we have a snapshot, make sure a restyle is triggered.
|
2018-08-07 02:44:56 +03:00
|
|
|
aElement.NoteDirtyForServo();
|
2018-04-07 16:48:43 +03:00
|
|
|
return *snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::DoProcessPendingRestyles(ServoTraversalFlags aFlags) {
|
|
|
|
nsPresContext* presContext = PresContext();
|
2019-02-15 09:29:55 +03:00
|
|
|
nsIPresShell* shell = presContext->PresShell();
|
2018-04-07 16:48:43 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(presContext->Document(), "No document? Pshaw!");
|
|
|
|
// FIXME(emilio): In the "flush animations" case, ideally, we should only
|
|
|
|
// recascade animation styles running on the compositor, so we shouldn't care
|
|
|
|
// about other styles, or new rules that apply to the page...
|
|
|
|
//
|
|
|
|
// However, that's not true as of right now, see bug 1388031 and bug 1388692.
|
|
|
|
MOZ_ASSERT((aFlags & ServoTraversalFlags::FlushThrottledAnimations) ||
|
|
|
|
!presContext->HasPendingMediaQueryUpdates(),
|
|
|
|
"Someone forgot to update media queries?");
|
|
|
|
MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript(), "Missing a script blocker!");
|
2019-02-15 09:29:55 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mInStyleRefresh, "Reentrant call?");
|
2018-04-07 16:48:43 +03:00
|
|
|
|
2019-02-15 09:29:55 +03:00
|
|
|
if (MOZ_UNLIKELY(!shell->DidInitialize())) {
|
2018-04-07 16:48:43 +03:00
|
|
|
// PresShell::FlushPendingNotifications doesn't early-return in the case
|
|
|
|
// where the PresShell hasn't yet been initialized (and therefore we haven't
|
|
|
|
// yet done the initial style traversal of the DOM tree). We should arguably
|
|
|
|
// fix up the callers and assert against this case, but we just detect and
|
|
|
|
// handle it for now.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-15 09:29:55 +03:00
|
|
|
// It'd be bad!
|
|
|
|
nsIPresShell::AutoAssertNoFlush noReentrantFlush(*shell);
|
|
|
|
|
2018-04-07 16:48:43 +03:00
|
|
|
// Create a AnimationsWithDestroyedFrame during restyling process to
|
|
|
|
// stop animations and transitions on elements that have no frame at the end
|
|
|
|
// of the restyling process.
|
|
|
|
AnimationsWithDestroyedFrame animationsWithDestroyedFrame(this);
|
|
|
|
|
|
|
|
ServoStyleSet* styleSet = StyleSet();
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = presContext->Document();
|
2018-04-07 16:48:43 +03:00
|
|
|
|
|
|
|
// Ensure the refresh driver is active during traversal to avoid mutating
|
|
|
|
// mActiveTimer and mMostRecentRefresh time.
|
|
|
|
presContext->RefreshDriver()->MostRecentRefresh();
|
|
|
|
|
|
|
|
// Perform the Servo traversal, and the post-traversal if required. We do this
|
|
|
|
// in a loop because certain rare paths in the frame constructor (like
|
|
|
|
// uninstalling XBL bindings) can trigger additional style validations.
|
|
|
|
mInStyleRefresh = true;
|
|
|
|
if (mHaveNonAnimationRestyles) {
|
|
|
|
++mAnimationGeneration;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mRestyleForCSSRuleChanges) {
|
|
|
|
aFlags |= ServoTraversalFlags::ForCSSRuleChanges;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (styleSet->StyleDocument(aFlags)) {
|
|
|
|
ClearSnapshots();
|
|
|
|
|
2019-01-26 23:37:45 +03:00
|
|
|
// Select scroll anchors for frames that have been scrolled. Do this
|
|
|
|
// before processing restyled frames so that anchor nodes are correctly
|
|
|
|
// marked when directly moving frames with RecomputePosition.
|
|
|
|
presContext->PresShell()->FlushPendingScrollAnchorSelections();
|
|
|
|
|
2018-04-07 16:48:43 +03:00
|
|
|
nsStyleChangeList currentChanges;
|
|
|
|
bool anyStyleChanged = false;
|
|
|
|
|
|
|
|
// Recreate styles , and queue up change hints (which also handle lazy frame
|
|
|
|
// construction).
|
|
|
|
{
|
|
|
|
AutoRestyleTimelineMarker marker(presContext->GetDocShell(), false);
|
|
|
|
DocumentStyleRootIterator iter(doc->GetServoRestyleRoot());
|
|
|
|
while (Element* root = iter.GetNextStyleRoot()) {
|
|
|
|
nsTArray<nsIFrame*> wrappersToRestyle;
|
|
|
|
ServoRestyleState state(*styleSet, currentChanges, wrappersToRestyle);
|
|
|
|
ServoPostTraversalFlags flags = ServoPostTraversalFlags::Empty;
|
|
|
|
anyStyleChanged |= ProcessPostTraversal(root, nullptr, state, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
doc->ClearServoRestyleRoot();
|
|
|
|
|
|
|
|
// Process the change hints.
|
|
|
|
//
|
|
|
|
// Unfortunately, the frame constructor can generate new change hints while
|
|
|
|
// processing existing ones. We redirect those into a secondary queue and
|
|
|
|
// iterate until there's nothing left.
|
|
|
|
{
|
|
|
|
AutoTimelineMarker marker(presContext->GetDocShell(),
|
|
|
|
"StylesApplyChanges");
|
|
|
|
ReentrantChangeList newChanges;
|
|
|
|
mReentrantChanges = &newChanges;
|
|
|
|
while (!currentChanges.IsEmpty()) {
|
|
|
|
ProcessRestyledFrames(currentChanges);
|
|
|
|
MOZ_ASSERT(currentChanges.IsEmpty());
|
|
|
|
for (ReentrantChange& change : newChanges) {
|
|
|
|
if (!(change.mHint & nsChangeHint_ReconstructFrame) &&
|
|
|
|
!change.mContent->GetPrimaryFrame()) {
|
|
|
|
// SVG Elements post change hints without ensuring that the primary
|
|
|
|
// frame will be there after that (see bug 1366142).
|
|
|
|
//
|
|
|
|
// Just ignore those, since we can't really process them.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
currentChanges.AppendChange(change.mContent->GetPrimaryFrame(),
|
|
|
|
change.mContent, change.mHint);
|
|
|
|
}
|
|
|
|
newChanges.Clear();
|
|
|
|
}
|
|
|
|
mReentrantChanges = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (anyStyleChanged) {
|
|
|
|
// Maybe no styles changed when:
|
|
|
|
//
|
|
|
|
// * Only explicit change hints were posted in the first place.
|
|
|
|
// * When an attribute or state change in the content happens not to need
|
|
|
|
// a restyle after all.
|
|
|
|
//
|
|
|
|
// In any case, we don't need to increment the restyle generation in that
|
|
|
|
// case.
|
|
|
|
IncrementRestyleGeneration();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
doc->ClearServoRestyleRoot();
|
|
|
|
|
2018-12-21 13:58:34 +03:00
|
|
|
FlushOverflowChangedTracker();
|
|
|
|
|
2018-04-07 16:48:43 +03:00
|
|
|
ClearSnapshots();
|
|
|
|
styleSet->AssertTreeIsClean();
|
|
|
|
mHaveNonAnimationRestyles = false;
|
|
|
|
mRestyleForCSSRuleChanges = false;
|
|
|
|
mInStyleRefresh = false;
|
|
|
|
|
|
|
|
// Now that everything has settled, see if we have enough free rule nodes in
|
|
|
|
// the tree to warrant sweeping them.
|
|
|
|
styleSet->MaybeGCRuleTree();
|
|
|
|
|
|
|
|
// Note: We are in the scope of |animationsWithDestroyedFrame|, so
|
|
|
|
// |mAnimationsWithDestroyedFrame| is still valid.
|
|
|
|
MOZ_ASSERT(mAnimationsWithDestroyedFrame);
|
|
|
|
mAnimationsWithDestroyedFrame->StopAnimationsForElementsWithoutFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static void VerifyFlatTree(const nsIContent& aContent) {
|
|
|
|
StyleChildrenIterator iter(&aContent);
|
|
|
|
|
|
|
|
for (auto* content = iter.GetNextChild(); content;
|
|
|
|
content = iter.GetNextChild()) {
|
|
|
|
MOZ_ASSERT(content->GetFlattenedTreeParentNodeForStyle() == &aContent);
|
2018-04-13 21:13:10 +03:00
|
|
|
MOZ_ASSERT(!content->IsActiveChildrenElement());
|
2018-04-07 16:48:43 +03:00
|
|
|
VerifyFlatTree(*content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void RestyleManager::ProcessPendingRestyles() {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (auto* root = mPresContext->Document()->GetRootElement()) {
|
|
|
|
VerifyFlatTree(*root);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DoProcessPendingRestyles(ServoTraversalFlags::Empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::ProcessAllPendingAttributeAndStateInvalidations() {
|
|
|
|
if (mSnapshots.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (auto iter = mSnapshots.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
// Servo data for the element might have been dropped. (e.g. by removing
|
|
|
|
// from its document)
|
|
|
|
if (iter.Key()->HasFlag(ELEMENT_HAS_SNAPSHOT)) {
|
|
|
|
Servo_ProcessInvalidations(StyleSet()->RawSet(), iter.Key(), &mSnapshots);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ClearSnapshots();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RestyleManager::HasPendingRestyleAncestor(Element* aElement) const {
|
|
|
|
return Servo_HasPendingRestyleAncestor(aElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::UpdateOnlyAnimationStyles() {
|
|
|
|
bool doCSS = PresContext()->EffectCompositor()->HasPendingStyleUpdates();
|
|
|
|
if (!doCSS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DoProcessPendingRestyles(ServoTraversalFlags::FlushThrottledAnimations);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::ContentStateChanged(nsIContent* aContent,
|
|
|
|
EventStates aChangedBits) {
|
2019-02-19 12:25:55 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mInStyleRefresh);
|
2018-04-07 16:48:43 +03:00
|
|
|
|
|
|
|
if (!aContent->IsElement()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-07 02:44:56 +03:00
|
|
|
Element& element = *aContent->AsElement();
|
|
|
|
if (!element.HasServoData()) {
|
2018-04-07 16:48:43 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-14 11:47:25 +03:00
|
|
|
const EventStates kVisitedAndUnvisited =
|
|
|
|
NS_EVENT_STATE_VISITED | NS_EVENT_STATE_UNVISITED;
|
2018-09-05 15:52:16 +03:00
|
|
|
// NOTE: We want to return ASAP for visitedness changes, but we don't want to
|
|
|
|
// mess up the situation where the element became a link or stopped being one.
|
|
|
|
if (aChangedBits.HasAllStates(kVisitedAndUnvisited) &&
|
2018-08-14 11:47:25 +03:00
|
|
|
!Gecko_VisitedStylesEnabled(element.OwnerDoc())) {
|
|
|
|
aChangedBits &= ~kVisitedAndUnvisited;
|
|
|
|
if (aChangedBits.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-01 05:04:12 +03:00
|
|
|
if (auto changeHint = ChangeForContentStateChange(element, aChangedBits)) {
|
2019-03-14 14:47:50 +03:00
|
|
|
Servo_NoteExplicitHints(&element, RestyleHint{0}, changeHint);
|
2019-03-01 05:04:12 +03:00
|
|
|
}
|
2018-04-07 16:48:43 +03:00
|
|
|
|
|
|
|
// Don't bother taking a snapshot if no rules depend on these state bits.
|
|
|
|
//
|
|
|
|
// We always take a snapshot for the LTR/RTL event states, since Servo doesn't
|
|
|
|
// track those bits in the same way, and we know that :dir() rules are always
|
|
|
|
// present in UA style sheets.
|
|
|
|
if (!aChangedBits.HasAtLeastOneOfStates(DIRECTION_STATES) &&
|
2018-08-07 02:44:56 +03:00
|
|
|
!StyleSet()->HasStateDependency(element, aChangedBits)) {
|
2018-04-07 16:48:43 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-07 02:44:56 +03:00
|
|
|
ServoElementSnapshot& snapshot = SnapshotFor(element);
|
|
|
|
EventStates previousState = element.StyleState() ^ aChangedBits;
|
2018-04-07 16:48:43 +03:00
|
|
|
snapshot.AddState(previousState);
|
|
|
|
|
|
|
|
// Assuming we need to invalidate cached style in getComputedStyle for
|
|
|
|
// undisplayed elements, since we don't know if it is needed.
|
|
|
|
IncrementUndisplayedRestyleGeneration();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool AttributeInfluencesOtherPseudoClassState(
|
|
|
|
const Element& aElement, const nsAtom* aAttribute) {
|
|
|
|
// We must record some state for :-moz-browser-frame and
|
|
|
|
// :-moz-table-border-nonzero.
|
|
|
|
if (aAttribute == nsGkAtoms::mozbrowser) {
|
|
|
|
return aElement.IsAnyOfHTMLElements(nsGkAtoms::iframe, nsGkAtoms::frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::border) {
|
|
|
|
return aElement.IsHTMLElement(nsGkAtoms::table);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool NeedToRecordAttrChange(
|
|
|
|
const ServoStyleSet& aStyleSet, const Element& aElement,
|
|
|
|
int32_t aNameSpaceID, nsAtom* aAttribute,
|
|
|
|
bool* aInfluencesOtherPseudoClassState) {
|
|
|
|
*aInfluencesOtherPseudoClassState =
|
|
|
|
AttributeInfluencesOtherPseudoClassState(aElement, aAttribute);
|
|
|
|
|
|
|
|
// If the attribute influences one of the pseudo-classes that are backed by
|
|
|
|
// attributes, we just record it.
|
|
|
|
if (*aInfluencesOtherPseudoClassState) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We assume that id and class attributes are used in class/id selectors, and
|
|
|
|
// thus record them.
|
|
|
|
//
|
|
|
|
// TODO(emilio): We keep a filter of the ids in use somewhere in the StyleSet,
|
|
|
|
// presumably we could try to filter the old and new id, but it's not clear
|
|
|
|
// it's worth it.
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::id || aAttribute == nsGkAtoms::_class)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We always record lang="", even though we force a subtree restyle when it
|
|
|
|
// changes, since it can change how its siblings match :lang(..) due to
|
|
|
|
// selectors like :lang(..) + div.
|
|
|
|
if (aAttribute == nsGkAtoms::lang) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, just record the attribute change if a selector in the page may
|
|
|
|
// reference it from an attribute selector.
|
|
|
|
return aStyleSet.MightHaveAttributeDependency(aElement, aAttribute);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::AttributeWillChange(Element* aElement,
|
|
|
|
int32_t aNameSpaceID,
|
2019-01-29 18:27:02 +03:00
|
|
|
nsAtom* aAttribute, int32_t aModType) {
|
2018-08-07 02:44:56 +03:00
|
|
|
TakeSnapshotForAttributeChange(*aElement, aNameSpaceID, aAttribute);
|
2018-04-07 16:48:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::ClassAttributeWillBeChangedBySMIL(Element* aElement) {
|
2018-08-07 02:44:56 +03:00
|
|
|
TakeSnapshotForAttributeChange(*aElement, kNameSpaceID_None,
|
2018-04-07 16:48:43 +03:00
|
|
|
nsGkAtoms::_class);
|
|
|
|
}
|
|
|
|
|
2018-08-07 02:44:56 +03:00
|
|
|
void RestyleManager::TakeSnapshotForAttributeChange(Element& aElement,
|
2018-04-07 16:48:43 +03:00
|
|
|
int32_t aNameSpaceID,
|
|
|
|
nsAtom* aAttribute) {
|
2019-02-15 09:29:55 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mInStyleRefresh);
|
2018-04-07 16:48:43 +03:00
|
|
|
|
2018-08-07 02:44:56 +03:00
|
|
|
if (!aElement.HasServoData()) {
|
2018-04-07 16:48:43 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool influencesOtherPseudoClassState;
|
|
|
|
if (!NeedToRecordAttrChange(*StyleSet(), aElement, aNameSpaceID, aAttribute,
|
|
|
|
&influencesOtherPseudoClassState)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We cannot tell if the attribute change will affect the styles of
|
|
|
|
// undisplayed elements, because we don't actually restyle those elements
|
|
|
|
// during the restyle traversal. So just assume that the attribute change can
|
|
|
|
// cause the style to change.
|
|
|
|
IncrementUndisplayedRestyleGeneration();
|
|
|
|
|
|
|
|
// Some other random attribute changes may also affect the transitions,
|
|
|
|
// so we also set this true here.
|
|
|
|
mHaveNonAnimationRestyles = true;
|
|
|
|
|
|
|
|
ServoElementSnapshot& snapshot = SnapshotFor(aElement);
|
|
|
|
snapshot.AddAttrs(aElement, aNameSpaceID, aAttribute);
|
|
|
|
|
|
|
|
if (influencesOtherPseudoClassState) {
|
|
|
|
snapshot.AddOtherPseudoClassState(aElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For some attribute changes we must restyle the whole subtree:
|
|
|
|
//
|
|
|
|
// * <td> is affected by the cellpadding on its ancestor table
|
|
|
|
// * lwtheme and lwthemetextcolor on root element of XUL document
|
|
|
|
// affects all descendants due to :-moz-lwtheme* pseudo-classes
|
|
|
|
// * lang="" and xml:lang="" can affect all descendants due to :lang()
|
|
|
|
//
|
|
|
|
static inline bool AttributeChangeRequiresSubtreeRestyle(
|
|
|
|
const Element& aElement, nsAtom* aAttr) {
|
|
|
|
if (aAttr == nsGkAtoms::cellpadding) {
|
|
|
|
return aElement.IsHTMLElement(nsGkAtoms::table);
|
|
|
|
}
|
|
|
|
if (aAttr == nsGkAtoms::lwtheme || aAttr == nsGkAtoms::lwthemetextcolor) {
|
|
|
|
return aElement.GetNameSpaceID() == kNameSpaceID_XUL &&
|
|
|
|
&aElement == aElement.OwnerDoc()->GetRootElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
return aAttr == nsGkAtoms::lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::AttributeChanged(Element* aElement, int32_t aNameSpaceID,
|
|
|
|
nsAtom* aAttribute, int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue) {
|
|
|
|
MOZ_ASSERT(!mInStyleRefresh);
|
|
|
|
|
|
|
|
auto changeHint = nsChangeHint(0);
|
2019-03-14 14:47:50 +03:00
|
|
|
auto restyleHint = RestyleHint{0};
|
2018-04-07 16:48:43 +03:00
|
|
|
|
|
|
|
changeHint |= aElement->GetAttributeChangeHint(aAttribute, aModType);
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::style) {
|
2019-03-14 14:47:50 +03:00
|
|
|
restyleHint |= StyleRestyleHint_RESTYLE_STYLE_ATTRIBUTE;
|
2018-04-07 16:48:43 +03:00
|
|
|
} else if (AttributeChangeRequiresSubtreeRestyle(*aElement, aAttribute)) {
|
2019-03-14 14:47:50 +03:00
|
|
|
restyleHint |= RestyleHint::RestyleSubtree();
|
2018-04-07 16:48:43 +03:00
|
|
|
} else if (aElement->IsAttributeMapped(aAttribute)) {
|
2019-03-14 14:47:50 +03:00
|
|
|
// FIXME(emilio): Does this really need to re-selector-match?
|
|
|
|
restyleHint |= StyleRestyleHint_RESTYLE_SELF;
|
2018-04-07 16:48:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nsIFrame* primaryFrame = aElement->GetPrimaryFrame()) {
|
|
|
|
// See if we have appearance information for a theme.
|
|
|
|
const nsStyleDisplay* disp = primaryFrame->StyleDisplay();
|
2018-07-25 16:03:45 +03:00
|
|
|
if (disp->HasAppearance()) {
|
2018-04-07 16:48:43 +03:00
|
|
|
nsITheme* theme = PresContext()->GetTheme();
|
|
|
|
if (theme && theme->ThemeSupportsWidget(PresContext(), primaryFrame,
|
|
|
|
disp->mAppearance)) {
|
|
|
|
bool repaint = false;
|
|
|
|
theme->WidgetStateChanged(primaryFrame, disp->mAppearance, aAttribute,
|
|
|
|
&repaint, aOldValue);
|
|
|
|
if (repaint) {
|
|
|
|
changeHint |= nsChangeHint_RepaintFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
primaryFrame->AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (restyleHint || changeHint) {
|
|
|
|
Servo_NoteExplicitHints(aElement, restyleHint, changeHint);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (restyleHint) {
|
|
|
|
// Assuming we need to invalidate cached style in getComputedStyle for
|
|
|
|
// undisplayed elements, since we don't know if it is needed.
|
|
|
|
IncrementUndisplayedRestyleGeneration();
|
|
|
|
|
|
|
|
// If we change attributes, we have to mark this to be true, so we will
|
|
|
|
// increase the animation generation for the new created transition if any.
|
|
|
|
mHaveNonAnimationRestyles = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 04:14:09 +03:00
|
|
|
void RestyleManager::ReparentComputedStyleForFirstLine(nsIFrame* aFrame) {
|
2018-04-07 16:48:43 +03:00
|
|
|
// This is only called when moving frames in or out of the first-line
|
|
|
|
// pseudo-element (or one of its descendants). We can't say much about
|
|
|
|
// aFrame's ancestors, unfortunately (e.g. during a dynamic insert into
|
|
|
|
// something inside an inline-block on the first line the ancestors could be
|
|
|
|
// totally arbitrary), but we will definitely find a line frame on the
|
|
|
|
// ancestor chain. Note that the lineframe may not actually be the one that
|
|
|
|
// corresponds to ::first-line; when we're moving _out_ of the ::first-line it
|
|
|
|
// will be one of the continuations instead.
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
nsIFrame* f = aFrame->GetParent();
|
|
|
|
while (f && !f->IsLineFrame()) {
|
|
|
|
f = f->GetParent();
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(f, "Must have found a first-line frame");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-06 04:14:09 +03:00
|
|
|
DoReparentComputedStyleForFirstLine(aFrame, *StyleSet());
|
2018-04-07 16:48:43 +03:00
|
|
|
}
|
|
|
|
|
2018-04-06 04:14:09 +03:00
|
|
|
void RestyleManager::DoReparentComputedStyleForFirstLine(
|
|
|
|
nsIFrame* aFrame, ServoStyleSet& aStyleSet) {
|
2018-04-07 16:48:43 +03:00
|
|
|
if (aFrame->IsBackdropFrame()) {
|
|
|
|
// Style context of backdrop frame has no parent style, and thus we do not
|
|
|
|
// need to reparent it.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aFrame->IsPlaceholderFrame()) {
|
|
|
|
// Also reparent the out-of-flow and all its continuations. We're doing
|
|
|
|
// this to match Gecko for now, but it's not clear that this behavior is
|
|
|
|
// correct per spec. It's certainly pretty odd for out-of-flows whose
|
|
|
|
// containing block is not within the first line.
|
|
|
|
//
|
|
|
|
// Right now we're somewhat inconsistent in this testcase:
|
|
|
|
//
|
|
|
|
// <style>
|
|
|
|
// div { color: orange; clear: left; }
|
|
|
|
// div::first-line { color: blue; }
|
|
|
|
// </style>
|
|
|
|
// <div>
|
|
|
|
// <span style="float: left">What color is this text?</span>
|
|
|
|
// </div>
|
|
|
|
// <div>
|
|
|
|
// <span><span style="float: left">What color is this text?</span></span>
|
|
|
|
// </div>
|
|
|
|
//
|
|
|
|
// We make the first float orange and the second float blue. On the other
|
|
|
|
// hand, if the float were within an inline-block that was on the first
|
|
|
|
// line, arguably it _should_ inherit from the ::first-line...
|
|
|
|
nsIFrame* outOfFlow =
|
|
|
|
nsPlaceholderFrame::GetRealFrameForPlaceholder(aFrame);
|
|
|
|
MOZ_ASSERT(outOfFlow, "no out-of-flow frame");
|
|
|
|
for (; outOfFlow; outOfFlow = outOfFlow->GetNextContinuation()) {
|
2018-04-06 04:14:09 +03:00
|
|
|
DoReparentComputedStyleForFirstLine(outOfFlow, aStyleSet);
|
2018-04-07 16:48:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME(emilio): This is the only caller of GetParentComputedStyle, let's try
|
|
|
|
// to remove it?
|
|
|
|
nsIFrame* providerFrame;
|
|
|
|
ComputedStyle* newParentStyle =
|
|
|
|
aFrame->GetParentComputedStyle(&providerFrame);
|
|
|
|
// If our provider is our child, we want to reparent it first, because we
|
|
|
|
// inherit style from it.
|
|
|
|
bool isChild = providerFrame && providerFrame->GetParent() == aFrame;
|
|
|
|
nsIFrame* providerChild = nullptr;
|
|
|
|
if (isChild) {
|
2018-04-06 04:14:09 +03:00
|
|
|
DoReparentComputedStyleForFirstLine(providerFrame, aStyleSet);
|
2018-04-07 16:48:43 +03:00
|
|
|
// Get the style again after ReparentComputedStyle() which might have
|
|
|
|
// changed it.
|
|
|
|
newParentStyle = providerFrame->Style();
|
|
|
|
providerChild = providerFrame;
|
|
|
|
MOZ_ASSERT(!providerFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW),
|
|
|
|
"Out of flow provider?");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!newParentStyle) {
|
|
|
|
// No need to do anything here for this frame, but we should still reparent
|
|
|
|
// its descendants, because those may have styles that inherit from the
|
|
|
|
// parent of this frame (e.g. non-anonymous columns in an anonymous
|
|
|
|
// colgroup).
|
|
|
|
MOZ_ASSERT(aFrame->Style()->IsNonInheritingAnonBox(),
|
|
|
|
"Why did this frame not end up with a parent context?");
|
|
|
|
ReparentFrameDescendants(aFrame, providerChild, aStyleSet);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isElement = aFrame->GetContent()->IsElement();
|
|
|
|
|
2018-04-06 04:14:09 +03:00
|
|
|
// We probably don't want to initiate transitions from ReparentComputedStyle,
|
|
|
|
// since we call it during frame construction rather than in response to
|
|
|
|
// dynamic changes.
|
2018-04-07 16:48:43 +03:00
|
|
|
// Also see the comment at the start of
|
|
|
|
// nsTransitionManager::ConsiderInitiatingTransition.
|
|
|
|
//
|
|
|
|
// We don't try to do the fancy copying from previous continuations that
|
|
|
|
// GeckoRestyleManager does here, because that relies on knowing the parents
|
|
|
|
// of ComputedStyles, and we don't know those.
|
|
|
|
ComputedStyle* oldStyle = aFrame->Style();
|
|
|
|
Element* ourElement =
|
2019-02-19 16:44:33 +03:00
|
|
|
oldStyle->GetPseudoType() == PseudoStyleType::NotPseudo && isElement
|
2018-04-07 16:48:43 +03:00
|
|
|
? aFrame->GetContent()->AsElement()
|
|
|
|
: nullptr;
|
|
|
|
ComputedStyle* newParent = newParentStyle;
|
|
|
|
|
|
|
|
ComputedStyle* newParentIgnoringFirstLine;
|
2019-02-19 16:44:33 +03:00
|
|
|
if (newParent->GetPseudoType() == PseudoStyleType::firstLine) {
|
2019-02-21 00:18:14 +03:00
|
|
|
MOZ_ASSERT(
|
|
|
|
providerFrame && providerFrame->GetParent()->IsBlockFrameOrSubclass(),
|
|
|
|
"How could we get a ::first-line parent style without having "
|
|
|
|
"a ::first-line provider frame?");
|
2018-04-07 16:48:43 +03:00
|
|
|
// If newParent is a ::first-line style, get the parent blockframe, and then
|
|
|
|
// correct it for our pseudo as needed (e.g. stepping out of anon boxes).
|
|
|
|
// Use the resulting style for the "parent style ignoring ::first-line".
|
|
|
|
nsIFrame* blockFrame = providerFrame->GetParent();
|
|
|
|
nsIFrame* correctedFrame =
|
2019-02-19 16:44:33 +03:00
|
|
|
nsFrame::CorrectStyleParentFrame(blockFrame, oldStyle->GetPseudoType());
|
2018-04-07 16:48:43 +03:00
|
|
|
newParentIgnoringFirstLine = correctedFrame->Style();
|
|
|
|
} else {
|
|
|
|
newParentIgnoringFirstLine = newParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!providerFrame) {
|
|
|
|
// No providerFrame means we inherited from a display:contents thing. Our
|
|
|
|
// layout parent style is the style of our nearest ancestor frame. But we
|
|
|
|
// have to be careful to do that with our placeholder, not with us, if we're
|
|
|
|
// out of flow.
|
|
|
|
if (aFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
|
2018-06-22 01:52:15 +03:00
|
|
|
aFrame->FirstContinuation()
|
|
|
|
->GetPlaceholderFrame()
|
|
|
|
->GetLayoutParentStyleForOutOfFlow(&providerFrame);
|
2018-04-07 16:48:43 +03:00
|
|
|
} else {
|
2019-02-19 16:44:33 +03:00
|
|
|
providerFrame = nsFrame::CorrectStyleParentFrame(
|
|
|
|
aFrame->GetParent(), oldStyle->GetPseudoType());
|
2018-04-07 16:48:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ComputedStyle* layoutParent = providerFrame->Style();
|
|
|
|
|
|
|
|
RefPtr<ComputedStyle> newStyle = aStyleSet.ReparentComputedStyle(
|
|
|
|
oldStyle, newParent, newParentIgnoringFirstLine, layoutParent,
|
|
|
|
ourElement);
|
|
|
|
aFrame->SetComputedStyle(newStyle);
|
|
|
|
|
|
|
|
// This logic somewhat mirrors the logic in
|
|
|
|
// RestyleManager::ProcessPostTraversal.
|
|
|
|
if (isElement) {
|
|
|
|
// We can't use UpdateAdditionalComputedStyles as-is because it needs a
|
|
|
|
// ServoRestyleState and maintaining one of those during a _frametree_
|
|
|
|
// traversal is basically impossible.
|
|
|
|
uint32_t index = 0;
|
|
|
|
while (auto* oldAdditionalStyle =
|
|
|
|
aFrame->GetAdditionalComputedStyle(index)) {
|
|
|
|
RefPtr<ComputedStyle> newAdditionalContext =
|
|
|
|
aStyleSet.ReparentComputedStyle(oldAdditionalStyle, newStyle,
|
|
|
|
newStyle, newStyle, nullptr);
|
|
|
|
aFrame->SetAdditionalComputedStyle(index, newAdditionalContext);
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generally, owned anon boxes are our descendants. The only exceptions are
|
|
|
|
// tables (for the table wrapper) and inline frames (for the block part of the
|
|
|
|
// block-in-inline split). We're going to update our descendants when looping
|
|
|
|
// over kids, and we don't want to update the block part of a block-in-inline
|
|
|
|
// split if the inline is on the first line but the block is not (and if the
|
|
|
|
// block is, it's the child of something else on the first line and will get
|
|
|
|
// updated as a child). And given how this method ends up getting called, if
|
|
|
|
// we reach here for a table frame, we are already in the middle of
|
|
|
|
// reparenting the table wrapper frame. So no need to
|
|
|
|
// UpdateStyleOfOwnedAnonBoxes() here.
|
|
|
|
|
|
|
|
ReparentFrameDescendants(aFrame, providerChild, aStyleSet);
|
|
|
|
|
|
|
|
// We do not need to do the equivalent of UpdateFramePseudoElementStyles,
|
2018-04-19 19:18:35 +03:00
|
|
|
// because those are handled by our descendant walk.
|
2018-04-07 16:48:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void RestyleManager::ReparentFrameDescendants(nsIFrame* aFrame,
|
|
|
|
nsIFrame* aProviderChild,
|
|
|
|
ServoStyleSet& aStyleSet) {
|
2018-04-19 19:18:35 +03:00
|
|
|
if (aFrame->GetContent()->IsElement() &&
|
|
|
|
!aFrame->GetContent()->AsElement()->HasServoData()) {
|
|
|
|
// We're getting into a display: none subtree, avoid reparenting into stuff
|
|
|
|
// that is going to go away anyway in seconds.
|
|
|
|
return;
|
|
|
|
}
|
2018-04-07 16:48:43 +03:00
|
|
|
nsIFrame::ChildListIterator lists(aFrame);
|
|
|
|
for (; !lists.IsDone(); lists.Next()) {
|
|
|
|
for (nsIFrame* child : lists.CurrentList()) {
|
|
|
|
// only do frames that are in flow
|
|
|
|
if (!(child->GetStateBits() & NS_FRAME_OUT_OF_FLOW) &&
|
|
|
|
child != aProviderChild) {
|
2018-04-06 04:14:09 +03:00
|
|
|
DoReparentComputedStyleForFirstLine(child, aStyleSet);
|
2018-04-07 16:48:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-08 10:08:46 +03:00
|
|
|
} // namespace mozilla
|