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 * @unrestricted | 5 * @unrestricted |
6 */ | 6 */ |
7 UI.Tooltip = class { | 7 UI.Tooltip = class { |
8 /** | 8 /** |
9 * @param {!Document} doc | 9 * @param {!Document} doc |
10 */ | 10 */ |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // Reposition to ensure text doesn't overflow unnecessarily. | 106 // Reposition to ensure text doesn't overflow unnecessarily. |
107 this._tooltipElement.positionAt(0, 0); | 107 this._tooltipElement.positionAt(0, 0); |
108 | 108 |
109 // Show tooltip instantly if a tooltip was shown recently. | 109 // Show tooltip instantly if a tooltip was shown recently. |
110 var now = Date.now(); | 110 var now = Date.now(); |
111 var instant = (this._tooltipLastClosed && now - this._tooltipLastClosed < UI
.Tooltip.Timing.InstantThreshold); | 111 var instant = (this._tooltipLastClosed && now - this._tooltipLastClosed < UI
.Tooltip.Timing.InstantThreshold); |
112 this._tooltipElement.classList.toggle('instant', instant); | 112 this._tooltipElement.classList.toggle('instant', instant); |
113 this._tooltipLastOpened = instant ? now : now + UI.Tooltip.Timing.OpeningDel
ay; | 113 this._tooltipLastOpened = instant ? now : now + UI.Tooltip.Timing.OpeningDel
ay; |
114 | 114 |
115 // Get container element. | 115 // Get container element. |
116 var container = UI.Dialog.modalHostView().element; | 116 var container = UI.GlassPane.container(/** @type {!Document} */ (anchorEleme
nt.ownerDocument)); |
117 // Position tooltip based on the anchor element. | 117 // Position tooltip based on the anchor element. |
118 var containerBox = container.boxInWindow(this.element.window()); | 118 var containerBox = container.boxInWindow(this.element.window()); |
119 var anchorBox = this._anchorElement.boxInWindow(this.element.window()); | 119 var anchorBox = this._anchorElement.boxInWindow(this.element.window()); |
120 const anchorOffset = 2; | 120 const anchorOffset = 2; |
121 const pageMargin = 2; | 121 const pageMargin = 2; |
122 var cursorOffset = 10; | 122 var cursorOffset = 10; |
123 this._tooltipElement.classList.toggle('tooltip-breakword', !this._tooltipEle
ment.textContent.match('\\s')); | 123 this._tooltipElement.classList.toggle('tooltip-breakword', !this._tooltipEle
ment.textContent.match('\\s')); |
124 this._tooltipElement.style.maxWidth = (containerBox.width - pageMargin * 2)
+ 'px'; | 124 this._tooltipElement.style.maxWidth = (containerBox.width - pageMargin * 2)
+ 'px'; |
125 this._tooltipElement.style.maxHeight = ''; | 125 this._tooltipElement.style.maxHeight = ''; |
126 var tooltipWidth = this._tooltipElement.offsetWidth; | 126 var tooltipWidth = this._tooltipElement.offsetWidth; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 }, | 188 }, |
189 | 189 |
190 /** | 190 /** |
191 * @param {!Element|string} x | 191 * @param {!Element|string} x |
192 * @this {!Element} | 192 * @this {!Element} |
193 */ | 193 */ |
194 set: function(x) { | 194 set: function(x) { |
195 UI.Tooltip.install(this, x); | 195 UI.Tooltip.install(this, x); |
196 } | 196 } |
197 }); | 197 }); |
OLD | NEW |