Title: [109328] trunk
Revision
109328
Author
[email protected]
Date
2012-03-01 02:28:55 -0800 (Thu, 01 Mar 2012)

Log Message

Web Inspector: abstract out the common pattern of creating auto-updated locations.
https://bugs.webkit.org/show_bug.cgi?id=79906

Reviewed by Vsevolod Vlasov.

Source/WebCore:

* inspector/front-end/DebuggerPresentationModel.js:
(WebInspector.PresentationCallFrame.prototype.uiLocation):
(WebInspector.DebuggerPresentationModel.CallFramePlacard):
(WebInspector.DebuggerPresentationModel.CallFramePlacard.prototype.discard):
(WebInspector.DebuggerPresentationModel.CallFramePlacard.prototype._update):
(WebInspector.DebuggerPresentationModel.LinkifierFormatter.prototype.formatRawSourceCodeAnchor):
(WebInspector.DebuggerPresentationModel.DefaultLinkifierFormatter.prototype.formatRawSourceCodeAnchor):
(WebInspector.DebuggerPresentationModel.Linkifier):
(WebInspector.DebuggerPresentationModel.Linkifier.prototype.linkifyRawSourceCode):
(WebInspector.DebuggerPresentationModel.Linkifier.prototype.reset):
(WebInspector.DebuggerPresentationModel.Linkifier.prototype._updateAnchor):
* inspector/front-end/RawSourceCode.js:
(WebInspector.RawSourceCode.prototype.createLiveLocation):
(WebInspector.RawSourceCode.LiveLocation):
(WebInspector.RawSourceCode.LiveLocation.prototype.init):
(WebInspector.RawSourceCode.LiveLocation.prototype.dispose):
(WebInspector.RawSourceCode.LiveLocation.prototype._update):

LayoutTests:

* inspector/debugger/linkifier.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (109327 => 109328)


--- trunk/LayoutTests/ChangeLog	2012-03-01 09:53:57 UTC (rev 109327)
+++ trunk/LayoutTests/ChangeLog	2012-03-01 10:28:55 UTC (rev 109328)
@@ -1,3 +1,12 @@
+2012-02-29  Pavel Podivilov  <[email protected]>
+
+        Web Inspector: abstract out the common pattern of creating auto-updated locations.
+        https://bugs.webkit.org/show_bug.cgi?id=79906
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/debugger/linkifier.html:
+
 2012-02-29  Shinya Kawanaka  <[email protected]> 
 
         Fallback elements in non-youngest shadow tree should not be rendered.

Modified: trunk/LayoutTests/inspector/debugger/linkifier.html (109327 => 109328)


--- trunk/LayoutTests/inspector/debugger/linkifier.html	2012-03-01 09:53:57 UTC (rev 109327)
+++ trunk/LayoutTests/inspector/debugger/linkifier.html	2012-03-01 10:28:55 UTC (rev 109328)
@@ -43,14 +43,14 @@
         InspectorTest.addResult("listeners added on raw source code: " + (count2 - count1));
         InspectorTest.addResult("original location: " + link.textContent);
 
-        InspectorTest.addSniffer(linkifier, "_updateAnchor", linkUpdated);
+        InspectorTest.addSniffer(linkifier._formatter, "formatLiveAnchor", linkUpdated);
         WebInspector.debuggerPresentationModel.setFormatSource(true);
     }
 
     function linkUpdated()
     {
         InspectorTest.addResult("pretty printed location: " + link.textContent);
-        InspectorTest.addSniffer(linkifier, "_updateAnchor", linkReverted);
+        InspectorTest.addSniffer(linkifier._formatter, "formatLiveAnchor", linkReverted);
         WebInspector.debuggerPresentationModel.setFormatSource(false);
     }
 
@@ -75,7 +75,7 @@
             var listenersArray = listeners[eventTypes];
             count += listenersArray.length;
         }
-        return count; 
+        return count;
     }
 }
 

Modified: trunk/Source/WebCore/ChangeLog (109327 => 109328)


--- trunk/Source/WebCore/ChangeLog	2012-03-01 09:53:57 UTC (rev 109327)
+++ trunk/Source/WebCore/ChangeLog	2012-03-01 10:28:55 UTC (rev 109328)
@@ -1,3 +1,28 @@
+2012-02-29  Pavel Podivilov  <[email protected]>
+
+        Web Inspector: abstract out the common pattern of creating auto-updated locations.
+        https://bugs.webkit.org/show_bug.cgi?id=79906
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/front-end/DebuggerPresentationModel.js:
+        (WebInspector.PresentationCallFrame.prototype.uiLocation):
+        (WebInspector.DebuggerPresentationModel.CallFramePlacard):
+        (WebInspector.DebuggerPresentationModel.CallFramePlacard.prototype.discard):
+        (WebInspector.DebuggerPresentationModel.CallFramePlacard.prototype._update):
+        (WebInspector.DebuggerPresentationModel.LinkifierFormatter.prototype.formatRawSourceCodeAnchor):
+        (WebInspector.DebuggerPresentationModel.DefaultLinkifierFormatter.prototype.formatRawSourceCodeAnchor):
+        (WebInspector.DebuggerPresentationModel.Linkifier):
+        (WebInspector.DebuggerPresentationModel.Linkifier.prototype.linkifyRawSourceCode):
+        (WebInspector.DebuggerPresentationModel.Linkifier.prototype.reset):
+        (WebInspector.DebuggerPresentationModel.Linkifier.prototype._updateAnchor):
+        * inspector/front-end/RawSourceCode.js:
+        (WebInspector.RawSourceCode.prototype.createLiveLocation):
+        (WebInspector.RawSourceCode.LiveLocation):
+        (WebInspector.RawSourceCode.LiveLocation.prototype.init):
+        (WebInspector.RawSourceCode.LiveLocation.prototype.dispose):
+        (WebInspector.RawSourceCode.LiveLocation.prototype._update):
+
 2012-03-01  Kenneth Rohde Christiansen  <[email protected]>
 
         Make the tiling code slightly smarter

Modified: trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js (109327 => 109328)


--- trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js	2012-03-01 09:53:57 UTC (rev 109327)
+++ trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js	2012-03-01 10:28:55 UTC (rev 109328)
@@ -749,16 +749,13 @@
      */
     uiLocation: function(callback)
     {
-        function uiSourceCodeListChanged()
+        function locationUpdated(uiLocation)
         {
-            callback(this._rawSourceCode.rawLocationToUILocation(this._callFrame.location));
-            this._rawSourceCode.removeEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, uiSourceCodeListChanged, this);
-        }
-        var uiLocation = this._rawSourceCode.rawLocationToUILocation(this._callFrame.location);
-        if (uiLocation)
             callback(uiLocation);
-        else
-            this._rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, uiSourceCodeListChanged, this);
+            liveLocation.dispose();
+        }
+        var liveLocation = this._rawSourceCode.createLiveLocation(this._callFrame.location, locationUpdated.bind(this));
+        liveLocation.init();
     }
 }
 
@@ -770,23 +767,19 @@
 WebInspector.DebuggerPresentationModel.CallFramePlacard = function(callFrame)
 {
     WebInspector.Placard.call(this, callFrame._callFrame.functionName || WebInspector.UIString("(anonymous function)"), "");
-    this._callFrame = callFrame;
-    this._update();
-    this._callFrame._rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, this._update, this);
+    this._liveLocation = callFrame._rawSourceCode.createLiveLocation(callFrame._callFrame.location, this._update.bind(this));
+    this._liveLocation.init();
 }
 
 WebInspector.DebuggerPresentationModel.CallFramePlacard.prototype = {
     discard: function()
     {
-        this._callFrame._rawSourceCode.removeEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, this._update, this);
+        this._liveLocation.dispose();
     },
 
-    _update: function()
+    _update: function(uiLocation)
     {
-        var rawSourceCode = this._callFrame._rawSourceCode;
-        var uiLocation = rawSourceCode.rawLocationToUILocation(this._callFrame._callFrame.location);
-        if (uiLocation)
-            this.subtitle = WebInspector.displayNameForURL(uiLocation.uiSourceCode.url) + ":" + (uiLocation.lineNumber + 1);
+        this.subtitle = WebInspector.displayNameForURL(uiLocation.uiSourceCode.url) + ":" + (uiLocation.lineNumber + 1);
     }
 }
 
@@ -859,6 +852,8 @@
     }
 }
 
+WebInspector.DebuggerPresentationModelResourceBinding.prototype.__proto__ = WebInspector.ResourceDomainModelBinding.prototype;
+
 /**
  * @interface
  */
@@ -868,10 +863,10 @@
 
 WebInspector.DebuggerPresentationModel.LinkifierFormatter.prototype = {
     /**
-     * @param {WebInspector.RawSourceCode} rawSourceCode
      * @param {Element} anchor
+     * @param {WebInspector.UILocation} uiLocation
      */
-    formatRawSourceCodeAnchor: function(rawSourceCode, anchor) { },
+    formatLiveAnchor: function(anchor, uiLocation) { },
 }
 
 /**
@@ -886,15 +881,11 @@
 
 WebInspector.DebuggerPresentationModel.DefaultLinkifierFormatter.prototype = {
     /**
-     * @param {WebInspector.RawSourceCode} rawSourceCode
      * @param {Element} anchor
+     * @param {WebInspector.UILocation} uiLocation
      */
-    formatRawSourceCodeAnchor: function(rawSourceCode, anchor)
+    formatLiveAnchor: function(anchor, uiLocation)
     {
-        var uiLocation = rawSourceCode.rawLocationToUILocation(anchor.rawLocation);
-        if (!uiLocation)
-            return;
-
         anchor.textContent = WebInspector.formatLinkText(uiLocation.uiSourceCode.url, uiLocation.lineNumber);
 
         var text = WebInspector.formatLinkText(uiLocation.uiSourceCode.url, uiLocation.lineNumber);
@@ -915,7 +906,7 @@
 {
     this._model = model;
     this._formatter = formatter || new WebInspector.DebuggerPresentationModel.DefaultLinkifierFormatter();
-    this._anchorsForRawSourceCode = {};
+    this._liveLocations = [];
 }
 
 WebInspector.DebuggerPresentationModel.Linkifier.prototype = {
@@ -943,17 +934,10 @@
     linkifyRawSourceCode: function(rawSourceCode, lineNumber, columnNumber, classes)
     {
         var anchor = WebInspector.linkifyURLAsNode(rawSourceCode.url, "", classes, false);
-        anchor.rawLocation = { lineNumber: lineNumber, columnNumber: columnNumber };
-
-        var anchors = this._anchorsForRawSourceCode[rawSourceCode.id];
-        if (!anchors) {
-            anchors = [];
-            this._anchorsForRawSourceCode[rawSourceCode.id] = anchors;
-            rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, this._updateSourceAnchors, this);
-        }
-
-        this._updateAnchor(rawSourceCode, anchor);
-        anchors.push(anchor);
+        var rawLocation = { lineNumber: lineNumber, columnNumber: columnNumber };
+        var liveLocation = rawSourceCode.createLiveLocation(rawLocation, this._updateAnchor.bind(this, anchor));
+        liveLocation.init();
+        this._liveLocations.push(liveLocation);
         return anchor;
     },
 
@@ -967,44 +951,24 @@
 
     reset: function()
     {
-        for (var id in this._anchorsForRawSourceCode) {
-            if (this._model._rawSourceCodeForScriptId[id]) // In case of navigation the list of rawSourceCodes is empty.
-                this._model._rawSourceCodeForScriptId[id].removeEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, this._updateSourceAnchors, this);
-        }
-        this._anchorsForRawSourceCode = {};
+        for (var i = 0; i < this._liveLocations.length; ++i)
+            this._liveLocations[i].dispose();
+        this._liveLocations = [];
     },
 
     /**
-     * @param {WebInspector.Event} event
-     */
-    _updateSourceAnchors: function(event)
-    {
-        var rawSourceCode = /** @type {WebInspector.RawSourceCode} */ event.target;
-        var anchors = this._anchorsForRawSourceCode[rawSourceCode.id];
-        for (var i = 0; i < anchors.length; ++i)
-            this._updateAnchor(rawSourceCode, anchors[i]);
-    },
-
-    /**
-     * @param {WebInspector.RawSourceCode} rawSourceCode
      * @param {Element} anchor
+     * @param {WebInspector.UILocation} uiLocation
      */
-    _updateAnchor: function(rawSourceCode, anchor)
+    _updateAnchor: function(anchor, uiLocation)
     {
-        var uiLocation = rawSourceCode.rawLocationToUILocation(anchor.rawLocation);
-        if (!uiLocation)
-            return;
-
         anchor.preferredPanel = "scripts";
         anchor.uiSourceCode = uiLocation.uiSourceCode;
         anchor.lineNumber = uiLocation.lineNumber;
-
-        this._formatter.formatRawSourceCodeAnchor(rawSourceCode, anchor);
+        this._formatter.formatLiveAnchor(anchor, uiLocation);
     }
 }
 
-WebInspector.DebuggerPresentationModelResourceBinding.prototype.__proto__ = WebInspector.ResourceDomainModelBinding.prototype;
-
 /**
  * @type {?WebInspector.DebuggerPresentationModel}
  */

Modified: trunk/Source/WebCore/inspector/front-end/RawSourceCode.js (109327 => 109328)


--- trunk/Source/WebCore/inspector/front-end/RawSourceCode.js	2012-03-01 09:53:57 UTC (rev 109327)
+++ trunk/Source/WebCore/inspector/front-end/RawSourceCode.js	2012-03-01 10:28:55 UTC (rev 109328)
@@ -109,6 +109,11 @@
         return [];
     },
 
+    createLiveLocation: function(rawLocation, updateDelegate)
+    {
+        return new WebInspector.RawSourceCode.LiveLocation(this, rawLocation, updateDelegate);
+    },
+
     /**
      * @param {boolean} formatted
      */
@@ -280,6 +285,39 @@
 WebInspector.RawSourceCode.prototype.__proto__ = WebInspector.Object.prototype;
 
 /**
+ * @constructor
+ * @param {WebInspector.RawSourceCode} rawSourceCode
+ * @param {DebuggerAgent.Location} rawLocation
+ * @param {function(WebInspector.UILocation)} updateDelegate
+ */
+WebInspector.RawSourceCode.LiveLocation = function(rawSourceCode, rawLocation, updateDelegate)
+{
+    this._rawSourceCode = rawSourceCode;
+    this._rawLocation = rawLocation;
+    this._updateDelegate = updateDelegate;
+}
+
+WebInspector.RawSourceCode.LiveLocation.prototype = {
+    init: function()
+    {
+        this._rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, this._update, this);
+        this._update();
+    },
+
+    dispose: function()
+    {
+        this._rawSourceCode.removeEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, this._update, this);
+    },
+
+    _update: function()
+    {
+        var uiLocation = this._rawSourceCode.rawLocationToUILocation(this._rawLocation);
+        if (uiLocation)
+            this._updateDelegate(uiLocation);
+    }
+}
+
+/**
  * @interface
  */
 WebInspector.RawSourceCode.SourceMapping = function()

Modified: trunk/Source/WebCore/inspector/front-end/ScriptsSearchScope.js (109327 => 109328)


--- trunk/Source/WebCore/inspector/front-end/ScriptsSearchScope.js	2012-03-01 09:53:57 UTC (rev 109327)
+++ trunk/Source/WebCore/inspector/front-end/ScriptsSearchScope.js	2012-03-01 10:28:55 UTC (rev 109328)
@@ -176,10 +176,10 @@
 
 WebInspector.ScriptsSearchResultsPane.LinkifierFormatter.prototype = {
     /**
-     * @param {WebInspector.RawSourceCode} rawSourceCode
      * @param {Element} anchor
+     * @param {WebInspector.UILocation} uiLocation
      */
-    formatRawSourceCodeAnchor: function(rawSourceCode, anchor)
+    formatLiveAnchor: function(anchor, uiLocation)
     {
         // Empty because we don't want to ever update anchor contents after creation.
     }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to