2016-02-24 10:01:10 +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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_ServoStyleSet_h
|
|
|
|
#define mozilla_ServoStyleSet_h
|
|
|
|
|
2017-05-19 11:16:41 +03:00
|
|
|
#include "mozilla/EffectCompositor.h"
|
2016-02-26 04:51:02 +03:00
|
|
|
#include "mozilla/EnumeratedArray.h"
|
2016-02-24 10:01:10 +03:00
|
|
|
#include "mozilla/EventStates.h"
|
2017-04-30 09:45:32 +03:00
|
|
|
#include "mozilla/PostTraversalTask.h"
|
2016-10-24 12:16:46 +03:00
|
|
|
#include "mozilla/ServoBindingTypes.h"
|
2016-07-19 04:02:55 +03:00
|
|
|
#include "mozilla/ServoElementSnapshot.h"
|
2017-04-30 09:45:32 +03:00
|
|
|
#include "mozilla/ServoUtils.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2016-02-24 10:01:10 +03:00
|
|
|
#include "mozilla/SheetType.h"
|
2016-01-27 05:02:04 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2017-03-28 12:05:12 +03:00
|
|
|
#include "MainThreadUtils.h"
|
2016-02-24 10:01:10 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2017-03-08 08:18:39 +03:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2016-07-19 04:02:55 +03:00
|
|
|
#include "nsChangeHint.h"
|
2016-02-24 10:01:10 +03:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
} // namespace dom
|
|
|
|
class CSSStyleSheet;
|
2016-07-13 23:42:47 +03:00
|
|
|
class ServoRestyleManager;
|
2016-02-24 10:01:12 +03:00
|
|
|
class ServoStyleSheet;
|
2017-01-29 06:58:28 +03:00
|
|
|
struct Keyframe;
|
2017-05-07 17:36:47 +03:00
|
|
|
class ServoElementSnapshotTable;
|
2016-02-24 10:01:10 +03:00
|
|
|
} // namespace mozilla
|
2017-05-11 07:47:24 +03:00
|
|
|
class nsCSSCounterStyleRule;
|
2017-03-28 12:05:12 +03:00
|
|
|
class nsIContent;
|
2016-02-24 10:01:12 +03:00
|
|
|
class nsIDocument;
|
2016-02-24 10:01:10 +03:00
|
|
|
class nsStyleContext;
|
|
|
|
class nsPresContext;
|
2017-01-29 06:58:28 +03:00
|
|
|
struct nsTimingFunction;
|
2017-05-10 23:11:36 +03:00
|
|
|
struct RawServoRuleNode;
|
2016-02-24 10:01:10 +03:00
|
|
|
struct TreeMatchContext;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2017-05-30 03:46:33 +03:00
|
|
|
/**
|
|
|
|
* A few flags used to track which kind of stylist state we may need to
|
|
|
|
* update.
|
|
|
|
*/
|
|
|
|
enum class StylistState : uint8_t {
|
|
|
|
/** The stylist is not dirty, we should do nothing */
|
|
|
|
NotDirty = 0,
|
|
|
|
|
|
|
|
/** The style sheets have changed, so we need to update the style data. */
|
|
|
|
StyleSheetsDirty = 1 << 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All style data is dirty and both style sheet data and default computed
|
|
|
|
* values need to be recomputed.
|
|
|
|
*/
|
|
|
|
FullyDirty = 1 << 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(StylistState)
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
/**
|
|
|
|
* The set of style sheets that apply to a document, backed by a Servo
|
|
|
|
* Stylist. A ServoStyleSet contains ServoStyleSheets.
|
|
|
|
*/
|
|
|
|
class ServoStyleSet
|
|
|
|
{
|
2016-07-13 23:42:47 +03:00
|
|
|
friend class ServoRestyleManager;
|
2017-05-07 17:36:47 +03:00
|
|
|
typedef ServoElementSnapshotTable SnapshotTable;
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
public:
|
2017-03-28 10:31:41 +03:00
|
|
|
class AutoAllowStaleStyles
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoAllowStaleStyles(ServoStyleSet* aStyleSet)
|
|
|
|
: mStyleSet(aStyleSet)
|
|
|
|
{
|
|
|
|
if (mStyleSet) {
|
|
|
|
MOZ_ASSERT(!mStyleSet->mAllowResolveStaleStyles);
|
|
|
|
mStyleSet->mAllowResolveStaleStyles = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoAllowStaleStyles()
|
|
|
|
{
|
|
|
|
if (mStyleSet) {
|
|
|
|
mStyleSet->mAllowResolveStaleStyles = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ServoStyleSet* mStyleSet;
|
|
|
|
};
|
|
|
|
|
2017-03-27 22:51:07 +03:00
|
|
|
static bool IsInServoTraversal()
|
2017-02-02 22:48:28 +03:00
|
|
|
{
|
|
|
|
// The callers of this function are generally main-thread-only _except_
|
|
|
|
// for potentially running during the Servo traversal, in which case they may
|
|
|
|
// take special paths that avoid writing to caches and the like. In order
|
|
|
|
// to allow those callers to branch efficiently without checking TLS, we
|
|
|
|
// maintain this static boolean. However, the danger is that those callers
|
|
|
|
// are generally unprepared to deal with non-Servo-but-also-non-main-thread
|
|
|
|
// callers, and are likely to take the main-thread codepath if this function
|
|
|
|
// returns false. So we assert against other non-main-thread callers here.
|
2017-03-27 22:51:07 +03:00
|
|
|
MOZ_ASSERT(sInServoTraversal || NS_IsMainThread());
|
2017-02-02 22:48:28 +03:00
|
|
|
return sInServoTraversal;
|
|
|
|
}
|
|
|
|
|
2017-04-30 09:41:11 +03:00
|
|
|
static ServoStyleSet* Current()
|
|
|
|
{
|
|
|
|
return sInServoTraversal;
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSet();
|
2017-03-08 08:18:39 +03:00
|
|
|
~ServoStyleSet();
|
2016-02-24 10:01:12 +03:00
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
void Init(nsPresContext* aPresContext);
|
|
|
|
void BeginShutdown();
|
|
|
|
void Shutdown();
|
|
|
|
|
2017-05-25 20:50:03 +03:00
|
|
|
void RecordStyleSheetChange(mozilla::ServoStyleSheet*, StyleSheet::ChangeType);
|
2017-05-24 03:53:08 +03:00
|
|
|
|
|
|
|
void RecordShadowStyleChange(mozilla::dom::ShadowRoot* aShadowRoot) {
|
|
|
|
// FIXME(emilio): When we properly support shadow dom we'll need to do
|
|
|
|
// better.
|
2017-05-25 20:50:03 +03:00
|
|
|
ForceAllStyleDirty();
|
2017-05-24 03:53:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool StyleSheetsHaveChanged() const
|
|
|
|
{
|
|
|
|
return StylistNeedsUpdate();
|
|
|
|
}
|
|
|
|
|
2017-06-02 18:55:55 +03:00
|
|
|
bool MediumFeaturesChanged() const;
|
|
|
|
|
2017-05-24 03:53:08 +03:00
|
|
|
void InvalidateStyleForCSSRuleChanges();
|
|
|
|
|
2017-04-06 05:22:36 +03:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2017-06-05 06:57:13 +03:00
|
|
|
const RawServoStyleSet* RawSet() const {
|
|
|
|
return mRawSet.get();
|
|
|
|
}
|
2017-04-06 05:22:36 +03:00
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
bool GetAuthorStyleDisabled() const;
|
|
|
|
nsresult SetAuthorStyleDisabled(bool aStyleDisabled);
|
|
|
|
|
|
|
|
void BeginUpdate();
|
|
|
|
nsresult EndUpdate();
|
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
ResolveStyleFor(dom::Element* aElement,
|
2016-11-02 09:11:24 +03:00
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
LazyComputeBehavior aMayCompute);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2017-03-08 08:18:32 +03:00
|
|
|
// Get a style context for a text node (which no rules will match).
|
|
|
|
//
|
|
|
|
// The returned style context will have nsCSSAnonBoxes::mozText as its pseudo.
|
|
|
|
//
|
|
|
|
// (Perhaps mozText should go away and we shouldn't even create style
|
|
|
|
// contexts for such content nodes, when text-combine-upright is not
|
|
|
|
// present. However, not doing any rule matching for them is a first step.)
|
2016-02-24 10:01:10 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2016-04-29 07:01:44 +03:00
|
|
|
ResolveStyleForText(nsIContent* aTextNode,
|
|
|
|
nsStyleContext* aParentContext);
|
|
|
|
|
2017-03-08 08:18:32 +03:00
|
|
|
// Get a style context for a first-letter continuation (which no rules will
|
|
|
|
// match).
|
|
|
|
//
|
|
|
|
// The returned style context will have
|
|
|
|
// nsCSSAnonBoxes::firstLetterContinuation as its pseudo.
|
|
|
|
//
|
|
|
|
// (Perhaps nsCSSAnonBoxes::firstLetterContinuation should go away and we
|
|
|
|
// shouldn't even create style contexts for such frames. However, not doing
|
|
|
|
// any rule matching for them is a first step. And right now we do use this
|
|
|
|
// style context for some things)
|
2016-04-29 07:01:44 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2017-03-08 08:18:32 +03:00
|
|
|
ResolveStyleForFirstLetterContinuation(nsStyleContext* aParentContext);
|
|
|
|
|
|
|
|
// Get a style context for a placeholder frame (which no rules will match).
|
|
|
|
//
|
|
|
|
// The returned style context will have nsCSSAnonBoxes::oofPlaceholder as
|
|
|
|
// its pseudo.
|
|
|
|
//
|
|
|
|
// (Perhaps nsCSSAnonBoxes::oofPaceholder should go away and we shouldn't even
|
2017-03-08 08:18:40 +03:00
|
|
|
// create style contexts for placeholders. However, not doing any rule
|
|
|
|
// matching for them is a first step.)
|
2017-03-08 08:18:32 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2017-03-08 08:18:40 +03:00
|
|
|
ResolveStyleForPlaceholder();
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2017-03-08 08:18:32 +03:00
|
|
|
// Get a style context for a pseudo-element. aParentElement must be
|
|
|
|
// non-null. aPseudoID is the CSSPseudoElementType for the
|
|
|
|
// pseudo-element. aPseudoElement must be non-null if the pseudo-element
|
|
|
|
// type is one that allows user action pseudo-classes after it or allows
|
|
|
|
// style attributes; otherwise, it is ignored.
|
2016-02-24 10:01:10 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2016-12-22 04:58:38 +03:00
|
|
|
ResolvePseudoElementStyle(dom::Element* aOriginatingElement,
|
2017-05-14 19:39:22 +03:00
|
|
|
CSSPseudoElementType aType,
|
2016-02-24 10:01:10 +03:00
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
dom::Element* aPseudoElement);
|
|
|
|
|
2016-12-28 10:49:12 +03:00
|
|
|
// Resolves style for a (possibly-pseudo) Element without assuming that the
|
|
|
|
// style has been resolved, and without worrying about setting the style
|
|
|
|
// context up to live in the style context tree (a null parent is used).
|
2017-04-15 01:37:34 +03:00
|
|
|
// |aPeudoTag| and |aPseudoType| must match.
|
2016-12-28 10:49:12 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
ResolveTransientStyle(dom::Element* aElement,
|
2017-04-15 01:37:34 +03:00
|
|
|
nsIAtom* aPseudoTag,
|
2017-05-24 09:37:47 +03:00
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
StyleRuleInclusion aRules =
|
|
|
|
StyleRuleInclusion::All);
|
2017-04-15 01:37:34 +03:00
|
|
|
|
|
|
|
// Similar to ResolveTransientStyle() but returns ServoComputedValues.
|
|
|
|
// Unlike ResolveServoStyle() this function calls PreTraverseSync().
|
|
|
|
already_AddRefed<ServoComputedValues>
|
2017-05-14 19:39:22 +03:00
|
|
|
ResolveTransientServoStyle(dom::Element* aElement,
|
2017-05-24 09:37:47 +03:00
|
|
|
CSSPseudoElementType aPseudoTag,
|
|
|
|
StyleRuleInclusion aRules =
|
|
|
|
StyleRuleInclusion::All);
|
2016-12-28 10:49:12 +03:00
|
|
|
|
2017-03-09 07:41:04 +03:00
|
|
|
// Get a style context for an anonymous box. aPseudoTag is the pseudo-tag to
|
|
|
|
// use and must be non-null. It must be an anon box, and must be one that
|
2017-04-24 11:25:37 +03:00
|
|
|
// inherits style from the given aParentContext.
|
2016-02-24 10:01:10 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2017-03-09 07:50:28 +03:00
|
|
|
ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
|
2017-04-24 11:25:37 +03:00
|
|
|
nsStyleContext* aParentContext);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2017-03-09 07:41:04 +03:00
|
|
|
// Get a style context for an anonymous box that does not inherit style from
|
|
|
|
// anything. aPseudoTag is the pseudo-tag to use and must be non-null. It
|
|
|
|
// must be an anon box, and must be a non-inheriting one.
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
ResolveNonInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag);
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
// manage the set of style sheets in the style set
|
2016-02-24 10:01:12 +03:00
|
|
|
nsresult AppendStyleSheet(SheetType aType, ServoStyleSheet* aSheet);
|
|
|
|
nsresult PrependStyleSheet(SheetType aType, ServoStyleSheet* aSheet);
|
|
|
|
nsresult RemoveStyleSheet(SheetType aType, ServoStyleSheet* aSheet);
|
2016-02-24 10:01:10 +03:00
|
|
|
nsresult ReplaceSheets(SheetType aType,
|
2016-02-24 10:01:12 +03:00
|
|
|
const nsTArray<RefPtr<ServoStyleSheet>>& aNewSheets);
|
2016-02-24 10:01:10 +03:00
|
|
|
nsresult InsertStyleSheetBefore(SheetType aType,
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSheet* aNewSheet,
|
|
|
|
ServoStyleSheet* aReferenceSheet);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
|
|
|
int32_t SheetCount(SheetType aType) const;
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSheet* StyleSheetAt(SheetType aType, int32_t aIndex) const;
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
nsresult RemoveDocStyleSheet(ServoStyleSheet* aSheet);
|
|
|
|
nsresult AddDocStyleSheet(ServoStyleSheet* aSheet, nsIDocument* aDocument);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
|
|
|
// check whether there is ::before/::after style for an element
|
|
|
|
already_AddRefed<nsStyleContext>
|
2016-12-22 04:58:38 +03:00
|
|
|
ProbePseudoElementStyle(dom::Element* aOriginatingElement,
|
2016-02-24 10:01:10 +03:00
|
|
|
mozilla::CSSPseudoElementType aType,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
dom::Element* aPseudoElement = nullptr);
|
|
|
|
|
|
|
|
// Test if style is dependent on content state
|
|
|
|
nsRestyleHint HasStateDependentStyle(dom::Element* aElement,
|
|
|
|
EventStates aStateMask);
|
2016-07-19 04:02:55 +03:00
|
|
|
nsRestyleHint HasStateDependentStyle(
|
|
|
|
dom::Element* aElement, mozilla::CSSPseudoElementType aPseudoType,
|
|
|
|
dom::Element* aPseudoElement, EventStates aStateMask);
|
|
|
|
|
2016-07-13 23:42:47 +03:00
|
|
|
/**
|
2016-08-12 00:12:49 +03:00
|
|
|
* Performs a Servo traversal to compute style for all dirty nodes in the
|
2017-05-07 17:36:47 +03:00
|
|
|
* document.
|
|
|
|
*
|
|
|
|
* This will traverse all of the document's style roots (that is, its document
|
|
|
|
* element, and the roots of the document-level native anonymous content).
|
|
|
|
*
|
2017-05-21 02:16:26 +03:00
|
|
|
* |aRestyleBehavior| should be `Normal` or `ForCSSRuleChanges`.
|
|
|
|
* We need to specify |ForCSSRuleChanges| to try to update all CSS animations
|
|
|
|
* when we call this function due to CSS rule changes since @keyframes rules
|
|
|
|
* may have changed.
|
|
|
|
*
|
2017-05-07 17:36:47 +03:00
|
|
|
* Returns true if a post-traversal is required.
|
2016-07-13 23:42:47 +03:00
|
|
|
*/
|
2017-05-21 02:16:26 +03:00
|
|
|
bool StyleDocument(TraversalRestyleBehavior aRestyleBehavior);
|
2016-08-12 00:12:49 +03:00
|
|
|
|
2017-05-19 11:16:41 +03:00
|
|
|
/**
|
|
|
|
* Performs a Servo animation-only traversal to compute style for all nodes
|
|
|
|
* with the animation-only dirty bit in the document.
|
|
|
|
*
|
|
|
|
* This will traverse all of the document's style roots (that is, its document
|
|
|
|
* element, and the roots of the document-level native anonymous content).
|
|
|
|
*/
|
|
|
|
bool StyleDocumentForAnimationOnly();
|
|
|
|
|
2016-08-12 00:12:49 +03:00
|
|
|
/**
|
2016-12-11 09:11:36 +03:00
|
|
|
* Eagerly styles a subtree of unstyled nodes that was just appended to the
|
2016-08-12 00:12:49 +03:00
|
|
|
* tree. This is used in situations where we need the style immediately and
|
|
|
|
* cannot wait for a future batch restyle.
|
|
|
|
*/
|
2017-03-28 12:05:12 +03:00
|
|
|
void StyleNewSubtree(dom::Element* aRoot);
|
2016-08-12 00:12:49 +03:00
|
|
|
|
|
|
|
/**
|
2016-12-11 09:11:36 +03:00
|
|
|
* Like the above, but skips the root node, and only styles unstyled children.
|
|
|
|
* When potentially appending multiple children, it's preferable to call
|
|
|
|
* StyleNewChildren on the node rather than making multiple calls to
|
|
|
|
* StyleNewSubtree on each child, since it allows for more parallelism.
|
2016-08-12 00:12:49 +03:00
|
|
|
*/
|
2017-03-28 12:05:12 +03:00
|
|
|
void StyleNewChildren(dom::Element* aParent);
|
2016-07-27 03:06:25 +03:00
|
|
|
|
2017-06-11 14:11:08 +03:00
|
|
|
/**
|
|
|
|
* Eagerly styles the children of an element that has just had an XBL
|
|
|
|
* binding applied to it. Some XBL consumers attach bindings to elements
|
|
|
|
* that have not been styled yet, and in such cases, this will do the
|
|
|
|
* equivalent of StyleNewSubtree instead.
|
|
|
|
*/
|
|
|
|
void StyleNewlyBoundElement(dom::Element* aElement);
|
|
|
|
|
2017-04-04 14:34:30 +03:00
|
|
|
/**
|
|
|
|
* Like StyleNewSubtree, but in response to a request to reconstruct frames
|
|
|
|
* for the given subtree, and so works on elements that already have
|
|
|
|
* styles. This will leave the subtree in a state just like after an initial
|
|
|
|
* styling, i.e. with new styles, no change hints, and with the dirty
|
|
|
|
* descendants bits cleared. No comparison of old and new styles is done,
|
|
|
|
* so no change hints will be processed.
|
|
|
|
*/
|
|
|
|
void StyleSubtreeForReconstruct(dom::Element* aRoot);
|
|
|
|
|
2016-12-19 09:30:14 +03:00
|
|
|
/**
|
|
|
|
* Records that the contents of style sheets have changed since the last
|
|
|
|
* restyle. Calling this will ensure that the Stylist rebuilds its
|
|
|
|
* selector maps.
|
|
|
|
*/
|
2017-05-25 20:50:03 +03:00
|
|
|
void ForceAllStyleDirty();
|
2016-12-19 09:30:14 +03:00
|
|
|
|
2017-05-19 00:21:11 +03:00
|
|
|
/**
|
|
|
|
* Helper for correctly calling RebuildStylist without paying the cost of an
|
|
|
|
* extra function call in the common no-rebuild-needed case.
|
|
|
|
*/
|
|
|
|
void UpdateStylistIfNeeded()
|
|
|
|
{
|
|
|
|
if (StylistNeedsUpdate()) {
|
|
|
|
UpdateStylist();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
void AssertTreeIsClean();
|
|
|
|
#else
|
|
|
|
void AssertTreeIsClean() {}
|
|
|
|
#endif
|
|
|
|
|
2017-05-15 19:02:59 +03:00
|
|
|
/**
|
|
|
|
* Clears the style data, both style sheet data and cached non-inheriting
|
|
|
|
* style contexts, and marks the stylist as needing an unconditional full
|
|
|
|
* rebuild, including a device reset.
|
|
|
|
*/
|
|
|
|
void ClearDataAndMarkDeviceDirty();
|
|
|
|
|
2017-06-10 17:22:23 +03:00
|
|
|
/**
|
|
|
|
* Notifies the Servo stylesheet that the document's compatibility mode has changed.
|
|
|
|
*/
|
|
|
|
void CompatibilityModeChanged();
|
|
|
|
|
2017-01-04 22:52:27 +03:00
|
|
|
/**
|
|
|
|
* Resolve style for the given element, and return it as a
|
|
|
|
* ServoComputedValues, not an nsStyleContext.
|
|
|
|
*/
|
2017-01-06 00:12:53 +03:00
|
|
|
already_AddRefed<ServoComputedValues> ResolveServoStyle(dom::Element* aElement);
|
2017-01-04 22:52:27 +03:00
|
|
|
|
2017-05-13 10:34:38 +03:00
|
|
|
bool GetKeyframesForName(const nsString& aName,
|
|
|
|
const nsTimingFunction& aTimingFunction,
|
|
|
|
const ServoComputedValues* aComputedValues,
|
|
|
|
nsTArray<Keyframe>& aKeyframes);
|
2017-01-29 06:58:28 +03:00
|
|
|
|
2017-03-11 04:40:47 +03:00
|
|
|
nsTArray<ComputedKeyframeValues>
|
|
|
|
GetComputedKeyframeValuesFor(const nsTArray<Keyframe>& aKeyframes,
|
|
|
|
dom::Element* aElement,
|
2017-06-02 03:38:54 +03:00
|
|
|
ServoComputedValuesBorrowed aComputedValues);
|
2017-03-11 04:40:47 +03:00
|
|
|
|
2017-06-09 00:19:37 +03:00
|
|
|
void
|
|
|
|
GetAnimationValues(RawServoDeclarationBlock* aDeclarations,
|
|
|
|
dom::Element* aElement,
|
|
|
|
ServoComputedValuesBorrowed aComputedValues,
|
|
|
|
nsTArray<RefPtr<RawServoAnimationValue>>& aAnimationValues);
|
|
|
|
|
2017-03-27 09:53:27 +03:00
|
|
|
bool AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray);
|
|
|
|
|
2017-05-11 07:47:24 +03:00
|
|
|
nsCSSCounterStyleRule* CounterStyleRuleForName(nsIAtom* aName);
|
|
|
|
|
2017-04-06 04:34:50 +03:00
|
|
|
already_AddRefed<ServoComputedValues>
|
2017-05-14 19:39:22 +03:00
|
|
|
GetBaseComputedValuesForElement(dom::Element* aElement,
|
|
|
|
CSSPseudoElementType aPseudoType);
|
2017-04-06 04:34:50 +03:00
|
|
|
|
2017-04-15 01:37:35 +03:00
|
|
|
/**
|
|
|
|
* Resolve style for a given declaration block with/without the parent style.
|
|
|
|
* If the parent style is not specified, the document default computed values
|
|
|
|
* is used.
|
|
|
|
*/
|
|
|
|
already_AddRefed<ServoComputedValues>
|
|
|
|
ResolveForDeclarations(ServoComputedValuesBorrowedOrNull aParentOrNull,
|
|
|
|
RawServoDeclarationBlockBorrowed aDeclarations);
|
|
|
|
|
2017-05-03 06:15:27 +03:00
|
|
|
already_AddRefed<RawServoAnimationValue>
|
2017-06-02 03:38:22 +03:00
|
|
|
ComputeAnimationValue(dom::Element* aElement,
|
|
|
|
RawServoDeclarationBlock* aDeclaration,
|
2017-06-02 03:38:46 +03:00
|
|
|
ServoComputedValuesBorrowed aComputedValues);
|
2017-05-03 06:15:27 +03:00
|
|
|
|
2017-04-30 09:45:32 +03:00
|
|
|
void AppendTask(PostTraversalTask aTask)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInServoTraversal());
|
|
|
|
|
|
|
|
// We currently only use PostTraversalTasks while the Servo font metrics
|
|
|
|
// mutex is locked. If we need to use them in other situations during
|
|
|
|
// a traversal, we should assert that we've taken appropriate
|
|
|
|
// synchronization measures.
|
|
|
|
AssertIsMainThreadOrServoFontMetricsLocked();
|
|
|
|
|
|
|
|
mPostTraversalTasks.AppendElement(aTask);
|
|
|
|
}
|
|
|
|
|
2017-05-16 02:30:10 +03:00
|
|
|
// Returns true if a restyle of the document is needed due to cloning
|
|
|
|
// sheet inners.
|
|
|
|
bool EnsureUniqueInnerOnCSSSheets();
|
|
|
|
|
|
|
|
// Called by StyleSheet::EnsureUniqueInner to let us know it cloned
|
|
|
|
// its inner.
|
|
|
|
void SetNeedsRestyleAfterEnsureUniqueInner() {
|
|
|
|
mNeedsRestyleAfterEnsureUniqueInner = true;
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
private:
|
2017-04-30 09:45:32 +03:00
|
|
|
// On construction, sets sInServoTraversal to the given ServoStyleSet.
|
|
|
|
// On destruction, clears sInServoTraversal and calls RunPostTraversalTasks.
|
2017-04-30 09:41:11 +03:00
|
|
|
class MOZ_STACK_CLASS AutoSetInServoTraversal
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoSetInServoTraversal(ServoStyleSet* aSet)
|
2017-04-30 09:45:32 +03:00
|
|
|
: mSet(aSet)
|
2017-04-30 09:41:11 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!sInServoTraversal);
|
|
|
|
MOZ_ASSERT(aSet);
|
|
|
|
sInServoTraversal = aSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSetInServoTraversal()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(sInServoTraversal);
|
|
|
|
sInServoTraversal = nullptr;
|
2017-04-30 09:45:32 +03:00
|
|
|
mSet->RunPostTraversalTasks();
|
2017-04-30 09:41:11 +03:00
|
|
|
}
|
2017-04-30 09:45:32 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
ServoStyleSet* mSet;
|
2017-04-30 09:41:11 +03:00
|
|
|
};
|
|
|
|
|
2016-04-29 03:56:37 +03:00
|
|
|
already_AddRefed<nsStyleContext> GetContext(already_AddRefed<ServoComputedValues>,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
nsIAtom* aPseudoTag,
|
2017-01-29 06:59:00 +03:00
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
dom::Element* aElementForAnimation);
|
2016-04-29 03:56:37 +03:00
|
|
|
|
2016-04-29 07:04:16 +03:00
|
|
|
already_AddRefed<nsStyleContext> GetContext(nsIContent* aContent,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
nsIAtom* aPseudoTag,
|
2016-11-02 09:11:24 +03:00
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
LazyComputeBehavior aMayCompute);
|
2016-04-29 07:04:16 +03:00
|
|
|
|
2017-05-17 19:33:32 +03:00
|
|
|
/**
|
|
|
|
* Rebuild the style data. This will force a stylesheet flush, and also
|
|
|
|
* recompute the default computed styles.
|
|
|
|
*/
|
|
|
|
void RebuildData();
|
|
|
|
|
2017-05-07 17:36:47 +03:00
|
|
|
/**
|
|
|
|
* Gets the pending snapshots to handle from the restyle manager.
|
|
|
|
*/
|
|
|
|
const SnapshotTable& Snapshots();
|
|
|
|
|
2017-01-20 02:56:53 +03:00
|
|
|
/**
|
|
|
|
* Resolve all ServoDeclarationBlocks attached to mapped
|
|
|
|
* presentation attributes cached on the document.
|
2017-05-07 17:36:47 +03:00
|
|
|
*
|
2017-01-20 02:56:53 +03:00
|
|
|
* Call this before jumping into Servo's style system.
|
|
|
|
*/
|
|
|
|
void ResolveMappedAttrDeclarationBlocks();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform all lazy operations required before traversing
|
2017-05-07 17:36:47 +03:00
|
|
|
* a subtree.
|
|
|
|
*
|
|
|
|
* Returns whether a post-traversal is required.
|
2017-01-20 02:56:53 +03:00
|
|
|
*/
|
2017-02-10 05:42:30 +03:00
|
|
|
bool PrepareAndTraverseSubtree(RawGeckoElementBorrowed aRoot,
|
2017-04-08 17:57:08 +03:00
|
|
|
TraversalRootBehavior aRootBehavior,
|
|
|
|
TraversalRestyleBehavior aRestyleBehavior);
|
2017-01-20 02:56:53 +03:00
|
|
|
|
2017-03-08 08:18:39 +03:00
|
|
|
/**
|
2017-05-07 17:36:47 +03:00
|
|
|
* Clear our cached mNonInheritingStyleContexts.
|
|
|
|
*
|
|
|
|
* We do this when we want to make sure those style contexts won't live too
|
|
|
|
* long (e.g. when rebuilding all style data or when shutting down the style
|
|
|
|
* set).
|
2017-03-08 08:18:39 +03:00
|
|
|
*/
|
|
|
|
void ClearNonInheritingStyleContexts();
|
|
|
|
|
2017-03-08 23:20:17 +03:00
|
|
|
/**
|
|
|
|
* Perform processes that we should do before traversing.
|
2017-04-04 14:34:30 +03:00
|
|
|
*
|
|
|
|
* When aRoot is null, the entire document is pre-traversed. Otherwise,
|
|
|
|
* only the subtree rooted at aRoot is pre-traversed.
|
2017-03-08 23:20:17 +03:00
|
|
|
*/
|
2017-05-19 11:16:41 +03:00
|
|
|
void PreTraverse(dom::Element* aRoot = nullptr,
|
|
|
|
EffectCompositor::AnimationRestyleType =
|
|
|
|
EffectCompositor::AnimationRestyleType::Throttled);
|
2017-03-17 00:10:22 +03:00
|
|
|
// Subset of the pre-traverse steps that involve syncing up data
|
|
|
|
void PreTraverseSync();
|
2017-03-08 23:20:17 +03:00
|
|
|
|
2017-05-15 19:02:59 +03:00
|
|
|
/**
|
|
|
|
* Note that the stylist needs a style flush due to style sheet changes.
|
|
|
|
*/
|
|
|
|
void SetStylistStyleSheetsDirty()
|
|
|
|
{
|
2017-05-30 03:46:33 +03:00
|
|
|
mStylistState |= StylistState::StyleSheetsDirty;
|
2017-05-15 19:02:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool StylistNeedsUpdate() const
|
|
|
|
{
|
|
|
|
return mStylistState != StylistState::NotDirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the stylist as needed to ensure style data is up-to-date.
|
|
|
|
*
|
|
|
|
* This should only be called if StylistNeedsUpdate returns true.
|
2017-05-10 20:13:39 +03:00
|
|
|
*/
|
2017-05-15 19:02:59 +03:00
|
|
|
void UpdateStylist();
|
2017-05-10 20:13:39 +03:00
|
|
|
|
2017-05-14 19:39:22 +03:00
|
|
|
already_AddRefed<ServoComputedValues>
|
2017-05-24 09:37:47 +03:00
|
|
|
ResolveStyleLazily(dom::Element* aElement,
|
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
StyleRuleInclusion aRules =
|
|
|
|
StyleRuleInclusion::All);
|
2017-03-08 23:20:17 +03:00
|
|
|
|
2017-04-30 09:45:32 +03:00
|
|
|
void RunPostTraversalTasks();
|
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void PrependSheetOfType(SheetType aType,
|
|
|
|
ServoStyleSheet* aSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void AppendSheetOfType(SheetType aType,
|
|
|
|
ServoStyleSheet* aSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void InsertSheetOfType(SheetType aType,
|
|
|
|
ServoStyleSheet* aSheet,
|
|
|
|
ServoStyleSheet* aBeforeSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void RemoveSheetOfType(SheetType aType,
|
|
|
|
ServoStyleSheet* aSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
|
2016-03-18 23:14:07 +03:00
|
|
|
nsPresContext* mPresContext;
|
2016-01-27 05:02:04 +03:00
|
|
|
UniquePtr<RawServoStyleSet> mRawSet;
|
|
|
|
EnumeratedArray<SheetType, SheetType::Count,
|
2017-05-12 22:04:55 +03:00
|
|
|
nsTArray<RefPtr<ServoStyleSheet>>> mSheets;
|
2017-03-28 10:31:41 +03:00
|
|
|
bool mAllowResolveStaleStyles;
|
2017-04-11 10:43:14 +03:00
|
|
|
bool mAuthorStyleDisabled;
|
2017-05-15 19:02:59 +03:00
|
|
|
StylistState mStylistState;
|
2017-05-26 17:29:10 +03:00
|
|
|
uint64_t mUserFontSetUpdateGeneration;
|
2017-02-02 22:48:28 +03:00
|
|
|
|
2017-05-16 02:30:10 +03:00
|
|
|
bool mNeedsRestyleAfterEnsureUniqueInner;
|
|
|
|
|
2017-03-08 08:18:39 +03:00
|
|
|
// Stores pointers to our cached style contexts for non-inheriting anonymous
|
|
|
|
// boxes.
|
2017-03-09 07:39:45 +03:00
|
|
|
EnumeratedArray<nsCSSAnonBoxes::NonInheriting,
|
|
|
|
nsCSSAnonBoxes::NonInheriting::_Count,
|
|
|
|
RefPtr<nsStyleContext>> mNonInheritingStyleContexts;
|
2017-03-08 08:18:39 +03:00
|
|
|
|
2017-04-30 09:45:32 +03:00
|
|
|
// Tasks to perform after a traversal, back on the main thread.
|
|
|
|
//
|
|
|
|
// These are similar to Servo's SequentialTasks, except that they are
|
|
|
|
// posted by C++ code running on style worker threads.
|
|
|
|
nsTArray<PostTraversalTask> mPostTraversalTasks;
|
|
|
|
|
2017-04-30 09:41:11 +03:00
|
|
|
static ServoStyleSet* sInServoTraversal;
|
2016-02-24 10:01:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_ServoStyleSet_h
|