Bug 1552098 - Add "Matched CSS Rules" command to the layout debugger. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D31397

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Cameron McCormack 2019-05-16 23:11:50 +00:00
parent 496ef2001b
commit 00bc6ad52c
8 changed files with 68 additions and 0 deletions

View File

@ -2006,4 +2006,27 @@ void nsContainerFrame::List(FILE* out, const char* aPrefix,
fprintf_stderr(out, "%s<>\n", str.get());
}
}
void nsContainerFrame::ListWithMatchedRules(FILE* out,
const char* aPrefix) const {
fprintf_stderr(out, "%s%s\n", aPrefix, ListTag().get());
nsCString rulePrefix;
rulePrefix += aPrefix;
rulePrefix += " ";
ListMatchedRules(out, rulePrefix.get());
nsCString childPrefix;
childPrefix += aPrefix;
childPrefix += " ";
ChildListIterator lists(this);
for (; !lists.IsDone(); lists.Next()) {
nsFrameList::Enumerator childFrames(lists.CurrentList());
for (; !childFrames.AtEnd(); childFrames.Next()) {
nsIFrame* kid = childFrames.get();
kid->ListWithMatchedRules(out, childPrefix.get());
}
}
}
#endif

View File

@ -73,6 +73,8 @@ class nsContainerFrame : public nsSplittableFrame {
#ifdef DEBUG_FRAME_DUMP
void List(FILE* out = stderr, const char* aPrefix = "",
uint32_t aFlags = 0) const override;
void ListWithMatchedRules(FILE* out = stderr,
const char* aPrefix = "") const override;
#endif
// nsContainerFrame methods

View File

@ -7605,6 +7605,26 @@ void nsIFrame::List(FILE* out, const char* aPrefix, uint32_t aFlags) const {
fprintf_stderr(out, "%s\n", str.get());
}
void nsIFrame::ListMatchedRules(FILE* out, const char* aPrefix) const {
nsTArray<const RawServoStyleRule*> rawRuleList;
Servo_ComputedValues_GetStyleRuleList(mComputedStyle, &rawRuleList);
for (const RawServoStyleRule* rawRule : rawRuleList) {
nsString ruleText;
Servo_StyleRule_GetCssText(rawRule, &ruleText);
fprintf_stderr(out, "%s%s\n", aPrefix,
NS_ConvertUTF16toUTF8(ruleText).get());
}
}
void nsIFrame::ListWithMatchedRules(FILE* out, const char* aPrefix) const {
fprintf_stderr(out, "%s%s\n", aPrefix, ListTag().get());
nsCString rulePrefix;
rulePrefix += aPrefix;
rulePrefix += " ";
ListMatchedRules(out, rulePrefix.get());
}
nsresult nsFrame::GetFrameName(nsAString& aResult) const {
return MakeFrameName(NS_LITERAL_STRING("Frame"), aResult);
}

View File

@ -4582,6 +4582,9 @@ class nsIFrame : public nsQueryFrame {
enum {TRAVERSE_SUBDOCUMENT_FRAMES = 0x01};
virtual void List(FILE* out = stderr, const char* aPrefix = "",
uint32_t aFlags = 0) const;
virtual void ListWithMatchedRules(FILE* out = stderr,
const char* aPrefix = "") const;
void ListMatchedRules(FILE* out, const char* aPrefix) const;
/**
* lists the frames beginning from the root frame
* - calls root frame's List(...)

View File

@ -46,6 +46,7 @@ interface nsILayoutDebuggingTools : nsISupports
void dumpViews();
void dumpStyleSheets();
void dumpMatchedRules();
void dumpComputedStyles();
void dumpReflowStats();

View File

@ -413,6 +413,22 @@ nsLayoutDebuggingTools::DumpStyleSheets() {
return NS_OK;
}
NS_IMETHODIMP nsLayoutDebuggingTools::DumpMatchedRules() {
NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED);
#ifdef DEBUG_FRAME_DUMP
FILE* out = stdout;
if (PresShell* presShell = GetPresShell(mDocShell)) {
nsIFrame* root = presShell->GetRootFrame();
if (root) {
root->ListWithMatchedRules(out);
}
} else {
fputs("null pres shell\n", out);
}
#endif
return NS_OK;
}
NS_IMETHODIMP
nsLayoutDebuggingTools::DumpComputedStyles() {
NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED);

View File

@ -83,6 +83,7 @@
<menuitem id="menu_dumpViews" label="&ldb.dumpViews.label;" accesskey="&ldb.dumpViews.accesskey;" oncommand="gDebugger.dumpViews();" />
<menuseparator />
<menuitem id="menu_dumpStyleSheets" label="&ldb.dumpStyleSheets.label;" accesskey="&ldb.dumpStyleSheets.accesskey;" oncommand="gDebugger.dumpStyleSheets();" />
<menuitem id="menu_dumpMatchedRules" label="&ldb.dumpMatchedRules.label;" accesskey="&ldb.dumpMatchedRules.accesskey;" oncommand="gDebugger.dumpMatchedRules();" />
<menuitem id="menu_dumpComputedStyles" label="&ldb.dumpComputedStyles.label;" accesskey="&ldb.dumpComputedStyles.accesskey;" oncommand="gDebugger.dumpComputedStyles();" />
<menuseparator />
<menuitem id="menu_dumpReflowStats" label="&ldb.dumpReflowStats.label;" accesskey="&ldb.dumpReflowStats.accesskey;" oncommand="gDebugger.dumpReflowStats();" />

View File

@ -70,6 +70,8 @@
<!ENTITY ldb.dumpViews.accesskey "V">
<!ENTITY ldb.dumpStyleSheets.label "Style Sheets">
<!ENTITY ldb.dumpStyleSheets.accesskey "S">
<!ENTITY ldb.dumpMatchedRules.label "Matched CSS Rules">
<!ENTITY ldb.dumpMatchedRules.accesskey "M">
<!ENTITY ldb.dumpComputedStyles.label "Style Contexts">
<!ENTITY ldb.dumpComputedStyles.accesskey "x">
<!ENTITY ldb.dumpReflowStats.label "Reflow Statistics">