Title: [123852] trunk
Revision
123852
Author
[email protected]
Date
2012-07-27 01:50:31 -0700 (Fri, 27 Jul 2012)

Log Message

Web Inspector: Move formatting support from _javascript_Source to UISourceCode.
https://bugs.webkit.org/show_bug.cgi?id=92373

Reviewed by Pavel Feldman.

Source/WebCore:

Moved formatting support from _javascript_Source to UISourceCode.
Extracted Formatter interface from ScriptFormatter and created IdentityFormatter
implememntation and Formatter.createFormatter(contentType) formatter factory.
Introduced virtual formattedChanged() method on UISourceCode.

* inspector/front-end/_javascript_Source.js:
(WebInspector._javascript_Source):
(WebInspector._javascript_Source.prototype.uiLocationToRawLocation):
(WebInspector._javascript_Source.prototype.breakpointStorageId):
(WebInspector._javascript_Source.prototype.searchInContent):
(WebInspector._javascript_Source.prototype.formattedChanged):
* inspector/front-end/ScriptFormatter.js:
(WebInspector.Formatter):
(WebInspector.Formatter.createFormatter):
(WebInspector.Formatter.locationToPosition):
(WebInspector.Formatter.positionToLocation):
(WebInspector.Formatter.prototype.formatContent):
(WebInspector.ScriptFormatter):
(WebInspector.IdentityFormatter):
(WebInspector.IdentityFormatter.prototype.formatContent):
(WebInspector.FormatterSourceMappingImpl.prototype.originalToFormatted):
(WebInspector.FormatterSourceMappingImpl.prototype.formattedToOriginal):
* inspector/front-end/UISourceCode.js:
(WebInspector.UISourceCode):
(WebInspector.UISourceCode.prototype.requestContent):
(WebInspector.UISourceCode.prototype._fireContentAvailable):
(WebInspector.UISourceCode.prototype.uiLocationToRawLocation):
(WebInspector.UISourceCode.prototype.overrideLocation):
(WebInspector.UISourceCode.prototype.togglingFormatter):
(WebInspector.UISourceCode.prototype.formatted):
(WebInspector.UISourceCode.prototype.setFormatted.if):
(WebInspector.UISourceCode.prototype.setFormatted.didGetContent.formattedChanged):
(WebInspector.UISourceCode.prototype.setFormatted.didGetContent):
(WebInspector.UISourceCode.prototype.setFormatted):
(WebInspector.UISourceCode.prototype.createFormatter):
(WebInspector.UISourceCode.prototype.formattedChanged):

LayoutTests:

* inspector/debugger/script-formatter.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (123851 => 123852)


--- trunk/LayoutTests/ChangeLog	2012-07-27 08:41:19 UTC (rev 123851)
+++ trunk/LayoutTests/ChangeLog	2012-07-27 08:50:31 UTC (rev 123852)
@@ -1,3 +1,12 @@
+2012-07-27  Vsevolod Vlasov  <[email protected]>
+
+        Web Inspector: Move formatting support from _javascript_Source to UISourceCode.
+        https://bugs.webkit.org/show_bug.cgi?id=92373
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/debugger/script-formatter.html:
+
 2012-07-27  János Badics  <[email protected]>
 
         [Qt] Unreviewed, rebaseline for tests introduced in r123790

Modified: trunk/LayoutTests/inspector/debugger/script-formatter.html (123851 => 123852)


--- trunk/LayoutTests/inspector/debugger/script-formatter.html	2012-07-27 08:41:19 UTC (rev 123851)
+++ trunk/LayoutTests/inspector/debugger/script-formatter.html	2012-07-27 08:50:31 UTC (rev 123852)
@@ -48,9 +48,9 @@
                 {
                     var originalPosition = source.indexOf(string);
                     InspectorTest.assertTrue(originalPosition !== -1);
-                    var originalLocation = WebInspector.ScriptFormatter.positionToLocation(source.lineEndings(), originalPosition);
+                    var originalLocation = WebInspector.Formatter.positionToLocation(source.lineEndings(), originalPosition);
                     var formattedLocation = mapping.originalToFormatted(originalLocation[0], originalLocation[1]);
-                    var formattedPosition = WebInspector.ScriptFormatter.locationToPosition(formattedSource.lineEndings(), formattedLocation[0], formattedLocation[1]);
+                    var formattedPosition = WebInspector.Formatter.locationToPosition(formattedSource.lineEndings(), formattedLocation[0], formattedLocation[1]);
                     var expectedFormattedPosition = formattedSource.indexOf(string);
                     InspectorTest.assertEquals(expectedFormattedPosition, formattedPosition, "wrong mapping for <" + string + ">");
                 }

Modified: trunk/Source/WebCore/ChangeLog (123851 => 123852)


--- trunk/Source/WebCore/ChangeLog	2012-07-27 08:41:19 UTC (rev 123851)
+++ trunk/Source/WebCore/ChangeLog	2012-07-27 08:50:31 UTC (rev 123852)
@@ -1,3 +1,47 @@
+2012-07-27  Vsevolod Vlasov  <[email protected]>
+
+        Web Inspector: Move formatting support from _javascript_Source to UISourceCode.
+        https://bugs.webkit.org/show_bug.cgi?id=92373
+
+        Reviewed by Pavel Feldman.
+
+        Moved formatting support from _javascript_Source to UISourceCode.
+        Extracted Formatter interface from ScriptFormatter and created IdentityFormatter
+        implememntation and Formatter.createFormatter(contentType) formatter factory.
+        Introduced virtual formattedChanged() method on UISourceCode.
+
+        * inspector/front-end/_javascript_Source.js:
+        (WebInspector._javascript_Source):
+        (WebInspector._javascript_Source.prototype.uiLocationToRawLocation):
+        (WebInspector._javascript_Source.prototype.breakpointStorageId):
+        (WebInspector._javascript_Source.prototype.searchInContent):
+        (WebInspector._javascript_Source.prototype.formattedChanged):
+        * inspector/front-end/ScriptFormatter.js:
+        (WebInspector.Formatter):
+        (WebInspector.Formatter.createFormatter):
+        (WebInspector.Formatter.locationToPosition):
+        (WebInspector.Formatter.positionToLocation):
+        (WebInspector.Formatter.prototype.formatContent):
+        (WebInspector.ScriptFormatter):
+        (WebInspector.IdentityFormatter):
+        (WebInspector.IdentityFormatter.prototype.formatContent):
+        (WebInspector.FormatterSourceMappingImpl.prototype.originalToFormatted):
+        (WebInspector.FormatterSourceMappingImpl.prototype.formattedToOriginal):
+        * inspector/front-end/UISourceCode.js:
+        (WebInspector.UISourceCode):
+        (WebInspector.UISourceCode.prototype.requestContent):
+        (WebInspector.UISourceCode.prototype._fireContentAvailable):
+        (WebInspector.UISourceCode.prototype.uiLocationToRawLocation):
+        (WebInspector.UISourceCode.prototype.overrideLocation):
+        (WebInspector.UISourceCode.prototype.togglingFormatter):
+        (WebInspector.UISourceCode.prototype.formatted):
+        (WebInspector.UISourceCode.prototype.setFormatted.if):
+        (WebInspector.UISourceCode.prototype.setFormatted.didGetContent.formattedChanged):
+        (WebInspector.UISourceCode.prototype.setFormatted.didGetContent):
+        (WebInspector.UISourceCode.prototype.setFormatted):
+        (WebInspector.UISourceCode.prototype.createFormatter):
+        (WebInspector.UISourceCode.prototype.formattedChanged):
+
 2012-07-27  Vivek Galatage  <[email protected]>
 
         Page object should ascertain EditorClient to be non-null

Modified: trunk/Source/WebCore/inspector/front-end/_javascript_Source.js (123851 => 123852)


--- trunk/Source/WebCore/inspector/front-end/_javascript_Source.js	2012-07-27 08:41:19 UTC (rev 123851)
+++ trunk/Source/WebCore/inspector/front-end/_javascript_Source.js	2012-07-27 08:50:31 UTC (rev 123852)
@@ -40,127 +40,22 @@
 {
     WebInspector.UISourceCode.call(this, url, resource, contentProvider, sourceMapping);
     this._isEditable = isEditable;
-
-    this._formatterMapping = new WebInspector.IdentityFormatterSourceMapping();
-    // FIXME: postpone breakpoints restore to after the mapping has been established.
-    setTimeout(function() {
-        if (!this._formatted)
-            WebInspector.breakpointManager.restoreBreakpoints(this);
-    }.bind(this), 0);
 }
 
 WebInspector._javascript_Source.prototype = {
     /**
-     * @param {?string} content
-     * @param {boolean} contentEncoded
-     * @param {string} mimeType
-     */
-    fireContentAvailable: function(content, contentEncoded, mimeType)
-    {
-        WebInspector.UISourceCode.prototype.fireContentAvailable.call(this, content, contentEncoded, mimeType);
-        if (this._formatOnLoad) {
-            delete this._formatOnLoad;
-            this.setFormatted(true);
-        }
-    },
-
-    /**
-     * @param {boolean} formatted
-     * @param {function()=} callback
-     */
-    setFormatted: function(formatted, callback)
-    {
-        callback = callback || function() {};
-        if (!this.contentLoaded()) {
-            this._formatOnLoad = formatted;
-            callback();
-            return;
-        }
-
-        if (this._formatted === formatted) {
-            callback();
-            return;
-        }
-
-        this._formatted = formatted;
-
-        // Re-request content
-        this._contentLoaded = false;
-        this._content = false;
-        WebInspector.UISourceCode.prototype.requestContent.call(this, didGetContent.bind(this));
-  
-        /**
-         * @this {WebInspector.UISourceCode}
-         * @param {?string} content
-         * @param {boolean} contentEncoded
-         * @param {string} mimeType
-         */
-        function didGetContent(content, contentEncoded, mimeType)
-        {
-            if (!formatted) {
-                this._togglingFormatter = true;
-                this.contentChanged(content || "", mimeType);
-                delete this._togglingFormatter;
-                this._formatterMapping = new WebInspector.IdentityFormatterSourceMapping();
-                this.updateLiveLocations();
-                callback();
-                return;
-            }
-    
-            var formatter = new WebInspector.ScriptFormatter();
-            formatter.formatContent(mimeType, content || "", didFormatContent.bind(this));
-  
-            /**
-             * @this {WebInspector.UISourceCode}
-             * @param {string} formattedContent
-             * @param {WebInspector.FormatterSourceMapping} formatterMapping
-             */
-            function didFormatContent(formattedContent, formatterMapping)
-            {
-                this._togglingFormatter = true;
-                this.contentChanged(formattedContent, mimeType);
-                delete this._togglingFormatter;
-                this._formatterMapping = formatterMapping;
-                this.updateLiveLocations();
-                WebInspector.breakpointManager.restoreBreakpoints(this);
-                callback();
-            }
-        }
-    },
-
-    /**
-     * @return {boolean}
-     */
-    togglingFormatter: function()
-    {
-        return this._togglingFormatter;
-    },
-
-    /**
      * @param {number} lineNumber
      * @param {number} columnNumber
      * @return {WebInspector.DebuggerModel.Location}
      */
     uiLocationToRawLocation: function(lineNumber, columnNumber)
     {
-        var location = this._formatterMapping.formattedToOriginal(lineNumber, columnNumber);
-        var rawLocation = WebInspector.UISourceCode.prototype.uiLocationToRawLocation.call(this, location[0], location[1]);
+        var rawLocation = WebInspector.UISourceCode.prototype.uiLocationToRawLocation.call(this, lineNumber, columnNumber);
         var debuggerModelLocation = /** @type {WebInspector.DebuggerModel.Location} */ rawLocation;
         return debuggerModelLocation;
     },
 
     /**
-     * @param {WebInspector.UILocation} uiLocation
-     */
-    overrideLocation: function(uiLocation)
-    {
-        var location = this._formatterMapping.originalToFormatted(uiLocation.lineNumber, uiLocation.columnNumber);
-        uiLocation.lineNumber = location[0];
-        uiLocation.columnNumber = location[1];
-        return uiLocation;
-    },
-
-    /**
      * @return {boolean}
      */
     supportsEnabledBreakpointsWhileEditing: function()
@@ -173,7 +68,7 @@
      */
     breakpointStorageId: function()
     {
-        return this._formatted ? "deobfuscated:" + this.url : this.url;
+        return this.formatted() ? "deobfuscated:" + this.url : this.url;
     },
 
     /**
@@ -223,6 +118,11 @@
         var content = this.content();
         var provider = content ? new WebInspector.StaticContentProvider(this._contentProvider.contentType(), content) : this._contentProvider;
         provider.searchInContent(query, caseSensitive, isRegex, callback);
+    },
+
+    formattedChanged: function()
+    {
+        WebInspector.breakpointManager.restoreBreakpoints(this);
     }
 }
 

Modified: trunk/Source/WebCore/inspector/front-end/ScriptFormatter.js (123851 => 123852)


--- trunk/Source/WebCore/inspector/front-end/ScriptFormatter.js	2012-07-27 08:41:19 UTC (rev 123851)
+++ trunk/Source/WebCore/inspector/front-end/ScriptFormatter.js	2012-07-27 08:50:31 UTC (rev 123852)
@@ -29,20 +29,30 @@
  */
 
 /**
- * @constructor
+ * @interface
  */
-WebInspector.ScriptFormatter = function()
+WebInspector.Formatter = function()
 {
-    this._tasks = [];
 }
 
 /**
+ * @param {WebInspector.ResourceType} contentType
+ * @return {?WebInspector.Formatter}
+ */
+WebInspector.Formatter.createFormatter = function(contentType)
+{
+    if (contentType === WebInspector.resourceTypes.Script || contentType === WebInspector.resourceTypes.Document)
+        return new WebInspector.ScriptFormatter();
+    return new WebInspector.IdentityFormatter();
+}
+
+/**
  * @param {Array.<number>} lineEndings
  * @param {number} lineNumber
  * @param {number} columnNumber
  * @return {number}
  */
-WebInspector.ScriptFormatter.locationToPosition = function(lineEndings, lineNumber, columnNumber)
+WebInspector.Formatter.locationToPosition = function(lineEndings, lineNumber, columnNumber)
 {
     var position = lineNumber ? lineEndings[lineNumber - 1] + 1 : 0;
     return position + columnNumber;
@@ -53,7 +63,7 @@
  * @param {number} position
  * @return {Array.<number>}
  */
-WebInspector.ScriptFormatter.positionToLocation = function(lineEndings, position)
+WebInspector.Formatter.positionToLocation = function(lineEndings, position)
 {
     var lineNumber = lineEndings.upperBound(position - 1);
     if (!lineNumber)
@@ -63,10 +73,30 @@
     return [lineNumber, columnNumber];
 }
 
+WebInspector.Formatter.prototype = {
+    /**
+     * @param {string} mimeType
+     * @param {string} content
+     * @param {function(string, WebInspector.FormatterSourceMapping)} callback
+     */
+    formatContent: function(mimeType, content, callback)
+    {
+    }
+}
+
+/**
+ * @constructor
+ * @implements {WebInspector.Formatter}
+ */
+WebInspector.ScriptFormatter = function()
+{
+    this._tasks = [];
+}
+
 WebInspector.ScriptFormatter.prototype = {
     /**
      * @param {string} mimeType
-     * @param {?string} content
+     * @param {string} content
      * @param {function(string, WebInspector.FormatterSourceMapping)} callback
      */
     formatContent: function(mimeType, content, callback)
@@ -103,7 +133,28 @@
 
 /**
  * @constructor
+ * @implements {WebInspector.Formatter}
  */
+WebInspector.IdentityFormatter = function()
+{
+    this._tasks = [];
+}
+
+WebInspector.IdentityFormatter.prototype = {
+    /**
+     * @param {string} mimeType
+     * @param {string} content
+     * @param {function(string, WebInspector.FormatterSourceMapping)} callback
+     */
+    formatContent: function(mimeType, content, callback)
+    {
+        callback(content, new WebInspector.IdentityFormatterSourceMapping());
+    }
+}
+
+/**
+ * @constructor
+ */
 WebInspector.FormatterMappingPayload = function()
 {
     this.original = [];
@@ -185,9 +236,9 @@
      */
     originalToFormatted: function(lineNumber, columnNumber)
     {
-        var originalPosition = WebInspector.ScriptFormatter.locationToPosition(this._originalLineEndings, lineNumber, columnNumber || 0);
+        var originalPosition = WebInspector.Formatter.locationToPosition(this._originalLineEndings, lineNumber, columnNumber || 0);
         var formattedPosition = this._convertPosition(this._mapping.original, this._mapping.formatted, originalPosition || 0);
-        return WebInspector.ScriptFormatter.positionToLocation(this._formattedLineEndings, formattedPosition);
+        return WebInspector.Formatter.positionToLocation(this._formattedLineEndings, formattedPosition);
     },
 
     /**
@@ -197,9 +248,9 @@
      */
     formattedToOriginal: function(lineNumber, columnNumber)
     {
-        var formattedPosition = WebInspector.ScriptFormatter.locationToPosition(this._formattedLineEndings, lineNumber, columnNumber || 0);
+        var formattedPosition = WebInspector.Formatter.locationToPosition(this._formattedLineEndings, lineNumber, columnNumber || 0);
         var originalPosition = this._convertPosition(this._mapping.formatted, this._mapping.original, formattedPosition);
-        return WebInspector.ScriptFormatter.positionToLocation(this._originalLineEndings, originalPosition || 0);
+        return WebInspector.Formatter.positionToLocation(this._originalLineEndings, originalPosition || 0);
     },
 
     /**

Modified: trunk/Source/WebCore/inspector/front-end/UISourceCode.js (123851 => 123852)


--- trunk/Source/WebCore/inspector/front-end/UISourceCode.js	2012-07-27 08:41:19 UTC (rev 123851)
+++ trunk/Source/WebCore/inspector/front-end/UISourceCode.js	2012-07-27 08:50:31 UTC (rev 123852)
@@ -64,6 +64,10 @@
      */
     this.history = [];
     this._restoreRevisionHistory();
+    this._formatterMapping = new WebInspector.IdentityFormatterSourceMapping();
+
+    // FIXME: postpone formattedChanged call to after the mapping has been established.
+    setTimeout(this.formattedChanged.bind(this), 0);
 }
 
 WebInspector.UISourceCode.Events = {
@@ -137,7 +141,7 @@
         }
         this._requestContentCallbacks.push(callback);
         if (this._requestContentCallbacks.length === 1)
-            this._contentProvider.requestContent(this.fireContentAvailable.bind(this));
+            this._contentProvider.requestContent(this._fireContentAvailable.bind(this));
     },
 
     /**
@@ -351,7 +355,7 @@
      * @param {boolean} contentEncoded
      * @param {string} mimeType
      */
-    fireContentAvailable: function(content, contentEncoded, mimeType)
+    _fireContentAvailable: function(content, contentEncoded, mimeType)
     {
         this._contentLoaded = true;
         this._mimeType = mimeType;
@@ -361,6 +365,11 @@
         this._requestContentCallbacks = [];
         for (var i = 0; i < callbacks.length; ++i)
             callbacks[i](content, contentEncoded, mimeType);
+
+        if (this._formatOnLoad) {
+            delete this._formatOnLoad;
+            this.setFormatted(true);
+        }
     },
 
     /**
@@ -378,7 +387,8 @@
      */
     uiLocationToRawLocation: function(lineNumber, columnNumber)
     {
-        return this._sourceMapping.uiLocationToRawLocation(this, lineNumber, columnNumber);
+        var location = this._formatterMapping.formattedToOriginal(lineNumber, columnNumber);
+        return this._sourceMapping.uiLocationToRawLocation(this, location[0], location[1]);
     },
 
     /**
@@ -409,6 +419,9 @@
      */
     overrideLocation: function(uiLocation)
     {
+        var location = this._formatterMapping.originalToFormatted(uiLocation.lineNumber, uiLocation.columnNumber);
+        uiLocation.lineNumber = location[0];
+        uiLocation.columnNumber = location[1];
         return uiLocation;
     },
 
@@ -445,13 +458,90 @@
     },
 
     /**
+     * @return {boolean}
+     */
+    togglingFormatter: function()
+    {
+        return this._togglingFormatter;
+    },
+
+    /**
+     * @return {boolean}
+     */
+    formatted: function()
+    {
+        return this._formatted;
+    },
+
+    /**
      * @param {boolean} formatted
      * @param {function()=} callback
      */
     setFormatted: function(formatted, callback)
     {
-        if (callback)
+        callback = callback || function() {};
+        if (!this.contentLoaded()) {
+            this._formatOnLoad = formatted;
             callback();
+            return;
+        }
+
+        if (this._formatted === formatted) {
+            callback();
+            return;
+        }
+
+        this._formatted = formatted;
+
+        // Re-request content
+        this._contentLoaded = false;
+        this._content = false;
+        WebInspector.UISourceCode.prototype.requestContent.call(this, didGetContent.bind(this));
+  
+        /**
+         * @this {WebInspector.UISourceCode}
+         * @param {?string} content
+         * @param {boolean} contentEncoded
+         * @param {string} mimeType
+         */
+        function didGetContent(content, contentEncoded, mimeType)
+        {
+            var formatter;
+            if (!formatted)
+                formatter = new WebInspector.IdentityFormatter();
+            else
+                formatter = WebInspector.Formatter.createFormatter(this.contentType());
+            formatter.formatContent(mimeType, content || "", formattedChanged.bind(this));
+  
+            /**
+             * @this {WebInspector.UISourceCode}
+             * @param {string} content
+             * @param {WebInspector.FormatterSourceMapping} formatterMapping
+             */
+            function formattedChanged(content, formatterMapping)
+            {
+                this._togglingFormatter = true;
+                this.contentChanged(content, mimeType);
+                delete this._togglingFormatter;
+                this._formatterMapping = formatterMapping;
+                this.updateLiveLocations();
+                this.formattedChanged();
+                callback();
+            }
+        }
+    },
+
+    /**
+     * @return {WebInspector.Formatter} formatter
+     */
+    createFormatter: function()
+    {
+        // overridden by subclasses.
+        return null;
+    },
+
+    formattedChanged: function()
+    {
     }
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to