diff options
| author | Steve Block <steveblock@google.com> | 2010-02-02 14:57:50 +0000 |
|---|---|---|
| committer | Steve Block <steveblock@google.com> | 2010-02-04 15:06:55 +0000 |
| commit | d0825bca7fe65beaee391d30da42e937db621564 (patch) | |
| tree | 7461c49eb5844ffd1f35d1ba2c8b7584c1620823 /WebCore/inspector/front-end/SourceView.js | |
| parent | 3db770bd97c5a59b6c7574ca80a39e5a51c1defd (diff) | |
| download | external_webkit-d0825bca7fe65beaee391d30da42e937db621564.zip external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.gz external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.bz2 | |
Merge webkit.org at r54127 : Initial merge by git
Change-Id: Ib661abb595522f50ea406f72d3a0ce17f7193c82
Diffstat (limited to 'WebCore/inspector/front-end/SourceView.js')
| -rw-r--r-- | WebCore/inspector/front-end/SourceView.js | 108 |
1 files changed, 15 insertions, 93 deletions
diff --git a/WebCore/inspector/front-end/SourceView.js b/WebCore/inspector/front-end/SourceView.js index 7ab7b5b..292b8af 100644 --- a/WebCore/inspector/front-end/SourceView.js +++ b/WebCore/inspector/front-end/SourceView.js @@ -28,54 +28,35 @@ WebInspector.SourceView = function(resource) { - // Set the sourceFrame first since WebInspector.ResourceView will set headersVisible - // and our override of headersVisible needs the sourceFrame. - this.sourceFrame = new WebInspector.SourceFrame(null, this._addBreakpoint.bind(this)); - WebInspector.ResourceView.call(this, resource); - resource.addEventListener("finished", this._resourceLoadingFinished, this); - this.element.addStyleClass("source"); + this.sourceFrame = new WebInspector.SourceFrame(this.contentElement, this._addBreakpoint.bind(this)); + resource.addEventListener("finished", this._resourceLoadingFinished, this); this._frameNeedsSetup = true; - - this.contentElement.appendChild(this.sourceFrame.element); - - var gutterElement = document.createElement("div"); - gutterElement.className = "webkit-line-gutter-backdrop"; - this.element.appendChild(gutterElement); } WebInspector.SourceView.prototype = { - set headersVisible(x) - { - if (x === this._headersVisible) - return; - - var superSetter = WebInspector.ResourceView.prototype.__lookupSetter__("headersVisible"); - if (superSetter) - superSetter.call(this, x); - - this.sourceFrame.autoSizesToFitContentHeight = x; - }, - show: function(parentElement) { WebInspector.ResourceView.prototype.show.call(this, parentElement); this.setupSourceFrameIfNeeded(); + this.sourceFrame.visible = true; + this.resize(); }, hide: function() { WebInspector.View.prototype.hide.call(this); + this.sourceFrame.visible = false; this._currentSearchResultIndex = -1; }, resize: function() { - if (this.sourceFrame.autoSizesToFitContentHeight) - this.sourceFrame.sizeToFitContentHeight(); + if (this.sourceFrame) + this.sourceFrame.resize(); }, detach: function() @@ -96,28 +77,13 @@ WebInspector.SourceView.prototype = { this.attach(); delete this._frameNeedsSetup; - this.sourceFrame.addEventListener("content loaded", this._contentLoaded, this); - InspectorFrontendHost.addResourceSourceToFrame(this.resource.identifier, this.sourceFrame.element); + WebInspector.getResourceContent(this.resource.identifier, this._contentLoaded.bind(this)); }, - _contentLoaded: function() + _contentLoaded: function(content) { - delete this._frameNeedsSetup; - this.sourceFrame.removeEventListener("content loaded", this._contentLoaded, this); - - if (this.resource.type === WebInspector.Resource.Type.Script - || this.resource.mimeType === "application/json" - || this.resource.mimeType === "application/javascript" - || /\.js(on)?$/.test(this.resource.lastPathComponent) ) { - this.sourceFrame.addEventListener("syntax highlighting complete", this._syntaxHighlightingComplete, this); - this.sourceFrame.syntaxHighlightJavascript(); - } else if (this.resource.type === WebInspector.Resource.Type.Stylesheet - || this.resource.mimeType === "text/css" - || /\.css$/.test(this.resource.lastPathComponent) ) { - this.sourceFrame.addEventListener("syntax highlighting complete", this._syntaxHighlightingComplete, this); - this.sourceFrame.syntaxHighlightCSS(); - } else - this._sourceFrameSetupFinished(); + this.sourceFrame.setContent(this.resource.mimeType, content); + this._sourceFrameSetupFinished(); }, _resourceLoadingFinished: function(event) @@ -155,6 +121,7 @@ WebInspector.SourceView.prototype = { { this._currentSearchResultIndex = -1; this._searchResults = []; + this.sourceFrame.clearSelection(); delete this._delayedFindSearchMatches; }, @@ -163,44 +130,11 @@ WebInspector.SourceView.prototype = { // Call searchCanceled since it will reset everything we need before doing a new search. this.searchCanceled(); - var lineQueryRegex = /(^|\s)(?:#|line:\s*)(\d+)(\s|$)/i; - var lineQueryMatch = query.match(lineQueryRegex); - if (lineQueryMatch) { - var lineToSearch = parseInt(lineQueryMatch[2]); - - // If there was a space before and after the line query part, replace with a space. - // Otherwise replace with an empty string to eat the prefix or postfix space. - var lineQueryReplacement = (lineQueryMatch[1] && lineQueryMatch[3] ? " " : ""); - var filterlessQuery = query.replace(lineQueryRegex, lineQueryReplacement); - } - this._searchFinishedCallback = finishedCallback; function findSearchMatches(query, finishedCallback) { - if (isNaN(lineToSearch)) { - // Search the whole document since there was no line to search. - this._searchResults = (InspectorFrontendHost.search(this.sourceFrame.element.contentDocument, query) || []); - } else { - var sourceRow = this.sourceFrame.sourceRow(lineToSearch); - if (sourceRow) { - if (filterlessQuery) { - // There is still a query string, so search for that string in the line. - this._searchResults = (InspectorFrontendHost.search(sourceRow, filterlessQuery) || []); - } else { - // Match the whole line, since there was no remaining query string to match. - var rowRange = this.sourceFrame.element.contentDocument.createRange(); - rowRange.selectNodeContents(sourceRow); - this._searchResults = [rowRange]; - } - } - - // Attempt to search for the whole query, just incase it matches a color like "#333". - var wholeQueryMatches = InspectorFrontendHost.search(this.sourceFrame.element.contentDocument, query); - if (wholeQueryMatches) - this._searchResults = this._searchResults.concat(wholeQueryMatches); - } - + this._searchResults = this.sourceFrame.findSearchMatches(query); if (this._searchResults) finishedCallback(this, this._searchResults.length); } @@ -287,29 +221,17 @@ WebInspector.SourceView.prototype = { if (!foundRange) return; - var selection = this.sourceFrame.element.contentWindow.getSelection(); - selection.removeAllRanges(); - selection.addRange(foundRange); - - if (foundRange.startContainer.scrollIntoViewIfNeeded) - foundRange.startContainer.scrollIntoViewIfNeeded(true); - else if (foundRange.startContainer.parentNode) - foundRange.startContainer.parentNode.scrollIntoViewIfNeeded(true); + this.sourceFrame.setSelection(foundRange); }, _sourceFrameSetupFinished: function() { this._sourceFrameSetup = true; + this.resize(); if (this._delayedFindSearchMatches) { this._delayedFindSearchMatches(); delete this._delayedFindSearchMatches; } - }, - - _syntaxHighlightingComplete: function(event) - { - this._sourceFrameSetupFinished(); - this.sourceFrame.removeEventListener("syntax highlighting complete", null, this); } } |
