Bug 1341086 - Part 2: stylo: Support all non-ts pseudos with an argument; r=emilio,heycam

MozReview-Commit-ID: IHjX2Q3k8eD

--HG--
extra : rebase_source : 57df0f0e54fd1aa1ce4b304238c7070ef9af6dd4
This commit is contained in:
Manish Goregaokar 2017-03-16 14:10:22 -07:00
Родитель 49b745a058
Коммит 681045b70e
9 изменённых файлов: 81 добавлений и 18 удалений

Просмотреть файл

@ -9631,8 +9631,8 @@ nsDocument::ForgetImagePreload(nsIURI* aURI)
}
}
EventStates
nsDocument::GetDocumentState()
void
nsDocument::UpdatePossiblyStaleDocumentState()
{
if (!mGotDocumentState.HasState(NS_DOCUMENT_STATE_RTL_LOCALE)) {
if (IsDocumentRightToLeft()) {
@ -9648,9 +9648,21 @@ nsDocument::GetDocumentState()
}
mGotDocumentState |= NS_DOCUMENT_STATE_WINDOW_INACTIVE;
}
}
EventStates
nsDocument::ThreadSafeGetDocumentState() const
{
return mDocumentState;
}
EventStates
nsDocument::GetDocumentState()
{
UpdatePossiblyStaleDocumentState();
return ThreadSafeGetDocumentState();
}
namespace {
/**

Просмотреть файл

@ -980,7 +980,12 @@ public:
virtual nsISupports* GetCurrentContentSink() override;
virtual mozilla::EventStates GetDocumentState() override;
virtual mozilla::EventStates GetDocumentState() final;
// GetDocumentState() mutates the state due to lazy resolution;
// and can't be used during parallel traversal. Use this instead,
// and ensure GetDocumentState() has been called first.
// This will assert if the state is stale.
virtual mozilla::EventStates ThreadSafeGetDocumentState() const final;
// Only BlockOnload should call this!
void AsyncBlockOnload();
@ -1391,6 +1396,7 @@ protected:
// caches its result here.
mozilla::Maybe<bool> mIsThirdParty;
private:
void UpdatePossiblyStaleDocumentState();
static bool CustomElementConstructor(JSContext* aCx, unsigned aArgc, JS::Value* aVp);
/**

Просмотреть файл

@ -2381,6 +2381,7 @@ public:
* nsIDocument.h.
*/
virtual mozilla::EventStates GetDocumentState() = 0;
virtual mozilla::EventStates ThreadSafeGetDocumentState() const = 0;
virtual nsISupports* GetCurrentContentSink() = 0;

Просмотреть файл

@ -486,6 +486,19 @@ nscolor Gecko_GetLookAndFeelSystemColor(int32_t aId,
return result;
}
bool
Gecko_MatchStringArgPseudo(RawGeckoElementBorrowed aElement,
CSSPseudoClassType aType,
const char16_t* aIdent,
bool* aSetSlowSelectorFlag)
{
MOZ_ASSERT(aElement->OwnerDoc() == aElement->GetComposedDoc());
EventStates dummyMask; // mask is never read because we pass aDependence=nullptr
return nsCSSRuleProcessor::StringPseudoMatches(aElement, aType, aIdent,
aElement->OwnerDoc(), true,
dummyMask, aSetSlowSelectorFlag, nullptr);
}
template <typename Implementor>
static nsIAtom*
AtomAttrValue(Implementor* aElement, nsIAtom* aName)

Просмотреть файл

@ -377,6 +377,11 @@ const nsMediaFeature* Gecko_GetMediaFeatures();
nscolor Gecko_GetLookAndFeelSystemColor(int32_t color_id,
RawGeckoPresContextBorrowed pres_context);
bool Gecko_MatchStringArgPseudo(RawGeckoElementBorrowed element,
mozilla::CSSPseudoClassType type,
const char16_t* ident,
bool* set_slow_selector);
// Style-struct management.
#define STYLE_STRUCT(name, checkdata_cb) \
void Gecko_Construct_Default_nsStyle##name( \

Просмотреть файл

@ -148,7 +148,7 @@ ServoStyleSet::GetContext(nsIContent* aContent,
Element* element = aContent->AsElement();
ResolveMappedAttrDeclarationBlocks();
PreTraverseSync();
RefPtr<ServoComputedValues> computedValues;
if (aMayCompute == LazyComputeBehavior::Allow) {
computedValues = ResolveStyleLazily(element, nullptr);
@ -190,10 +190,20 @@ ServoStyleSet::ResolveMappedAttrDeclarationBlocks()
}
void
ServoStyleSet::PreTraverse()
ServoStyleSet::PreTraverseSync()
{
ResolveMappedAttrDeclarationBlocks();
// This is lazily computed and pseudo matching needs to access
// it so force computation early.
mPresContext->Document()->GetDocumentState();
}
void
ServoStyleSet::PreTraverse()
{
PreTraverseSync();
// Process animation stuff that we should avoid doing during the parallel
// traversal.
mPresContext->EffectCompositor()->PreTraverse();

Просмотреть файл

@ -286,6 +286,8 @@ private:
* Perform processes that we should do before traversing.
*/
void PreTraverse();
// Subset of the pre-traverse steps that involve syncing up data
void PreTraverseSync();
already_AddRefed<ServoComputedValues> ResolveStyleLazily(dom::Element* aElement,
nsIAtom* aPseudoTag);

Просмотреть файл

@ -1638,20 +1638,29 @@ StateSelectorMatches(Element* aElement,
}
/* static */ bool
nsCSSRuleProcessor::StringPseudoMatches(mozilla::dom::Element* aElement,
nsCSSRuleProcessor::StringPseudoMatches(const mozilla::dom::Element* aElement,
CSSPseudoClassType aPseudo,
char16_t* aString,
nsIDocument* aDocument,
const char16_t* aString,
const nsIDocument* aDocument,
bool aForStyling,
EventStates aStateMask,
bool* aSetSlowSelectorFlag,
bool* const aDependence)
{
MOZ_ASSERT(aSetSlowSelectorFlag);
switch (aPseudo) {
case CSSPseudoClassType::mozLocaleDir:
{
bool docIsRTL =
aDocument->GetDocumentState().
HasState(NS_DOCUMENT_STATE_RTL_LOCALE);
bool docIsRTL;
if (aIsGecko) {
auto doc = const_cast<nsIDocument*>(aDocument);
docIsRTL = doc->GetDocumentState()
.HasState(NS_DOCUMENT_STATE_RTL_LOCALE);
} else {
docIsRTL = aDocument->ThreadSafeGetDocumentState()
.HasState(NS_DOCUMENT_STATE_RTL_LOCALE);
}
nsDependentString dirString(aString);
@ -1691,7 +1700,7 @@ nsCSSRuleProcessor::StringPseudoMatches(mozilla::dom::Element* aElement,
// :-moz-empty-except-children-with-localname() ~ E
// because we don't know to restyle the grandparent of the
// inserted/removed element (as in bug 534804 for :empty).
aElement->SetFlags(NODE_HAS_SLOW_SELECTOR);
*aSetSlowSelectorFlag = true;
}
do {
child = aElement->GetChildAt(++index);
@ -2141,13 +2150,18 @@ static bool SelectorMatches(Element* aElement,
default:
{
MOZ_ASSERT(nsCSSPseudoClasses::HasStringArg(pseudoClass->mType));
bool setSlowSelectorFlag = false;
bool matched = nsCSSRuleProcessor::StringPseudoMatches(aElement,
pseudoClass->mType,
pseudoClass->u.mString,
aTreeMatchContext.mDocument,
aTreeMatchContext.mForStyling,
aNodeMatchContext.mStateMask,
&setSlowSelectorFlag,
aDependence);
if (setSlowSelectorFlag) {
aElement->SetFlags(NODE_HAS_SLOW_SELECTOR);
}
if (!matched) {
return false;

Просмотреть файл

@ -141,9 +141,8 @@ public:
* parses but does not match. Asserts if it fails to parse; only
* call this when you're sure it's a string-like pseudo.
*
* This will assert if the document has a stale document state,
* ensure that UpdatePossiblyStaleDocumentState() has been called
* first.
* In Servo mode, please ensure that UpdatePossiblyStaleDocumentState()
* has been called first.
*
* @param aElement The element we are trying to match
* @param aPseudo The name of the pseudoselector
@ -156,12 +155,13 @@ public:
* @param aDependence Pointer to be set to true if we ignored a state due to
* aStateMask. Can be null.
*/
static bool StringPseudoMatches(mozilla::dom::Element* aElement,
static bool StringPseudoMatches(const mozilla::dom::Element* aElement,
mozilla::CSSPseudoClassType aPseudo,
char16_t* aString,
nsIDocument* aDocument,
const char16_t* aString,
const nsIDocument* aDocument,
bool aForStyling,
mozilla::EventStates aStateMask,
bool* aSetSlowSelectorFlag,
bool* const aDependence = nullptr);
// nsIStyleRuleProcessor