| 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,
"ui/tooltip.css"); | 12 this._shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element,
"ui/tooltip.css"); |
| 13 | 13 |
| 14 this._tooltipElement = this._shadowRoot.createChild("div", "tooltip"); | 14 this._tooltipElement = this._shadowRoot.createChild("div", "tooltip"); |
| 15 doc.addEventListener("mousemove", this._mouseMove.bind(this), true); | 15 doc.addEventListener("mousemove", this._mouseMove.bind(this), true); |
| 16 doc.addEventListener("mousedown", this._hide.bind(this, true), true); | 16 doc.addEventListener("mousedown", this._hide.bind(this, true), true); |
| 17 doc.addEventListener("mouseleave", this._hide.bind(this, false), true); | 17 doc.addEventListener("mouseleave", this._hide.bind(this, false), true); |
| 18 doc.addEventListener("keydown", this._hide.bind(this, true), true); | 18 doc.addEventListener("keydown", this._hide.bind(this, true), true); |
| 19 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._reset, this); | 19 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._reset, this); |
| 20 doc.defaultView.addEventListener("resize", this._reset.bind(this), false); | 20 doc.defaultView.addEventListener("resize", this._reset.bind(this), false); |
| 21 } | 21 }; |
| 22 | 22 |
| 23 WebInspector.Tooltip.Timing = { | 23 WebInspector.Tooltip.Timing = { |
| 24 // Max time between tooltips showing that no opening delay is required. | 24 // Max time between tooltips showing that no opening delay is required. |
| 25 "InstantThreshold": 300, | 25 "InstantThreshold": 300, |
| 26 // Wait time before opening a tooltip. | 26 // Wait time before opening a tooltip. |
| 27 "OpeningDelay": 600 | 27 "OpeningDelay": 600 |
| 28 } | 28 }; |
| 29 | 29 |
| 30 WebInspector.Tooltip.prototype = { | 30 WebInspector.Tooltip.prototype = { |
| 31 /** | 31 /** |
| 32 * @param {!Event} event | 32 * @param {!Event} event |
| 33 */ | 33 */ |
| 34 _mouseMove: function(event) | 34 _mouseMove: function(event) |
| 35 { | 35 { |
| 36 var mouseEvent = /** @type {!MouseEvent} */ (event); | 36 var mouseEvent = /** @type {!MouseEvent} */ (event); |
| 37 var path = mouseEvent.path; | 37 var path = mouseEvent.path; |
| 38 if (!path || mouseEvent.buttons !== 0 || (mouseEvent.movementX === 0 &&
mouseEvent.movementY === 0)) | 38 if (!path || mouseEvent.buttons !== 0 || (mouseEvent.movementX === 0 &&
mouseEvent.movementY === 0)) |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 delete this._tooltipLastClosed; | 137 delete this._tooltipLastClosed; |
| 138 }, | 138 }, |
| 139 | 139 |
| 140 _reset: function() | 140 _reset: function() |
| 141 { | 141 { |
| 142 this._hide(true); | 142 this._hide(true); |
| 143 this._tooltipElement.positionAt(0, 0); | 143 this._tooltipElement.positionAt(0, 0); |
| 144 this._tooltipElement.style.maxWidth = "0"; | 144 this._tooltipElement.style.maxWidth = "0"; |
| 145 this._tooltipElement.style.maxHeight = "0"; | 145 this._tooltipElement.style.maxHeight = "0"; |
| 146 } | 146 } |
| 147 } | 147 }; |
| 148 | 148 |
| 149 WebInspector.Tooltip._symbol = Symbol("Tooltip"); | 149 WebInspector.Tooltip._symbol = Symbol("Tooltip"); |
| 150 | 150 |
| 151 /** | 151 /** |
| 152 * @param {!Document} doc | 152 * @param {!Document} doc |
| 153 */ | 153 */ |
| 154 WebInspector.Tooltip.installHandler = function(doc) | 154 WebInspector.Tooltip.installHandler = function(doc) |
| 155 { | 155 { |
| 156 new WebInspector.Tooltip(doc); | 156 new WebInspector.Tooltip(doc); |
| 157 } | 157 }; |
| 158 | 158 |
| 159 /** | 159 /** |
| 160 * @param {!Element} element | 160 * @param {!Element} element |
| 161 * @param {!Element|string} tooltipContent | 161 * @param {!Element|string} tooltipContent |
| 162 * @param {string=} actionId | 162 * @param {string=} actionId |
| 163 * @param {!Object=} options | 163 * @param {!Object=} options |
| 164 */ | 164 */ |
| 165 WebInspector.Tooltip.install = function(element, tooltipContent, actionId, optio
ns) | 165 WebInspector.Tooltip.install = function(element, tooltipContent, actionId, optio
ns) |
| 166 { | 166 { |
| 167 if (typeof tooltipContent === "string" && tooltipContent === "") { | 167 if (typeof tooltipContent === "string" && tooltipContent === "") { |
| 168 delete element[WebInspector.Tooltip._symbol]; | 168 delete element[WebInspector.Tooltip._symbol]; |
| 169 return; | 169 return; |
| 170 } | 170 } |
| 171 element[WebInspector.Tooltip._symbol] = { content: tooltipContent, actionId:
actionId, options: options || {} }; | 171 element[WebInspector.Tooltip._symbol] = { content: tooltipContent, actionId:
actionId, options: options || {} }; |
| 172 } | 172 }; |
| 173 | 173 |
| 174 /** | 174 /** |
| 175 * @param {!Element} element | 175 * @param {!Element} element |
| 176 */ | 176 */ |
| 177 WebInspector.Tooltip.addNativeOverrideContainer = function(element) | 177 WebInspector.Tooltip.addNativeOverrideContainer = function(element) |
| 178 { | 178 { |
| 179 WebInspector.Tooltip._nativeOverrideContainer.push(element); | 179 WebInspector.Tooltip._nativeOverrideContainer.push(element); |
| 180 } | 180 }; |
| 181 | 181 |
| 182 /** @type {!Array.<!Element>} */ | 182 /** @type {!Array.<!Element>} */ |
| 183 WebInspector.Tooltip._nativeOverrideContainer = []; | 183 WebInspector.Tooltip._nativeOverrideContainer = []; |
| 184 WebInspector.Tooltip._nativeTitle = /** @type {!ObjectPropertyDescriptor} */(Obj
ect.getOwnPropertyDescriptor(HTMLElement.prototype, "title")); | 184 WebInspector.Tooltip._nativeTitle = /** @type {!ObjectPropertyDescriptor} */(Obj
ect.getOwnPropertyDescriptor(HTMLElement.prototype, "title")); |
| 185 | 185 |
| 186 Object.defineProperty(HTMLElement.prototype, "title", { | 186 Object.defineProperty(HTMLElement.prototype, "title", { |
| 187 /** | 187 /** |
| 188 * @return {!Element|string} | 188 * @return {!Element|string} |
| 189 * @this {!Element} | 189 * @this {!Element} |
| 190 */ | 190 */ |
| 191 get: function() | 191 get: function() |
| 192 { | 192 { |
| 193 var tooltip = this[WebInspector.Tooltip._symbol]; | 193 var tooltip = this[WebInspector.Tooltip._symbol]; |
| 194 return tooltip ? tooltip.content : ""; | 194 return tooltip ? tooltip.content : ""; |
| 195 }, | 195 }, |
| 196 | 196 |
| 197 /** | 197 /** |
| 198 * @param {!Element|string} x | 198 * @param {!Element|string} x |
| 199 * @this {!Element} | 199 * @this {!Element} |
| 200 */ | 200 */ |
| 201 set: function(x) | 201 set: function(x) |
| 202 { | 202 { |
| 203 WebInspector.Tooltip.install(this, x); | 203 WebInspector.Tooltip.install(this, x); |
| 204 } | 204 } |
| 205 }); | 205 }); |
| OLD | NEW |