[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

pfeldman at chromium.org pfeldman at chromium.org
Wed Dec 22 16:32:52 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 0628eaf0014076873fe37ad1e569fa1f00b1dbef
Author: pfeldman at chromium.org <pfeldman at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Nov 25 18:01:55 2010 +0000

    2010-11-25  Pavel Feldman  <pfeldman at chromium.org>
    
            Reviewed by Yury Semikhatsky.
    
            Web Inspector: highlight diffs of revisions against base version.
            https://bugs.webkit.org/show_bug.cgi?id=50088
    
            * inspector/front-end/CSSStyleModel.js:
            (WebInspector.CSSStyleModel.prototype._styleSheetChanged.callback):
            (WebInspector.CSSStyleModel.prototype._styleSheetChanged):
            * inspector/front-end/ResourcesPanel.js:
            (WebInspector.ResourcesPanel):
            (WebInspector.ResourcesPanel.prototype.show):
            (WebInspector.ResourcesPanel.prototype._showResourceView.callback):
            (WebInspector.ResourcesPanel.prototype._showResourceView):
            (WebInspector.ResourcesPanel.prototype._applyDiffMarkup):
            (WebInspector.FrameResourceTreeElement.prototype._contentChanged):
            * inspector/front-end/SourceFrame.js:
            (WebInspector.SourceFrame.prototype.markDiff):
            (WebInspector.SourceFrame.prototype._createViewerIfNeeded):
            (WebInspector.SourceFrame.prototype._updateDiffDecorations.addDecorations):
            (WebInspector.SourceFrame.prototype._updateDiffDecorations):
            (WebInspector.SourceFrame.prototype._removeDiffDecorations):
            * inspector/front-end/SourceView.js:
            * inspector/front-end/textViewer.css:
            (.webkit-line-number):
            (.diff-container .webkit-added-line .webkit-line-content):
            (.diff-container .webkit-removed-line .webkit-line-content):
            (.diff-container .webkit-changed-line .webkit-line-content):
            * inspector/front-end/utilities.js:
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@72737 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 3bc7c0a..2f50ded 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,34 @@
+2010-11-25  Pavel Feldman  <pfeldman at chromium.org>
+
+        Reviewed by Yury Semikhatsky.
+
+        Web Inspector: highlight diffs of revisions against base version.
+        https://bugs.webkit.org/show_bug.cgi?id=50088
+
+        * inspector/front-end/CSSStyleModel.js:
+        (WebInspector.CSSStyleModel.prototype._styleSheetChanged.callback):
+        (WebInspector.CSSStyleModel.prototype._styleSheetChanged):
+        * inspector/front-end/ResourcesPanel.js:
+        (WebInspector.ResourcesPanel):
+        (WebInspector.ResourcesPanel.prototype.show):
+        (WebInspector.ResourcesPanel.prototype._showResourceView.callback):
+        (WebInspector.ResourcesPanel.prototype._showResourceView):
+        (WebInspector.ResourcesPanel.prototype._applyDiffMarkup):
+        (WebInspector.FrameResourceTreeElement.prototype._contentChanged):
+        * inspector/front-end/SourceFrame.js:
+        (WebInspector.SourceFrame.prototype.markDiff):
+        (WebInspector.SourceFrame.prototype._createViewerIfNeeded):
+        (WebInspector.SourceFrame.prototype._updateDiffDecorations.addDecorations):
+        (WebInspector.SourceFrame.prototype._updateDiffDecorations):
+        (WebInspector.SourceFrame.prototype._removeDiffDecorations):
+        * inspector/front-end/SourceView.js:
+        * inspector/front-end/textViewer.css:
+        (.webkit-line-number):
+        (.diff-container .webkit-added-line .webkit-line-content):
+        (.diff-container .webkit-removed-line .webkit-line-content):
+        (.diff-container .webkit-changed-line .webkit-line-content):
+        * inspector/front-end/utilities.js:
+
 2010-11-25  Sheriff Bot  <webkit.review.bot at gmail.com>
 
         Unreviewed, rolling out r72732.
diff --git a/WebCore/inspector/front-end/CSSStyleModel.js b/WebCore/inspector/front-end/CSSStyleModel.js
index 4b6cfb2..baf44c9 100644
--- a/WebCore/inspector/front-end/CSSStyleModel.js
+++ b/WebCore/inspector/front-end/CSSStyleModel.js
@@ -163,7 +163,7 @@ WebInspector.CSSStyleModel.prototype = {
         function callback(href, content)
         {
             var resource = WebInspector.resourceManager.resourceForURL(href);
-            if (resource)
+            if (resource && resource.type === WebInspector.Resource.Type.Stylesheet)
                 resource.content = content;
         }
         InspectorBackend.getStyleSheetText2(styleSheetId, callback);
diff --git a/WebCore/inspector/front-end/ResourcesPanel.js b/WebCore/inspector/front-end/ResourcesPanel.js
index a194f53..ff99ebc 100644
--- a/WebCore/inspector/front-end/ResourcesPanel.js
+++ b/WebCore/inspector/front-end/ResourcesPanel.js
@@ -64,6 +64,7 @@ WebInspector.ResourcesPanel = function(database)
 
     this.storageViews = document.createElement("div");
     this.storageViews.id = "storage-views";
+    this.storageViews.className = "diff-container";
     this.element.appendChild(this.storageViews);
 
     this.storageViewStatusBarItemsContainer = document.createElement("div");
@@ -100,7 +101,7 @@ WebInspector.ResourcesPanel.prototype = {
         WebInspector.Panel.prototype.show.call(this);
 
         if (this.visibleView instanceof WebInspector.ResourceView)
-            this.visibleView.show(this.storageViews);
+            this._showResourceView(this.visibleView.resource);
 
         if (this._initializedDefaultSelection)
             return;
@@ -366,9 +367,46 @@ WebInspector.ResourcesPanel.prototype = {
     _showResourceView: function(resource)
     {
         var view = WebInspector.ResourceManager.resourceViewForResource(resource);
+
+        // Consider rendering diff markup here.
+        if (resource._baseRevision && resource.content && view instanceof WebInspector.SourceView) {
+            function callback(baseContent)
+            {
+                if (baseContent)
+                    this._applyDiffMarkup(view, baseContent, resource.content);
+            }
+            resource._baseRevision.requestContent(callback.bind(this));
+        }
         this._innerShowView(view);
     },
 
+    _applyDiffMarkup: function(view, baseContent, newContent) {
+        var oldLines = baseContent.split("\n");
+        var newLines = newContent.split("\n");
+
+        var diff = Array.diff(oldLines, newLines);
+
+        var diffData = {};
+        diffData.added = [];
+        diffData.removed = [];
+        diffData.changed = [];
+
+        var offset = 0;
+        var right = diff.right;
+        for (var i = 0; i < right.length; ++i) {
+            if (typeof right[i] === "string") {
+                if (right.length > i + 1 && right[i + 1].row === i + 1 - offset)
+                    diffData.changed.push(i);
+                else {
+                    diffData.added.push(i);
+                    offset++;
+                }
+            } else
+                offset = i - right[i].row;
+        }
+        view.sourceFrame.markDiff(diffData);
+    },
+
     showDatabase: function(database, tableName)
     {
         if (!database)
@@ -1066,11 +1104,16 @@ WebInspector.FrameResourceTreeElement.prototype = {
             }
             this._resource.addEventListener("finished", finished);
         }
+
+        if (!this._resource._baseRevision)
+            this._resource._baseRevision = revisionResource;
+        else
+            revisionResource._baseRevision = this._resource._baseRevision;
+
         if (event.data.oldContent)
             revisionResource.setInitialContent(event.data.oldContent);
         this.insertChild(new WebInspector.ResourceRevisionTreeElement(this._storagePanel, revisionResource, event.data.oldContentTimestamp), 0);
 
-        
         var oldView = WebInspector.ResourceManager.existingResourceViewForResource(this._resource);
         if (oldView) {
             var newView = WebInspector.ResourceManager.recreateResourceView(this._resource);
diff --git a/WebCore/inspector/front-end/SourceFrame.js b/WebCore/inspector/front-end/SourceFrame.js
index 66a0005..8e077cd 100644
--- a/WebCore/inspector/front-end/SourceFrame.js
+++ b/WebCore/inspector/front-end/SourceFrame.js
@@ -87,6 +87,16 @@ WebInspector.SourceFrame.prototype = {
             this._updateExecutionLine(previousLine);
     },
 
+    markDiff: function(diffData)
+    {
+        if (this._diffLines && this._textViewer)
+            this._removeDiffDecorations();
+
+        this._diffLines = diffData;
+        if (this._textViewer)
+            this._updateDiffDecorations();
+    },
+
     revealLine: function(lineNumber)
     {
         if (this._textViewer)
@@ -210,6 +220,7 @@ WebInspector.SourceFrame.prototype = {
         this._addExistingMessagesToSource();
         this._addExistingBreakpointsToSource();
         this._updateExecutionLine();
+        this._updateDiffDecorations();
         this._textViewer.resize();
 
         if (this._lineNumberToReveal) {
@@ -330,6 +341,33 @@ WebInspector.SourceFrame.prototype = {
             this._textViewer.addDecoration(this._executionLine - 1, "webkit-execution-line");
     },
 
+    _updateDiffDecorations: function()
+    {
+        if (!this._diffLines)
+            return;
+
+        function addDecorations(textViewer, lines, className)
+        {
+            for (var i = 0; i < lines.length; ++i)
+                textViewer.addDecoration(lines[i], className);
+        }
+        addDecorations(this._textViewer, this._diffLines.added, "webkit-added-line");
+        addDecorations(this._textViewer, this._diffLines.removed, "webkit-removed-line");
+        addDecorations(this._textViewer, this._diffLines.changed, "webkit-changed-line");
+    },
+
+    _removeDiffDecorations: function()
+    {
+        function removeDecorations(textViewer, lines, className)
+        {
+            for (var i = 0; i < lines.length; ++i)
+                textViewer.removeDecoration(lines[i], className);
+        }
+        removeDecorations(this._textViewer, this._diffLines.added, "webkit-added-line");
+        removeDecorations(this._textViewer, this._diffLines.removed, "webkit-removed-line");
+        removeDecorations(this._textViewer, this._diffLines.changed, "webkit-changed-line");
+    },
+
     _addExistingMessagesToSource: function()
     {
         var length = this._messages.length;
diff --git a/WebCore/inspector/front-end/SourceView.js b/WebCore/inspector/front-end/SourceView.js
index b624ee3..e764cf8 100644
--- a/WebCore/inspector/front-end/SourceView.js
+++ b/WebCore/inspector/front-end/SourceView.js
@@ -80,6 +80,7 @@ WebInspector.SourceView.prototype = {
         this.sourceFrame.scrollTop = scrollTop;
     },
 
+
     setupSourceFrameIfNeeded: function()
     {
         if (!this._frameNeedsSetup)
diff --git a/WebCore/inspector/front-end/textViewer.css b/WebCore/inspector/front-end/textViewer.css
index 8a96b1f..bee9fe5 100644
--- a/WebCore/inspector/front-end/textViewer.css
+++ b/WebCore/inspector/front-end/textViewer.css
@@ -64,8 +64,8 @@
     vertical-align: top;
     word-break: normal;
     -webkit-user-select: none;
-	padding-right: 4px;
-	padding-left: 6px;
+    padding-right: 4px;
+    padding-left: 6px;
 }
 
 .webkit-line-number-outer {
@@ -141,6 +141,19 @@
     outline: 1px solid rgb(64, 115, 244);
 }
 
+.diff-container .webkit-added-line .webkit-line-content {
+    background-color: rgb(220, 255, 220);
+}
+
+.diff-container .webkit-removed-line .webkit-line-content {
+    background-color: rgb(255, 220, 220);
+    text-decoration: line-through;
+}
+
+.diff-container .webkit-changed-line .webkit-line-content {
+    background-color: rgb(220, 220, 255);
+}
+
 .webkit-search-result {
     -webkit-border-radius: 4px;
     padding: 2px 2px 2px 3px;
diff --git a/WebCore/inspector/front-end/utilities.js b/WebCore/inspector/front-end/utilities.js
index 3aff6bb..f978c6f 100644
--- a/WebCore/inspector/front-end/utilities.js
+++ b/WebCore/inspector/front-end/utilities.js
@@ -24,6 +24,9 @@
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Contains diff method based on Javascript Diff Algorithm By John Resig
+ * http://ejohn.org/files/jsdiff.js (released under the MIT license).
  */
 
 Function.prototype.bind = function(thisObject)
@@ -731,6 +734,51 @@ Array.prototype.keySet = function()
     return keys;
 }
 
+Array.diff = function(left, right)
+{
+    var o = left;
+    var n = right;
+
+    var ns = {};
+    var os = {};
+
+    for (var i = 0; i < n.length; i++) {
+        if (ns[n[i]] == null)
+            ns[n[i]] = { rows: [], o: null };
+        ns[n[i]].rows.push(i);
+    }
+
+    for (var i = 0; i < o.length; i++) {
+        if (os[o[i]] == null)
+            os[o[i]] = { rows: [], n: null };
+        os[o[i]].rows.push(i);
+    }
+
+    for (var i in ns) {
+        if (ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1) {
+            n[ns[i].rows[0]] = { text: n[ns[i].rows[0]], row: os[i].rows[0] };
+            o[os[i].rows[0]] = { text: o[os[i].rows[0]], row: ns[i].rows[0] };
+        }
+    }
+
+    for (var i = 0; i < n.length - 1; i++) {
+        if (n[i].text != null && n[i + 1].text == null && n[i].row + 1 < o.length && o[n[i].row + 1].text == null && n[i + 1] == o[n[i].row + 1]) {
+            n[i + 1] = { text: n[i + 1], row: n[i].row + 1 };
+            o[n[i].row + 1] = { text: o[n[i].row + 1], row: i + 1 };
+        }
+    }
+
+    for (var i = n.length - 1; i > 0; i--) {
+        if (n[i].text != null && n[i - 1].text == null && n[i].row > 0 && o[n[i].row - 1].text == null && 
+            n[i - 1] == o[n[i].row - 1]) {
+            n[i - 1] = { text: n[i - 1], row: n[i].row - 1 };
+            o[n[i].row - 1] = { text: o[n[i].row - 1], row: i - 1 };
+        }
+    }
+
+    return { left: o, right: n };
+}
+
 Array.convert = function(list)
 {
     // Cast array-like object to an array.

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list