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"
|
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"
|
2017-04-30 09:45:32 +03:00
|
|
|
#include "mozilla/ServoUtils.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"
|
2018-03-29 14:15:46 +03:00
|
|
|
#include "nsCoord.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 {
|
2018-03-29 14:15:46 +03:00
|
|
|
namespace css {
|
|
|
|
class Rule;
|
|
|
|
} // namespace css
|
2016-02-24 10:01:10 +03:00
|
|
|
namespace dom {
|
|
|
|
class Element;
|
2018-03-29 14:15:46 +03:00
|
|
|
class ShadowRoot;
|
2016-02-24 10:01:10 +03:00
|
|
|
} // namespace dom
|
2018-04-30 18:50:03 +03:00
|
|
|
class StyleSheet;
|
2017-01-29 06:58:28 +03:00
|
|
|
struct Keyframe;
|
2017-05-07 17:36:47 +03:00
|
|
|
class ServoElementSnapshotTable;
|
2018-03-22 21:20:41 +03:00
|
|
|
class ComputedStyle;
|
2017-06-19 08:45:43 +03:00
|
|
|
class ServoStyleRuleMap;
|
2018-03-29 14:15:46 +03:00
|
|
|
class StyleSheet;
|
2016-02-24 10:01:10 +03:00
|
|
|
} // namespace mozilla
|
2018-03-29 14:15:46 +03:00
|
|
|
class gfxFontFeatureValueSet;
|
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
|
2018-04-30 18:50:03 +03:00
|
|
|
* Stylist. A ServoStyleSet contains StyleSheets.
|
2016-02-24 10:01:10 +03:00
|
|
|
*/
|
|
|
|
class ServoStyleSet
|
|
|
|
{
|
2018-04-05 21:55:51 +03:00
|
|
|
friend class RestyleManager;
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-16 13:49:18 +03:00
|
|
|
ServoStyleSet();
|
2017-03-08 08:18:39 +03:00
|
|
|
~ServoStyleSet();
|
2016-02-24 10:01:12 +03:00
|
|
|
|
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.
|
2018-04-30 18:50:03 +03:00
|
|
|
void RuleAdded(StyleSheet&, css::Rule&);
|
|
|
|
void RuleRemoved(StyleSheet&, css::Rule&);
|
|
|
|
void RuleChanged(StyleSheet& aSheet, css::Rule* aRule);
|
2017-05-24 03:53:08 +03:00
|
|
|
|
2018-01-16 17:14:39 +03:00
|
|
|
// Runs style invalidation due to document state changes.
|
|
|
|
void InvalidateStyleForDocumentStateChanges(EventStates aStatesChanged);
|
|
|
|
|
2018-02-18 16:35:57 +03:00
|
|
|
void RecordShadowStyleChange(dom::ShadowRoot&);
|
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.
|
2018-03-29 14:15:46 +03:00
|
|
|
inline nscoord EvaluateSourceSizeList(
|
|
|
|
const RawServoSourceSizeList* aSourceSizeList) const;
|
2017-11-13 08:33:46 +03:00
|
|
|
|
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
|
|
|
|
2018-02-08 15:05:28 +03:00
|
|
|
bool GetAuthorStyleDisabled() const
|
|
|
|
{
|
|
|
|
return mAuthorStyleDisabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetAuthorStyleDisabled(bool aStyleDisabled);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2018-07-24 19:15:01 +03:00
|
|
|
// FIXME(emilio): All the callers pass Allow here, and aParentContext isn't
|
|
|
|
// used...
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
2016-02-24 10:01:10 +03:00
|
|
|
ResolveStyleFor(dom::Element* aElement,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aParentContext,
|
2016-11-02 09:11:24 +03:00
|
|
|
LazyComputeBehavior aMayCompute);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
// Get a CopmutedStyle for a text node (which no rules will match).
|
2017-03-08 08:18:32 +03:00
|
|
|
//
|
2018-08-15 09:14:41 +03:00
|
|
|
// The returned ComputedStyle will have nsCSSAnonBoxes::mozText as its pseudo.
|
2017-03-08 08:18:32 +03:00
|
|
|
//
|
|
|
|
// (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.)
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
|
|
|
ResolveStyleForText(nsIContent* aTextNode, ComputedStyle* aParentContext);
|
2016-04-29 07:01:44 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
// Get a ComputedStyle for a first-letter continuation (which no rules will
|
2017-03-08 08:18:32 +03:00
|
|
|
// match).
|
|
|
|
//
|
2018-03-22 21:20:41 +03:00
|
|
|
// The returned ComputedStyle will have
|
2018-08-15 09:14:41 +03:00
|
|
|
// nsCSSAnonBoxes::firstLetterContinuation as its pseudo.
|
2017-03-08 08:18:32 +03:00
|
|
|
//
|
2018-08-15 09:14:41 +03:00
|
|
|
// (Perhaps nsCSSAnonBoxes::firstLetterContinuation should go away and we
|
2018-03-22 21:20:41 +03:00
|
|
|
// shouldn't even create ComputedStyles for such frames. However, not doing
|
2017-03-08 08:18:32 +03:00
|
|
|
// any rule matching for them is a first step. And right now we do use this
|
2018-03-22 21:20:41 +03:00
|
|
|
// ComputedStyle for some things)
|
|
|
|
already_AddRefed<ComputedStyle>
|
|
|
|
ResolveStyleForFirstLetterContinuation(ComputedStyle* aParentContext);
|
2017-03-08 08:18:32 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
// Get a ComputedStyle for a placeholder frame (which no rules will match).
|
2017-03-08 08:18:32 +03:00
|
|
|
//
|
2018-08-15 09:14:41 +03:00
|
|
|
// The returned ComputedStyle will have nsCSSAnonBoxes::oofPlaceholder as
|
2017-03-08 08:18:32 +03:00
|
|
|
// its pseudo.
|
|
|
|
//
|
2018-08-15 09:14:41 +03:00
|
|
|
// (Perhaps nsCSSAnonBoxes::oofPaceholder should go away and we shouldn't even
|
2018-03-22 21:20:41 +03:00
|
|
|
// create ComputedStyle for placeholders. However, not doing any rule
|
2017-03-08 08:18:40 +03:00
|
|
|
// matching for them is a first step.)
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
2017-03-08 08:18:40 +03:00
|
|
|
ResolveStyleForPlaceholder();
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
// Get a ComputedStyle for a pseudo-element. aParentElement must be
|
2017-03-08 08:18:32 +03:00
|
|
|
// 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.
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
2016-12-22 04:58:38 +03:00
|
|
|
ResolvePseudoElementStyle(dom::Element* aOriginatingElement,
|
2017-05-14 19:39:22 +03:00
|
|
|
CSSPseudoElementType aType,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* 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.)
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
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
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
// Get a ComputedStyle for an anonymous box. aPseudoTag is the pseudo-tag to
|
2017-03-09 07:41:04 +03:00
|
|
|
// 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.
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
2017-10-03 01:05:19 +03:00
|
|
|
ResolveInheritingAnonymousBoxStyle(nsAtom* aPseudoTag,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aParentContext);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
// Get a ComputedStyle for an anonymous box that does not inherit style from
|
2017-03-09 07:41:04 +03:00
|
|
|
// 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.
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
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
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
2017-10-20 13:31:13 +03:00
|
|
|
ResolveXULTreePseudoStyle(dom::Element* aParentElement,
|
|
|
|
nsICSSAnonBoxPseudo* aPseudoTag,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aParentContext,
|
2017-10-20 13:31:13 +03:00
|
|
|
const AtomArray& aInputWord);
|
|
|
|
#endif
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
// manage the set of style sheets in the style set
|
2018-04-30 18:50:03 +03:00
|
|
|
nsresult AppendStyleSheet(SheetType aType, StyleSheet* aSheet);
|
|
|
|
nsresult PrependStyleSheet(SheetType aType, StyleSheet* aSheet);
|
|
|
|
nsresult RemoveStyleSheet(SheetType aType, StyleSheet* aSheet);
|
2016-02-24 10:01:10 +03:00
|
|
|
nsresult ReplaceSheets(SheetType aType,
|
2018-04-30 18:50:03 +03:00
|
|
|
const nsTArray<RefPtr<StyleSheet>>& aNewSheets);
|
2016-02-24 10:01:10 +03:00
|
|
|
nsresult InsertStyleSheetBefore(SheetType aType,
|
2018-04-30 18:50:03 +03:00
|
|
|
StyleSheet* aNewSheet,
|
|
|
|
StyleSheet* aReferenceSheet);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
|
|
|
int32_t SheetCount(SheetType aType) const;
|
2018-04-30 18:50:03 +03:00
|
|
|
StyleSheet* StyleSheetAt(SheetType aType, int32_t aIndex) const;
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2018-04-16 20:10:57 +03:00
|
|
|
void AppendAllNonDocumentAuthorSheets(nsTArray<StyleSheet*>& aArray) const;
|
2017-06-30 02:09:22 +03:00
|
|
|
|
2017-06-19 08:45:43 +03:00
|
|
|
template<typename Func>
|
|
|
|
void EnumerateStyleSheetArrays(Func aCallback) const {
|
|
|
|
for (const auto& sheetArray : mSheets) {
|
|
|
|
aCallback(sheetArray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-30 18:50:03 +03:00
|
|
|
nsresult RemoveDocStyleSheet(StyleSheet* aSheet);
|
|
|
|
nsresult AddDocStyleSheet(StyleSheet* aSheet, nsIDocument* aDocument);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
|
|
|
// check whether there is ::before/::after style for an element
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
2018-07-24 19:15:01 +03:00
|
|
|
ProbePseudoElementStyle(const dom::Element& aOriginatingElement,
|
2017-11-28 03:50:45 +03:00
|
|
|
CSSPseudoElementType aType,
|
2018-07-24 19:15:01 +03:00
|
|
|
ComputedStyle* aParentStyle);
|
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.
|
|
|
|
*
|
2018-03-22 21:20:41 +03:00
|
|
|
* Right now this clears the non-inheriting ComputedStyle cache, and resets
|
2017-08-02 15:39:32 +03:00
|
|
|
* 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
|
2018-03-22 21:20:41 +03:00
|
|
|
* ComputedStyle.
|
2017-07-20 19:36:20 +03:00
|
|
|
*
|
|
|
|
* FIXME(emilio): Is there a point in this after bug 1367904?
|
2017-01-04 22:52:27 +03:00
|
|
|
*/
|
2018-07-24 19:15:01 +03:00
|
|
|
inline already_AddRefed<ComputedStyle> ResolveServoStyle(const dom::Element&);
|
2017-01-04 22:52:27 +03:00
|
|
|
|
2018-07-06 06:19:10 +03:00
|
|
|
bool GetKeyframesForName(const dom::Element&,
|
|
|
|
const ComputedStyle&,
|
2018-05-01 08:09:12 +03:00
|
|
|
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,
|
2018-07-24 19:15:01 +03:00
|
|
|
const ComputedStyle* aStyle);
|
2017-03-11 04:40:47 +03:00
|
|
|
|
2017-06-09 00:19:37 +03:00
|
|
|
void
|
|
|
|
GetAnimationValues(RawServoDeclarationBlock* aDeclarations,
|
|
|
|
dom::Element* aElement,
|
2018-03-22 21:20:41 +03:00
|
|
|
const mozilla::ComputedStyle* aStyle,
|
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);
|
|
|
|
|
2018-04-05 01:41:28 +03:00
|
|
|
const RawServoCounterStyleRule* 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();
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
2017-07-17 21:41:44 +03:00
|
|
|
GetBaseContextForElement(dom::Element* aElement,
|
2018-03-22 21:20:41 +03:00
|
|
|
const ComputedStyle* aStyle);
|
2017-04-06 04:34:50 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
// Get a ComputedStyle that represents |aStyle|, but as though it additionally
|
|
|
|
// matched the rules of the newly added |aAnimaitonaValue|.
|
|
|
|
//
|
|
|
|
// We use this function to temporarily generate a ComputedStyle for
|
2017-10-19 05:51:55 +03:00
|
|
|
// calculating the cumulative change hints.
|
2018-03-22 21:20:41 +03:00
|
|
|
//
|
2017-10-19 05:51:55 +03:00
|
|
|
// 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.
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
2017-10-19 05:51:55 +03:00
|
|
|
ResolveServoStyleByAddingAnimation(dom::Element* aElement,
|
2018-03-22 21:20:41 +03:00
|
|
|
const ComputedStyle* aStyle,
|
2017-10-19 05:51:55 +03:00
|
|
|
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.
|
|
|
|
*/
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
|
|
|
ResolveForDeclarations(const ComputedStyle* 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,
|
2018-03-22 21:20:41 +03:00
|
|
|
const mozilla::ComputedStyle* aStyle);
|
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.
|
|
|
|
*/
|
2018-07-24 19:15:01 +03:00
|
|
|
bool MightHaveAttributeDependency(const dom::Element&, 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.
|
|
|
|
*/
|
2018-07-24 19:15:01 +03:00
|
|
|
bool HasStateDependency(const dom::Element&, EventStates) 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
|
|
|
/**
|
2018-03-22 21:20:41 +03:00
|
|
|
* Get a new ComputedStyle that uses the same rules as the given ComputedStyle
|
2017-07-29 04:11:18 +03:00
|
|
|
* but has a different parent.
|
|
|
|
*
|
2018-03-22 21:20:41 +03:00
|
|
|
* aElement is non-null if this is a ComputedStyle for a frame whose mContent
|
|
|
|
* is an element and which has no pseudo on its ComputedStyle (so it's the
|
2017-07-29 04:11:18 +03:00
|
|
|
* actual style for the element being passed).
|
|
|
|
*/
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
|
|
|
ReparentComputedStyle(ComputedStyle* aComputedStyle,
|
|
|
|
ComputedStyle* aNewParent,
|
|
|
|
ComputedStyle* aNewParentIgnoringFirstLine,
|
|
|
|
ComputedStyle* aNewLayoutParent,
|
2018-03-29 14:15:46 +03:00
|
|
|
dom::Element* aElement);
|
2017-07-29 04:11:18 +03:00
|
|
|
|
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
|
|
|
/**
|
2018-05-30 19:15:25 +03:00
|
|
|
* Resolve all DeclarationBlocks attached to mapped
|
2017-01-20 02:56:53 +03:00
|
|
|
* 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
|
|
|
/**
|
2018-03-22 21:20:41 +03:00
|
|
|
* Clear our cached mNonInheritingComputedStyles.
|
2017-05-07 17:36:47 +03:00
|
|
|
*
|
2018-03-22 21:20:41 +03:00
|
|
|
* We do this when we want to make sure those ComputedStyles won't live too
|
2017-05-07 17:36:47 +03:00
|
|
|
* long (e.g. when rebuilding all style data or when shutting down the style
|
|
|
|
* set).
|
2017-03-08 08:18:39 +03:00
|
|
|
*/
|
2018-03-22 21:20:41 +03:00
|
|
|
void ClearNonInheritingComputedStyles();
|
2017-03-08 08:18:39 +03:00
|
|
|
|
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
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle>
|
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,
|
2018-04-30 18:50:03 +03:00
|
|
|
StyleSheet* aSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void AppendSheetOfType(SheetType aType,
|
2018-04-30 18:50:03 +03:00
|
|
|
StyleSheet* aSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void InsertSheetOfType(SheetType aType,
|
2018-04-30 18:50:03 +03:00
|
|
|
StyleSheet* aSheet,
|
|
|
|
StyleSheet* aBeforeSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void RemoveSheetOfType(SheetType aType,
|
2018-04-30 18:50:03 +03:00
|
|
|
StyleSheet* aSheet);
|
2017-05-02 02:46:41 +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,
|
2018-04-30 18:50:03 +03:00
|
|
|
nsTArray<RefPtr<StyleSheet>>> 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-02-02 22:48:28 +03:00
|
|
|
|
2017-05-16 02:30:10 +03:00
|
|
|
bool mNeedsRestyleAfterEnsureUniqueInner;
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
// Stores pointers to our cached ComputedStyles for non-inheriting anonymous
|
2017-03-08 08:18:39 +03:00
|
|
|
// boxes.
|
2017-03-09 07:39:45 +03:00
|
|
|
EnumeratedArray<nsCSSAnonBoxes::NonInheriting,
|
|
|
|
nsCSSAnonBoxes::NonInheriting::_Count,
|
2018-03-22 21:20:41 +03:00
|
|
|
RefPtr<ComputedStyle>> mNonInheritingComputedStyles;
|
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
|