Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/UIUtils.js

Issue 2482153003: DevTools: Depict network request timings on timeline network pane. (Closed)
Patch Set: Tweaks Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). 4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com).
5 * Copyright (C) 2009 Joseph Pecoraro 5 * Copyright (C) 2009 Joseph Pecoraro
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 10 *
(...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 if (value === input.value) 1608 if (value === input.value)
1609 return; 1609 return;
1610 var valid = validate(value); 1610 var valid = validate(value);
1611 input.classList.toggle('error-input', !valid); 1611 input.classList.toggle('error-input', !valid);
1612 input.value = value; 1612 input.value = value;
1613 } 1613 }
1614 1614
1615 return setValue; 1615 return setValue;
1616 }; 1616 };
1617 1617
1618 /**
1619 * @param {!CanvasRenderingContext2D} context
1620 * @param {string} text
1621 * @param {number} maxWidth
1622 * @return {string}
1623 */
1624 WebInspector.trimTextMiddle = function(context, text, maxWidth) {
1625 const maxLength = 200;
1626 if (maxWidth <= 10)
1627 return '';
1628 if (text.length > maxLength)
1629 text = text.trimMiddle(maxLength);
1630 const textWidth = WebInspector.measureTextWidth(context, text);
1631 if (textWidth <= maxWidth)
1632 return text;
1633
1634 var l = 0;
1635 var r = text.length;
1636 var lv = 0;
1637 var rv = textWidth;
1638 while (l < r && lv !== rv && lv !== maxWidth) {
1639 const m = Math.ceil(l + (r - l) * (maxWidth - lv) / (rv - lv));
1640 const mv = WebInspector.measureTextWidth(context, text.trimMiddle(m));
1641 if (mv <= maxWidth) {
1642 l = m;
1643 lv = mv;
1644 } else {
1645 r = m - 1;
1646 rv = mv;
1647 }
1648 }
1649 text = text.trimMiddle(l);
1650 return text !== '\u2026' ? text : '';
1651 };
1652
1653 /**
1654 * @param {!CanvasRenderingContext2D} context
1655 * @param {string} text
1656 * @return {number}
1657 */
1658 WebInspector.measureTextWidth = function(context, text) {
1659 const maxCacheableLength = 200;
1660 if (text.length > maxCacheableLength)
1661 return context.measureText(text).width;
1662
1663 var widthCache = WebInspector.measureTextWidth._textWidthCache;
1664 if (!widthCache) {
1665 widthCache = new Map();
1666 WebInspector.measureTextWidth._textWidthCache = widthCache;
1667 }
1668 const font = context.font;
1669 var textWidths = widthCache.get(font);
1670 if (!textWidths) {
1671 textWidths = new Map();
1672 widthCache.set(font, textWidths);
1673 }
1674 var width = textWidths.get(text);
1675 if (!width) {
1676 width = context.measureText(text).width;
1677 textWidths.set(text, width);
1678 }
1679 return width;
1680 };
1681
1618 /** 1682 /**
1619 * @unrestricted 1683 * @unrestricted
1620 */ 1684 */
1621 WebInspector.ThemeSupport = class { 1685 WebInspector.ThemeSupport = class {
1622 /** 1686 /**
1623 * @param {!WebInspector.Setting} setting 1687 * @param {!WebInspector.Setting} setting
1624 */ 1688 */
1625 constructor(setting) { 1689 constructor(setting) {
1626 this._themeName = setting.get() || 'default'; 1690 this._themeName = setting.get() || 'default';
1627 this._themableProperties = new Set([ 1691 this._themableProperties = new Set([
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 return new Promise(fulfill => { 1964 return new Promise(fulfill => {
1901 var image = new Image(); 1965 var image = new Image();
1902 image.addEventListener('load', () => fulfill(image)); 1966 image.addEventListener('load', () => fulfill(image));
1903 image.addEventListener('error', () => fulfill(null)); 1967 image.addEventListener('error', () => fulfill(null));
1904 image.src = url; 1968 image.src = url;
1905 }); 1969 });
1906 }; 1970 };
1907 1971
1908 /** @type {!WebInspector.ThemeSupport} */ 1972 /** @type {!WebInspector.ThemeSupport} */
1909 WebInspector.themeSupport; 1973 WebInspector.themeSupport;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698