2016-02-24 10:01:12 +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/. */
|
|
|
|
|
|
|
|
#include "mozilla/ServoRestyleManager.h"
|
2016-12-01 11:19:50 +03:00
|
|
|
|
|
|
|
#include "mozilla/DocumentStyleRootIterator.h"
|
2016-10-24 12:16:46 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2016-12-01 11:19:50 +03:00
|
|
|
#include "mozilla/ServoRestyleManagerInlines.h"
|
2016-07-08 10:08:46 +03:00
|
|
|
#include "mozilla/ServoStyleSet.h"
|
2016-08-12 05:01:52 +03:00
|
|
|
#include "mozilla/dom/ChildIterator.h"
|
|
|
|
#include "nsContentUtils.h"
|
2016-08-29 18:20:07 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2016-08-12 05:01:52 +03:00
|
|
|
#include "nsStyleChangeList.h"
|
2016-02-24 10:01:12 +03:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-07-08 10:08:46 +03:00
|
|
|
ServoRestyleManager::ServoRestyleManager(nsPresContext* aPresContext)
|
|
|
|
: RestyleManagerBase(aPresContext)
|
2016-11-02 09:11:24 +03:00
|
|
|
, mReentrantChanges(nullptr)
|
2016-05-05 07:01:37 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
void
|
|
|
|
ServoRestyleManager::PostRestyleEvent(Element* aElement,
|
|
|
|
nsRestyleHint aRestyleHint,
|
|
|
|
nsChangeHint aMinChangeHint)
|
|
|
|
{
|
2017-01-14 12:39:33 +03:00
|
|
|
MOZ_ASSERT(!(aMinChangeHint & nsChangeHint_NeutralChange),
|
|
|
|
"Didn't expect explicit change hints to be neutral!");
|
2016-07-08 10:08:46 +03:00
|
|
|
if (MOZ_UNLIKELY(IsDisconnected()) ||
|
|
|
|
MOZ_UNLIKELY(PresContext()->PresShell()->IsDestroying())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-19 04:02:55 +03:00
|
|
|
if (aRestyleHint == 0 && !aMinChangeHint && !HasPendingRestyles()) {
|
|
|
|
return; // Nothing to do.
|
2016-07-13 23:42:47 +03:00
|
|
|
}
|
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
// We allow posting change hints during restyling, but not restyle hints
|
|
|
|
// themselves, since those would require us to re-traverse the tree.
|
|
|
|
MOZ_ASSERT_IF(mInStyleRefresh, aRestyleHint == 0);
|
|
|
|
|
|
|
|
// Processing change hints sometimes causes new change hints to be generated.
|
|
|
|
// Doing this after the gecko post-traversal is problematic, so instead we just
|
|
|
|
// queue them up for special handling.
|
|
|
|
if (mReentrantChanges) {
|
|
|
|
MOZ_ASSERT(aRestyleHint == 0);
|
|
|
|
mReentrantChanges->AppendElement(ReentrantChange { aElement, aMinChangeHint });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-03 06:41:02 +03:00
|
|
|
// XXX This is a temporary hack to make style attribute change works.
|
|
|
|
// In the future, we should be able to use this hint directly.
|
|
|
|
if (aRestyleHint & eRestyle_StyleAttribute) {
|
2016-11-08 05:39:30 +03:00
|
|
|
aRestyleHint &= ~eRestyle_StyleAttribute;
|
|
|
|
aRestyleHint |= eRestyle_Self | eRestyle_Subtree;
|
2016-11-03 06:41:02 +03:00
|
|
|
}
|
|
|
|
|
2016-12-19 09:30:09 +03:00
|
|
|
// XXX For now, convert eRestyle_Subtree into (eRestyle_Self |
|
|
|
|
// eRestyle_SomeDescendants), which Servo will interpret as
|
|
|
|
// RESTYLE_SELF | RESTYLE_DESCENDANTS, since this is a commonly
|
|
|
|
// posted restyle hint that doesn't yet align with RestyleHint's
|
|
|
|
// bits.
|
|
|
|
if (aRestyleHint & eRestyle_Subtree) {
|
|
|
|
aRestyleHint &= ~eRestyle_Subtree;
|
|
|
|
aRestyleHint |= eRestyle_Self | eRestyle_SomeDescendants;
|
|
|
|
}
|
|
|
|
|
2016-07-19 04:02:55 +03:00
|
|
|
if (aRestyleHint || aMinChangeHint) {
|
2016-11-02 09:11:24 +03:00
|
|
|
Servo_NoteExplicitHints(aElement, aRestyleHint, aMinChangeHint);
|
2016-07-08 10:08:46 +03:00
|
|
|
}
|
|
|
|
|
2016-08-04 04:58:06 +03:00
|
|
|
PostRestyleEventInternal(false);
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoRestyleManager::PostRestyleEventForLazyConstruction()
|
|
|
|
{
|
2016-08-04 04:58:06 +03:00
|
|
|
PostRestyleEventInternal(true);
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoRestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint,
|
|
|
|
nsRestyleHint aRestyleHint)
|
|
|
|
{
|
2017-01-15 01:34:49 +03:00
|
|
|
// TODO(emilio, bz): We probably need to do some actual restyling here too.
|
|
|
|
NS_WARNING("stylo: ServoRestyleManager::RebuildAllStyleData is incomplete");
|
|
|
|
StyleSet()->RebuildData();
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoRestyleManager::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
|
|
|
|
nsRestyleHint aRestyleHint)
|
|
|
|
{
|
2016-08-03 20:35:59 +03:00
|
|
|
NS_WARNING("stylo: ServoRestyleManager::PostRebuildAllStyleDataEvent not implemented");
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
/* static */ void
|
|
|
|
ServoRestyleManager::ClearServoDataFromSubtree(Element* aElement)
|
2016-11-09 09:25:58 +03:00
|
|
|
{
|
2016-11-02 09:11:24 +03:00
|
|
|
aElement->ClearServoData();
|
2016-11-09 09:25:58 +03:00
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
StyleChildrenIterator it(aElement);
|
|
|
|
for (nsIContent* n = it.GetNextChild(); n; n = it.GetNextChild()) {
|
|
|
|
if (n->IsElement()) {
|
|
|
|
ClearServoDataFromSubtree(n->AsElement());
|
2016-11-09 09:25:58 +03:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 09:11:24 +03:00
|
|
|
|
|
|
|
aElement->UnsetHasDirtyDescendantsForServo();
|
2016-11-09 09:25:58 +03:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:54:10 +03:00
|
|
|
/* static */ void
|
2016-11-02 09:11:24 +03:00
|
|
|
ServoRestyleManager::ClearDirtyDescendantsFromSubtree(Element* aElement)
|
2016-11-18 11:54:10 +03:00
|
|
|
{
|
2016-11-02 09:11:24 +03:00
|
|
|
StyleChildrenIterator it(aElement);
|
2016-11-18 11:54:10 +03:00
|
|
|
for (nsIContent* n = it.GetNextChild(); n; n = it.GetNextChild()) {
|
2016-11-02 09:11:24 +03:00
|
|
|
if (n->IsElement()) {
|
|
|
|
ClearDirtyDescendantsFromSubtree(n->AsElement());
|
|
|
|
}
|
2016-11-18 11:54:10 +03:00
|
|
|
}
|
2016-11-02 09:11:24 +03:00
|
|
|
|
|
|
|
aElement->UnsetHasDirtyDescendantsForServo();
|
2016-11-18 11:54:10 +03:00
|
|
|
}
|
|
|
|
|
2016-07-29 05:20:45 +03:00
|
|
|
void
|
2016-11-02 09:11:24 +03:00
|
|
|
ServoRestyleManager::RecreateStyleContexts(Element* aElement,
|
2016-07-13 23:42:47 +03:00
|
|
|
nsStyleContext* aParentContext,
|
2016-07-29 05:20:45 +03:00
|
|
|
ServoStyleSet* aStyleSet,
|
|
|
|
nsStyleChangeList& aChangeListToProcess)
|
2016-07-13 23:42:47 +03:00
|
|
|
{
|
2016-11-02 09:11:24 +03:00
|
|
|
nsIFrame* primaryFrame = aElement->GetPrimaryFrame();
|
2016-11-01 13:24:58 +03:00
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
// FIXME(bholley): Once we transfer ownership of the styles to the frame, we
|
|
|
|
// can fast-reject without the FFI call by checking mServoData for null.
|
2017-01-06 00:12:53 +03:00
|
|
|
nsChangeHint changeHint = Servo_TakeChangeHint(aElement);
|
2017-01-14 12:39:33 +03:00
|
|
|
if (changeHint & ~nsChangeHint_NeutralChange) {
|
|
|
|
aChangeListToProcess.AppendChange(
|
|
|
|
primaryFrame, aElement, changeHint & ~nsChangeHint_NeutralChange);
|
2016-07-13 23:42:47 +03:00
|
|
|
}
|
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
// 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) {
|
|
|
|
ClearDirtyDescendantsFromSubtree(aElement);
|
2016-11-01 13:24:58 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
// If we have a frame and a non-zero + non-reconstruct change hint, we need to
|
|
|
|
// attach a new style context.
|
|
|
|
bool recreateContext = primaryFrame && changeHint;
|
|
|
|
if (recreateContext) {
|
2017-01-06 00:12:53 +03:00
|
|
|
RefPtr<ServoComputedValues> computedValues = aStyleSet->ResolveServoStyle(aElement);
|
2016-07-29 05:20:45 +03:00
|
|
|
|
2016-08-07 00:18:12 +03:00
|
|
|
// Hold the old style context alive, because it could become a dangling
|
|
|
|
// pointer during the replacement. In practice it's not a huge deal (on
|
|
|
|
// GetNextContinuationWithSameStyle the pointer is not dereferenced, only
|
|
|
|
// compared), but better not playing with dangling pointers if not needed.
|
|
|
|
RefPtr<nsStyleContext> oldStyleContext = primaryFrame->StyleContext();
|
|
|
|
MOZ_ASSERT(oldStyleContext);
|
2016-07-15 21:48:45 +03:00
|
|
|
|
2016-07-29 05:20:45 +03:00
|
|
|
RefPtr<nsStyleContext> newContext =
|
2016-08-07 00:18:12 +03:00
|
|
|
aStyleSet->GetContext(computedValues.forget(), aParentContext, nullptr,
|
2016-07-15 21:48:45 +03:00
|
|
|
CSSPseudoElementType::NotPseudo);
|
|
|
|
|
2016-08-07 00:18:12 +03:00
|
|
|
// XXX This could not always work as expected: there are kinds of content
|
2016-07-29 05:20:45 +03:00
|
|
|
// with the first split and the last sharing style, but others not. We
|
|
|
|
// should handle those properly.
|
|
|
|
for (nsIFrame* f = primaryFrame; f;
|
|
|
|
f = GetNextContinuationWithSameStyle(f, oldStyleContext)) {
|
|
|
|
f->SetStyleContext(newContext);
|
|
|
|
}
|
|
|
|
|
2016-08-12 05:01:52 +03:00
|
|
|
// Update pseudo-elements state if appropriate.
|
2016-11-01 13:24:58 +03:00
|
|
|
const static CSSPseudoElementType pseudosToRestyle[] = {
|
|
|
|
CSSPseudoElementType::before,
|
|
|
|
CSSPseudoElementType::after,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (CSSPseudoElementType pseudoType : pseudosToRestyle) {
|
|
|
|
nsIAtom* pseudoTag = nsCSSPseudoElements::GetPseudoAtom(pseudoType);
|
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
if (nsIFrame* pseudoFrame = FrameForPseudoElement(aElement, pseudoTag)) {
|
2016-11-01 13:24:58 +03:00
|
|
|
// TODO: we could maybe make this more performant via calling into
|
|
|
|
// Servo just once to know which pseudo-elements we've got to restyle?
|
|
|
|
RefPtr<nsStyleContext> pseudoContext =
|
2016-11-02 09:11:24 +03:00
|
|
|
aStyleSet->ProbePseudoElementStyle(aElement, pseudoType, newContext);
|
|
|
|
MOZ_ASSERT(pseudoContext, "should have taken the ReconstructFrame path above");
|
|
|
|
pseudoFrame->SetStyleContext(pseudoContext);
|
|
|
|
|
|
|
|
// We only care restyling text nodes, since other type of nodes
|
|
|
|
// (images), are still not supported. If that eventually changes, we
|
|
|
|
// may have to write more code here... Or not, I don't think too
|
|
|
|
// many inherited properties can affect those other frames.
|
|
|
|
StyleChildrenIterator it(pseudoFrame->GetContent());
|
|
|
|
for (nsIContent* n = it.GetNextChild(); n; n = it.GetNextChild()) {
|
|
|
|
if (n->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
RefPtr<nsStyleContext> childContext =
|
|
|
|
aStyleSet->ResolveStyleForText(n, pseudoContext);
|
|
|
|
MOZ_ASSERT(n->GetPrimaryFrame(),
|
|
|
|
"How? This node is created at FC time!");
|
|
|
|
n->GetPrimaryFrame()->SetStyleContext(childContext);
|
2016-08-12 05:01:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-15 21:48:45 +03:00
|
|
|
}
|
2016-07-13 23:42:47 +03:00
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
bool traverseElementChildren = aElement->HasDirtyDescendantsForServo();
|
|
|
|
bool traverseTextChildren = recreateContext;
|
|
|
|
if (traverseElementChildren || traverseTextChildren) {
|
|
|
|
StyleChildrenIterator it(aElement);
|
2016-07-15 21:48:45 +03:00
|
|
|
for (nsIContent* n = it.GetNextChild(); n; n = it.GetNextChild()) {
|
2016-11-02 09:11:24 +03:00
|
|
|
if (traverseElementChildren && n->IsElement()) {
|
2017-01-12 05:48:13 +03:00
|
|
|
if (!primaryFrame) {
|
|
|
|
// The frame constructor presumably decided to suppress frame
|
|
|
|
// construction on this subtree. Just clear the dirty descendants
|
|
|
|
// bit from the subtree, since there's no point in harvesting the
|
|
|
|
// change hints.
|
|
|
|
MOZ_ASSERT(!n->AsElement()->GetPrimaryFrame(),
|
|
|
|
"Only display:contents should do this, and we don't handle that yet");
|
|
|
|
ClearDirtyDescendantsFromSubtree(n->AsElement());
|
|
|
|
} else {
|
|
|
|
RecreateStyleContexts(n->AsElement(), primaryFrame->StyleContext(),
|
|
|
|
aStyleSet, aChangeListToProcess);
|
|
|
|
}
|
2016-11-02 09:11:24 +03:00
|
|
|
} else if (traverseTextChildren && n->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
RecreateStyleContextsForText(n, primaryFrame->StyleContext(),
|
|
|
|
aStyleSet);
|
2016-11-01 13:24:58 +03:00
|
|
|
}
|
2016-07-15 21:48:45 +03:00
|
|
|
}
|
2016-07-13 23:42:47 +03:00
|
|
|
}
|
2016-11-02 09:11:24 +03:00
|
|
|
|
|
|
|
aElement->UnsetHasDirtyDescendantsForServo();
|
2016-07-13 23:42:47 +03:00
|
|
|
}
|
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
void
|
|
|
|
ServoRestyleManager::RecreateStyleContextsForText(nsIContent* aTextNode,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
ServoStyleSet* aStyleSet)
|
2016-07-23 01:19:30 +03:00
|
|
|
{
|
2016-11-02 09:11:24 +03:00
|
|
|
nsIFrame* primaryFrame = aTextNode->GetPrimaryFrame();
|
|
|
|
if (primaryFrame) {
|
|
|
|
RefPtr<nsStyleContext> oldStyleContext = primaryFrame->StyleContext();
|
|
|
|
RefPtr<nsStyleContext> newContext =
|
|
|
|
aStyleSet->ResolveStyleForText(aTextNode, aParentContext);
|
2016-07-23 01:19:30 +03:00
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
for (nsIFrame* f = primaryFrame; f;
|
|
|
|
f = GetNextContinuationWithSameStyle(f, oldStyleContext)) {
|
|
|
|
f->SetStyleContext(newContext);
|
|
|
|
}
|
2016-07-23 01:19:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 05:01:52 +03:00
|
|
|
/* static */ nsIFrame*
|
2016-10-18 07:29:03 +03:00
|
|
|
ServoRestyleManager::FrameForPseudoElement(const nsIContent* aContent,
|
2016-08-12 05:01:52 +03:00
|
|
|
nsIAtom* aPseudoTagOrNull)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT_IF(aPseudoTagOrNull, aContent->IsElement());
|
|
|
|
nsIFrame* primaryFrame = aContent->GetPrimaryFrame();
|
|
|
|
|
|
|
|
if (!aPseudoTagOrNull) {
|
|
|
|
return primaryFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!primaryFrame) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: we probably need to special-case display: contents here. Gecko's
|
|
|
|
// RestyleManager passes the primary frame of the parent instead.
|
|
|
|
if (aPseudoTagOrNull == nsCSSPseudoElements::before) {
|
|
|
|
return nsLayoutUtils::GetBeforeFrameForContent(primaryFrame, aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPseudoTagOrNull == nsCSSPseudoElements::after) {
|
|
|
|
return nsLayoutUtils::GetAfterFrameForContent(primaryFrame, aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Unkown pseudo-element given to "
|
|
|
|
"ServoRestyleManager::FrameForPseudoElement");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
void
|
|
|
|
ServoRestyleManager::ProcessPendingRestyles()
|
|
|
|
{
|
2016-07-29 05:20:45 +03:00
|
|
|
MOZ_ASSERT(PresContext()->Document(), "No document? Pshaw!");
|
|
|
|
MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript(), "Missing a script blocker!");
|
2016-08-31 04:06:47 +03:00
|
|
|
|
|
|
|
if (MOZ_UNLIKELY(!PresContext()->PresShell()->DidInitialize())) {
|
|
|
|
// PresShell::FlushPendingNotifications doesn't early-return in the case
|
|
|
|
// where the PreShell 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.
|
2016-07-18 21:28:27 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-07-13 23:42:47 +03:00
|
|
|
|
2016-08-31 04:06:47 +03:00
|
|
|
if (!HasPendingRestyles()) {
|
2016-07-27 03:06:25 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-27 07:45:46 +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);
|
|
|
|
|
2016-08-31 04:06:47 +03:00
|
|
|
ServoStyleSet* styleSet = StyleSet();
|
2016-07-13 23:42:47 +03:00
|
|
|
nsIDocument* doc = PresContext()->Document();
|
2016-07-19 04:02:55 +03:00
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
// XXXbholley: Should this be while() per bug 1316247?
|
|
|
|
if (HasPendingRestyles()) {
|
|
|
|
mInStyleRefresh = true;
|
|
|
|
styleSet->StyleDocument();
|
2017-01-24 10:27:56 +03:00
|
|
|
PresContext()->EffectCompositor()->ClearElementsToRestyle();
|
2016-11-08 11:24:34 +03:00
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
// First do any queued-up frame creation. (see bugs 827239 and 997506).
|
|
|
|
//
|
|
|
|
// XXXEmilio I'm calling this to avoid random behavior changes, since we
|
|
|
|
// delay frame construction after styling we should re-check once our
|
|
|
|
// model is more stable whether we can skip this call.
|
|
|
|
//
|
|
|
|
// Note this has to be *after* restyling, because otherwise frame
|
|
|
|
// construction will find unstyled nodes, and that's not funny.
|
|
|
|
PresContext()->FrameConstructor()->CreateNeededFrames();
|
2016-11-09 09:25:28 +03:00
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
// Recreate style contexts and queue up change hints.
|
|
|
|
nsStyleChangeList currentChanges;
|
2016-12-01 11:19:50 +03:00
|
|
|
DocumentStyleRootIterator iter(doc);
|
|
|
|
while (Element* root = iter.GetNextStyleRoot()) {
|
|
|
|
RecreateStyleContexts(root, nullptr, styleSet, currentChanges);
|
|
|
|
}
|
2016-08-04 04:58:06 +03:00
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
// 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.
|
|
|
|
ReentrantChangeList newChanges;
|
|
|
|
mReentrantChanges = &newChanges;
|
|
|
|
while (!currentChanges.IsEmpty()) {
|
|
|
|
ProcessRestyledFrames(currentChanges);
|
|
|
|
MOZ_ASSERT(currentChanges.IsEmpty());
|
|
|
|
for (ReentrantChange& change: newChanges) {
|
|
|
|
currentChanges.AppendChange(change.mContent->GetPrimaryFrame(),
|
|
|
|
change.mContent, change.mHint);
|
|
|
|
}
|
|
|
|
newChanges.Clear();
|
2016-07-28 00:00:29 +03:00
|
|
|
}
|
2016-11-02 09:11:24 +03:00
|
|
|
mReentrantChanges = nullptr;
|
2016-07-13 23:42:47 +03:00
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
styleSet->AssertTreeIsClean();
|
|
|
|
mInStyleRefresh = false;
|
|
|
|
}
|
2016-08-12 00:12:49 +03:00
|
|
|
|
2016-07-08 10:08:46 +03:00
|
|
|
IncrementRestyleGeneration();
|
2017-01-27 07:45:46 +03:00
|
|
|
|
|
|
|
// Note: We are in the scope of |animationsWithDestroyedFrame|, so
|
|
|
|
// |mAnimationsWithDestroyedFrame| is still valid.
|
|
|
|
MOZ_ASSERT(mAnimationsWithDestroyedFrame);
|
|
|
|
mAnimationsWithDestroyedFrame->StopAnimationsForElementsWithoutFrames();
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-16 21:33:30 +03:00
|
|
|
ServoRestyleManager::RestyleForInsertOrChange(nsINode* aContainer,
|
2016-02-24 10:01:12 +03:00
|
|
|
nsIContent* aChild)
|
|
|
|
{
|
2016-08-11 21:48:27 +03:00
|
|
|
//
|
|
|
|
// XXXbholley: We need the Gecko logic here to correctly restyle for things
|
|
|
|
// like :empty and positional selectors (though we may not need to post
|
|
|
|
// restyle events as agressively as the Gecko path does).
|
|
|
|
//
|
|
|
|
// Bug 1297899 tracks this work.
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-16 21:33:30 +03:00
|
|
|
ServoRestyleManager::ContentInserted(nsINode* aContainer, nsIContent* aChild)
|
2016-08-11 21:48:27 +03:00
|
|
|
{
|
|
|
|
RestyleForInsertOrChange(aContainer, aChild);
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-16 21:33:30 +03:00
|
|
|
ServoRestyleManager::RestyleForAppend(nsIContent* aContainer,
|
2016-02-24 10:01:12 +03:00
|
|
|
nsIContent* aFirstNewContent)
|
|
|
|
{
|
2016-08-11 21:48:27 +03:00
|
|
|
//
|
|
|
|
// XXXbholley: We need the Gecko logic here to correctly restyle for things
|
|
|
|
// like :empty and positional selectors (though we may not need to post
|
|
|
|
// restyle events as agressively as the Gecko path does).
|
|
|
|
//
|
|
|
|
// Bug 1297899 tracks this work.
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-16 21:33:30 +03:00
|
|
|
ServoRestyleManager::ContentAppended(nsIContent* aContainer,
|
2016-08-11 21:48:27 +03:00
|
|
|
nsIContent* aFirstNewContent)
|
|
|
|
{
|
|
|
|
RestyleForAppend(aContainer, aFirstNewContent);
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-08-16 21:33:30 +03:00
|
|
|
ServoRestyleManager::ContentRemoved(nsINode* aContainer,
|
2016-08-11 21:48:27 +03:00
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aFollowingSibling)
|
2016-02-24 10:01:12 +03:00
|
|
|
{
|
2016-08-11 21:48:27 +03:00
|
|
|
NS_WARNING("stylo: ServoRestyleManager::ContentRemoved not implemented");
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoRestyleManager::ContentStateChanged(nsIContent* aContent,
|
2016-07-19 04:02:55 +03:00
|
|
|
EventStates aChangedBits)
|
2016-02-24 10:01:12 +03:00
|
|
|
{
|
2016-07-08 10:08:46 +03:00
|
|
|
if (!aContent->IsElement()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Element* aElement = aContent->AsElement();
|
|
|
|
nsChangeHint changeHint;
|
|
|
|
nsRestyleHint restyleHint;
|
2016-07-19 04:02:55 +03:00
|
|
|
|
|
|
|
// NOTE: restyleHint here is effectively always 0, since that's what
|
|
|
|
// ServoStyleSet::HasStateDependentStyle returns. Servo computes on
|
|
|
|
// ProcessPendingRestyles using the ElementSnapshot, but in theory could
|
|
|
|
// compute it sequentially easily.
|
|
|
|
//
|
|
|
|
// Determine what's the best way to do it, and how much work do we save
|
|
|
|
// processing the restyle hint early (i.e., computing the style hint here
|
|
|
|
// sequentially, potentially saving the snapshot), vs lazily (snapshot
|
|
|
|
// approach).
|
|
|
|
//
|
|
|
|
// If we take the sequential approach we need to specialize Servo's restyle
|
|
|
|
// hints system a bit more, and mesure whether we save something storing the
|
|
|
|
// restyle hint in the table and deferring the dirtiness setting until
|
|
|
|
// ProcessPendingRestyles (that's a requirement if we store snapshots though),
|
|
|
|
// vs processing the restyle hint in-place, dirtying the nodes on
|
|
|
|
// PostRestyleEvent.
|
|
|
|
//
|
|
|
|
// If we definitely take the snapshot approach, we should take rid of
|
|
|
|
// HasStateDependentStyle, etc (though right now they're no-ops).
|
|
|
|
ContentStateChangedInternal(aElement, aChangedBits, &changeHint,
|
|
|
|
&restyleHint);
|
|
|
|
|
|
|
|
EventStates previousState = aElement->StyleState() ^ aChangedBits;
|
2016-11-02 09:11:24 +03:00
|
|
|
ServoElementSnapshot* snapshot = Servo_Element_GetSnapshot(aElement);
|
|
|
|
if (snapshot) {
|
|
|
|
snapshot->AddState(previousState);
|
|
|
|
PostRestyleEvent(aElement, restyleHint, changeHint);
|
|
|
|
}
|
2016-07-08 10:08:46 +03:00
|
|
|
|
2016-05-05 07:01:37 +03:00
|
|
|
return NS_OK;
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoRestyleManager::AttributeWillChange(Element* aElement,
|
|
|
|
int32_t aNameSpaceID,
|
2016-07-19 04:02:55 +03:00
|
|
|
nsIAtom* aAttribute, int32_t aModType,
|
2016-02-24 10:01:12 +03:00
|
|
|
const nsAttrValue* aNewValue)
|
|
|
|
{
|
2016-11-02 09:11:24 +03:00
|
|
|
ServoElementSnapshot* snapshot = Servo_Element_GetSnapshot(aElement);
|
|
|
|
if (snapshot) {
|
|
|
|
snapshot->AddAttrs(aElement);
|
|
|
|
}
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
2016-11-03 06:41:02 +03:00
|
|
|
void
|
|
|
|
ServoRestyleManager::AttributeChanged(Element* aElement, int32_t aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute, int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue)
|
|
|
|
{
|
2016-11-02 09:11:24 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
ServoElementSnapshot* snapshot = Servo_Element_GetSnapshot(aElement);
|
|
|
|
MOZ_ASSERT_IF(snapshot, snapshot->HasAttrs());
|
|
|
|
#endif
|
2016-11-03 06:41:02 +03:00
|
|
|
if (aAttribute == nsGkAtoms::style) {
|
|
|
|
PostRestyleEvent(aElement, eRestyle_StyleAttribute, nsChangeHint(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
nsresult
|
|
|
|
ServoRestyleManager::ReparentStyleContext(nsIFrame* aFrame)
|
|
|
|
{
|
2016-07-29 01:22:54 +03:00
|
|
|
NS_WARNING("stylo: ServoRestyleManager::ReparentStyleContext not implemented");
|
2016-06-10 10:07:17 +03:00
|
|
|
return NS_OK;
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|