OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 16 matching lines...) Expand all Loading... | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 /** | 31 /** |
32 * @unrestricted | 32 * @unrestricted |
33 */ | 33 */ |
34 UI.PopoverHelper = class { | 34 UI.PopoverHelper = class { |
35 /** | 35 /** |
36 * @param {!Element} container | 36 * @param {!Element} container |
37 * @param {function(!Event):?UI.PopoverRequest} getRequest | 37 * @param {function(!MouseEvent):?UI.PopoverRequest} getRequest |
38 */ | 38 */ |
39 constructor(container, getRequest) { | 39 constructor(container, getRequest) { |
40 this._disableOnClick = false; | 40 this._disableOnClick = false; |
41 this._hasPadding = false; | 41 this._hasPadding = false; |
42 this._getRequest = getRequest; | 42 this._getRequest = getRequest; |
43 this._scheduledRequest = null; | 43 this._scheduledRequest = null; |
44 /** @type {?function()} */ | 44 /** @type {?function()} */ |
45 this._hidePopoverCallback = null; | 45 this._hidePopoverCallback = null; |
46 container.addEventListener('mousedown', this._mouseDown.bind(this), false); | 46 container.addEventListener('mousedown', this._mouseDown.bind(this), false); |
47 container.addEventListener('mousemove', this._mouseMove.bind(this), false); | 47 container.addEventListener('mousemove', this._mouseMove.bind(this), false); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 _mouseDown(event) { | 86 _mouseDown(event) { |
87 if (this._disableOnClick) { | 87 if (this._disableOnClick) { |
88 this.hidePopover(); | 88 this.hidePopover(); |
89 return; | 89 return; |
90 } | 90 } |
91 if (this._eventInScheduledContent(event)) | 91 if (this._eventInScheduledContent(event)) |
92 return; | 92 return; |
93 | 93 |
94 this._startHidePopoverTimer(0); | 94 this._startHidePopoverTimer(0); |
95 this._stopShowPopoverTimer(); | 95 this._stopShowPopoverTimer(); |
96 this._startShowPopoverTimer(event, 0); | 96 this._startShowPopoverTimer(/** @type {!MouseEvent} */ (event), 0); |
97 } | 97 } |
98 | 98 |
99 /** | 99 /** |
100 * @param {!Event} event | 100 * @param {!Event} event |
101 */ | 101 */ |
102 _mouseMove(event) { | 102 _mouseMove(event) { |
103 // Pretend that nothing has happened. | 103 // Pretend that nothing has happened. |
104 if (this._eventInScheduledContent(event)) | 104 if (this._eventInScheduledContent(event)) |
105 return; | 105 return; |
106 | 106 |
107 this._startHidePopoverTimer(this._hideTimeout); | 107 this._startHidePopoverTimer(this._hideTimeout); |
108 this._stopShowPopoverTimer(); | 108 this._stopShowPopoverTimer(); |
109 if (event.which && this._disableOnClick) | 109 if (event.which && this._disableOnClick) |
110 return; | 110 return; |
111 this._startShowPopoverTimer(event, this.isPopoverVisible() ? this._showTimeo ut * 0.6 : this._showTimeout); | 111 this._startShowPopoverTimer( |
112 /** @type {!MouseEvent} */ (event), this.isPopoverVisible() ? this._show Timeout * 0.6 : this._showTimeout); | |
112 } | 113 } |
113 | 114 |
114 /** | 115 /** |
115 * @param {!Event} event | 116 * @param {!Event} event |
116 */ | 117 */ |
117 _popoverMouseMove(event) { | 118 _popoverMouseMove(event) { |
118 this._stopHidePopoverTimer(); | 119 this._stopHidePopoverTimer(); |
119 } | 120 } |
120 | 121 |
121 /** | 122 /** |
(...skipping 25 matching lines...) Expand all Loading... | |
147 if (!this._hidePopoverCallback || this._hidePopoverTimer) | 148 if (!this._hidePopoverCallback || this._hidePopoverTimer) |
148 return; | 149 return; |
149 | 150 |
150 this._hidePopoverTimer = setTimeout(() => { | 151 this._hidePopoverTimer = setTimeout(() => { |
151 this._hidePopover(); | 152 this._hidePopover(); |
152 delete this._hidePopoverTimer; | 153 delete this._hidePopoverTimer; |
153 }, timeout); | 154 }, timeout); |
154 } | 155 } |
155 | 156 |
156 /** | 157 /** |
157 * @param {!Event} event | 158 * @param {!MouseEvent} event |
dgozman
2017/04/26 16:04:58
Why MouseEvent? So far we used Event everywhere, a
pfeldman
2017/04/27 21:05:05
I'd like to pass typed event into the getRequest c
| |
158 * @param {number} timeout | 159 * @param {number} timeout |
159 */ | 160 */ |
160 _startShowPopoverTimer(event, timeout) { | 161 _startShowPopoverTimer(event, timeout) { |
161 this._scheduledRequest = this._getRequest.call(null, event); | 162 this._scheduledRequest = this._getRequest.call(null, event); |
162 if (!this._scheduledRequest) | 163 if (!this._scheduledRequest) |
163 return; | 164 return; |
164 | 165 |
165 this._showPopoverTimer = setTimeout(() => { | 166 this._showPopoverTimer = setTimeout(() => { |
166 delete this._showPopoverTimer; | 167 delete this._showPopoverTimer; |
167 this._stopHidePopoverTimer(); | 168 this._stopHidePopoverTimer(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 delete this._hidePopoverTimer; | 246 delete this._hidePopoverTimer; |
246 | 247 |
247 // We know that we reached the popup, but we might have moved over other ele ments. | 248 // We know that we reached the popup, but we might have moved over other ele ments. |
248 // Discard pending command. | 249 // Discard pending command. |
249 this._stopShowPopoverTimer(); | 250 this._stopShowPopoverTimer(); |
250 } | 251 } |
251 }; | 252 }; |
252 | 253 |
253 /** @typedef {{box: !AnchorBox, show:(function(!UI.GlassPane):!Promise<boolean>) , hide:(function()|undefined)}} */ | 254 /** @typedef {{box: !AnchorBox, show:(function(!UI.GlassPane):!Promise<boolean>) , hide:(function()|undefined)}} */ |
254 UI.PopoverRequest; | 255 UI.PopoverRequest; |
OLD | NEW |