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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 return this.element; | 72 return this.element; |
73 }, | 73 }, |
74 | 74 |
75 /** | 75 /** |
76 * @param {!Element} anchor | 76 * @param {!Element} anchor |
77 * @param {!WebInspector.Popover} popover | 77 * @param {!WebInspector.Popover} popover |
78 */ | 78 */ |
79 _showPopover: function(anchor, popover) | 79 _showPopover: function(anchor, popover) |
80 { | 80 { |
81 this._popover = popover; | 81 this._popover = popover; |
82 this._popoverContents = createElement("div"); | 82 this._buildPopoverContents().then(maybeShowPopover.bind(this)); |
83 if (!this._populatePopoverContents()) | 83 /** |
84 return; | 84 * @this {WebInspector.TimelineOverviewPane} |
85 var content = new WebInspector.TimelineOverviewPane.PopoverContents(); | 85 * @param {!DocumentFragment} fragment |
86 content.contentElement.appendChild(this._popoverContents); | 86 */ |
87 popover.showView(content, this._currentPositionElement); | 87 function maybeShowPopover(fragment) |
88 { | |
89 if (!fragment.firstChild) | |
90 return; | |
91 var content = new WebInspector.TimelineOverviewPane.PopoverContents( ); | |
92 this._popoverContents = content.contentElement.createChild("div"); | |
93 this._popoverContents.appendChild(fragment); | |
94 popover.showView(content, this._currentPositionElement); | |
95 } | |
88 }, | 96 }, |
89 | 97 |
90 _onHidePopover: function() | 98 _onHidePopover: function() |
91 { | 99 { |
92 this._popover = null; | 100 this._popover = null; |
93 this._popoverContents = null; | 101 this._popoverContents = null; |
94 }, | 102 }, |
95 | 103 |
96 /** | 104 /** |
97 * @param {!Event} event | 105 * @param {!Event} event |
98 */ | 106 */ |
99 _onMouseMove: function(event) | 107 _onMouseMove: function(event) |
100 { | 108 { |
101 if (!this._cursorEnabled) | 109 if (!this._cursorEnabled) |
102 return; | 110 return; |
103 var x = event.offsetX + event.target.offsetLeft; | 111 var x = event.offsetX + event.target.offsetLeft; |
104 this._currentPositionElement.style.left = x + "px"; | 112 this._currentPositionElement.style.left = x + "px"; |
105 this._currentPositionElement.style.visibility = "visible"; | 113 this._currentPositionElement.style.visibility = "visible"; |
106 if (!this._popover) | 114 if (!this._popover) |
107 return; | 115 return; |
108 this._populatePopoverContents(); | 116 this._buildPopoverContents().then(updatePopover.bind(this)); |
109 this._popover.positionElement(this._currentPositionElement); | 117 this._popover.positionElement(this._currentPositionElement); |
118 /** | |
119 * @this {WebInspector.TimelineOverviewPane} | |
120 * @param {!DocumentFragment} fragment | |
121 */ | |
122 function updatePopover(fragment) | |
123 { | |
124 if (!this._popoverContents) | |
125 return; | |
126 this._popoverContents.removeChildren(); | |
127 this._popoverContents.appendChild(fragment); | |
128 } | |
129 | |
110 }, | 130 }, |
111 | 131 |
112 _populatePopoverContents: function() | 132 /** |
133 * @return {!Promise<!DocumentFragment>} | |
134 */ | |
135 _buildPopoverContents: function() | |
113 { | 136 { |
114 var cursor = this._currentPositionElement; | 137 var cursor = this._currentPositionElement; |
115 var x = cursor.offsetLeft; | 138 var x = cursor.offsetLeft; |
116 var elements = []; | 139 var promises = []; |
117 for (var control of this._overviewControls) { | 140 for (var control of this._overviewControls) |
118 var element = control.popoverElement(x); | 141 promises.push(control.popoverElementPromise(x)) |
119 if (element) | 142 |
120 elements.push(element); | 143 return Promise.all(promises).then(buildFragment); |
144 | |
145 /** | |
146 * @param {!Array<?Element>} elements | |
147 */ | |
148 function buildFragment(elements) | |
149 { | |
150 var fragment = cursor.ownerDocument.createDocumentFragment(); | |
151 for (var element of elements) { | |
152 if (element) | |
153 fragment.appendChild(element); | |
154 } | |
155 return fragment; | |
121 } | 156 } |
122 this._popoverContents.removeChildren(); | |
123 if (!elements.length) | |
124 return false; | |
125 elements.forEach(this._popoverContents.appendChild.bind(this._popoverCon tents)); | |
126 return true; | |
127 }, | 157 }, |
128 | 158 |
129 _hideCurrentPosition: function() | 159 _hideCurrentPosition: function() |
130 { | 160 { |
131 this._currentPositionElement.style.visibility = "hidden"; | 161 this._currentPositionElement.style.visibility = "hidden"; |
132 }, | 162 }, |
133 | 163 |
134 /** | 164 /** |
135 * @override | 165 * @override |
136 */ | 166 */ |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 show: function(parentElement, insertBefore) { }, | 453 show: function(parentElement, insertBefore) { }, |
424 | 454 |
425 update: function() { }, | 455 update: function() { }, |
426 | 456 |
427 dispose: function() { }, | 457 dispose: function() { }, |
428 | 458 |
429 reset: function() { }, | 459 reset: function() { }, |
430 | 460 |
431 /** | 461 /** |
432 * @param {number} x | 462 * @param {number} x |
433 * @return {?Element} | 463 * @return {!Promise<?Element>} |
alph
2015/06/19 14:22:38
Looks like over complication.
Can it just return a
| |
434 */ | 464 */ |
435 popoverElement: function(x) { }, | 465 popoverElementPromise: function(x) { }, |
436 | 466 |
437 /** | 467 /** |
438 * @param {!Event} event | 468 * @param {!Event} event |
439 * @return {boolean} | 469 * @return {boolean} |
440 */ | 470 */ |
441 onClick: function(event) { }, | 471 onClick: function(event) { }, |
442 | 472 |
443 /** | 473 /** |
444 * @param {number} windowLeft | 474 * @param {number} windowLeft |
445 * @param {number} windowRight | 475 * @param {number} windowRight |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 /** | 523 /** |
494 * @override | 524 * @override |
495 */ | 525 */ |
496 reset: function() | 526 reset: function() |
497 { | 527 { |
498 }, | 528 }, |
499 | 529 |
500 /** | 530 /** |
501 * @override | 531 * @override |
502 * @param {number} x | 532 * @param {number} x |
503 * @return {?Element} | 533 * @return {!Promise<?Element>} |
504 */ | 534 */ |
505 popoverElement: function(x) | 535 popoverElementPromise: function(x) |
506 { | 536 { |
507 return null; | 537 return Promise.resolve(/** @type {?Element} */ (null)); |
508 }, | 538 }, |
509 | 539 |
510 /** | 540 /** |
511 * @override | 541 * @override |
512 */ | 542 */ |
513 timelineStarted: function() | 543 timelineStarted: function() |
514 { | 544 { |
515 }, | 545 }, |
516 | 546 |
517 /** | 547 /** |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 }, | 603 }, |
574 | 604 |
575 resetCanvas: function() | 605 resetCanvas: function() |
576 { | 606 { |
577 this._canvas.width = this.element.clientWidth * window.devicePixelRatio; | 607 this._canvas.width = this.element.clientWidth * window.devicePixelRatio; |
578 this._canvas.height = this.element.clientHeight * window.devicePixelRati o; | 608 this._canvas.height = this.element.clientHeight * window.devicePixelRati o; |
579 }, | 609 }, |
580 | 610 |
581 __proto__: WebInspector.VBox.prototype | 611 __proto__: WebInspector.VBox.prototype |
582 } | 612 } |
OLD | NEW |