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-07-08 10:08:46 +03:00
|
|
|
#include "mozilla/ServoStyleSet.h"
|
2017-02-28 05:29:28 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2016-08-12 05:01:52 +03:00
|
|
|
#include "mozilla/dom/ChildIterator.h"
|
|
|
|
#include "nsContentUtils.h"
|
2017-02-21 13:25:11 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2016-08-29 18:20:07 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2017-02-20 08:37:13 +03:00
|
|
|
#include "nsRefreshDriver.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)
|
2017-02-13 06:21:32 +03:00
|
|
|
: RestyleManager(StyleBackendType::Servo, 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;
|
|
|
|
}
|
|
|
|
|
2017-03-02 05:07:14 +03:00
|
|
|
// We allow posting restyles from within change hint handling, but not from
|
|
|
|
// within the restyle algorithm itself.
|
|
|
|
MOZ_ASSERT(!ServoStyleSet::IsInServoTraversal());
|
2017-01-29 06:59:00 +03:00
|
|
|
|
2017-02-10 05:42:30 +03:00
|
|
|
if (aRestyleHint == 0 && !aMinChangeHint) {
|
2016-07-19 04:02:55 +03:00
|
|
|
return; // Nothing to do.
|
2016-07-13 23:42:47 +03:00
|
|
|
}
|
|
|
|
|
2017-03-02 05:07:14 +03:00
|
|
|
// 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) {
|
2016-11-02 09:11:24 +03:00
|
|
|
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::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
|
|
|
}
|
|
|
|
|
2017-02-28 05:29:28 +03:00
|
|
|
|
|
|
|
// Clears HasDirtyDescendants and RestyleData from all elements in the
|
|
|
|
// subtree rooted at aElement.
|
|
|
|
static void
|
|
|
|
ClearRestyleStateFromSubtree(Element* aElement)
|
2016-11-18 11:54:10 +03:00
|
|
|
{
|
2017-02-28 05:29:28 +03:00
|
|
|
if (aElement->HasDirtyDescendantsForServo()) {
|
|
|
|
StyleChildrenIterator it(aElement);
|
|
|
|
for (nsIContent* n = it.GetNextChild(); n; n = it.GetNextChild()) {
|
|
|
|
if (n->IsElement()) {
|
|
|
|
ClearRestyleStateFromSubtree(n->AsElement());
|
|
|
|
}
|
2016-11-02 09:11:24 +03:00
|
|
|
}
|
2016-11-18 11:54:10 +03:00
|
|
|
}
|
2016-11-02 09:11:24 +03:00
|
|
|
|
2017-02-28 05:29:28 +03:00
|
|
|
Unused << Servo_TakeChangeHint(aElement);
|
2016-11-02 09:11:24 +03:00
|
|
|
aElement->UnsetHasDirtyDescendantsForServo();
|
2017-02-28 06:06:07 +03:00
|
|
|
aElement->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES);
|
2016-11-18 11:54:10 +03:00
|
|
|
}
|
|
|
|
|
2016-07-29 05:20:45 +03:00
|
|
|
void
|
2017-02-28 06:06:07 +03:00
|
|
|
ServoRestyleManager::ProcessPostTraversal(Element* aElement,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
ServoStyleSet* aStyleSet,
|
|
|
|
nsStyleChangeList& aChangeList)
|
2016-07-13 23:42:47 +03:00
|
|
|
{
|
2017-02-17 22:52:39 +03:00
|
|
|
nsIFrame* styleFrame = nsLayoutUtils::GetStyleFrame(aElement);
|
2016-11-01 13:24:58 +03:00
|
|
|
|
2017-02-28 06:06:07 +03:00
|
|
|
// Grab the change hint from Servo.
|
2017-01-06 00:12:53 +03:00
|
|
|
nsChangeHint changeHint = Servo_TakeChangeHint(aElement);
|
2017-02-28 06:06:07 +03:00
|
|
|
|
|
|
|
// Handle lazy frame construction by posting a reconstruct for any lazily-
|
|
|
|
// constructed roots.
|
|
|
|
if (aElement->HasFlag(NODE_NEEDS_FRAME)) {
|
|
|
|
changeHint |= nsChangeHint_ReconstructFrame;
|
|
|
|
// The only time the primary frame is non-null is when image maps do hacky
|
|
|
|
// SetPrimaryFrame calls.
|
|
|
|
MOZ_ASSERT_IF(styleFrame, styleFrame->GetType() == nsGkAtoms::imageFrame);
|
|
|
|
styleFrame = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-02-03 05:37:08 +03:00
|
|
|
// 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.
|
2017-02-17 22:52:39 +03:00
|
|
|
if ((styleFrame || (changeHint & nsChangeHint_ReconstructFrame)) && changeHint) {
|
2017-02-28 06:06:07 +03:00
|
|
|
aChangeList.AppendChange(styleFrame, aElement, changeHint);
|
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) {
|
2017-02-28 05:29:28 +03:00
|
|
|
ClearRestyleStateFromSubtree(aElement);
|
2016-11-01 13:24:58 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-03 23:06:57 +03:00
|
|
|
// TODO(emilio): We could avoid some refcount traffic here, specially in the
|
|
|
|
// ServoComputedValues case, which uses atomic refcounting.
|
|
|
|
//
|
|
|
|
// 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 =
|
2017-02-17 22:52:39 +03:00
|
|
|
styleFrame ? styleFrame->StyleContext() : nullptr;
|
2017-02-03 23:06:57 +03:00
|
|
|
|
2017-02-21 13:25:11 +03:00
|
|
|
UndisplayedNode* displayContentsNode = nullptr;
|
|
|
|
// FIXME(emilio, bug 1303605): This can be simpler for Servo.
|
|
|
|
// Note that we intentionally don't check for display: none content.
|
|
|
|
if (!oldStyleContext) {
|
|
|
|
displayContentsNode =
|
|
|
|
PresContext()->FrameConstructor()->GetDisplayContentsNodeFor(aElement);
|
|
|
|
if (displayContentsNode) {
|
|
|
|
oldStyleContext = displayContentsNode->mStyle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-03 23:06:57 +03:00
|
|
|
RefPtr<ServoComputedValues> computedValues =
|
|
|
|
aStyleSet->ResolveServoStyle(aElement);
|
|
|
|
|
|
|
|
// Note that we rely in the fact that we don't cascade pseudo-element styles
|
|
|
|
// separately right now (that is, if a pseudo style changes, the normal style
|
|
|
|
// changes too).
|
|
|
|
//
|
|
|
|
// Otherwise we should probably encode that information somehow to avoid
|
|
|
|
// expensive checks in the common case.
|
|
|
|
//
|
|
|
|
// Also, we're going to need to check for pseudos of display: contents
|
|
|
|
// elements, though that is buggy right now even in non-stylo mode, see
|
|
|
|
// bug 1251799.
|
|
|
|
const bool recreateContext = oldStyleContext &&
|
|
|
|
oldStyleContext->StyleSource().AsServoComputedValues() != computedValues;
|
2016-07-29 05:20:45 +03:00
|
|
|
|
2017-02-21 13:25:11 +03:00
|
|
|
RefPtr<nsStyleContext> newContext = nullptr;
|
2017-02-03 23:06:57 +03:00
|
|
|
if (recreateContext) {
|
2017-02-21 13:25:11 +03:00
|
|
|
MOZ_ASSERT(styleFrame || displayContentsNode);
|
|
|
|
newContext =
|
2016-08-07 00:18:12 +03:00
|
|
|
aStyleSet->GetContext(computedValues.forget(), aParentContext, nullptr,
|
2017-01-29 06:59:00 +03:00
|
|
|
CSSPseudoElementType::NotPseudo, aElement);
|
2016-07-15 21:48:45 +03:00
|
|
|
|
2017-02-21 18:56:43 +03:00
|
|
|
newContext->EnsureStructsForServo(oldStyleContext);
|
|
|
|
|
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.
|
2017-03-03 23:45:40 +03:00
|
|
|
// XXXbz I think the UpdateStyleOfOwnedAnonBoxes call below handles _that_
|
|
|
|
// right, but not other cases where we happen to have different styles on
|
|
|
|
// different continuations... (e.g. first-line).
|
2017-02-17 22:52:39 +03:00
|
|
|
for (nsIFrame* f = styleFrame; f;
|
2016-07-29 05:20:45 +03:00
|
|
|
f = GetNextContinuationWithSameStyle(f, oldStyleContext)) {
|
|
|
|
f->SetStyleContext(newContext);
|
|
|
|
}
|
|
|
|
|
2017-02-21 13:25:11 +03:00
|
|
|
if (MOZ_UNLIKELY(displayContentsNode)) {
|
|
|
|
MOZ_ASSERT(!styleFrame);
|
|
|
|
displayContentsNode->mStyle = newContext;
|
|
|
|
}
|
|
|
|
|
2017-03-03 23:44:48 +03:00
|
|
|
if (styleFrame) {
|
2017-02-28 06:06:07 +03:00
|
|
|
styleFrame->UpdateStyleOfOwnedAnonBoxes(*aStyleSet, aChangeList, changeHint);
|
2017-03-03 23:44:48 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-02-28 06:06:07 +03:00
|
|
|
bool descendantsNeedFrames = aElement->HasFlag(NODE_DESCENDANTS_NEED_FRAMES);
|
|
|
|
bool traverseElementChildren =
|
|
|
|
aElement->HasDirtyDescendantsForServo() || descendantsNeedFrames;
|
|
|
|
bool traverseTextChildren = recreateContext || descendantsNeedFrames;
|
2016-11-02 09:11:24 +03:00
|
|
|
if (traverseElementChildren || traverseTextChildren) {
|
2017-02-21 13:25:11 +03:00
|
|
|
nsStyleContext* upToDateContext =
|
|
|
|
recreateContext ? newContext : oldStyleContext;
|
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
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-02-28 06:06:07 +03:00
|
|
|
ProcessPostTraversal(n->AsElement(), upToDateContext,
|
|
|
|
aStyleSet, aChangeList);
|
2016-11-02 09:11:24 +03:00
|
|
|
} else if (traverseTextChildren && n->IsNodeOfType(nsINode::eTEXT)) {
|
2017-02-28 06:06:07 +03:00
|
|
|
ProcessPostTraversalForText(n, upToDateContext, aStyleSet, aChangeList);
|
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();
|
2017-02-28 06:06:07 +03:00
|
|
|
aElement->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES);
|
2016-07-13 23:42:47 +03:00
|
|
|
}
|
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
void
|
2017-02-28 06:06:07 +03:00
|
|
|
ServoRestyleManager::ProcessPostTraversalForText(nsIContent* aTextNode,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
ServoStyleSet* aStyleSet,
|
|
|
|
nsStyleChangeList& aChangeList)
|
2016-07-23 01:19:30 +03:00
|
|
|
{
|
2017-02-28 06:06:07 +03:00
|
|
|
// Handle lazy frame construction.
|
|
|
|
if (aTextNode->HasFlag(NODE_NEEDS_FRAME)) {
|
|
|
|
aChangeList.AppendChange(nullptr, aTextNode, nsChangeHint_ReconstructFrame);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle restyle.
|
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;
|
|
|
|
}
|
|
|
|
|
2017-02-21 13:25:11 +03:00
|
|
|
// FIXME(emilio): Need to take into account display: contents pseudos!
|
2016-08-12 05:01:52 +03:00
|
|
|
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
|
|
|
|
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
|
|
|
|
2017-02-20 08:37:13 +03:00
|
|
|
// Ensure the refresh driver is active during traversal to avoid mutating
|
|
|
|
// mActiveTimer and mMostRecentRefresh time.
|
|
|
|
PresContext()->RefreshDriver()->MostRecentRefresh();
|
|
|
|
|
2017-02-10 05:42:30 +03:00
|
|
|
|
2017-03-02 05:07:14 +03:00
|
|
|
// 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;
|
|
|
|
while (styleSet->StyleDocument()) {
|
2017-01-24 10:27:56 +03:00
|
|
|
PresContext()->EffectCompositor()->ClearElementsToRestyle();
|
2016-11-08 11:24:34 +03:00
|
|
|
|
2017-02-28 06:06:07 +03:00
|
|
|
// Recreate style contexts, and queue up change hints (which also handle
|
|
|
|
// lazy frame construction).
|
2016-11-02 09:11:24 +03:00
|
|
|
nsStyleChangeList currentChanges;
|
2016-12-01 11:19:50 +03:00
|
|
|
DocumentStyleRootIterator iter(doc);
|
|
|
|
while (Element* root = iter.GetNextStyleRoot()) {
|
2017-02-28 06:06:07 +03:00
|
|
|
ProcessPostTraversal(root, nullptr, styleSet, currentChanges);
|
2016-12-01 11:19:50 +03:00
|
|
|
}
|
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
|
|
|
|
2017-02-11 11:50:02 +03:00
|
|
|
IncrementRestyleGeneration();
|
2016-11-02 09:11:24 +03:00
|
|
|
}
|
2016-08-12 00:12:49 +03:00
|
|
|
|
2017-02-10 05:42:30 +03:00
|
|
|
mInStyleRefresh = false;
|
2017-03-02 05:07:14 +03:00
|
|
|
styleSet->AssertTreeIsClean();
|
2017-02-10 05:42:30 +03:00
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
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
|