Changeset 199635 in webkit
- Timestamp:
- Apr 16, 2016 6:26:07 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r199613 r199635 1 2016-04-16 Matt Baker <mattbaker@apple.com> 2 3 Web Inspector: Adopt Number.prototype.toLocaleString For All Sizes and Times 4 https://bugs.webkit.org/show_bug.cgi?id=152033 5 <rdar://problem/23815589> 6 7 Reviewed by Timothy Hatcher. 8 9 Add test coverage for string formatters, and additional test cases for 10 Number.percentageString and Number.secondsToString. 11 12 * inspector/unit-tests/number-utilities-expected.txt: 13 * inspector/unit-tests/number-utilities.html: 14 * inspector/unit-tests/string-utilities-expected.txt: Added. 15 * inspector/unit-tests/string-utilities.html: Added. 16 1 17 2016-04-15 Myles C. Maxfield <mmaxfield@apple.com> 2 18 -
trunk/LayoutTests/inspector/unit-tests/number-utilities-expected.txt
r196284 r199635 15 15 16 16 -- Running test case: Number.secondsToString 17 PASS: normal resolution of 0ms should be ms with no decimals 17 18 PASS: normal resolution of sub 1ms should be ms 18 19 PASS: normal resolution of sub 10ms should be ms … … 26 27 PASS: normal resolution of greater than 1 day should be days 27 28 PASS: normal resolution of greater than 1 day should be days 29 PASS: high resolution of 0ms should be ms with no decimals 28 30 PASS: high resolution of sub 1ms should be ms with decimals 29 31 PASS: high resolution of sub 10ms should be ms with decimals … … 47 49 PASS: high resolution of greater than 10mb should be megabytes 48 50 51 -- Running test case: Number.percentageString 52 PASS: precision should default to 1 if unspecified 53 -
trunk/LayoutTests/inspector/unit-tests/number-utilities.html
r196284 r199635 33 33 test: () => { 34 34 // Normal resolution. 35 InspectorTest.expectThat(Number.secondsToString(0, false) === "0ms", "normal resolution of 0ms should be ms with no decimals"); 35 36 InspectorTest.expectThat(Number.secondsToString(0.000123456, false) === "0.12ms", "normal resolution of sub 1ms should be ms"); 36 37 InspectorTest.expectThat(Number.secondsToString(0.00123456, false) === "1.23ms", "normal resolution of sub 10ms should be ms"); … … 46 47 47 48 // High resolution. 49 InspectorTest.expectThat(Number.secondsToString(0, true) === "0ms", "high resolution of 0ms should be ms with no decimals"); 48 50 InspectorTest.expectThat(Number.secondsToString(0.000123456, true) === "0.123ms", "high resolution of sub 1ms should be ms with decimals"); 49 51 InspectorTest.expectThat(Number.secondsToString(0.00123456, true) === "1.235ms", "high resolution of sub 10ms should be ms with decimals"); … … 83 85 }); 84 86 87 suite.addTestCase({ 88 name: "Number.percentageString", 89 test: () => { 90 InspectorTest.expectThat(Number.percentageString(1 / 3) === "33.3%", "precision should default to 1 if unspecified"); 91 92 return true; 93 } 94 }); 95 85 96 suite.runTestCasesAndFinish(); 86 97 } -
trunk/Source/WebInspectorUI/ChangeLog
r199634 r199635 1 2016-04-16 Matt Baker <mattbaker@apple.com> 2 3 Web Inspector: Adopt Number.prototype.toLocaleString For All Sizes and Times 4 https://bugs.webkit.org/show_bug.cgi?id=152033 5 <rdar://problem/23815589> 6 7 Reviewed by Timothy Hatcher. 8 9 Update string formatters to localize float and percentage strings. Hook up 10 console message formatters to use String.standardFormatters so that console 11 statements (e.g. console.log("%.3f", 3.14159)) are properly formatted. 12 13 * Localizations/en.lproj/localizedStrings.js: 14 * UserInterface/Base/Utilities.js: 15 (value): 16 tokenizeFormatString should default to 6 digits when no precision 17 sub-specifier is provided. 18 19 percentageString should localize formatting, and take a fraction value 20 (0 to 1) instead of a percentage. 21 22 secondsToString should perform special-case formatting for zero values 23 ("0ms") instead of the general purpose float formatter. 24 25 (value.d): 26 Switch to parseInt to floor floating point values and support numeric strings. 27 Return NaN instead of zero when passed a value that can't be converted to integer. 28 29 (value.f): 30 Switch to parseFloat to support numeric strings, and localize formatting. 31 Remove precision check, as it will never be less than zero. Return NaN 32 instead of zero when passed a value that can't be converted to float. 33 34 (prettyFunctionName): 35 Convert substitutions (an arguments object) to an array before calling join. 36 37 * UserInterface/Views/ConsoleMessageView.js: 38 (WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.floatFormatter): 39 Use String.standardFormatters.f. 40 41 (WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.integerFormatter): 42 Use String.standardFormatters.d. 43 44 * UserInterface/Views/LayoutTimelineDataGridNode.js: 45 (WebInspector.LayoutTimelineDataGridNode.prototype.createCellContent): 46 (WebInspector.LayoutTimelineDataGridNode): 47 Use integer formatting for pixel values. 48 49 * UserInterface/Views/ProfileDataGridNode.js: 50 (WebInspector.ProfileDataGridNode.prototype._recalculateData): 51 (WebInspector.ProfileDataGridNode.prototype._totalTimeContent): 52 Treat percentage as a fraction from 0 to 1. 53 54 * UserInterface/Views/ResourceDetailsSidebarPanel.js: 55 (WebInspector.ResourceDetailsSidebarPanel.prototype._refreshImageSizeSection): 56 Use integer formatting for pixel values. 57 1 58 2016-04-16 Matt Baker <mattbaker@apple.com> 2 59 -
trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js
r199380 r199635 24 24 localizedStrings["%d \xd7 %d pixels (Natural: %d \xd7 %d pixels)"] = "%d \xd7 %d pixels (Natural: %d \xd7 %d pixels)"; 25 25 localizedStrings["%d matches"] = "%d matches"; 26 localizedStrings["% fpx"] = "%fpx";27 localizedStrings["% fpx²"] = "%fpx²";26 localizedStrings["%dpx"] = "%dpx"; 27 localizedStrings["%dpx²"] = "%dpx²"; 28 28 localizedStrings["%s (computed)"] = "%s (computed)"; 29 29 localizedStrings["%s (default)"] = "%s (default)"; -
trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js
r199143 r199635 641 641 } 642 642 643 var precision = -1; 643 const defaultPrecision = 6; 644 645 let precision = defaultPrecision; 644 646 if (format[index] === ".") { 645 647 // This is a precision specifier. If no digit follows the ".", 646 // then the precision should be zero.648 // then use the default precision of six digits (ISO C99 specification). 647 649 ++index; 648 650 649 651 precision = parseInt(format.substring(index), 10); 650 652 if (isNaN(precision)) 651 precision = 0;653 precision = defaultPrecision; 652 654 653 655 while (!isNaN(format[index])) … … 716 718 d: function(substitution) 717 719 { 718 return !isNaN(substitution) ? substitution : 0;720 return parseInt(substitution); 719 721 }, 720 722 721 723 f: function(substitution, token) 722 724 { 723 if (substitution && token.precision > -1) 724 substitution = substitution.toFixed(token.precision); 725 return !isNaN(substitution) ? substitution : (token.precision > -1 ? Number(0).toFixed(token.precision) : 0); 725 let value = parseFloat(substitution); 726 if (isNaN(value)) 727 return NaN; 728 729 let options = { 730 minimumFractionDigits: token.precision, 731 maximumFractionDigits: token.precision, 732 useGrouping: false 733 }; 734 return value.toLocaleString(undefined, options); 726 735 }, 727 736 … … 742 751 function prettyFunctionName() 743 752 { 744 return "String.format(\"" + format + "\", \"" + substitutions.join("\", \"") + "\")";753 return "String.format(\"" + format + "\", \"" + Array.from(substitutions).join("\", \"") + "\")"; 745 754 } 746 755 … … 913 922 Object.defineProperty(Number, "percentageString", 914 923 { 915 value: function( percent, precision = 1)916 { 917 console.assert( percent >= 0 && percent <= 100);918 return percent.toFixed(precision) + "%";924 value: function(fraction, precision = 1) 925 { 926 console.assert(fraction >= 0 && fraction <= 1); 927 return fraction.toLocaleString(undefined, {minimumFractionDigits: precision, style: "percent"}); 919 928 } 920 929 }); … … 937 946 { 938 947 let ms = seconds * 1000; 948 if (!ms) 949 return WebInspector.UIString("%.0fms").format(0); 939 950 940 951 if (Math.abs(ms) < 10) { -
trunk/Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js
r196275 r199635 600 600 } 601 601 602 function floatFormatter(obj )602 function floatFormatter(obj, token) 603 603 { 604 if (typeof obj.value !== "number") 605 return parseFloat(obj.description); 606 return obj.value; 604 let value = typeof obj.value === "number" ? obj.value : obj.description; 605 return String.standardFormatters.f(value, token); 607 606 } 608 607 609 608 function integerFormatter(obj) 610 609 { 611 if (typeof obj.value !== "number") 612 return parseInt(obj.description); 613 return Math.floor(obj.value); 610 let value = typeof obj.value === "number" ? obj.value : obj.description; 611 return String.standardFormatters.d(value); 614 612 } 615 613 -
trunk/Source/WebInspectorUI/UserInterface/Views/LayoutTimelineDataGridNode.js
r197909 r199635 69 69 case "width": 70 70 case "height": 71 return isNaN(value) ? emDash : WebInspector.UIString("% fpx").format(value);71 return isNaN(value) ? emDash : WebInspector.UIString("%dpx").format(value); 72 72 73 73 case "area": 74 return isNaN(value) ? emDash : WebInspector.UIString("% fpx²").format(value);74 return isNaN(value) ? emDash : WebInspector.UIString("%dpx²").format(value); 75 75 76 76 case "startTime": -
trunk/Source/WebInspectorUI/UserInterface/Views/ProfileDataGridNode.js
r199201 r199635 189 189 let totalTime = duration; 190 190 let selfTime = leafDuration + this._extraSelfTimeFromChargedChildren; 191 let percent = (totalTime / this._tree.totalSampleTime) * 100;192 193 this._data = {totalTime, selfTime, percent};191 let fraction = totalTime / this._tree.totalSampleTime; 192 193 this._data = {totalTime, selfTime, fraction}; 194 194 } 195 195 196 196 _totalTimeContent() 197 197 { 198 let {totalTime, percent} = this._data;198 let {totalTime, fraction} = this._data; 199 199 200 200 let fragment = document.createDocumentFragment(); … … 204 204 let percentElement = fragment.appendChild(document.createElement("span")); 205 205 percentElement.classList.add("percentage"); 206 percentElement.textContent = Number.percentageString( percent);206 percentElement.textContent = Number.percentageString(fraction); 207 207 return fragment; 208 208 } -
trunk/Source/WebInspectorUI/UserInterface/Views/ResourceDetailsSidebarPanel.js
r196275 r199635 417 417 // Get the metrics for this resource and fill in the metrics rows with that information. 418 418 resource.getImageSize(function(size) { 419 this._imageWidthRow.value = WebInspector.UIString("% fpx").format(size.width);420 this._imageHeightRow.value = WebInspector.UIString("% fpx").format(size.height);419 this._imageWidthRow.value = WebInspector.UIString("%dpx").format(size.width); 420 this._imageHeightRow.value = WebInspector.UIString("%dpx").format(size.height); 421 421 }.bind(this)); 422 422 }
Note: See TracChangeset
for help on using the changeset viewer.