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 { |
11 this.element = doc.body.createChild("div"); | 11 this.element = doc.body.createChild("div"); |
12 this._shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element)
; | 12 this._shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element)
; |
13 this._shadowRoot.appendChild(WebInspector.Widget.createStyleElement("ui/tool
tip.css")); | 13 this._shadowRoot.appendChild(WebInspector.Widget.createStyleElement("ui/tool
tip.css")); |
14 | 14 |
15 this._tooltipElement = this._shadowRoot.createChild("div", "tooltip"); | 15 this._tooltipElement = this._shadowRoot.createChild("div", "tooltip"); |
16 doc.addEventListener("mousemove", this._mouseMove.bind(this), true); | 16 doc.addEventListener("mousemove", this._mouseMove.bind(this), true); |
17 doc.addEventListener("mousedown", this._hide.bind(this), true); | 17 doc.addEventListener("mousedown", this._hide.bind(this, true), true); |
18 } | 18 } |
19 | 19 |
20 WebInspector.Tooltip.Timing = { | 20 WebInspector.Tooltip.Timing = { |
21 // Max time between tooltips showing that no opening delay is required. | 21 // Max time between tooltips showing that no opening delay is required. |
22 "InstantThreshold": 300, | 22 "InstantThreshold": 300, |
23 // Wait time before opening a tooltip. | 23 // Wait time before opening a tooltip. |
24 "OpeningDelay": 600 | 24 "OpeningDelay": 600 |
25 } | 25 } |
26 | 26 |
27 WebInspector.Tooltip.AlignmentOverride = { | 27 WebInspector.Tooltip.AlignmentOverride = { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 var tooltipHeight = this._tooltipElement.offsetHeight; | 99 var tooltipHeight = this._tooltipElement.offsetHeight; |
100 var tooltipX = anchorBox.x; | 100 var tooltipX = anchorBox.x; |
101 tooltipX = Number.constrain(tooltipX, | 101 tooltipX = Number.constrain(tooltipX, |
102 containerOffset.x + pageMargin, | 102 containerOffset.x + pageMargin, |
103 containerOffset.x + containerOffsetWidth - tooltipWidth - pageMargin
); | 103 containerOffset.x + containerOffsetWidth - tooltipWidth - pageMargin
); |
104 var onBottom = anchorBox.y + anchorOffset + anchorBox.height < container
Offset.y + containerOffsetHeight; | 104 var onBottom = anchorBox.y + anchorOffset + anchorBox.height < container
Offset.y + containerOffsetHeight; |
105 var tooltipY = onBottom ? anchorBox.y + anchorBox.height + anchorOffset
: anchorBox.y - tooltipHeight - anchorOffset; | 105 var tooltipY = onBottom ? anchorBox.y + anchorBox.height + anchorOffset
: anchorBox.y - tooltipHeight - anchorOffset; |
106 this._tooltipElement.positionAt(tooltipX, tooltipY); | 106 this._tooltipElement.positionAt(tooltipX, tooltipY); |
107 }, | 107 }, |
108 | 108 |
109 _hide: function() | 109 /** |
| 110 * @param {boolean=} removeInstant |
| 111 */ |
| 112 _hide: function(removeInstant) |
110 { | 113 { |
111 delete this._anchorElement; | 114 delete this._anchorElement; |
112 this._tooltipElement.classList.remove("shown"); | 115 this._tooltipElement.classList.remove("shown"); |
113 if (Date.now() > this._tooltipLastOpened) | 116 if (Date.now() > this._tooltipLastOpened) |
114 this._tooltipLastClosed = Date.now(); | 117 this._tooltipLastClosed = Date.now(); |
| 118 if (removeInstant) |
| 119 delete this._tooltipLastClosed; |
115 } | 120 } |
116 } | 121 } |
117 | 122 |
118 WebInspector.Tooltip._symbol = Symbol("Tooltip"); | 123 WebInspector.Tooltip._symbol = Symbol("Tooltip"); |
119 | 124 |
120 /** | 125 /** |
121 * @param {!Document} doc | 126 * @param {!Document} doc |
122 */ | 127 */ |
123 WebInspector.Tooltip.installHandler = function(doc) | 128 WebInspector.Tooltip.installHandler = function(doc) |
124 { | 129 { |
(...skipping 27 matching lines...) Expand all Loading... |
152 | 157 |
153 /** | 158 /** |
154 * @param {!Element|string} x | 159 * @param {!Element|string} x |
155 * @this {!Element} | 160 * @this {!Element} |
156 */ | 161 */ |
157 set: function(x) | 162 set: function(x) |
158 { | 163 { |
159 WebInspector.Tooltip.install(this, x); | 164 WebInspector.Tooltip.install(this, x); |
160 } | 165 } |
161 }); | 166 }); |
OLD | NEW |