Changeset 28002 in webkit
- Timestamp:
- Nov 24, 2007 2:35:52 PM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r27999 r28002 1 2007-11-24 Timothy Hatcher <timothy@apple.com> 2 3 Reviewed by Adam Roben. 4 5 Bug 16121: Web Inspector needs helper functions that pass a 'this' object to 6 addEventListener and setTimeout 7 http://bugs.webkit.org/show_bug.cgi?id=16121 8 9 Add Function.prototype.bind. This helper will return a wrapper function 10 that will call the original function with the supplied arguments 11 and using the supplied 'this' object. 12 13 * page/inspector/Database.js: Remove a use of setTimeout by 14 inheriting some common functions from Resource. 15 * page/inspector/DatabasePanel.js: Use the new bind function. 16 * page/inspector/ConsolePanel.js: Ditto. 17 * page/inspector/DocumentPanel.js: Ditto. 18 * page/inspector/NetworkPanel.js: Ditto. 19 * page/inspector/PropertiesSection.js: Ditto. 20 * page/inspector/Resource.js: Ditto. 21 * page/inspector/SidebarPane.js: Ditto. 22 * page/inspector/inspector.html: Moved Database.js after Resource.js, 23 now that Database.js uses it. 24 * page/inspector/inspector.js: Use the new bind function. Also 25 removed a setTimeout used for the localized strings code. There is 26 now a load event listener added to the localized strings script 27 element that will call WebInspector.loaded. 28 * page/inspector/utilities.js: Add Function.prototype.bind. 29 1 30 2007-11-24 Timothy Hatcher <timothy@apple.com> 2 31 -
trunk/WebCore/page/inspector/ConsolePanel.js
r27883 r28002 40 40 this.element.appendChild(this.messageList); 41 41 42 var console = this; 43 this.messageList.addEventListener("click", function(event) { console.messageListClicked(event) }, true); 42 this.messageList.addEventListener("click", this.messageListClicked.bind(this), true); 44 43 45 44 this.consolePrompt = document.createElement("textarea"); … … 47 46 this.element.appendChild(this.consolePrompt); 48 47 49 this.consolePrompt.addEventListener("keydown", function(event) { console.promptKeypress(event) }, false);48 this.consolePrompt.addEventListener("keydown", this.promptKeypress.bind(this), false); 50 49 } 51 50 -
trunk/WebCore/page/inspector/Database.js
r26787 r28002 96 96 }, 97 97 98 updateTitleSoon: function()99 {100 if (this.updateTitleTimeout)101 return;102 var _self = this;103 this.updateTitleTimeout = setTimeout(function () { _self.updateTitle() }, 0);104 },105 106 98 updateTitle: function() 107 99 { … … 129 121 }, 130 122 131 select: function() 132 { 133 WebInspector.navigateToResource(this); 134 }, 135 136 deselect: function() 137 { 138 this.listItem.deselect(true); 139 if (WebInspector.currentPanel === this._panel) 140 WebInspector.currentPanel = null; 141 }, 142 143 attach: function() 144 { 145 this.panel.attach(); 146 }, 147 148 detach: function() 149 { 150 if (this._panel) 151 this.panel.detach(); 152 } 123 // Inherit the other functions from the Resource prototype. 124 updateTitleSoon: WebInspector.Resource.prototype.updateTitleSoon, 125 select: WebInspector.Resource.prototype.select, 126 deselect: WebInspector.Resource.prototype.deselect, 127 attach: WebInspector.Resource.prototype.attach, 128 detach: WebInspector.Resource.prototype.detach 153 129 } -
trunk/WebCore/page/inspector/DatabasePanel.js
r27892 r28002 41 41 this.element.appendChild(this.queryPromptElement); 42 42 43 var panel = this; 44 this.queryPromptElement.addEventListener("keydown", function(event) { panel.queryInputKeypress(event) }, false); 43 this.queryPromptElement.addEventListener("keydown", this.queryInputKeypress.bind(this), false); 45 44 46 45 this.queryPromptHistory = []; … … 53 52 queryView.contentElement.appendChild(queryView.commandListElement); 54 53 54 var panel = this; 55 55 queryView.show = function() 56 56 { … … 70 70 browseView.reloadTableElement.className = "database-table-reload"; 71 71 browseView.reloadTableElement.title = WebInspector.UIString("Reload"); 72 browseView.reloadTableElement.addEventListener("click", function() { panel.updateTableList(); panel.updateTableBrowser() }, false);72 browseView.reloadTableElement.addEventListener("click", this.reloadClicked.bind(this), false); 73 73 74 74 browseView.show = function() … … 136 136 }, 137 137 138 reloadClicked: function() 139 { 140 this.updateTableList(); 141 this.updateTableBrowser(); 142 }, 143 138 144 updateTableList: function() 139 145 { … … 146 152 var changeTableFunction = function() 147 153 { 148 var browseView = panel.views.browse;149 154 var index = browseView.tableSelectElement.selectedIndex; 150 155 if (index != -1) -
trunk/WebCore/page/inspector/DocumentPanel.js
r27999 r28002 84 84 domView.sidebarResizeElement = document.createElement("div"); 85 85 domView.sidebarResizeElement.className = "sidebar-resizer-vertical sidebar-resizer-vertical-right"; 86 domView.sidebarResizeElement.addEventListener("mousedown", function(event) { panel.rightSidebarResizerDragStart(event) }, false);86 domView.sidebarResizeElement.addEventListener("mousedown", this.rightSidebarResizerDragStart.bind(this), false); 87 87 88 88 domView.contentElement.appendChild(domView.sideContentElement); … … 385 385 if (document.body.offsetWidth <= 0) { 386 386 // The stylesheet hasn't loaded yet, so we need to update later. 387 var panel = this; 388 setTimeout(function() { panel.updateBreadcrumbSizes() }, 0); 387 setTimeout(this.updateBreadcrumbSizes.bind(this), 0); 389 388 return; 390 389 } … … 756 755 if (document.body.offsetWidth <= 0) { 757 756 // The stylesheet hasn't loaded yet, so we need to update later. 758 var element = this; 759 setTimeout(function() { element.updateSelection() }, 0); 757 setTimeout(this.updateSelection.bind(this), 0); 760 758 return; 761 759 } … … 772 770 onattach: function() 773 771 { 774 var element = this; 775 this.listItemElement.addEventListener("mousedown", function(event) { element.onmousedown(event) }, false); 772 this.listItemElement.addEventListener("mousedown", this.onmousedown.bind(this), false); 776 773 }, 777 774 -
trunk/WebCore/page/inspector/NetworkPanel.js
r27999 r28002 47 47 this.resourcesElement = document.createElement("div"); 48 48 this.resourcesElement.className = "network-resources"; 49 var panel = this; 50 this.resourcesElement.addEventListener("click", function(event) { return panel.onClick(event) }, false); 49 this.resourcesElement.addEventListener("click", this.resourcesClicked.bind(this), false); 51 50 this.timelineElement.appendChild(this.resourcesElement); 52 51 … … 61 60 this.graphModeSelectElement = document.createElement("select"); 62 61 this.graphModeSelectElement.className = "network-graph-mode"; 63 this.graphModeSelectElement.addEventListener("change", function(event) { return panel.onModeChange(event) }, false);62 this.graphModeSelectElement.addEventListener("change", this.changeGraphMode.bind(this), false); 64 63 this.graphLabelElement.appendChild(this.graphModeSelectElement); 65 64 this.graphLabelElement.appendChild(document.createElement("br")); … … 113 112 }, 114 113 115 onClick: function(event)114 resourcesClicked: function(event) 116 115 { 117 116 // If the click wasn't inside a network resource row, ignore it. … … 135 134 }, 136 135 137 onModeChange: function(event)136 changeGraphMode: function(event) 138 137 { 139 138 this.updateSummaryGraph(); … … 231 230 if ("sortTimelineEntriesTimeout" in this) 232 231 return; 233 234 var _self = this; 235 this.sortTimelineEntriesTimeout = setTimeout(function () { _self.sortTimelineEntriesIfNeeded() }, 500); 232 this.sortTimelineEntriesTimeout = setTimeout(this.sortTimelineEntriesIfNeeded.bind(this), 500); 236 233 }, 237 234 … … 284 281 if ("updateTimelineDividersTimeout" in this) 285 282 return; 286 287 var _self = this; 288 this.updateTimelineDividersTimeout = setTimeout(function () { _self.updateTimelineDividersIfNeeded() }, 500); 283 this.updateTimelineDividersTimeout = setTimeout(this.updateTimelineDividersIfNeeded.bind(this), 500); 289 284 }, 290 285 … … 303 298 if (document.body.offsetWidth <= 0) { 304 299 // The stylesheet hasn't loaded yet, so we need to update later. 305 var panel = this; 306 setTimeout(function () { panel.updateTimelineDividersIfNeeded() }, 0); 300 setTimeout(this.updateTimelineDividersIfNeeded.bind(this), 0); 307 301 return; 308 302 } … … 338 332 if ("refreshAllTimelineEntriesTimeout" in this) 339 333 return; 340 341 var _self = this; 342 this.refreshAllTimelineEntriesTimeout = setTimeout(function () { _self.refreshAllTimelineEntries() }, 500, skipBoundryUpdate, skipTimelineSort, immediate); 334 this.refreshAllTimelineEntriesTimeout = setTimeout(this.refreshAllTimelineEntries.bind(this), 500, skipBoundryUpdate, skipTimelineSort, immediate); 343 335 }, 344 336 … … 593 585 if ("updateSummaryGraphTimeout" in this) 594 586 return; 595 596 var _self = this; 597 this.updateSummaryGraphTimeout = setTimeout(function () { _self.updateSummaryGraph() }, 500); 587 this.updateSummaryGraphTimeout = setTimeout(this.updateSummaryGraph.bind(this), 500); 598 588 }, 599 589 … … 704 694 this.fileElement.insertBefore(this.tipButtonElement, this.fileElement.firstChild); 705 695 706 var entry = this; 707 this.tipButtonElement.addEventListener("click", function(event) { entry.toggleTipBalloon(event) }, false ); 696 this.tipButtonElement.addEventListener("click", this.toggleTipBalloon.bind(this), false ); 708 697 709 698 this.areaElement = document.createElement("div"); -
trunk/WebCore/page/inspector/PropertiesSection.js
r27575 r28002 43 43 this.headerElement.appendChild(this.titleElement); 44 44 this.headerElement.appendChild(this.subtitleElement); 45 46 var section = this; 47 this.headerElement.addEventListener("click", function() { section.expanded = !section.expanded; }, false); 45 this.headerElement.addEventListener("click", this.toggleExpanded.bind(this), false); 48 46 49 47 this.propertiesElement = document.createElement("ol"); … … 133 131 this._expanded = false; 134 132 this.element.removeStyleClass("expanded"); 133 }, 134 135 toggleExpanded: function() 136 { 137 this.expanded = !this.expanded; 135 138 } 136 139 } -
trunk/WebCore/page/inspector/Resource.js
r27883 r28002 497 497 if (this.updateTitleTimeout) 498 498 return; 499 var _self = this; 500 this.updateTitleTimeout = setTimeout(function () { _self.updateTitle() }, 0); 499 this.updateTitleTimeout = setTimeout(this.updateTitle.bind(this), 0); 501 500 }, 502 501 -
trunk/WebCore/page/inspector/SidebarPane.js
r27431 r28002 34 34 this.titleElement = document.createElement("div"); 35 35 this.titleElement.className = "title"; 36 37 var pane = this; 38 this.titleElement.addEventListener("click", function() { pane.expanded = !pane.expanded; }, false); 36 this.titleElement.addEventListener("click", this.toggleExpanded.bind(this), false); 39 37 40 38 this.bodyElement = document.createElement("div"); … … 117 115 if (this.oncollapse) 118 116 this.oncollapse(this); 117 }, 118 119 toggleExpanded: function() 120 { 121 this.expanded = !this.expanded; 119 122 } 120 123 } -
trunk/WebCore/page/inspector/inspector.html
r27999 r28002 34 34 <script type="text/javascript" src="treeoutline.js"></script> 35 35 <script type="text/javascript" src="inspector.js"></script> 36 <script type="text/javascript" src="Database.js"></script>37 36 <script type="text/javascript" src="Resource.js"></script> 38 37 <script type="text/javascript" src="ResourceCategory.js"></script> 38 <script type="text/javascript" src="Database.js"></script> 39 39 <script type="text/javascript" src="SidebarPane.js"></script> 40 40 <script type="text/javascript" src="PropertiesSection.js"></script> -
trunk/WebCore/page/inspector/inspector.js
r27935 r28002 211 211 } 212 212 213 WebInspector.setupLocalizedString = function(event)214 {215 var localizedStringsURL = InspectorController.localizedStringsURL();216 if (localizedStringsURL) {217 var localizedStringsScriptElement = document.createElement("script");218 localizedStringsScriptElement.type = "text/javascript";219 localizedStringsScriptElement.src = localizedStringsURL;220 document.getElementsByTagName("head").item(0).appendChild(localizedStringsScriptElement);221 }222 }223 224 213 WebInspector.loaded = function() 225 214 { … … 260 249 this.addMainEventListeners(document); 261 250 262 window.addEventListener("unload", function(event) { WebInspector.windowUnload(event) }, true);263 window.addEventListener("resize", function(event) { WebInspector.windowResize(event) }, true);264 265 document.addEventListener("mousedown", function(event) { WebInspector.changeFocus(event) }, true);266 document.addEventListener("focus", function(event) { WebInspector.changeFocus(event) }, true);267 document.addEventListener("keypress", function(event) { WebInspector.documentKeypress(event) }, true);268 document.addEventListener("beforecopy", function(event) { WebInspector.documentCanCopy(event) }, true);269 document.addEventListener("copy", function(event) { WebInspector.documentCopy(event) }, true);251 window.addEventListener("unload", this.windowUnload.bind(this), true); 252 window.addEventListener("resize", this.windowResize.bind(this), true); 253 254 document.addEventListener("mousedown", this.changeFocus.bind(this), true); 255 document.addEventListener("focus", this.changeFocus.bind(this), true); 256 document.addEventListener("keypress", this.documentKeypress.bind(this), true); 257 document.addEventListener("beforecopy", this.documentCanCopy.bind(this), true); 258 document.addEventListener("copy", this.documentCopy.bind(this), true); 270 259 271 260 document.getElementById("back").title = WebInspector.UIString("Show previous panel."); … … 274 263 document.getElementById("search").setAttribute("placeholder", WebInspector.UIString("Search")); 275 264 276 document.getElementById("back").addEventListener("click", function(event) { WebInspector.back() }, true);277 document.getElementById("forward").addEventListener("click", function(event) { WebInspector.forward() }, true);265 document.getElementById("back").addEventListener("click", this.back.bind(this), true); 266 document.getElementById("forward").addEventListener("click", this.forward.bind(this), true); 278 267 this.updateBackForwardButtons(); 279 268 280 document.getElementById("attachToggle").addEventListener("click", function(event) { WebInspector.toggleAttach() }, true); 281 document.getElementById("statusToggle").addEventListener("click", function(event) { WebInspector.toggleStatusArea() }, true); 282 document.getElementById("sidebarResizeWidget").addEventListener("mousedown", WebInspector.sidebarResizerDragStart, true); 283 document.getElementById("sidebarResizer").addEventListener("mousedown", WebInspector.sidebarResizerDragStart, true); 284 document.getElementById("searchResultsResizer").addEventListener("mousedown", WebInspector.searchResultsResizerDragStart, false); 269 document.getElementById("attachToggle").addEventListener("click", this.toggleAttach.bind(this), true); 270 document.getElementById("statusToggle").addEventListener("click", this.toggleStatusArea.bind(this), true); 271 272 document.getElementById("sidebarResizeWidget").addEventListener("mousedown", this.sidebarResizerDragStart, true); 273 document.getElementById("sidebarResizer").addEventListener("mousedown", this.sidebarResizerDragStart, true); 274 document.getElementById("searchResultsResizer").addEventListener("mousedown", this.searchResultsResizerDragStart, true); 285 275 286 276 document.body.addStyleClass("detached"); … … 291 281 var windowLoaded = function() 292 282 { 293 WebInspector.setupLocalizedString(event); 294 295 // Delay calling loaded to give time for the localized strings file to load. 296 // Calling it too early will cause localized string lookups to fail. 297 setTimeout(function() { WebInspector.loaded() }, 0); 283 var localizedStringsURL = InspectorController.localizedStringsURL(); 284 if (localizedStringsURL) { 285 var localizedStringsScriptElement = document.createElement("script"); 286 localizedStringsScriptElement.addEventListener("load", WebInspector.loaded.bind(WebInspector), false); 287 localizedStringsScriptElement.type = "text/javascript"; 288 localizedStringsScriptElement.src = localizedStringsURL; 289 document.getElementsByTagName("head").item(0).appendChild(localizedStringsScriptElement); 290 } else 291 WebInspector.loaded(); 298 292 299 293 delete windowLoaded; -
trunk/WebCore/page/inspector/utilities.js
r27981 r28002 80 80 { 81 81 var properties = []; 82 for (var prop in obj) {82 for (var prop in obj) 83 83 properties.push(prop); 84 }85 86 84 properties.sort(); 87 85 return properties; 86 } 87 88 Function.prototype.bind = function(thisObject) 89 { 90 var func = this; 91 var args = Array.prototype.slice.call(arguments, 1); 92 return function() { return func.apply(thisObject, args.concat(Array.prototype.slice.call(arguments, 0))) }; 88 93 } 89 94 … … 141 146 if (node.nodeName.toLowerCase() === nodeName.toLowerCase()) 142 147 return node; 143 144 148 return null; 145 149 } … … 150 154 if (node.nodeType === Node.ELEMENT_NODE && node.hasStyleClass(className)) 151 155 return node; 152 153 156 return null; 154 157 } … … 158 161 if (!this.parentNode) 159 162 return null; 160 161 163 return this.parentNode.firstParentOrSelfWithClass(className); 162 164 }
Note: See TracChangeset
for help on using the changeset viewer.