OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 * @param {symbol} eventType | 103 * @param {symbol} eventType |
104 * @param {function(!Common.Event)} listener | 104 * @param {function(!Common.Event)} listener |
105 * @param {!Object=} thisObject | 105 * @param {!Object=} thisObject |
106 * @return {!Common.EventTarget.EventDescriptor} | 106 * @return {!Common.EventTarget.EventDescriptor} |
107 */ | 107 */ |
108 addEventListener(eventType, listener, thisObject) { | 108 addEventListener(eventType, listener, thisObject) { |
109 return this._window.addEventListener(eventType, listener, thisObject); | 109 return this._window.addEventListener(eventType, listener, thisObject); |
110 } | 110 } |
111 | 111 |
112 /** | 112 /** |
113 * @param {?function(!Event):boolean} clickHandler | |
114 */ | |
115 setClickHandler(clickHandler) { | |
116 this._window.setClickHandler(clickHandler); | |
117 } | |
118 | |
119 /** | |
120 * @param {number} zoomFactor | 113 * @param {number} zoomFactor |
121 * @param {number} referencePoint | 114 * @param {number} referencePoint |
122 */ | 115 */ |
123 zoom(zoomFactor, referencePoint) { | 116 zoom(zoomFactor, referencePoint) { |
124 this._window._zoom(zoomFactor, referencePoint); | 117 this._window._zoom(zoomFactor, referencePoint); |
125 } | 118 } |
126 | 119 |
127 /** | 120 /** |
128 * @param {boolean} enabled | 121 * @param {boolean} enabled |
129 */ | 122 */ |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 178 } |
186 | 179 |
187 /** | 180 /** |
188 * @param {boolean} enabled | 181 * @param {boolean} enabled |
189 */ | 182 */ |
190 setEnabled(enabled) { | 183 setEnabled(enabled) { |
191 this._enabled = enabled; | 184 this._enabled = enabled; |
192 } | 185 } |
193 | 186 |
194 /** | 187 /** |
195 * @param {?function(!Event):boolean} clickHandler | |
196 */ | |
197 setClickHandler(clickHandler) { | |
198 this._clickHandler = clickHandler; | |
199 } | |
200 | |
201 /** | |
202 * @param {!Event} event | 188 * @param {!Event} event |
203 */ | 189 */ |
204 _resizerElementStartDragging(event) { | 190 _resizerElementStartDragging(event) { |
205 if (!this._enabled) | 191 if (!this._enabled) |
206 return false; | 192 return false; |
207 this._resizerParentOffsetLeft = event.pageX - event.offsetX - event.target.o
ffsetLeft; | 193 this._resizerParentOffsetLeft = event.pageX - event.offsetX - event.target.o
ffsetLeft; |
208 event.stopPropagation(); | 194 event.stopPropagation(); |
209 return true; | 195 return true; |
210 } | 196 } |
211 | 197 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 233 } |
248 | 234 |
249 /** | 235 /** |
250 * @param {!Event} event | 236 * @param {!Event} event |
251 */ | 237 */ |
252 _endWindowSelectorDragging(event) { | 238 _endWindowSelectorDragging(event) { |
253 var window = this._overviewWindowSelector._close(event.x - this._offsetLeft)
; | 239 var window = this._overviewWindowSelector._close(event.x - this._offsetLeft)
; |
254 delete this._overviewWindowSelector; | 240 delete this._overviewWindowSelector; |
255 var clickThreshold = 3; | 241 var clickThreshold = 3; |
256 if (window.end - window.start < clickThreshold) { | 242 if (window.end - window.start < clickThreshold) { |
257 if (this._clickHandler && this._clickHandler.call(null, event)) | 243 if (this.dispatchEventToListeners(UI.OverviewGrid.Events.Click, event)) |
258 return; | 244 return; |
259 var middle = window.end; | 245 var middle = window.end; |
260 window.start = Math.max(0, middle - UI.OverviewGrid.MinSelectableSize / 2)
; | 246 window.start = Math.max(0, middle - UI.OverviewGrid.MinSelectableSize / 2)
; |
261 window.end = Math.min(this._parentElement.clientWidth, middle + UI.Overvie
wGrid.MinSelectableSize / 2); | 247 window.end = Math.min(this._parentElement.clientWidth, middle + UI.Overvie
wGrid.MinSelectableSize / 2); |
262 } else if (window.end - window.start < UI.OverviewGrid.MinSelectableSize) { | 248 } else if (window.end - window.start < UI.OverviewGrid.MinSelectableSize) { |
263 if (this._parentElement.clientWidth - window.end > UI.OverviewGrid.MinSele
ctableSize) | 249 if (this._parentElement.clientWidth - window.end > UI.OverviewGrid.MinSele
ctableSize) |
264 window.end = window.start + UI.OverviewGrid.MinSelectableSize; | 250 window.end = window.start + UI.OverviewGrid.MinSelectableSize; |
265 else | 251 else |
266 window.start = window.end - UI.OverviewGrid.MinSelectableSize; | 252 window.start = window.end - UI.OverviewGrid.MinSelectableSize; |
267 } | 253 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 left = Number.constrain(left, 0, 1 - newWindowSize); | 398 left = Number.constrain(left, 0, 1 - newWindowSize); |
413 | 399 |
414 right = reference + (right - reference) * factor; | 400 right = reference + (right - reference) * factor; |
415 right = Number.constrain(right, newWindowSize, 1); | 401 right = Number.constrain(right, newWindowSize, 1); |
416 this._setWindow(left, right); | 402 this._setWindow(left, right); |
417 } | 403 } |
418 }; | 404 }; |
419 | 405 |
420 /** @enum {symbol} */ | 406 /** @enum {symbol} */ |
421 UI.OverviewGrid.Events = { | 407 UI.OverviewGrid.Events = { |
422 WindowChanged: Symbol('WindowChanged') | 408 WindowChanged: Symbol('WindowChanged'), |
| 409 Click: Symbol('Click') |
423 }; | 410 }; |
424 | 411 |
425 /** | 412 /** |
426 * @unrestricted | 413 * @unrestricted |
427 */ | 414 */ |
428 UI.OverviewGrid.WindowSelector = class { | 415 UI.OverviewGrid.WindowSelector = class { |
429 constructor(parent, position) { | 416 constructor(parent, position) { |
430 this._startPosition = position; | 417 this._startPosition = position; |
431 this._width = parent.offsetWidth; | 418 this._width = parent.offsetWidth; |
432 this._windowSelector = createElement('div'); | 419 this._windowSelector = createElement('div'); |
(...skipping 14 matching lines...) Expand all Loading... |
447 position = Math.max(0, Math.min(position, this._width)); | 434 position = Math.max(0, Math.min(position, this._width)); |
448 if (position < this._startPosition) { | 435 if (position < this._startPosition) { |
449 this._windowSelector.style.left = position + 'px'; | 436 this._windowSelector.style.left = position + 'px'; |
450 this._windowSelector.style.right = this._width - this._startPosition + 'px
'; | 437 this._windowSelector.style.right = this._width - this._startPosition + 'px
'; |
451 } else { | 438 } else { |
452 this._windowSelector.style.left = this._startPosition + 'px'; | 439 this._windowSelector.style.left = this._startPosition + 'px'; |
453 this._windowSelector.style.right = this._width - position + 'px'; | 440 this._windowSelector.style.right = this._width - position + 'px'; |
454 } | 441 } |
455 } | 442 } |
456 }; | 443 }; |
OLD | NEW |