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

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

Issue 2604883002: DevTools: namespace globals (Closed)
Patch Set: address CL feedback Created 3 years, 12 months 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 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 }; 1223 };
1224 1224
1225 /** 1225 /**
1226 * @param {string} localName 1226 * @param {string} localName
1227 * @param {string} typeExtension 1227 * @param {string} typeExtension
1228 * @param {!Object} prototype 1228 * @param {!Object} prototype
1229 * @return {function()} 1229 * @return {function()}
1230 * @suppressGlobalPropertiesCheck 1230 * @suppressGlobalPropertiesCheck
1231 * @template T 1231 * @template T
1232 */ 1232 */
1233 function registerCustomElement(localName, typeExtension, prototype) { 1233 UI.registerCustomElement = function(localName, typeExtension, prototype) {
1234 return document.registerElement(typeExtension, {prototype: Object.create(proto type), extends: localName}); 1234 return document.registerElement(typeExtension, {prototype: Object.create(proto type), extends: localName});
1235 } 1235 };
1236 1236
1237 /** 1237 /**
1238 * @param {string} text 1238 * @param {string} text
1239 * @param {function(!Event)=} clickHandler 1239 * @param {function(!Event)=} clickHandler
1240 * @param {string=} className 1240 * @param {string=} className
1241 * @param {string=} title 1241 * @param {string=} title
1242 * @return {!Element} 1242 * @return {!Element}
1243 */ 1243 */
1244 function createTextButton(text, clickHandler, className, title) { 1244 UI.createTextButton = function(text, clickHandler, className, title) {
1245 var element = createElementWithClass('button', className || '', 'text-button') ; 1245 var element = createElementWithClass('button', className || '', 'text-button') ;
1246 element.textContent = text; 1246 element.textContent = text;
1247 if (clickHandler) 1247 if (clickHandler)
1248 element.addEventListener('click', clickHandler, false); 1248 element.addEventListener('click', clickHandler, false);
1249 if (title) 1249 if (title)
1250 element.title = title; 1250 element.title = title;
1251 return element; 1251 return element;
1252 } 1252 };
1253 1253
1254 /** 1254 /**
1255 * @param {string} name 1255 * @param {string} name
1256 * @param {string} title 1256 * @param {string} title
1257 * @param {boolean=} checked 1257 * @param {boolean=} checked
1258 * @return {!Element} 1258 * @return {!Element}
1259 */ 1259 */
1260 function createRadioLabel(name, title, checked) { 1260 UI.createRadioLabel = function(name, title, checked) {
1261 var element = createElement('label', 'dt-radio'); 1261 var element = createElement('label', 'dt-radio');
1262 element.radioElement.name = name; 1262 element.radioElement.name = name;
1263 element.radioElement.checked = !!checked; 1263 element.radioElement.checked = !!checked;
1264 element.createTextChild(title); 1264 element.createTextChild(title);
1265 return element; 1265 return element;
1266 } 1266 };
1267 1267
1268 /** 1268 /**
1269 * @param {string} title 1269 * @param {string} title
1270 * @param {string} iconClass 1270 * @param {string} iconClass
1271 * @return {!Element} 1271 * @return {!Element}
1272 */ 1272 */
1273 function createLabel(title, iconClass) { 1273 UI.createLabel = function(title, iconClass) {
1274 var element = createElement('label', 'dt-icon-label'); 1274 var element = createElement('label', 'dt-icon-label');
1275 element.createChild('span').textContent = title; 1275 element.createChild('span').textContent = title;
1276 element.type = iconClass; 1276 element.type = iconClass;
1277 return element; 1277 return element;
1278 } 1278 };
1279 1279
1280 /** 1280 /**
1281 * @param {string=} title 1281 * @param {string=} title
1282 * @param {boolean=} checked 1282 * @param {boolean=} checked
1283 * @param {string=} subtitle 1283 * @param {string=} subtitle
1284 * @return {!Element} 1284 * @return {!Element}
1285 */ 1285 */
1286 function createCheckboxLabel(title, checked, subtitle) { 1286 UI.createCheckboxLabel = function(title, checked, subtitle) {
1287 var element = createElement('label', 'dt-checkbox'); 1287 var element = createElement('label', 'dt-checkbox');
1288 element.checkboxElement.checked = !!checked; 1288 element.checkboxElement.checked = !!checked;
1289 if (title !== undefined) { 1289 if (title !== undefined) {
1290 element.textElement = element.createChild('div', 'dt-checkbox-text'); 1290 element.textElement = element.createChild('div', 'dt-checkbox-text');
1291 element.textElement.textContent = title; 1291 element.textElement.textContent = title;
1292 if (subtitle !== undefined) { 1292 if (subtitle !== undefined) {
1293 element.subtitleElement = element.textElement.createChild('div', 'dt-check box-subtitle'); 1293 element.subtitleElement = element.textElement.createChild('div', 'dt-check box-subtitle');
1294 element.subtitleElement.textContent = subtitle; 1294 element.subtitleElement.textContent = subtitle;
1295 } 1295 }
1296 } 1296 }
1297 return element; 1297 return element;
1298 } 1298 };
1299 1299
1300 /** 1300 /**
1301 * @return {!Element} 1301 * @return {!Element}
1302 * @param {number} min 1302 * @param {number} min
1303 * @param {number} max 1303 * @param {number} max
1304 * @param {number} tabIndex 1304 * @param {number} tabIndex
1305 */ 1305 */
1306 function createSliderLabel(min, max, tabIndex) { 1306 UI.createSliderLabel = function(min, max, tabIndex) {
1307 var element = createElement('label', 'dt-slider'); 1307 var element = createElement('label', 'dt-slider');
1308 element.sliderElement.min = min; 1308 element.sliderElement.min = min;
1309 element.sliderElement.max = max; 1309 element.sliderElement.max = max;
1310 element.sliderElement.step = 1; 1310 element.sliderElement.step = 1;
1311 element.sliderElement.tabIndex = tabIndex; 1311 element.sliderElement.tabIndex = tabIndex;
1312 return element; 1312 return element;
1313 } 1313 };
1314 1314
1315 /** 1315 /**
1316 * @param {!Node} node 1316 * @param {!Node} node
1317 * @param {string} cssFile 1317 * @param {string} cssFile
1318 * @suppressGlobalPropertiesCheck 1318 * @suppressGlobalPropertiesCheck
1319 */ 1319 */
1320 UI.appendStyle = function(node, cssFile) { 1320 UI.appendStyle = function(node, cssFile) {
1321 var content = Runtime.cachedResources[cssFile] || ''; 1321 var content = Runtime.cachedResources[cssFile] || '';
1322 if (!content) 1322 if (!content)
1323 console.error(cssFile + ' not preloaded. Check module.json'); 1323 console.error(cssFile + ' not preloaded. Check module.json');
1324 var styleElement = createElement('style'); 1324 var styleElement = createElement('style');
1325 styleElement.type = 'text/css'; 1325 styleElement.type = 'text/css';
1326 styleElement.textContent = content; 1326 styleElement.textContent = content;
1327 node.appendChild(styleElement); 1327 node.appendChild(styleElement);
1328 1328
1329 var themeStyleSheet = UI.themeSupport.themeStyleSheet(cssFile, content); 1329 var themeStyleSheet = UI.themeSupport.themeStyleSheet(cssFile, content);
1330 if (themeStyleSheet) { 1330 if (themeStyleSheet) {
1331 styleElement = createElement('style'); 1331 styleElement = createElement('style');
1332 styleElement.type = 'text/css'; 1332 styleElement.type = 'text/css';
1333 styleElement.textContent = themeStyleSheet + '\n' + Runtime.resolveSourceURL (cssFile + '.theme'); 1333 styleElement.textContent = themeStyleSheet + '\n' + Runtime.resolveSourceURL (cssFile + '.theme');
1334 node.appendChild(styleElement); 1334 node.appendChild(styleElement);
1335 } 1335 }
1336 }; 1336 };
1337 1337
1338 (function() { 1338 (function() {
1339 registerCustomElement('button', 'text-button', { 1339 UI.registerCustomElement('button', 'text-button', {
1340 /** 1340 /**
1341 * @this {Element} 1341 * @this {Element}
1342 */ 1342 */
1343 createdCallback: function() { 1343 createdCallback: function() {
1344 this.type = 'button'; 1344 this.type = 'button';
1345 var root = UI.createShadowRootWithCoreStyles(this, 'ui/textButton.css'); 1345 var root = UI.createShadowRootWithCoreStyles(this, 'ui/textButton.css');
1346 root.createChild('content'); 1346 root.createChild('content');
1347 }, 1347 },
1348 1348
1349 __proto__: HTMLButtonElement.prototype 1349 __proto__: HTMLButtonElement.prototype
1350 }); 1350 });
1351 1351
1352 registerCustomElement('label', 'dt-radio', { 1352 UI.registerCustomElement('label', 'dt-radio', {
1353 /** 1353 /**
1354 * @this {Element} 1354 * @this {Element}
1355 */ 1355 */
1356 createdCallback: function() { 1356 createdCallback: function() {
1357 this.radioElement = this.createChild('input', 'dt-radio-button'); 1357 this.radioElement = this.createChild('input', 'dt-radio-button');
1358 this.radioElement.type = 'radio'; 1358 this.radioElement.type = 'radio';
1359 var root = UI.createShadowRootWithCoreStyles(this, 'ui/radioButton.css'); 1359 var root = UI.createShadowRootWithCoreStyles(this, 'ui/radioButton.css');
1360 root.createChild('content').select = '.dt-radio-button'; 1360 root.createChild('content').select = '.dt-radio-button';
1361 root.createChild('content'); 1361 root.createChild('content');
1362 this.addEventListener('click', radioClickHandler, false); 1362 this.addEventListener('click', radioClickHandler, false);
1363 }, 1363 },
1364 1364
1365 __proto__: HTMLLabelElement.prototype 1365 __proto__: HTMLLabelElement.prototype
1366 }); 1366 });
1367 1367
1368 /** 1368 /**
1369 * @param {!Event} event 1369 * @param {!Event} event
1370 * @suppressReceiverCheck 1370 * @suppressReceiverCheck
1371 * @this {Element} 1371 * @this {Element}
1372 */ 1372 */
1373 function radioClickHandler(event) { 1373 function radioClickHandler(event) {
1374 if (this.radioElement.checked || this.radioElement.disabled) 1374 if (this.radioElement.checked || this.radioElement.disabled)
1375 return; 1375 return;
1376 this.radioElement.checked = true; 1376 this.radioElement.checked = true;
1377 this.radioElement.dispatchEvent(new Event('change')); 1377 this.radioElement.dispatchEvent(new Event('change'));
1378 } 1378 }
1379 1379
1380 registerCustomElement('label', 'dt-checkbox', { 1380 UI.registerCustomElement('label', 'dt-checkbox', {
1381 /** 1381 /**
1382 * @this {Element} 1382 * @this {Element}
1383 */ 1383 */
1384 createdCallback: function() { 1384 createdCallback: function() {
1385 this._root = UI.createShadowRootWithCoreStyles(this, 'ui/checkboxTextLabel .css'); 1385 this._root = UI.createShadowRootWithCoreStyles(this, 'ui/checkboxTextLabel .css');
1386 var checkboxElement = createElementWithClass('input', 'dt-checkbox-button' ); 1386 var checkboxElement = createElementWithClass('input', 'dt-checkbox-button' );
1387 checkboxElement.type = 'checkbox'; 1387 checkboxElement.type = 'checkbox';
1388 this._root.appendChild(checkboxElement); 1388 this._root.appendChild(checkboxElement);
1389 this.checkboxElement = checkboxElement; 1389 this.checkboxElement = checkboxElement;
1390 1390
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 * @param {boolean} focus 1437 * @param {boolean} focus
1438 * @this {Element} 1438 * @this {Element}
1439 */ 1439 */
1440 set visualizeFocus(focus) { 1440 set visualizeFocus(focus) {
1441 this.checkboxElement.classList.toggle('dt-checkbox-visualize-focus', focus ); 1441 this.checkboxElement.classList.toggle('dt-checkbox-visualize-focus', focus );
1442 }, 1442 },
1443 1443
1444 __proto__: HTMLLabelElement.prototype 1444 __proto__: HTMLLabelElement.prototype
1445 }); 1445 });
1446 1446
1447 registerCustomElement('label', 'dt-icon-label', { 1447 UI.registerCustomElement('label', 'dt-icon-label', {
1448 /** 1448 /**
1449 * @this {Element} 1449 * @this {Element}
1450 */ 1450 */
1451 createdCallback: function() { 1451 createdCallback: function() {
1452 var root = UI.createShadowRootWithCoreStyles(this); 1452 var root = UI.createShadowRootWithCoreStyles(this);
1453 this._iconElement = UI.Icon.create(); 1453 this._iconElement = UI.Icon.create();
1454 this._iconElement.style.setProperty('margin-right', '4px'); 1454 this._iconElement.style.setProperty('margin-right', '4px');
1455 root.appendChild(this._iconElement); 1455 root.appendChild(this._iconElement);
1456 root.createChild('content'); 1456 root.createChild('content');
1457 }, 1457 },
1458 1458
1459 /** 1459 /**
1460 * @param {string} type 1460 * @param {string} type
1461 * @this {Element} 1461 * @this {Element}
1462 */ 1462 */
1463 set type(type) { 1463 set type(type) {
1464 this._iconElement.setIconType(type); 1464 this._iconElement.setIconType(type);
1465 }, 1465 },
1466 1466
1467 __proto__: HTMLLabelElement.prototype 1467 __proto__: HTMLLabelElement.prototype
1468 }); 1468 });
1469 1469
1470 registerCustomElement('label', 'dt-slider', { 1470 UI.registerCustomElement('label', 'dt-slider', {
1471 /** 1471 /**
1472 * @this {Element} 1472 * @this {Element}
1473 */ 1473 */
1474 createdCallback: function() { 1474 createdCallback: function() {
1475 var root = UI.createShadowRootWithCoreStyles(this, 'ui/slider.css'); 1475 var root = UI.createShadowRootWithCoreStyles(this, 'ui/slider.css');
1476 this.sliderElement = createElementWithClass('input', 'dt-range-input'); 1476 this.sliderElement = createElementWithClass('input', 'dt-range-input');
1477 this.sliderElement.type = 'range'; 1477 this.sliderElement.type = 'range';
1478 root.appendChild(this.sliderElement); 1478 root.appendChild(this.sliderElement);
1479 }, 1479 },
1480 1480
1481 /** 1481 /**
1482 * @param {number} amount 1482 * @param {number} amount
1483 * @this {Element} 1483 * @this {Element}
1484 */ 1484 */
1485 set value(amount) { 1485 set value(amount) {
1486 this.sliderElement.value = amount; 1486 this.sliderElement.value = amount;
1487 }, 1487 },
1488 1488
1489 /** 1489 /**
1490 * @this {Element} 1490 * @this {Element}
1491 */ 1491 */
1492 get value() { 1492 get value() {
1493 return this.sliderElement.value; 1493 return this.sliderElement.value;
1494 }, 1494 },
1495 1495
1496 __proto__: HTMLLabelElement.prototype 1496 __proto__: HTMLLabelElement.prototype
1497 }); 1497 });
1498 1498
1499 registerCustomElement('label', 'dt-small-bubble', { 1499 UI.registerCustomElement('label', 'dt-small-bubble', {
1500 /** 1500 /**
1501 * @this {Element} 1501 * @this {Element}
1502 */ 1502 */
1503 createdCallback: function() { 1503 createdCallback: function() {
1504 var root = UI.createShadowRootWithCoreStyles(this, 'ui/smallBubble.css'); 1504 var root = UI.createShadowRootWithCoreStyles(this, 'ui/smallBubble.css');
1505 this._textElement = root.createChild('div'); 1505 this._textElement = root.createChild('div');
1506 this._textElement.className = 'info'; 1506 this._textElement.className = 'info';
1507 this._textElement.createChild('content'); 1507 this._textElement.createChild('content');
1508 }, 1508 },
1509 1509
1510 /** 1510 /**
1511 * @param {string} type 1511 * @param {string} type
1512 * @this {Element} 1512 * @this {Element}
1513 */ 1513 */
1514 set type(type) { 1514 set type(type) {
1515 this._textElement.className = type; 1515 this._textElement.className = type;
1516 }, 1516 },
1517 1517
1518 __proto__: HTMLLabelElement.prototype 1518 __proto__: HTMLLabelElement.prototype
1519 }); 1519 });
1520 1520
1521 registerCustomElement('div', 'dt-close-button', { 1521 UI.registerCustomElement('div', 'dt-close-button', {
1522 /** 1522 /**
1523 * @this {Element} 1523 * @this {Element}
1524 */ 1524 */
1525 createdCallback: function() { 1525 createdCallback: function() {
1526 var root = UI.createShadowRootWithCoreStyles(this, 'ui/closeButton.css'); 1526 var root = UI.createShadowRootWithCoreStyles(this, 'ui/closeButton.css');
1527 this._buttonElement = root.createChild('div', 'close-button'); 1527 this._buttonElement = root.createChild('div', 'close-button');
1528 }, 1528 },
1529 1529
1530 /** 1530 /**
1531 * @param {boolean} gray 1531 * @param {boolean} gray
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
2009 return new Promise(fulfill => { 2009 return new Promise(fulfill => {
2010 var image = new Image(); 2010 var image = new Image();
2011 image.addEventListener('load', () => fulfill(image)); 2011 image.addEventListener('load', () => fulfill(image));
2012 image.addEventListener('error', () => fulfill(null)); 2012 image.addEventListener('error', () => fulfill(null));
2013 image.src = url; 2013 image.src = url;
2014 }); 2014 });
2015 }; 2015 };
2016 2016
2017 /** @type {!UI.ThemeSupport} */ 2017 /** @type {!UI.ThemeSupport} */
2018 UI.themeSupport; 2018 UI.themeSupport;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698