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-10-20 13:31:13 +03:00
|
|
|
#include "mozilla/AtomArray.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"
|
2018-02-06 17:00:37 +03:00
|
|
|
#include "mozilla/MediaFeatureChange.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-11-13 08:33:46 +03:00
|
|
|
#include "mozilla/ServoBindings.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"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
Bug 1400078 - Measure the UA cache. r=njn.
ServoStyleSetSizes now has two uses, one for the Stylist, and one for the UA
cache, and so the patch removes 'Stylist' from the field names.
Example output from about:memory:
> +----1,359,608 B (00.55%) -- layout
> | +----756,488 B (00.31%) -- style-sheet-cache [2]
> | +----393,968 B (00.16%) -- servo-ua-cache
> | | +--234,496 B (00.10%) -- element-and-pseudos-maps
> | | +---59,648 B (00.02%) -- revalidation-selectors
> | | +---58,320 B (00.02%) -- invalidation-map
> | | +---30,752 B (00.01%) -- other
> | | +---10,752 B (00.00%) -- precomputed-pseudos
MozReview-Commit-ID: 8oxuJO0ojp
--HG--
extra : rebase_source : 7d86216967259b71df7280261d025cc65bf00ba4
2017-09-19 02:25:00 +03:00
|
|
|
#include "nsIMemoryReporter.h"
|
2016-02-24 10:01:10 +03:00
|
|
|
#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;
|
2017-06-28 04:34:06 +03:00
|
|
|
class ServoStyleContext;
|
2017-06-19 08:45:43 +03:00
|
|
|
class ServoStyleRuleMap;
|
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 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-09-02 10:25:45 +03:00
|
|
|
// A few flags used to track which kind of stylist state we may need to
|
|
|
|
// update.
|
2017-05-30 03:46:33 +03:00
|
|
|
enum class StylistState : uint8_t {
|
2017-09-02 10:25:45 +03:00
|
|
|
// The stylist is not dirty, we should do nothing.
|
2017-05-30 03:46:33 +03:00
|
|
|
NotDirty = 0,
|
|
|
|
|
2017-09-02 10:25:45 +03:00
|
|
|
// The style sheets have changed, so we need to update the style data.
|
|
|
|
StyleSheetsDirty = 1 << 0,
|
|
|
|
|
|
|
|
// Some of the style sheets of the bound elements in binding manager have
|
|
|
|
// changed, so we need to tell the binding manager to update style data.
|
|
|
|
XBLStyleSheetsDirty = 1 << 1,
|
2017-05-30 03:46:33 +03:00
|
|
|
};
|
|
|
|
|
2017-09-02 10:25:45 +03:00
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(StylistState)
|
|
|
|
|
2017-08-12 13:19:22 +03:00
|
|
|
// Bitfield type to represent Servo stylesheet origins.
|
|
|
|
enum class OriginFlags : uint8_t {
|
|
|
|
UserAgent = 0x01,
|
|
|
|
User = 0x02,
|
|
|
|
Author = 0x04,
|
|
|
|
All = 0x07,
|
|
|
|
};
|
|
|
|
|
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(OriginFlags)
|
|
|
|
|
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:
|
2018-01-30 23:05:43 +03:00
|
|
|
static bool IsInServoTraversal() { return mozilla::IsInServoTraversal(); }
|
2017-02-02 22:48:28 +03:00
|
|
|
|
2017-09-19 04:26:29 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Used for debug assertions. We make this debug-only to prevent callers from
|
|
|
|
// accidentally using it instead of IsInServoTraversal, which is cheaper. We
|
|
|
|
// can change this if a use-case arises.
|
|
|
|
static bool IsCurrentThreadInServoTraversal();
|
|
|
|
#endif
|
|
|
|
|
2017-04-30 09:41:11 +03:00
|
|
|
static ServoStyleSet* Current()
|
|
|
|
{
|
|
|
|
return sInServoTraversal;
|
|
|
|
}
|
|
|
|
|
2017-08-31 23:50:24 +03:00
|
|
|
// The kind of styleset we have.
|
|
|
|
//
|
|
|
|
// We use ServoStyleSet also from XBL bindings, and some stuff needs to be
|
|
|
|
// different between them.
|
|
|
|
enum class Kind : uint8_t {
|
|
|
|
// A "master" StyleSet.
|
|
|
|
//
|
|
|
|
// This one is owned by a pres shell for a given document.
|
|
|
|
Master,
|
|
|
|
|
|
|
|
// A StyleSet for XBL, which is owned by a given XBL binding.
|
|
|
|
ForXBL,
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit ServoStyleSet(Kind aKind);
|
2017-03-08 08:18:39 +03:00
|
|
|
~ServoStyleSet();
|
2016-02-24 10:01:12 +03:00
|
|
|
|
2017-09-01 11:45:39 +03:00
|
|
|
static UniquePtr<ServoStyleSet>
|
|
|
|
CreateXBLServoStyleSet(nsPresContext* aPresContext,
|
|
|
|
const nsTArray<RefPtr<ServoStyleSheet>>& aNewSheets);
|
|
|
|
|
2018-01-05 22:17:26 +03:00
|
|
|
void Init(nsPresContext* aPresContext);
|
2017-11-28 03:50:45 +03:00
|
|
|
void BeginShutdown() {}
|
2016-02-24 10:01:10 +03:00
|
|
|
void Shutdown();
|
|
|
|
|
2017-11-28 03:50:45 +03:00
|
|
|
// Called when a rules in a stylesheet in this set, or a child sheet of that,
|
|
|
|
// are mutated from CSSOM.
|
|
|
|
void RuleAdded(ServoStyleSheet&, css::Rule&);
|
|
|
|
void RuleRemoved(ServoStyleSheet&, css::Rule&);
|
|
|
|
void RuleChanged(ServoStyleSheet& aSheet, css::Rule* aRule);
|
2017-05-24 03:53:08 +03:00
|
|
|
|
2017-11-28 03:50:45 +03:00
|
|
|
// All the relevant changes are handled in RuleAdded / RuleRemoved / etc, and
|
|
|
|
// the relevant AppendSheet / RemoveSheet...
|
|
|
|
void RecordStyleSheetChange(ServoStyleSheet*, StyleSheet::ChangeType) {}
|
|
|
|
|
2018-01-16 17:14:39 +03:00
|
|
|
// Runs style invalidation due to document state changes.
|
|
|
|
void InvalidateStyleForDocumentStateChanges(EventStates aStatesChanged);
|
|
|
|
|
2017-11-28 03:50:45 +03:00
|
|
|
void RecordShadowStyleChange(dom::ShadowRoot* aShadowRoot) {
|
2017-05-24 03:53:08 +03:00
|
|
|
// FIXME(emilio): When we properly support shadow dom we'll need to do
|
|
|
|
// better.
|
2017-08-12 13:49:01 +03:00
|
|
|
MarkOriginsDirty(OriginFlags::All);
|
2017-05-24 03:53:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool StyleSheetsHaveChanged() const
|
|
|
|
{
|
|
|
|
return StylistNeedsUpdate();
|
|
|
|
}
|
|
|
|
|
2018-02-06 17:00:37 +03:00
|
|
|
nsRestyleHint MediumFeaturesChanged(MediaFeatureChangeReason);
|
2017-06-02 18:55:55 +03:00
|
|
|
|
2017-11-13 08:33:46 +03:00
|
|
|
// Evaluates a given SourceSizeList, returning the optimal viewport width in
|
|
|
|
// app units.
|
|
|
|
//
|
|
|
|
// The SourceSizeList parameter can be null, in which case it will return
|
|
|
|
// 100vw.
|
|
|
|
nscoord EvaluateSourceSizeList(const RawServoSourceSizeList* aSourceSizeList) const {
|
|
|
|
return Servo_SourceSizeList_Evaluate(mRawSet.get(), aSourceSizeList);
|
|
|
|
}
|
|
|
|
|
2017-05-24 03:53:08 +03:00
|
|
|
void InvalidateStyleForCSSRuleChanges();
|
|
|
|
|
2017-08-30 11:21:26 +03:00
|
|
|
void AddSizeOfIncludingThis(nsWindowSizes& aSizes) 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();
|
|
|
|
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2016-02-24 10:01:10 +03:00
|
|
|
ResolveStyleFor(dom::Element* aElement,
|
2017-07-17 21:42:04 +03:00
|
|
|
ServoStyleContext* aParentContext,
|
2016-11-02 09:11:24 +03:00
|
|
|
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.)
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2016-04-29 07:01:44 +03:00
|
|
|
ResolveStyleForText(nsIContent* aTextNode,
|
2017-07-17 21:42:04 +03:00
|
|
|
ServoStyleContext* aParentContext);
|
2016-04-29 07:01:44 +03:00
|
|
|
|
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)
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2017-07-17 21:42:04 +03:00
|
|
|
ResolveStyleForFirstLetterContinuation(ServoStyleContext* aParentContext);
|
2017-03-08 08:18:32 +03:00
|
|
|
|
|
|
|
// 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-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
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.
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2016-12-22 04:58:38 +03:00
|
|
|
ResolvePseudoElementStyle(dom::Element* aOriginatingElement,
|
2017-05-14 19:39:22 +03:00
|
|
|
CSSPseudoElementType aType,
|
2017-07-17 21:42:04 +03:00
|
|
|
ServoStyleContext* aParentContext,
|
2016-02-24 10:01:10 +03:00
|
|
|
dom::Element* aPseudoElement);
|
|
|
|
|
2016-12-28 10:49:12 +03:00
|
|
|
// Resolves style for a (possibly-pseudo) Element without assuming that the
|
2017-08-04 12:26:03 +03:00
|
|
|
// style has been resolved. If the element was unstyled and a new style
|
|
|
|
// context was resolved, it is not stored in the DOM. (That is, the element
|
2017-10-11 04:00:28 +03:00
|
|
|
// remains unstyled.)
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2017-08-04 12:26:03 +03:00
|
|
|
ResolveStyleLazily(dom::Element* aElement,
|
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
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.
|
2017-06-28 04:34:06 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2017-10-03 01:05:19 +03:00
|
|
|
ResolveInheritingAnonymousBoxStyle(nsAtom* aPseudoTag,
|
2017-07-17 21:42:04 +03:00
|
|
|
ServoStyleContext* 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.
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2017-10-03 01:05:19 +03:00
|
|
|
ResolveNonInheritingAnonymousBoxStyle(nsAtom* aPseudoTag);
|
2017-03-09 07:41:04 +03:00
|
|
|
|
2017-10-20 13:31:13 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
already_AddRefed<ServoStyleContext>
|
|
|
|
ResolveXULTreePseudoStyle(dom::Element* aParentElement,
|
|
|
|
nsICSSAnonBoxPseudo* aPseudoTag,
|
|
|
|
ServoStyleContext* aParentContext,
|
|
|
|
const AtomArray& aInputWord);
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2017-06-30 02:09:22 +03:00
|
|
|
void AppendAllXBLStyleSheets(nsTArray<StyleSheet*>& aArray) const;
|
|
|
|
|
2017-06-19 08:45:43 +03:00
|
|
|
template<typename Func>
|
|
|
|
void EnumerateStyleSheetArrays(Func aCallback) const {
|
|
|
|
for (const auto& sheetArray : mSheets) {
|
|
|
|
aCallback(sheetArray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2016-12-22 04:58:38 +03:00
|
|
|
ProbePseudoElementStyle(dom::Element* aOriginatingElement,
|
2017-11-28 03:50:45 +03:00
|
|
|
CSSPseudoElementType aType,
|
2017-07-17 21:42:04 +03:00
|
|
|
ServoStyleContext* aParentContext);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
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-07-26 20:00:28 +03:00
|
|
|
* We specify |ForCSSRuleChanges| to try to update all CSS animations
|
2017-05-21 02:16:26 +03:00
|
|
|
* 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-07-26 04:45:37 +03:00
|
|
|
bool StyleDocument(ServoTraversalFlags aFlags);
|
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
|
|
|
|
2017-05-19 00:21:11 +03:00
|
|
|
/**
|
2017-08-02 15:39:32 +03:00
|
|
|
* Helper for correctly calling UpdateStylist without paying the cost of an
|
2017-05-19 00:21:11 +03:00
|
|
|
* extra function call in the common no-rebuild-needed case.
|
|
|
|
*/
|
|
|
|
void UpdateStylistIfNeeded()
|
|
|
|
{
|
|
|
|
if (StylistNeedsUpdate()) {
|
|
|
|
UpdateStylist();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-16 20:20:25 +03:00
|
|
|
/**
|
|
|
|
* Checks whether the rule tree has crossed its threshold for unused nodes,
|
|
|
|
* and if so, frees them.
|
|
|
|
*/
|
|
|
|
void MaybeGCRuleTree();
|
|
|
|
|
2017-07-26 20:43:48 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the given element may be used as the root of a style
|
|
|
|
* traversal. Reasons for false include having an unstyled parent, or having
|
|
|
|
* a parent that is display:none.
|
|
|
|
*
|
|
|
|
* Most traversal callsites don't need to check this, but some do.
|
|
|
|
*/
|
2017-09-26 08:25:06 +03:00
|
|
|
static bool MayTraverseFrom(const dom::Element* aElement);
|
2017-07-26 20:43:48 +03:00
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
void AssertTreeIsClean();
|
|
|
|
#else
|
|
|
|
void AssertTreeIsClean() {}
|
|
|
|
#endif
|
|
|
|
|
2017-05-15 19:02:59 +03:00
|
|
|
/**
|
2017-08-02 15:39:32 +03:00
|
|
|
* Clears any cached style data that may depend on all sorts of computed
|
|
|
|
* values.
|
|
|
|
*
|
|
|
|
* Right now this clears the non-inheriting style context cache, and resets
|
|
|
|
* the default computed values.
|
|
|
|
*
|
|
|
|
* This does _not_, however, clear the stylist.
|
2017-05-15 19:02:59 +03:00
|
|
|
*/
|
2017-08-02 15:39:32 +03:00
|
|
|
void ClearCachedStyleData();
|
2017-05-15 19:02:59 +03:00
|
|
|
|
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
|
2017-07-20 19:36:20 +03:00
|
|
|
* ServoStyleContext.
|
|
|
|
*
|
|
|
|
* FIXME(emilio): Is there a point in this after bug 1367904?
|
2017-01-04 22:52:27 +03:00
|
|
|
*/
|
2017-08-11 22:55:32 +03:00
|
|
|
already_AddRefed<ServoStyleContext> ResolveServoStyle(dom::Element* aElement);
|
2017-01-04 22:52:27 +03:00
|
|
|
|
2017-10-10 11:00:28 +03:00
|
|
|
bool GetKeyframesForName(nsAtom* aName,
|
2017-05-13 10:34:38 +03:00
|
|
|
const nsTimingFunction& aTimingFunction,
|
|
|
|
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-07-18 15:29:12 +03:00
|
|
|
const ServoStyleContext* aContext);
|
2017-03-11 04:40:47 +03:00
|
|
|
|
2017-06-09 00:19:37 +03:00
|
|
|
void
|
|
|
|
GetAnimationValues(RawServoDeclarationBlock* aDeclarations,
|
|
|
|
dom::Element* aElement,
|
2017-07-18 15:29:12 +03:00
|
|
|
const ServoStyleContext* aContext,
|
2017-06-09 00:19:37 +03:00
|
|
|
nsTArray<RefPtr<RawServoAnimationValue>>& aAnimationValues);
|
|
|
|
|
2017-03-27 09:53:27 +03:00
|
|
|
bool AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray);
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsCSSCounterStyleRule* CounterStyleRuleForName(nsAtom* aName);
|
2017-05-11 07:47:24 +03:00
|
|
|
|
2017-08-24 04:05:53 +03:00
|
|
|
// Get all the currently-active font feature values set.
|
|
|
|
already_AddRefed<gfxFontFeatureValueSet> BuildFontFeatureValueSet();
|
|
|
|
|
2017-07-17 21:41:44 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
|
|
|
GetBaseContextForElement(dom::Element* aElement,
|
|
|
|
nsPresContext* aPresContext,
|
2017-07-17 21:42:00 +03:00
|
|
|
const ServoStyleContext* aStyle);
|
2017-04-06 04:34:50 +03:00
|
|
|
|
2017-10-19 05:51:55 +03:00
|
|
|
// Get a style context that represents |aStyle|, but as though
|
|
|
|
// it additionally matched the rules of the newly added |aAnimaitonaValue|.
|
|
|
|
// We use this function to temporarily generate a ServoStyleContext for
|
|
|
|
// calculating the cumulative change hints.
|
|
|
|
// This must hold:
|
|
|
|
// The additional rules must be appropriate for the transition
|
|
|
|
// level of the cascade, which is the highest level of the cascade.
|
|
|
|
// (This is the case for one current caller, the cover rule used
|
|
|
|
// for CSS transitions.)
|
|
|
|
// Note: |aElement| should be the generated element if it is pseudo.
|
|
|
|
already_AddRefed<ServoStyleContext>
|
|
|
|
ResolveServoStyleByAddingAnimation(dom::Element* aElement,
|
|
|
|
const ServoStyleContext* aStyle,
|
|
|
|
RawServoAnimationValue* aAnimationValue);
|
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.
|
|
|
|
*/
|
2017-07-17 21:42:00 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
|
|
|
ResolveForDeclarations(const ServoStyleContext* aParentOrNull,
|
2017-07-07 00:56:06 +03:00
|
|
|
RawServoDeclarationBlockBorrowed aDeclarations);
|
2017-04-15 01:37:35 +03:00
|
|
|
|
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-07-18 15:29:12 +03:00
|
|
|
const ServoStyleContext* aContext);
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-19 08:45:43 +03:00
|
|
|
// Returns the style rule map.
|
|
|
|
ServoStyleRuleMap* StyleRuleMap();
|
|
|
|
|
2017-05-08 11:04:31 +03:00
|
|
|
/**
|
|
|
|
* Returns true if a modification to an an attribute with the specified
|
|
|
|
* local name might require us to restyle the element.
|
|
|
|
*
|
|
|
|
* This function allows us to skip taking a an attribute snapshot when
|
|
|
|
* the modified attribute doesn't appear in an attribute selector in
|
|
|
|
* a style sheet.
|
|
|
|
*/
|
2017-06-28 08:18:02 +03:00
|
|
|
bool MightHaveAttributeDependency(const dom::Element& aElement,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute) const;
|
2017-05-08 11:04:31 +03:00
|
|
|
|
2017-05-09 13:13:45 +03:00
|
|
|
/**
|
|
|
|
* Returns true if a change in event state on an element might require
|
|
|
|
* us to restyle the element.
|
|
|
|
*
|
|
|
|
* This function allows us to skip taking a state snapshot when
|
|
|
|
* the changed state isn't depended upon by any pseudo-class selectors
|
|
|
|
* in a style sheet.
|
|
|
|
*/
|
2017-07-04 20:16:04 +03:00
|
|
|
bool HasStateDependency(const dom::Element& aElement,
|
|
|
|
EventStates aState) const;
|
2017-05-09 13:13:45 +03:00
|
|
|
|
2017-11-01 13:20:39 +03:00
|
|
|
/**
|
|
|
|
* Returns true if a change in document state might require us to restyle the
|
|
|
|
* document.
|
|
|
|
*/
|
|
|
|
bool HasDocumentStateDependency(EventStates aState) const;
|
|
|
|
|
2017-07-29 04:11:18 +03:00
|
|
|
/**
|
|
|
|
* Get a new style context that uses the same rules as the given style context
|
|
|
|
* but has a different parent.
|
|
|
|
*
|
|
|
|
* aElement is non-null if this is a style context for a frame whose mContent
|
|
|
|
* is an element and which has no pseudo on its style context (so it's the
|
|
|
|
* actual style for the element being passed).
|
|
|
|
*/
|
|
|
|
already_AddRefed<ServoStyleContext>
|
|
|
|
ReparentStyleContext(ServoStyleContext* aStyleContext,
|
|
|
|
ServoStyleContext* aNewParent,
|
|
|
|
ServoStyleContext* aNewParentIgnoringFirstLine,
|
|
|
|
ServoStyleContext* aNewLayoutParent,
|
|
|
|
Element* aElement);
|
|
|
|
|
2017-10-12 10:56:02 +03:00
|
|
|
bool IsMaster() const { return mKind == Kind::Master; }
|
|
|
|
bool IsForXBL() const { return mKind == Kind::ForXBL; }
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
private:
|
2017-08-10 20:58:40 +03:00
|
|
|
friend class AutoSetInServoTraversal;
|
|
|
|
friend class AutoPrepareTraversal;
|
2017-04-30 09:41:11 +03:00
|
|
|
|
2017-09-01 20:28:57 +03:00
|
|
|
bool ShouldTraverseInParallel() const;
|
|
|
|
|
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();
|
|
|
|
|
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-08-11 22:54:35 +03:00
|
|
|
void PreTraverse(ServoTraversalFlags aFlags,
|
|
|
|
dom::Element* aRoot = nullptr);
|
|
|
|
|
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-08-12 13:49:01 +03:00
|
|
|
/**
|
|
|
|
* Records that the contents of style sheets at the specified origin have
|
|
|
|
* changed since the last. Calling this will ensure that the Stylist
|
|
|
|
* rebuilds its selector maps.
|
|
|
|
*/
|
|
|
|
void MarkOriginsDirty(OriginFlags aChangedOrigins);
|
|
|
|
|
2017-05-15 19:02:59 +03:00
|
|
|
/**
|
|
|
|
* Note that the stylist needs a style flush due to style sheet changes.
|
|
|
|
*/
|
Bug 1418433 - move the implementation of SetStylistStyleSheetsDirty to .cpp file. r=heycam
This is a pre-patch for the real fix of Bug 1418433.
In the real fix, we'll add a IncrementUndisplayedRestyleGeneration() call into
SetStylistStyleSheetsDirty(). However, the IncrementUndisplayedRestyleGeneration()
call needs get through some deep structures in nsPresContext, RestyleManager,...
etc., and doing so means we need to move bunches of related include files, forward
declarations, from .cpp file to .h file, which doesn't make sense.
Instead, we move the implementation parts of SetStylistStyleSheetsDirty() to .cpp
file (since it is now a bit more complicated than it was), so we can use the existing
include files in the .cpp file to add IncrementUndisplayedRestyleGeneration() call
(this is in a following patch).
MozReview-Commit-ID: 3Vp9qyCf8NA
--HG--
extra : rebase_source : 16386256e16a2ca98bf988d66d861cbea58490a3
2017-11-29 13:56:15 +03:00
|
|
|
void SetStylistStyleSheetsDirty();
|
2017-09-02 10:25:45 +03:00
|
|
|
|
Bug 1418433 - move the implementation of SetStylistStyleSheetsDirty to .cpp file. r=heycam
This is a pre-patch for the real fix of Bug 1418433.
In the real fix, we'll add a IncrementUndisplayedRestyleGeneration() call into
SetStylistStyleSheetsDirty(). However, the IncrementUndisplayedRestyleGeneration()
call needs get through some deep structures in nsPresContext, RestyleManager,...
etc., and doing so means we need to move bunches of related include files, forward
declarations, from .cpp file to .h file, which doesn't make sense.
Instead, we move the implementation parts of SetStylistStyleSheetsDirty() to .cpp
file (since it is now a bit more complicated than it was), so we can use the existing
include files in the .cpp file to add IncrementUndisplayedRestyleGeneration() call
(this is in a following patch).
MozReview-Commit-ID: 3Vp9qyCf8NA
--HG--
extra : rebase_source : 16386256e16a2ca98bf988d66d861cbea58490a3
2017-11-29 13:56:15 +03:00
|
|
|
void SetStylistXBLStyleSheetsDirty();
|
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-07-17 21:42:00 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2017-08-04 12:26:03 +03:00
|
|
|
ResolveStyleLazilyInternal(dom::Element* aElement,
|
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
StyleRuleInclusion aRules =
|
2017-11-09 20:29:36 +03:00
|
|
|
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
|
|
|
|
2017-08-31 23:50:24 +03:00
|
|
|
const Kind mKind;
|
2017-09-02 10:25:45 +03:00
|
|
|
|
2018-01-05 15:51:08 +03:00
|
|
|
// The owner document of this style set. Null if this is an XBL style set.
|
|
|
|
//
|
|
|
|
// TODO(emilio): This should become a DocumentOrShadowRoot, and be owned by it
|
|
|
|
// directly instead of the shell, eventually.
|
|
|
|
nsIDocument* mDocument;
|
|
|
|
|
|
|
|
const nsPresContext* GetPresContext() const {
|
|
|
|
return const_cast<ServoStyleSet*>(this)->GetPresContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the associated pres context if we're the master style set and we
|
|
|
|
* have an associated pres shell.
|
|
|
|
*/
|
|
|
|
nsPresContext* GetPresContext();
|
2017-09-02 10:25:45 +03:00
|
|
|
|
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-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-07-07 08:35:28 +03:00
|
|
|
uint32_t mUserFontCacheUpdateGeneration;
|
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,
|
2017-07-20 19:36:20 +03:00
|
|
|
RefPtr<ServoStyleContext>> 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-06-19 08:45:43 +03:00
|
|
|
// Map from raw Servo style rule to Gecko's wrapper object.
|
|
|
|
// Constructed lazily when requested by devtools.
|
2017-11-28 03:50:45 +03:00
|
|
|
UniquePtr<ServoStyleRuleMap> mStyleRuleMap;
|
2016-02-24 10:01:10 +03:00
|
|
|
};
|
|
|
|
|
Bug 1400078 - Measure the UA cache. r=njn.
ServoStyleSetSizes now has two uses, one for the Stylist, and one for the UA
cache, and so the patch removes 'Stylist' from the field names.
Example output from about:memory:
> +----1,359,608 B (00.55%) -- layout
> | +----756,488 B (00.31%) -- style-sheet-cache [2]
> | +----393,968 B (00.16%) -- servo-ua-cache
> | | +--234,496 B (00.10%) -- element-and-pseudos-maps
> | | +---59,648 B (00.02%) -- revalidation-selectors
> | | +---58,320 B (00.02%) -- invalidation-map
> | | +---30,752 B (00.01%) -- other
> | | +---10,752 B (00.00%) -- precomputed-pseudos
MozReview-Commit-ID: 8oxuJO0ojp
--HG--
extra : rebase_source : 7d86216967259b71df7280261d025cc65bf00ba4
2017-09-19 02:25:00 +03:00
|
|
|
class UACacheReporter final : public nsIMemoryReporter
|
|
|
|
{
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
|
|
|
|
|
|
|
private:
|
|
|
|
~UACacheReporter() {}
|
|
|
|
};
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_ServoStyleSet_h
|