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

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

Issue 2776263006: [DevTools] Migrate checkbox label to a proper web component (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/Toolbar.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 * @return {!Element} 1250 * @return {!Element}
1251 */ 1251 */
1252 UI.createLabel = function(title, iconClass) { 1252 UI.createLabel = function(title, iconClass) {
1253 var element = createElement('label', 'dt-icon-label'); 1253 var element = createElement('label', 'dt-icon-label');
1254 element.createChild('span').textContent = title; 1254 element.createChild('span').textContent = title;
1255 element.type = iconClass; 1255 element.type = iconClass;
1256 return element; 1256 return element;
1257 }; 1257 };
1258 1258
1259 /** 1259 /**
1260 * @param {string=} title
1261 * @param {boolean=} checked
1262 * @param {string=} subtitle
1263 * @return {!Element}
1264 */
1265 UI.createCheckboxLabel = function(title, checked, subtitle) {
1266 var element = createElement('label', 'dt-checkbox');
1267 element.checkboxElement.checked = !!checked;
1268 if (title !== undefined) {
1269 element.textElement = element.shadowRoot.createChild('div', 'dt-checkbox-tex t');
1270 element.textElement.textContent = title;
1271 if (subtitle !== undefined) {
1272 element.subtitleElement = element.textElement.createChild('div', 'dt-check box-subtitle');
1273 element.subtitleElement.textContent = subtitle;
1274 }
1275 }
1276 return element;
1277 };
1278
1279 /**
1280 * @return {!Element} 1260 * @return {!Element}
1281 * @param {number} min 1261 * @param {number} min
1282 * @param {number} max 1262 * @param {number} max
1283 * @param {number} tabIndex 1263 * @param {number} tabIndex
1284 */ 1264 */
1285 UI.createSliderLabel = function(min, max, tabIndex) { 1265 UI.createSliderLabel = function(min, max, tabIndex) {
1286 var element = createElement('label', 'dt-slider'); 1266 var element = createElement('label', 'dt-slider');
1287 element.sliderElement.min = min; 1267 element.sliderElement.min = min;
1288 element.sliderElement.max = max; 1268 element.sliderElement.max = max;
1289 element.sliderElement.step = 1; 1269 element.sliderElement.step = 1;
(...skipping 17 matching lines...) Expand all
1307 1287
1308 var themeStyleSheet = UI.themeSupport.themeStyleSheet(cssFile, content); 1288 var themeStyleSheet = UI.themeSupport.themeStyleSheet(cssFile, content);
1309 if (themeStyleSheet) { 1289 if (themeStyleSheet) {
1310 styleElement = createElement('style'); 1290 styleElement = createElement('style');
1311 styleElement.type = 'text/css'; 1291 styleElement.type = 'text/css';
1312 styleElement.textContent = themeStyleSheet + '\n' + Runtime.resolveSourceURL (cssFile + '.theme'); 1292 styleElement.textContent = themeStyleSheet + '\n' + Runtime.resolveSourceURL (cssFile + '.theme');
1313 node.appendChild(styleElement); 1293 node.appendChild(styleElement);
1314 } 1294 }
1315 }; 1295 };
1316 1296
1297 /**
1298 * @extends {HTMLLabelElement}
1299 */
1300 UI.CheckboxLabel = class extends HTMLLabelElement {
1301 constructor() {
1302 super();
1303 /** @type {!DocumentFragment} */
1304 this._shadowRoot;
1305 /** @type {!HTMLInputElement} */
1306 this.checkboxElement;
1307 /** @type {!Element} */
1308 this.textElement;
1309 throw new Error('Checkbox must be created via factory method.');
1310 }
1311
1312 /**
1313 * @override
1314 */
1315 createdCallback() {
1316 UI.CheckboxLabel._lastId = (UI.CheckboxLabel._lastId || 0) + 1;
1317 var id = 'ui-checkbox-label' + UI.CheckboxLabel._lastId;
1318 this._shadowRoot = UI.createShadowRootWithCoreStyles(this, 'ui/checkboxTextL abel.css');
1319 this.checkboxElement = /** @type {!HTMLInputElement} */ (this._shadowRoot.cr eateChild('input'));
1320 this.checkboxElement.type = 'checkbox';
1321 this.checkboxElement.setAttribute('id', id);
1322 this.textElement = this._shadowRoot.createChild('label', 'dt-checkbox-text') ;
1323 this.textElement.setAttribute('for', id);
1324 this._shadowRoot.createChild('content');
1325 }
1326
1327 /**
1328 * @param {string=} title
1329 * @param {boolean=} checked
1330 * @param {string=} subtitle
1331 * @return {!UI.CheckboxLabel}
1332 */
1333 static create(title, checked, subtitle) {
1334 if (!UI.CheckboxLabel._constructor)
1335 UI.CheckboxLabel._constructor = UI.registerCustomElement('label', 'dt-chec kbox', UI.CheckboxLabel.prototype);
1336 var element = /** @type {!UI.CheckboxLabel} */ (new UI.CheckboxLabel._constr uctor());
1337 element.checkboxElement.checked = !!checked;
1338 if (title !== undefined) {
1339 element.textElement.textContent = title;
1340 if (subtitle !== undefined)
1341 element.textElement.createChild('div', 'dt-checkbox-subtitle').textConte nt = subtitle;
1342 }
1343 return element;
1344 }
1345
1346 /**
1347 * @param {string} color
1348 * @this {Element}
1349 */
1350 set backgroundColor(color) {
1351 this.checkboxElement.classList.add('dt-checkbox-themed');
1352 this.checkboxElement.style.backgroundColor = color;
1353 }
1354
1355 /**
1356 * @param {string} color
1357 * @this {Element}
1358 */
1359 set checkColor(color) {
1360 this.checkboxElement.classList.add('dt-checkbox-themed');
1361 var stylesheet = createElement('style');
1362 stylesheet.textContent = 'input.dt-checkbox-themed:checked:after { backgroun d-color: ' + color + '}';
1363 this._shadowRoot.appendChild(stylesheet);
1364 }
1365
1366 /**
1367 * @param {string} color
1368 * @this {Element}
1369 */
1370 set borderColor(color) {
1371 this.checkboxElement.classList.add('dt-checkbox-themed');
1372 this.checkboxElement.style.borderColor = color;
1373 }
1374
1375 /**
1376 * @param {boolean} focus
1377 * @this {Element}
1378 */
1379 set visualizeFocus(focus) {
1380 this.checkboxElement.classList.toggle('dt-checkbox-visualize-focus', focus);
1381 }
1382 };
1383
1317 (function() { 1384 (function() {
1318 UI.registerCustomElement('button', 'text-button', { 1385 UI.registerCustomElement('button', 'text-button', {
1319 /** 1386 /**
1320 * @this {Element} 1387 * @this {Element}
1321 */ 1388 */
1322 createdCallback: function() { 1389 createdCallback: function() {
1323 this.type = 'button'; 1390 this.type = 'button';
1324 var root = UI.createShadowRootWithCoreStyles(this, 'ui/textButton.css'); 1391 var root = UI.createShadowRootWithCoreStyles(this, 'ui/textButton.css');
1325 root.createChild('content'); 1392 root.createChild('content');
1326 }, 1393 },
(...skipping 22 matching lines...) Expand all
1349 * @suppressReceiverCheck 1416 * @suppressReceiverCheck
1350 * @this {Element} 1417 * @this {Element}
1351 */ 1418 */
1352 function radioClickHandler(event) { 1419 function radioClickHandler(event) {
1353 if (this.radioElement.checked || this.radioElement.disabled) 1420 if (this.radioElement.checked || this.radioElement.disabled)
1354 return; 1421 return;
1355 this.radioElement.checked = true; 1422 this.radioElement.checked = true;
1356 this.radioElement.dispatchEvent(new Event('change')); 1423 this.radioElement.dispatchEvent(new Event('change'));
1357 } 1424 }
1358 1425
1359 UI.registerCustomElement('label', 'dt-checkbox', {
1360 /**
1361 * @this {Element}
1362 */
1363 createdCallback: function() {
1364 this._root = UI.createShadowRootWithCoreStyles(this, 'ui/checkboxTextLabel .css');
1365 var checkboxElement = createElementWithClass('input', 'dt-checkbox-button' );
1366 checkboxElement.type = 'checkbox';
1367 this._root.appendChild(checkboxElement);
1368 this.checkboxElement = checkboxElement;
1369
1370 this.addEventListener('click', toggleCheckbox.bind(this));
1371
1372 /**
1373 * @param {!Event} event
1374 * @this {Node}
1375 */
1376 function toggleCheckbox(event) {
1377 var deepTarget = event.deepElementFromPoint();
1378 if (deepTarget !== checkboxElement && deepTarget !== this) {
1379 event.consume();
1380 checkboxElement.click();
1381 }
1382 }
1383
1384 this._root.createChild('content');
1385 },
1386
1387 /**
1388 * @param {string} color
1389 * @this {Element}
1390 */
1391 set backgroundColor(color) {
1392 this.checkboxElement.classList.add('dt-checkbox-themed');
1393 this.checkboxElement.style.backgroundColor = color;
1394 },
1395
1396 /**
1397 * @param {string} color
1398 * @this {Element}
1399 */
1400 set checkColor(color) {
1401 this.checkboxElement.classList.add('dt-checkbox-themed');
1402 var stylesheet = createElement('style');
1403 stylesheet.textContent = 'input.dt-checkbox-themed:checked:after { backgro und-color: ' + color + '}';
1404 this._root.appendChild(stylesheet);
1405 },
1406
1407 /**
1408 * @param {string} color
1409 * @this {Element}
1410 */
1411 set borderColor(color) {
1412 this.checkboxElement.classList.add('dt-checkbox-themed');
1413 this.checkboxElement.style.borderColor = color;
1414 },
1415
1416 /**
1417 * @param {boolean} focus
1418 * @this {Element}
1419 */
1420 set visualizeFocus(focus) {
1421 this.checkboxElement.classList.toggle('dt-checkbox-visualize-focus', focus );
1422 },
1423
1424 __proto__: HTMLLabelElement.prototype
1425 });
1426
1427 UI.registerCustomElement('label', 'dt-icon-label', { 1426 UI.registerCustomElement('label', 'dt-icon-label', {
1428 /** 1427 /**
1429 * @this {Element} 1428 * @this {Element}
1430 */ 1429 */
1431 createdCallback: function() { 1430 createdCallback: function() {
1432 var root = UI.createShadowRootWithCoreStyles(this); 1431 var root = UI.createShadowRootWithCoreStyles(this);
1433 this._iconElement = UI.Icon.create(); 1432 this._iconElement = UI.Icon.create();
1434 this._iconElement.style.setProperty('margin-right', '4px'); 1433 this._iconElement.style.setProperty('margin-right', '4px');
1435 root.appendChild(this._iconElement); 1434 root.appendChild(this._iconElement);
1436 root.createChild('content'); 1435 root.createChild('content');
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 */ 2063 */
2065 constructor(message, okCallback, cancelCallback) { 2064 constructor(message, okCallback, cancelCallback) {
2066 super(true); 2065 super(true);
2067 this.registerRequiredCSS('ui/confirmDialog.css'); 2066 this.registerRequiredCSS('ui/confirmDialog.css');
2068 this.contentElement.createChild('div', 'message').createChild('span').textCo ntent = message; 2067 this.contentElement.createChild('div', 'message').createChild('span').textCo ntent = message;
2069 var buttonsBar = this.contentElement.createChild('div', 'button'); 2068 var buttonsBar = this.contentElement.createChild('div', 'button');
2070 buttonsBar.appendChild(UI.createTextButton(Common.UIString('Ok'), okCallback )); 2069 buttonsBar.appendChild(UI.createTextButton(Common.UIString('Ok'), okCallback ));
2071 buttonsBar.appendChild(UI.createTextButton(Common.UIString('Cancel'), cancel Callback)); 2070 buttonsBar.appendChild(UI.createTextButton(Common.UIString('Cancel'), cancel Callback));
2072 } 2071 }
2073 }; 2072 };
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/Toolbar.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698