| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @param {!Document} doc | 7 * @param {!Document} doc |
| 8 */ | 8 */ |
| 9 WebInspector.Tooltip = function(doc) | 9 WebInspector.Tooltip = function(doc) |
| 10 { | 10 { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 _show: function(anchorElement) | 57 _show: function(anchorElement) |
| 58 { | 58 { |
| 59 var tooltip = anchorElement[WebInspector.Tooltip._symbol]; | 59 var tooltip = anchorElement[WebInspector.Tooltip._symbol]; |
| 60 this._anchorElement = anchorElement; | 60 this._anchorElement = anchorElement; |
| 61 this._tooltipElement.removeChildren(); | 61 this._tooltipElement.removeChildren(); |
| 62 if (typeof tooltip.content === "string") | 62 if (typeof tooltip.content === "string") |
| 63 this._tooltipElement.textContent = tooltip.content; | 63 this._tooltipElement.textContent = tooltip.content; |
| 64 else | 64 else |
| 65 this._tooltipElement.appendChild(tooltip.content); | 65 this._tooltipElement.appendChild(tooltip.content); |
| 66 | 66 |
| 67 if (tooltip.actionId) { | 67 if (tooltip.shortcuts || tooltip.actionId) { |
| 68 var shortcuts = WebInspector.shortcutRegistry.shortcutDescriptorsFor
Action(tooltip.actionId); | 68 var shortcuts = tooltip.shortcuts || WebInspector.shortcutRegistry.s
hortcutDescriptorsForAction(tooltip.actionId); |
| 69 if (shortcuts && shortcuts.length) { | 69 for (var shortcut of shortcuts) { |
| 70 var shortcutElement = this._tooltipElement.createChild("div", "t
ooltip-shortcut"); | 70 var shortcutElement = this._tooltipElement.createChild("div", "t
ooltip-shortcut"); |
| 71 shortcutElement.textContent = shortcuts[0].name; | 71 shortcutElement.textContent = shortcut.name; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 this._tooltipElement.classList.add("shown"); | 75 this._tooltipElement.classList.add("shown"); |
| 76 // Reposition to ensure text doesn't overflow unnecessarily. | 76 // Reposition to ensure text doesn't overflow unnecessarily. |
| 77 this._tooltipElement.positionAt(0, 0); | 77 this._tooltipElement.positionAt(0, 0); |
| 78 | 78 |
| 79 // Show tooltip instantly if a tooltip was shown recently. | 79 // Show tooltip instantly if a tooltip was shown recently. |
| 80 var now = Date.now(); | 80 var now = Date.now(); |
| 81 var instant = (this._tooltipLastClosed && now - this._tooltipLastClosed
< WebInspector.Tooltip.Timing.InstantThreshold); | 81 var instant = (this._tooltipLastClosed && now - this._tooltipLastClosed
< WebInspector.Tooltip.Timing.InstantThreshold); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 WebInspector.Tooltip.installHandler = function(doc) | 128 WebInspector.Tooltip.installHandler = function(doc) |
| 129 { | 129 { |
| 130 new WebInspector.Tooltip(doc); | 130 new WebInspector.Tooltip(doc); |
| 131 } | 131 } |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * @param {!Element} element | 134 * @param {!Element} element |
| 135 * @param {!Element|string} tooltipContent | 135 * @param {!Element|string} tooltipContent |
| 136 * @param {string=} alignment | 136 * @param {string=} alignment |
| 137 * @param {string=} actionId | 137 * @param {string=} actionId |
| 138 * @param {!Array.<!WebInspector.KeyboardShortcut.Descriptor>=} shortcuts |
| 138 */ | 139 */ |
| 139 WebInspector.Tooltip.install = function(element, tooltipContent, alignment, acti
onId) | 140 WebInspector.Tooltip.install = function(element, tooltipContent, alignment, acti
onId, shortcuts) |
| 140 { | 141 { |
| 141 if (Runtime.experiments.isEnabled("tooltips")) | 142 if (Runtime.experiments.isEnabled("tooltips")) |
| 142 element[WebInspector.Tooltip._symbol] = { content: tooltipContent, alig
nment: alignment, actionId: actionId }; | 143 element[WebInspector.Tooltip._symbol] = { content: tooltipContent, alig
nment: alignment, actionId: actionId, shortcuts: shortcuts }; |
| 143 else if (typeof tooltipContent === "string") | 144 else if (typeof tooltipContent === "string") |
| 144 element.title = tooltipContent; | 145 element.title = tooltipContent; |
| 145 else | 146 else |
| 146 console.assert("Cannot set an element without custom tooltips enabled"); | 147 console.assert("Cannot set an element without custom tooltips enabled"); |
| 147 } | 148 } |
| OLD | NEW |