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 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1205 var barX = this._timeToPositionClipped(entryStartTime); | 1205 var barX = this._timeToPositionClipped(entryStartTime); |
| 1206 var barRight = Math.min(this._timeToPositionClipped(entryStartTime + entryTotalTimes[entryIndex]), unclippedWidth) + 1; | 1206 var barRight = Math.min(this._timeToPositionClipped(entryStartTime + entryTotalTimes[entryIndex]), unclippedWidth) + 1; |
| 1207 var barWidth = barRight - barX; | 1207 var barWidth = barRight - barX; |
| 1208 var barLevel = entryLevels[entryIndex]; | 1208 var barLevel = entryLevels[entryIndex]; |
| 1209 var barY = this._levelToHeight(barLevel); | 1209 var barY = this._levelToHeight(barLevel); |
| 1210 var text = this._dataProvider.entryTitle(entryIndex); | 1210 var text = this._dataProvider.entryTitle(entryIndex); |
| 1211 if (text && text.length) { | 1211 if (text && text.length) { |
| 1212 context.font = this._dataProvider.entryFont(entryIndex); | 1212 context.font = this._dataProvider.entryFont(entryIndex); |
| 1213 text = this._prepareText(context, text, barWidth - 2 * textPaddi ng); | 1213 text = this._prepareText(context, text, barWidth - 2 * textPaddi ng); |
| 1214 } | 1214 } |
| 1215 | |
| 1216 if (this._dataProvider.decorateEntry(entryIndex, context, text, barX , barY, barWidth, barHeight)) | 1215 if (this._dataProvider.decorateEntry(entryIndex, context, text, barX , barY, barWidth, barHeight)) |
| 1217 continue; | 1216 continue; |
| 1218 if (!text || !text.length) | 1217 if (!text || !text.length) |
| 1219 continue; | 1218 continue; |
| 1220 | 1219 |
| 1221 context.fillStyle = this._dataProvider.textColor(entryIndex); | 1220 context.fillStyle = this._dataProvider.textColor(entryIndex); |
| 1222 context.fillText(text, barX + textPadding, textBaseHeight - barLevel * this._barHeightDelta); | 1221 context.fillText(text, barX + textPadding, textBaseHeight - barLevel * this._barHeightDelta); |
| 1223 } | 1222 } |
| 1224 | 1223 |
| 1225 this._drawFlowEvents(context, width, height); | 1224 this._drawFlowEvents(context, width, height); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1440 if (typeof entry.value === "string") | 1439 if (typeof entry.value === "string") |
| 1441 row.createChild("td").textContent = entry.value; | 1440 row.createChild("td").textContent = entry.value; |
| 1442 else | 1441 else |
| 1443 row.createChild("td").appendChild(entry.value); | 1442 row.createChild("td").appendChild(entry.value); |
| 1444 } | 1443 } |
| 1445 return infoTable; | 1444 return infoTable; |
| 1446 }, | 1445 }, |
| 1447 | 1446 |
| 1448 /** | 1447 /** |
| 1449 * @param {!CanvasRenderingContext2D} context | 1448 * @param {!CanvasRenderingContext2D} context |
| 1450 * @param {string} title | 1449 * @param {string} text |
| 1451 * @param {number} maxSize | 1450 * @param {number} maxWidth |
| 1452 * @return {string} | 1451 * @return {string} |
| 1453 */ | 1452 */ |
| 1454 _prepareText: function(context, title, maxSize) | 1453 _prepareText: function(context, text, maxWidth) |
| 1455 { | 1454 { |
| 1456 var titleWidth = this._measureWidth(context, title); | 1455 var /** @const */ maxLength = 200; |
| 1457 if (maxSize >= titleWidth) | 1456 if (maxWidth <= 10) |
| 1458 return title; | 1457 return ""; |
| 1458 if (text.length > maxLength) | |
| 1459 text = text.trimMiddle(maxLength); | |
| 1460 var textWidth = this._measureWidth(context, text); | |
| 1461 if (textWidth <= maxWidth) | |
| 1462 return text; | |
| 1459 | 1463 |
| 1460 var l = 2; | 1464 var l = 0; |
| 1461 var r = title.length; | 1465 var r = text.length; |
| 1462 while (l < r) { | 1466 var lv = 0; |
| 1463 var m = (l + r) >> 1; | 1467 var rv = textWidth; |
| 1464 if (this._measureWidth(context, title.trimMiddle(m)) <= maxSize) | 1468 while (l < r && rv !== lv) { |
| 1465 l = m + 1; | 1469 var m = Math.ceil(l + (r - l) * (maxWidth - lv) / (rv - lv)); |
|
caseq
2015/12/02 22:31:53
I'm a bit concerned with what happens when maxWidt
alph
2015/12/02 23:35:37
Thanks. Fixed.
| |
| 1466 else | 1470 var mv = this._measureWidth(context, text.trimMiddle(m)); |
| 1467 r = m; | 1471 if (mv <= maxWidth) { |
| 1472 l = m; | |
| 1473 lv = mv; | |
| 1474 } else { | |
| 1475 r = m - 1; | |
| 1476 rv = mv; | |
| 1477 } | |
| 1468 } | 1478 } |
| 1469 title = title.trimMiddle(r - 1); | 1479 text = text.trimMiddle(l); |
| 1470 return title !== "\u2026" ? title : ""; | 1480 return text !== "\u2026" ? text : ""; |
| 1471 }, | 1481 }, |
| 1472 | 1482 |
| 1473 /** | 1483 /** |
| 1474 * @param {!CanvasRenderingContext2D} context | 1484 * @param {!CanvasRenderingContext2D} context |
| 1475 * @param {string} text | 1485 * @param {string} text |
| 1476 * @return {number} | 1486 * @return {number} |
| 1477 */ | 1487 */ |
| 1478 _measureWidth: function(context, text) | 1488 _measureWidth: function(context, text) |
| 1479 { | 1489 { |
| 1480 if (text.length > 20) | 1490 if (text.length > 200) |
| 1481 return context.measureText(text).width; | 1491 return context.measureText(text).width; |
| 1482 | 1492 |
| 1483 var font = context.font; | 1493 var font = context.font; |
| 1484 var textWidths = this._textWidth[font]; | 1494 var textWidths = this._textWidth[font]; |
| 1485 if (!textWidths) { | 1495 if (!textWidths) { |
| 1486 textWidths = {}; | 1496 textWidths = {}; |
| 1487 this._textWidth[font] = textWidths; | 1497 this._textWidth[font] = textWidths; |
| 1488 } | 1498 } |
| 1489 var width = textWidths[text]; | 1499 var width = textWidths[text]; |
| 1490 if (!width) { | 1500 if (!width) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1584 this.update(); | 1594 this.update(); |
| 1585 }, | 1595 }, |
| 1586 | 1596 |
| 1587 _enabled: function() | 1597 _enabled: function() |
| 1588 { | 1598 { |
| 1589 return this._rawTimelineDataLength !== 0; | 1599 return this._rawTimelineDataLength !== 0; |
| 1590 }, | 1600 }, |
| 1591 | 1601 |
| 1592 __proto__: WebInspector.HBox.prototype | 1602 __proto__: WebInspector.HBox.prototype |
| 1593 } | 1603 } |
| OLD | NEW |