Changeset 109328 in webkit


Ignore:
Timestamp:
Mar 1, 2012 2:28:55 AM (12 years ago)
Author:
podivilov@chromium.org
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:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r109321 r109328  
     12012-02-29  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Web Inspector: abstract out the common pattern of creating auto-updated locations.
     4        https://bugs.webkit.org/show_bug.cgi?id=79906
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        * inspector/debugger/linkifier.html:
     9
    1102012-02-29  Shinya Kawanaka  <shinyak@chromium.org>
    211
  • trunk/LayoutTests/inspector/debugger/linkifier.html

    r101126 r109328  
    4444        InspectorTest.addResult("original location: " + link.textContent);
    4545
    46         InspectorTest.addSniffer(linkifier, "_updateAnchor", linkUpdated);
     46        InspectorTest.addSniffer(linkifier._formatter, "formatLiveAnchor", linkUpdated);
    4747        WebInspector.debuggerPresentationModel.setFormatSource(true);
    4848    }
     
    5151    {
    5252        InspectorTest.addResult("pretty printed location: " + link.textContent);
    53         InspectorTest.addSniffer(linkifier, "_updateAnchor", linkReverted);
     53        InspectorTest.addSniffer(linkifier._formatter, "formatLiveAnchor", linkReverted);
    5454        WebInspector.debuggerPresentationModel.setFormatSource(false);
    5555    }
     
    7676            count += listenersArray.length;
    7777        }
    78         return count; 
     78        return count;
    7979    }
    8080}
  • trunk/Source/WebCore/ChangeLog

    r109327 r109328  
     12012-02-29  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Web Inspector: abstract out the common pattern of creating auto-updated locations.
     4        https://bugs.webkit.org/show_bug.cgi?id=79906
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        * inspector/front-end/DebuggerPresentationModel.js:
     9        (WebInspector.PresentationCallFrame.prototype.uiLocation):
     10        (WebInspector.DebuggerPresentationModel.CallFramePlacard):
     11        (WebInspector.DebuggerPresentationModel.CallFramePlacard.prototype.discard):
     12        (WebInspector.DebuggerPresentationModel.CallFramePlacard.prototype._update):
     13        (WebInspector.DebuggerPresentationModel.LinkifierFormatter.prototype.formatRawSourceCodeAnchor):
     14        (WebInspector.DebuggerPresentationModel.DefaultLinkifierFormatter.prototype.formatRawSourceCodeAnchor):
     15        (WebInspector.DebuggerPresentationModel.Linkifier):
     16        (WebInspector.DebuggerPresentationModel.Linkifier.prototype.linkifyRawSourceCode):
     17        (WebInspector.DebuggerPresentationModel.Linkifier.prototype.reset):
     18        (WebInspector.DebuggerPresentationModel.Linkifier.prototype._updateAnchor):
     19        * inspector/front-end/RawSourceCode.js:
     20        (WebInspector.RawSourceCode.prototype.createLiveLocation):
     21        (WebInspector.RawSourceCode.LiveLocation):
     22        (WebInspector.RawSourceCode.LiveLocation.prototype.init):
     23        (WebInspector.RawSourceCode.LiveLocation.prototype.dispose):
     24        (WebInspector.RawSourceCode.LiveLocation.prototype._update):
     25
    1262012-03-01  Kenneth Rohde Christiansen  <kenneth@webkit.org>
    227
  • trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js

    r109323 r109328  
    750750    uiLocation: function(callback)
    751751    {
    752         function uiSourceCodeListChanged()
     752        function locationUpdated(uiLocation)
    753753        {
    754             callback(this._rawSourceCode.rawLocationToUILocation(this._callFrame.location));
    755             this._rawSourceCode.removeEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, uiSourceCodeListChanged, this);
    756         }
    757         var uiLocation = this._rawSourceCode.rawLocationToUILocation(this._callFrame.location);
    758         if (uiLocation)
    759754            callback(uiLocation);
    760         else
    761             this._rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, uiSourceCodeListChanged, this);
     755            liveLocation.dispose();
     756        }
     757        var liveLocation = this._rawSourceCode.createLiveLocation(this._callFrame.location, locationUpdated.bind(this));
     758        liveLocation.init();
    762759    }
    763760}
     
    771768{
    772769    WebInspector.Placard.call(this, callFrame._callFrame.functionName || WebInspector.UIString("(anonymous function)"), "");
    773     this._callFrame = callFrame;
    774     this._update();
    775     this._callFrame._rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, this._update, this);
     770    this._liveLocation = callFrame._rawSourceCode.createLiveLocation(callFrame._callFrame.location, this._update.bind(this));
     771    this._liveLocation.init();
    776772}
    777773
     
    779775    discard: function()
    780776    {
    781         this._callFrame._rawSourceCode.removeEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, this._update, this);
    782     },
    783 
    784     _update: function()
    785     {
    786         var rawSourceCode = this._callFrame._rawSourceCode;
    787         var uiLocation = rawSourceCode.rawLocationToUILocation(this._callFrame._callFrame.location);
    788         if (uiLocation)
    789             this.subtitle = WebInspector.displayNameForURL(uiLocation.uiSourceCode.url) + ":" + (uiLocation.lineNumber + 1);
     777        this._liveLocation.dispose();
     778    },
     779
     780    _update: function(uiLocation)
     781    {
     782        this.subtitle = WebInspector.displayNameForURL(uiLocation.uiSourceCode.url) + ":" + (uiLocation.lineNumber + 1);
    790783    }
    791784}
     
    860853}
    861854
     855WebInspector.DebuggerPresentationModelResourceBinding.prototype.__proto__ = WebInspector.ResourceDomainModelBinding.prototype;
     856
    862857/**
    863858 * @interface
     
    869864WebInspector.DebuggerPresentationModel.LinkifierFormatter.prototype = {
    870865    /**
    871      * @param {WebInspector.RawSourceCode} rawSourceCode
    872866     * @param {Element} anchor
    873      */
    874     formatRawSourceCodeAnchor: function(rawSourceCode, anchor) { },
     867     * @param {WebInspector.UILocation} uiLocation
     868     */
     869    formatLiveAnchor: function(anchor, uiLocation) { },
    875870}
    876871
     
    887882WebInspector.DebuggerPresentationModel.DefaultLinkifierFormatter.prototype = {
    888883    /**
    889      * @param {WebInspector.RawSourceCode} rawSourceCode
    890884     * @param {Element} anchor
    891      */
    892     formatRawSourceCodeAnchor: function(rawSourceCode, anchor)
    893     {
    894         var uiLocation = rawSourceCode.rawLocationToUILocation(anchor.rawLocation);
    895         if (!uiLocation)
    896             return;
    897 
     885     * @param {WebInspector.UILocation} uiLocation
     886     */
     887    formatLiveAnchor: function(anchor, uiLocation)
     888    {
    898889        anchor.textContent = WebInspector.formatLinkText(uiLocation.uiSourceCode.url, uiLocation.lineNumber);
    899890
     
    916907    this._model = model;
    917908    this._formatter = formatter || new WebInspector.DebuggerPresentationModel.DefaultLinkifierFormatter();
    918     this._anchorsForRawSourceCode = {};
     909    this._liveLocations = [];
    919910}
    920911
     
    944935    {
    945936        var anchor = WebInspector.linkifyURLAsNode(rawSourceCode.url, "", classes, false);
    946         anchor.rawLocation = { lineNumber: lineNumber, columnNumber: columnNumber };
    947 
    948         var anchors = this._anchorsForRawSourceCode[rawSourceCode.id];
    949         if (!anchors) {
    950             anchors = [];
    951             this._anchorsForRawSourceCode[rawSourceCode.id] = anchors;
    952             rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, this._updateSourceAnchors, this);
    953         }
    954 
    955         this._updateAnchor(rawSourceCode, anchor);
    956         anchors.push(anchor);
     937        var rawLocation = { lineNumber: lineNumber, columnNumber: columnNumber };
     938        var liveLocation = rawSourceCode.createLiveLocation(rawLocation, this._updateAnchor.bind(this, anchor));
     939        liveLocation.init();
     940        this._liveLocations.push(liveLocation);
    957941        return anchor;
    958942    },
     
    968952    reset: function()
    969953    {
    970         for (var id in this._anchorsForRawSourceCode) {
    971             if (this._model._rawSourceCodeForScriptId[id]) // In case of navigation the list of rawSourceCodes is empty.
    972                 this._model._rawSourceCodeForScriptId[id].removeEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, this._updateSourceAnchors, this);
    973         }
    974         this._anchorsForRawSourceCode = {};
    975     },
    976 
    977     /**
    978      * @param {WebInspector.Event} event
    979      */
    980     _updateSourceAnchors: function(event)
    981     {
    982         var rawSourceCode = /** @type {WebInspector.RawSourceCode} */ event.target;
    983         var anchors = this._anchorsForRawSourceCode[rawSourceCode.id];
    984         for (var i = 0; i < anchors.length; ++i)
    985             this._updateAnchor(rawSourceCode, anchors[i]);
    986     },
    987 
    988     /**
    989      * @param {WebInspector.RawSourceCode} rawSourceCode
     954        for (var i = 0; i < this._liveLocations.length; ++i)
     955            this._liveLocations[i].dispose();
     956        this._liveLocations = [];
     957    },
     958
     959    /**
    990960     * @param {Element} anchor
    991      */
    992     _updateAnchor: function(rawSourceCode, anchor)
    993     {
    994         var uiLocation = rawSourceCode.rawLocationToUILocation(anchor.rawLocation);
    995         if (!uiLocation)
    996             return;
    997 
     961     * @param {WebInspector.UILocation} uiLocation
     962     */
     963    _updateAnchor: function(anchor, uiLocation)
     964    {
    998965        anchor.preferredPanel = "scripts";
    999966        anchor.uiSourceCode = uiLocation.uiSourceCode;
    1000967        anchor.lineNumber = uiLocation.lineNumber;
    1001 
    1002         this._formatter.formatRawSourceCodeAnchor(rawSourceCode, anchor);
     968        this._formatter.formatLiveAnchor(anchor, uiLocation);
    1003969    }
    1004970}
    1005 
    1006 WebInspector.DebuggerPresentationModelResourceBinding.prototype.__proto__ = WebInspector.ResourceDomainModelBinding.prototype;
    1007971
    1008972/**
  • trunk/Source/WebCore/inspector/front-end/RawSourceCode.js

    r109323 r109328  
    110110    },
    111111
     112    createLiveLocation: function(rawLocation, updateDelegate)
     113    {
     114        return new WebInspector.RawSourceCode.LiveLocation(this, rawLocation, updateDelegate);
     115    },
     116
    112117    /**
    113118     * @param {boolean} formatted
     
    281286
    282287/**
     288 * @constructor
     289 * @param {WebInspector.RawSourceCode} rawSourceCode
     290 * @param {DebuggerAgent.Location} rawLocation
     291 * @param {function(WebInspector.UILocation)} updateDelegate
     292 */
     293WebInspector.RawSourceCode.LiveLocation = function(rawSourceCode, rawLocation, updateDelegate)
     294{
     295    this._rawSourceCode = rawSourceCode;
     296    this._rawLocation = rawLocation;
     297    this._updateDelegate = updateDelegate;
     298}
     299
     300WebInspector.RawSourceCode.LiveLocation.prototype = {
     301    init: function()
     302    {
     303        this._rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, this._update, this);
     304        this._update();
     305    },
     306
     307    dispose: function()
     308    {
     309        this._rawSourceCode.removeEventListener(WebInspector.RawSourceCode.Events.UISourceCodeListChanged, this._update, this);
     310    },
     311
     312    _update: function()
     313    {
     314        var uiLocation = this._rawSourceCode.rawLocationToUILocation(this._rawLocation);
     315        if (uiLocation)
     316            this._updateDelegate(uiLocation);
     317    }
     318}
     319
     320/**
    283321 * @interface
    284322 */
  • trunk/Source/WebCore/inspector/front-end/ScriptsSearchScope.js

    r108971 r109328  
    177177WebInspector.ScriptsSearchResultsPane.LinkifierFormatter.prototype = {
    178178    /**
    179      * @param {WebInspector.RawSourceCode} rawSourceCode
    180179     * @param {Element} anchor
     180     * @param {WebInspector.UILocation} uiLocation
    181181     */
    182     formatRawSourceCodeAnchor: function(rawSourceCode, anchor)
     182    formatLiveAnchor: function(anchor, uiLocation)
    183183    {
    184184        // Empty because we don't want to ever update anchor contents after creation.
Note: See TracChangeset for help on using the changeset viewer.