Files
palemoon27/layout/style/nsCSSRuleProcessor.h
roytam1 2828386673 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1247182 - Add an nsCSSRuleProcessor constructor that takes ownership of the given sheet array. r=birtles (07fd64f305)
- Bug 1260983 - Update animation properties when the style context changes; r=heycam (f68f67fc24)
- Bug 1160342 - Implement marquee using mutation observers, r=smaug (f8be96bfd8)
- Bug 1219842 - Enable a bunch of mochitest-plain tests under e10s. r=mrbkap (40aa7c1fce)
- Bug 1249061 - Improve property/attribute handling for marquees. r=smaug (1189869b3d)
- Bug 1266324 - Rename style const macro for unicode-bidi:bidi-override to be consistent with other style consts. r=jfkthame (24ded3fb69)
- Bug 1189894 - remove Atomics.h IntrinsicAddSub hack; r=erahm (d68fcf1801)
- Bug 1247338 - really make Atomic's constructor constexpr; r=Waldo (948c372b36)
- Bug 1266294 - Remove unnecessary compiler version checks for gcc <= 4.8.0 in mfbt. r=froydnj (8739fa352b)
- Bug 1260247. In chaos mode randomly decide to start a new image load even if the image is in the image cache when allowed by spec. r=seth (0d9dd4a1e9)
- Bug 1266294 - Remove unnecessary compiler version checks for gcc <= 4.8.0 in mfbt. r=froydnj (c230e51053)
- Bug 1209100 - Back out bug 1165185 on inbound. (af5f585393)
- Bug 1263342 - don't use REFCOUNTED_VIRTUAL_TYPENAME for mfbt FunctionImplBase. r=froydnj (f02a160c0b)
- Bug 1262577 - allow comparing mozilla::function with nullptr. r=froydnj (515a90b79a)
- Bug 1232418 - Allow mozilla::Tuple to support equality comparison; r=Waldo (1e8cb10660)
- Bug 1262663 - Clean up UniquePtr return documentation. r=Waldo (e92392b74e)
- Bug 1254831 - Fix compiler errors when SHOW_BOUNDING_BOX #ifdef is enabled. r=fredw (c0982211e8)
- Bug 1161169: Clean up usage of mContentParent and clearly identify it as specifically for async plugin init; r=billm,jimm (2ed3b9f96d)
- Bug 1164931 - Clear hangs when they're over (r=mrbkap) (f8de731e19)
- Bug 1250046 - Remove Shumway references from IPC. r=jmathies (7d7305c309)
- Bug 1254831 - Invalidate mfracs when linethickness changes. r=fredw (ff3d2bf6d0)
- Bug 1256943: Ensure that BLOCKED_ON_PLUGIN_MODULE_INIT_MS is being recorded in e10s chrome; r=jimm (ab879d7aec)
- Bug 1248821 - Force Flash to windowless mode regardless of sandbox level. r=jimm (007d45d5ef)
- Bug 1253434 - Avoid trying to capture plugin windows that have a zero width or height and a positive value for the other dim. r=aklotz (7a4995e8a5)
- Bug 1254829 - Calling TerminateProcess for WindowsXP to bypass DLL detach handler, r=bsmedberg (c04377e7b9)
- Bug 1263499 - unify the QuickExit function, r=bsmedberg (eeefdd7c2b)
- Bug 1246763 - Refactor GMP info file parsing into helper class. r=gerald (b4544c7370)
- Bug 1247556 - Use GMPInfoFileParser in GMPParent::ReadGMPMetaData(). r=gerald (6369ea568b)
- Bug 1247763 - Remove info file parsing from GMP child process. r=gerald (4454d25162)
- Bug 1258220 - Disable Adobe GMP if SSE2 isn't supported. r=gerald (55aba6b28a)
- Bug 1245789 - Make GMPParent::Init() return a promise, so it can be async. r=gerald (34ecae588a)
- Bug 1245789 - Add GMPAdapter which can be passed to GMPLoader to adapt non GMP library to GMP API. r=gerald (11f1734a6a)
- Bug 1245789 - Send name of GMPAdapter over to GMP process in StartPlugin message. r=gerald (a7b2df2c0d)
- Bug 1231633 - give scalar mLoadReplace a default value. r=bz (a7d1293b26)
- Bug 1245743 - Don't push new timeline markers while popping markers. r=vporof (f6efe5651e)
- Bug 1255459 - Use AutoRestore in ObservedDocShell::PopMarkers. r=smaug (d5fa90046e)
- Bug 1244897 - Use TimerlineConsumers in PopProfileTimelineMarkers to ensure that all methods acquire TimelineConsumers Mutex. r=vporof (39485ada73)
- Bug 1253516 - Do not acquire a lock that protects data that is not used; r=vporof (773337acce)
- Bug 1262970 - Change PRINCIPAL_HANDLE_NONE to a nullptr #define. r=froydnj (df470bc91c)
- Bug 1068596 - Pass SHARE_DELETE when opening a file so the file can be deleted without waiting for GC. r=roc (5b7d146cb8)
- Bug 1262970 - Allow nsMainThreadPtrHandle to be constructed by and compared to nullptr. r=froydnj (dbf01e5191)
- Bug 1249904: Use content-range values to determine length if content-length is unknown. r=roc (38a1388ea5)
- Bug 1251044: P1. Use content-range values to determine content's length. r=roc (72fb7f2a37)
- Bug 1251044: P2. Remove dead code and generalise the use of content-range header. r=roc (81d8dbf6f0)
- Bug 1228677 - Do not enforce CORS when loading file for MediaResource. r=cpearce (7d042fd6c2)
- Bug 1142272 - platformAPI memory leak, delete on return false. r=erahm (a7932ba850)
- Bug 1149616 - Fix the calculation of slots count in Read/WriteBuffer. r=bechen (6a2d010b3b)
- Bug 1262473 - don't needlessly construct nsAutoCString temporaries when serializing GMPVideoCodec; r=cpearce (7734560bb5)
- Bug 1245789 - Handle unencrypted samples in encrypted media. r=gerald Some encrypted MP4 files lack subsample info for some samples, so we need this check to prevent us crashing on such files. (6cf556699c)
- Bug 1245789 - Load Widevine CDM with sandbox level USER_RESTRICTED instead of USER_LOCKDOWN. r=bobowen (fd1ffd40a4)
- Bug 1245789 - Store GMPCapabilities by value, rather than on the heap. r=gerald (06c1737a4b)
- non-EME bits of Bug 1245789 - Parse Chrome CDM manifest in GMPService.addPluginDir (4116c843bd)
- Bug 1245789 - Whitelist functions needed by Widevine CDM in GMP child processes. r=jed (e525178fe5)
- Bug 1245789 - Ensure Widevine's nodeId are always unique and not permitted persistent storage. r=gerald (562e5b389b)
- Bug 1245789 - Push detection of WMF decoding for clearkey into GMPParent to simplify request media key system access logic. r=gerald (feffe136ba)
- Bug 1245789 - Make XPCOMThreadWrapper::GetCurrent() work. r=bholley (4e04f099cc)
- Bug 1245789 - Change GMPParent::InitPromise to instead use GenericPromise as defined in MozPromise.h. r=gerald (7c7c0f15d4)
- Bug 1158773: Use the same initial and delayed integrity level for Windows content sandbox level 0. r=tabraldes (2d6607e8a8)
- Bug 1219369: In Windows debug builds allow write access to TEMP for logging purposes. r=tabraldes (61737cff53)
- Bug 1166669: Enable process-level mitigations for the Windows content process sandbox. r=tabraldes (da06c34ceb)
- Bug 1197943: Turn off MITIGATION_STRICT_HANDLE_CHECKS for NPAPI process sandbox for causing hangs. r=aklotz (d31b767cd0)
- Bug 1245789 - Ensure GMPs have finished loading from MOZ_GMP_PATH before GMPServiceParent::GetContentParentFrom returns. r=gerald (361156a95b)
- Bug 1245789 - Ensure GMP service has added all plugins before running GMP remove tests. r=gerald (53616c6f09)
- Bug 1245789 - Expose AsyncAddPluginDirectory on GMPServiceParent. r=gerald (2a0fcd39ee)
- Bug 1183433 - Remove G-M-PServiceParent::AbortAsyncShutdown declaration, as it's not defined nor used anywhere. r=cpearce (b8f29f61dd)
- bit of Bug 1185392 - Use a separate mutex to protect mAsyncShutdownPluginStatesMutex, as mMutex could already be held when trying to update the states. r=cpearce (2be59fc7c9)
2024-06-18 09:37:48 +08:00

294 lines
10 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
// vim:cindent:tabstop=2:expandtab:shiftwidth=2:
/* 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/. */
/*
* style rule processor for CSS style sheets, responsible for selector
* matching and cascading
*/
#ifndef nsCSSRuleProcessor_h_
#define nsCSSRuleProcessor_h_
#include "mozilla/Attributes.h"
#include "mozilla/EventStates.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/RefCountType.h"
#include "mozilla/SheetType.h"
#include "mozilla/UniquePtr.h"
#include "nsAutoPtr.h"
#include "nsExpirationTracker.h"
#include "nsIMediaList.h"
#include "nsIStyleRuleProcessor.h"
#include "nsRuleWalker.h"
#include "nsTArray.h"
struct CascadeEnumData;
struct ElementDependentRuleProcessorData;
struct nsCSSSelector;
struct nsCSSSelectorList;
struct nsFontFaceRuleContainer;
struct RuleCascadeData;
struct TreeMatchContext;
class nsCSSKeyframesRule;
class nsCSSPageRule;
class nsCSSFontFeatureValuesRule;
class nsCSSCounterStyleRule;
namespace mozilla {
class CSSStyleSheet;
enum class CSSPseudoElementType : uint8_t;
namespace css {
class DocumentRule;
} // namespace css
} // namespace mozilla
/**
* The CSS style rule processor provides a mechanism for sibling style
* sheets to combine their rule processing in order to allow proper
* cascading to happen.
*
* CSS style rule processors keep a live reference on all style sheets
* bound to them. The CSS style sheets keep a weak reference to all the
* processors that they are bound to (many to many). The CSS style sheet
* is told when the rule processor is going away (via DropRuleProcessor).
*/
class nsCSSRuleProcessor: public nsIStyleRuleProcessor {
public:
typedef nsTArray<RefPtr<mozilla::CSSStyleSheet>> sheet_array_type;
// aScopeElement must be non-null iff aSheetType is
// SheetType::ScopedDoc.
// aPreviousCSSRuleProcessor is the rule processor (if any) that this
// one is replacing.
nsCSSRuleProcessor(const sheet_array_type& aSheets,
mozilla::SheetType aSheetType,
mozilla::dom::Element* aScopeElement,
nsCSSRuleProcessor* aPreviousCSSRuleProcessor,
bool aIsShared = false);
nsCSSRuleProcessor(sheet_array_type&& aSheets,
mozilla::SheetType aSheetType,
mozilla::dom::Element* aScopeElement,
nsCSSRuleProcessor* aPreviousCSSRuleProcessor,
bool aIsShared = false);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(nsCSSRuleProcessor)
public:
nsresult ClearRuleCascades();
static void Startup();
static void Shutdown();
static void FreeSystemMetrics();
static bool HasSystemMetric(nsIAtom* aMetric);
/*
* Returns true if the given aElement matches one of the
* selectors in aSelectorList. Note that this method will assume
* the given aElement is not a relevant link. aSelectorList must not
* include any pseudo-element selectors. aSelectorList is allowed
* to be null; in this case false will be returned.
*/
static bool SelectorListMatches(mozilla::dom::Element* aElement,
TreeMatchContext& aTreeMatchContext,
nsCSSSelectorList* aSelectorList);
/*
* Helper to get the content state for a content node. This may be
* slightly adjusted from IntrinsicState().
*/
static mozilla::EventStates GetContentState(
mozilla::dom::Element* aElement,
const TreeMatchContext& aTreeMatchContext);
/*
* Helper to get the content state for :visited handling for an element
*/
static mozilla::EventStates GetContentStateForVisitedHandling(
mozilla::dom::Element* aElement,
const TreeMatchContext& aTreeMatchContext,
nsRuleWalker::VisitedHandlingType aVisitedHandling,
bool aIsRelevantLink);
/*
* Helper to test whether a node is a link
*/
static bool IsLink(mozilla::dom::Element* aElement);
/**
* Returns true if the given aElement matches aSelector.
* Like nsCSSRuleProcessor.cpp's SelectorMatches (and unlike
* SelectorMatchesTree), this does not check an entire selector list
* separated by combinators.
*
* :visited and :link will match both visited and non-visited links,
* as if aTreeMatchContext->mVisitedHandling were eLinksVisitedOrUnvisited.
*
* aSelector is restricted to not containing pseudo-elements.
*/
static bool RestrictedSelectorMatches(mozilla::dom::Element* aElement,
nsCSSSelector* aSelector,
TreeMatchContext& aTreeMatchContext);
// nsIStyleRuleProcessor
virtual void RulesMatching(ElementRuleProcessorData* aData) override;
virtual void RulesMatching(PseudoElementRuleProcessorData* aData) override;
virtual void RulesMatching(AnonBoxRuleProcessorData* aData) override;
#ifdef MOZ_XUL
virtual void RulesMatching(XULTreeRuleProcessorData* aData) override;
#endif
virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) override;
virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) override;
virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) override;
virtual nsRestyleHint
HasAttributeDependentStyle(AttributeRuleProcessorData* aData,
mozilla::RestyleHintData& aRestyleHintDataResult)
override;
virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) override;
/**
* If this rule processor currently has a substantive media query
* result cache key, return a copy of it.
*/
mozilla::UniquePtr<nsMediaQueryResultCacheKey> CloneMQCacheKey();
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf)
const MOZ_MUST_OVERRIDE override;
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
const MOZ_MUST_OVERRIDE override;
// Append all the currently-active font face rules to aArray. Return
// true for success and false for failure.
bool AppendFontFaceRules(nsPresContext* aPresContext,
nsTArray<nsFontFaceRuleContainer>& aArray);
nsCSSKeyframesRule* KeyframesRuleForName(nsPresContext* aPresContext,
const nsString& aName);
nsCSSCounterStyleRule* CounterStyleRuleForName(nsPresContext* aPresContext,
const nsAString& aName);
bool AppendPageRules(nsPresContext* aPresContext,
nsTArray<nsCSSPageRule*>& aArray);
bool AppendFontFeatureValuesRules(nsPresContext* aPresContext,
nsTArray<nsCSSFontFeatureValuesRule*>& aArray);
/**
* Returns the scope element for the scoped style sheets this rule
* processor is for. If this is not a rule processor for scoped style
* sheets, it returns null.
*/
mozilla::dom::Element* GetScopeElement() const { return mScopeElement; }
void TakeDocumentRulesAndCacheKey(
nsPresContext* aPresContext,
nsTArray<mozilla::css::DocumentRule*>& aDocumentRules,
nsDocumentRuleResultCacheKey& aDocumentRuleResultCacheKey);
bool IsShared() const { return mIsShared; }
nsExpirationState* GetExpirationState() { return &mExpirationState; }
void AddStyleSetRef();
void ReleaseStyleSetRef();
void SetInRuleProcessorCache(bool aVal) {
MOZ_ASSERT(mIsShared);
mInRuleProcessorCache = aVal;
}
bool IsInRuleProcessorCache() const { return mInRuleProcessorCache; }
bool IsUsedByMultipleStyleSets() const { return mStyleSetRefCnt > 1; }
#ifdef XP_WIN
// Cached theme identifier for the moz-windows-theme media query.
static uint8_t GetWindowsThemeIdentifier();
static void SetWindowsThemeIdentifier(uint8_t aId) {
sWinThemeId = aId;
}
#endif
struct StateSelector {
StateSelector(mozilla::EventStates aStates, nsCSSSelector* aSelector)
: mStates(aStates),
mSelector(aSelector)
{}
mozilla::EventStates mStates;
nsCSSSelector* mSelector;
};
protected:
virtual ~nsCSSRuleProcessor();
private:
static bool CascadeSheet(mozilla::CSSStyleSheet* aSheet,
CascadeEnumData* aData);
RuleCascadeData* GetRuleCascade(nsPresContext* aPresContext);
void RefreshRuleCascade(nsPresContext* aPresContext);
nsRestyleHint HasStateDependentStyle(ElementDependentRuleProcessorData* aData,
mozilla::dom::Element* aStatefulElement,
mozilla::CSSPseudoElementType aPseudoType,
mozilla::EventStates aStateMask);
void ClearSheets();
// The sheet order here is the same as in nsStyleSet::mSheets
sheet_array_type mSheets;
// active first, then cached (most recent first)
RuleCascadeData* mRuleCascades;
// If we cleared our mRuleCascades or replaced a previous rule
// processor, this is the media query result cache key that was used
// before we lost the old rule cascades.
mozilla::UniquePtr<nsMediaQueryResultCacheKey> mPreviousCacheKey;
// The last pres context for which GetRuleCascades was called.
nsPresContext *mLastPresContext;
// The scope element for this rule processor's scoped style sheets.
// Only used if mSheetType == nsStyleSet::eScopedDocSheet.
RefPtr<mozilla::dom::Element> mScopeElement;
nsTArray<mozilla::css::DocumentRule*> mDocumentRules;
nsDocumentRuleResultCacheKey mDocumentCacheKey;
nsExpirationState mExpirationState;
MozRefCountType mStyleSetRefCnt;
// type of stylesheet using this processor
mozilla::SheetType mSheetType;
const bool mIsShared;
// Whether we need to build up mDocumentCacheKey and mDocumentRules as
// we build a RuleCascadeData. Is true only for shared rule processors
// and only before we build the first RuleCascadeData. See comment in
// RefreshRuleCascade for why.
bool mMustGatherDocumentRules;
bool mInRuleProcessorCache;
#ifdef DEBUG
bool mDocumentRulesAndCacheKeyValid;
#endif
#ifdef XP_WIN
static uint8_t sWinThemeId;
#endif
};
#endif /* nsCSSRuleProcessor_h_ */