[analyzer] Better UI in html reports for displaying shortcuts help

Make the help window accessible, but don't show by default.
Use a different CSS class from macro.

llvm-svn: 322750
This commit is contained in:
George Karpenkov 2018-01-17 20:06:26 +00:00
parent 8e21678d5b
commit 6d83f34afd
2 changed files with 48 additions and 3 deletions

View File

@ -311,6 +311,10 @@ void html::AddHeaderFooterInternalBuiltinCSS(Rewriter &R, FileID FID,
" -webkit-border-radius:5px; -webkit-box-shadow:1px 1px 7px #000; "
" border-radius:5px; box-shadow:1px 1px 7px #000; "
"position: absolute; top: -1em; left:10em; z-index: 1 } \n"
" #tooltiphint { position: fixed; width: 50em; margin-left: -25em;"
"left: 50%; padding: 10px; border: 1px solid #b0b0b0;"
"border-radius: 2px; box-shadow: 1px 1px 7px black; "
"background-color: #c0c0c0; z-index: 2; }\n"
" .macro { color: darkmagenta; background-color:LemonChiffon;"
// Macros are position: relative to provide base for expansions.
" position: relative }\n"

View File

@ -101,6 +101,9 @@ private:
/// \return Executed lines from \p D in JSON format.
std::string serializeExecutedLines(const PathDiagnostic &D);
/// \return Javascript for displaying shortcuts help;
std::string showHelpJavascript();
};
} // end anonymous namespace
@ -347,6 +350,8 @@ void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R,
int LineNumber = path.back()->getLocation().asLocation().getExpansionLineNumber();
int ColumnNumber = path.back()->getLocation().asLocation().getExpansionColumnNumber();
R.InsertTextBefore(SMgr.getLocForStartOfFile(FID), showHelpJavascript());
R.InsertTextBefore(SMgr.getLocForStartOfFile(FID),
generateKeyboardNavigationJavascript());
@ -399,9 +404,17 @@ void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R,
</table>
<!-- REPORTSUMMARYEXTRA -->
<h3>Annotated Source Code</h3>
<p><span class='macro'>[?]
<span class='expansion'>Use j/k keys for keyboard navigation</span>
</span></p>
<p>Press <a href="#" onclick="toggleHelp(); return false;">'?'</a>
to see keyboard shortcuts</p>
<div id='tooltiphint' hidden="true">
<p>Keyboard shortcuts: </p>
<ul>
<li>Use 'j/k' keys for keyboard navigation</li>
<li>Use 'Shift+S' to show/hide relevant lines</li>
<li>Use '?' to toggle this window</li>
</ul>
<a href="#" onclick="toggleHelp(); return false;">Close</a>
</div>
)<<<";
R.InsertTextBefore(SMgr.getLocForStartOfFile(FID), os.str());
@ -461,6 +474,34 @@ void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R,
html::AddHeaderFooterInternalBuiltinCSS(R, FID, Entry->getName());
}
std::string HTMLDiagnostics::showHelpJavascript() {
return R"<<<(
<script type='text/javascript'>
var toggleHelp = function() {
var hint = document.querySelector("#tooltiphint");
var attributeName = "hidden";
if (hint.hasAttribute(attributeName)) {
hint.removeAttribute(attributeName);
} else {
hint.setAttribute("hidden", "true");
}
};
window.addEventListener("keydown", function (event) {
if (event.defaultPrevented) {
return;
}
if (event.key == "?") {
toggleHelp();
} else {
return;
}
event.preventDefault();
});
</script>
)<<<";
}
std::string
HTMLDiagnostics::showRelevantLinesJavascript(const PathDiagnostic &D) {
std::string s;