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

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

Issue 344443003: DevTools: Code fixes for the Closure compiler roll (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comments Created 6 years, 6 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 | « Source/devtools/front_end/ui/ShortcutRegistry.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 16 matching lines...) Expand all
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 /** 32 /**
33 * @param {!Element} element 33 * @param {!Element} element
34 * @param {?function(!MouseEvent): boolean} elementDragStart 34 * @param {?function(!MouseEvent): boolean} elementDragStart
35 * @param {function(!MouseEvent)} elementDrag 35 * @param {function(!MouseEvent)} elementDrag
36 * @param {?function(!MouseEvent)} elementDragEnd 36 * @param {?function(!MouseEvent)} elementDragEnd
37 * @param {!string} cursor 37 * @param {string} cursor
38 * @param {?string=} hoverCursor 38 * @param {?string=} hoverCursor
39 */ 39 */
40 WebInspector.installDragHandle = function(element, elementDragStart, elementDrag , elementDragEnd, cursor, hoverCursor) 40 WebInspector.installDragHandle = function(element, elementDragStart, elementDrag , elementDragEnd, cursor, hoverCursor)
41 { 41 {
42 element.addEventListener("mousedown", WebInspector.elementDragStart.bind(Web Inspector, elementDragStart, elementDrag, elementDragEnd, cursor), false); 42 element.addEventListener("mousedown", WebInspector.elementDragStart.bind(Web Inspector, elementDragStart, elementDrag, elementDragEnd, cursor), false);
43 if (hoverCursor !== null) 43 if (hoverCursor !== null)
44 element.style.cursor = hoverCursor || cursor; 44 element.style.cursor = hoverCursor || cursor;
45 } 45 }
46 46
47 /** 47 /**
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 WebInspector.GlassPane.DefaultFocusedViewStack[0].focus(); 160 WebInspector.GlassPane.DefaultFocusedViewStack[0].focus();
161 this.element.remove(); 161 this.element.remove();
162 } 162 }
163 } 163 }
164 164
165 /** 165 /**
166 * @type {!Array.<!WebInspector.View>} 166 * @type {!Array.<!WebInspector.View>}
167 */ 167 */
168 WebInspector.GlassPane.DefaultFocusedViewStack = []; 168 WebInspector.GlassPane.DefaultFocusedViewStack = [];
169 169
170 /**
171 * @param {?Node=} node
172 * @return {boolean}
173 */
170 WebInspector.isBeingEdited = function(node) 174 WebInspector.isBeingEdited = function(node)
171 { 175 {
172 if (node.nodeType !== Node.ELEMENT_NODE) 176 if (!node || node.nodeType !== Node.ELEMENT_NODE)
173 return false; 177 return false;
174 var element = /** {!Element} */ (node); 178 var element = /** {!Element} */ (node);
175 if (element.classList.contains("text-prompt") || element.nodeName === "INPUT " || element.nodeName === "TEXTAREA") 179 if (element.classList.contains("text-prompt") || element.nodeName === "INPUT " || element.nodeName === "TEXTAREA")
176 return true; 180 return true;
177 181
178 if (!WebInspector.__editingCount) 182 if (!WebInspector.__editingCount)
179 return false; 183 return false;
180 184
181 while (element) { 185 while (element) {
182 if (element.__editing) 186 if (element.__editing)
183 return true; 187 return true;
184 element = element.parentElement; 188 element = element.parentElement;
185 } 189 }
186 return false; 190 return false;
187 } 191 }
188 192
193 /**
194 * @param {!Element} element
195 * @param {boolean} value
196 * @return {boolean}
197 */
189 WebInspector.markBeingEdited = function(element, value) 198 WebInspector.markBeingEdited = function(element, value)
190 { 199 {
191 if (value) { 200 if (value) {
192 if (element.__editing) 201 if (element.__editing)
193 return false; 202 return false;
194 element.classList.add("being-edited"); 203 element.classList.add("being-edited");
195 element.__editing = true; 204 element.__editing = true;
196 WebInspector.__editingCount = (WebInspector.__editingCount || 0) + 1; 205 WebInspector.__editingCount = (WebInspector.__editingCount || 0) + 1;
197 } else { 206 } else {
198 if (!element.__editing) 207 if (!element.__editing)
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 if (kilobytes < 1024) 471 if (kilobytes < 1024)
463 return WebInspector.UIString("%.0f\u2009KB", kilobytes); 472 return WebInspector.UIString("%.0f\u2009KB", kilobytes);
464 473
465 var megabytes = kilobytes / 1024; 474 var megabytes = kilobytes / 1024;
466 if (megabytes < 100) 475 if (megabytes < 100)
467 return WebInspector.UIString("%.1f\u2009MB", megabytes); 476 return WebInspector.UIString("%.1f\u2009MB", megabytes);
468 else 477 else
469 return WebInspector.UIString("%.0f\u2009MB", megabytes); 478 return WebInspector.UIString("%.0f\u2009MB", megabytes);
470 } 479 }
471 480
481 /**
482 * @param {number} num
483 * @return {string}
484 */
472 Number.withThousandsSeparator = function(num) 485 Number.withThousandsSeparator = function(num)
473 { 486 {
474 var str = num + ""; 487 var str = num + "";
475 var re = /(\d+)(\d{3})/; 488 var re = /(\d+)(\d{3})/;
476 while (str.match(re)) 489 while (str.match(re))
477 str = str.replace(re, "$1\u2009$2"); // \u2009 is a thin space. 490 str = str.replace(re, "$1\u2009$2"); // \u2009 is a thin space.
478 return str; 491 return str;
479 } 492 }
480 493
494 /**
495 * @return {boolean}
496 */
481 WebInspector.useLowerCaseMenuTitles = function() 497 WebInspector.useLowerCaseMenuTitles = function()
482 { 498 {
483 return WebInspector.platform() === "windows"; 499 return WebInspector.platform() === "windows";
484 } 500 }
485 501
502 /**
503 * @param {string} format
504 * @param {?Array.<string>} substitutions
505 * @param {!Object.<string, function(string, ...):*>} formatters
506 * @param {string} initialValue
507 * @param {function(string, string): ?} append
508 * @return {!{formattedResult: string, unusedSubstitutions: ?Array.<string>}};
509 */
486 WebInspector.formatLocalized = function(format, substitutions, formatters, initi alValue, append) 510 WebInspector.formatLocalized = function(format, substitutions, formatters, initi alValue, append)
487 { 511 {
488 return String.format(WebInspector.UIString(format), substitutions, formatter s, initialValue, append); 512 return String.format(WebInspector.UIString(format), substitutions, formatter s, initialValue, append);
489 } 513 }
490 514
515 /**
516 * @return {string}
517 */
491 WebInspector.openLinkExternallyLabel = function() 518 WebInspector.openLinkExternallyLabel = function()
492 { 519 {
493 return WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Open l ink in new tab" : "Open Link in New Tab"); 520 return WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Open l ink in new tab" : "Open Link in New Tab");
494 } 521 }
495 522
523 /**
524 * @return {string}
525 */
496 WebInspector.copyLinkAddressLabel = function() 526 WebInspector.copyLinkAddressLabel = function()
497 { 527 {
498 return WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy l ink address" : "Copy Link Address"); 528 return WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy l ink address" : "Copy Link Address");
499 } 529 }
500 530
501 WebInspector.installPortStyles = function() 531 WebInspector.installPortStyles = function()
502 { 532 {
503 var platform = WebInspector.platform(); 533 var platform = WebInspector.platform();
504 document.body.classList.add("platform-" + platform); 534 document.body.classList.add("platform-" + platform);
505 var flavor = WebInspector.platformFlavor(); 535 var flavor = WebInspector.platformFlavor();
506 if (flavor) 536 if (flavor)
507 document.body.classList.add("platform-" + flavor); 537 document.body.classList.add("platform-" + flavor);
508 var port = WebInspector.port(); 538 var port = WebInspector.port();
509 document.body.classList.add("port-" + port); 539 document.body.classList.add("port-" + port);
510 } 540 }
511 541
512 WebInspector._windowFocused = function(event) 542 WebInspector._windowFocused = function(event)
513 { 543 {
514 if (event.target.document.nodeType === Node.DOCUMENT_NODE) 544 if (event.target.document.nodeType === Node.DOCUMENT_NODE)
515 document.body.classList.remove("inactive"); 545 document.body.classList.remove("inactive");
516 } 546 }
517 547
518 WebInspector._windowBlurred = function(event) 548 WebInspector._windowBlurred = function(event)
519 { 549 {
520 if (event.target.document.nodeType === Node.DOCUMENT_NODE) 550 if (event.target.document.nodeType === Node.DOCUMENT_NODE)
521 document.body.classList.add("inactive"); 551 document.body.classList.add("inactive");
522 } 552 }
523 553
554 /**
555 * @return {!Element}
556 */
524 WebInspector.previousFocusElement = function() 557 WebInspector.previousFocusElement = function()
525 { 558 {
526 return WebInspector._previousFocusElement; 559 return WebInspector._previousFocusElement;
527 } 560 }
528 561
562 /**
563 * @return {!Element}
564 */
529 WebInspector.currentFocusElement = function() 565 WebInspector.currentFocusElement = function()
530 { 566 {
531 return WebInspector._currentFocusElement; 567 return WebInspector._currentFocusElement;
532 } 568 }
533 569
534 WebInspector._focusChanged = function(event) 570 WebInspector._focusChanged = function(event)
535 { 571 {
536 WebInspector.setCurrentFocusElement(event.target); 572 WebInspector.setCurrentFocusElement(event.target);
537 } 573 }
538 574
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 { 656 {
621 if (WebInspector._themeStyleElement) 657 if (WebInspector._themeStyleElement)
622 WebInspector._themeStyleElement.textContent = ""; 658 WebInspector._themeStyleElement.textContent = "";
623 } 659 }
624 660
625 /** 661 /**
626 * @param {!Element} element 662 * @param {!Element} element
627 * @param {number} offset 663 * @param {number} offset
628 * @param {number} length 664 * @param {number} length
629 * @param {!Array.<!Object>=} domChanges 665 * @param {!Array.<!Object>=} domChanges
666 * @return {?Element}
630 */ 667 */
631 WebInspector.highlightSearchResult = function(element, offset, length, domChange s) 668 WebInspector.highlightSearchResult = function(element, offset, length, domChange s)
632 { 669 {
633 var result = WebInspector.highlightSearchResults(element, [new WebInspector. SourceRange(offset, length)], domChanges); 670 var result = WebInspector.highlightSearchResults(element, [new WebInspector. SourceRange(offset, length)], domChanges);
634 return result.length ? result[0] : null; 671 return result.length ? result[0] : null;
635 } 672 }
636 673
637 /** 674 /**
638 * @param {!Element} element 675 * @param {!Element} element
639 * @param {!Array.<!WebInspector.SourceRange>} resultRanges 676 * @param {!Array.<!WebInspector.SourceRange>} resultRanges
640 * @param {!Array.<!Object>=} changes 677 * @param {!Array.<!Object>=} changes
678 * @return {!Array.<!Element>}
641 */ 679 */
642 WebInspector.highlightSearchResults = function(element, resultRanges, changes) 680 WebInspector.highlightSearchResults = function(element, resultRanges, changes)
643 { 681 {
644 return WebInspector.highlightRangesWithStyleClass(element, resultRanges, "hi ghlighted-search-result", changes); 682 return WebInspector.highlightRangesWithStyleClass(element, resultRanges, "hi ghlighted-search-result", changes);
645 } 683 }
646 684
647 /** 685 /**
648 * @param {!Element} element 686 * @param {!Element} element
649 * @param {string} className 687 * @param {string} className
650 */ 688 */
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 window.addEventListener("focus", WebInspector._windowFocused, false); 902 window.addEventListener("focus", WebInspector._windowFocused, false);
865 window.addEventListener("blur", WebInspector._windowBlurred, false); 903 window.addEventListener("blur", WebInspector._windowBlurred, false);
866 document.addEventListener("focus", WebInspector._focusChanged, true); 904 document.addEventListener("focus", WebInspector._focusChanged, true);
867 document.addEventListener("blur", WebInspector._documentBlurred, true); 905 document.addEventListener("blur", WebInspector._documentBlurred, true);
868 window.removeEventListener("DOMContentLoaded", windowLoaded, false); 906 window.removeEventListener("DOMContentLoaded", windowLoaded, false);
869 } 907 }
870 908
871 window.addEventListener("DOMContentLoaded", windowLoaded, false); 909 window.addEventListener("DOMContentLoaded", windowLoaded, false);
872 910
873 })(); 911 })();
OLDNEW
« no previous file with comments | « Source/devtools/front_end/ui/ShortcutRegistry.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698