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-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;
|
2019-01-02 16:05:23 +03:00
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
class nsPresContext;
|
2017-01-29 06:58:28 +03:00
|
|
|
struct nsTimingFunction;
|
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,
|
|
|
|
|
2019-04-23 19:43:15 +03:00
|
|
|
// Some of the style sheets of the shadow trees in the document have
|
|
|
|
// changed.
|
|
|
|
ShadowDOMStyleSheetsDirty = 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;
|
|
|
|
|
2019-04-19 07:20:31 +03:00
|
|
|
using Origin = StyleOrigin;
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
public:
|
2019-04-19 07:32:12 +03:00
|
|
|
static constexpr const StyleOrigin kOrigins[] = {
|
|
|
|
StyleOrigin::UserAgent, StyleOrigin::User, StyleOrigin::Author};
|
|
|
|
|
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; }
|
|
|
|
|
2019-04-03 10:02:00 +03:00
|
|
|
explicit ServoStyleSet(dom::Document&);
|
2017-03-08 08:18:39 +03:00
|
|
|
~ServoStyleSet();
|
2016-02-24 10:01:12 +03:00
|
|
|
|
2019-04-03 10:02:00 +03:00
|
|
|
void ShellDetachedFromDocument();
|
2016-02-24 10:01:10 +03:00
|
|
|
|
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(); }
|
|
|
|
|
2019-03-14 14:47:50 +03:00
|
|
|
RestyleHint 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-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 08:46:39 +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(
|
2019-02-19 16:44:33 +03:00
|
|
|
nsIContent* aTextNode, ComputedStyle* aParentStyle);
|
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 08:46:39 +03:00
|
|
|
// nsCSSAnonBoxes::firstLetterContinuation() as its pseudo.
|
2017-03-08 08:18:32 +03:00
|
|
|
//
|
2018-08-15 08:46:39 +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(
|
2019-02-19 16:44:33 +03:00
|
|
|
ComputedStyle* aParentStyle);
|
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 08:46:39 +03:00
|
|
|
// The returned ComputedStyle will have nsCSSAnonBoxes::oofPlaceholder() as
|
2017-03-08 08:18:32 +03:00
|
|
|
// its pseudo.
|
|
|
|
//
|
2018-08-15 08:46:39 +03:00
|
|
|
// (Perhaps nsCSSAnonBoxes::oofPaceholder() should go away and we shouldn't
|
2018-03-22 21:20:41 +03:00
|
|
|
// even 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> ResolveStyleForPlaceholder();
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2019-05-01 22:03:06 +03:00
|
|
|
// Get a ComputedStyle for a pseudo-element. aParentElement must be
|
|
|
|
// non-null. aPseudoID is the PseudoStyleType 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> ResolvePseudoElementStyle(
|
2019-05-01 22:03:06 +03:00
|
|
|
dom::Element* aOriginatingElement, PseudoStyleType aType,
|
|
|
|
ComputedStyle* aParentStyle, dom::Element* aPseudoElement);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
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
|
2019-04-09 21:05:04 +03:00
|
|
|
// was resolved, it is not stored in the DOM. (That is, the element remains
|
|
|
|
// unstyled.)
|
|
|
|
//
|
|
|
|
// TODO(emilio): Element argument should be `const`.
|
2018-03-22 21:20:41 +03:00
|
|
|
already_AddRefed<ComputedStyle> ResolveStyleLazily(
|
2019-04-09 21:05:04 +03:00
|
|
|
dom::Element&, PseudoStyleType = PseudoStyleType::NotPseudo,
|
|
|
|
StyleRuleInclusion = StyleRuleInclusion::All);
|
2016-12-28 10:49:12 +03:00
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
// Get a ComputedStyle for an anonymous box. The pseudo type must be an
|
|
|
|
// inheriting anon box.
|
2017-10-03 01:05:19 +03:00
|
|
|
already_AddRefed<ComputedStyle> ResolveInheritingAnonymousBoxStyle(
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType, ComputedStyle* aParentStyle);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
// Get a ComputedStyle for an anonymous box. The pseudo type must be
|
|
|
|
// a non-inheriting anon box.
|
2017-10-03 01:05:19 +03:00
|
|
|
already_AddRefed<ComputedStyle> ResolveNonInheritingAnonymousBoxStyle(
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType);
|
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> ResolveXULTreePseudoStyle(
|
2018-10-10 08:49:13 +03:00
|
|
|
dom::Element* aParentElement, nsCSSAnonBoxPseudoStaticAtom* aPseudoTag,
|
2019-02-19 16:44:33 +03:00
|
|
|
ComputedStyle* aParentStyle, const AtomArray& aInputWord);
|
2017-10-20 13:31:13 +03:00
|
|
|
#endif
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
// manage the set of style sheets in the style set
|
2019-04-19 07:20:31 +03:00
|
|
|
void AppendStyleSheet(Origin, StyleSheet*);
|
|
|
|
void RemoveStyleSheet(Origin, StyleSheet*);
|
|
|
|
void InsertStyleSheetBefore(Origin, StyleSheet*, StyleSheet* aReferenceSheet);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2019-04-19 07:20:31 +03:00
|
|
|
size_t SheetCount(Origin) const;
|
|
|
|
StyleSheet* SheetAt(Origin, size_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
|
|
|
|
2019-04-19 07:20:31 +03:00
|
|
|
void RemoveDocStyleSheet(StyleSheet* aSheet) {
|
|
|
|
RemoveStyleSheet(StyleOrigin::Author, aSheet);
|
2017-06-19 08:45:43 +03:00
|
|
|
}
|
|
|
|
|
2019-04-19 07:20:31 +03:00
|
|
|
void AddDocStyleSheet(StyleSheet* aSheet);
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2019-05-01 22:03:06 +03:00
|
|
|
// check whether there is ::before/::after style for an element
|
|
|
|
already_AddRefed<ComputedStyle> ProbePseudoElementStyle(
|
|
|
|
const dom::Element& aOriginatingElement, PseudoStyleType aType,
|
|
|
|
ComputedStyle* aParentStyle);
|
|
|
|
|
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();
|
|
|
|
|
2019-04-19 07:20:31 +03:00
|
|
|
template <typename T>
|
|
|
|
void EnumerateStyleSheets(T aCb) {
|
|
|
|
for (auto origin : kOrigins) {
|
|
|
|
for (size_t i = 0, count = SheetCount(origin); i < count; ++i) {
|
|
|
|
aCb(*SheetAt(origin, i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2019-04-05 00:40:55 +03:00
|
|
|
void AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray);
|
2017-03-27 09:53:27 +03:00
|
|
|
|
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> GetBaseContextForElement(
|
|
|
|
dom::Element* aElement, 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.
|
|
|
|
already_AddRefed<ComputedStyle> ResolveServoStyleByAddingAnimation(
|
2018-03-22 21:20:41 +03:00
|
|
|
dom::Element* aElement, 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,
|
2019-03-21 20:00:27 +03:00
|
|
|
const RawServoDeclarationBlock* aDeclarations);
|
2017-04-15 01:37:35 +03:00
|
|
|
|
2017-05-03 06:15:27 +03:00
|
|
|
already_AddRefed<RawServoAnimationValue> ComputeAnimationValue(
|
2017-06-02 03:38:22 +03:00
|
|
|
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, dom::Element* aElement);
|
2018-11-30 13:46:48 +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;
|
2019-04-27 18:37:58 +03:00
|
|
|
friend class PostTraversalTask;
|
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
|
|
|
|
2019-04-23 19:43:15 +03:00
|
|
|
void SetStylistShadowDOMStyleSheetsDirty();
|
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-04-30 09:45:32 +03:00
|
|
|
void RunPostTraversalTasks();
|
|
|
|
|
2019-04-19 07:20:31 +03:00
|
|
|
void PrependSheetOfType(Origin, StyleSheet*);
|
|
|
|
void AppendSheetOfType(Origin, StyleSheet*);
|
|
|
|
void InsertSheetOfType(Origin, StyleSheet*, StyleSheet* aBeforeSheet);
|
|
|
|
void RemoveSheetOfType(Origin, StyleSheet*);
|
2018-01-05 15:51:08 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-04-19 07:20:31 +03:00
|
|
|
// The owner document of this style set. Never null, and always outlives the
|
|
|
|
// StyleSet.
|
|
|
|
dom::Document* mDocument;
|
2016-01-27 05:02:04 +03:00
|
|
|
UniquePtr<RawServoStyleSet> mRawSet;
|
2017-02-02 22:48:28 +03:00
|
|
|
|
2019-04-19 07:20:31 +03:00
|
|
|
// Map from raw Servo style rule to Gecko's wrapper object.
|
|
|
|
// Constructed lazily when requested by devtools.
|
|
|
|
UniquePtr<ServoStyleRuleMap> mStyleRuleMap;
|
|
|
|
uint64_t mUserFontSetUpdateGeneration = 0;
|
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;
|
|
|
|
|
2019-04-19 07:20:31 +03:00
|
|
|
// Stores pointers to our cached ComputedStyles for non-inheriting anonymous
|
|
|
|
// boxes.
|
|
|
|
EnumeratedArray<nsCSSAnonBoxes::NonInheriting,
|
|
|
|
nsCSSAnonBoxes::NonInheriting::_Count, RefPtr<ComputedStyle>>
|
|
|
|
mNonInheritingComputedStyles;
|
|
|
|
|
|
|
|
StylistState mStylistState = StylistState::NotDirty;
|
|
|
|
bool mAuthorStyleDisabled = false;
|
|
|
|
bool mNeedsRestyleAfterEnsureUniqueInner = false;
|
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
|