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-07-08 10:08:46 +03:00
|
|
|
#include "mozilla/ServoStyleSet.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-05-05 07:01:37 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-13 23:42:47 +03:00
|
|
|
/* static */ void
|
|
|
|
ServoRestyleManager::DirtyTree(nsIContent* aContent)
|
2016-02-24 10:01:12 +03:00
|
|
|
{
|
2016-07-13 23:42:47 +03:00
|
|
|
if (aContent->IsDirtyForServo()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aContent->SetIsDirtyForServo();
|
|
|
|
|
|
|
|
FlattenedChildIterator it(aContent);
|
|
|
|
|
|
|
|
nsIContent* n = it.GetNextChild();
|
|
|
|
bool hadChildren = bool(n);
|
|
|
|
for ( ; n; n = it.GetNextChild()) {
|
|
|
|
DirtyTree(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hadChildren) {
|
|
|
|
aContent->SetHasDirtyDescendantsForServo();
|
|
|
|
}
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoRestyleManager::PostRestyleEvent(Element* aElement,
|
|
|
|
nsRestyleHint aRestyleHint,
|
|
|
|
nsChangeHint aMinChangeHint)
|
|
|
|
{
|
2016-07-08 10:08:46 +03:00
|
|
|
if (MOZ_UNLIKELY(IsDisconnected()) ||
|
|
|
|
MOZ_UNLIKELY(PresContext()->PresShell()->IsDestroying())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-13 23:42:47 +03:00
|
|
|
if (aRestyleHint == 0 && !aMinChangeHint) {
|
|
|
|
// Nothing to do here
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-08 10:08:46 +03:00
|
|
|
nsIPresShell* presShell = PresContext()->PresShell();
|
|
|
|
if (!ObservingRefreshDriver()) {
|
|
|
|
SetObservingRefreshDriver(PresContext()->RefreshDriver()->
|
|
|
|
AddStyleFlushObserver(presShell));
|
|
|
|
}
|
|
|
|
|
2016-07-13 23:42:47 +03:00
|
|
|
// Propagate the IS_DIRTY flag down the tree.
|
|
|
|
DirtyTree(aElement);
|
|
|
|
|
|
|
|
// Propagate the HAS_DIRTY_DESCENDANTS flag to the root.
|
2016-07-08 10:08:46 +03:00
|
|
|
nsINode* cur = aElement;
|
|
|
|
while ((cur = cur->GetParentNode())) {
|
|
|
|
if (cur->HasDirtyDescendantsForServo())
|
|
|
|
break;
|
|
|
|
cur->SetHasDirtyDescendantsForServo();
|
|
|
|
}
|
|
|
|
|
|
|
|
presShell->GetDocument()->SetNeedStyleFlush();
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoRestyleManager::PostRestyleEventForLazyConstruction()
|
|
|
|
{
|
2016-05-05 07:01:37 +03:00
|
|
|
NS_ERROR("stylo: ServoRestyleManager::PostRestyleEventForLazyConstruction not implemented");
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoRestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint,
|
|
|
|
nsRestyleHint aRestyleHint)
|
|
|
|
{
|
2016-05-05 07:01:37 +03:00
|
|
|
NS_ERROR("stylo: ServoRestyleManager::RebuildAllStyleData not implemented");
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoRestyleManager::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
|
|
|
|
nsRestyleHint aRestyleHint)
|
|
|
|
{
|
2016-05-05 07:01:37 +03:00
|
|
|
MOZ_CRASH("stylo: ServoRestyleManager::PostRebuildAllStyleDataEvent not implemented");
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
2016-07-13 23:42:47 +03:00
|
|
|
/* static */ void
|
|
|
|
ServoRestyleManager::RecreateStyleContexts(nsIContent* aContent,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
ServoStyleSet* aStyleSet)
|
|
|
|
{
|
|
|
|
if (!(aContent->IsDirtyForServo() || aContent->HasDirtyDescendantsForServo())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* primaryFrame = aContent->GetPrimaryFrame();
|
|
|
|
|
|
|
|
// TODO: AFAIK this can happen when we have, let's say, display: none. Here we
|
|
|
|
// should trigger frame construction if the element is actually dirty (I
|
|
|
|
// guess), but we'd better do that once we have all the restyle hints thing
|
|
|
|
// figured out.
|
|
|
|
if (!primaryFrame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ServoComputedValues> computedValues =
|
|
|
|
dont_AddRef(Servo_GetComputedValues(aContent));
|
|
|
|
|
|
|
|
// TODO: Figure out what pseudos does this content have, and do the proper
|
|
|
|
// thing with them.
|
|
|
|
RefPtr<nsStyleContext> context =
|
|
|
|
aStyleSet->GetContext(computedValues.forget(),
|
|
|
|
aParentContext,
|
|
|
|
nullptr,
|
|
|
|
CSSPseudoElementType::NotPseudo);
|
|
|
|
|
|
|
|
// TODO: Compare old and new styles to generate restyle change hints, and
|
|
|
|
// process them.
|
|
|
|
primaryFrame->SetStyleContext(context.get());
|
|
|
|
|
|
|
|
FlattenedChildIterator it(aContent);
|
|
|
|
for (nsIContent* n = it.GetNextChild(); n; n = it.GetNextChild()) {
|
|
|
|
RecreateStyleContexts(n, context.get(), aStyleSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
void
|
|
|
|
ServoRestyleManager::ProcessPendingRestyles()
|
|
|
|
{
|
2016-07-13 23:42:47 +03:00
|
|
|
ServoStyleSet* styleSet = StyleSet();
|
|
|
|
|
|
|
|
nsIDocument* doc = PresContext()->Document();
|
|
|
|
Element* root = doc->GetRootElement();
|
|
|
|
|
|
|
|
if (root) {
|
|
|
|
styleSet->RestyleSubtree(root, /* aForce = */ false);
|
|
|
|
RecreateStyleContexts(root, nullptr, styleSet);
|
|
|
|
}
|
|
|
|
|
2016-07-08 10:08:46 +03:00
|
|
|
IncrementRestyleGeneration();
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoRestyleManager::RestyleForInsertOrChange(Element* aContainer,
|
|
|
|
nsIContent* aChild)
|
|
|
|
{
|
2016-05-05 07:01:37 +03:00
|
|
|
NS_ERROR("stylo: ServoRestyleManager::RestyleForInsertOrChange not implemented");
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoRestyleManager::RestyleForAppend(Element* aContainer,
|
|
|
|
nsIContent* aFirstNewContent)
|
|
|
|
{
|
2016-05-05 07:01:37 +03:00
|
|
|
NS_ERROR("stylo: ServoRestyleManager::RestyleForAppend not implemented");
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoRestyleManager::RestyleForRemove(Element* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aFollowingSibling)
|
|
|
|
{
|
2016-05-05 07:01:37 +03:00
|
|
|
NS_ERROR("stylo: ServoRestyleManager::RestyleForRemove not implemented");
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoRestyleManager::ContentStateChanged(nsIContent* aContent,
|
|
|
|
EventStates aStateMask)
|
|
|
|
{
|
2016-07-08 10:08:46 +03:00
|
|
|
if (!aContent->IsElement()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Element* aElement = aContent->AsElement();
|
|
|
|
nsChangeHint changeHint;
|
|
|
|
nsRestyleHint restyleHint;
|
|
|
|
ContentStateChangedInternal(aElement, aStateMask, &changeHint, &restyleHint);
|
|
|
|
|
|
|
|
// TODO(emilio): Post a restyle here, and make it effective.
|
|
|
|
// PostRestyleEvent(aElement, restyleHint, changeHint);
|
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,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aNewValue)
|
|
|
|
{
|
2016-05-05 07:01:37 +03:00
|
|
|
NS_ERROR("stylo: ServoRestyleManager::AttributeWillChange not implemented");
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoRestyleManager::AttributeChanged(Element* aElement,
|
|
|
|
int32_t aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue)
|
|
|
|
{
|
2016-05-05 07:01:37 +03:00
|
|
|
NS_ERROR("stylo: ServoRestyleManager::AttributeChanged not implemented");
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoRestyleManager::ReparentStyleContext(nsIFrame* aFrame)
|
|
|
|
{
|
2016-05-05 07:01:37 +03:00
|
|
|
MOZ_CRASH("stylo: ServoRestyleManager::ReparentStyleContext not implemented");
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ServoRestyleManager::HasPendingRestyles()
|
|
|
|
{
|
2016-05-05 07:01:37 +03:00
|
|
|
NS_ERROR("stylo: ServoRestyleManager::HasPendingRestyles not implemented");
|
|
|
|
return false;
|
2016-02-24 10:01:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|