Chromium Code Reviews| 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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 | 467 |
| 468 onResize: function() | 468 onResize: function() |
| 469 { | 469 { |
| 470 this._scheduleUpdate(); | 470 this._scheduleUpdate(); |
| 471 }, | 471 }, |
| 472 | 472 |
| 473 _scheduleUpdate: function() | 473 _scheduleUpdate: function() |
| 474 { | 474 { |
| 475 if (this._updateTimerId) | 475 if (this._updateTimerId) |
| 476 return; | 476 return; |
| 477 this._updateTimerId = setTimeout(this.update.bind(this), 10); | 477 this._updateTimerId = requestAnimationFrame(this.update.bind(this)); |
| 478 }, | 478 }, |
| 479 | 479 |
| 480 update: function() | 480 update: function() |
| 481 { | 481 { |
| 482 this._updateTimerId = 0; | 482 this._updateTimerId = 0; |
| 483 var timelineData = this._timelineData(); | 483 var timelineData = this._timelineData(); |
| 484 if (!timelineData) | 484 if (!timelineData) |
| 485 return; | 485 return; |
| 486 this._resetCanvas(this._overviewContainer.clientWidth, this._overviewCon tainer.clientHeight - WebInspector.FlameChart.DividersBarHeight); | 486 this._resetCanvas(this._overviewContainer.clientWidth, this._overviewCon tainer.clientHeight - WebInspector.FlameChart.DividersBarHeight); |
| 487 this._overviewCalculator._updateBoundaries(this); | 487 this._overviewCalculator._updateBoundaries(this); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 this._windowRight = 1.0; | 606 this._windowRight = 1.0; |
| 607 this._windowWidth = 1.0; | 607 this._windowWidth = 1.0; |
| 608 this._timeWindowLeft = 0; | 608 this._timeWindowLeft = 0; |
| 609 this._timeWindowRight = Infinity; | 609 this._timeWindowRight = Infinity; |
| 610 this._barHeight = dataProvider.barHeight(); | 610 this._barHeight = dataProvider.barHeight(); |
| 611 this._barHeightDelta = this._isTopDown ? -this._barHeight : this._barHeight; | 611 this._barHeightDelta = this._isTopDown ? -this._barHeight : this._barHeight; |
| 612 this._minWidth = 1; | 612 this._minWidth = 1; |
| 613 this._paddingLeft = 15; | 613 this._paddingLeft = 15; |
| 614 this._highlightedEntryIndex = -1; | 614 this._highlightedEntryIndex = -1; |
| 615 this._selectedEntryIndex = -1; | 615 this._selectedEntryIndex = -1; |
| 616 this._textWidth = {}; | |
| 616 } | 617 } |
| 617 | 618 |
| 618 WebInspector.FlameChart.MainPane.prototype = { | 619 WebInspector.FlameChart.MainPane.prototype = { |
| 619 /** | 620 /** |
| 620 * @return {?WebInspector.FlameChart.TimelineData} | 621 * @return {?WebInspector.FlameChart.TimelineData} |
| 621 */ | 622 */ |
| 622 _timelineData: function() | 623 _timelineData: function() |
| 623 { | 624 { |
| 624 return this._dataProvider.timelineData(); | 625 return this._dataProvider.timelineData(); |
| 625 }, | 626 }, |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 var timeToPixel = this._timeToPixel; | 818 var timeToPixel = this._timeToPixel; |
| 818 var pixelWindowLeft = this._pixelWindowLeft; | 819 var pixelWindowLeft = this._pixelWindowLeft; |
| 819 var paddingLeft = this._paddingLeft; | 820 var paddingLeft = this._paddingLeft; |
| 820 var minWidth = this._minWidth; | 821 var minWidth = this._minWidth; |
| 821 var entryTotalTimes = timelineData.entryTotalTimes; | 822 var entryTotalTimes = timelineData.entryTotalTimes; |
| 822 var entryOffsets = timelineData.entryOffsets; | 823 var entryOffsets = timelineData.entryOffsets; |
| 823 var entryLevels = timelineData.entryLevels; | 824 var entryLevels = timelineData.entryLevels; |
| 824 | 825 |
| 825 var titleIndexes = new Uint32Array(timelineData.entryTotalTimes); | 826 var titleIndexes = new Uint32Array(timelineData.entryTotalTimes); |
| 826 var lastTitleIndex = 0; | 827 var lastTitleIndex = 0; |
| 827 var dotsWidth = context.measureText("\u2026").width; | |
| 828 var textPadding = this._dataProvider.textPadding(); | 828 var textPadding = this._dataProvider.textPadding(); |
| 829 this._minTextWidth = context.measureText("\u2026").width + 2 * textPaddi ng; | 829 var dotsWidth = this._measureWidth(context, "\u2026"); |
|
loislo
2014/03/06 06:04:51
lets also assign it to this._dotWidth
pfeldman
2014/03/06 11:19:57
I removed this._dotsWidth instead.
| |
| 830 this._minTextWidth = 2 * textPadding + dotsWidth; | |
| 830 var minTextWidth = this._minTextWidth; | 831 var minTextWidth = this._minTextWidth; |
| 831 | 832 |
| 832 var lastDrawOffset = new Int32Array(this._dataProvider.maxStackDepth()); | 833 var lastDrawOffset = new Int32Array(this._dataProvider.maxStackDepth()); |
| 833 for (var i = 0; i < lastDrawOffset.length; ++i) | 834 for (var i = 0; i < lastDrawOffset.length; ++i) |
| 834 lastDrawOffset[i] = -1; | 835 lastDrawOffset[i] = -1; |
| 835 | 836 |
| 836 var barX = 0; | 837 var barX = 0; |
| 837 var barY = 0; | 838 var barY = 0; |
| 838 var barWidth = 0; | 839 var barWidth = 0; |
| 839 var barRight = 0; | 840 var barRight = 0; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 912 barLevel = entryLevels[entryIndex]; | 913 barLevel = entryLevels[entryIndex]; |
| 913 barY = this._levelToHeight(barLevel); | 914 barY = this._levelToHeight(barLevel); |
| 914 context.rect(barX, barY, barWidth, this._barHeight); | 915 context.rect(barX, barY, barWidth, this._barHeight); |
| 915 if (barWidth > minTextWidth) | 916 if (barWidth > minTextWidth) |
| 916 titleIndexes[lastTitleIndex++] = entryIndex; | 917 titleIndexes[lastTitleIndex++] = entryIndex; |
| 917 } | 918 } |
| 918 context.fill(); | 919 context.fill(); |
| 919 } | 920 } |
| 920 | 921 |
| 921 context.textBaseline = "alphabetic"; | 922 context.textBaseline = "alphabetic"; |
| 922 context.fillStyle = "#333"; | 923 this._dotsWidth = this._measureWidth(context, "\u2026"); |
|
loislo
2014/03/06 06:04:51
looks like we don't need this line.
alph
2014/03/06 06:24:46
Could that be done in the constructor?
pfeldman
2014/03/06 11:19:57
Same here, removed
pfeldman
2014/03/06 11:19:57
It might depend on the styles, though I am not sur
| |
| 923 this._dotsWidth = context.measureText("\u2026").width; | |
| 924 | 924 |
| 925 for (i = 0; i < lastTitleIndex; ++i) { | 925 for (i = 0; i < lastTitleIndex; ++i) { |
| 926 entryIndex = titleIndexes[i]; | 926 entryIndex = titleIndexes[i]; |
| 927 text = this._dataProvider.entryTitle(entryIndex); | 927 text = this._dataProvider.entryTitle(entryIndex); |
| 928 if (!text || !text.length) | 928 if (!text || !text.length) |
| 929 continue; | 929 continue; |
| 930 font = this._dataProvider.entryFont(entryIndex); | 930 font = this._dataProvider.entryFont(entryIndex); |
| 931 entryOffset = entryOffsets[entryIndex]; | 931 entryOffset = entryOffsets[entryIndex]; |
| 932 barX = this._offsetToPosition(entryOffset); | 932 barX = this._offsetToPosition(entryOffset); |
| 933 barRight = this._offsetToPosition(entryOffset + entryTotalTimes[entr yIndex]); | 933 barRight = this._offsetToPosition(entryOffset + entryTotalTimes[entr yIndex]); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 titleCell.textContent = entryInfo[i].title; | 998 titleCell.textContent = entryInfo[i].title; |
| 999 titleCell.className = "title"; | 999 titleCell.className = "title"; |
| 1000 var textCell = row.createChild("td"); | 1000 var textCell = row.createChild("td"); |
| 1001 textCell.textContent = entryInfo[i].text; | 1001 textCell.textContent = entryInfo[i].text; |
| 1002 } | 1002 } |
| 1003 return infoTable; | 1003 return infoTable; |
| 1004 }, | 1004 }, |
| 1005 | 1005 |
| 1006 _prepareText: function(context, title, maxSize) | 1006 _prepareText: function(context, title, maxSize) |
| 1007 { | 1007 { |
| 1008 if (maxSize < this._dotsWidth) | 1008 var titleWidth = this._measureWidth(context, title); |
| 1009 return null; | |
| 1010 var titleWidth = context.measureText(title).width; | |
| 1011 if (maxSize > titleWidth) | 1009 if (maxSize > titleWidth) |
| 1012 return title; | 1010 return title; |
| 1013 maxSize -= this._dotsWidth; | 1011 maxSize -= this._dotsWidth; |
| 1014 var dotRegExp=/[\.\$]/g; | 1012 var dotRegExp=/[\.\$]/g; |
| 1015 var match = dotRegExp.exec(title); | 1013 var match = dotRegExp.exec(title); |
| 1016 if (!match) { | 1014 if (!match) { |
| 1017 var visiblePartSize = maxSize / titleWidth; | 1015 var visiblePartSize = maxSize / titleWidth; |
| 1018 var newTextLength = Math.floor(title.length * visiblePartSize) + 1; | 1016 var newTextLength = Math.floor(title.length * visiblePartSize) + 1; |
| 1019 var minTextLength = 4; | 1017 var minTextLength = 2; |
| 1020 if (newTextLength < minTextLength) | 1018 if (newTextLength < minTextLength) |
| 1021 return null; | 1019 return null; |
| 1022 var substring; | 1020 var substring; |
| 1023 do { | 1021 do { |
| 1024 --newTextLength; | 1022 --newTextLength; |
| 1025 substring = title.substring(0, newTextLength); | 1023 substring = title.substring(0, newTextLength); |
| 1026 } while (context.measureText(substring).width > maxSize); | 1024 } while (this._measureWidth(context, substring).width > maxSize); |
| 1027 return title.substring(0, newTextLength) + "\u2026"; | 1025 return title.substring(0, newTextLength) + "\u2026"; |
| 1028 } | 1026 } |
| 1029 while (match) { | 1027 while (match) { |
| 1030 var substring = title.substring(match.index + 1); | 1028 var substring = title.substring(match.index + 1); |
| 1031 var width = context.measureText(substring).width; | 1029 var width = this._measureWidth(context, substring).width; |
| 1032 if (maxSize > width) | 1030 if (maxSize > width) |
| 1033 return "\u2026" + substring; | 1031 return "\u2026" + substring; |
| 1034 match = dotRegExp.exec(title); | 1032 match = dotRegExp.exec(title); |
| 1035 } | 1033 } |
| 1036 var i = 0; | 1034 var i = 0; |
| 1037 do { | 1035 do { |
| 1038 ++i; | 1036 ++i; |
| 1039 } while (context.measureText(title.substring(0, i)).width < maxSize); | 1037 } while (this._measureWidth(context, title.substring(0, i)).width < maxS ize); |
| 1040 return title.substring(0, i - 1) + "\u2026"; | 1038 return title.substring(0, i - 1) + "\u2026"; |
| 1041 }, | 1039 }, |
| 1042 | 1040 |
| 1041 /** | |
| 1042 * @param {Context} context | |
|
alph
2014/03/06 06:24:46
!Context
pfeldman
2014/03/06 11:19:57
Done.
| |
| 1043 * @param {string} text | |
| 1044 * @return {number} | |
| 1045 */ | |
| 1046 _measureWidth: function(context, text) | |
| 1047 { | |
| 1048 if (text.length > 20) | |
|
alph
2014/03/06 06:24:46
I'm wondering does it really help the performance?
pfeldman
2014/03/06 11:19:57
It prevents from forcing layout.
alph
2014/03/06 11:23:27
I was asking about that 'if' statement, not about
| |
| 1049 return context.measureText(text).width; | |
| 1050 | |
| 1051 var width = this._textWidth[text]; | |
| 1052 if (!width) { | |
| 1053 width = context.measureText(text).width; | |
| 1054 this._textWidth[text] = width; | |
| 1055 } | |
| 1056 return width; | |
| 1057 }, | |
| 1058 | |
| 1043 _updateBoundaries: function() | 1059 _updateBoundaries: function() |
| 1044 { | 1060 { |
| 1045 this._totalTime = this._dataProvider.totalTime(); | 1061 this._totalTime = this._dataProvider.totalTime(); |
| 1046 this._zeroTime = this._dataProvider.zeroTime(); | 1062 this._zeroTime = this._dataProvider.zeroTime(); |
| 1047 if (this._timeBasedWindow) { | 1063 if (this._timeBasedWindow) { |
| 1048 if (this._timeWindowRight !== Infinity) { | 1064 if (this._timeWindowRight !== Infinity) { |
| 1049 this._windowLeft = (this._timeWindowLeft - this._zeroTime) / thi s._totalTime; | 1065 this._windowLeft = (this._timeWindowLeft - this._zeroTime) / thi s._totalTime; |
| 1050 this._windowRight = (this._timeWindowRight - this._zeroTime) / t his._totalTime; | 1066 this._windowRight = (this._timeWindowRight - this._zeroTime) / t his._totalTime; |
| 1051 this._windowWidth = this._windowRight - this._windowLeft; | 1067 this._windowWidth = this._windowRight - this._windowLeft; |
| 1052 } else { | 1068 } else { |
| 1053 this._windowLeft = 0; | 1069 this._windowLeft = 0; |
| 1054 this._windowRight = 1; | 1070 this._windowRight = 1; |
| 1055 this._windowWidth = 1; | 1071 this._windowWidth = 1; |
| 1056 } | 1072 } |
| 1057 } else { | 1073 } else { |
| 1058 this._timeWindowLeft = this._windowLeft * this._totalTime; | 1074 this._timeWindowLeft = this._windowLeft * this._totalTime; |
| 1059 this._timeWindowRight = this._windowRight * this._totalTime; | 1075 this._timeWindowRight = this._windowRight * this._totalTime; |
| 1060 } | 1076 } |
| 1061 | 1077 |
| 1062 this._pixelWindowWidth = this.element.clientWidth - this._paddingLeft; | 1078 this._pixelWindowWidth = this._offsetWidth - this._paddingLeft; |
| 1063 this._totalPixels = Math.floor(this._pixelWindowWidth / this._windowWidt h); | 1079 this._totalPixels = Math.floor(this._pixelWindowWidth / this._windowWidt h); |
| 1064 this._pixelWindowLeft = Math.floor(this._totalPixels * this._windowLeft) ; | 1080 this._pixelWindowLeft = Math.floor(this._totalPixels * this._windowLeft) ; |
| 1065 this._pixelWindowRight = Math.floor(this._totalPixels * this._windowRigh t); | 1081 this._pixelWindowRight = Math.floor(this._totalPixels * this._windowRigh t); |
| 1066 | 1082 |
| 1067 this._timeToPixel = this._totalPixels / this._totalTime; | 1083 this._timeToPixel = this._totalPixels / this._totalTime; |
| 1068 this._pixelToTime = this._totalTime / this._totalPixels; | 1084 this._pixelToTime = this._totalTime / this._totalPixels; |
| 1069 this._paddingLeftTime = this._paddingLeft / this._timeToPixel; | 1085 this._paddingLeftTime = this._paddingLeft / this._timeToPixel; |
| 1070 }, | 1086 }, |
| 1071 | 1087 |
| 1072 onResize: function() | 1088 onResize: function() |
| 1073 { | 1089 { |
| 1090 this._offsetWidth = this.element.offsetWidth; | |
| 1091 this._offsetHeight = this.element.offsetHeight; | |
| 1074 this._scheduleUpdate(); | 1092 this._scheduleUpdate(); |
| 1075 }, | 1093 }, |
| 1076 | 1094 |
| 1077 _scheduleUpdate: function() | 1095 _scheduleUpdate: function() |
| 1078 { | 1096 { |
| 1079 if (this._updateTimerId) | 1097 if (this._updateTimerId) |
| 1080 return; | 1098 return; |
| 1081 this._updateTimerId = setTimeout(this.update.bind(this), 10); | 1099 this._updateTimerId = requestAnimationFrame(this.update.bind(this)); |
| 1082 }, | 1100 }, |
| 1083 | 1101 |
| 1084 update: function() | 1102 update: function() |
| 1085 { | 1103 { |
| 1086 this._updateTimerId = 0; | 1104 this._updateTimerId = 0; |
| 1087 if (!this._timelineData()) { | 1105 if (!this._timelineData()) { |
| 1088 this._timelineGrid.hideDividers(); | 1106 this._timelineGrid.hideDividers(); |
| 1089 return; | 1107 return; |
| 1090 } | 1108 } |
| 1091 this._updateBoundaries(); | 1109 this._updateBoundaries(); |
| 1092 if (this._timelineData().entryLevels.length) | 1110 if (this._timelineData().entryLevels.length) |
| 1093 this._timelineGrid.showDividers(); | 1111 this._timelineGrid.showDividers(); |
| 1094 else | 1112 else |
| 1095 this._timelineGrid.hideDividers(); | 1113 this._timelineGrid.hideDividers(); |
| 1096 this.draw(this.element.clientWidth, this.element.clientHeight); | 1114 this.draw(this._offsetWidth, this._offsetHeight); |
| 1097 this._calculator._updateBoundaries(this); | 1115 this._calculator._updateBoundaries(this); |
| 1098 this._timelineGrid.element.style.width = this.element.clientWidth; | 1116 this._timelineGrid.element.style.width = this._offsetWidth; |
| 1099 var offsets = this._dataProvider.dividerOffsets(this._calculator.minimum Boundary(), this._calculator.maximumBoundary()); | 1117 var offsets = this._dataProvider.dividerOffsets(this._calculator.minimum Boundary(), this._calculator.maximumBoundary()); |
| 1100 this._timelineGrid.updateDividers(this._calculator, offsets, true); | 1118 this._timelineGrid.updateDividers(this._calculator, offsets, true); |
| 1101 }, | 1119 }, |
| 1102 | 1120 |
| 1103 reset: function() | 1121 reset: function() |
| 1104 { | 1122 { |
| 1105 this._highlightedEntryIndex = -1; | 1123 this._highlightedEntryIndex = -1; |
| 1106 this._selectedEntryIndex = -1; | 1124 this._selectedEntryIndex = -1; |
| 1125 this._textWidth = {}; | |
| 1107 this.update(); | 1126 this.update(); |
| 1108 }, | 1127 }, |
| 1109 | 1128 |
| 1110 __proto__: WebInspector.View.prototype | 1129 __proto__: WebInspector.View.prototype |
| 1111 } | 1130 } |
| OLD | NEW |