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/. */
|
|
|
|
|
|
|
|
#include "mozilla/ServoStyleSet.h"
|
|
|
|
|
2017-04-08 01:49:44 +03:00
|
|
|
#include "gfxPlatformFontList.h"
|
2017-06-28 22:03:18 +03:00
|
|
|
#include "mozilla/AutoRestyleTimelineMarker.h"
|
2016-12-01 11:19:50 +03:00
|
|
|
#include "mozilla/DocumentStyleRootIterator.h"
|
2017-08-03 23:16:31 +03:00
|
|
|
#include "mozilla/LookAndFeel.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 "mozilla/RestyleManagerInlines.h"
|
2017-06-14 02:38:16 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2016-07-13 23:42:47 +03:00
|
|
|
#include "mozilla/ServoRestyleManager.h"
|
2017-06-19 08:45:43 +03:00
|
|
|
#include "mozilla/ServoStyleRuleMap.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 "mozilla/ServoTypes.h"
|
2017-06-19 08:45:43 +03:00
|
|
|
#include "mozilla/css/Loader.h"
|
2017-03-18 09:15:09 +03:00
|
|
|
#include "mozilla/dom/AnonymousContent.h"
|
2016-08-12 00:12:49 +03:00
|
|
|
#include "mozilla/dom/ChildIterator.h"
|
2017-07-08 13:00:24 +03:00
|
|
|
#include "mozilla/dom/FontFaceSet.h"
|
2017-01-01 03:10:45 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/dom/ElementInlines.h"
|
2016-02-24 10:01:10 +03:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2017-06-18 12:57:55 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2016-03-18 23:14:07 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2017-04-14 04:28:25 +03:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2017-04-08 01:49:44 +03:00
|
|
|
#include "nsDeviceContext.h"
|
2017-01-20 02:56:53 +03:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2017-06-18 12:57:55 +03:00
|
|
|
#include "nsIAnonymousContentCreator.h"
|
2016-04-29 07:01:44 +03:00
|
|
|
#include "nsIDocumentInlines.h"
|
2016-07-28 06:03:49 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2017-04-26 07:00:11 +03:00
|
|
|
#include "nsSMILAnimationController.h"
|
2016-03-18 23:14:07 +03:00
|
|
|
#include "nsStyleContext.h"
|
2016-02-26 04:51:02 +03:00
|
|
|
#include "nsStyleSet.h"
|
2017-05-26 17:29:10 +03:00
|
|
|
#include "gfxUserFontSet.h"
|
2016-02-24 10:01:10 +03:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2017-08-10 20:58:40 +03:00
|
|
|
ServoStyleSet* ServoStyleSet::sInServoTraversal = nullptr;
|
|
|
|
|
2017-09-19 04:26:29 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool
|
|
|
|
ServoStyleSet::IsCurrentThreadInServoTraversal()
|
|
|
|
{
|
|
|
|
return sInServoTraversal && (NS_IsMainThread() || Servo_IsWorkerThread());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-08-10 20:58:40 +03:00
|
|
|
namespace mozilla {
|
|
|
|
// On construction, sets sInServoTraversal to the given ServoStyleSet.
|
|
|
|
// On destruction, clears sInServoTraversal and calls RunPostTraversalTasks.
|
|
|
|
class MOZ_RAII AutoSetInServoTraversal
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoSetInServoTraversal(ServoStyleSet* aSet)
|
|
|
|
: mSet(aSet)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!ServoStyleSet::sInServoTraversal);
|
|
|
|
MOZ_ASSERT(aSet);
|
|
|
|
ServoStyleSet::sInServoTraversal = aSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSetInServoTraversal()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(ServoStyleSet::sInServoTraversal);
|
|
|
|
ServoStyleSet::sInServoTraversal = nullptr;
|
|
|
|
mSet->RunPostTraversalTasks();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ServoStyleSet* mSet;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Sets up for one or more calls to Servo_TraverseSubtree.
|
|
|
|
class MOZ_RAII AutoPrepareTraversal
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoPrepareTraversal(ServoStyleSet* aSet)
|
|
|
|
// For markers for animations, we have already set the markers in
|
|
|
|
// ServoRestyleManager::PostRestyleEventForAnimations so that we don't need
|
|
|
|
// to care about animation restyles here.
|
|
|
|
: mTimelineMarker(aSet->mPresContext->GetDocShell(), false)
|
|
|
|
, mSetInServoTraversal(aSet)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!aSet->StylistNeedsUpdate());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
AutoRestyleTimelineMarker mTimelineMarker;
|
|
|
|
AutoSetInServoTraversal mSetInServoTraversal;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2017-08-31 23:50:24 +03:00
|
|
|
ServoStyleSet::ServoStyleSet(Kind aKind)
|
|
|
|
: mKind(aKind)
|
|
|
|
, mPresContext(nullptr)
|
2017-04-11 10:43:14 +03:00
|
|
|
, mAuthorStyleDisabled(false)
|
2017-05-15 19:02:59 +03:00
|
|
|
, mStylistState(StylistState::NotDirty)
|
2017-05-26 17:29:10 +03:00
|
|
|
, mUserFontSetUpdateGeneration(0)
|
2017-07-07 08:35:28 +03:00
|
|
|
, mUserFontCacheUpdateGeneration(0)
|
2017-05-16 02:30:10 +03:00
|
|
|
, mNeedsRestyleAfterEnsureUniqueInner(false)
|
2016-02-24 10:01:12 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-03-08 08:18:39 +03:00
|
|
|
ServoStyleSet::~ServoStyleSet()
|
|
|
|
{
|
2017-05-24 03:02:51 +03:00
|
|
|
for (auto& sheetArray : mSheets) {
|
|
|
|
for (auto& sheet : sheetArray) {
|
|
|
|
sheet->DropStyleSet(this);
|
|
|
|
}
|
|
|
|
}
|
2017-03-08 08:18:39 +03:00
|
|
|
}
|
|
|
|
|
2017-09-01 11:45:39 +03:00
|
|
|
UniquePtr<ServoStyleSet>
|
|
|
|
ServoStyleSet::CreateXBLServoStyleSet(
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
const nsTArray<RefPtr<ServoStyleSheet>>& aNewSheets)
|
|
|
|
{
|
|
|
|
auto set = MakeUnique<ServoStyleSet>(Kind::ForXBL);
|
|
|
|
set->Init(aPresContext, nullptr);
|
|
|
|
|
|
|
|
// The XBL style sheets aren't document level sheets, but we need to
|
|
|
|
// decide a particular SheetType to add them to style set. This type
|
|
|
|
// doesn't affect the place where we pull those rules from
|
|
|
|
// stylist::push_applicable_declarations_as_xbl_only_stylist().
|
|
|
|
set->ReplaceSheets(SheetType::Doc, aNewSheets);
|
|
|
|
|
|
|
|
// Update stylist immediately.
|
|
|
|
set->UpdateStylist();
|
|
|
|
|
|
|
|
// The PresContext of the bound document could be destroyed anytime later,
|
|
|
|
// which shouldn't be used for XBL styleset, so we clear it here to avoid
|
|
|
|
// dangling pointer.
|
|
|
|
set->mPresContext = nullptr;
|
|
|
|
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
void
|
2017-06-29 23:43:59 +03:00
|
|
|
ServoStyleSet::Init(nsPresContext* aPresContext, nsBindingManager* aBindingManager)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-03-18 23:14:07 +03:00
|
|
|
mPresContext = aPresContext;
|
2017-09-04 12:57:00 +03:00
|
|
|
mLastPresContextUsesXBLStyleSet = aPresContext;
|
2017-09-02 10:25:45 +03:00
|
|
|
|
2017-01-04 22:52:26 +03:00
|
|
|
mRawSet.reset(Servo_StyleSet_Init(aPresContext));
|
2017-06-29 23:43:59 +03:00
|
|
|
mBindingManager = aBindingManager;
|
2017-01-04 22:52:26 +03:00
|
|
|
|
2017-04-08 01:49:44 +03:00
|
|
|
mPresContext->DeviceContext()->InitFontCache();
|
|
|
|
|
2017-01-04 22:52:26 +03:00
|
|
|
// Now that we have an mRawSet, go ahead and notify about whatever stylesheets
|
|
|
|
// we have so far.
|
2017-05-12 22:04:55 +03:00
|
|
|
for (auto& sheetArray : mSheets) {
|
|
|
|
for (auto& sheet : sheetArray) {
|
2017-01-04 22:52:26 +03:00
|
|
|
// There's no guarantee this will create a list on the servo side whose
|
|
|
|
// ordering matches the list that would have been created had all those
|
2017-05-02 02:46:41 +03:00
|
|
|
// sheets been appended/prepended/etc after we had mRawSet. That's okay
|
|
|
|
// because Servo only needs to maintain relative ordering within a sheet
|
|
|
|
// type, which this preserves.
|
|
|
|
|
2017-06-29 04:07:06 +03:00
|
|
|
MOZ_ASSERT(sheet->RawContents(),
|
|
|
|
"We should only append non-null raw sheets.");
|
|
|
|
Servo_StyleSet_AppendStyleSheet(mRawSet.get(), sheet);
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 15:41:32 +03:00
|
|
|
// We added prefilled stylesheets into mRawSet, so the stylist is dirty.
|
|
|
|
// The Stylist should be updated later when necessary.
|
|
|
|
SetStylistStyleSheetsDirty();
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoStyleSet::BeginShutdown()
|
|
|
|
{
|
2017-03-18 09:15:09 +03:00
|
|
|
nsIDocument* doc = mPresContext->Document();
|
|
|
|
|
2017-06-19 08:45:43 +03:00
|
|
|
// Remove the style rule map from document's observer and drop it.
|
|
|
|
if (mStyleRuleMap) {
|
|
|
|
doc->RemoveObserver(mStyleRuleMap);
|
|
|
|
doc->CSSLoader()->RemoveObserver(mStyleRuleMap);
|
|
|
|
mStyleRuleMap = nullptr;
|
|
|
|
}
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoStyleSet::Shutdown()
|
|
|
|
{
|
2017-03-08 08:18:39 +03:00
|
|
|
// Make sure we drop our cached style contexts before the presshell arena
|
|
|
|
// starts going away.
|
|
|
|
ClearNonInheritingStyleContexts();
|
2016-01-27 05:02:04 +03:00
|
|
|
mRawSet = nullptr;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2017-05-24 03:53:08 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::InvalidateStyleForCSSRuleChanges()
|
|
|
|
{
|
2017-05-25 20:50:03 +03:00
|
|
|
MOZ_ASSERT(StylistNeedsUpdate());
|
2017-05-26 18:46:31 +03:00
|
|
|
mPresContext->RestyleManager()->AsServo()->PostRestyleEventForCSSRuleChanges();
|
2017-05-24 03:53:08 +03:00
|
|
|
}
|
|
|
|
|
2017-09-04 12:57:00 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::SetPresContext(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsForXBL(), "Only XBL styleset can set PresContext!");
|
|
|
|
|
|
|
|
mLastPresContextUsesXBLStyleSet = aPresContext;
|
|
|
|
|
|
|
|
const OriginFlags rulesChanged = static_cast<OriginFlags>(
|
|
|
|
Servo_StyleSet_SetDevice(mRawSet.get(), aPresContext));
|
|
|
|
|
|
|
|
if (rulesChanged != OriginFlags(0)) {
|
|
|
|
MarkOriginsDirty(rulesChanged);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-24 04:27:08 +03:00
|
|
|
nsRestyleHint
|
2017-08-02 15:39:32 +03:00
|
|
|
ServoStyleSet::MediumFeaturesChanged(bool aViewportChanged)
|
2017-06-02 18:55:55 +03:00
|
|
|
{
|
2017-08-02 15:39:32 +03:00
|
|
|
bool viewportUnitsUsed = false;
|
2017-09-02 10:25:45 +03:00
|
|
|
bool rulesChanged = MediumFeaturesChangedRules(&viewportUnitsUsed);
|
2017-09-02 10:25:45 +03:00
|
|
|
|
2017-09-02 10:25:45 +03:00
|
|
|
if (mBindingManager &&
|
|
|
|
mBindingManager->MediumFeaturesChanged(mPresContext)) {
|
|
|
|
SetStylistXBLStyleSheetsDirty();
|
|
|
|
rulesChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rulesChanged) {
|
2017-08-02 15:39:32 +03:00
|
|
|
return eRestyle_Subtree;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (viewportUnitsUsed && aViewportChanged) {
|
|
|
|
return eRestyle_ForceDescendants;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsRestyleHint(0);
|
2017-06-02 18:55:55 +03:00
|
|
|
}
|
|
|
|
|
2017-09-02 10:25:45 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::MediumFeaturesChangedRules(bool* aViewportUnitsUsed)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aViewportUnitsUsed);
|
|
|
|
|
|
|
|
const OriginFlags rulesChanged = static_cast<OriginFlags>(
|
|
|
|
Servo_StyleSet_MediumFeaturesChanged(mRawSet.get(), aViewportUnitsUsed));
|
|
|
|
|
|
|
|
if (rulesChanged != OriginFlags(0)) {
|
|
|
|
MarkOriginsDirty(rulesChanged);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-30 11:21:26 +03:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(ServoStyleSetMallocSizeOf)
|
Bug 1387958 - Measure the stylist during memory reporting. r=heycam.
Example output from the Obama Wikipedia page:
> ├──2,315,600 B (01.16%) -- stylist
> │ ├──1,916,928 B (00.96%) ── invalidation-map
> │ ├────228,800 B (00.11%) ── rule-tree
> │ ├────142,336 B (00.07%) ── element-and-pseudos-maps
> │ ├─────14,336 B (00.01%) ── revalidation-selectors
> │ ├──────9,648 B (00.00%) ── other
> │ └──────3,552 B (00.00%) ── precomputed-pseudos
This change requires new code to measure HashMaps, which uses the new
'malloc_enclosing_size_of' functions that can measure a heap block from an
interior pointer.
The patch changes MallocSizeOfFn to a newtype, and introduces
MallocEnclosingSizeOfFn alongside.
It also adds new traits: MallocSizeOfBox, MallocSizeOfVec, MallocSizeOfHash.
These each contain a single method that does shallow measurement of the
relevant type, which is often useful. (This is a different style to the
existing MallocSizeOf trait, which does deep measurement, but I'm moving away
from the always-deep-measurement style because it's less flexible.)
MozReview-Commit-ID: FgJCCmdw0ZF
--HG--
extra : rebase_source : c692c2073aa66020224489b97247c49de95a99a4
2017-09-05 04:38:45 +03:00
|
|
|
MOZ_DEFINE_MALLOC_ENCLOSING_SIZE_OF(ServoStyleSetMallocEnclosingSizeOf)
|
2017-08-30 11:21:26 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
ServoStyleSet::AddSizeOfIncludingThis(nsWindowSizes& aSizes) const
|
2017-04-06 05:22:36 +03:00
|
|
|
{
|
2017-08-30 11:21:26 +03:00
|
|
|
MallocSizeOf mallocSizeOf = aSizes.mState.mMallocSizeOf;
|
|
|
|
|
|
|
|
aSizes.mLayoutServoStyleSetsOther += mallocSizeOf(this);
|
|
|
|
|
|
|
|
if (mRawSet) {
|
|
|
|
aSizes.mLayoutServoStyleSetsOther += mallocSizeOf(mRawSet.get());
|
|
|
|
ServoStyleSetSizes sizes;
|
|
|
|
// Measure mRawSet. We use ServoStyleSetMallocSizeOf rather than
|
|
|
|
// aMallocSizeOf to distinguish in DMD's output the memory measured within
|
|
|
|
// Servo code.
|
Bug 1387958 - Measure the stylist during memory reporting. r=heycam.
Example output from the Obama Wikipedia page:
> ├──2,315,600 B (01.16%) -- stylist
> │ ├──1,916,928 B (00.96%) ── invalidation-map
> │ ├────228,800 B (00.11%) ── rule-tree
> │ ├────142,336 B (00.07%) ── element-and-pseudos-maps
> │ ├─────14,336 B (00.01%) ── revalidation-selectors
> │ ├──────9,648 B (00.00%) ── other
> │ └──────3,552 B (00.00%) ── precomputed-pseudos
This change requires new code to measure HashMaps, which uses the new
'malloc_enclosing_size_of' functions that can measure a heap block from an
interior pointer.
The patch changes MallocSizeOfFn to a newtype, and introduces
MallocEnclosingSizeOfFn alongside.
It also adds new traits: MallocSizeOfBox, MallocSizeOfVec, MallocSizeOfHash.
These each contain a single method that does shallow measurement of the
relevant type, which is often useful. (This is a different style to the
existing MallocSizeOf trait, which does deep measurement, but I'm moving away
from the always-deep-measurement style because it's less flexible.)
MozReview-Commit-ID: FgJCCmdw0ZF
--HG--
extra : rebase_source : c692c2073aa66020224489b97247c49de95a99a4
2017-09-05 04:38:45 +03:00
|
|
|
Servo_StyleSet_AddSizeOfExcludingThis(ServoStyleSetMallocSizeOf,
|
|
|
|
ServoStyleSetMallocEnclosingSizeOf,
|
|
|
|
&sizes, mRawSet.get());
|
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
|
|
|
|
|
|
|
// The StyleSet does not contain precomputed pseudos; they are in the UA
|
|
|
|
// cache.
|
|
|
|
MOZ_RELEASE_ASSERT(sizes.mPrecomputedPseudos == 0);
|
|
|
|
|
|
|
|
aSizes.mLayoutServoStyleSetsStylistRuleTree += sizes.mRuleTree;
|
Bug 1387958 - Measure the stylist during memory reporting. r=heycam.
Example output from the Obama Wikipedia page:
> ├──2,315,600 B (01.16%) -- stylist
> │ ├──1,916,928 B (00.96%) ── invalidation-map
> │ ├────228,800 B (00.11%) ── rule-tree
> │ ├────142,336 B (00.07%) ── element-and-pseudos-maps
> │ ├─────14,336 B (00.01%) ── revalidation-selectors
> │ ├──────9,648 B (00.00%) ── other
> │ └──────3,552 B (00.00%) ── precomputed-pseudos
This change requires new code to measure HashMaps, which uses the new
'malloc_enclosing_size_of' functions that can measure a heap block from an
interior pointer.
The patch changes MallocSizeOfFn to a newtype, and introduces
MallocEnclosingSizeOfFn alongside.
It also adds new traits: MallocSizeOfBox, MallocSizeOfVec, MallocSizeOfHash.
These each contain a single method that does shallow measurement of the
relevant type, which is often useful. (This is a different style to the
existing MallocSizeOf trait, which does deep measurement, but I'm moving away
from the always-deep-measurement style because it's less flexible.)
MozReview-Commit-ID: FgJCCmdw0ZF
--HG--
extra : rebase_source : c692c2073aa66020224489b97247c49de95a99a4
2017-09-05 04:38:45 +03:00
|
|
|
aSizes.mLayoutServoStyleSetsStylistElementAndPseudosMaps +=
|
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
|
|
|
sizes.mElementAndPseudosMaps;
|
Bug 1387958 - Measure the stylist during memory reporting. r=heycam.
Example output from the Obama Wikipedia page:
> ├──2,315,600 B (01.16%) -- stylist
> │ ├──1,916,928 B (00.96%) ── invalidation-map
> │ ├────228,800 B (00.11%) ── rule-tree
> │ ├────142,336 B (00.07%) ── element-and-pseudos-maps
> │ ├─────14,336 B (00.01%) ── revalidation-selectors
> │ ├──────9,648 B (00.00%) ── other
> │ └──────3,552 B (00.00%) ── precomputed-pseudos
This change requires new code to measure HashMaps, which uses the new
'malloc_enclosing_size_of' functions that can measure a heap block from an
interior pointer.
The patch changes MallocSizeOfFn to a newtype, and introduces
MallocEnclosingSizeOfFn alongside.
It also adds new traits: MallocSizeOfBox, MallocSizeOfVec, MallocSizeOfHash.
These each contain a single method that does shallow measurement of the
relevant type, which is often useful. (This is a different style to the
existing MallocSizeOf trait, which does deep measurement, but I'm moving away
from the always-deep-measurement style because it's less flexible.)
MozReview-Commit-ID: FgJCCmdw0ZF
--HG--
extra : rebase_source : c692c2073aa66020224489b97247c49de95a99a4
2017-09-05 04:38:45 +03:00
|
|
|
aSizes.mLayoutServoStyleSetsStylistInvalidationMap +=
|
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
|
|
|
sizes.mInvalidationMap;
|
Bug 1387958 - Measure the stylist during memory reporting. r=heycam.
Example output from the Obama Wikipedia page:
> ├──2,315,600 B (01.16%) -- stylist
> │ ├──1,916,928 B (00.96%) ── invalidation-map
> │ ├────228,800 B (00.11%) ── rule-tree
> │ ├────142,336 B (00.07%) ── element-and-pseudos-maps
> │ ├─────14,336 B (00.01%) ── revalidation-selectors
> │ ├──────9,648 B (00.00%) ── other
> │ └──────3,552 B (00.00%) ── precomputed-pseudos
This change requires new code to measure HashMaps, which uses the new
'malloc_enclosing_size_of' functions that can measure a heap block from an
interior pointer.
The patch changes MallocSizeOfFn to a newtype, and introduces
MallocEnclosingSizeOfFn alongside.
It also adds new traits: MallocSizeOfBox, MallocSizeOfVec, MallocSizeOfHash.
These each contain a single method that does shallow measurement of the
relevant type, which is often useful. (This is a different style to the
existing MallocSizeOf trait, which does deep measurement, but I'm moving away
from the always-deep-measurement style because it's less flexible.)
MozReview-Commit-ID: FgJCCmdw0ZF
--HG--
extra : rebase_source : c692c2073aa66020224489b97247c49de95a99a4
2017-09-05 04:38:45 +03:00
|
|
|
aSizes.mLayoutServoStyleSetsStylistRevalidationSelectors +=
|
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
|
|
|
sizes.mRevalidationSelectors;
|
|
|
|
aSizes.mLayoutServoStyleSetsStylistOther += sizes.mOther;
|
2017-08-30 11:21:26 +03:00
|
|
|
}
|
2017-04-06 05:22:36 +03:00
|
|
|
|
2017-06-19 08:45:43 +03:00
|
|
|
if (mStyleRuleMap) {
|
2017-08-30 11:21:26 +03:00
|
|
|
aSizes.mLayoutServoStyleSetsOther +=
|
|
|
|
mStyleRuleMap->SizeOfIncludingThis(aSizes.mState.mMallocSizeOf);
|
2017-06-19 08:45:43 +03:00
|
|
|
}
|
|
|
|
|
2017-04-06 05:22:36 +03:00
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mSheets
|
|
|
|
// - mNonInheritingStyleContexts
|
|
|
|
//
|
|
|
|
// The following members are not measured:
|
|
|
|
// - mPresContext, because it a non-owning pointer
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::GetAuthorStyleDisabled() const
|
|
|
|
{
|
2017-04-11 10:43:14 +03:00
|
|
|
return mAuthorStyleDisabled;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::SetAuthorStyleDisabled(bool aStyleDisabled)
|
|
|
|
{
|
2017-04-11 10:43:14 +03:00
|
|
|
if (mAuthorStyleDisabled == aStyleDisabled) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mAuthorStyleDisabled = aStyleDisabled;
|
2017-08-12 13:49:01 +03:00
|
|
|
MarkOriginsDirty(OriginFlags::Author);
|
2017-04-11 10:43:14 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoStyleSet::BeginUpdate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::EndUpdate()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2016-02-24 10:01:10 +03:00
|
|
|
ServoStyleSet::ResolveStyleFor(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
|
|
|
{
|
2016-12-28 10:49:12 +03:00
|
|
|
if (aMayCompute == LazyComputeBehavior::Allow) {
|
2017-04-12 05:05:26 +03:00
|
|
|
PreTraverseSync();
|
2017-08-04 12:26:03 +03:00
|
|
|
return ResolveStyleLazilyInternal(
|
2017-10-11 04:00:28 +03:00
|
|
|
aElement, CSSPseudoElementType::NotPseudo);
|
2016-12-28 10:49:12 +03:00
|
|
|
}
|
|
|
|
|
2017-08-11 22:55:32 +03:00
|
|
|
return ResolveServoStyle(aElement);
|
2016-04-29 03:56:37 +03:00
|
|
|
}
|
2016-03-18 23:14:07 +03:00
|
|
|
|
2017-11-16 02:39:29 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
|
|
|
ServoStyleSet::ReresolveStyleForBindings(Element* aElement)
|
|
|
|
{
|
|
|
|
// XXX: We should have a better way to restyle ourselves.
|
|
|
|
ServoRestyleManager::ClearServoDataFromSubtree(aElement);
|
|
|
|
StyleNewSubtree(aElement);
|
|
|
|
|
|
|
|
// Servo's should_traverse_children() in traversal.rs skips
|
|
|
|
// styling descendants of elements with a -moz-binding the
|
|
|
|
// first time. Thus call StyleNewChildren() again.
|
|
|
|
StyleNewChildren(aElement);
|
|
|
|
|
|
|
|
return ResolveServoStyle(aElement);
|
|
|
|
}
|
|
|
|
|
2017-08-04 12:26:04 +03:00
|
|
|
/**
|
|
|
|
* Clears any stale Servo element data that might existing in the specified
|
|
|
|
* element's document. Upon destruction, asserts that the element and all
|
|
|
|
* its ancestors still have no element data, if the document has no pres shell.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS AutoClearStaleData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoClearStaleData(Element* aElement)
|
|
|
|
#ifdef DEBUG
|
|
|
|
: mElement(aElement)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
aElement->OwnerDoc()->ClearStaleServoDataFromDocument();
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoClearStaleData()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Assert that the element and its ancestors are all unstyled, if the
|
|
|
|
// document has no pres shell.
|
|
|
|
if (mElement->OwnerDoc()->HasShellOrBFCacheEntry()) {
|
|
|
|
// We must check whether we're in the bfcache because its presence
|
|
|
|
// means we have a "hidden" pres shell with up-to-date data in the
|
|
|
|
// tree.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (Element* e = mElement; e; e = e->GetParentElement()) {
|
|
|
|
MOZ_ASSERT(!e->HasServoData(), "expected element to be unstyled");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
#ifdef DEBUG
|
|
|
|
Element* mElement;
|
|
|
|
#endif
|
|
|
|
};
|
2016-02-24 10:01:10 +03:00
|
|
|
|
2017-05-07 17:36:47 +03:00
|
|
|
const ServoElementSnapshotTable&
|
|
|
|
ServoStyleSet::Snapshots()
|
|
|
|
{
|
|
|
|
return mPresContext->RestyleManager()->AsServo()->Snapshots();
|
|
|
|
}
|
|
|
|
|
2017-01-20 02:56:53 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::ResolveMappedAttrDeclarationBlocks()
|
|
|
|
{
|
|
|
|
if (nsHTMLStyleSheet* sheet = mPresContext->Document()->GetAttributeStyleSheet()) {
|
2017-04-08 17:42:43 +03:00
|
|
|
sheet->CalculateMappedServoDeclarations(mPresContext);
|
2017-01-20 02:56:53 +03:00
|
|
|
}
|
2017-02-23 04:19:04 +03:00
|
|
|
|
|
|
|
mPresContext->Document()->ResolveScheduledSVGPresAttrs();
|
2017-01-20 02:56:53 +03:00
|
|
|
}
|
|
|
|
|
2017-03-08 23:20:17 +03:00
|
|
|
void
|
2017-03-17 00:10:22 +03:00
|
|
|
ServoStyleSet::PreTraverseSync()
|
2017-03-08 23:20:17 +03:00
|
|
|
{
|
2017-07-28 08:18:13 +03:00
|
|
|
// Get the Document's root element to ensure that the cache is valid before
|
|
|
|
// calling into the (potentially-parallel) Servo traversal, where a cache hit
|
|
|
|
// is necessary to avoid a data race when updating the cache.
|
|
|
|
mozilla::Unused << mPresContext->Document()->GetRootElement();
|
|
|
|
|
2017-01-20 02:56:53 +03:00
|
|
|
ResolveMappedAttrDeclarationBlocks();
|
2017-02-02 22:48:28 +03:00
|
|
|
|
2017-04-14 04:28:25 +03:00
|
|
|
nsCSSRuleProcessor::InitSystemMetrics();
|
|
|
|
|
2017-08-03 23:16:31 +03:00
|
|
|
LookAndFeel::NativeInit();
|
|
|
|
|
2017-03-17 00:10:22 +03:00
|
|
|
// This is lazily computed and pseudo matching needs to access
|
|
|
|
// it so force computation early.
|
|
|
|
mPresContext->Document()->GetDocumentState();
|
2017-04-08 01:49:44 +03:00
|
|
|
|
2017-05-26 17:29:10 +03:00
|
|
|
if (gfxUserFontSet* userFontSet = mPresContext->Document()->GetUserFontSet()) {
|
2017-07-07 08:35:28 +03:00
|
|
|
// Ensure that the @font-face data is not stale
|
2017-05-26 17:29:10 +03:00
|
|
|
uint64_t generation = userFontSet->GetGeneration();
|
|
|
|
if (generation != mUserFontSetUpdateGeneration) {
|
|
|
|
mPresContext->DeviceContext()->UpdateFontCacheUserFonts(userFontSet);
|
|
|
|
mUserFontSetUpdateGeneration = generation;
|
|
|
|
}
|
2017-07-07 08:35:28 +03:00
|
|
|
|
2017-07-08 13:00:24 +03:00
|
|
|
// Ensure that the FontFaceSet's cached document principal is up to date.
|
|
|
|
FontFaceSet* fontFaceSet =
|
|
|
|
static_cast<FontFaceSet::UserFontSet*>(userFontSet)->GetFontFaceSet();
|
|
|
|
fontFaceSet->UpdateStandardFontLoadPrincipal();
|
|
|
|
bool principalChanged = fontFaceSet->HasStandardFontLoadPrincipalChanged();
|
|
|
|
|
2017-07-07 08:35:28 +03:00
|
|
|
// Ensure that the user font cache holds up-to-date data on whether
|
|
|
|
// our font set is allowed to re-use fonts from the cache.
|
|
|
|
uint32_t cacheGeneration = gfxUserFontSet::UserFontCache::Generation();
|
2017-07-08 13:00:24 +03:00
|
|
|
if (principalChanged) {
|
|
|
|
gfxUserFontSet::UserFontCache::ClearAllowedFontSets(userFontSet);
|
|
|
|
}
|
|
|
|
if (cacheGeneration != mUserFontCacheUpdateGeneration || principalChanged) {
|
2017-07-07 08:35:28 +03:00
|
|
|
gfxUserFontSet::UserFontCache::UpdateAllowedFontSets(userFontSet);
|
|
|
|
mUserFontCacheUpdateGeneration = cacheGeneration;
|
|
|
|
}
|
2017-05-26 17:29:10 +03:00
|
|
|
}
|
2017-05-15 19:02:59 +03:00
|
|
|
|
|
|
|
UpdateStylistIfNeeded();
|
2017-05-20 22:47:36 +03:00
|
|
|
mPresContext->CacheAllLangs();
|
2017-03-17 00:10:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-08-11 22:54:35 +03:00
|
|
|
ServoStyleSet::PreTraverse(ServoTraversalFlags aFlags, Element* aRoot)
|
2017-03-17 00:10:22 +03:00
|
|
|
{
|
|
|
|
PreTraverseSync();
|
|
|
|
|
2017-03-08 23:20:17 +03:00
|
|
|
// Process animation stuff that we should avoid doing during the parallel
|
|
|
|
// traversal.
|
2017-04-26 07:00:11 +03:00
|
|
|
nsSMILAnimationController* smilController =
|
2017-08-31 09:00:39 +03:00
|
|
|
mPresContext->Document()->HasAnimationController()
|
|
|
|
? mPresContext->Document()->GetAnimationController()
|
|
|
|
: nullptr;
|
|
|
|
|
2017-04-04 14:34:30 +03:00
|
|
|
if (aRoot) {
|
2017-05-19 11:16:41 +03:00
|
|
|
mPresContext->EffectCompositor()
|
2017-08-11 22:54:35 +03:00
|
|
|
->PreTraverseInSubtree(aFlags, aRoot);
|
2017-04-26 07:00:11 +03:00
|
|
|
if (smilController) {
|
|
|
|
smilController->PreTraverseInSubtree(aRoot);
|
|
|
|
}
|
2017-04-04 14:34:30 +03:00
|
|
|
} else {
|
2017-08-11 22:54:35 +03:00
|
|
|
mPresContext->EffectCompositor()->PreTraverse(aFlags);
|
2017-04-26 07:00:11 +03:00
|
|
|
if (smilController) {
|
|
|
|
smilController->PreTraverse();
|
|
|
|
}
|
2017-04-04 14:34:30 +03:00
|
|
|
}
|
2017-03-08 23:20:17 +03:00
|
|
|
}
|
|
|
|
|
2017-08-05 00:34:18 +03:00
|
|
|
static inline already_AddRefed<ServoStyleContext>
|
|
|
|
ResolveStyleForTextOrFirstLetterContinuation(
|
|
|
|
RawServoStyleSetBorrowed aStyleSet,
|
|
|
|
ServoStyleContext& aParent,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAnonBox)
|
2017-08-05 00:34:18 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aAnonBox == nsCSSAnonBoxes::mozText ||
|
|
|
|
aAnonBox == nsCSSAnonBoxes::firstLetterContinuation);
|
|
|
|
auto inheritTarget = aAnonBox == nsCSSAnonBoxes::mozText
|
|
|
|
? InheritTarget::Text
|
|
|
|
: InheritTarget::FirstLetterContinuation;
|
|
|
|
|
|
|
|
RefPtr<ServoStyleContext> style =
|
|
|
|
aParent.GetCachedInheritingAnonBoxStyle(aAnonBox);
|
|
|
|
if (!style) {
|
|
|
|
style = Servo_ComputedValues_Inherit(aStyleSet,
|
|
|
|
aAnonBox,
|
|
|
|
&aParent,
|
|
|
|
inheritTarget).Consume();
|
|
|
|
MOZ_ASSERT(style);
|
2017-08-06 19:42:55 +03:00
|
|
|
aParent.SetCachedInheritedAnonBoxStyle(aAnonBox, style);
|
2017-08-05 00:34:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return style.forget();
|
|
|
|
}
|
|
|
|
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2016-04-29 07:01:44 +03:00
|
|
|
ServoStyleSet::ResolveStyleForText(nsIContent* aTextNode,
|
2017-07-17 21:42:04 +03:00
|
|
|
ServoStyleContext* aParentContext)
|
2016-04-29 07:01:44 +03:00
|
|
|
{
|
2016-04-29 07:04:16 +03:00
|
|
|
MOZ_ASSERT(aTextNode && aTextNode->IsNodeOfType(nsINode::eTEXT));
|
2016-08-12 21:30:29 +03:00
|
|
|
MOZ_ASSERT(aTextNode->GetParent());
|
2016-10-26 02:27:08 +03:00
|
|
|
MOZ_ASSERT(aParentContext);
|
|
|
|
|
2017-08-05 00:34:18 +03:00
|
|
|
return ResolveStyleForTextOrFirstLetterContinuation(
|
|
|
|
mRawSet.get(), *aParentContext, nsCSSAnonBoxes::mozText);
|
2016-04-29 07:01:44 +03:00
|
|
|
}
|
|
|
|
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2017-07-17 21:42:04 +03:00
|
|
|
ServoStyleSet::ResolveStyleForFirstLetterContinuation(ServoStyleContext* aParentContext)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2017-08-05 00:34:18 +03:00
|
|
|
MOZ_ASSERT(aParentContext);
|
|
|
|
|
|
|
|
return ResolveStyleForTextOrFirstLetterContinuation(
|
|
|
|
mRawSet.get(), *aParentContext, nsCSSAnonBoxes::firstLetterContinuation);
|
2017-03-08 08:18:32 +03:00
|
|
|
}
|
|
|
|
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2017-03-08 08:18:40 +03:00
|
|
|
ServoStyleSet::ResolveStyleForPlaceholder()
|
2017-03-08 08:18:32 +03:00
|
|
|
{
|
2017-07-20 19:36:20 +03:00
|
|
|
RefPtr<ServoStyleContext>& cache =
|
2017-03-09 07:39:45 +03:00
|
|
|
mNonInheritingStyleContexts[nsCSSAnonBoxes::NonInheriting::oofPlaceholder];
|
2017-03-08 08:18:40 +03:00
|
|
|
if (cache) {
|
2017-07-20 19:36:20 +03:00
|
|
|
RefPtr<ServoStyleContext> retval = cache;
|
2017-03-08 08:18:40 +03:00
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
2017-07-17 21:42:00 +03:00
|
|
|
RefPtr<ServoStyleContext> computedValues =
|
2017-04-28 14:10:00 +03:00
|
|
|
Servo_ComputedValues_Inherit(mRawSet.get(),
|
2017-07-17 21:42:00 +03:00
|
|
|
nsCSSAnonBoxes::oofPlaceholder,
|
2017-04-28 14:10:00 +03:00
|
|
|
nullptr,
|
|
|
|
InheritTarget::PlaceholderFrame)
|
|
|
|
.Consume();
|
2016-05-06 01:32:00 +03:00
|
|
|
MOZ_ASSERT(computedValues);
|
|
|
|
|
2017-07-17 21:42:24 +03:00
|
|
|
cache = computedValues;
|
|
|
|
return computedValues.forget();
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2017-09-20 07:43:31 +03:00
|
|
|
static inline bool
|
|
|
|
LazyPseudoIsCacheable(CSSPseudoElementType aType,
|
|
|
|
Element* aOriginatingElement,
|
|
|
|
ServoStyleContext* aParentContext)
|
|
|
|
{
|
|
|
|
return aParentContext &&
|
|
|
|
!nsCSSPseudoElements::IsEagerlyCascadedInServo(aType) &&
|
2017-09-23 02:09:18 +03:00
|
|
|
aOriginatingElement->HasServoData() &&
|
2017-09-20 07:43:31 +03:00
|
|
|
!Servo_Element_IsPrimaryStyleReusedViaRuleNode(aOriginatingElement);
|
|
|
|
}
|
|
|
|
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2016-12-22 04:58:38 +03:00
|
|
|
ServoStyleSet::ResolvePseudoElementStyle(Element* aOriginatingElement,
|
2016-02-24 10:01:10 +03:00
|
|
|
CSSPseudoElementType aType,
|
2017-07-17 21:42:04 +03:00
|
|
|
ServoStyleContext* aParentContext,
|
2016-02-24 10:01:10 +03:00
|
|
|
Element* aPseudoElement)
|
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-05-10 20:13:39 +03:00
|
|
|
|
2016-04-29 03:56:37 +03:00
|
|
|
MOZ_ASSERT(aType < CSSPseudoElementType::Count);
|
|
|
|
|
2017-07-17 21:42:00 +03:00
|
|
|
RefPtr<ServoStyleContext> computedValues;
|
|
|
|
|
2017-05-13 20:29:14 +03:00
|
|
|
if (aPseudoElement) {
|
|
|
|
MOZ_ASSERT(aType == aPseudoElement->GetPseudoElementType());
|
2017-07-18 14:56:15 +03:00
|
|
|
computedValues =
|
2017-08-11 22:55:32 +03:00
|
|
|
Servo_ResolveStyle(aPseudoElement, mRawSet.get()).Consume();
|
2017-05-13 20:29:14 +03:00
|
|
|
} else {
|
2017-08-06 19:42:55 +03:00
|
|
|
bool cacheable =
|
2017-09-20 07:43:31 +03:00
|
|
|
LazyPseudoIsCacheable(aType, aOriginatingElement, aParentContext);
|
2017-05-13 20:29:14 +03:00
|
|
|
computedValues =
|
2017-08-06 19:42:55 +03:00
|
|
|
cacheable ? aParentContext->GetCachedLazyPseudoStyle(aType) : nullptr;
|
|
|
|
|
|
|
|
if (!computedValues) {
|
|
|
|
computedValues = Servo_ResolvePseudoStyle(aOriginatingElement,
|
|
|
|
aType,
|
|
|
|
/* is_probe = */ false,
|
|
|
|
aParentContext,
|
|
|
|
mRawSet.get()).Consume();
|
|
|
|
if (cacheable) {
|
|
|
|
aParentContext->SetCachedLazyPseudoStyle(computedValues);
|
|
|
|
}
|
|
|
|
}
|
2017-05-13 20:29:14 +03:00
|
|
|
}
|
|
|
|
|
2016-04-29 03:56:37 +03:00
|
|
|
MOZ_ASSERT(computedValues);
|
2017-07-17 21:42:24 +03:00
|
|
|
return computedValues.forget();
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2017-08-04 12:26:03 +03:00
|
|
|
ServoStyleSet::ResolveStyleLazily(Element* aElement,
|
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
StyleRuleInclusion aRuleInclusion)
|
2017-04-15 01:37:34 +03:00
|
|
|
{
|
2017-08-04 12:26:04 +03:00
|
|
|
// Lazy style computation avoids storing any new data in the tree.
|
|
|
|
// If the tree has stale data in it, then the AutoClearStaleData below
|
|
|
|
// will ensure it's cleared so we don't use it. But if the document is
|
|
|
|
// in the bfcache, then we will have valid, usable data in the tree,
|
|
|
|
// but we don't want to use it. Instead we want to pretend as if the
|
|
|
|
// document has no pres shell and no styles.
|
|
|
|
//
|
|
|
|
// If we don't do this, then we can very easily mix styles from different
|
|
|
|
// style sets in the tree. For example, calling getComputedStyle on an
|
|
|
|
// element in a display:none iframe (which has no pres shell) will use the
|
|
|
|
// caller's style set for any styling. If we allowed this to re-use any
|
|
|
|
// existing styles in the DOM, then we would do selector matching on the
|
|
|
|
// undisplayed element with the caller's style set's rules, but inherit from
|
|
|
|
// values that were computed with the style set from the target element's
|
|
|
|
// hidden-by-the-bfcache-entry pres shell.
|
|
|
|
bool ignoreExistingStyles = aElement->OwnerDoc()->GetBFCacheEntry();
|
|
|
|
|
|
|
|
AutoClearStaleData guard(aElement);
|
2017-04-15 01:37:34 +03:00
|
|
|
PreTraverseSync();
|
2017-10-11 04:00:28 +03:00
|
|
|
return ResolveStyleLazilyInternal(aElement, aPseudoType,
|
2017-10-06 07:51:02 +03:00
|
|
|
aRuleInclusion,
|
2017-08-04 12:26:04 +03:00
|
|
|
ignoreExistingStyles);
|
2016-12-28 10:49:12 +03:00
|
|
|
}
|
|
|
|
|
2017-06-28 04:34:06 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2017-10-03 01:05:19 +03:00
|
|
|
ServoStyleSet::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
|
|
|
MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(aPseudoTag) &&
|
|
|
|
!nsCSSAnonBoxes::IsNonInheritingAnonBox(aPseudoTag));
|
2017-09-06 22:56:53 +03:00
|
|
|
MOZ_ASSERT_IF(aParentContext, !StylistNeedsUpdate());
|
|
|
|
|
|
|
|
UpdateStylistIfNeeded();
|
|
|
|
|
2017-08-05 00:34:18 +03:00
|
|
|
RefPtr<ServoStyleContext> style = nullptr;
|
|
|
|
|
|
|
|
if (aParentContext) {
|
|
|
|
style = aParentContext->GetCachedInheritingAnonBoxStyle(aPseudoTag);
|
2016-07-28 06:03:49 +03:00
|
|
|
}
|
2016-03-18 23:14:07 +03:00
|
|
|
|
2017-08-05 00:34:18 +03:00
|
|
|
if (!style) {
|
|
|
|
style =
|
|
|
|
Servo_ComputedValues_GetForAnonymousBox(aParentContext,
|
|
|
|
aPseudoTag,
|
|
|
|
mRawSet.get()).Consume();
|
|
|
|
MOZ_ASSERT(style);
|
|
|
|
if (aParentContext) {
|
2017-08-06 19:42:55 +03:00
|
|
|
aParentContext->SetCachedInheritedAnonBoxStyle(aPseudoTag, style);
|
2017-08-05 00:34:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return style.forget();
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2017-10-03 01:05:19 +03:00
|
|
|
ServoStyleSet::ResolveNonInheritingAnonymousBoxStyle(nsAtom* aPseudoTag)
|
2017-03-09 07:41:04 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(aPseudoTag) &&
|
|
|
|
nsCSSAnonBoxes::IsNonInheritingAnonBox(aPseudoTag));
|
|
|
|
MOZ_ASSERT(aPseudoTag != nsCSSAnonBoxes::pageContent,
|
|
|
|
"If nsCSSAnonBoxes::pageContent ends up non-inheriting, check "
|
|
|
|
"whether we need to do anything to move the "
|
2017-03-09 07:50:28 +03:00
|
|
|
"@page handling from ResolveInheritingAnonymousBoxStyle to "
|
2017-03-09 07:41:04 +03:00
|
|
|
"ResolveNonInheritingAnonymousBoxStyle");
|
|
|
|
|
|
|
|
nsCSSAnonBoxes::NonInheriting type =
|
|
|
|
nsCSSAnonBoxes::NonInheritingTypeForPseudoTag(aPseudoTag);
|
2017-07-20 19:36:20 +03:00
|
|
|
RefPtr<ServoStyleContext>& cache = mNonInheritingStyleContexts[type];
|
2017-03-09 07:41:04 +03:00
|
|
|
if (cache) {
|
2017-07-20 19:36:20 +03:00
|
|
|
RefPtr<ServoStyleContext> retval = cache;
|
2017-03-09 07:41:04 +03:00
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
2017-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-05-10 20:13:39 +03:00
|
|
|
|
2017-03-13 19:53:45 +03:00
|
|
|
// We always want to skip parent-based display fixup here. It never makes
|
2017-04-24 11:25:37 +03:00
|
|
|
// sense for non-inheriting anonymous boxes. (Static assertions in
|
|
|
|
// nsCSSAnonBoxes.cpp ensure that all non-inheriting non-anonymous boxes
|
|
|
|
// are indeed annotated as skipping this fixup.)
|
2017-03-13 19:53:45 +03:00
|
|
|
MOZ_ASSERT(!nsCSSAnonBoxes::IsNonInheritingAnonBox(nsCSSAnonBoxes::viewport),
|
|
|
|
"viewport needs fixup to handle blockifying it");
|
2017-07-17 21:42:00 +03:00
|
|
|
RefPtr<ServoStyleContext> computedValues =
|
2017-07-18 15:29:12 +03:00
|
|
|
Servo_ComputedValues_GetForAnonymousBox(nullptr,
|
2017-07-17 21:42:00 +03:00
|
|
|
aPseudoTag,
|
2017-03-09 07:41:04 +03:00
|
|
|
mRawSet.get()).Consume();
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (!computedValues) {
|
|
|
|
nsString pseudo;
|
|
|
|
aPseudoTag->ToString(pseudo);
|
|
|
|
NS_ERROR(nsPrintfCString("stylo: could not get anon-box: %s",
|
|
|
|
NS_ConvertUTF16toUTF8(pseudo).get()).get());
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-07-17 21:42:24 +03:00
|
|
|
cache = computedValues;
|
|
|
|
return computedValues.forget();
|
2017-03-09 07:41:04 +03:00
|
|
|
}
|
|
|
|
|
2017-10-20 13:31:13 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
already_AddRefed<ServoStyleContext>
|
|
|
|
ServoStyleSet::ResolveXULTreePseudoStyle(dom::Element* aParentElement,
|
|
|
|
nsICSSAnonBoxPseudo* aPseudoTag,
|
|
|
|
ServoStyleContext* aParentContext,
|
|
|
|
const AtomArray& aInputWord)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(nsCSSAnonBoxes::IsTreePseudoElement(aPseudoTag));
|
|
|
|
MOZ_ASSERT(aParentContext);
|
|
|
|
MOZ_ASSERT(!StylistNeedsUpdate());
|
|
|
|
|
|
|
|
return Servo_ComputedValues_ResolveXULTreePseudoStyle(
|
|
|
|
aParentElement,
|
|
|
|
aPseudoTag,
|
|
|
|
aParentContext,
|
|
|
|
&aInputWord,
|
|
|
|
mRawSet.get()
|
|
|
|
).Consume();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
// manage the set of style sheets in the style set
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::AppendStyleSheet(SheetType aType,
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSheet* aSheet)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-02-26 04:51:02 +03:00
|
|
|
MOZ_ASSERT(aSheet);
|
|
|
|
MOZ_ASSERT(aSheet->IsApplicable());
|
2017-11-16 04:37:17 +03:00
|
|
|
MOZ_ASSERT(IsCSSSheetType(aType));
|
2017-06-29 04:07:06 +03:00
|
|
|
MOZ_ASSERT(aSheet->RawContents(), "Raw sheet should be in place before insertion.");
|
2017-05-02 02:46:41 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
RemoveSheetOfType(aType, aSheet);
|
|
|
|
AppendSheetOfType(aType, aSheet);
|
2016-02-26 04:51:02 +03:00
|
|
|
|
2017-01-04 22:52:26 +03:00
|
|
|
if (mRawSet) {
|
|
|
|
// Maintain a mirrored list of sheets on the servo side.
|
2017-05-12 22:04:55 +03:00
|
|
|
// Servo will remove aSheet from its original position as part of the call
|
|
|
|
// to Servo_StyleSet_AppendStyleSheet.
|
2017-06-29 04:07:06 +03:00
|
|
|
Servo_StyleSet_AppendStyleSheet(mRawSet.get(), aSheet);
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-02-26 05:57:42 +03:00
|
|
|
|
2016-02-26 04:51:02 +03:00
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::PrependStyleSheet(SheetType aType,
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSheet* aSheet)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-02-26 04:51:02 +03:00
|
|
|
MOZ_ASSERT(aSheet);
|
|
|
|
MOZ_ASSERT(aSheet->IsApplicable());
|
2017-11-16 04:37:17 +03:00
|
|
|
MOZ_ASSERT(IsCSSSheetType(aType));
|
2017-06-29 04:07:06 +03:00
|
|
|
MOZ_ASSERT(aSheet->RawContents(),
|
|
|
|
"Raw sheet should be in place before insertion.");
|
2017-05-02 02:46:41 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
RemoveSheetOfType(aType, aSheet);
|
|
|
|
PrependSheetOfType(aType, aSheet);
|
2016-02-26 04:51:02 +03:00
|
|
|
|
2017-01-04 22:52:26 +03:00
|
|
|
if (mRawSet) {
|
|
|
|
// Maintain a mirrored list of sheets on the servo side.
|
2017-05-12 22:04:55 +03:00
|
|
|
// Servo will remove aSheet from its original position as part of the call
|
|
|
|
// to Servo_StyleSet_PrependStyleSheet.
|
2017-06-29 04:07:06 +03:00
|
|
|
Servo_StyleSet_PrependStyleSheet(mRawSet.get(), aSheet);
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-02-26 05:57:42 +03:00
|
|
|
|
2016-02-26 04:51:02 +03:00
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::RemoveStyleSheet(SheetType aType,
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSheet* aSheet)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-02-26 05:57:42 +03:00
|
|
|
MOZ_ASSERT(aSheet);
|
2017-11-16 04:37:17 +03:00
|
|
|
MOZ_ASSERT(IsCSSSheetType(aType));
|
2016-02-26 05:57:42 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
RemoveSheetOfType(aType, aSheet);
|
|
|
|
if (mRawSet) {
|
2017-01-04 22:52:26 +03:00
|
|
|
// Maintain a mirrored list of sheets on the servo side.
|
2017-06-29 04:07:06 +03:00
|
|
|
Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), aSheet);
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-02-26 05:57:42 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::ReplaceSheets(SheetType aType,
|
2016-02-24 10:01:12 +03:00
|
|
|
const nsTArray<RefPtr<ServoStyleSheet>>& aNewSheets)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-08-03 07:08:01 +03:00
|
|
|
// Gecko uses a two-dimensional array keyed by sheet type, whereas Servo
|
|
|
|
// stores a flattened list. This makes ReplaceSheets a pretty clunky thing
|
|
|
|
// to express. If the need ever arises, we can easily make this more efficent,
|
|
|
|
// probably by aligning the representations better between engines.
|
|
|
|
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-05-10 20:13:39 +03:00
|
|
|
|
2017-05-02 02:46:41 +03:00
|
|
|
// Remove all the existing sheets first.
|
2017-05-24 03:02:51 +03:00
|
|
|
for (const auto& sheet : mSheets[aType]) {
|
|
|
|
sheet->DropStyleSet(this);
|
|
|
|
if (mRawSet) {
|
2017-06-29 04:07:06 +03:00
|
|
|
Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), sheet);
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-08-03 07:08:01 +03:00
|
|
|
}
|
2017-05-12 22:04:55 +03:00
|
|
|
mSheets[aType].Clear();
|
2016-08-03 07:08:01 +03:00
|
|
|
|
2017-05-02 02:46:41 +03:00
|
|
|
// Add in all the new sheets.
|
|
|
|
for (auto& sheet : aNewSheets) {
|
2017-05-12 22:04:55 +03:00
|
|
|
AppendSheetOfType(aType, sheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
if (mRawSet) {
|
2017-06-29 04:07:06 +03:00
|
|
|
MOZ_ASSERT(sheet->RawContents(), "Raw sheet should be in place before replacement.");
|
|
|
|
Servo_StyleSet_AppendStyleSheet(mRawSet.get(), sheet);
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-12-22 02:33:24 +03:00
|
|
|
}
|
|
|
|
|
2016-08-03 07:08:01 +03:00
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::InsertStyleSheetBefore(SheetType aType,
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSheet* aNewSheet,
|
|
|
|
ServoStyleSheet* aReferenceSheet)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-04-29 07:01:44 +03:00
|
|
|
MOZ_ASSERT(aNewSheet);
|
|
|
|
MOZ_ASSERT(aReferenceSheet);
|
|
|
|
MOZ_ASSERT(aNewSheet->IsApplicable());
|
2017-04-18 21:29:13 +03:00
|
|
|
MOZ_ASSERT(aNewSheet != aReferenceSheet, "Can't place sheet before itself.");
|
2017-06-29 04:07:06 +03:00
|
|
|
MOZ_ASSERT(aNewSheet->RawContents(), "Raw sheet should be in place before insertion.");
|
|
|
|
MOZ_ASSERT(aReferenceSheet->RawContents(), "Reference sheet should have a raw sheet.");
|
2016-04-29 07:01:44 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
// Servo will remove aNewSheet from its original position as part of the
|
|
|
|
// call to Servo_StyleSet_InsertStyleSheetBefore.
|
|
|
|
RemoveSheetOfType(aType, aNewSheet);
|
|
|
|
InsertSheetOfType(aType, aNewSheet, aReferenceSheet);
|
2016-04-29 07:01:44 +03:00
|
|
|
|
2017-01-04 22:52:26 +03:00
|
|
|
if (mRawSet) {
|
|
|
|
// Maintain a mirrored list of sheets on the servo side.
|
2017-06-29 04:07:06 +03:00
|
|
|
Servo_StyleSet_InsertStyleSheetBefore(
|
|
|
|
mRawSet.get(), aNewSheet, aReferenceSheet);
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-04-29 07:01:44 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
ServoStyleSet::SheetCount(SheetType aType) const
|
|
|
|
{
|
2017-11-16 04:37:17 +03:00
|
|
|
MOZ_ASSERT(IsCSSSheetType(aType));
|
2017-05-12 22:04:55 +03:00
|
|
|
return mSheets[aType].Length();
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSheet*
|
2017-06-29 04:07:06 +03:00
|
|
|
ServoStyleSet::StyleSheetAt(SheetType aType, int32_t aIndex) const
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2017-11-16 04:37:17 +03:00
|
|
|
MOZ_ASSERT(IsCSSSheetType(aType));
|
2017-05-12 22:04:55 +03:00
|
|
|
return mSheets[aType][aIndex];
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2017-06-30 02:09:22 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::AppendAllXBLStyleSheets(nsTArray<StyleSheet*>& aArray) const
|
|
|
|
{
|
|
|
|
if (mBindingManager) {
|
|
|
|
mBindingManager->AppendAllSheets(aArray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
nsresult
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSet::RemoveDocStyleSheet(ServoStyleSheet* aSheet)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-04-29 07:01:44 +03:00
|
|
|
return RemoveStyleSheet(SheetType::Doc, aSheet);
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSet::AddDocStyleSheet(ServoStyleSheet* aSheet,
|
2016-02-24 10:01:10 +03:00
|
|
|
nsIDocument* aDocument)
|
|
|
|
{
|
2017-01-09 12:42:52 +03:00
|
|
|
MOZ_ASSERT(aSheet->IsApplicable());
|
2017-06-29 04:07:06 +03:00
|
|
|
MOZ_ASSERT(aSheet->RawContents(), "Raw sheet should be in place by this point.");
|
2017-01-09 12:42:52 +03:00
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
RefPtr<StyleSheet> strong(aSheet);
|
2016-04-29 07:01:44 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
RemoveSheetOfType(SheetType::Doc, aSheet);
|
2016-04-29 07:01:44 +03:00
|
|
|
|
|
|
|
size_t index =
|
2017-05-12 22:04:55 +03:00
|
|
|
aDocument->FindDocStyleSheetInsertionPoint(mSheets[SheetType::Doc], aSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
if (index < mSheets[SheetType::Doc].Length()) {
|
2017-05-02 02:46:41 +03:00
|
|
|
// This case is insert before.
|
2017-05-12 22:04:55 +03:00
|
|
|
ServoStyleSheet *beforeSheet = mSheets[SheetType::Doc][index];
|
|
|
|
InsertSheetOfType(SheetType::Doc, aSheet, beforeSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
|
|
|
|
if (mRawSet) {
|
|
|
|
// Maintain a mirrored list of sheets on the servo side.
|
2017-06-29 04:07:06 +03:00
|
|
|
Servo_StyleSet_InsertStyleSheetBefore(mRawSet.get(), aSheet, beforeSheet);
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-05-02 02:46:41 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This case is append.
|
2017-05-12 22:04:55 +03:00
|
|
|
AppendSheetOfType(SheetType::Doc, aSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
|
|
|
|
if (mRawSet) {
|
|
|
|
// Maintain a mirrored list of sheets on the servo side.
|
2017-06-29 04:07:06 +03:00
|
|
|
Servo_StyleSet_AppendStyleSheet(mRawSet.get(), aSheet);
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-04-29 07:01:44 +03:00
|
|
|
}
|
|
|
|
|
2016-02-26 05:57:42 +03:00
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2017-07-20 19:36:20 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2016-12-22 04:58:38 +03:00
|
|
|
ServoStyleSet::ProbePseudoElementStyle(Element* aOriginatingElement,
|
2016-02-24 10:01:10 +03:00
|
|
|
CSSPseudoElementType aType,
|
2017-07-17 21:42:04 +03:00
|
|
|
ServoStyleContext* aParentContext)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-05-10 20:13:39 +03:00
|
|
|
|
2017-06-27 09:35:09 +03:00
|
|
|
// NB: We ignore aParentContext, because in some cases
|
|
|
|
// (first-line/first-letter on anonymous box blocks) Gecko passes something
|
|
|
|
// nonsensical there. In all other cases we want to inherit directly from
|
|
|
|
// aOriginatingElement's styles anyway.
|
2016-04-29 03:56:37 +03:00
|
|
|
MOZ_ASSERT(aType < CSSPseudoElementType::Count);
|
|
|
|
|
2017-08-06 19:42:55 +03:00
|
|
|
bool cacheable =
|
2017-09-20 07:43:31 +03:00
|
|
|
LazyPseudoIsCacheable(aType, aOriginatingElement, aParentContext);
|
2017-08-06 19:42:55 +03:00
|
|
|
|
2017-07-17 21:42:00 +03:00
|
|
|
RefPtr<ServoStyleContext> computedValues =
|
2017-08-06 19:42:55 +03:00
|
|
|
cacheable ? aParentContext->GetCachedLazyPseudoStyle(aType) : nullptr;
|
2016-04-29 03:56:37 +03:00
|
|
|
if (!computedValues) {
|
2017-08-06 19:42:55 +03:00
|
|
|
computedValues = Servo_ResolvePseudoStyle(aOriginatingElement, aType,
|
|
|
|
/* is_probe = */ true,
|
|
|
|
nullptr,
|
|
|
|
mRawSet.get()).Consume();
|
|
|
|
if (!computedValues) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cacheable) {
|
|
|
|
// NB: We don't need to worry about the before/after handling below
|
|
|
|
// because those are eager and thus not |cacheable| anyway.
|
|
|
|
aParentContext->SetCachedLazyPseudoStyle(computedValues);
|
|
|
|
}
|
2016-04-29 03:56:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// For :before and :after pseudo-elements, having display: none or no
|
|
|
|
// 'content' property is equivalent to not having the pseudo-element
|
|
|
|
// at all.
|
2017-05-14 19:39:22 +03:00
|
|
|
bool isBeforeOrAfter = aType == CSSPseudoElementType::before ||
|
|
|
|
aType == CSSPseudoElementType::after;
|
2017-01-29 06:59:00 +03:00
|
|
|
if (isBeforeOrAfter) {
|
2017-07-21 07:44:02 +03:00
|
|
|
const nsStyleDisplay* display = computedValues->ComputedData()->GetStyleDisplay();
|
|
|
|
const nsStyleContent* content = computedValues->ComputedData()->GetStyleContent();
|
2016-09-03 21:46:58 +03:00
|
|
|
if (display->mDisplay == StyleDisplay::None ||
|
2016-04-29 03:56:37 +03:00
|
|
|
content->ContentCount() == 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-17 21:42:24 +03:00
|
|
|
return computedValues.forget();
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2017-02-10 05:42:30 +03:00
|
|
|
bool
|
2017-09-01 20:28:57 +03:00
|
|
|
ServoStyleSet::StyleDocument(ServoTraversalFlags aFlags)
|
2016-08-12 00:12:49 +03:00
|
|
|
{
|
2017-08-23 04:13:57 +03:00
|
|
|
nsIDocument* doc = mPresContext->Document();
|
|
|
|
if (!doc->GetServoRestyleRoot()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-01 20:28:57 +03:00
|
|
|
PreTraverse(aFlags);
|
2017-07-19 04:38:47 +03:00
|
|
|
AutoPrepareTraversal guard(this);
|
|
|
|
const SnapshotTable& snapshots = Snapshots();
|
2017-03-08 23:20:17 +03:00
|
|
|
|
2016-12-01 11:19:50 +03:00
|
|
|
// Restyle the document from the root element and each of the document level
|
|
|
|
// NAC subtree roots.
|
2017-02-10 05:42:30 +03:00
|
|
|
bool postTraversalRequired = false;
|
2017-07-19 04:38:47 +03:00
|
|
|
|
|
|
|
Element* rootElement = doc->GetRootElement();
|
2017-09-01 20:31:45 +03:00
|
|
|
MOZ_ASSERT_IF(rootElement, rootElement->HasServoData());
|
2017-07-19 04:38:47 +03:00
|
|
|
|
2017-09-01 20:28:57 +03:00
|
|
|
if (ShouldTraverseInParallel()) {
|
|
|
|
aFlags |= ServoTraversalFlags::ParallelTraversal;
|
|
|
|
}
|
|
|
|
|
2017-07-19 04:38:47 +03:00
|
|
|
// Do the first traversal.
|
|
|
|
DocumentStyleRootIterator iter(doc->GetServoRestyleRoot());
|
2016-12-01 11:19:50 +03:00
|
|
|
while (Element* root = iter.GetNextStyleRoot()) {
|
2017-09-26 08:25:06 +03:00
|
|
|
MOZ_ASSERT(MayTraverseFrom(root));
|
|
|
|
|
|
|
|
Element* parent = root->GetFlattenedTreeParentElementForStyle();
|
|
|
|
MOZ_ASSERT_IF(parent,
|
|
|
|
!parent->HasAnyOfFlags(Element::kAllServoDescendantBits));
|
|
|
|
|
|
|
|
postTraversalRequired |=
|
|
|
|
Servo_TraverseSubtree(root, mRawSet.get(), &snapshots, aFlags);
|
|
|
|
postTraversalRequired |=
|
|
|
|
root->HasAnyOfFlags(Element::kAllServoDescendantBits | NODE_NEEDS_FRAME);
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
MOZ_ASSERT(root == doc->GetServoRestyleRoot());
|
|
|
|
if (parent->HasDirtyDescendantsForServo()) {
|
|
|
|
// If any style invalidation was triggered in our siblings, then we may
|
|
|
|
// need to post-traverse them, even if the root wasn't restyled after
|
|
|
|
// all.
|
2017-10-10 04:05:54 +03:00
|
|
|
uint32_t existingBits = doc->GetServoRestyleRootDirtyBits();
|
|
|
|
// We need to propagate the existing bits to the parent.
|
|
|
|
parent->SetFlags(existingBits);
|
2017-09-26 08:25:06 +03:00
|
|
|
doc->SetServoRestyleRoot(
|
|
|
|
parent,
|
2017-10-10 04:05:54 +03:00
|
|
|
existingBits | ELEMENT_HAS_DIRTY_DESCENDANTS_FOR_SERVO);
|
2017-09-26 08:25:06 +03:00
|
|
|
postTraversalRequired = true;
|
|
|
|
}
|
|
|
|
}
|
2017-07-19 04:38:47 +03:00
|
|
|
}
|
2017-08-11 03:10:37 +03:00
|
|
|
|
2017-07-19 04:38:47 +03:00
|
|
|
// If there are still animation restyles needed, trigger a second traversal to
|
|
|
|
// update CSS animations or transitions' styles.
|
|
|
|
//
|
|
|
|
// Note that we need to check the style root again, because doing another
|
|
|
|
// PreTraverse on the EffectCompositor might alter the style root. But we
|
|
|
|
// don't need to worry about NAC, since document-level NAC shouldn't have
|
|
|
|
// animations.
|
|
|
|
//
|
|
|
|
// We don't need to do this for SMIL since SMIL only updates its animation
|
|
|
|
// values once at the begin of a tick. As a result, even if the previous
|
|
|
|
// traversal caused, for example, the font-size to change, the SMIL style
|
|
|
|
// won't be updated until the next tick anyway.
|
2017-09-01 20:28:57 +03:00
|
|
|
if (mPresContext->EffectCompositor()->PreTraverse(aFlags)) {
|
2017-07-19 04:38:47 +03:00
|
|
|
nsINode* styleRoot = doc->GetServoRestyleRoot();
|
|
|
|
Element* root = styleRoot->IsElement() ? styleRoot->AsElement() : rootElement;
|
2017-09-01 20:31:45 +03:00
|
|
|
|
2017-09-26 08:25:06 +03:00
|
|
|
postTraversalRequired |=
|
|
|
|
Servo_TraverseSubtree(root, mRawSet.get(), &snapshots, aFlags);
|
|
|
|
postTraversalRequired |=
|
|
|
|
root->HasAnyOfFlags(Element::kAllServoDescendantBits | NODE_NEEDS_FRAME);
|
2016-12-01 11:19:50 +03:00
|
|
|
}
|
2017-08-11 03:10:37 +03:00
|
|
|
|
2017-02-10 05:42:30 +03:00
|
|
|
return postTraversalRequired;
|
2016-08-12 00:12:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-12-11 09:11:36 +03:00
|
|
|
ServoStyleSet::StyleNewSubtree(Element* aRoot)
|
2016-08-12 00:12:49 +03:00
|
|
|
{
|
2017-07-28 08:07:58 +03:00
|
|
|
MOZ_ASSERT(!aRoot->HasServoData(), "Should have called StyleNewChildren");
|
|
|
|
PreTraverseSync();
|
2017-07-26 23:13:00 +03:00
|
|
|
AutoPrepareTraversal guard(this);
|
2017-03-08 23:20:17 +03:00
|
|
|
|
2017-07-26 23:13:00 +03:00
|
|
|
// Do the traversal. The snapshots will not be used.
|
|
|
|
const SnapshotTable& snapshots = Snapshots();
|
2017-08-11 22:54:35 +03:00
|
|
|
auto flags = ServoTraversalFlags::Empty;
|
2017-09-01 20:28:57 +03:00
|
|
|
if (ShouldTraverseInParallel()) {
|
|
|
|
flags |= ServoTraversalFlags::ParallelTraversal;
|
|
|
|
}
|
|
|
|
|
2017-02-10 05:42:30 +03:00
|
|
|
DebugOnly<bool> postTraversalRequired =
|
2017-08-11 22:54:35 +03:00
|
|
|
Servo_TraverseSubtree(aRoot, mRawSet.get(), &snapshots, flags);
|
2017-02-10 05:42:30 +03:00
|
|
|
MOZ_ASSERT(!postTraversalRequired);
|
2017-07-26 23:13:00 +03:00
|
|
|
|
|
|
|
// Annoyingly, the newly-styled content may have animations that need
|
|
|
|
// starting, which requires traversing them again. Mark the elements
|
|
|
|
// that need animation processing, then do a forgetful traversal to
|
|
|
|
// update the styles and clear the animation bits.
|
2017-08-11 22:54:35 +03:00
|
|
|
if (mPresContext->EffectCompositor()->PreTraverseInSubtree(flags, aRoot)) {
|
2017-07-26 23:13:00 +03:00
|
|
|
postTraversalRequired =
|
|
|
|
Servo_TraverseSubtree(aRoot, mRawSet.get(), &snapshots,
|
|
|
|
ServoTraversalFlags::AnimationOnly |
|
|
|
|
ServoTraversalFlags::Forgetful |
|
|
|
|
ServoTraversalFlags::ClearAnimationOnlyDirtyDescendants);
|
|
|
|
MOZ_ASSERT(!postTraversalRequired);
|
|
|
|
}
|
2016-08-12 00:12:49 +03:00
|
|
|
}
|
|
|
|
|
2016-05-25 09:55:49 +03:00
|
|
|
void
|
2016-12-11 09:11:36 +03:00
|
|
|
ServoStyleSet::StyleNewChildren(Element* aParent)
|
2016-05-25 09:55:49 +03:00
|
|
|
{
|
2017-07-28 08:07:58 +03:00
|
|
|
MOZ_ASSERT(aParent->HasServoData(), "Should have called StyleNewSubtree");
|
2017-07-19 04:38:47 +03:00
|
|
|
if (Servo_Element_IsDisplayNone(aParent)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-28 08:07:58 +03:00
|
|
|
PreTraverseSync();
|
2017-07-26 23:13:00 +03:00
|
|
|
AutoPrepareTraversal guard(this);
|
|
|
|
|
|
|
|
// Implementing StyleNewChildren correctly is very annoying, for two reasons:
|
|
|
|
// (1) We have to tiptoe around existing invalidations in the tree. In rare
|
|
|
|
// cases Gecko calls into the frame constructor with pending invalidations,
|
|
|
|
// and in other rare cases the frame constructor needs to perform
|
|
|
|
// synchronous styling rather than using the normal lazy frame
|
|
|
|
// construction mechanism. If both of these cases happen together, then we
|
|
|
|
// get an |aParent| with dirty style and/or dirty descendants, which we
|
|
|
|
// can't process right now because we're not set up to update the frames
|
|
|
|
// and process the change hints. We handle this case by passing the
|
|
|
|
// UnstyledOnly flag to servo.
|
|
|
|
// (2) We don't have a good way to handle animations. When styling unstyled
|
|
|
|
// content, a followup animation traversal may be required (for example
|
|
|
|
// to change the transition style from the after-change style we used in
|
|
|
|
// the animation cascade to the timeline-correct style). But once we do
|
|
|
|
// the initial styling, we don't have a good way to distinguish the new
|
|
|
|
// content and scope our animation processing to that. We should handle
|
|
|
|
// this somehow, but for now we just don't do the followup animation
|
|
|
|
// traversal, which is buggy.
|
|
|
|
|
|
|
|
// Set ourselves up to find the children by marking the parent as having
|
|
|
|
// dirty descendants.
|
|
|
|
bool hadDirtyDescendants = aParent->HasDirtyDescendantsForServo();
|
|
|
|
aParent->SetHasDirtyDescendantsForServo();
|
|
|
|
|
2017-08-11 03:28:25 +03:00
|
|
|
auto flags = ServoTraversalFlags::UnstyledOnly;
|
2017-09-01 20:28:57 +03:00
|
|
|
if (ShouldTraverseInParallel()) {
|
2017-08-11 03:28:25 +03:00
|
|
|
flags |= ServoTraversalFlags::ParallelTraversal;
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:13:00 +03:00
|
|
|
// Do the traversal. The snapshots will be ignored.
|
|
|
|
const SnapshotTable& snapshots = Snapshots();
|
2017-08-11 03:28:25 +03:00
|
|
|
Servo_TraverseSubtree(aParent, mRawSet.get(), &snapshots, flags);
|
2017-03-08 23:20:17 +03:00
|
|
|
|
2017-07-26 23:13:00 +03:00
|
|
|
// Restore the old state of the dirty descendants bit.
|
|
|
|
if (!hadDirtyDescendants) {
|
|
|
|
aParent->UnsetHasDirtyDescendantsForServo();
|
|
|
|
}
|
2016-11-02 09:11:24 +03:00
|
|
|
}
|
|
|
|
|
2017-06-11 14:11:08 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::StyleNewlyBoundElement(Element* aElement)
|
|
|
|
{
|
|
|
|
// In general the element is always styled by the time we're applying XBL
|
|
|
|
// bindings, because we need to style the element to know what the binding
|
|
|
|
// URI is. However, programmatic consumers of the XBL service (like the
|
|
|
|
// XML pretty printer) _can_ apply bindings without having styled the bound
|
|
|
|
// element. We could assert against this and require the callers manually
|
|
|
|
// resolve the style first, but it's easy enough to just handle here.
|
2017-07-28 08:07:58 +03:00
|
|
|
if (MOZ_LIKELY(aElement->HasServoData())) {
|
|
|
|
StyleNewChildren(aElement);
|
|
|
|
} else {
|
|
|
|
StyleNewSubtree(aElement);
|
|
|
|
}
|
2017-06-11 14:11:08 +03:00
|
|
|
}
|
|
|
|
|
2016-12-19 09:30:14 +03:00
|
|
|
void
|
2017-08-12 13:49:01 +03:00
|
|
|
ServoStyleSet::MarkOriginsDirty(OriginFlags aChangedOrigins)
|
2016-12-19 09:30:14 +03:00
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-08-12 13:19:22 +03:00
|
|
|
Servo_StyleSet_NoteStyleSheetsChanged(mRawSet.get(),
|
|
|
|
mAuthorStyleDisabled,
|
2017-08-12 13:49:01 +03:00
|
|
|
aChangedOrigins);
|
2016-12-19 09:30:14 +03:00
|
|
|
}
|
|
|
|
|
2017-05-25 20:50:03 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::RecordStyleSheetChange(
|
|
|
|
ServoStyleSheet* aSheet,
|
|
|
|
StyleSheet::ChangeType aChangeType)
|
|
|
|
{
|
|
|
|
switch (aChangeType) {
|
|
|
|
case StyleSheet::ChangeType::RuleAdded:
|
|
|
|
case StyleSheet::ChangeType::RuleRemoved:
|
|
|
|
case StyleSheet::ChangeType::RuleChanged:
|
|
|
|
// FIXME(emilio): We can presumably do better in a bunch of these.
|
2017-08-12 13:49:01 +03:00
|
|
|
return MarkOriginsDirty(aSheet->GetOrigin());
|
2017-05-26 18:46:31 +03:00
|
|
|
case StyleSheet::ChangeType::ApplicableStateChanged:
|
2017-05-25 20:50:03 +03:00
|
|
|
case StyleSheet::ChangeType::Added:
|
|
|
|
case StyleSheet::ChangeType::Removed:
|
2017-05-26 18:46:31 +03:00
|
|
|
// Do nothing, we've already recorded the change in the
|
|
|
|
// Append/Remove/Replace methods, etc, and will act consequently.
|
2017-05-25 20:50:03 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
ServoStyleSet::AssertTreeIsClean()
|
|
|
|
{
|
2016-12-28 11:26:10 +03:00
|
|
|
DocumentStyleRootIterator iter(mPresContext->Document());
|
|
|
|
while (Element* root = iter.GetNextStyleRoot()) {
|
2016-11-02 09:11:24 +03:00
|
|
|
Servo_AssertTreeIsClean(root);
|
|
|
|
}
|
2016-05-25 09:55:49 +03:00
|
|
|
}
|
2016-11-02 09:11:24 +03:00
|
|
|
#endif
|
2017-01-04 22:52:27 +03:00
|
|
|
|
2017-01-29 06:58:28 +03:00
|
|
|
bool
|
2017-10-10 11:00:28 +03:00
|
|
|
ServoStyleSet::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-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-05-10 20:13:39 +03:00
|
|
|
|
2017-05-13 10:34:38 +03:00
|
|
|
return Servo_StyleSet_GetKeyframesForName(mRawSet.get(),
|
2017-10-10 11:00:28 +03:00
|
|
|
aName,
|
2017-05-13 10:34:38 +03:00
|
|
|
&aTimingFunction,
|
|
|
|
&aKeyframes);
|
2017-01-29 06:58:28 +03:00
|
|
|
}
|
|
|
|
|
2017-03-11 04:40:47 +03:00
|
|
|
nsTArray<ComputedKeyframeValues>
|
2017-03-21 10:41:23 +03:00
|
|
|
ServoStyleSet::GetComputedKeyframeValuesFor(
|
|
|
|
const nsTArray<Keyframe>& aKeyframes,
|
2017-06-02 03:38:22 +03:00
|
|
|
Element* aElement,
|
2017-07-18 15:29:12 +03:00
|
|
|
const ServoStyleContext* aContext)
|
2017-03-11 04:40:47 +03:00
|
|
|
{
|
2017-08-04 12:26:04 +03:00
|
|
|
// Servo_GetComputedKeyframeValues below won't handle ignoring existing
|
|
|
|
// element data for bfcached documents. (See comment in ResolveStyleLazily
|
|
|
|
// about these bfcache issues.)
|
|
|
|
MOZ_RELEASE_ASSERT(!aElement->OwnerDoc()->GetBFCacheEntry());
|
|
|
|
|
|
|
|
AutoClearStaleData guard(aElement);
|
2017-03-11 04:40:47 +03:00
|
|
|
nsTArray<ComputedKeyframeValues> result(aKeyframes.Length());
|
|
|
|
|
|
|
|
// Construct each nsTArray<PropertyStyleAnimationValuePair> here.
|
|
|
|
result.AppendElements(aKeyframes.Length());
|
|
|
|
|
|
|
|
Servo_GetComputedKeyframeValues(&aKeyframes,
|
2017-06-02 03:38:22 +03:00
|
|
|
aElement,
|
2017-07-18 15:29:12 +03:00
|
|
|
aContext,
|
2017-03-11 04:40:47 +03:00
|
|
|
mRawSet.get(),
|
|
|
|
&result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-06-09 00:19:37 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::GetAnimationValues(
|
|
|
|
RawServoDeclarationBlock* aDeclarations,
|
|
|
|
Element* aElement,
|
2017-07-18 15:29:12 +03:00
|
|
|
const ServoStyleContext* aStyleContext,
|
2017-06-09 00:19:37 +03:00
|
|
|
nsTArray<RefPtr<RawServoAnimationValue>>& aAnimationValues)
|
|
|
|
{
|
2017-08-04 12:26:04 +03:00
|
|
|
// Servo_GetAnimationValues below won't handle ignoring existing element
|
|
|
|
// data for bfcached documents. (See comment in ResolveStyleLazily
|
|
|
|
// about these bfcache issues.)
|
|
|
|
MOZ_RELEASE_ASSERT(!aElement->OwnerDoc()->GetBFCacheEntry());
|
|
|
|
|
|
|
|
AutoClearStaleData guard(aElement);
|
2017-06-09 00:19:37 +03:00
|
|
|
Servo_GetAnimationValues(aDeclarations,
|
|
|
|
aElement,
|
2017-07-18 15:29:12 +03:00
|
|
|
aStyleContext,
|
2017-06-09 00:19:37 +03:00
|
|
|
mRawSet.get(),
|
|
|
|
&aAnimationValues);
|
|
|
|
}
|
|
|
|
|
2017-07-17 21:41:44 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
|
|
|
ServoStyleSet::GetBaseContextForElement(
|
2017-07-10 14:33:21 +03:00
|
|
|
Element* aElement,
|
2017-07-17 21:41:44 +03:00
|
|
|
nsPresContext* aPresContext,
|
2017-07-10 14:33:21 +03:00
|
|
|
CSSPseudoElementType aPseudoType,
|
2017-07-17 21:42:00 +03:00
|
|
|
const ServoStyleContext* aStyle)
|
2017-04-06 04:34:50 +03:00
|
|
|
{
|
2017-08-04 12:26:04 +03:00
|
|
|
// Servo_StyleSet_GetBaseComputedValuesForElement below won't handle ignoring
|
|
|
|
// existing element data for bfcached documents. (See comment in
|
|
|
|
// ResolveStyleLazily about these bfcache issues.)
|
|
|
|
MOZ_RELEASE_ASSERT(!aElement->OwnerDoc()->GetBFCacheEntry(),
|
|
|
|
"GetBaseContextForElement does not support documents in the "
|
|
|
|
"bfcache");
|
|
|
|
|
|
|
|
AutoClearStaleData guard(aElement);
|
2017-07-17 21:42:00 +03:00
|
|
|
return Servo_StyleSet_GetBaseComputedValuesForElement(mRawSet.get(),
|
2017-04-06 04:34:50 +03:00
|
|
|
aElement,
|
2017-07-10 14:33:21 +03:00
|
|
|
aStyle,
|
2017-05-07 17:36:47 +03:00
|
|
|
&Snapshots(),
|
2017-05-14 19:39:22 +03:00
|
|
|
aPseudoType).Consume();
|
2017-04-06 04:34:50 +03:00
|
|
|
}
|
|
|
|
|
2017-10-19 05:51:55 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
|
|
|
ServoStyleSet::ResolveServoStyleByAddingAnimation(
|
|
|
|
Element* aElement,
|
|
|
|
const ServoStyleContext* aStyle,
|
|
|
|
RawServoAnimationValue* aAnimationValue)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(!aElement->OwnerDoc()->GetBFCacheEntry(),
|
|
|
|
"ResolveServoStyleByAddingAniamtion does not support "
|
|
|
|
"documents in the bfcache");
|
|
|
|
|
|
|
|
AutoClearStaleData guard(aElement);
|
|
|
|
return Servo_StyleSet_GetComputedValuesByAddingAnimation(
|
|
|
|
mRawSet.get(),
|
|
|
|
aElement,
|
|
|
|
aStyle,
|
|
|
|
&Snapshots(),
|
|
|
|
aAnimationValue).Consume();
|
|
|
|
}
|
|
|
|
|
2017-05-03 06:15:27 +03:00
|
|
|
already_AddRefed<RawServoAnimationValue>
|
|
|
|
ServoStyleSet::ComputeAnimationValue(
|
2017-06-02 03:38:22 +03:00
|
|
|
Element* aElement,
|
2017-05-03 06:15:27 +03:00
|
|
|
RawServoDeclarationBlock* aDeclarations,
|
2017-07-18 15:29:12 +03:00
|
|
|
const ServoStyleContext* aContext)
|
2017-05-03 06:15:27 +03:00
|
|
|
{
|
2017-08-04 12:26:04 +03:00
|
|
|
// Servo_AnimationValue_Compute below won't handle ignoring existing element
|
|
|
|
// data for bfcached documents. (See comment in ResolveStyleLazily about
|
|
|
|
// these bfcache issues.)
|
|
|
|
MOZ_RELEASE_ASSERT(!aElement->OwnerDoc()->GetBFCacheEntry());
|
|
|
|
|
|
|
|
AutoClearStaleData guard(aElement);
|
2017-06-02 03:38:22 +03:00
|
|
|
return Servo_AnimationValue_Compute(aElement,
|
|
|
|
aDeclarations,
|
2017-07-18 15:29:12 +03:00
|
|
|
aContext,
|
2017-05-03 06:15:27 +03:00
|
|
|
mRawSet.get()).Consume();
|
|
|
|
}
|
|
|
|
|
2017-05-16 02:30:10 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::EnsureUniqueInnerOnCSSSheets()
|
|
|
|
{
|
2017-05-16 03:11:08 +03:00
|
|
|
AutoTArray<StyleSheet*, 32> queue;
|
|
|
|
for (auto& entryArray : mSheets) {
|
|
|
|
for (auto& sheet : entryArray) {
|
|
|
|
queue.AppendElement(sheet);
|
|
|
|
}
|
|
|
|
}
|
2017-05-16 02:30:10 +03:00
|
|
|
// This is a stub until more of the functionality of nsStyleSet is
|
|
|
|
// replicated for Servo here.
|
|
|
|
|
2017-05-16 03:11:08 +03:00
|
|
|
// Bug 1290276 will replicate the nsStyleSet work of checking
|
|
|
|
// a nsBindingManager
|
|
|
|
|
|
|
|
while (!queue.IsEmpty()) {
|
|
|
|
uint32_t idx = queue.Length() - 1;
|
|
|
|
StyleSheet* sheet = queue[idx];
|
|
|
|
queue.RemoveElementAt(idx);
|
|
|
|
|
2017-10-03 21:15:26 +03:00
|
|
|
// Only call EnsureUniqueInner for complete sheets. If we do call it on
|
|
|
|
// incomplete sheets, we'll cause problems when the sheet is actually
|
|
|
|
// loaded. We don't care about incomplete sheets here anyway, because this
|
|
|
|
// method is only invoked by nsPresContext::EnsureSafeToHandOutCSSRules.
|
|
|
|
// The CSSRule objects we are handing out won't contain any rules derived
|
|
|
|
// from incomplete sheets (because they aren't yet applied in styling).
|
|
|
|
if (sheet->IsComplete()) {
|
|
|
|
sheet->EnsureUniqueInner();
|
|
|
|
}
|
2017-05-16 03:11:08 +03:00
|
|
|
|
|
|
|
// Enqueue all the sheet's children.
|
|
|
|
sheet->AppendAllChildSheets(queue);
|
|
|
|
}
|
|
|
|
|
2017-08-22 21:36:14 +03:00
|
|
|
if (mNeedsRestyleAfterEnsureUniqueInner) {
|
|
|
|
// TODO(emilio): We could make this faster if needed tracking the specific
|
|
|
|
// origins and all that, but the only caller of this doesn't seem to really
|
|
|
|
// care about perf.
|
|
|
|
MarkOriginsDirty(OriginFlags::All);
|
|
|
|
}
|
2017-05-16 02:30:10 +03:00
|
|
|
bool res = mNeedsRestyleAfterEnsureUniqueInner;
|
|
|
|
mNeedsRestyleAfterEnsureUniqueInner = false;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-01-04 22:52:27 +03:00
|
|
|
void
|
2017-08-02 15:39:32 +03:00
|
|
|
ServoStyleSet::ClearCachedStyleData()
|
2017-01-04 22:52:27 +03:00
|
|
|
{
|
2017-03-08 08:18:39 +03:00
|
|
|
ClearNonInheritingStyleContexts();
|
2017-08-02 15:39:32 +03:00
|
|
|
Servo_StyleSet_RebuildCachedData(mRawSet.get());
|
2017-01-04 22:52:27 +03:00
|
|
|
}
|
2017-01-04 22:52:27 +03:00
|
|
|
|
2017-06-10 17:22:23 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::CompatibilityModeChanged()
|
|
|
|
{
|
|
|
|
Servo_StyleSet_CompatModeChanged(mRawSet.get());
|
|
|
|
}
|
|
|
|
|
2017-07-17 21:42:00 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2017-08-11 22:55:32 +03:00
|
|
|
ServoStyleSet::ResolveServoStyle(Element* aElement)
|
2017-01-04 22:52:27 +03:00
|
|
|
{
|
2017-07-23 06:06:07 +03:00
|
|
|
RefPtr<ServoStyleContext> result =
|
2017-08-11 22:55:32 +03:00
|
|
|
Servo_ResolveStyle(aElement, mRawSet.get()).Consume();
|
2017-07-23 06:06:07 +03:00
|
|
|
return result.forget();
|
2017-01-04 22:52:27 +03:00
|
|
|
}
|
2017-02-02 22:48:28 +03:00
|
|
|
|
2017-03-08 08:18:39 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::ClearNonInheritingStyleContexts()
|
|
|
|
{
|
2017-07-20 19:36:20 +03:00
|
|
|
for (RefPtr<ServoStyleContext>& ptr : mNonInheritingStyleContexts) {
|
2017-03-08 08:18:39 +03:00
|
|
|
ptr = nullptr;
|
2017-03-11 04:40:47 +03:00
|
|
|
}
|
2017-03-08 08:18:39 +03:00
|
|
|
}
|
|
|
|
|
2017-07-17 21:42:00 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2017-08-04 12:26:03 +03:00
|
|
|
ServoStyleSet::ResolveStyleLazilyInternal(Element* aElement,
|
|
|
|
CSSPseudoElementType aPseudoType,
|
2017-08-04 12:26:04 +03:00
|
|
|
StyleRuleInclusion aRuleInclusion,
|
|
|
|
bool aIgnoreExistingStyles)
|
2017-03-08 23:20:17 +03:00
|
|
|
{
|
2017-05-14 19:39:22 +03:00
|
|
|
mPresContext->EffectCompositor()->PreTraverse(aElement, aPseudoType);
|
2017-05-15 19:02:59 +03:00
|
|
|
MOZ_ASSERT(!StylistNeedsUpdate());
|
2017-04-30 09:41:11 +03:00
|
|
|
|
|
|
|
AutoSetInServoTraversal guard(this);
|
2017-04-26 15:01:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* NB: This is needed because we process animations and transitions on the
|
|
|
|
* pseudo-elements themselves, not on the parent's EagerPseudoStyles.
|
|
|
|
*
|
|
|
|
* That means that that style doesn't account for animations, and we can't do
|
|
|
|
* that easily from the traversal without doing wasted work.
|
|
|
|
*
|
|
|
|
* As such, we just lie here a bit, which is the entrypoint of
|
|
|
|
* getComputedStyle, the only API where this can be observed, to look at the
|
|
|
|
* style of the pseudo-element if it exists instead.
|
|
|
|
*/
|
|
|
|
Element* elementForStyleResolution = aElement;
|
2017-05-14 19:39:22 +03:00
|
|
|
CSSPseudoElementType pseudoTypeForStyleResolution = aPseudoType;
|
|
|
|
if (aPseudoType == CSSPseudoElementType::before) {
|
2017-04-26 15:01:25 +03:00
|
|
|
if (Element* pseudo = nsLayoutUtils::GetBeforePseudo(aElement)) {
|
|
|
|
elementForStyleResolution = pseudo;
|
2017-05-14 19:39:22 +03:00
|
|
|
pseudoTypeForStyleResolution = CSSPseudoElementType::NotPseudo;
|
2017-04-26 15:01:25 +03:00
|
|
|
}
|
2017-05-14 19:39:22 +03:00
|
|
|
} else if (aPseudoType == CSSPseudoElementType::after) {
|
2017-04-26 15:01:25 +03:00
|
|
|
if (Element* pseudo = nsLayoutUtils::GetAfterPseudo(aElement)) {
|
|
|
|
elementForStyleResolution = pseudo;
|
2017-05-14 19:39:22 +03:00
|
|
|
pseudoTypeForStyleResolution = CSSPseudoElementType::NotPseudo;
|
2017-04-26 15:01:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-17 21:42:00 +03:00
|
|
|
RefPtr<ServoStyleContext> computedValues =
|
2017-04-26 15:01:25 +03:00
|
|
|
Servo_ResolveStyleLazily(elementForStyleResolution,
|
2017-05-14 19:39:22 +03:00
|
|
|
pseudoTypeForStyleResolution,
|
2017-05-24 09:37:47 +03:00
|
|
|
aRuleInclusion,
|
2017-05-07 17:36:47 +03:00
|
|
|
&Snapshots(),
|
2017-08-04 12:26:04 +03:00
|
|
|
mRawSet.get(),
|
|
|
|
aIgnoreExistingStyles).Consume();
|
2017-03-10 05:53:19 +03:00
|
|
|
|
2017-05-14 19:39:22 +03:00
|
|
|
if (mPresContext->EffectCompositor()->PreTraverse(aElement, aPseudoType)) {
|
2017-03-10 05:53:19 +03:00
|
|
|
computedValues =
|
2017-04-26 15:01:25 +03:00
|
|
|
Servo_ResolveStyleLazily(elementForStyleResolution,
|
2017-05-14 19:39:22 +03:00
|
|
|
pseudoTypeForStyleResolution,
|
2017-05-24 09:37:47 +03:00
|
|
|
aRuleInclusion,
|
2017-05-07 17:36:47 +03:00
|
|
|
&Snapshots(),
|
2017-08-04 12:26:04 +03:00
|
|
|
mRawSet.get(),
|
|
|
|
aIgnoreExistingStyles).Consume();
|
2017-03-10 05:53:19 +03:00
|
|
|
}
|
2017-04-26 15:01:25 +03:00
|
|
|
|
2017-03-10 05:53:19 +03:00
|
|
|
return computedValues.forget();
|
2017-03-08 23:20:17 +03:00
|
|
|
}
|
|
|
|
|
2017-03-27 09:53:27 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray)
|
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-03-27 09:53:27 +03:00
|
|
|
Servo_StyleSet_GetFontFaceRules(mRawSet.get(), &aArray);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-11 07:47:24 +03:00
|
|
|
nsCSSCounterStyleRule*
|
2017-10-03 01:05:19 +03:00
|
|
|
ServoStyleSet::CounterStyleRuleForName(nsAtom* aName)
|
2017-05-11 07:47:24 +03:00
|
|
|
{
|
|
|
|
return Servo_StyleSet_GetCounterStyleRule(mRawSet.get(), aName);
|
|
|
|
}
|
|
|
|
|
2017-08-24 04:05:53 +03:00
|
|
|
already_AddRefed<gfxFontFeatureValueSet>
|
|
|
|
ServoStyleSet::BuildFontFeatureValueSet()
|
|
|
|
{
|
|
|
|
UpdateStylistIfNeeded();
|
2017-08-31 03:08:50 +03:00
|
|
|
RefPtr<gfxFontFeatureValueSet> set =
|
|
|
|
Servo_StyleSet_BuildFontFeatureValueSet(mRawSet.get());
|
2017-08-24 04:05:53 +03:00
|
|
|
return set.forget();
|
|
|
|
}
|
|
|
|
|
2017-07-17 21:42:00 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
2017-04-15 01:37:35 +03:00
|
|
|
ServoStyleSet::ResolveForDeclarations(
|
2017-07-17 21:42:00 +03:00
|
|
|
const ServoStyleContext* aParentOrNull,
|
2017-07-07 00:56:06 +03:00
|
|
|
RawServoDeclarationBlockBorrowed aDeclarations)
|
2017-04-15 01:37:35 +03:00
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-04-15 01:37:35 +03:00
|
|
|
return Servo_StyleSet_ResolveForDeclarations(mRawSet.get(),
|
|
|
|
aParentOrNull,
|
2017-07-07 00:56:06 +03:00
|
|
|
aDeclarations).Consume();
|
2017-04-15 01:37:35 +03:00
|
|
|
}
|
|
|
|
|
2017-05-10 20:13:39 +03:00
|
|
|
void
|
2017-05-15 19:02:59 +03:00
|
|
|
ServoStyleSet::UpdateStylist()
|
2017-05-10 20:13:39 +03:00
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
MOZ_ASSERT(StylistNeedsUpdate());
|
2017-08-31 23:59:11 +03:00
|
|
|
|
2017-09-02 10:25:45 +03:00
|
|
|
if (mStylistState & StylistState::StyleSheetsDirty) {
|
|
|
|
// There's no need to compute invalidations and such for an XBL styleset,
|
|
|
|
// since they are loaded and unloaded synchronously, and they don't have to
|
|
|
|
// deal with dynamic content changes.
|
|
|
|
Element* root =
|
|
|
|
IsMaster() ? mPresContext->Document()->GetDocumentElement() : nullptr;
|
|
|
|
|
|
|
|
Servo_StyleSet_FlushStyleSheets(mRawSet.get(), root);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MOZ_UNLIKELY(mStylistState & StylistState::XBLStyleSheetsDirty)) {
|
|
|
|
MOZ_ASSERT(IsMaster(), "Only master styleset can mark XBL stylesets dirty!");
|
|
|
|
mBindingManager->UpdateBoundContentBindingsForServo(mPresContext);
|
|
|
|
}
|
2017-08-31 23:59:11 +03:00
|
|
|
|
2017-05-15 19:02:59 +03:00
|
|
|
mStylistState = StylistState::NotDirty;
|
2017-05-10 20:13:39 +03:00
|
|
|
}
|
|
|
|
|
2017-06-16 20:20:25 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::MaybeGCRuleTree()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
Servo_MaybeGCRuleTree(mRawSet.get());
|
|
|
|
}
|
|
|
|
|
2017-09-26 08:25:06 +03:00
|
|
|
/* static */ bool
|
|
|
|
ServoStyleSet::MayTraverseFrom(const Element* aElement)
|
2017-07-26 20:43:48 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aElement->IsInComposedDoc());
|
|
|
|
Element* parent = aElement->GetFlattenedTreeParentElementForStyle();
|
|
|
|
if (!parent) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parent->HasServoData()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-19 04:38:47 +03:00
|
|
|
return !Servo_Element_IsDisplayNone(parent);
|
2017-07-26 20:43:48 +03:00
|
|
|
}
|
|
|
|
|
2017-09-01 20:28:57 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::ShouldTraverseInParallel() const
|
|
|
|
{
|
|
|
|
return mPresContext->PresShell()->IsActive();
|
|
|
|
}
|
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void
|
2017-05-02 02:46:41 +03:00
|
|
|
ServoStyleSet::PrependSheetOfType(SheetType aType,
|
2017-05-12 22:04:55 +03:00
|
|
|
ServoStyleSheet* aSheet)
|
2017-05-02 02:46:41 +03:00
|
|
|
{
|
2017-05-24 03:02:51 +03:00
|
|
|
aSheet->AddStyleSet(this);
|
2017-05-12 22:04:55 +03:00
|
|
|
mSheets[aType].InsertElementAt(0, aSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
}
|
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void
|
2017-05-02 02:46:41 +03:00
|
|
|
ServoStyleSet::AppendSheetOfType(SheetType aType,
|
2017-05-12 22:04:55 +03:00
|
|
|
ServoStyleSheet* aSheet)
|
2017-05-02 02:46:41 +03:00
|
|
|
{
|
2017-05-24 03:02:51 +03:00
|
|
|
aSheet->AddStyleSet(this);
|
2017-05-12 22:04:55 +03:00
|
|
|
mSheets[aType].AppendElement(aSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
}
|
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void
|
2017-05-02 02:46:41 +03:00
|
|
|
ServoStyleSet::InsertSheetOfType(SheetType aType,
|
|
|
|
ServoStyleSheet* aSheet,
|
2017-05-12 22:04:55 +03:00
|
|
|
ServoStyleSheet* aBeforeSheet)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mSheets[aType].Length(); ++i) {
|
|
|
|
if (mSheets[aType][i] == aBeforeSheet) {
|
2017-05-24 03:02:51 +03:00
|
|
|
aSheet->AddStyleSet(this);
|
2017-05-12 22:04:55 +03:00
|
|
|
mSheets[aType].InsertElementAt(i, aSheet);
|
|
|
|
return;
|
2017-05-02 02:46:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void
|
2017-05-02 02:46:41 +03:00
|
|
|
ServoStyleSet::RemoveSheetOfType(SheetType aType,
|
|
|
|
ServoStyleSheet* aSheet)
|
|
|
|
{
|
2017-05-12 22:04:55 +03:00
|
|
|
for (uint32_t i = 0; i < mSheets[aType].Length(); ++i) {
|
|
|
|
if (mSheets[aType][i] == aSheet) {
|
2017-05-24 03:02:51 +03:00
|
|
|
aSheet->DropStyleSet(this);
|
2017-05-12 22:04:55 +03:00
|
|
|
mSheets[aType].RemoveElementAt(i);
|
2017-05-02 02:46:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-30 09:45:32 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::RunPostTraversalTasks()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!IsInServoTraversal());
|
|
|
|
|
|
|
|
if (mPostTraversalTasks.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<PostTraversalTask> tasks;
|
|
|
|
tasks.SwapElements(mPostTraversalTasks);
|
|
|
|
|
|
|
|
for (auto& task : tasks) {
|
|
|
|
task.Run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 08:45:43 +03:00
|
|
|
ServoStyleRuleMap*
|
|
|
|
ServoStyleSet::StyleRuleMap()
|
|
|
|
{
|
|
|
|
if (!mStyleRuleMap) {
|
|
|
|
mStyleRuleMap = new ServoStyleRuleMap(this);
|
2017-08-22 09:46:25 +03:00
|
|
|
if (mPresContext) {
|
|
|
|
nsIDocument* doc = mPresContext->Document();
|
|
|
|
doc->AddObserver(mStyleRuleMap);
|
|
|
|
doc->CSSLoader()->AddObserver(mStyleRuleMap);
|
|
|
|
}
|
2017-06-19 08:45:43 +03:00
|
|
|
}
|
|
|
|
return mStyleRuleMap;
|
|
|
|
}
|
|
|
|
|
2017-05-08 11:04:31 +03:00
|
|
|
bool
|
2017-06-28 08:18:02 +03:00
|
|
|
ServoStyleSet::MightHaveAttributeDependency(const Element& aElement,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute) const
|
2017-05-08 11:04:31 +03:00
|
|
|
{
|
2017-06-28 08:18:02 +03:00
|
|
|
return Servo_StyleSet_MightHaveAttributeDependency(
|
|
|
|
mRawSet.get(), &aElement, aAttribute);
|
2017-05-08 11:04:31 +03:00
|
|
|
}
|
|
|
|
|
2017-05-09 13:13:45 +03:00
|
|
|
bool
|
2017-07-04 20:16:04 +03:00
|
|
|
ServoStyleSet::HasStateDependency(const Element& aElement,
|
|
|
|
EventStates aState) const
|
2017-05-09 13:13:45 +03:00
|
|
|
{
|
2017-06-28 08:18:02 +03:00
|
|
|
return Servo_StyleSet_HasStateDependency(
|
|
|
|
mRawSet.get(), &aElement, aState.ServoValue());
|
2017-05-09 13:13:45 +03:00
|
|
|
}
|
|
|
|
|
2017-11-01 13:20:39 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::HasDocumentStateDependency(EventStates aState) const
|
|
|
|
{
|
|
|
|
return Servo_StyleSet_HasDocumentStateDependency(
|
|
|
|
mRawSet.get(), aState.ServoValue());
|
|
|
|
}
|
|
|
|
|
2017-07-29 04:11:18 +03:00
|
|
|
already_AddRefed<ServoStyleContext>
|
|
|
|
ServoStyleSet::ReparentStyleContext(ServoStyleContext* aStyleContext,
|
|
|
|
ServoStyleContext* aNewParent,
|
|
|
|
ServoStyleContext* aNewParentIgnoringFirstLine,
|
|
|
|
ServoStyleContext* aNewLayoutParent,
|
|
|
|
Element* aElement)
|
|
|
|
{
|
2017-07-29 04:20:41 +03:00
|
|
|
return Servo_ReparentStyle(aStyleContext, aNewParent,
|
|
|
|
aNewParentIgnoringFirstLine, aNewLayoutParent,
|
|
|
|
aElement, mRawSet.get()).Consume();
|
2017-07-29 04:11:18 +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
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(UACacheReporter, nsIMemoryReporter)
|
|
|
|
|
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(ServoUACacheMallocSizeOf)
|
|
|
|
MOZ_DEFINE_MALLOC_ENCLOSING_SIZE_OF(ServoUACacheMallocEnclosingSizeOf)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
UACacheReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData, bool aAnonymize)
|
|
|
|
{
|
|
|
|
ServoStyleSetSizes sizes;
|
|
|
|
Servo_UACache_AddSizeOf(ServoUACacheMallocSizeOf,
|
|
|
|
ServoUACacheMallocEnclosingSizeOf, &sizes);
|
|
|
|
|
|
|
|
#define REPORT(_path, _amount, _desc) \
|
|
|
|
do { \
|
|
|
|
size_t __amount = _amount; /* evaluate _amount only once */ \
|
|
|
|
if (__amount > 0) { \
|
|
|
|
MOZ_COLLECT_REPORT(_path, KIND_HEAP, UNITS_BYTES, __amount, _desc); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
// The UA cache does not contain the rule tree; that's in the StyleSet.
|
|
|
|
MOZ_RELEASE_ASSERT(sizes.mRuleTree == 0);
|
|
|
|
|
|
|
|
REPORT("explicit/layout/servo-ua-cache/precomputed-pseudos",
|
|
|
|
sizes.mPrecomputedPseudos,
|
|
|
|
"Memory used by precomputed pseudo-element declarations within the "
|
|
|
|
"UA cache.");
|
|
|
|
|
|
|
|
REPORT("explicit/layout/servo-ua-cache/element-and-pseudos-maps",
|
|
|
|
sizes.mElementAndPseudosMaps,
|
|
|
|
"Memory used by element and pseudos maps within the UA cache.");
|
|
|
|
|
|
|
|
REPORT("explicit/layout/servo-ua-cache/invalidation-map",
|
|
|
|
sizes.mInvalidationMap,
|
|
|
|
"Memory used by invalidation maps within the UA cache.");
|
|
|
|
|
|
|
|
REPORT("explicit/layout/servo-ua-cache/revalidation-selectors",
|
|
|
|
sizes.mRevalidationSelectors,
|
|
|
|
"Memory used by selectors for cache revalidation within the UA "
|
|
|
|
"cache.");
|
|
|
|
|
|
|
|
REPORT("explicit/layout/servo-ua-cache/other",
|
|
|
|
sizes.mOther,
|
|
|
|
"Memory used by other data within the UA cache");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|