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

Side by Side Diff: Source/devtools/front_end/InspectorView.js

Issue 186763002: DevTools: Small refactoring of InspectorView (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address vsevik's comments #2 Created 6 years, 9 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 | « no previous file | 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 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 if (!WebInspector.isWin() || (!this._openBracketIdentifiers[event.keyIde ntifier] && !this._closeBracketIdentifiers[event.keyIdentifier])) { 320 if (!WebInspector.isWin() || (!this._openBracketIdentifiers[event.keyIde ntifier] && !this._closeBracketIdentifiers[event.keyIdentifier])) {
321 this._keyDownInternal(event); 321 this._keyDownInternal(event);
322 return; 322 return;
323 } 323 }
324 324
325 this._keyDownTimer = setTimeout(this._keyDownInternal.bind(this, event), 0); 325 this._keyDownTimer = setTimeout(this._keyDownInternal.bind(this, event), 0);
326 }, 326 },
327 327
328 _keyDownInternal: function(event) 328 _keyDownInternal: function(event)
329 { 329 {
330 if (this._openBracketIdentifiers[event.keyIdentifier]) { 330 var direction = 0;
331 var isRotateLeft = !event.shiftKey && !event.altKey;
332 if (isRotateLeft) {
333 var panelOrder = this._tabbedPane.allTabs();
334 var index = panelOrder.indexOf(this.currentPanel().name);
335 index = (index === 0) ? panelOrder.length - 1 : index - 1;
336 this.showPanel(panelOrder[index]);
337 event.consume(true);
338 return;
339 }
340 331
341 var isGoBack = event.altKey; 332 if (this._openBracketIdentifiers[event.keyIdentifier])
342 if (isGoBack && this._canGoBackInHistory()) { 333 direction = -1;
343 this._goBackInHistory(); 334
344 event.consume(true); 335 if (this._closeBracketIdentifiers[event.keyIdentifier])
345 } 336 direction = 1;
337
338 if (!direction)
339 return;
340
341 if (!event.shiftKey && !event.altKey) {
342 this._changePanelInDirection(direction);
343 event.consume(true);
346 return; 344 return;
347 } 345 }
348 346
349 if (this._closeBracketIdentifiers[event.keyIdentifier]) { 347 if (event.altKey && this._moveInHistory(direction))
350 var isRotateRight = !event.shiftKey && !event.altKey; 348 event.consume(true)
351 if (isRotateRight) {
352 var panelOrder = this._tabbedPane.allTabs();
353 var index = panelOrder.indexOf(this.currentPanel().name);
354 index = (index + 1) % panelOrder.length;
355 this.showPanel(panelOrder[index]);
356 event.consume(true);
357 return;
358 }
359
360 var isGoForward = event.altKey;
361 if (isGoForward && this._canGoForwardInHistory()) {
362 this._goForwardInHistory();
363 event.consume(true);
364 }
365 return;
366 }
367 }, 349 },
368 350
369 _canGoBackInHistory: function() 351 _changePanelInDirection: function(direction)
370 { 352 {
371 return this._historyIterator > 0; 353 var panelOrder = this._tabbedPane.allTabs();
354 var index = panelOrder.indexOf(this.currentPanel().name);
355 index = (index + panelOrder.length + direction) % panelOrder.length;
356 this.showPanel(panelOrder[index]);
372 }, 357 },
373 358
374 _goBackInHistory: function() 359 _moveInHistory: function(move)
375 { 360 {
361 var newIndex = this._historyIterator + move;
362 if (newIndex >= this._history.length || newIndex < 0)
363 return false;
364
376 this._inHistory = true; 365 this._inHistory = true;
377 this.setCurrentPanel(WebInspector.panels[this._history[--this._historyIt erator]]); 366 this._historyIterator = newIndex;
367 this.setCurrentPanel(WebInspector.panels[this._history[this._historyIter ator]]);
378 delete this._inHistory; 368 delete this._inHistory;
379 },
380 369
381 _canGoForwardInHistory: function() 370 return true;
382 {
383 return this._historyIterator < this._history.length - 1;
384 },
385
386 _goForwardInHistory: function()
387 {
388 this._inHistory = true;
389 this.setCurrentPanel(WebInspector.panels[this._history[++this._historyIt erator]]);
390 delete this._inHistory;
391 }, 371 },
392 372
393 _pushToHistory: function(panelName) 373 _pushToHistory: function(panelName)
394 { 374 {
395 if (this._inHistory) 375 if (this._inHistory)
396 return; 376 return;
397 377
398 this._history.splice(this._historyIterator + 1, this._history.length - t his._historyIterator - 1); 378 this._history.splice(this._historyIterator + 1, this._history.length - t his._historyIterator - 1);
399 if (!this._history.length || this._history[this._history.length - 1] !== panelName) 379 if (!this._history.length || this._history[this._history.length - 1] !== panelName)
400 this._history.push(panelName); 380 this._history.push(panelName);
401 this._historyIterator = this._history.length - 1; 381 this._historyIterator = this._history.length - 1;
402 }, 382 },
403 383
404 onResize: function() 384 onResize: function()
405 { 385 {
406 WebInspector.Dialog.modalHostRepositioned(); 386 WebInspector.Dialog.modalHostRepositioned();
407 }, 387 },
408 388
409 /** 389 /**
410 * @return {!Element} 390 * @return {!Element}
411 */ 391 */
412 topResizerElement: function() 392 topResizerElement: function()
413 { 393 {
414 return this._tabbedPane.headerElement(); 394 return this._tabbedPane.headerElement();
415 }, 395 },
416 396
397 _createImagedCounterElementIfNeeded: function(count, id, styleName)
398 {
399 if (!count)
400 return;
401
402 var imageElement = this._errorWarningCountElement.createChild("div", sty leName);
403 var counterElement = this._errorWarningCountElement.createChild("span");
404 counterElement.id = id;
405 counterElement.textContent = count;
406 },
407
417 /** 408 /**
418 * @param {number} errors 409 * @param {number} errors
419 * @param {number} warnings 410 * @param {number} warnings
420 */ 411 */
421 setErrorAndWarningCounts: function(errors, warnings) 412 setErrorAndWarningCounts: function(errors, warnings)
422 { 413 {
423 if (!errors && !warnings) { 414 this._errorWarningCountElement.classList.toggle("hidden", !errors && !wa rnings);
424 this._errorWarningCountElement.classList.add("hidden");
425 this._tabbedPane.headerResized();
426 return;
427 }
428
429 this._errorWarningCountElement.classList.remove("hidden");
430 this._errorWarningCountElement.removeChildren(); 415 this._errorWarningCountElement.removeChildren();
431 416
432 if (errors) { 417 this._createImagedCounterElementIfNeeded(errors, "error-count", "error-i con-small");
433 var errorImageElement = this._errorWarningCountElement.createChild(" div", "error-icon-small"); 418 this._createImagedCounterElementIfNeeded(warnings, "warning-count", "war ning-icon-small");
434 var errorElement = this._errorWarningCountElement.createChild("span" );
435 errorElement.id = "error-count";
436 errorElement.textContent = errors;
437 }
438 419
439 if (warnings) { 420 var errorString = errors ? WebInspector.UIString("%d error%s", errors, errors > 1 ? "s" : "") : "";
440 var warningsImageElement = this._errorWarningCountElement.createChil d("div", "warning-icon-small"); 421 var warningString = warnings ? WebInspector.UIString("%d warning%s", wa rnings, warnings > 1 ? "s" : "") : "";
441 var warningsElement = this._errorWarningCountElement.createChild("sp an"); 422 var commaString = errors && warnings ? ", " : "";
442 warningsElement.id = "warning-count"; 423 this._errorWarningCountElement.title = errorString + commaString + warni ngString;
443 warningsElement.textContent = warnings;
444 }
445
446 if (errors) {
447 if (warnings) {
448 if (errors == 1) {
449 if (warnings == 1)
450 this._errorWarningCountElement.title = WebInspector.UISt ring("%d error, %d warning", errors, warnings);
451 else
452 this._errorWarningCountElement.title = WebInspector.UISt ring("%d error, %d warnings", errors, warnings);
453 } else if (warnings == 1)
454 this._errorWarningCountElement.title = WebInspector.UIString ("%d errors, %d warning", errors, warnings);
455 else
456 this._errorWarningCountElement.title = WebInspector.UIString ("%d errors, %d warnings", errors, warnings);
457 } else if (errors == 1)
458 this._errorWarningCountElement.title = WebInspector.UIString("%d error", errors);
459 else
460 this._errorWarningCountElement.title = WebInspector.UIString("%d errors", errors);
461 } else if (warnings == 1)
462 this._errorWarningCountElement.title = WebInspector.UIString("%d war ning", warnings);
463 else if (warnings)
464 this._errorWarningCountElement.title = WebInspector.UIString("%d war nings", warnings);
465 else
466 this._errorWarningCountElement.title = null;
467
468 this._tabbedPane.headerResized(); 424 this._tabbedPane.headerResized();
469 }, 425 },
470 426
471 __proto__: WebInspector.View.prototype 427 __proto__: WebInspector.View.prototype
472 }; 428 };
473 429
474 /** 430 /**
475 * @type {!WebInspector.InspectorView} 431 * @type {!WebInspector.InspectorView}
476 */ 432 */
477 WebInspector.inspectorView; 433 WebInspector.inspectorView;
478 434
479 /** 435 /**
480 * @constructor 436 * @constructor
481 * @extends {WebInspector.View} 437 * @extends {WebInspector.View}
482 */ 438 */
483 WebInspector.RootView = function() 439 WebInspector.RootView = function()
484 { 440 {
485 WebInspector.View.call(this); 441 WebInspector.View.call(this);
486 this.markAsRoot(); 442 this.markAsRoot();
487 this.element.classList.add("fill", "root-view"); 443 this.element.classList.add("fill", "root-view");
488 this.element.setAttribute("spellcheck", false); 444 this.element.setAttribute("spellcheck", false);
489 window.addEventListener("resize", this.doResize.bind(this), true); 445 window.addEventListener("resize", this.doResize.bind(this), true);
490 }; 446 };
491 447
492 WebInspector.RootView.prototype = { 448 WebInspector.RootView.prototype = {
493 __proto__: WebInspector.View.prototype 449 __proto__: WebInspector.View.prototype
494 }; 450 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698