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

Side by Side Diff: chrome/browser/resources/inspect/inspect.js

Issue 23441060: DevTools: Improve design of WebViews available for inspection in chrome://inspect (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/inspect/inspect.css ('k') | chrome/browser/ui/webui/inspect_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var MIN_VERSION_TAB_CLOSE = 25; 5 var MIN_VERSION_TAB_CLOSE = 25;
6 var MIN_VERSION_TARGET_ID = 26; 6 var MIN_VERSION_TARGET_ID = 26;
7 var MIN_VERSION_NEW_TAB = 29; 7 var MIN_VERSION_NEW_TAB = 29;
8 var MIN_VERSION_TAB_ACTIVATE = 30; 8 var MIN_VERSION_TAB_ACTIVATE = 30;
9 9
10 function inspect(data) { 10 function inspect(data) {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 if (alreadyDisplayed(browserSection, browser)) 275 if (alreadyDisplayed(browserSection, browser))
276 continue; 276 continue;
277 277
278 pageList.textContent = ''; 278 pageList.textContent = '';
279 for (var p = 0; p < browser.pages.length; p++) { 279 for (var p = 0; p < browser.pages.length; p++) {
280 var page = browser.pages[p]; 280 var page = browser.pages[p];
281 // Attached targets have no unique id until Chrome 26. For such targets 281 // Attached targets have no unique id until Chrome 26. For such targets
282 // it is impossible to activate existing DevTools window. 282 // it is impossible to activate existing DevTools window.
283 page.hasNoUniqueId = page.attached && 283 page.hasNoUniqueId = page.attached &&
284 majorChromeVersion < MIN_VERSION_TARGET_ID; 284 majorChromeVersion < MIN_VERSION_TARGET_ID;
285 var row = addTargetToList( 285 var row = addTargetToList(page, pageList, ['name', 'url']);
286 page, pageList, ['faviconUrl', 'name', 'url', 'description']); 286 if (page['description'])
287 addWebViewDetails(row, page);
288 else
289 addFavicon(row, page);
287 if (isChrome) { 290 if (isChrome) {
288 if (majorChromeVersion >= MIN_VERSION_TAB_ACTIVATE) { 291 if (majorChromeVersion >= MIN_VERSION_TAB_ACTIVATE) {
289 row.appendChild(createActionLink( 292 addActionLink(row, 'activate', activate.bind(null, page), false);
290 'activate', activate.bind(null, page), false));
291 } 293 }
292 row.appendChild(createActionLink( 294 addActionLink(row, 'reload', reload.bind(null, page), page.attached);
293 'reload', reload.bind(null, page), page.attached));
294 if (majorChromeVersion >= MIN_VERSION_TAB_CLOSE) { 295 if (majorChromeVersion >= MIN_VERSION_TAB_CLOSE) {
295 row.appendChild(createActionLink( 296 addActionLink(
296 'close', terminate.bind(null, page), page.attached)); 297 row, 'close', terminate.bind(null, page), page.attached);
297 } 298 }
298 } 299 }
299 } 300 }
300 } 301 }
301 } 302 }
302 } 303 }
303 304
304 function addToPagesList(data) { 305 function addToPagesList(data) {
305 addTargetToList(data, $('pages-list'), ['faviconUrl', 'name', 'url']); 306 var row = addTargetToList(data, $('pages-list'), ['name', 'url']);
307 addFavicon(row, data);
306 } 308 }
307 309
308 function addToExtensionsList(data) { 310 function addToExtensionsList(data) {
309 addTargetToList(data, $('extensions-list'), ['name', 'url']); 311 addTargetToList(data, $('extensions-list'), ['name', 'url']);
310 } 312 }
311 313
312 function addToAppsList(data) { 314 function addToAppsList(data) {
313 var row = addTargetToList(data, $('apps-list'), ['name', 'url']); 315 var row = addTargetToList(data, $('apps-list'), ['name', 'url']);
314 if (data.guests) { 316 if (data.guests) {
315 Array.prototype.forEach.call(data.guests, function(guest) { 317 Array.prototype.forEach.call(data.guests, function(guest) {
316 var guestRow = addTargetToList(guest, row, ['faviconUrl', 'name', 'url']); 318 var guestRow = addTargetToList(guest, row, ['name', 'url']);
317 guestRow.classList.add('guest'); 319 guestRow.classList.add('guest');
320 addFavicon(guestRow, data);
318 }); 321 });
319 } 322 }
320 } 323 }
321 324
322 function addToWorkersList(data) { 325 function addToWorkersList(data) {
323 var row = addTargetToList(data, $('workers-list'), ['pid', 'url']); 326 var row = addTargetToList(data, $('workers-list'), ['pid', 'url']);
324 row.appendChild(createActionLink( 327 addActionLink(row, 'terminate', terminate.bind(null, data), data.attached);
325 'terminate', terminate.bind(null, data), data.attached));
326 } 328 }
327 329
328 function addToOthersList(data) { 330 function addToOthersList(data) {
329 addTargetToList(data, $('others-list'), ['url']); 331 addTargetToList(data, $('others-list'), ['url']);
330 } 332 }
331 333
332 function formatValue(data, property) { 334 function formatValue(data, property) {
333 var value = data[property]; 335 var value = data[property];
334 336
335 if (property == 'name' && value == '') { 337 if (property == 'name' && value == '') {
336 value = 'untitled'; 338 value = 'untitled';
337 } 339 }
338 340
339 if (property == 'faviconUrl') {
340 var faviconElement = document.createElement('img');
341 if (value)
342 faviconElement.src = value;
343 return faviconElement;
344 }
345
346 var text = value ? String(value) : ''; 341 var text = value ? String(value) : '';
347 if (text.length > 100) 342 if (text.length > 100)
348 text = text.substring(0, 100) + '\u2026'; 343 text = text.substring(0, 100) + '\u2026';
349 344
350 if (property == 'pid') 345 if (property == 'pid')
351 text = 'Pid:' + text; 346 text = 'Pid:' + text;
352 347
353 var span = document.createElement('div'); 348 var span = document.createElement('div');
354 span.textContent = text; 349 span.textContent = text;
355 span.className = property; 350 span.className = property;
356 return span; 351 return span;
357 } 352 }
358 353
359 function addWebViewDescription(webview, list) { 354 function addFavicon(row, data) {
355 var favicon = document.createElement('img');
356 if (data['faviconUrl'])
357 favicon.src = data['faviconUrl'];
358 row.insertBefore(favicon, row.firstChild);
359 }
360
361 function addWebViewDetails(row, data) {
362 var webview;
363 try {
364 webview = JSON.parse(data['description']);
365 } catch (e) {
366 return;
367 }
368 addWebViewDescription(row, webview);
369 if (data.adbScreenWidth && data.adbScreenHeight)
370 addWebViewThumbnail(
371 row, webview, data.adbScreenWidth, data.adbScreenHeight);
372 }
373
374 function addWebViewDescription(row, webview) {
360 var viewStatus = { visibility: 'empty', position: '', size: '' }; 375 var viewStatus = { visibility: 'empty', position: '', size: '' };
361 if (!webview.empty) { 376 if (!webview.empty) {
362 if (webview.attached) 377 if (webview.attached)
363 viewStatus.visibility = webview.visible ? 'visible' : 'hidden'; 378 viewStatus.visibility = webview.visible ? 'visible' : 'hidden';
364 else 379 else
365 viewStatus.visibility = 'detached'; 380 viewStatus.visibility = 'detached';
366 viewStatus.size = 'size ' + webview.width + ' \u00d7 ' + webview.height; 381 viewStatus.size = 'size ' + webview.width + ' \u00d7 ' + webview.height;
367 } 382 }
368 if (webview.attached) { 383 if (webview.attached) {
369 viewStatus.position = 384 viewStatus.position =
370 'at (' + webview.screenX + ', ' + webview.screenY + ')'; 385 'at (' + webview.screenX + ', ' + webview.screenY + ')';
371 } 386 }
372 387
373 var row = document.createElement('div'); 388 var subRow = document.createElement('div');
374 row.className = 'subrow webview'; 389 subRow.className = 'subrow webview';
375 if (webview.empty || !webview.attached || !webview.visible) 390 if (webview.empty || !webview.attached || !webview.visible)
376 row.className += ' invisible-view'; 391 subRow.className += ' invisible-view';
377 row.appendChild(formatValue(viewStatus, 'visibility')); 392 subRow.appendChild(formatValue(viewStatus, 'visibility'));
378 row.appendChild(formatValue(viewStatus, 'position')); 393 subRow.appendChild(formatValue(viewStatus, 'position'));
379 row.appendChild(formatValue(viewStatus, 'size')); 394 subRow.appendChild(formatValue(viewStatus, 'size'));
380 list.appendChild(row); 395 var mainSubrow = row.querySelector('.subrow.main');
381 return row; 396 if (mainSubrow.nextSibling)
397 mainSubrow.parentNode.insertBefore(subRow, mainSubrow.nextSibling);
398 else
399 mainSubrow.parentNode.appendChild(subRow);
400 }
401
402 function addWebViewThumbnail(row, webview, screenWidth, screenHeight) {
403 var maxScreenRectSize = 50;
404 var screenRectWidth;
405 var screenRectHeight;
406
407 var aspectRatio = screenWidth / screenHeight;
408 if (aspectRatio < 1) {
409 screenRectWidth = Math.round(maxScreenRectSize * aspectRatio);
410 screenRectHeight = maxScreenRectSize;
411 } else {
412 screenRectWidth = maxScreenRectSize;
413 screenRectHeight = Math.round(maxScreenRectSize / aspectRatio);
414 }
415
416 var thumbnail = document.createElement('div');
417 thumbnail.className = 'webview-thumbnail';
418 var thumbnailWidth = 3 * screenRectWidth;
419 thumbnail.style.width = thumbnailWidth + 'px';
420
421 var screenRect = document.createElement('div');
422 screenRect.className = 'screen-rect';
423 screenRect.style.width = screenRectWidth + 'px';
424 screenRect.style.height = screenRectHeight + 'px';
425 thumbnail.appendChild(screenRect);
426
427 if (!webview.empty && webview.attached) {
428 var viewRect = document.createElement('div');
429 viewRect.className = 'view-rect';
430 if (!webview.visible)
431 viewRect.classList.add('hidden');
432 function percent(ratio) {
433 return ratio * 100 + '%';
434 }
435 viewRect.style.left = percent(webview.screenX / screenWidth);
436 viewRect.style.top = percent(webview.screenY / screenHeight);
437 viewRect.style.width = percent(webview.width / screenWidth);
438 viewRect.style.height = percent(webview.height / screenHeight);
439 screenRect.appendChild(viewRect);
440 }
441
442 row.insertBefore(thumbnail, row.firstChild);
382 } 443 }
383 444
384 function addTargetToList(data, list, properties) { 445 function addTargetToList(data, list, properties) {
385 var row = document.createElement('div'); 446 var row = document.createElement('div');
386 row.className = 'row'; 447 row.className = 'row';
387 448
449 var subrowBox = document.createElement('div');
450 row.appendChild(subrowBox);
451
388 var subrow = document.createElement('div'); 452 var subrow = document.createElement('div');
389 subrow.className = 'subrow'; 453 subrow.className = 'subrow main';
390 row.appendChild(subrow); 454 subrowBox.appendChild(subrow);
391 455
392 var description = null; 456 var description = null;
393 for (var j = 0; j < properties.length; j++) { 457 for (var j = 0; j < properties.length; j++)
394 if (properties[j] != 'description') 458 subrow.appendChild(formatValue(data, properties[j]));
395 subrow.appendChild(formatValue(data, properties[j]));
396 else if (data['description']) {
397 try {
398 description = JSON.parse(data['description']);
399 } catch (e) {}
400 }
401 }
402 459
403 if (description) 460 if (description)
404 addWebViewDescription(description, row); 461 addWebViewDescription(description, subrowBox);
405 462
406 row.appendChild(createActionLink( 463 var actionBox = document.createElement('div');
407 'inspect', inspect.bind(null, data), data.hasNoUniqueId)); 464 actionBox.className = 'actions';
465 subrowBox.appendChild(actionBox);
466
467 addActionLink(row, 'inspect', inspect.bind(null, data), data.hasNoUniqueId);
408 468
409 list.appendChild(row); 469 list.appendChild(row);
410 return row; 470 return row;
411 } 471 }
412 472
413 function createActionLink(text, handler, opt_disabled) { 473 function addActionLink(row, text, handler, opt_disabled) {
414 var link = document.createElement('a'); 474 var link = document.createElement('a');
415 if (opt_disabled) 475 if (opt_disabled)
416 link.classList.add('disabled'); 476 link.classList.add('disabled');
417 else 477 else
418 link.classList.remove('disabled'); 478 link.classList.remove('disabled');
419 479
420 link.setAttribute('href', '#'); 480 link.setAttribute('href', '#');
421 link.textContent = text; 481 link.textContent = text;
422 link.addEventListener('click', handler, true); 482 link.addEventListener('click', handler, true);
423 return link; 483 row.querySelector('.actions').appendChild(link);
424 } 484 }
425 485
426 486
427 function initPortForwarding() { 487 function initPortForwarding() {
428 $('port-forwarding-enable').addEventListener('change', enablePortForwarding); 488 $('port-forwarding-enable').addEventListener('change', enablePortForwarding);
429 489
430 $('port-forwarding-config-open').addEventListener( 490 $('port-forwarding-config-open').addEventListener(
431 'click', openPortForwardingConfig); 491 'click', openPortForwardingConfig);
432 $('port-forwarding-config-close').addEventListener( 492 $('port-forwarding-config-close').addEventListener(
433 'click', closePortForwardingConfig); 493 'click', closePortForwardingConfig);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 if (line.querySelector('.invalid')) 708 if (line.querySelector('.invalid'))
649 return; 709 return;
650 line.classList.remove('fresh'); 710 line.classList.remove('fresh');
651 var freshLine = createEmptyConfigLine(); 711 var freshLine = createEmptyConfigLine();
652 line.parentNode.appendChild(freshLine); 712 line.parentNode.appendChild(freshLine);
653 if (opt_selectNew) 713 if (opt_selectNew)
654 freshLine.querySelector('.port').focus(); 714 freshLine.querySelector('.port').focus();
655 } 715 }
656 716
657 document.addEventListener('DOMContentLoaded', onload); 717 document.addEventListener('DOMContentLoaded', onload);
OLDNEW
« no previous file with comments | « chrome/browser/resources/inspect/inspect.css ('k') | chrome/browser/ui/webui/inspect_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698