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
|
|
|
|
|
2016-02-26 04:51:02 +03:00
|
|
|
#include "mozilla/EnumeratedArray.h"
|
2016-02-24 10:01:10 +03:00
|
|
|
#include "mozilla/EventStates.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"
|
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"
|
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-03-11 04:40:47 +03:00
|
|
|
struct ServoComputedStyleValues;
|
2016-02-24 10:01:10 +03:00
|
|
|
} // namespace mozilla
|
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;
|
2016-02-24 10:01:10 +03:00
|
|
|
struct TreeMatchContext;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2016-02-24 10:01:10 +03:00
|
|
|
public:
|
2017-02-02 22:48:28 +03:00
|
|
|
static bool IsInServoTraversal(bool aAssertServoTraversalOrMainThread = true)
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
MOZ_ASSERT_IF(aAssertServoTraversalOrMainThread,
|
|
|
|
sInServoTraversal || NS_IsMainThread());
|
|
|
|
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();
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
ResolveStyleFor(dom::Element* aElement,
|
|
|
|
nsStyleContext* aParentContext,
|
2016-11-02 09:11:24 +03:00
|
|
|
LazyComputeBehavior aMayCompute,
|
2016-02-24 10:01:10 +03:00
|
|
|
TreeMatchContext& aTreeMatchContext);
|
|
|
|
|
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,
|
2016-02-24 10:01:10 +03:00
|
|
|
mozilla::CSSPseudoElementType aType,
|
|
|
|
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).
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
ResolveTransientStyle(dom::Element* aElement,
|
|
|
|
mozilla::CSSPseudoElementType aPseudoType);
|
|
|
|
|
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
|
|
|
|
// inherits style from the given aParentContext. aFlags is an nsStyleSet
|
|
|
|
// flags bitfield.
|
2016-02-24 10:01:10 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2017-03-09 07:50:28 +03:00
|
|
|
ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
uint32_t aFlags = 0);
|
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);
|
|
|
|
|
|
|
|
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,
|
|
|
|
TreeMatchContext& aTreeMatchContext,
|
|
|
|
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-02-10 05:42:30 +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). Returns true if a post-traversal is required.
|
2016-07-13 23:42:47 +03:00
|
|
|
*/
|
2017-02-10 05:42:30 +03:00
|
|
|
bool StyleDocument();
|
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.
|
|
|
|
*/
|
2016-12-11 09:11:36 +03:00
|
|
|
void StyleNewSubtree(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
|
|
|
*/
|
2016-12-11 09:11:36 +03:00
|
|
|
void StyleNewChildren(Element* aParent);
|
2016-07-27 03:06:25 +03:00
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
void NoteStyleSheetsChanged();
|
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
void AssertTreeIsClean();
|
|
|
|
#else
|
|
|
|
void AssertTreeIsClean() {}
|
|
|
|
#endif
|
|
|
|
|
2017-01-04 22:52:27 +03:00
|
|
|
/**
|
2017-01-15 01:34:49 +03:00
|
|
|
* Rebuild the style data. This will force a stylesheet flush, and also
|
|
|
|
* recompute the default computed styles.
|
2017-01-04 22:52:27 +03:00
|
|
|
*/
|
2017-01-15 01:34:49 +03:00
|
|
|
void RebuildData();
|
2017-01-04 22:52:27 +03:00
|
|
|
|
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-01-29 06:58:28 +03:00
|
|
|
bool FillKeyframesForName(const nsString& aName,
|
|
|
|
const nsTimingFunction& aTimingFunction,
|
|
|
|
const ServoComputedValues* aComputedValues,
|
|
|
|
nsTArray<Keyframe>& aKeyframes);
|
|
|
|
|
2017-03-11 04:40:47 +03:00
|
|
|
nsTArray<ComputedKeyframeValues>
|
|
|
|
GetComputedKeyframeValuesFor(const nsTArray<Keyframe>& aKeyframes,
|
|
|
|
dom::Element* aElement,
|
|
|
|
const ServoComputedStyleValues& aServoValues);
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
private:
|
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-01-20 02:56:53 +03:00
|
|
|
/**
|
|
|
|
* Resolve all ServoDeclarationBlocks attached to mapped
|
|
|
|
* presentation attributes cached on the document.
|
|
|
|
* Call this before jumping into Servo's style system.
|
|
|
|
*/
|
|
|
|
void ResolveMappedAttrDeclarationBlocks();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform all lazy operations required before traversing
|
2017-02-10 05:42:30 +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-01-20 02:56:53 +03:00
|
|
|
mozilla::TraversalRootBehavior aRootBehavior);
|
|
|
|
|
2017-03-08 08:18:39 +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).
|
|
|
|
*/
|
|
|
|
void ClearNonInheritingStyleContexts();
|
|
|
|
|
2017-03-08 23:20:17 +03:00
|
|
|
/**
|
|
|
|
* Perform processes that we should do before traversing.
|
|
|
|
*/
|
|
|
|
void PreTraverse();
|
|
|
|
|
2017-03-08 23:20:17 +03:00
|
|
|
already_AddRefed<ServoComputedValues> ResolveStyleLazily(dom::Element* aElement,
|
|
|
|
nsIAtom* aPseudoTag);
|
|
|
|
|
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,
|
|
|
|
nsTArray<RefPtr<ServoStyleSheet>>> mSheets;
|
2016-02-24 10:01:12 +03:00
|
|
|
int32_t mBatching;
|
2017-02-02 22:48:28 +03:00
|
|
|
|
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-02-02 22:48:28 +03:00
|
|
|
static bool sInServoTraversal;
|
2016-02-24 10:01:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_ServoStyleSet_h
|