Changeset 51601 in webkit


Ignore:
Timestamp:
Dec 2, 2009 10:32:08 AM (14 years ago)
Author:
pfeldman@chromium.org
Message:

2009-12-02 Pavel Feldman <pfeldman@dhcp-172-28-174-220.spb.corp.google.com>

Reviewed by Timothy Hatcher.

Web Inspector: DOM tree selection disappears upon page refresh.

https://bugs.webkit.org/show_bug.cgi?id=31142

Test: inspector/elements-panel-selection-on-refresh.html

  • inspector/InjectedScriptHost.cpp: (WebCore::InjectedScriptHost::pushNodeByPathToFrontend):
  • inspector/InjectedScriptHost.h:
  • inspector/InjectedScriptHost.idl:
  • inspector/InspectorBackend.h:
  • inspector/InspectorController.cpp: (WebCore::InspectorController::close): (WebCore::InspectorController::releaseDOMAgent): (WebCore::InspectorController::resetScriptObjects):
  • inspector/InspectorDOMAgent.cpp: (WebCore::InspectorDOMAgent::~InspectorDOMAgent): (WebCore::InspectorDOMAgent::reset): (WebCore::InspectorDOMAgent::setDocument): (WebCore::InspectorDOMAgent::pushDocumentToFrontend): (WebCore::InspectorDOMAgent::nodeForPath): (WebCore::InspectorDOMAgent::pushNodePathToFrontend):
  • inspector/InspectorDOMAgent.h:
  • inspector/front-end/DOMAgent.js: (WebInspector.DOMNode.prototype._renumber): (WebInspector.DOMAgent.prototype._setDocument):
  • inspector/front-end/ElementsPanel.js: (WebInspector.ElementsPanel.prototype.reset): (WebInspector.ElementsPanel.prototype.setDocument.selectDefaultNode): (WebInspector.ElementsPanel.prototype.setDocument.selectLastSelectedNode): (WebInspector.ElementsPanel.prototype.setDocument):
  • inspector/front-end/InjectedScript.js: (InjectedScript.pushNodeByPathToFrontend):
  • inspector/front-end/InjectedScriptAccess.js:
Location:
trunk
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r51597 r51601  
     12009-12-02  Pavel Feldman  <pfeldman@dhcp-172-28-174-220.spb.corp.google.com>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Web Inspector: DOM tree selection disappears upon page refresh.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=31142
     8
     9        * inspector/elements-panel-selection-on-refresh-expected.txt: Added.
     10        * inspector/elements-panel-selection-on-refresh.html: Added.
     11
    1122009-12-02  Csaba Osztrogonác  <ossy@webkit.org>
    213
  • trunk/WebCore/ChangeLog

    r51600 r51601  
     12009-12-02  Pavel Feldman  <pfeldman@dhcp-172-28-174-220.spb.corp.google.com>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Web Inspector: DOM tree selection disappears upon page refresh.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=31142
     8
     9        Test: inspector/elements-panel-selection-on-refresh.html
     10
     11        * inspector/InjectedScriptHost.cpp:
     12        (WebCore::InjectedScriptHost::pushNodeByPathToFrontend):
     13        * inspector/InjectedScriptHost.h:
     14        * inspector/InjectedScriptHost.idl:
     15        * inspector/InspectorBackend.h:
     16        * inspector/InspectorController.cpp:
     17        (WebCore::InspectorController::close):
     18        (WebCore::InspectorController::releaseDOMAgent):
     19        (WebCore::InspectorController::resetScriptObjects):
     20        * inspector/InspectorDOMAgent.cpp:
     21        (WebCore::InspectorDOMAgent::~InspectorDOMAgent):
     22        (WebCore::InspectorDOMAgent::reset):
     23        (WebCore::InspectorDOMAgent::setDocument):
     24        (WebCore::InspectorDOMAgent::pushDocumentToFrontend):
     25        (WebCore::InspectorDOMAgent::nodeForPath):
     26        (WebCore::InspectorDOMAgent::pushNodePathToFrontend):
     27        * inspector/InspectorDOMAgent.h:
     28        * inspector/front-end/DOMAgent.js:
     29        (WebInspector.DOMNode.prototype._renumber):
     30        (WebInspector.DOMAgent.prototype._setDocument):
     31        * inspector/front-end/ElementsPanel.js:
     32        (WebInspector.ElementsPanel.prototype.reset):
     33        (WebInspector.ElementsPanel.prototype.setDocument.selectDefaultNode):
     34        (WebInspector.ElementsPanel.prototype.setDocument.selectLastSelectedNode):
     35        (WebInspector.ElementsPanel.prototype.setDocument):
     36        * inspector/front-end/InjectedScript.js:
     37        (InjectedScript.pushNodeByPathToFrontend):
     38        * inspector/front-end/InjectedScriptAccess.js:
     39
    1402009-12-01  Dave Hyatt  <hyatt@apple.com>
    241
  • trunk/WebCore/inspector/InjectedScriptHost.cpp

    r51528 r51601  
    124124}
    125125
     126long InjectedScriptHost::pushNodeByPathToFrontend(const String& path)
     127{
     128    InspectorDOMAgent* domAgent = inspectorDOMAgent();
     129    if (!domAgent)
     130        return 0;
     131
     132    Node* node = domAgent->nodeForPath(path);
     133    if (!node)
     134        return 0;
     135
     136    return domAgent->pushNodePathToFrontend(node);
     137}
     138
    126139#if ENABLE(JAVASCRIPT_DEBUGGER)
    127140JavaScriptCallFrame* InjectedScriptHost::currentCallFrame() const
  • trunk/WebCore/inspector/InjectedScriptHost.h

    r51528 r51601  
    6464    ScriptValue unwrapObject(const String& objectId);
    6565    long pushNodePathToFrontend(Node* node, bool selectInUI);
     66
    6667    void addNodesToSearchResult(const String& nodeIds);
     68    long pushNodeByPathToFrontend(const String& path);
     69
    6770#if ENABLE(JAVASCRIPT_DEBUGGER)
    6871    JavaScriptCallFrame* currentCallFrame() const;
  • trunk/WebCore/inspector/InjectedScriptHost.idl

    r51528 r51601  
    4242        [Custom] DOMObject unwrapObject(in long objectId);
    4343        [Custom] int pushNodePathToFrontend(in DOMObject node, in boolean selectInUI);
     44
    4445        void addNodesToSearchResult(in DOMString nodeIds);
     46        long pushNodeByPathToFrontend(in DOMString path);
    4547
    4648#if defined(ENABLE_JAVASCRIPT_DEBUGGER) && ENABLE_JAVASCRIPT_DEBUGGER
  • trunk/WebCore/inspector/InspectorController.cpp

    r51598 r51601  
    625625    closeWindow();
    626626
    627     m_frontend.set(0);
    628627    m_injectedScriptObj = ScriptObject();
    629628    releaseDOMAgent();
     629    m_frontend.set(0);
    630630    m_timelineAgent = 0;
    631631    m_scriptState = 0;
     
    665665    // no references to the DOM agent from the DOM tree.
    666666    if (m_domAgent)
    667         m_domAgent->setDocument(0);
     667        m_domAgent->reset();
    668668    m_domAgent = 0;
    669669}
     
    728728
    729729    m_frontend->reset();
    730     m_domAgent->setDocument(0);
     730    m_domAgent->reset();
    731731    m_objectGroups.clear();
    732732    m_idToWrappedObject.clear();
  • trunk/WebCore/inspector/InspectorDOMAgent.cpp

    r51439 r51601  
    6969InspectorDOMAgent::~InspectorDOMAgent()
    7070{
    71     setDocument(0);
    72 }
    73 
    74 void InspectorDOMAgent::setDocument(Document* doc)
    75 {
    76     if (doc == mainFrameDocument())
    77         return;
     71    reset();
     72}
     73
     74void InspectorDOMAgent::reset()
     75{
    7876    discardBindings();
    7977
     
    8381
    8482    ASSERT(!m_documents.size());
     83}
     84
     85void InspectorDOMAgent::setDocument(Document* doc)
     86{
     87    if (doc == mainFrameDocument())
     88        return;
     89
     90    reset();
    8591
    8692    if (doc) {
    8793        startListening(doc);
    88         if (doc->documentElement()) {
     94        if (doc->documentElement())
    8995            pushDocumentToFrontend();
    90         }
    91     }
     96    } else
     97        m_frontend->setDocument(ScriptObject());
    9298}
    9399
     
    240246}
    241247
    242 void InspectorDOMAgent::pushDocumentToFrontend()
     248bool InspectorDOMAgent::pushDocumentToFrontend()
    243249{
    244250    Document* document = mainFrameDocument();
     251    if (!document)
     252        return false;
    245253    if (!m_documentNodeToIdMap.contains(document))
    246254        m_frontend->setDocument(buildObjectForNode(document, 2, &m_documentNodeToIdMap));
     255    return true;
    247256}
    248257
     
    280289}
    281290
     291Node* InspectorDOMAgent::nodeForPath(const String& path)
     292{
     293    // The path is of form "1,HTML,2,BODY,1,DIV"
     294    Node* node = mainFrameDocument();
     295    if (!node)
     296        return 0;
     297
     298    Vector<String> pathTokens;
     299    path.split(",", false, pathTokens);
     300    for (size_t i = 0; i < pathTokens.size() - 1; i += 2) {
     301        bool success = true;
     302        unsigned childNumber = pathTokens[i].toUInt(&success);
     303        if (!success)
     304            return 0;
     305        if (childNumber >= innerChildNodeCount(node))
     306            return 0;
     307
     308        Node* child = innerFirstChild(node);
     309        String childName = pathTokens[i + 1];
     310        for (size_t j = 0; child && j < childNumber; ++j)
     311            child = innerNextSibling(child);
     312
     313        if (!child || child->nodeName() != childName)
     314            return 0;
     315        node = child;
     316    }
     317    return node;
     318}
     319
    282320void InspectorDOMAgent::getChildNodes(long callId, long nodeId)
    283321{
     
    291329
    292330    // If we are sending information to the client that is currently being created. Send root node first.
    293     pushDocumentToFrontend();
     331    if (!pushDocumentToFrontend())
     332        return 0;
    294333
    295334    // Return id in case the node is known.
     
    571610}
    572611
    573 int InspectorDOMAgent::innerChildNodeCount(Node* node)
    574 {
    575     int count = 0;
     612unsigned InspectorDOMAgent::innerChildNodeCount(Node* node)
     613{
     614    unsigned count = 0;
    576615    Node* child = innerFirstChild(node);
    577616    while (child) {
  • trunk/WebCore/inspector/InspectorDOMAgent.h

    r49950 r51601  
    8484        ~InspectorDOMAgent();
    8585
     86        void reset();
     87
    8688        virtual bool operator==(const EventListener& other);
    8789
     
    98100
    99101        Node* nodeForId(long nodeId);
     102        Node* nodeForPath(const String& path);
    100103        long pushNodePathToFrontend(Node* node);
    101104
     
    110113        void unbind(Node* node, NodeToIdMap* nodesMap);
    111114
    112         void pushDocumentToFrontend();
     115        bool pushDocumentToFrontend();
    113116        void pushChildNodesToFrontend(long nodeId);
    114117
     
    124127        Node* innerNextSibling(Node* node);
    125128        Node* innerPreviousSibling(Node* node);
    126         int innerChildNodeCount(Node* node);
     129        unsigned innerChildNodeCount(Node* node);
    127130        Node* innerParentNode(Node* node);
    128131        bool isWhitespace(Node* node);
  • trunk/WebCore/inspector/front-end/DOMAgent.js

    r51528 r51601  
    180180        for (var i = 0; i < this._childNodeCount; ++i) {
    181181            var child = this.children[i];
     182            child.index = i;
    182183            child.nextSibling = i + 1 < this._childNodeCount ? this.children[i + 1] : null;
    183184            child.prevSibling = i - 1 >= 0 ? this.children[i - 1] : null;
     
    374375    {
    375376        this._idToDOMNode = {};
    376         if (payload) {
     377        if (payload && "id" in payload) {
    377378            this.document = new WebInspector.DOMDocument(this, this._window, payload);
    378379            this._idToDOMNode[payload.id] = this.document;
     
    380381        } else
    381382            this.document = null;
    382         WebInspector.panels.elements.reset();
     383        WebInspector.panels.elements.setDocument(this.document);
    383384    },
    384385
  • trunk/WebCore/inspector/front-end/ElementsPanel.js

    r51528 r51601  
    165165    reset: function()
    166166    {
     167        if (this.focusedDOMNode) {
     168            this._selectedPathOnReset = [];
     169            var node = this.focusedDOMNode;
     170            while ("index" in node) {
     171                this._selectedPathOnReset.push(node.nodeName);
     172                this._selectedPathOnReset.push(node.index);
     173                node = node.parentNode;
     174            }
     175            this._selectedPathOnReset.reverse();
     176        }
     177
    167178        this.rootDOMNode = null;
    168179        this.focusedDOMNode = null;
     
    179190        delete this.currentQuery;
    180191        this.searchCanceled();
    181 
    182         var domWindow = WebInspector.domAgent.domWindow;
    183         if (!domWindow || !domWindow.document || !domWindow.document.firstChild)
    184             return;
    185 
    186         var inspectedRootDocument = domWindow.document;
     192    },
     193
     194    setDocument: function(inspectedRootDocument)
     195    {
     196        this.reset();
     197
     198        if (!inspectedRootDocument)
     199            return;
     200
    187201        inspectedRootDocument.addEventListener("DOMNodeInserted", this._nodeInserted.bind(this));
    188202        inspectedRootDocument.addEventListener("DOMNodeRemoved", this._nodeRemoved.bind(this));
     
    190204        this.treeOutline.suppressSelectHighlight = true;
    191205        this.rootDOMNode = inspectedRootDocument;
    192 
    193         var canidateFocusNode = inspectedRootDocument.body || inspectedRootDocument.documentElement;
    194         if (canidateFocusNode) {
    195             this.focusedDOMNode = canidateFocusNode;
    196 
    197             if (this.treeOutline.selectedTreeElement)
    198                 this.treeOutline.selectedTreeElement.expand();
    199         }
    200206        this.treeOutline.suppressSelectHighlight = false;
     207
     208        function selectDefaultNode()
     209        {
     210            this.treeOutline.suppressSelectHighlight = true;
     211            var candidateFocusNode = inspectedRootDocument.body || inspectedRootDocument.documentElement;
     212            if (candidateFocusNode) {
     213                this.focusedDOMNode = candidateFocusNode;
     214
     215                if (this.treeOutline.selectedTreeElement)
     216                    this.treeOutline.selectedTreeElement.expand();
     217            }
     218        }
     219
     220        function selectLastSelectedNode(nodeId)
     221        {
     222            var node = nodeId ? WebInspector.domAgent.nodeForId(nodeId) : 0;
     223            if (!node) {
     224                selectDefaultNode.call(this);
     225                return;
     226            }
     227
     228            this.treeOutline.suppressSelectHighlight = true;
     229            this.focusedDOMNode = node;
     230            this.treeOutline.suppressSelectHighlight = false;
     231        }
     232
     233        if (this._selectedPathOnReset)
     234            InjectedScriptAccess.nodeByPath(this._selectedPathOnReset, selectLastSelectedNode.bind(this));
     235        else
     236            selectDefaultNode.call(this);
     237        delete this._selectedPathOnReset;
    201238    },
    202239
  • trunk/WebCore/inspector/front-end/InjectedScript.js

    r51528 r51601  
    10511051}
    10521052
     1053InjectedScript.nodeByPath = function(path)
     1054{
     1055    // We make this call through the injected script only to get a nice
     1056    // callback for it.
     1057    return InjectedScriptHost.pushNodeByPathToFrontend(path.join(","));
     1058}
     1059
    10531060// Called from within InspectorController on the 'inspected page' side.
    10541061InjectedScript.createProxyObject = function(object, objectId, abbreviate)
  • trunk/WebCore/inspector/front-end/InjectedScriptAccess.js

    r51528 r51601  
    7171InjectedScriptAccess._installHandler("performSearch");
    7272InjectedScriptAccess._installHandler("pushNodeToFrontend");
     73InjectedScriptAccess._installHandler("nodeByPath");
    7374InjectedScriptAccess._installHandler("searchCanceled");
    7475InjectedScriptAccess._installHandler("setPropertyValue");
Note: See TracChangeset for help on using the changeset viewer.