diff options
Diffstat (limited to 'WebCore/inspector/front-end/DOMAgent.js')
-rw-r--r-- | WebCore/inspector/front-end/DOMAgent.js | 214 |
1 files changed, 108 insertions, 106 deletions
diff --git a/WebCore/inspector/front-end/DOMAgent.js b/WebCore/inspector/front-end/DOMAgent.js index 7942f0a..5aacd41 100644 --- a/WebCore/inspector/front-end/DOMAgent.js +++ b/WebCore/inspector/front-end/DOMAgent.js @@ -31,7 +31,7 @@ WebInspector.DOMNode = function(doc, payload) { this.ownerDocument = doc; - this.id = payload.id; + this._id = payload.id; this.nodeType = payload.nodeType; this.nodeName = payload.nodeName; this._nodeValue = payload.nodeValue; @@ -48,22 +48,14 @@ WebInspector.DOMNode = function(doc, payload) { this.nextSibling = null; this.prevSibling = null; this.firstChild = null; - this.lastChild = null; this.parentNode = null; - if (payload.children) - this._setChildrenPayload(payload.children); + if (payload.childNodes) + this._setChildrenPayload(payload.childNodes); this._computedStyle = null; this.style = null; this._matchedCSSRules = []; - - if (this.nodeType == Node.ELEMENT_NODE) { - if (this.nodeName == "HTML") - this.ownerDocument.documentElement = this; - if (this.nodeName == "BODY") - this.ownerDocument.body = this; - } } WebInspector.DOMNode.prototype = { @@ -169,11 +161,9 @@ WebInspector.DOMNode.prototype = { this._childNodeCount = this.children.length; if (this._childNodeCount == 0) { this.firstChild = null; - this.lastChild = null; return; } this.firstChild = this.children[0]; - this.lastChild = this.children[this._childNodeCount - 1]; for (var i = 0; i < this._childNodeCount; ++i) { var child = this.children[i]; child.nextSibling = i + 1 < this._childNodeCount ? this.children[i + 1] : null; @@ -218,9 +208,17 @@ WebInspector.DOMNode.prototype = { } } -WebInspector.DOMDocument = function(domAgent, defaultView, payload) +WebInspector.DOMDocument = function(domAgent, defaultView) { - WebInspector.DOMNode.call(this, this, payload); + WebInspector.DOMNode.call(this, null, + { + id: 0, + nodeType: Node.DOCUMENT_NODE, + nodeName: "", + nodeValue: "", + attributes: [], + childNodeCount: 0 + }); this._listeners = {}; this._domAgent = domAgent; this.defaultView = defaultView; @@ -228,7 +226,7 @@ WebInspector.DOMDocument = function(domAgent, defaultView, payload) WebInspector.DOMDocument.prototype = { - addEventListener: function(name, callback) + addEventListener: function(name, callback, useCapture) { var listeners = this._listeners[name]; if (!listeners) { @@ -238,7 +236,7 @@ WebInspector.DOMDocument.prototype = { listeners.push(callback); }, - removeEventListener: function(name, callback) + removeEventListener: function(name, callback, useCapture) { var listeners = this._listeners[name]; if (!listeners) @@ -253,12 +251,10 @@ WebInspector.DOMDocument.prototype = { { var listeners = this._listeners[name]; if (!listeners) - return; + return; - for (var i = 0; i < listeners.length; ++i) { - var listener = listeners[i]; - listener.call(this, event); - } + for (var i = 0; i < listeners.length; ++i) + listeners[i](event); } } @@ -306,8 +302,23 @@ WebInspector.DOMAgent = function() { this._idToDOMNode = null; this.document = null; - // TODO: update ElementsPanel to not track embedded iframes - it is already being handled + // Install onpopulate handler. This is a temporary measure. + // TODO: add this code into the original updateChildren once domAgent + // becomes primary source of DOM information. + // TODO2: update ElementsPanel to not track embedded iframes - it is already being handled // in the agent backend. + var domAgent = this; + var originalUpdateChildren = WebInspector.ElementsTreeElement.prototype.updateChildren; + WebInspector.ElementsTreeElement.prototype.updateChildren = function() + { + domAgent.getChildNodesAsync(this.representedObject, originalUpdateChildren.bind(this)); + }; + + // Mute console handle to avoid crash on selection change. + // TODO: Re-implement inspectorConsoleAPI to work in a serialized way and remove this workaround. + WebInspector.Console.prototype.addInspectedNode = function() + { + }; // Whitespace is ignored in InspectorDOMAgent already -> no need to filter. // TODO: Either remove all of its usages or push value into the agent backend. @@ -320,36 +331,38 @@ WebInspector.DOMAgent.prototype = { return this._window; }, - getChildNodesAsync: function(parent, callback) + getChildNodesAsync: function(parent, opt_callback) { var children = parent.children; - if (children) { - callback(children); - return; - } - function mycallback() { - callback(parent.children); + if (children && opt_callback) { + opt_callback(children); + return; } + var mycallback = function() { + if (opt_callback) { + opt_callback(parent.children); + } + }; var callId = WebInspector.Callback.wrap(mycallback); - InspectorController.getChildNodes(callId, parent.id); + InspectorController.getChildNodes(callId, parent._id); }, setAttributeAsync: function(node, name, value, callback) { var mycallback = this._didApplyDomChange.bind(this, node, callback); - InspectorController.setAttribute(WebInspector.Callback.wrap(mycallback), node.id, name, value); + InspectorController.setAttribute(WebInspector.Callback.wrap(mycallback), node._id, name, value); }, removeAttributeAsync: function(node, name, callback) { var mycallback = this._didApplyDomChange.bind(this, node, callback); - InspectorController.removeAttribute(WebInspector.Callback.wrap(mycallback), node.id, name); + InspectorController.removeAttribute(WebInspector.Callback.wrap(mycallback), node._id, name); }, setTextNodeValueAsync: function(node, text, callback) { var mycallback = this._didApplyDomChange.bind(this, node, callback); - InspectorController.setTextNodeValue(WebInspector.Callback.wrap(mycallback), node.id, text); + InspectorController.setTextNodeValue(WebInspector.Callback.wrap(mycallback), node._id, text); }, _didApplyDomChange: function(node, callback, success) @@ -370,22 +383,26 @@ WebInspector.DOMAgent.prototype = { node._setAttributesPayload(attrsArray); }, - nodeForId: function(nodeId) { + getNodeForId: function(nodeId) { return this._idToDOMNode[nodeId]; }, - _setDocument: function(payload) + _setDocumentElement: function(payload) { - this.document = new WebInspector.DOMDocument(this, this._window, payload); - this._idToDOMNode = {}; - this._idToDOMNode[payload.id] = this.document; - this._bindNodes(this.document.children); + this.document = new WebInspector.DOMDocument(this, this._window); + this._idToDOMNode = { 0 : this.document }; + this._setChildNodes(0, [payload]); + this.document.documentElement = this.document.firstChild; + this.document.documentElement.ownerDocument = this.document; WebInspector.panels.elements.reset(); }, _setChildNodes: function(parentId, payloads) { var parent = this._idToDOMNode[parentId]; + if (parent.children) { + return; + } parent._setChildrenPayload(payloads); this._bindNodes(parent.children); }, @@ -394,7 +411,7 @@ WebInspector.DOMAgent.prototype = { { for (var i = 0; i < children.length; ++i) { var child = children[i]; - this._idToDOMNode[child.id] = child; + this._idToDOMNode[child._id] = child; if (child.children) this._bindNodes(child.children); } @@ -416,7 +433,7 @@ WebInspector.DOMAgent.prototype = { var parent = this._idToDOMNode[parentId]; var prev = this._idToDOMNode[prevId]; var node = parent._insertChild(prev, payload); - this._idToDOMNode[node.id] = node; + this._idToDOMNode[node._id] = node; var event = { target : node, relatedNode : parent }; this.document._fireDomEvent("DOMNodeInserted", event); }, @@ -433,7 +450,7 @@ WebInspector.DOMAgent.prototype = { } WebInspector.CSSStyleDeclaration = function(payload) { - this.id = payload.id; + this._id = payload.id; this.width = payload.width; this.height = payload.height; this.__disabledProperties = payload.__disabledProperties; @@ -475,13 +492,12 @@ WebInspector.CSSStyleDeclaration.parseStyle = function(payload) WebInspector.CSSStyleDeclaration.parseRule = function(payload) { var rule = {}; - rule.id = payload.id; + rule._id = payload.id; rule.selectorText = payload.selectorText; rule.style = new WebInspector.CSSStyleDeclaration(payload.style); rule.style.parentRule = rule; rule.isUserAgent = payload.isUserAgent; rule.isUser = payload.isUser; - rule.isViaInspector = payload.isViaInspector; if (payload.parentStyleSheet) rule.parentStyleSheet = { href: payload.parentStyleSheet.href }; @@ -570,9 +586,9 @@ WebInspector.attributesUpdated = function() this.domAgent._attributesUpdated.apply(this.domAgent, arguments); } -WebInspector.setDocument = function() +WebInspector.setDocumentElement = function() { - this.domAgent._setDocument.apply(this.domAgent, arguments); + this.domAgent._setDocumentElement.apply(this.domAgent, arguments); } WebInspector.setChildNodes = function() @@ -588,11 +604,13 @@ WebInspector.hasChildrenUpdated = function() WebInspector.childNodeInserted = function() { this.domAgent._childNodeInserted.apply(this.domAgent, arguments); + this._childNodeInserted.bind(this); } WebInspector.childNodeRemoved = function() { this.domAgent._childNodeRemoved.apply(this.domAgent, arguments); + this._childNodeRemoved.bind(this); } WebInspector.didGetChildNodes = WebInspector.Callback.processCallback; @@ -601,122 +619,106 @@ WebInspector.didApplyDomChange = WebInspector.Callback.processCallback; WebInspector.didRemoveAttribute = WebInspector.Callback.processCallback; WebInspector.didSetTextNodeValue = WebInspector.Callback.processCallback; +// Temporary methods for DOMAgent migration. +WebInspector.wrapNodeWithStyles = function(node, styles) +{ + var windowStub = new WebInspector.DOMWindow(null); + var docStub = new WebInspector.DOMDocument(null, windowStub); + var payload = {}; + payload.nodeType = node.nodeType; + payload.nodeName = node.nodeName; + payload.nodeValue = node.nodeValue; + payload.attributes = []; + payload.childNodeCount = 0; + + for (var i = 0; i < node.attributes.length; ++i) { + var attr = node.attributes[i]; + payload.attributes.push(attr.name); + payload.attributes.push(attr.value); + } + var nodeStub = new WebInspector.DOMNode(docStub, payload); + nodeStub._setStyles(styles.computedStyle, styles.inlineStyle, styles.styleAttributes, styles.matchedCSSRules); + return nodeStub; +} + // Temporary methods that will be dispatched via InspectorController into the injected context. InspectorController.getStyles = function(nodeId, authorOnly, callback) { setTimeout(function() { callback(InjectedScript.getStyles(nodeId, authorOnly)); - }, 0); + }, 0) } InspectorController.getComputedStyle = function(nodeId, callback) { setTimeout(function() { callback(InjectedScript.getComputedStyle(nodeId)); - }, 0); + }, 0) } InspectorController.getInlineStyle = function(nodeId, callback) { setTimeout(function() { callback(InjectedScript.getInlineStyle(nodeId)); - }, 0); + }, 0) } InspectorController.applyStyleText = function(styleId, styleText, propertyName, callback) { setTimeout(function() { callback(InjectedScript.applyStyleText(styleId, styleText, propertyName)); - }, 0); + }, 0) } InspectorController.setStyleText = function(style, cssText, callback) { setTimeout(function() { callback(InjectedScript.setStyleText(style, cssText)); - }, 0); + }, 0) } InspectorController.toggleStyleEnabled = function(styleId, propertyName, disabled, callback) { setTimeout(function() { callback(InjectedScript.toggleStyleEnabled(styleId, propertyName, disabled)); - }, 0); + }, 0) } -InspectorController.applyStyleRuleText = function(ruleId, newContent, selectedNodeId, callback) +InspectorController.applyStyleRuleText = function(ruleId, newContent, selectedNode, callback) { setTimeout(function() { - callback(InjectedScript.applyStyleRuleText(ruleId, newContent, selectedNodeId)); - }, 0); + callback(InjectedScript.applyStyleRuleText(ruleId, newContent, selectedNode)); + }, 0) } -InspectorController.addStyleSelector = function(newContent, selectedNodeId, callback) +InspectorController.addStyleSelector = function(newContent, callback) { setTimeout(function() { - callback(InjectedScript.addStyleSelector(newContent, selectedNodeId)); - }, 0); + callback(InjectedScript.addStyleSelector(newContent)); + }, 0) } -InspectorController.setStyleProperty = function(styleId, name, value, callback) -{ +InspectorController.setStyleProperty = function(styleId, name, value, callback) { setTimeout(function() { callback(InjectedScript.setStyleProperty(styleId, name, value)); - }, 0); + }, 0) } -InspectorController.getPrototypes = function(nodeId, callback) -{ +InspectorController.getPrototypes = function(objectProxy, callback) { setTimeout(function() { - callback(InjectedScript.getPrototypes(nodeId)); - }, 0); + callback(InjectedScript.getPrototypes(objectProxy)); + }, 0) } -InspectorController.getProperties = function(objectProxy, ignoreHasOwnProperty, callback) -{ +InspectorController.getProperties = function(objectProxy, ignoreHasOwnProperty, callback) { setTimeout(function() { callback(InjectedScript.getProperties(objectProxy, ignoreHasOwnProperty)); - }, 0); + }, 0) } -InspectorController.setPropertyValue = function(objectProxy, propertyName, expression, callback) -{ +InspectorController.setPropertyValue = function(objectProxy, propertyName, expression, callback) { setTimeout(function() { callback(InjectedScript.setPropertyValue(objectProxy, propertyName, expression)); - }, 0); -} - -InspectorController.evaluate = function(expression, callback) -{ - setTimeout(function() { - callback(InjectedScript.evaluate(expression)); - }, 0); -} - -InspectorController.addInspectedNode = function(nodeId, callback) -{ - setTimeout(function() { - callback(InjectedScript.addInspectedNode(nodeId)); - }, 0); -} - -InspectorController.performSearch = function(whitespaceTrimmedQuery, callback) -{ - setTimeout(function() { - callback(InjectedScript.performSearch(whitespaceTrimmedQuery)); - }, 0); -} - -InspectorController.searchCanceled = function(callback) -{ - setTimeout(function() { - callback(InjectedScript.searchCanceled()); - }, 0); + }, 0) } -InspectorController.getCookies = function(callback) -{ - setTimeout(function() { - callback(InjectedScript.getCookies()); - }, 0); -} |