| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 var instant = (this._tooltipLastClosed && now - this._tooltipLastClosed
< WebInspector.Tooltip.Timing.InstantThreshold); | 92 var instant = (this._tooltipLastClosed && now - this._tooltipLastClosed
< WebInspector.Tooltip.Timing.InstantThreshold); |
| 93 this._tooltipElement.classList.toggle("instant", instant); | 93 this._tooltipElement.classList.toggle("instant", instant); |
| 94 this._tooltipLastOpened = instant ? now : now + WebInspector.Tooltip.Tim
ing.OpeningDelay; | 94 this._tooltipLastOpened = instant ? now : now + WebInspector.Tooltip.Tim
ing.OpeningDelay; |
| 95 | 95 |
| 96 // Get container element. | 96 // Get container element. |
| 97 var container = WebInspector.Dialog.modalHostView().element; | 97 var container = WebInspector.Dialog.modalHostView().element; |
| 98 if (!anchorElement.isDescendant(container)) | 98 if (!anchorElement.isDescendant(container)) |
| 99 container = this.element.parentElement; | 99 container = this.element.parentElement; |
| 100 | 100 |
| 101 // Posititon tooltip based on the anchor element. | 101 // Posititon tooltip based on the anchor element. |
| 102 var containerOffset = container.offsetRelativeToWindow(this.element.wind
ow()); | 102 var containerBox = container.boxInWindow(this.element.window()); |
| 103 var containerOffsetWidth = container.offsetWidth; | |
| 104 var containerOffsetHeight = container.offsetHeight; | |
| 105 var anchorBox = this._anchorElement.boxInWindow(this.element.window()); | 103 var anchorBox = this._anchorElement.boxInWindow(this.element.window()); |
| 106 const anchorOffset = 2; | 104 const anchorOffset = 2; |
| 107 const pageMargin = 2; | 105 const pageMargin = 2; |
| 108 var cursorOffset = 10; | 106 var cursorOffset = 10; |
| 109 this._tooltipElement.classList.toggle("tooltip-breakword", !this._toolti
pElement.textContent.match("\\s")); | 107 this._tooltipElement.classList.toggle("tooltip-breakword", !this._toolti
pElement.textContent.match("\\s")); |
| 110 this._tooltipElement.style.maxWidth = (containerOffsetWidth - pageMargin
* 2) + "px"; | 108 this._tooltipElement.style.maxWidth = (containerBox.width - pageMargin *
2) + "px"; |
| 111 this._tooltipElement.style.maxHeight = ""; | 109 this._tooltipElement.style.maxHeight = ""; |
| 112 var tooltipWidth = this._tooltipElement.offsetWidth; | 110 var tooltipWidth = this._tooltipElement.offsetWidth; |
| 113 var tooltipHeight = this._tooltipElement.offsetHeight; | 111 var tooltipHeight = this._tooltipElement.offsetHeight; |
| 114 var anchorTooltipAtElement = this._anchorElement.nodeName === "BUTTON" |
| this._anchorElement.nodeName === "LABEL"; | 112 var anchorTooltipAtElement = this._anchorElement.nodeName === "BUTTON" |
| this._anchorElement.nodeName === "LABEL"; |
| 115 var tooltipX = anchorTooltipAtElement ? anchorBox.x : event.x + cursorOf
fset; | 113 var tooltipX = anchorTooltipAtElement ? anchorBox.x : event.x + cursorOf
fset; |
| 116 tooltipX = Number.constrain(tooltipX, | 114 tooltipX = Number.constrain(tooltipX, |
| 117 containerOffset.x + pageMargin, | 115 containerBox.x + pageMargin, |
| 118 containerOffset.x + containerOffsetWidth - tooltipWidth - pageMargin
); | 116 containerBox.x + containerBox.width - tooltipWidth - pageMargin); |
| 119 var tooltipY; | 117 var tooltipY; |
| 120 if (!anchorTooltipAtElement) { | 118 if (!anchorTooltipAtElement) { |
| 121 tooltipY = event.y + cursorOffset + tooltipHeight < containerOffset.
y + containerOffsetHeight ? event.y + cursorOffset : event.y - tooltipHeight; | 119 tooltipY = event.y + cursorOffset + tooltipHeight < containerBox.y +
containerBox.height ? event.y + cursorOffset : event.y - tooltipHeight; |
| 122 } else { | 120 } else { |
| 123 var onBottom = anchorBox.y + anchorOffset + anchorBox.height + toolt
ipHeight < containerOffset.y + containerOffsetHeight; | 121 var onBottom = anchorBox.y + anchorOffset + anchorBox.height + toolt
ipHeight < containerBox.y + containerBox.height; |
| 124 tooltipY = onBottom ? anchorBox.y + anchorBox.height + anchorOffset
: anchorBox.y - tooltipHeight - anchorOffset; | 122 tooltipY = onBottom ? anchorBox.y + anchorBox.height + anchorOffset
: anchorBox.y - tooltipHeight - anchorOffset; |
| 125 } | 123 } |
| 126 this._tooltipElement.positionAt(tooltipX, tooltipY); | 124 this._tooltipElement.positionAt(tooltipX, tooltipY); |
| 127 }, | 125 }, |
| 128 | 126 |
| 129 /** | 127 /** |
| 130 * @param {boolean} removeInstant | 128 * @param {boolean} removeInstant |
| 131 */ | 129 */ |
| 132 _hide: function(removeInstant) | 130 _hide: function(removeInstant) |
| 133 { | 131 { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 196 |
| 199 /** | 197 /** |
| 200 * @param {!Element|string} x | 198 * @param {!Element|string} x |
| 201 * @this {!Element} | 199 * @this {!Element} |
| 202 */ | 200 */ |
| 203 set: function(x) | 201 set: function(x) |
| 204 { | 202 { |
| 205 WebInspector.Tooltip.install(this, x); | 203 WebInspector.Tooltip.install(this, x); |
| 206 } | 204 } |
| 207 }); | 205 }); |
| OLD | NEW |