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

George Karpenkov via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 17 12:06:26 PST 2018


Author: george.karpenkov
Date: Wed Jan 17 12:06:26 2018
New Revision: 322750

URL: http://llvm.org/viewvc/llvm-project?rev=322750&view=rev
Log:
[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.

Modified:
    cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=322750&r1=322749&r2=322750&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Wed Jan 17 12:06:26 2018
@@ -311,6 +311,10 @@ void html::AddHeaderFooterInternalBuilti
           "  -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"

Modified: cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp?rev=322750&r1=322749&r2=322750&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp Wed Jan 17 12:06:26 2018
@@ -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
   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
 </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
   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;




More information about the cfe-commits mailing list