Merge "Add title and shortcuts for some links and buttons"
diff --git a/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html b/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html
index 495f8ab..33561d4 100644
--- a/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html
+++ b/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html
@@ -269,17 +269,17 @@
   _describe(Shortcut.NEXT_UNREVIEWED_FILE, ShortcutSection.DIFFS,
       'Mark file as reviewed and go to next unreviewed file');
 
-  _describe(Shortcut.NEXT_FILE, ShortcutSection.NAVIGATION, 'Select next file');
+  _describe(Shortcut.NEXT_FILE, ShortcutSection.NAVIGATION, 'Go to next file');
   _describe(Shortcut.PREV_FILE, ShortcutSection.NAVIGATION,
-      'Select previous file');
+      'Go to previous file');
   _describe(Shortcut.NEXT_FILE_WITH_COMMENTS, ShortcutSection.NAVIGATION,
-      'Select next file that has comments');
+      'Go to next file that has comments');
   _describe(Shortcut.PREV_FILE_WITH_COMMENTS, ShortcutSection.NAVIGATION,
-      'Select previous file that has comments');
+      'Go to previous file that has comments');
   _describe(Shortcut.OPEN_FIRST_FILE, ShortcutSection.NAVIGATION,
-      'Show first file');
+      'Go to first file');
   _describe(Shortcut.OPEN_LAST_FILE, ShortcutSection.NAVIGATION,
-      'Show last file');
+      'Go to last file');
   _describe(Shortcut.UP_TO_DASHBOARD, ShortcutSection.NAVIGATION,
       'Up to dashboard');
   _describe(Shortcut.UP_TO_CHANGE, ShortcutSection.NAVIGATION, 'Up to change');
@@ -350,6 +350,17 @@
       return this.listeners.delete(listener);
     }
 
+    getDescription(section, shortcutName) {
+      const binding =
+          _help.get(section).find(binding => binding.shortcut == shortcutName);
+      return binding ? binding.text : '';
+    }
+
+    getShortcut(shortcutName) {
+      const binding = this.bindings.get(shortcutName);
+      return binding ? this.describeBinding(binding) : '';
+    }
+
     activeShortcutsBySection() {
       const activeShortcuts = new Set();
       this.activeHosts.forEach(shortcuts => {
@@ -478,6 +489,8 @@
       GO_KEY: GO_KEY,
       // eslint-disable-next-line object-shorthand
       Shortcut: Shortcut,
+      // eslint-disable-next-line object-shorthand
+      ShortcutSection: ShortcutSection,
 
       properties: {
         _shortcut_go_key_last_pressed: {
@@ -528,6 +541,12 @@
         shortcutManager.bindShortcut(shortcut, ...bindings);
       },
 
+      createTitle(shortcutName, section) {
+        const desc = shortcutManager.getDescription(section, shortcutName);
+        const shortcut = shortcutManager.getShortcut(shortcutName);
+        return (desc && shortcut) ? `${desc} (shortcut: ${shortcut})` : '';
+      },
+
       _addOwnKeyBindings(shortcut, handler) {
         const bindings = shortcutManager.getBindingsForShortcut(shortcut);
         if (!bindings) {
@@ -632,6 +651,11 @@
      */
     Gerrit.KeyboardShortcutMixin = base =>
       class extends base {
+        get Shortcut() { return undefined; }
+
+        get ShortcutSection() { return undefined; }
+
+        createTitle(shortcutName, section) {}
       };
   }
 })(window);
diff --git a/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior_test.html b/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior_test.html
index ba143ec..f1bbcb0 100644
--- a/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior_test.html
+++ b/polygerrit-ui/app/behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior_test.html
@@ -189,7 +189,7 @@
               mapToObject(mgr.activeShortcutsBySection()),
               {
                 [NAVIGATION]: [
-                  {shortcut: NEXT_FILE, text: 'Select next file'},
+                  {shortcut: NEXT_FILE, text: 'Go to next file'},
                 ],
               });
 
@@ -207,7 +207,7 @@
                   {shortcut: NEXT_LINE, text: 'Go to next line'},
                 ],
                 [NAVIGATION]: [
-                  {shortcut: NEXT_FILE, text: 'Select next file'},
+                  {shortcut: NEXT_FILE, text: 'Go to next file'},
                 ],
               });
 
@@ -233,7 +233,7 @@
                   },
                 ],
                 [NAVIGATION]: [
-                  {shortcut: NEXT_FILE, text: 'Select next file'},
+                  {shortcut: NEXT_FILE, text: 'Go to next file'},
                 ],
               });
         });
@@ -286,7 +286,7 @@
                   {binding: [['g', 'o']], text: 'Go to Opened Changes'},
                 ],
                 [NAVIGATION]: [
-                  {binding: [[']']], text: 'Select next file'},
+                  {binding: [[']']], text: 'Go to next file'},
                 ],
               });
         });
diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html
index 5228578f..c62aba2 100644
--- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html
+++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html
@@ -441,6 +441,8 @@
                 <gr-button
                     id="replyBtn"
                     class="reply"
+                    title="[[createTitle(Shortcut.OPEN_REPLY_DIALOG,
+                      ShortcutSection.ACTIONS)]]"
                     hidden$="[[!_loggedIn]]"
                     primary
                     disabled="[[_replyDisabled]]"
diff --git a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.html b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.html
index 9146125..6fb6746 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.html
+++ b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.html
@@ -223,6 +223,8 @@
         <span class="downloadContainer desktop">
           <gr-button link
               class="download"
+              title="[[createTitle(Shortcut.OPEN_DOWNLOAD_DIALOG,
+                ShortcutSection.ACTIONS)]]"
               on-click="_handleDownloadTap">Download</gr-button>
         </span>
         <span class$="includedInContainer [[_hideIncludedIn(change)]] desktop">
@@ -235,6 +237,8 @@
           <gr-button
               id="expandBtn"
               link
+              title="[[createTitle(Shortcut.EXPAND_ALL_DIFF_CONTEXT,
+                ShortcutSection.DIFFS)]]"
               on-click="_expandAllDiffs">Expand All</gr-button>
           <gr-button
               id="collapseBtn"
diff --git a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.js b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.js
index 5828006..eb7c1f9 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.js
+++ b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.js
@@ -24,11 +24,13 @@
   /**
    * @appliesMixin Gerrit.FireMixin
    * @appliesMixin Gerrit.PatchSetMixin
+   * @appliesMixin Gerrit.KeyboardShortcutMixin
    * @extends Polymer.Element
    */
   class GrFileListHeader extends Polymer.mixinBehaviors( [
     Gerrit.FireBehavior,
     Gerrit.PatchSetBehavior,
+    Gerrit.KeyboardShortcutBehavior,
   ], Polymer.GestureEventListeners(
       Polymer.LegacyElementMixin(
           Polymer.Element))) {
diff --git a/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list.html b/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list.html
index 8d76510..1e57693 100644
--- a/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list.html
+++ b/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list.html
@@ -17,6 +17,7 @@
 
 <link rel="import" href="/bower_components/polymer/polymer.html">
 <link rel="import" href="/bower_components/paper-toggle-button/paper-toggle-button.html">
+<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
 <link rel="import" href="../../core/gr-reporting/gr-reporting.html">
 <link rel="import" href="../../shared/gr-button/gr-button.html">
 <link rel="import" href="../gr-message/gr-message.html">
@@ -84,6 +85,7 @@
         <gr-button
             id="collapse-messages"
             link
+            title="[[_expandCollapseTitle]]"
             on-click="_handleExpandCollapseTap">
           [[_computeExpandCollapseMessage(_expanded)]]
         </gr-button>
diff --git a/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list.js b/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list.js
index 20680b5..c637870 100644
--- a/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list.js
+++ b/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list.js
@@ -25,10 +25,15 @@
     SHOW_MORE: 'show-more-messages',
   };
 
-  /** @extends Polymer.Element */
-  class GrMessagesList extends Polymer.GestureEventListeners(
+  /**
+   * @appliesMixin Gerrit.KeyboardShortcutMixin
+   * @extends Polymer.Element
+   */
+  class GrMessagesList extends Polymer.mixinBehaviors( [
+    Gerrit.KeyboardShortcutBehavior,
+  ], Polymer.GestureEventListeners(
       Polymer.LegacyElementMixin(
-          Polymer.Element)) {
+          Polymer.Element))) {
     static get is() { return 'gr-messages-list'; }
 
     static get properties() {
@@ -55,6 +60,11 @@
           value: false,
           observer: '_expandedChanged',
         },
+
+        _expandCollapseTitle: {
+          type: String,
+        },
+
         _hideAutomated: {
           type: Boolean,
           value: false,
@@ -174,6 +184,14 @@
           this.notifyPath(`_visibleMessages.${i}.expanded`);
         }
       }
+
+      if (this._expanded) {
+        this._expandCollapseTitle = this.createTitle(
+            this.Shortcut.COLLAPSE_ALL_MESSAGES, this.ShortcutSection.ACTIONS);
+      } else {
+        this._expandCollapseTitle = this.createTitle(
+            this.Shortcut.EXPAND_ALL_MESSAGES, this.ShortcutSection.ACTIONS);
+      }
     }
 
     _highlightEl(el) {
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html
index 42fc4a6..6c20a6a 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html
@@ -240,14 +240,20 @@
             <span class="separator"></span>
           </span>
           <a class="navLink"
+              title="[[createTitle(Shortcut.PREV_FILE,
+                    ShortcutSection.NAVIGATION)]]"
               href$="[[_computeNavLinkURL(_change, _path, _fileList, -1, 1)]]">
             Prev</a>
           <span class="separator"></span>
           <a class="navLink"
+              title="[[createTitle(Shortcut.UP_TO_CHANGE,
+                ShortcutSection.NAVIGATION)]]"
               href$="[[_computeChangePath(_change, _patchRange.*, _change.revisions)]]">
             Up</a>
           <span class="separator"></span>
           <a class="navLink"
+              title="[[createTitle(Shortcut.NEXT_FILE,
+                ShortcutSection.NAVIGATION)]]"
               href$="[[_computeNavLinkURL(_change, _path, _fileList, 1, 1)]]">
             Next</a>
         </div>