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

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

Issue 663083004: [DevTools] Remove remaining usages of global properties. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed review comments Created 6 years, 2 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/TextPrompt.js ('k') | Source/devtools/front_end/ui/View.js » ('j') | 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 targetDocument.addEventListener("mouseup", WebInspector._elementDragEnd, tru e); 78 targetDocument.addEventListener("mouseup", WebInspector._elementDragEnd, tru e);
79 targetDocument.addEventListener("mouseout", WebInspector._mouseOutWhileDragg ing, true); 79 targetDocument.addEventListener("mouseout", WebInspector._mouseOutWhileDragg ing, true);
80 80
81 targetDocument.body.style.cursor = cursor; 81 targetDocument.body.style.cursor = cursor;
82 82
83 event.preventDefault(); 83 event.preventDefault();
84 } 84 }
85 85
86 WebInspector._mouseOutWhileDragging = function() 86 WebInspector._mouseOutWhileDragging = function()
87 { 87 {
88 var document = WebInspector._mouseOutWhileDraggingTargetDocument;
88 WebInspector._unregisterMouseOutWhileDragging(); 89 WebInspector._unregisterMouseOutWhileDragging();
89 WebInspector._elementDraggingGlassPane = new WebInspector.GlassPane(); 90 WebInspector._elementDraggingGlassPane = new WebInspector.GlassPane(document );
90 } 91 }
91 92
92 WebInspector._unregisterMouseOutWhileDragging = function() 93 WebInspector._unregisterMouseOutWhileDragging = function()
93 { 94 {
94 if (!WebInspector._mouseOutWhileDraggingTargetDocument) 95 if (!WebInspector._mouseOutWhileDraggingTargetDocument)
95 return; 96 return;
96 WebInspector._mouseOutWhileDraggingTargetDocument.removeEventListener("mouse out", WebInspector._mouseOutWhileDragging, true); 97 WebInspector._mouseOutWhileDraggingTargetDocument.removeEventListener("mouse out", WebInspector._mouseOutWhileDragging, true);
97 delete WebInspector._mouseOutWhileDraggingTargetDocument; 98 delete WebInspector._mouseOutWhileDraggingTargetDocument;
98 } 99 }
99 100
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 136
136 WebInspector._cancelDragEvents(/** @type {!MouseEvent} */ (event)); 137 WebInspector._cancelDragEvents(/** @type {!MouseEvent} */ (event));
137 138
138 event.preventDefault(); 139 event.preventDefault();
139 if (elementDragEnd) 140 if (elementDragEnd)
140 elementDragEnd(/** @type {!MouseEvent} */ (event)); 141 elementDragEnd(/** @type {!MouseEvent} */ (event));
141 } 142 }
142 143
143 /** 144 /**
144 * @constructor 145 * @constructor
146 * @param {!Document} document
145 */ 147 */
146 WebInspector.GlassPane = function() 148 WebInspector.GlassPane = function(document)
147 { 149 {
148 this.element = createElement("div"); 150 this.element = createElement("div");
149 this.element.style.cssText = "position:absolute;top:0;bottom:0;left:0;right: 0;background-color:transparent;z-index:1000;"; 151 this.element.style.cssText = "position:absolute;top:0;bottom:0;left:0;right: 0;background-color:transparent;z-index:1000;";
150 this.element.id = "glass-pane"; 152 this.element.id = "glass-pane";
151 document.body.appendChild(this.element); 153 document.body.appendChild(this.element);
152 WebInspector._glassPane = this; 154 WebInspector._glassPane = this;
153 } 155 }
154 156
155 WebInspector.GlassPane.prototype = { 157 WebInspector.GlassPane.prototype = {
156 dispose: function() 158 dispose: function()
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 /** 317 /**
316 * @param {!Event} event 318 * @param {!Event} event
317 * @param {!Element} element 319 * @param {!Element} element
318 * @param {function(string,string)=} finishHandler 320 * @param {function(string,string)=} finishHandler
319 * @param {function(string)=} suggestionHandler 321 * @param {function(string)=} suggestionHandler
320 * @param {function(string, number, string):string=} customNumberHandler 322 * @param {function(string, number, string):string=} customNumberHandler
321 * @return {boolean} 323 * @return {boolean}
322 */ 324 */
323 WebInspector.handleElementValueModifications = function(event, element, finishHa ndler, suggestionHandler, customNumberHandler) 325 WebInspector.handleElementValueModifications = function(event, element, finishHa ndler, suggestionHandler, customNumberHandler)
324 { 326 {
327 /**
328 * @return {?Range}
329 * @suppressGlobalPropertiesCheck
330 */
331 function createRange()
332 {
333 return document.createRange();
334 }
335
325 var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyId entifier === "Down" || event.type === "mousewheel"); 336 var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyId entifier === "Down" || event.type === "mousewheel");
326 var pageKeyPressed = (event.keyIdentifier === "PageUp" || event.keyIdentifie r === "PageDown"); 337 var pageKeyPressed = (event.keyIdentifier === "PageUp" || event.keyIdentifie r === "PageDown");
327 if (!arrowKeyOrMouseWheelEvent && !pageKeyPressed) 338 if (!arrowKeyOrMouseWheelEvent && !pageKeyPressed)
328 return false; 339 return false;
329 340
330 var selection = window.getSelection(); 341 var selection = window.getSelection();
331 if (!selection.rangeCount) 342 if (!selection.rangeCount)
332 return false; 343 return false;
333 344
334 var selectionRange = selection.getRangeAt(0); 345 var selectionRange = selection.getRangeAt(0);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 replacementString = customNumberHandler ? customNumberHandler(prefix , number, suffix) : prefix + number + suffix; 378 replacementString = customNumberHandler ? customNumberHandler(prefix , number, suffix) : prefix + number + suffix;
368 } 379 }
369 } 380 }
370 381
371 if (replacementString) { 382 if (replacementString) {
372 var replacementTextNode = createTextNode(replacementString); 383 var replacementTextNode = createTextNode(replacementString);
373 384
374 wordRange.deleteContents(); 385 wordRange.deleteContents();
375 wordRange.insertNode(replacementTextNode); 386 wordRange.insertNode(replacementTextNode);
376 387
377 var finalSelectionRange = document.createRange(); 388 var finalSelectionRange = createRange();
378 finalSelectionRange.setStart(replacementTextNode, 0); 389 finalSelectionRange.setStart(replacementTextNode, 0);
379 finalSelectionRange.setEnd(replacementTextNode, replacementString.length ); 390 finalSelectionRange.setEnd(replacementTextNode, replacementString.length );
380 391
381 selection.removeAllRanges(); 392 selection.removeAllRanges();
382 selection.addRange(finalSelectionRange); 393 selection.addRange(finalSelectionRange);
383 394
384 event.handled = true; 395 event.handled = true;
385 event.preventDefault(); 396 event.preventDefault();
386 397
387 if (finishHandler) 398 if (finishHandler)
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 } 571 }
561 572
562 /** 573 /**
563 * @return {string} 574 * @return {string}
564 */ 575 */
565 WebInspector.manageBlackboxingButtonLabel = function() 576 WebInspector.manageBlackboxingButtonLabel = function()
566 { 577 {
567 return WebInspector.UIString("Manage framework blackboxing..."); 578 return WebInspector.UIString("Manage framework blackboxing...");
568 } 579 }
569 580
570 WebInspector.installPortStyles = function() 581 /**
582 * @param {!Document} document
583 */
584 WebInspector.installPortStyles = function(document)
571 { 585 {
572 var platform = WebInspector.platform(); 586 var platform = WebInspector.platform();
573 document.body.classList.add("platform-" + platform); 587 document.body.classList.add("platform-" + platform);
574 var flavor = WebInspector.platformFlavor(); 588 var flavor = WebInspector.platformFlavor();
575 if (flavor) 589 if (flavor)
576 document.body.classList.add("platform-" + flavor); 590 document.body.classList.add("platform-" + flavor);
577 var port = WebInspector.port(); 591 var port = WebInspector.port();
578 document.body.classList.add("port-" + port); 592 document.body.classList.add("port-" + port);
579 } 593 }
580 594
581 WebInspector._windowFocused = function(event) 595 /**
596 * @param {!Document} document
597 * @param {!Event} event
598 */
599 WebInspector._windowFocused = function(document, event)
582 { 600 {
583 if (event.target.document.nodeType === Node.DOCUMENT_NODE) 601 if (event.target.document.nodeType === Node.DOCUMENT_NODE)
584 document.body.classList.remove("inactive"); 602 document.body.classList.remove("inactive");
585 } 603 }
586 604
587 WebInspector._windowBlurred = function(event) 605 /**
606 * @param {!Document} document
607 * @param {!Event} event
608 */
609 WebInspector._windowBlurred = function(document, event)
588 { 610 {
589 if (event.target.document.nodeType === Node.DOCUMENT_NODE) 611 if (event.target.document.nodeType === Node.DOCUMENT_NODE)
590 document.body.classList.add("inactive"); 612 document.body.classList.add("inactive");
591 } 613 }
592 614
593 /** 615 /**
594 * @return {!Element} 616 * @return {!Element}
595 */ 617 */
596 WebInspector.previousFocusElement = function() 618 WebInspector.previousFocusElement = function()
597 { 619 {
598 return WebInspector._previousFocusElement; 620 return WebInspector._previousFocusElement;
599 } 621 }
600 622
601 /** 623 /**
602 * @return {!Element} 624 * @return {!Element}
603 */ 625 */
604 WebInspector.currentFocusElement = function() 626 WebInspector.currentFocusElement = function()
605 { 627 {
606 return WebInspector._currentFocusElement; 628 return WebInspector._currentFocusElement;
607 } 629 }
608 630
609 WebInspector._focusChanged = function(event) 631 WebInspector._focusChanged = function(event)
610 { 632 {
611 WebInspector.setCurrentFocusElement(event.target); 633 WebInspector.setCurrentFocusElement(event.target);
612 } 634 }
613 635
614 WebInspector._documentBlurred = function(event) 636 /**
637 * @param {!Document} document
638 * @param {!Event} event
639 */
640 WebInspector._documentBlurred = function(document, event)
615 { 641 {
616 // We want to know when currentFocusElement loses focus to nowhere. 642 // We want to know when currentFocusElement loses focus to nowhere.
617 // This is the case when event.relatedTarget is null (no element is being fo cused) 643 // This is the case when event.relatedTarget is null (no element is being fo cused)
618 // and document.activeElement is reset to default (this is not a window blur ). 644 // and document.activeElement is reset to default (this is not a window blur ).
619 if (!event.relatedTarget && document.activeElement === document.body) 645 if (!event.relatedTarget && document.activeElement === document.body)
620 WebInspector.setCurrentFocusElement(null); 646 WebInspector.setCurrentFocusElement(null);
621 } 647 }
622 648
623 WebInspector._textInputTypes = ["text", "search", "tel", "url", "email", "passwo rd"].keySet(); 649 WebInspector._textInputTypes = ["text", "search", "tel", "url", "email", "passwo rd"].keySet();
624 WebInspector._isTextEditingElement = function(element) 650 WebInspector._isTextEditingElement = function(element)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 } else if (WebInspector._previousFocusElement) 684 } else if (WebInspector._previousFocusElement)
659 WebInspector._previousFocusElement.blur(); 685 WebInspector._previousFocusElement.blur();
660 } 686 }
661 687
662 WebInspector.restoreFocusFromElement = function(element) 688 WebInspector.restoreFocusFromElement = function(element)
663 { 689 {
664 if (element && element.isSelfOrAncestor(WebInspector.currentFocusElement())) 690 if (element && element.isSelfOrAncestor(WebInspector.currentFocusElement()))
665 WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement()) ; 691 WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement()) ;
666 } 692 }
667 693
668 WebInspector.setToolbarColors = function(backgroundColor, color) 694 /**
695 * @param {!Document} document
696 * @param {string} backgroundColor
697 * @param {string} color
698 */
699 WebInspector.setToolbarColors = function(document, backgroundColor, color)
669 { 700 {
670 if (!WebInspector._themeStyleElement) { 701 if (!WebInspector._themeStyleElement) {
671 WebInspector._themeStyleElement = createElement("style"); 702 WebInspector._themeStyleElement = createElement("style");
672 document.head.appendChild(WebInspector._themeStyleElement); 703 document.head.appendChild(WebInspector._themeStyleElement);
673 } 704 }
674 var parsedColor = WebInspector.Color.parse(color); 705 var parsedColor = WebInspector.Color.parse(color);
675 var shadowColor = parsedColor ? parsedColor.invert().setAlpha(0.33).toString (WebInspector.Color.Format.RGBA) : "white"; 706 var shadowColor = parsedColor ? parsedColor.invert().setAlpha(0.33).toString (WebInspector.Color.Format.RGBA) : "white";
676 var prefix = WebInspector.isMac() ? "body:not(.undocked)" : ""; 707 var prefix = WebInspector.isMac() ? "body:not(.undocked)" : "";
677 WebInspector._themeStyleElement.textContent = 708 WebInspector._themeStyleElement.textContent =
678 String.sprintf( 709 String.sprintf(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 } 753 }
723 754
724 /** 755 /**
725 * @param {!Element} element 756 * @param {!Element} element
726 */ 757 */
727 WebInspector.removeSearchResultsHighlight = function(element) 758 WebInspector.removeSearchResultsHighlight = function(element)
728 { 759 {
729 var highlightBits = element.querySelectorAll(".highlighted-search-result"); 760 var highlightBits = element.querySelectorAll(".highlighted-search-result");
730 for (var i = 0; i < highlightBits.length; ++i) { 761 for (var i = 0; i < highlightBits.length; ++i) {
731 var span = highlightBits[i]; 762 var span = highlightBits[i];
732 span.parentElement.replaceChild(document.createTextNode(span.textContent ), span); 763 span.parentElement.replaceChild(createTextNode(span.textContent), span);
733 } 764 }
734 } 765 }
735 766
736 /** 767 /**
737 * @param {!Element} element 768 * @param {!Element} element
738 * @param {string} className 769 * @param {string} className
739 */ 770 */
740 WebInspector.runCSSAnimationOnce = function(element, className) 771 WebInspector.runCSSAnimationOnce = function(element, className)
741 { 772 {
742 function animationEndCallback() 773 function animationEndCallback()
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 this._element.removeEventListener("mousedown", this._longClickData.mouse Down, false); 1107 this._element.removeEventListener("mousedown", this._longClickData.mouse Down, false);
1077 this._element.removeEventListener("mouseout", this._longClickData.reset, false); 1108 this._element.removeEventListener("mouseout", this._longClickData.reset, false);
1078 this._element.removeEventListener("mouseup", this._longClickData.mouseUp , false); 1109 this._element.removeEventListener("mouseup", this._longClickData.mouseUp , false);
1079 this._element.addEventListener("click", this._longClickData.reset, true) ; 1110 this._element.addEventListener("click", this._longClickData.reset, true) ;
1080 delete this._longClickData; 1111 delete this._longClickData;
1081 }, 1112 },
1082 1113
1083 __proto__: WebInspector.Object.prototype 1114 __proto__: WebInspector.Object.prototype
1084 } 1115 }
1085 1116
1086 WebInspector.initializeUIUtils = function() 1117 /**
1118 * @param {!Window} window
1119 */
1120 WebInspector.initializeUIUtils = function(window)
1087 { 1121 {
1088 window.addEventListener("focus", WebInspector._windowFocused, false); 1122 window.addEventListener("focus", WebInspector._windowFocused.bind(WebInspect or, window.document), false);
1089 window.addEventListener("blur", WebInspector._windowBlurred, false); 1123 window.addEventListener("blur", WebInspector._windowBlurred.bind(WebInspecto r, window.document), false);
1090 document.addEventListener("focus", WebInspector._focusChanged, true); 1124 window.document.addEventListener("focus", WebInspector._focusChanged, true);
1091 document.addEventListener("blur", WebInspector._documentBlurred, true); 1125 window.document.addEventListener("blur", WebInspector._documentBlurred.bind( WebInspector, window.document), true);
1092 } 1126 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/ui/TextPrompt.js ('k') | Source/devtools/front_end/ui/View.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698