Bug 1180118 - Part 10: Logging. r=bzbarsky

This commit is contained in:
Cameron McCormack 2015-08-05 22:42:21 +10:00
parent 22d35ac20c
commit ecfc9591b6
3 changed files with 126 additions and 15 deletions

View File

@ -63,6 +63,15 @@ FrameTagToString(const nsIFrame* aFrame)
aFrame->ListTag(result);
return result;
}
static nsCString
ElementTagToString(dom::Element* aElement)
{
nsCString result;
nsDependentAtomString buf(aElement->NodeInfo()->NameAtom());
result.AppendPrintf("(%s@%p)", NS_ConvertUTF16toUTF8(buf).get(), aElement);
return result;
}
#endif
RestyleManager::RestyleManager(nsPresContext* aPresContext)
@ -2768,6 +2777,10 @@ ElementRestyler::AddPendingRestylesForDescendantsMatchingSelectors(
Element* aElement,
Element* aRestyleRoot)
{
LOG_RESTYLE("considering element %s for eRestyle_SomeDescendants",
ElementTagToString(aElement).get());
LOG_RESTYLE_INDENT();
if (aElement->HasFlag(mRestyleTracker.RootBit())) {
aRestyleRoot = aElement;
}
@ -2775,7 +2788,10 @@ ElementRestyler::AddPendingRestylesForDescendantsMatchingSelectors(
if (mRestyleTracker.HasRestyleData(aElement)) {
nsRestyleHint rshint = eRestyle_SomeDescendants;
if (SelectorMatchesForRestyle(aElement)) {
LOG_RESTYLE("element has existing restyle data and matches a selector");
rshint |= eRestyle_Self;
} else {
LOG_RESTYLE("element has existing restyle data but doesn't match selectors");
}
RestyleHintData data;
data.mSelectorsForDescendants = mSelectorsForDescendants;
@ -2785,6 +2801,7 @@ ElementRestyler::AddPendingRestylesForDescendantsMatchingSelectors(
}
if (SelectorMatchesForRestyle(aElement)) {
LOG_RESTYLE("element has no restyle data but matches a selector");
RestyleHintData data;
data.mSelectorsForDescendants = mSelectorsForDescendants;
mRestyleTracker.AddPendingRestyle(aElement,
@ -2992,6 +3009,16 @@ ElementRestyler::Restyle(nsRestyleHint aRestyleHint)
if ((aRestyleHint & eRestyle_SomeDescendants) &&
!mSelectorsForDescendants.IsEmpty()) {
Element* element = mContent->AsElement();
LOG_RESTYLE("traversing descendants of element %s to propagate "
"eRestyle_SomeDescendants for these %d selectors:",
ElementTagToString(element).get(),
int(mSelectorsForDescendants.Length()));
LOG_RESTYLE_INDENT();
#ifdef RESTYLE_LOGGING
for (nsCSSSelector* sel : mSelectorsForDescendants) {
LOG_RESTYLE("%s", sel->RestrictedSelectorToString().get());
}
#endif
Element* restyleRoot = mRestyleTracker.FindClosestRestyleRoot(element);
FlattenedChildIterator it(element);
for (nsIContent* n = it.GetNextChild(); n; n = it.GetNextChild()) {

View File

@ -559,7 +559,7 @@ nsCSSSelector::ToString(nsAString& aString, CSSStyleSheet* aSheet,
const nsCSSSelector *s = stack.ElementAt(index);
stack.RemoveElementAt(index);
s->AppendToStringWithoutCombinators(aString, aSheet);
s->AppendToStringWithoutCombinators(aString, aSheet, false);
// Append the combinator, if needed.
if (!stack.IsEmpty()) {
@ -583,24 +583,85 @@ nsCSSSelector::ToString(nsAString& aString, CSSStyleSheet* aSheet,
}
void
nsCSSSelector::AppendToStringWithoutCombinators
(nsAString& aString, CSSStyleSheet* aSheet) const
nsCSSSelector::AppendToStringWithoutCombinators(
nsAString& aString,
CSSStyleSheet* aSheet,
bool aUseStandardNamespacePrefixes) const
{
AppendToStringWithoutCombinatorsOrNegations(aString, aSheet, false);
AppendToStringWithoutCombinatorsOrNegations(aString, aSheet, false,
aUseStandardNamespacePrefixes);
for (const nsCSSSelector* negation = mNegations; negation;
negation = negation->mNegations) {
aString.AppendLiteral(":not(");
negation->AppendToStringWithoutCombinatorsOrNegations(aString, aSheet,
true);
negation->AppendToStringWithoutCombinatorsOrNegations(
aString, aSheet, true, aUseStandardNamespacePrefixes);
aString.Append(char16_t(')'));
}
}
#ifdef DEBUG
nsCString
nsCSSSelector::RestrictedSelectorToString() const
{
MOZ_ASSERT(IsRestrictedSelector());
nsString result;
AppendToStringWithoutCombinators(result, nullptr, true);
return NS_ConvertUTF16toUTF8(result);
}
static bool
AppendStandardNamespacePrefixToString(nsAString& aString, int32_t aNameSpace)
{
if (aNameSpace == kNameSpaceID_Unknown) {
// Wildcard namespace; no prefix to write.
return false;
}
switch (aNameSpace) {
case kNameSpaceID_None:
break;
case kNameSpaceID_XML:
aString.AppendLiteral("xml");
break;
case kNameSpaceID_XHTML:
aString.AppendLiteral("html");
break;
case kNameSpaceID_XLink:
aString.AppendLiteral("xlink");
break;
case kNameSpaceID_XSLT:
aString.AppendLiteral("xsl");
break;
case kNameSpaceID_XBL:
aString.AppendLiteral("xbl");
break;
case kNameSpaceID_MathML:
aString.AppendLiteral("math");
break;
case kNameSpaceID_RDF:
aString.AppendLiteral("rdf");
break;
case kNameSpaceID_XUL:
aString.AppendLiteral("xul");
break;
case kNameSpaceID_SVG:
aString.AppendLiteral("svg");
break;
default:
aString.AppendLiteral("ns");
aString.AppendInt(aNameSpace);
break;
}
return true;
}
#endif
void
nsCSSSelector::AppendToStringWithoutCombinatorsOrNegations
(nsAString& aString, CSSStyleSheet* aSheet,
bool aIsNegated) const
bool aIsNegated,
bool aUseStandardNamespacePrefixes) const
{
nsAutoString temp;
bool isPseudoElement = IsPseudoElement();
@ -616,7 +677,18 @@ nsCSSSelector::AppendToStringWithoutCombinatorsOrNegations
// null, that means that the only namespaces we could have are the
// wildcard namespace (which can be implicit in this case) and the "none"
// namespace, which then needs to be explicitly specified.
if (!sheetNS) {
if (aUseStandardNamespacePrefixes) {
#ifdef DEBUG
// We have no sheet to look up prefix information from. This is
// only for debugging, so use some "standard" prefixes that
// are recognizable.
wroteNamespace =
AppendStandardNamespacePrefixToString(aString, mNameSpace);
if (wroteNamespace) {
aString.Append(char16_t('|'));
}
#endif
} else if (!sheetNS) {
NS_ASSERTION(mNameSpace == kNameSpaceID_Unknown ||
mNameSpace == kNameSpaceID_None,
"How did we get this namespace?");
@ -740,7 +812,12 @@ nsCSSSelector::AppendToStringWithoutCombinatorsOrNegations
aString.Append(char16_t('*'));
aString.Append(char16_t('|'));
} else if (list->mNameSpace != kNameSpaceID_None) {
if (aSheet) {
if (aUseStandardNamespacePrefixes) {
#ifdef DEBUG
AppendStandardNamespacePrefixToString(aString, list->mNameSpace);
aString.Append(char16_t('|'));
#endif
} else if (aSheet) {
nsXMLNameSpaceMap *sheetNS = aSheet->GetNameSpaceMap();
nsIAtom *prefixAtom = sheetNS->FindPrefix(list->mNameSpace);
// Default namespaces don't apply to attribute selectors, so

View File

@ -163,16 +163,23 @@ public:
return PseudoType() == nsCSSPseudoElements::ePseudo_NotPseudoElement;
}
#ifdef DEBUG
nsCString RestrictedSelectorToString() const;
#endif
private:
void AddPseudoClassInternal(nsPseudoClassList *aPseudoClass);
nsCSSSelector* Clone(bool aDeepNext, bool aDeepNegations) const;
void AppendToStringWithoutCombinators(nsAString& aString,
mozilla::CSSStyleSheet* aSheet) const;
void AppendToStringWithoutCombinatorsOrNegations(nsAString& aString,
mozilla::CSSStyleSheet* aSheet,
bool aIsNegated)
const;
void AppendToStringWithoutCombinators(
nsAString& aString,
mozilla::CSSStyleSheet* aSheet,
bool aUseStandardNamespacePrefixes) const;
void AppendToStringWithoutCombinatorsOrNegations(
nsAString& aString,
mozilla::CSSStyleSheet* aSheet,
bool aIsNegated,
bool aUseStandardNamespacePrefixes) const;
// Returns true if this selector can have a namespace specified (which
// happens if and only if the default namespace would apply to this
// selector).