You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pm...@apache.org on 2012/02/15 18:42:37 UTC
[11/51] [partial] Apache-ization, port to node.js
http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/c4fbd3d0/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMAgent.js
----------------------------------------------------------------------
diff --git a/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMAgent.js b/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMAgent.js
new file mode 100644
index 0000000..3645bb9
--- /dev/null
+++ b/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMAgent.js
@@ -0,0 +1,589 @@
+/*
+ * Copyright (C) 2009, 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2009 Joseph Pecoraro
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.DOMNode = function(doc, payload) {
+ this.ownerDocument = doc;
+
+ this.id = payload.id;
+ this.nodeType = payload.nodeType;
+ this.nodeName = payload.nodeName;
+ this.localName = payload.localName;
+ this._nodeValue = payload.nodeValue;
+ this.textContent = this.nodeValue;
+
+ this.attributes = [];
+ this._attributesMap = {};
+ if (payload.attributes)
+ this._setAttributesPayload(payload.attributes);
+
+ this._childNodeCount = payload.childNodeCount;
+ this.children = null;
+
+ this.nextSibling = null;
+ this.prevSibling = null;
+ this.firstChild = null;
+ this.lastChild = null;
+ this.parentNode = null;
+
+ if (payload.children)
+ this._setChildrenPayload(payload.children);
+
+ this._computedStyle = null;
+ this.style = null;
+ this._matchedCSSRules = [];
+
+ this.breakpoints = {};
+
+ if (this.nodeType === Node.ELEMENT_NODE) {
+ // HTML and BODY from internal iframes should not overwrite top-level ones.
+ if (!this.ownerDocument.documentElement && this.nodeName === "HTML")
+ this.ownerDocument.documentElement = this;
+ if (!this.ownerDocument.body && this.nodeName === "BODY")
+ this.ownerDocument.body = this;
+ if (payload.documentURL)
+ this.documentURL = payload.documentURL;
+ } else if (this.nodeType === Node.DOCUMENT_TYPE_NODE) {
+ this.publicId = payload.publicId;
+ this.systemId = payload.systemId;
+ this.internalSubset = payload.internalSubset;
+ } else if (this.nodeType === Node.DOCUMENT_NODE) {
+ this.documentURL = payload.documentURL;
+ } else if (this.nodeType === Node.ATTRIBUTE_NODE) {
+ this.name = payload.name;
+ this.value = payload.value;
+ }
+}
+
+WebInspector.DOMNode.prototype = {
+ hasAttributes: function()
+ {
+ return this.attributes.length > 0;
+ },
+
+ hasChildNodes: function()
+ {
+ return this._childNodeCount > 0;
+ },
+
+ get nodeValue() {
+ return this._nodeValue;
+ },
+
+ set nodeValue(value) {
+ if (this.nodeType != Node.TEXT_NODE)
+ return;
+ this.ownerDocument._domAgent.setTextNodeValueAsync(this, value, function() {});
+ },
+
+ getAttribute: function(name)
+ {
+ var attr = this._attributesMap[name];
+ return attr ? attr.value : undefined;
+ },
+
+ setAttribute: function(name, value)
+ {
+ var self = this;
+ var callback = function()
+ {
+ var attr = self._attributesMap[name];
+ if (attr)
+ attr.value = value;
+ else
+ attr = self._addAttribute(name, value);
+ };
+ this.ownerDocument._domAgent.setAttributeAsync(this, name, value, callback);
+ },
+
+ removeAttribute: function(name)
+ {
+ var self = this;
+ var callback = function()
+ {
+ delete self._attributesMap[name];
+ for (var i = 0; i < self.attributes.length; ++i) {
+ if (self.attributes[i].name == name) {
+ self.attributes.splice(i, 1);
+ break;
+ }
+ }
+ };
+ this.ownerDocument._domAgent.removeAttributeAsync(this, name, callback);
+ },
+
+ path: function()
+ {
+ var path = [];
+ var node = this;
+ while (node && "index" in node && node.nodeName.length) {
+ path.push([node.index, node.nodeName]);
+ node = node.parentNode;
+ }
+ path.reverse();
+ return path.join(",");
+ },
+
+ _setAttributesPayload: function(attrs)
+ {
+ this.attributes = [];
+ this._attributesMap = {};
+ for (var i = 0; i < attrs.length; i += 2)
+ this._addAttribute(attrs[i], attrs[i + 1]);
+ },
+
+ _insertChild: function(prev, payload)
+ {
+ var node = new WebInspector.DOMNode(this.ownerDocument, payload);
+ if (!prev) {
+ if (!this.children) {
+ // First node
+ this.children = [ node ];
+ } else
+ this.children.unshift(node);
+ } else
+ this.children.splice(this.children.indexOf(prev) + 1, 0, node);
+ this._renumber();
+ return node;
+ },
+
+ removeChild_: function(node)
+ {
+ this.children.splice(this.children.indexOf(node), 1);
+ node.parentNode = null;
+ this._renumber();
+ },
+
+ _setChildrenPayload: function(payloads)
+ {
+ this.children = [];
+ for (var i = 0; i < payloads.length; ++i) {
+ var payload = payloads[i];
+ var node = new WebInspector.DOMNode(this.ownerDocument, payload);
+ this.children.push(node);
+ }
+ this._renumber();
+ },
+
+ _renumber: function()
+ {
+ 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.index = i;
+ child.nextSibling = i + 1 < this._childNodeCount ? this.children[i + 1] : null;
+ child.prevSibling = i - 1 >= 0 ? this.children[i - 1] : null;
+ child.parentNode = this;
+ }
+ },
+
+ _addAttribute: function(name, value)
+ {
+ var attr = {
+ "name": name,
+ "value": value,
+ "_node": this
+ };
+ this._attributesMap[name] = attr;
+ this.attributes.push(attr);
+ }
+}
+
+WebInspector.DOMDocument = function(domAgent, defaultView, payload)
+{
+ WebInspector.DOMNode.call(this, this, payload);
+ this._listeners = {};
+ this._domAgent = domAgent;
+ this.defaultView = defaultView;
+}
+
+WebInspector.DOMDocument.prototype = {
+
+ addEventListener: function(name, callback)
+ {
+ var listeners = this._listeners[name];
+ if (!listeners) {
+ listeners = [];
+ this._listeners[name] = listeners;
+ }
+ listeners.push(callback);
+ },
+
+ removeEventListener: function(name, callback)
+ {
+ var listeners = this._listeners[name];
+ if (!listeners)
+ return;
+
+ var index = listeners.indexOf(callback);
+ if (index != -1)
+ listeners.splice(index, 1);
+ },
+
+ _fireDomEvent: function(name, event)
+ {
+ var listeners = this._listeners[name];
+ if (!listeners)
+ return;
+
+ for (var i = 0; i < listeners.length; ++i) {
+ var listener = listeners[i];
+ listener.call(this, event);
+ }
+ }
+}
+
+WebInspector.DOMDocument.prototype.__proto__ = WebInspector.DOMNode.prototype;
+
+
+WebInspector.DOMWindow = function(domAgent)
+{
+ this._domAgent = domAgent;
+}
+
+WebInspector.DOMWindow.prototype = {
+ get document()
+ {
+ return this._domAgent.document;
+ },
+
+ get Node()
+ {
+ return WebInspector.DOMNode;
+ },
+
+ get Element()
+ {
+ return WebInspector.DOMNode;
+ },
+
+ Object: function()
+ {
+ }
+}
+
+WebInspector.DOMAgent = function() {
+ this._window = new WebInspector.DOMWindow(this);
+ this._idToDOMNode = null;
+ this.document = null;
+ InspectorBackend.registerDomainDispatcher("DOM", new WebInspector.DOMDispatcher(this));
+}
+
+WebInspector.DOMAgent.prototype = {
+ get domWindow()
+ {
+ return this._window;
+ },
+
+ getChildNodesAsync: function(parent, callback)
+ {
+ var children = parent.children;
+ if (children) {
+ callback(children);
+ return;
+ }
+ function mycallback() {
+ callback(parent.children);
+ }
+ InspectorBackend.getChildNodes(parent.id, mycallback);
+ },
+
+ setAttributeAsync: function(node, name, value, callback)
+ {
+ var mycallback = this._didApplyDomChange.bind(this, node, callback);
+ InspectorBackend.setAttribute(node.id, name, value, mycallback);
+ },
+
+ removeAttributeAsync: function(node, name, callback)
+ {
+ var mycallback = this._didApplyDomChange.bind(this, node, callback);
+ InspectorBackend.removeAttribute(node.id, name, mycallback);
+ },
+
+ setTextNodeValueAsync: function(node, text, callback)
+ {
+ var mycallback = this._didApplyDomChange.bind(this, node, callback);
+ InspectorBackend.setTextNodeValue(node.id, text, mycallback);
+ },
+
+ _didApplyDomChange: function(node, callback, success)
+ {
+ if (!success)
+ return;
+ callback();
+ // TODO(pfeldman): Fix this hack.
+ var elem = WebInspector.panels.elements.treeOutline.findTreeElement(node);
+ if (elem)
+ elem.updateTitle();
+ },
+
+ _attributesUpdated: function(nodeId, attrsArray)
+ {
+ var node = this._idToDOMNode[nodeId];
+ node._setAttributesPayload(attrsArray);
+ var event = {target: node};
+ this.document._fireDomEvent("DOMAttrModified", event);
+ },
+
+ _characterDataModified: function(nodeId, newValue)
+ {
+ var node = this._idToDOMNode[nodeId];
+ node._nodeValue = newValue;
+ node.textContent = newValue;
+ var event = { target : node };
+ this.document._fireDomEvent("DOMCharacterDataModified", event);
+ },
+
+ nodeForId: function(nodeId)
+ {
+ return this._idToDOMNode[nodeId];
+ },
+
+ _setDocument: function(payload)
+ {
+ this._idToDOMNode = {};
+ if (payload && "id" in payload) {
+ this.document = new WebInspector.DOMDocument(this, this._window, payload);
+ this._idToDOMNode[payload.id] = this.document;
+ this._bindNodes(this.document.children);
+ WebInspector.breakpointManager.restoreDOMBreakpoints();
+ } else
+ this.document = null;
+ WebInspector.panels.elements.setDocument(this.document);
+ },
+
+ _setDetachedRoot: function(payload)
+ {
+ var root = new WebInspector.DOMNode(this.document, payload);
+ this._idToDOMNode[payload.id] = root;
+ },
+
+ _setChildNodes: function(parentId, payloads)
+ {
+ var parent = this._idToDOMNode[parentId];
+ parent._setChildrenPayload(payloads);
+ this._bindNodes(parent.children);
+ },
+
+ _bindNodes: function(children)
+ {
+ for (var i = 0; i < children.length; ++i) {
+ var child = children[i];
+ this._idToDOMNode[child.id] = child;
+ if (child.children)
+ this._bindNodes(child.children);
+ }
+ },
+
+ _childNodeCountUpdated: function(nodeId, newValue)
+ {
+ var node = this._idToDOMNode[nodeId];
+ node._childNodeCount = newValue;
+ var outline = WebInspector.panels.elements.treeOutline;
+ var treeElement = outline.findTreeElement(node);
+ if (treeElement)
+ treeElement.hasChildren = newValue;
+ },
+
+ _childNodeInserted: function(parentId, prevId, payload)
+ {
+ var parent = this._idToDOMNode[parentId];
+ var prev = this._idToDOMNode[prevId];
+ var node = parent._insertChild(prev, payload);
+ this._idToDOMNode[node.id] = node;
+ var event = { target : node, relatedNode : parent };
+ this.document._fireDomEvent("DOMNodeInserted", event);
+ },
+
+ _childNodeRemoved: function(parentId, nodeId)
+ {
+ var parent = this._idToDOMNode[parentId];
+ var node = this._idToDOMNode[nodeId];
+ parent.removeChild_(node);
+ var event = { target : node, relatedNode : parent };
+ this.document._fireDomEvent("DOMNodeRemoved", event);
+ delete this._idToDOMNode[nodeId];
+ this._removeBreakpoints(node);
+ },
+
+ _removeBreakpoints: function(node)
+ {
+ for (var type in node.breakpoints)
+ node.breakpoints[type].remove();
+ if (!node.children)
+ return;
+ for (var i = 0; i < node.children.length; ++i)
+ this._removeBreakpoints(node.children[i]);
+ }
+}
+
+WebInspector.DOMDispatcher = function(domAgent)
+{
+ this._domAgent = domAgent;
+}
+
+WebInspector.DOMDispatcher.prototype = {
+ setDocument: function(payload)
+ {
+ this._domAgent._setDocument(payload);
+ },
+
+ attributesUpdated: function(nodeId, attrsArray)
+ {
+ this._domAgent._attributesUpdated(nodeId, attrsArray);
+ },
+
+ characterDataModified: function(nodeId, newValue)
+ {
+ this._domAgent._characterDataModified(nodeId, newValue);
+ },
+
+ setChildNodes: function(parentId, payloads)
+ {
+ this._domAgent._setChildNodes(parentId, payloads);
+ },
+
+ setDetachedRoot: function(payload)
+ {
+ this._domAgent._setDetachedRoot(payload);
+ },
+
+ childNodeCountUpdated: function(nodeId, newValue)
+ {
+ this._domAgent._childNodeCountUpdated(nodeId, newValue);
+ },
+
+ childNodeInserted: function(parentId, prevId, payload)
+ {
+ this._domAgent._childNodeInserted(parentId, prevId, payload);
+ },
+
+ childNodeRemoved: function(parentId, nodeId)
+ {
+ this._domAgent._childNodeRemoved(parentId, nodeId);
+ }
+}
+
+WebInspector.ApplicationCacheDispatcher = function()
+{
+}
+
+WebInspector.ApplicationCacheDispatcher.getApplicationCachesAsync = function(callback)
+{
+ function mycallback(applicationCaches)
+ {
+ // FIXME: Currently, this list only returns a single application cache.
+ if (applicationCaches)
+ callback(applicationCaches);
+ }
+
+ InspectorBackend.getApplicationCaches(mycallback);
+}
+
+WebInspector.ApplicationCacheDispatcher.prototype = {
+ updateApplicationCacheStatus: function(status)
+ {
+ WebInspector.panels.resources.updateApplicationCacheStatus(status);
+ },
+
+ updateNetworkState: function(isNowOnline)
+ {
+ WebInspector.panels.resources.updateNetworkState(isNowOnline);
+ }
+}
+
+InspectorBackend.registerDomainDispatcher("ApplicationCache", new WebInspector.ApplicationCacheDispatcher());
+
+WebInspector.Cookies = {}
+
+WebInspector.Cookies.getCookiesAsync = function(callback)
+{
+ function mycallback(cookies, cookiesString)
+ {
+ if (cookiesString)
+ callback(WebInspector.Cookies.buildCookiesFromString(cookiesString), false);
+ else
+ callback(cookies, true);
+ }
+
+ InspectorBackend.getCookies(mycallback);
+}
+
+WebInspector.Cookies.buildCookiesFromString = function(rawCookieString)
+{
+ var rawCookies = rawCookieString.split(/;\s*/);
+ var cookies = [];
+
+ if (!(/^\s*$/.test(rawCookieString))) {
+ for (var i = 0; i < rawCookies.length; ++i) {
+ var cookie = rawCookies[i];
+ var delimIndex = cookie.indexOf("=");
+ var name = cookie.substring(0, delimIndex);
+ var value = cookie.substring(delimIndex + 1);
+ var size = name.length + value.length;
+ cookies.push({ name: name, value: value, size: size });
+ }
+ }
+
+ return cookies;
+}
+
+WebInspector.Cookies.cookieMatchesResourceURL = function(cookie, resourceURL)
+{
+ var url = resourceURL.asParsedURL();
+ if (!url || !this.cookieDomainMatchesResourceDomain(cookie.domain, url.host))
+ return false;
+ return (url.path.indexOf(cookie.path) === 0
+ && (!cookie.port || url.port == cookie.port)
+ && (!cookie.secure || url.scheme === "https"));
+}
+
+WebInspector.Cookies.cookieDomainMatchesResourceDomain = function(cookieDomain, resourceDomain)
+{
+ if (cookieDomain.charAt(0) !== '.')
+ return resourceDomain === cookieDomain;
+ return !!resourceDomain.match(new RegExp("^([^\\.]+\\.)?" + cookieDomain.substring(1).escapeForRegExp() + "$"), "i");
+}
+
+WebInspector.EventListeners = {}
+
+WebInspector.EventListeners.getEventListenersForNodeAsync = function(node, callback)
+{
+ if (!node)
+ return;
+ InspectorBackend.getEventListenersForNode(node.id, callback);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/c4fbd3d0/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMStorage.js
----------------------------------------------------------------------
diff --git a/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMStorage.js b/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMStorage.js
new file mode 100644
index 0000000..43011ea
--- /dev/null
+++ b/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMStorage.js
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2008 Nokia Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.DOMStorage = function(id, domain, isLocalStorage)
+{
+ this._id = id;
+ this._domain = domain;
+ this._isLocalStorage = isLocalStorage;
+}
+
+WebInspector.DOMStorage.prototype = {
+ get id()
+ {
+ return this._id;
+ },
+
+ get domain()
+ {
+ return this._domain;
+ },
+
+ get isLocalStorage()
+ {
+ return this._isLocalStorage;
+ },
+
+ getEntries: function(callback)
+ {
+ InspectorBackend.getDOMStorageEntries(this._id, callback);
+ },
+
+ setItem: function(key, value, callback)
+ {
+ InspectorBackend.setDOMStorageItem(this._id, key, value, callback);
+ },
+
+ removeItem: function(key, callback)
+ {
+ InspectorBackend.removeDOMStorageItem(this._id, key, callback);
+ }
+}
+
+
+WebInspector.DOMStorageDispatcher = function()
+{
+}
+
+WebInspector.DOMStorageDispatcher.prototype = {
+ addDOMStorage: function(payload)
+ {
+ if (!WebInspector.panels.resources)
+ return;
+ var domStorage = new WebInspector.DOMStorage(
+ payload.id,
+ payload.host,
+ payload.isLocalStorage);
+ WebInspector.panels.resources.addDOMStorage(domStorage);
+ },
+
+ selectDOMStorage: function(o)
+ {
+ WebInspector.showPanel("resources");
+ WebInspector.panels.resources.selectDOMStorage(o);
+ },
+
+ updateDOMStorage: function(storageId)
+ {
+ WebInspector.panels.resources.updateDOMStorage(storageId);
+ }
+}
+
+InspectorBackend.registerDomainDispatcher("DOMStorage", new WebInspector.DOMStorageDispatcher());
http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/c4fbd3d0/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMStorageItemsView.js
----------------------------------------------------------------------
diff --git a/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMStorageItemsView.js b/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMStorageItemsView.js
new file mode 100644
index 0000000..dbd736b
--- /dev/null
+++ b/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMStorageItemsView.js
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2008 Nokia Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.DOMStorageItemsView = function(domStorage)
+{
+ WebInspector.View.call(this);
+
+ this.domStorage = domStorage;
+
+ this.element.addStyleClass("storage-view");
+ this.element.addStyleClass("table");
+
+ this.deleteButton = new WebInspector.StatusBarButton(WebInspector.UIString("Delete"), "delete-storage-status-bar-item");
+ this.deleteButton.visible = false;
+ this.deleteButton.addEventListener("click", this._deleteButtonClicked.bind(this), false);
+
+ this.refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString("Refresh"), "refresh-storage-status-bar-item");
+ this.refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this), false);
+}
+
+WebInspector.DOMStorageItemsView.prototype = {
+ get statusBarItems()
+ {
+ return [this.refreshButton.element, this.deleteButton.element];
+ },
+
+ show: function(parentElement)
+ {
+ WebInspector.View.prototype.show.call(this, parentElement);
+ this.update();
+ },
+
+ hide: function()
+ {
+ WebInspector.View.prototype.hide.call(this);
+ this.deleteButton.visible = false;
+ },
+
+ update: function()
+ {
+ this.element.removeChildren();
+ var callback = this._showDOMStorageEntries.bind(this);
+ this.domStorage.getEntries(callback);
+ },
+
+ _showDOMStorageEntries: function(entries)
+ {
+ this._dataGrid = this._dataGridForDOMStorageEntries(entries);
+ this.element.appendChild(this._dataGrid.element);
+ this._dataGrid.autoSizeColumns(10);
+ this.deleteButton.visible = true;
+ },
+
+ resize: function()
+ {
+ if (this._dataGrid)
+ this._dataGrid.updateWidths();
+ },
+
+ _dataGridForDOMStorageEntries: function(entries)
+ {
+ var columns = {};
+ columns[0] = {};
+ columns[1] = {};
+ columns[0].title = WebInspector.UIString("Key");
+ columns[1].title = WebInspector.UIString("Value");
+
+ var nodes = [];
+
+ var keys = [];
+ var length = entries.length;
+ for (var i = 0; i < entries.length; i++) {
+ var data = {};
+
+ var key = entries[i][0];
+ data[0] = key;
+ var value = entries[i][1];
+ data[1] = value;
+ var node = new WebInspector.DataGridNode(data, false);
+ node.selectable = true;
+ nodes.push(node);
+ keys.push(key);
+ }
+
+ var dataGrid = new WebInspector.DataGrid(columns, this._editingCallback.bind(this), this._deleteCallback.bind(this));
+ var length = nodes.length;
+ for (var i = 0; i < length; ++i)
+ dataGrid.appendChild(nodes[i]);
+ dataGrid.addCreationNode(false);
+ if (length > 0)
+ nodes[0].selected = true;
+ return dataGrid;
+ },
+
+ _deleteButtonClicked: function(event)
+ {
+ if (!this._dataGrid || !this._dataGrid.selectedNode)
+ return;
+
+ this._deleteCallback(this._dataGrid.selectedNode);
+ },
+
+ _refreshButtonClicked: function(event)
+ {
+ this.update();
+ },
+
+ _editingCallback: function(editingNode, columnIdentifier, oldText, newText)
+ {
+ var domStorage = this.domStorage;
+ if (columnIdentifier === 0) {
+ if (oldText)
+ domStorage.removeItem(oldText);
+
+ domStorage.setItem(newText, editingNode.data[1]);
+ } else {
+ domStorage.setItem(editingNode.data[0], newText);
+ }
+
+ this.update();
+ },
+
+ _deleteCallback: function(node)
+ {
+ if (!node || node.isCreationNode)
+ return;
+
+ if (this.domStorage)
+ this.domStorage.removeItem(node.data[0]);
+
+ this.update();
+ }
+}
+
+WebInspector.DOMStorageItemsView.prototype.__proto__ = WebInspector.View.prototype;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/c4fbd3d0/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMSyntaxHighlighter.js
----------------------------------------------------------------------
diff --git a/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMSyntaxHighlighter.js b/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMSyntaxHighlighter.js
new file mode 100644
index 0000000..07233d3
--- /dev/null
+++ b/weinre.build/vendor/webkit/WebCore/inspector/front-end/DOMSyntaxHighlighter.js
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.DOMSyntaxHighlighter = function(mimeType)
+{
+ this._tokenizer = WebInspector.SourceTokenizer.Registry.getInstance().getTokenizer(mimeType);
+}
+
+WebInspector.DOMSyntaxHighlighter.prototype = {
+ createSpan: function(content, className)
+ {
+ var span = document.createElement("span");
+ span.className = "webkit-" + className;
+ span.appendChild(document.createTextNode(content));
+ return span;
+ },
+
+ syntaxHighlightNode: function(node)
+ {
+ this._tokenizer.condition = this._tokenizer.initialCondition;
+ var lines = node.textContent.split("\n");
+ node.removeChildren();
+
+ for (var i = lines[0].length ? 0 : 1; i < lines.length; ++i) {
+ var line = lines[i];
+ var plainTextStart = 0;
+ this._tokenizer.line = line;
+ var column = 0;
+ do {
+ var newColumn = this._tokenizer.nextToken(column);
+ var tokenType = this._tokenizer.tokenType;
+ if (tokenType) {
+ if (column > plainTextStart) {
+ var plainText = line.substring(plainTextStart, column);
+ node.appendChild(document.createTextNode(plainText));
+ }
+ var token = line.substring(column, newColumn);
+ node.appendChild(this.createSpan(token, tokenType));
+ plainTextStart = newColumn;
+ }
+ column = newColumn;
+ } while (column < line.length)
+
+ if (plainTextStart < line.length) {
+ var plainText = line.substring(plainTextStart, line.length);
+ node.appendChild(document.createTextNode(plainText));
+ }
+ if (i < lines.length - 1)
+ node.appendChild(document.createElement("br"));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/c4fbd3d0/weinre.build/vendor/webkit/WebCore/inspector/front-end/DataGrid.js
----------------------------------------------------------------------
diff --git a/weinre.build/vendor/webkit/WebCore/inspector/front-end/DataGrid.js b/weinre.build/vendor/webkit/WebCore/inspector/front-end/DataGrid.js
new file mode 100644
index 0000000..45f0b55
--- /dev/null
+++ b/weinre.build/vendor/webkit/WebCore/inspector/front-end/DataGrid.js
@@ -0,0 +1,1478 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.DataGrid = function(columns, editCallback, deleteCallback)
+{
+ this.element = document.createElement("div");
+ this.element.className = "data-grid";
+ this.element.tabIndex = 0;
+ this.element.addEventListener("keydown", this._keyDown.bind(this), false);
+
+ this._headerTable = document.createElement("table");
+ this._headerTable.className = "header";
+ this._headerTableHeaders = {};
+
+ this._dataTable = document.createElement("table");
+ this._dataTable.className = "data";
+
+ this._dataTable.addEventListener("mousedown", this._mouseDownInDataTable.bind(this), true);
+ this._dataTable.addEventListener("click", this._clickInDataTable.bind(this), true);
+
+ this._dataTable.addEventListener("contextmenu", this._contextMenuInDataTable.bind(this), true);
+
+ // FIXME: Add a createCallback which is different from editCallback and has different
+ // behavior when creating a new node.
+ if (editCallback) {
+ this._dataTable.addEventListener("dblclick", this._ondblclick.bind(this), false);
+ this._editCallback = editCallback;
+ }
+ if (deleteCallback)
+ this._deleteCallback = deleteCallback;
+
+ this.aligned = {};
+
+ this._scrollContainer = document.createElement("div");
+ this._scrollContainer.className = "data-container";
+ this._scrollContainer.appendChild(this._dataTable);
+
+ this.element.appendChild(this._headerTable);
+ this.element.appendChild(this._scrollContainer);
+
+ var headerRow = document.createElement("tr");
+ var columnGroup = document.createElement("colgroup");
+ this._columnCount = 0;
+
+ for (var columnIdentifier in columns) {
+ var column = columns[columnIdentifier];
+ if (column.disclosure)
+ this.disclosureColumnIdentifier = columnIdentifier;
+
+ var col = document.createElement("col");
+ if (column.width)
+ col.style.width = column.width;
+ column.element = col;
+ columnGroup.appendChild(col);
+
+ var cell = document.createElement("th");
+ cell.className = columnIdentifier + "-column";
+ cell.columnIdentifier = columnIdentifier;
+ this._headerTableHeaders[columnIdentifier] = cell;
+
+ var div = document.createElement("div");
+ if (column.titleDOMFragment)
+ div.appendChild(column.titleDOMFragment);
+ else
+ div.textContent = column.title;
+ cell.appendChild(div);
+
+ if (column.sort) {
+ cell.addStyleClass("sort-" + column.sort);
+ this._sortColumnCell = cell;
+ }
+
+ if (column.sortable) {
+ cell.addEventListener("click", this._clickInHeaderCell.bind(this), false);
+ cell.addStyleClass("sortable");
+ }
+
+ if (column.aligned)
+ this.aligned[columnIdentifier] = column.aligned;
+
+ headerRow.appendChild(cell);
+
+ ++this._columnCount;
+ }
+
+ columnGroup.span = this._columnCount;
+
+ var cell = document.createElement("th");
+ cell.className = "corner";
+ headerRow.appendChild(cell);
+
+ this._headerTableColumnGroup = columnGroup;
+ this._headerTable.appendChild(this._headerTableColumnGroup);
+ this.headerTableBody.appendChild(headerRow);
+
+ var fillerRow = document.createElement("tr");
+ fillerRow.className = "filler";
+
+ for (var columnIdentifier in columns) {
+ var column = columns[columnIdentifier];
+ var cell = document.createElement("td");
+ cell.className = columnIdentifier + "-column";
+ fillerRow.appendChild(cell);
+ }
+
+ this._dataTableColumnGroup = columnGroup.cloneNode(true);
+ this._dataTable.appendChild(this._dataTableColumnGroup);
+ this.dataTableBody.appendChild(fillerRow);
+
+ this.columns = columns || {};
+ this._columnsArray = [];
+ for (var columnIdentifier in columns) {
+ columns[columnIdentifier].ordinal = this._columnsArray.length;
+ this._columnsArray.push(columns[columnIdentifier]);
+ }
+
+ for (var i = 0; i < this._columnsArray.length; ++i)
+ this._columnsArray[i].bodyElement = this._dataTableColumnGroup.children[i];
+
+ this.children = [];
+ this.selectedNode = null;
+ this.expandNodesWhenArrowing = false;
+ this.root = true;
+ this.hasChildren = false;
+ this.expanded = true;
+ this.revealed = true;
+ this.selected = false;
+ this.dataGrid = this;
+ this.indentWidth = 15;
+ this.resizers = [];
+ this._columnWidthsInitialized = false;
+}
+
+WebInspector.DataGrid.prototype = {
+ _ondblclick: function(event)
+ {
+ if (this._editing || this._editingNode)
+ return;
+
+ this._startEditing(event.target);
+ },
+
+ _startEditingColumnOfDataGridNode: function(node, column)
+ {
+ this._editing = true;
+ this._editingNode = node;
+ this._editingNode.select();
+
+ var element = this._editingNode._element.children[column];
+ WebInspector.startEditing(element, {
+ context: element.textContent,
+ commitHandler: this._editingCommitted.bind(this),
+ cancelHandler: this._editingCancelled.bind(this)
+ });
+ window.getSelection().setBaseAndExtent(element, 0, element, 1);
+ },
+
+ _startEditing: function(target)
+ {
+ var element = target.enclosingNodeOrSelfWithNodeName("td");
+ if (!element)
+ return;
+
+ this._editingNode = this.dataGridNodeFromNode(target);
+ if (!this._editingNode) {
+ if (!this.creationNode)
+ return;
+ this._editingNode = this.creationNode;
+ }
+
+ // Force editing the 1st column when editing the creation node
+ if (this._editingNode.isCreationNode)
+ return this._startEditingColumnOfDataGridNode(this._editingNode, 0);
+
+ this._editing = true;
+ WebInspector.startEditing(element, {
+ context: element.textContent,
+ commitHandler: this._editingCommitted.bind(this),
+ cancelHandler: this._editingCancelled.bind(this)
+ });
+ window.getSelection().setBaseAndExtent(element, 0, element, 1);
+ },
+
+ _editingCommitted: function(element, newText, oldText, context, moveDirection)
+ {
+ // FIXME: We need more column identifiers here throughout this function.
+ // Not needed yet since only editable DataGrid is DOM Storage, which is Key - Value.
+
+ // FIXME: Better way to do this than regular expressions?
+ var columnIdentifier = parseInt(element.className.match(/\b(\d+)-column\b/)[1]);
+
+ var textBeforeEditing = this._editingNode.data[columnIdentifier];
+ var currentEditingNode = this._editingNode;
+
+ function moveToNextIfNeeded(wasChange) {
+ if (!moveDirection)
+ return;
+
+ if (moveDirection === "forward") {
+ if (currentEditingNode.isCreationNode && columnIdentifier === 0 && !wasChange)
+ return;
+
+ if (columnIdentifier === 0)
+ return this._startEditingColumnOfDataGridNode(currentEditingNode, 1);
+
+ var nextDataGridNode = currentEditingNode.traverseNextNode(true, null, true);
+ if (nextDataGridNode)
+ return this._startEditingColumnOfDataGridNode(nextDataGridNode, 0);
+ if (currentEditingNode.isCreationNode && wasChange) {
+ addCreationNode(false);
+ return this._startEditingColumnOfDataGridNode(this.creationNode, 0);
+ }
+ return;
+ }
+
+ if (moveDirection === "backward") {
+ if (columnIdentifier === 1)
+ return this._startEditingColumnOfDataGridNode(currentEditingNode, 0);
+ var nextDataGridNode = currentEditingNode.traversePreviousNode(true, null, true);
+
+ if (nextDataGridNode)
+ return this._startEditingColumnOfDataGridNode(nextDataGridNode, 1);
+ return;
+ }
+ }
+
+ if (textBeforeEditing == newText) {
+ this._editingCancelled(element);
+ moveToNextIfNeeded.call(this, false);
+ return;
+ }
+
+ // Update the text in the datagrid that we typed
+ this._editingNode.data[columnIdentifier] = newText;
+
+ // Make the callback - expects an editing node (table row), the column number that is being edited,
+ // the text that used to be there, and the new text.
+ this._editCallback(this._editingNode, columnIdentifier, textBeforeEditing, newText);
+
+ if (this._editingNode.isCreationNode)
+ this.addCreationNode(false);
+
+ this._editingCancelled(element);
+ moveToNextIfNeeded.call(this, true);
+ },
+
+ _editingCancelled: function(element, context)
+ {
+ delete this._editing;
+ this._editingNode = null;
+ },
+
+ get sortColumnIdentifier()
+ {
+ if (!this._sortColumnCell)
+ return null;
+ return this._sortColumnCell.columnIdentifier;
+ },
+
+ get sortOrder()
+ {
+ if (!this._sortColumnCell || this._sortColumnCell.hasStyleClass("sort-ascending"))
+ return "ascending";
+ if (this._sortColumnCell.hasStyleClass("sort-descending"))
+ return "descending";
+ return null;
+ },
+
+ get headerTableBody()
+ {
+ if ("_headerTableBody" in this)
+ return this._headerTableBody;
+
+ this._headerTableBody = this._headerTable.getElementsByTagName("tbody")[0];
+ if (!this._headerTableBody) {
+ this._headerTableBody = this.element.ownerDocument.createElement("tbody");
+ this._headerTable.insertBefore(this._headerTableBody, this._headerTable.tFoot);
+ }
+
+ return this._headerTableBody;
+ },
+
+ get dataTableBody()
+ {
+ if ("_dataTableBody" in this)
+ return this._dataTableBody;
+
+ this._dataTableBody = this._dataTable.getElementsByTagName("tbody")[0];
+ if (!this._dataTableBody) {
+ this._dataTableBody = this.element.ownerDocument.createElement("tbody");
+ this._dataTable.insertBefore(this._dataTableBody, this._dataTable.tFoot);
+ }
+
+ return this._dataTableBody;
+ },
+
+ autoSizeColumns: function(minPercent, maxPercent, maxDescentLevel)
+ {
+ if (minPercent)
+ minPercent = Math.min(minPercent, Math.floor(100 / this._columnCount));
+ var widths = {};
+ var columns = this.columns;
+ for (var columnIdentifier in columns)
+ widths[columnIdentifier] = (columns[columnIdentifier].title || "").length;
+
+ var children = maxDescentLevel ? this._enumerateChildren(this, [], maxDescentLevel + 1) : this.children;
+ for (var i = 0; i < children.length; ++i) {
+ var node = children[i];
+ for (var columnIdentifier in columns) {
+ var text = node.data[columnIdentifier] || "";
+ if (text.length > widths[columnIdentifier])
+ widths[columnIdentifier] = text.length;
+ }
+ }
+
+ var totalColumnWidths = 0;
+ for (var columnIdentifier in columns)
+ totalColumnWidths += widths[columnIdentifier];
+
+ var recoupPercent = 0;
+ for (var columnIdentifier in columns) {
+ var width = Math.round(100 * widths[columnIdentifier] / totalColumnWidths);
+ if (minPercent && width < minPercent) {
+ recoupPercent += (minPercent - width);
+ width = minPercent;
+ } else if (maxPercent && width > maxPercent) {
+ recoupPercent -= (width - maxPercent);
+ width = maxPercent;
+ }
+ widths[columnIdentifier] = width;
+ }
+
+ while (minPercent && recoupPercent > 0) {
+ for (var columnIdentifier in columns) {
+ if (widths[columnIdentifier] > minPercent) {
+ --widths[columnIdentifier];
+ --recoupPercent;
+ if (!recoupPercent)
+ break;
+ }
+ }
+ }
+
+ while (maxPercent && recoupPercent < 0) {
+ for (var columnIdentifier in columns) {
+ if (widths[columnIdentifier] < maxPercent) {
+ ++widths[columnIdentifier];
+ ++recoupPercent;
+ if (!recoupPercent)
+ break;
+ }
+ }
+ }
+
+ for (var columnIdentifier in columns)
+ columns[columnIdentifier].element.style.width = widths[columnIdentifier] + "%";
+ this._columnWidthsInitialized = false;
+ this.updateWidths();
+ },
+
+ _enumerateChildren: function(rootNode, result, maxLevel)
+ {
+ if (!rootNode.root)
+ result.push(rootNode);
+ if (!maxLevel)
+ return;
+ for (var i = 0; i < rootNode.children.length; ++i)
+ this._enumerateChildren(rootNode.children[i], result, maxLevel - 1);
+ return result;
+ },
+
+ // Updates the widths of the table, including the positions of the column
+ // resizers.
+ //
+ // IMPORTANT: This function MUST be called once after the element of the
+ // DataGrid is attached to its parent element and every subsequent time the
+ // width of the parent element is changed in order to make it possible to
+ // resize the columns.
+ //
+ // If this function is not called after the DataGrid is attached to its
+ // parent element, then the DataGrid's columns will not be resizable.
+ updateWidths: function()
+ {
+ var headerTableColumns = this._headerTableColumnGroup.children;
+
+ var tableWidth = this._dataTable.offsetWidth;
+ var numColumns = headerTableColumns.length;
+
+ // Do not attempt to use offsetes if we're not attached to the document tree yet.
+ if (!this._columnWidthsInitialized && this.element.offsetWidth) {
+ // Give all the columns initial widths now so that during a resize,
+ // when the two columns that get resized get a percent value for
+ // their widths, all the other columns already have percent values
+ // for their widths.
+ for (var i = 0; i < numColumns; i++) {
+ var columnWidth = this.headerTableBody.rows[0].cells[i].offsetWidth;
+ var percentWidth = ((columnWidth / tableWidth) * 100) + "%";
+ this._headerTableColumnGroup.children[i].style.width = percentWidth;
+ this._dataTableColumnGroup.children[i].style.width = percentWidth;
+ }
+ this._columnWidthsInitialized = true;
+ }
+ this._positionResizers();
+ this.dispatchEventToListeners("width changed");
+ },
+
+ columnWidthsMap: function()
+ {
+ var result = {};
+ for (var i = 0; i < this._columnsArray.length; ++i) {
+ var width = this._headerTableColumnGroup.children[i].style.width;
+ result[this._columnsArray[i].columnIdentifier] = parseFloat(width);
+ }
+ return result;
+ },
+
+ applyColumnWidthsMap: function(columnWidthsMap)
+ {
+ for (var columnIdentifier in this.columns) {
+ var column = this.columns[columnIdentifier];
+ var width = (columnWidthsMap[columnIdentifier] || 0) + "%";
+ this._headerTableColumnGroup.children[column.ordinal].style.width = width;
+ this._dataTableColumnGroup.children[column.ordinal].style.width = width;
+ }
+
+ // Normalize widths
+ delete this._columnWidthsInitialized;
+ this.updateWidths();
+ },
+
+ isColumnVisible: function(columnIdentifier)
+ {
+ var column = this.columns[columnIdentifier];
+ var columnElement = column.element;
+ return !columnElement.hidden;
+ },
+
+ showColumn: function(columnIdentifier)
+ {
+ var column = this.columns[columnIdentifier];
+ var columnElement = column.element;
+ if (!columnElement.hidden)
+ return;
+
+ columnElement.hidden = false;
+ columnElement.removeStyleClass("hidden");
+
+ var columnBodyElement = column.bodyElement;
+ columnBodyElement.hidden = false;
+ columnBodyElement.removeStyleClass("hidden");
+ },
+
+ hideColumn: function(columnIdentifier)
+ {
+ var column = this.columns[columnIdentifier];
+ var columnElement = column.element;
+ if (columnElement.hidden)
+ return;
+
+ var oldWidth = parseFloat(columnElement.style.width);
+
+ columnElement.hidden = true;
+ columnElement.addStyleClass("hidden");
+ columnElement.style.width = 0;
+
+ var columnBodyElement = column.bodyElement;
+ columnBodyElement.hidden = true;
+ columnBodyElement.addStyleClass("hidden");
+ columnBodyElement.style.width = 0;
+
+ this._columnWidthsInitialized = false;
+ },
+
+ get scrollContainer()
+ {
+ return this._scrollContainer;
+ },
+
+ isScrolledToLastRow: function()
+ {
+ return this._scrollContainer.isScrolledToBottom();
+ },
+
+ scrollToLastRow: function()
+ {
+ this._scrollContainer.scrollTop = this._scrollContainer.scrollHeight - this._scrollContainer.offsetHeight;
+ },
+
+ _positionResizers: function()
+ {
+ var headerTableColumns = this._headerTableColumnGroup.children;
+ var numColumns = headerTableColumns.length;
+ var left = 0;
+ var previousResizer = null;
+
+ // Make n - 1 resizers for n columns.
+ for (var i = 0; i < numColumns - 1; i++) {
+ var resizer = this.resizers[i];
+
+ if (!resizer) {
+ // This is the first call to updateWidth, so the resizers need
+ // to be created.
+ resizer = document.createElement("div");
+ resizer.addStyleClass("data-grid-resizer");
+ // This resizer is associated with the column to its right.
+ resizer.addEventListener("mousedown", this._startResizerDragging.bind(this), false);
+ this.element.appendChild(resizer);
+ this.resizers[i] = resizer;
+ }
+
+ // Get the width of the cell in the first (and only) row of the
+ // header table in order to determine the width of the column, since
+ // it is not possible to query a column for its width.
+ left += this.headerTableBody.rows[0].cells[i].offsetWidth;
+
+ var columnIsVisible = !this._headerTableColumnGroup.children[i].hidden;
+ if (columnIsVisible) {
+ resizer.style.removeProperty("display");
+ resizer.style.left = left + "px";
+ resizer.leftNeighboringColumnID = i;
+ if (previousResizer)
+ previousResizer.rightNeighboringColumnID = i;
+ previousResizer = resizer;
+ } else {
+ resizer.style.setProperty("display", "none");
+ resizer.leftNeighboringColumnID = 0;
+ resizer.rightNeighboringColumnID = 0;
+ }
+ }
+ if (previousResizer)
+ previousResizer.rightNeighboringColumnID = numColumns - 1;
+ },
+
+ addCreationNode: function(hasChildren)
+ {
+ if (this.creationNode)
+ this.creationNode.makeNormal();
+
+ var emptyData = {};
+ for (var column in this.columns)
+ emptyData[column] = '';
+ this.creationNode = new WebInspector.CreationDataGridNode(emptyData, hasChildren);
+ this.appendChild(this.creationNode);
+ },
+
+ appendChild: function(child)
+ {
+ this.insertChild(child, this.children.length);
+ },
+
+ insertChild: function(child, index)
+ {
+ if (!child)
+ throw("insertChild: Node can't be undefined or null.");
+ if (child.parent === this)
+ throw("insertChild: Node is already a child of this node.");
+
+ if (child.parent)
+ child.parent.removeChild(child);
+
+ this.children.splice(index, 0, child);
+ this.hasChildren = true;
+
+ child.parent = this;
+ child.dataGrid = this.dataGrid;
+ child._recalculateSiblings(index);
+
+ delete child._depth;
+ delete child._revealed;
+ delete child._attached;
+ child._shouldRefreshChildren = true;
+
+ var current = child.children[0];
+ while (current) {
+ current.dataGrid = this.dataGrid;
+ delete current._depth;
+ delete current._revealed;
+ delete current._attached;
+ current._shouldRefreshChildren = true;
+ current = current.traverseNextNode(false, child, true);
+ }
+
+ if (this.expanded)
+ child._attach();
+ },
+
+ removeChild: function(child)
+ {
+ if (!child)
+ throw("removeChild: Node can't be undefined or null.");
+ if (child.parent !== this)
+ throw("removeChild: Node is not a child of this node.");
+
+ child.deselect();
+ child._detach();
+
+ this.children.remove(child, true);
+
+ if (child.previousSibling)
+ child.previousSibling.nextSibling = child.nextSibling;
+ if (child.nextSibling)
+ child.nextSibling.previousSibling = child.previousSibling;
+
+ child.dataGrid = null;
+ child.parent = null;
+ child.nextSibling = null;
+ child.previousSibling = null;
+
+ if (this.children.length <= 0)
+ this.hasChildren = false;
+ },
+
+ removeChildren: function()
+ {
+ for (var i = 0; i < this.children.length; ++i) {
+ var child = this.children[i];
+ child.deselect();
+ child._detach();
+
+ child.dataGrid = null;
+ child.parent = null;
+ child.nextSibling = null;
+ child.previousSibling = null;
+ }
+
+ this.children = [];
+ this.hasChildren = false;
+ },
+
+ removeChildrenRecursive: function()
+ {
+ var childrenToRemove = this.children;
+
+ var child = this.children[0];
+ while (child) {
+ if (child.children.length)
+ childrenToRemove = childrenToRemove.concat(child.children);
+ child = child.traverseNextNode(false, this, true);
+ }
+
+ for (var i = 0; i < childrenToRemove.length; ++i) {
+ var child = childrenToRemove[i];
+ child.deselect();
+ child._detach();
+
+ child.children = [];
+ child.dataGrid = null;
+ child.parent = null;
+ child.nextSibling = null;
+ child.previousSibling = null;
+ }
+
+ this.children = [];
+ },
+
+ sortNodes: function(comparator, reverseMode)
+ {
+ function comparatorWrapper(a, b)
+ {
+ if (a._dataGridNode._data.summaryRow)
+ return 1;
+ if (b._dataGridNode._data.summaryRow)
+ return -1;
+
+ var aDataGirdNode = a._dataGridNode;
+ var bDataGirdNode = b._dataGridNode;
+ return reverseMode ? comparator(bDataGirdNode, aDataGirdNode) : comparator(aDataGirdNode, bDataGirdNode);
+ }
+
+ var tbody = this.dataTableBody;
+ var tbodyParent = tbody.parentElement;
+ tbodyParent.removeChild(tbody);
+
+ var childNodes = tbody.childNodes;
+ var fillerRow = childNodes[childNodes.length - 1];
+
+ var sortedRows = Array.prototype.slice.call(childNodes, 0, childNodes.length - 1);
+ sortedRows.sort(comparatorWrapper);
+ var sortedRowsLength = sortedRows.length;
+
+ tbody.removeChildren();
+ var previousSiblingNode = null;
+ for (var i = 0; i < sortedRowsLength; ++i) {
+ var row = sortedRows[i];
+ var node = row._dataGridNode;
+ node.previousSibling = previousSiblingNode;
+ if (previousSiblingNode)
+ previousSiblingNode.nextSibling = node;
+ tbody.appendChild(row);
+ previousSiblingNode = node;
+ }
+ if (previousSiblingNode)
+ previousSiblingNode.nextSibling = null;
+
+ tbody.appendChild(fillerRow);
+ tbodyParent.appendChild(tbody);
+ },
+
+ _keyDown: function(event)
+ {
+ if (!this.selectedNode || event.shiftKey || event.metaKey || event.ctrlKey || this._editing)
+ return;
+
+ var handled = false;
+ var nextSelectedNode;
+ if (event.keyIdentifier === "Up" && !event.altKey) {
+ nextSelectedNode = this.selectedNode.traversePreviousNode(true);
+ while (nextSelectedNode && !nextSelectedNode.selectable)
+ nextSelectedNode = nextSelectedNode.traversePreviousNode(!this.expandTreeNodesWhenArrowing);
+ handled = nextSelectedNode ? true : false;
+ } else if (event.keyIdentifier === "Down" && !event.altKey) {
+ nextSelectedNode = this.selectedNode.traverseNextNode(true);
+ while (nextSelectedNode && !nextSelectedNode.selectable)
+ nextSelectedNode = nextSelectedNode.traverseNextNode(!this.expandTreeNodesWhenArrowing);
+ handled = nextSelectedNode ? true : false;
+ } else if (event.keyIdentifier === "Left") {
+ if (this.selectedNode.expanded) {
+ if (event.altKey)
+ this.selectedNode.collapseRecursively();
+ else
+ this.selectedNode.collapse();
+ handled = true;
+ } else if (this.selectedNode.parent && !this.selectedNode.parent.root) {
+ handled = true;
+ if (this.selectedNode.parent.selectable) {
+ nextSelectedNode = this.selectedNode.parent;
+ handled = nextSelectedNode ? true : false;
+ } else if (this.selectedNode.parent)
+ this.selectedNode.parent.collapse();
+ }
+ } else if (event.keyIdentifier === "Right") {
+ if (!this.selectedNode.revealed) {
+ this.selectedNode.reveal();
+ handled = true;
+ } else if (this.selectedNode.hasChildren) {
+ handled = true;
+ if (this.selectedNode.expanded) {
+ nextSelectedNode = this.selectedNode.children[0];
+ handled = nextSelectedNode ? true : false;
+ } else {
+ if (event.altKey)
+ this.selectedNode.expandRecursively();
+ else
+ this.selectedNode.expand();
+ }
+ }
+ } else if (event.keyCode === 8 || event.keyCode === 46) {
+ if (this._deleteCallback) {
+ handled = true;
+ this._deleteCallback(this.selectedNode);
+ }
+ } else if (isEnterKey(event)) {
+ if (this._editCallback) {
+ handled = true;
+ // The first child of the selected element is the <td class="0-column">,
+ // and that's what we want to edit.
+ this._startEditing(this.selectedNode._element.children[0]);
+ }
+ }
+
+ if (nextSelectedNode) {
+ nextSelectedNode.reveal();
+ nextSelectedNode.select();
+ }
+
+ if (handled) {
+ event.preventDefault();
+ event.stopPropagation();
+ }
+ },
+
+ expand: function()
+ {
+ // This is the root, do nothing.
+ },
+
+ collapse: function()
+ {
+ // This is the root, do nothing.
+ },
+
+ reveal: function()
+ {
+ // This is the root, do nothing.
+ },
+
+ dataGridNodeFromNode: function(target)
+ {
+ var rowElement = target.enclosingNodeOrSelfWithNodeName("tr");
+ return rowElement._dataGridNode;
+ },
+
+ dataGridNodeFromPoint: function(x, y)
+ {
+ var node = this._dataTable.ownerDocument.elementFromPoint(x, y);
+ var rowElement = node.enclosingNodeOrSelfWithNodeName("tr");
+ return rowElement._dataGridNode;
+ },
+
+ _clickInHeaderCell: function(event)
+ {
+ var cell = event.target.enclosingNodeOrSelfWithNodeName("th");
+ if (!cell || !cell.columnIdentifier || !cell.hasStyleClass("sortable"))
+ return;
+
+ var sortOrder = this.sortOrder;
+
+ if (this._sortColumnCell)
+ this._sortColumnCell.removeMatchingStyleClasses("sort-\\w+");
+
+ if (cell == this._sortColumnCell) {
+ if (sortOrder === "ascending")
+ sortOrder = "descending";
+ else
+ sortOrder = "ascending";
+ }
+
+ this._sortColumnCell = cell;
+
+ cell.addStyleClass("sort-" + sortOrder);
+
+ this.dispatchEventToListeners("sorting changed");
+ },
+
+ markColumnAsSortedBy: function(columnIdentifier, sortOrder)
+ {
+ if (this._sortColumnCell)
+ this._sortColumnCell.removeMatchingStyleClasses("sort-\\w+");
+ this._sortColumnCell = this._headerTableHeaders[columnIdentifier];
+ this._sortColumnCell.addStyleClass("sort-" + sortOrder);
+ },
+
+ headerTableHeader: function(columnIdentifier)
+ {
+ return this._headerTableHeaders[columnIdentifier];
+ },
+
+ _mouseDownInDataTable: function(event)
+ {
+ var gridNode = this.dataGridNodeFromNode(event.target);
+ if (!gridNode || !gridNode.selectable)
+ return;
+
+ if (gridNode.isEventWithinDisclosureTriangle(event))
+ return;
+
+ if (event.metaKey) {
+ if (gridNode.selected)
+ gridNode.deselect();
+ else
+ gridNode.select();
+ } else
+ gridNode.select();
+ },
+
+ _contextMenuInDataTable: function(event)
+ {
+ var gridNode = this.dataGridNodeFromNode(event.target);
+ if (!gridNode || !gridNode.selectable)
+ return;
+
+ if (gridNode.isEventWithinDisclosureTriangle(event))
+ return;
+
+ var contextMenu = new WebInspector.ContextMenu();
+
+ // FIXME: Use the column names for Editing, instead of just "Edit".
+ if (this.dataGrid._editCallback) {
+ if (gridNode === this.creationNode)
+ contextMenu.appendItem(WebInspector.UIString("Add New"), this._startEditing.bind(this, event.target));
+ else
+ contextMenu.appendItem(WebInspector.UIString("Edit"), this._startEditing.bind(this, event.target));
+ }
+ if (this.dataGrid._deleteCallback && gridNode !== this.creationNode)
+ contextMenu.appendItem(WebInspector.UIString("Delete"), this._deleteCallback.bind(this, gridNode));
+
+ contextMenu.show(event);
+ },
+
+ _clickInDataTable: function(event)
+ {
+ var gridNode = this.dataGridNodeFromNode(event.target);
+ if (!gridNode || !gridNode.hasChildren)
+ return;
+
+ if (!gridNode.isEventWithinDisclosureTriangle(event))
+ return;
+
+ if (gridNode.expanded) {
+ if (event.altKey)
+ gridNode.collapseRecursively();
+ else
+ gridNode.collapse();
+ } else {
+ if (event.altKey)
+ gridNode.expandRecursively();
+ else
+ gridNode.expand();
+ }
+ },
+
+ _startResizerDragging: function(event)
+ {
+ this.currentResizer = event.target;
+ if (!this.currentResizer.rightNeighboringColumnID)
+ return;
+ WebInspector.elementDragStart(this.lastResizer, this._resizerDragging.bind(this),
+ this._endResizerDragging.bind(this), event, "col-resize");
+ },
+
+ _resizerDragging: function(event)
+ {
+ var resizer = this.currentResizer;
+ if (!resizer)
+ return;
+
+ // Constrain the dragpoint to be within the containing div of the
+ // datagrid.
+ var dragPoint = event.clientX - this.element.totalOffsetLeft;
+ // Constrain the dragpoint to be within the space made up by the
+ // column directly to the left and the column directly to the right.
+ var leftEdgeOfPreviousColumn = 0;
+ var firstRowCells = this.headerTableBody.rows[0].cells;
+ for (var i = 0; i < resizer.leftNeighboringColumnID; i++)
+ leftEdgeOfPreviousColumn += firstRowCells[i].offsetWidth;
+
+ var rightEdgeOfNextColumn = leftEdgeOfPreviousColumn + firstRowCells[resizer.leftNeighboringColumnID].offsetWidth + firstRowCells[resizer.rightNeighboringColumnID].offsetWidth;
+
+ // Give each column some padding so that they don't disappear.
+ var leftMinimum = leftEdgeOfPreviousColumn + this.ColumnResizePadding;
+ var rightMaximum = rightEdgeOfNextColumn - this.ColumnResizePadding;
+
+ dragPoint = Number.constrain(dragPoint, leftMinimum, rightMaximum);
+
+ resizer.style.left = (dragPoint - this.CenterResizerOverBorderAdjustment) + "px";
+
+ var percentLeftColumn = (((dragPoint - leftEdgeOfPreviousColumn) / this._dataTable.offsetWidth) * 100) + "%";
+ this._headerTableColumnGroup.children[resizer.leftNeighboringColumnID].style.width = percentLeftColumn;
+ this._dataTableColumnGroup.children[resizer.leftNeighboringColumnID].style.width = percentLeftColumn;
+
+ var percentRightColumn = (((rightEdgeOfNextColumn - dragPoint) / this._dataTable.offsetWidth) * 100) + "%";
+ this._headerTableColumnGroup.children[resizer.rightNeighboringColumnID].style.width = percentRightColumn;
+ this._dataTableColumnGroup.children[resizer.rightNeighboringColumnID].style.width = percentRightColumn;
+
+ this._positionResizers();
+ event.preventDefault();
+ this.dispatchEventToListeners("width changed");
+ },
+
+ _endResizerDragging: function(event)
+ {
+ WebInspector.elementDragEnd(event);
+ this.currentResizer = null;
+ this.dispatchEventToListeners("width changed");
+ },
+
+ ColumnResizePadding: 10,
+
+ CenterResizerOverBorderAdjustment: 3,
+}
+
+WebInspector.DataGrid.prototype.__proto__ = WebInspector.Object.prototype;
+
+WebInspector.DataGridNode = function(data, hasChildren)
+{
+ this._expanded = false;
+ this._selected = false;
+ this._shouldRefreshChildren = true;
+ this._data = data || {};
+ this.hasChildren = hasChildren || false;
+ this.children = [];
+ this.dataGrid = null;
+ this.parent = null;
+ this.previousSibling = null;
+ this.nextSibling = null;
+ this.disclosureToggleWidth = 10;
+}
+
+WebInspector.DataGridNode.prototype = {
+ selectable: true,
+
+ get element()
+ {
+ if (this._element)
+ return this._element;
+
+ if (!this.dataGrid)
+ return null;
+
+ this._element = document.createElement("tr");
+ this._element._dataGridNode = this;
+
+ if (this.hasChildren)
+ this._element.addStyleClass("parent");
+ if (this.expanded)
+ this._element.addStyleClass("expanded");
+ if (this.selected)
+ this._element.addStyleClass("selected");
+ if (this.revealed)
+ this._element.addStyleClass("revealed");
+
+ this.createCells();
+ return this._element;
+ },
+
+ createCells: function()
+ {
+ for (var columnIdentifier in this.dataGrid.columns) {
+ var cell = this.createCell(columnIdentifier);
+ this._element.appendChild(cell);
+ }
+ },
+
+ get data()
+ {
+ return this._data;
+ },
+
+ set data(x)
+ {
+ this._data = x || {};
+ this.refresh();
+ },
+
+ get revealed()
+ {
+ if ("_revealed" in this)
+ return this._revealed;
+
+ var currentAncestor = this.parent;
+ while (currentAncestor && !currentAncestor.root) {
+ if (!currentAncestor.expanded) {
+ this._revealed = false;
+ return false;
+ }
+
+ currentAncestor = currentAncestor.parent;
+ }
+
+ this._revealed = true;
+ return true;
+ },
+
+ set hasChildren(x)
+ {
+ if (this._hasChildren === x)
+ return;
+
+ this._hasChildren = x;
+
+ if (!this._element)
+ return;
+
+ if (this._hasChildren)
+ {
+ this._element.addStyleClass("parent");
+ if (this.expanded)
+ this._element.addStyleClass("expanded");
+ }
+ else
+ {
+ this._element.removeStyleClass("parent");
+ this._element.removeStyleClass("expanded");
+ }
+ },
+
+ get hasChildren()
+ {
+ return this._hasChildren;
+ },
+
+ set revealed(x)
+ {
+ if (this._revealed === x)
+ return;
+
+ this._revealed = x;
+
+ if (this._element) {
+ if (this._revealed)
+ this._element.addStyleClass("revealed");
+ else
+ this._element.removeStyleClass("revealed");
+ }
+
+ for (var i = 0; i < this.children.length; ++i)
+ this.children[i].revealed = x && this.expanded;
+ },
+
+ get depth()
+ {
+ if ("_depth" in this)
+ return this._depth;
+ if (this.parent && !this.parent.root)
+ this._depth = this.parent.depth + 1;
+ else
+ this._depth = 0;
+ return this._depth;
+ },
+
+ get shouldRefreshChildren()
+ {
+ return this._shouldRefreshChildren;
+ },
+
+ set shouldRefreshChildren(x)
+ {
+ this._shouldRefreshChildren = x;
+ if (x && this.expanded)
+ this.expand();
+ },
+
+ get selected()
+ {
+ return this._selected;
+ },
+
+ set selected(x)
+ {
+ if (x)
+ this.select();
+ else
+ this.deselect();
+ },
+
+ get expanded()
+ {
+ return this._expanded;
+ },
+
+ set expanded(x)
+ {
+ if (x)
+ this.expand();
+ else
+ this.collapse();
+ },
+
+ refresh: function()
+ {
+ if (!this._element || !this.dataGrid)
+ return;
+
+ this._element.removeChildren();
+ this.createCells();
+ },
+
+ createCell: function(columnIdentifier)
+ {
+ var cell = document.createElement("td");
+ cell.className = columnIdentifier + "-column";
+
+ var alignment = this.dataGrid.aligned[columnIdentifier];
+ if (alignment)
+ cell.addStyleClass(alignment);
+
+ var div = document.createElement("div");
+ div.textContent = this.data[columnIdentifier];
+ cell.appendChild(div);
+
+ if (columnIdentifier === this.dataGrid.disclosureColumnIdentifier) {
+ cell.addStyleClass("disclosure");
+ if (this.depth)
+ cell.style.setProperty("padding-left", (this.depth * this.dataGrid.indentWidth) + "px");
+ }
+
+ return cell;
+ },
+
+ // Share these functions with DataGrid. They are written to work with a DataGridNode this object.
+ appendChild: WebInspector.DataGrid.prototype.appendChild,
+ insertChild: WebInspector.DataGrid.prototype.insertChild,
+ removeChild: WebInspector.DataGrid.prototype.removeChild,
+ removeChildren: WebInspector.DataGrid.prototype.removeChildren,
+ removeChildrenRecursive: WebInspector.DataGrid.prototype.removeChildrenRecursive,
+
+ _recalculateSiblings: function(myIndex)
+ {
+ if (!this.parent)
+ return;
+
+ var previousChild = (myIndex > 0 ? this.parent.children[myIndex - 1] : null);
+
+ if (previousChild) {
+ previousChild.nextSibling = this;
+ this.previousSibling = previousChild;
+ } else
+ this.previousSibling = null;
+
+ var nextChild = this.parent.children[myIndex + 1];
+
+ if (nextChild) {
+ nextChild.previousSibling = this;
+ this.nextSibling = nextChild;
+ } else
+ this.nextSibling = null;
+ },
+
+ collapse: function()
+ {
+ if (this._element)
+ this._element.removeStyleClass("expanded");
+
+ this._expanded = false;
+
+ for (var i = 0; i < this.children.length; ++i)
+ this.children[i].revealed = false;
+
+ this.dispatchEventToListeners("collapsed");
+ },
+
+ collapseRecursively: function()
+ {
+ var item = this;
+ while (item) {
+ if (item.expanded)
+ item.collapse();
+ item = item.traverseNextNode(false, this, true);
+ }
+ },
+
+ expand: function()
+ {
+ if (!this.hasChildren || this.expanded)
+ return;
+
+ if (this.revealed && !this._shouldRefreshChildren)
+ for (var i = 0; i < this.children.length; ++i)
+ this.children[i].revealed = true;
+
+ if (this._shouldRefreshChildren) {
+ for (var i = 0; i < this.children.length; ++i)
+ this.children[i]._detach();
+
+ this.dispatchEventToListeners("populate");
+
+ if (this._attached) {
+ for (var i = 0; i < this.children.length; ++i) {
+ var child = this.children[i];
+ if (this.revealed)
+ child.revealed = true;
+ child._attach();
+ }
+ }
+
+ delete this._shouldRefreshChildren;
+ }
+
+ if (this._element)
+ this._element.addStyleClass("expanded");
+
+ this._expanded = true;
+
+ this.dispatchEventToListeners("expanded");
+ },
+
+ expandRecursively: function()
+ {
+ var item = this;
+ while (item) {
+ item.expand();
+ item = item.traverseNextNode(false, this);
+ }
+ },
+
+ reveal: function()
+ {
+ var currentAncestor = this.parent;
+ while (currentAncestor && !currentAncestor.root) {
+ if (!currentAncestor.expanded)
+ currentAncestor.expand();
+ currentAncestor = currentAncestor.parent;
+ }
+
+ this.element.scrollIntoViewIfNeeded(false);
+
+ this.dispatchEventToListeners("revealed");
+ },
+
+ select: function(supressSelectedEvent)
+ {
+ if (!this.dataGrid || !this.selectable || this.selected)
+ return;
+
+ if (this.dataGrid.selectedNode)
+ this.dataGrid.selectedNode.deselect();
+
+ this._selected = true;
+ this.dataGrid.selectedNode = this;
+
+ if (this._element)
+ this._element.addStyleClass("selected");
+
+ if (!supressSelectedEvent)
+ this.dispatchEventToListeners("selected");
+ },
+
+ deselect: function(supressDeselectedEvent)
+ {
+ if (!this.dataGrid || this.dataGrid.selectedNode !== this || !this.selected)
+ return;
+
+ this._selected = false;
+ this.dataGrid.selectedNode = null;
+
+ if (this._element)
+ this._element.removeStyleClass("selected");
+
+ if (!supressDeselectedEvent)
+ this.dispatchEventToListeners("deselected");
+ },
+
+ traverseNextNode: function(skipHidden, stayWithin, dontPopulate, info)
+ {
+ if (!dontPopulate && this.hasChildren)
+ this.dispatchEventToListeners("populate");
+
+ if (info)
+ info.depthChange = 0;
+
+ var node = (!skipHidden || this.revealed) ? this.children[0] : null;
+ if (node && (!skipHidden || this.expanded)) {
+ if (info)
+ info.depthChange = 1;
+ return node;
+ }
+
+ if (this === stayWithin)
+ return null;
+
+ node = (!skipHidden || this.revealed) ? this.nextSibling : null;
+ if (node)
+ return node;
+
+ node = this;
+ while (node && !node.root && !((!skipHidden || node.revealed) ? node.nextSibling : null) && node.parent !== stayWithin) {
+ if (info)
+ info.depthChange -= 1;
+ node = node.parent;
+ }
+
+ if (!node)
+ return null;
+
+ return (!skipHidden || node.revealed) ? node.nextSibling : null;
+ },
+
+ traversePreviousNode: function(skipHidden, dontPopulate)
+ {
+ var node = (!skipHidden || this.revealed) ? this.previousSibling : null;
+ if (!dontPopulate && node && node.hasChildren)
+ node.dispatchEventToListeners("populate");
+
+ while (node && ((!skipHidden || (node.revealed && node.expanded)) ? node.children[node.children.length - 1] : null)) {
+ if (!dontPopulate && node.hasChildren)
+ node.dispatchEventToListeners("populate");
+ node = ((!skipHidden || (node.revealed && node.expanded)) ? node.children[node.children.length - 1] : null);
+ }
+
+ if (node)
+ return node;
+
+ if (!this.parent || this.parent.root)
+ return null;
+
+ return this.parent;
+ },
+
+ isEventWithinDisclosureTriangle: function(event)
+ {
+ if (!this.hasChildren)
+ return false;
+ var cell = event.target.enclosingNodeOrSelfWithNodeName("td");
+ if (!cell.hasStyleClass("disclosure"))
+ return false;
+ var computedLeftPadding = window.getComputedStyle(cell).getPropertyCSSValue("padding-left").getFloatValue(CSSPrimitiveValue.CSS_PX);
+ var left = cell.totalOffsetLeft + computedLeftPadding;
+ return event.pageX >= left && event.pageX <= left + this.disclosureToggleWidth;
+ },
+
+ _attach: function()
+ {
+ if (!this.dataGrid || this._attached)
+ return;
+
+ this._attached = true;
+
+ var nextNode = null;
+ var previousNode = this.traversePreviousNode(true, true);
+ if (previousNode && previousNode.element.parentNode && previousNode.element.nextSibling)
+ var nextNode = previousNode.element.nextSibling;
+ if (!nextNode)
+ nextNode = this.dataGrid.dataTableBody.lastChild;
+ this.dataGrid.dataTableBody.insertBefore(this.element, nextNode);
+
+ if (this.expanded)
+ for (var i = 0; i < this.children.length; ++i)
+ this.children[i]._attach();
+ },
+
+ _detach: function()
+ {
+ if (!this._attached)
+ return;
+
+ this._attached = false;
+
+ if (this._element && this._element.parentNode)
+ this._element.parentNode.removeChild(this._element);
+
+ for (var i = 0; i < this.children.length; ++i)
+ this.children[i]._detach();
+ },
+
+ savePosition: function()
+ {
+ if (this._savedPosition)
+ return;
+
+ if (!this.parent)
+ throw("savePosition: Node must have a parent.");
+ this._savedPosition = {
+ parent: this.parent,
+ index: this.parent.children.indexOf(this)
+ };
+ },
+
+ restorePosition: function()
+ {
+ if (!this._savedPosition)
+ return;
+
+ if (this.parent !== this._savedPosition.parent)
+ this._savedPosition.parent.insertChild(this, this._savedPosition.index);
+
+ delete this._savedPosition;
+ }
+}
+
+WebInspector.DataGridNode.prototype.__proto__ = WebInspector.Object.prototype;
+
+WebInspector.CreationDataGridNode = function(data, hasChildren)
+{
+ WebInspector.DataGridNode.call(this, data, hasChildren);
+ this.isCreationNode = true;
+}
+
+WebInspector.CreationDataGridNode.prototype = {
+ makeNormal: function()
+ {
+ delete this.isCreationNode;
+ delete this.makeNormal;
+ }
+}
+
+WebInspector.CreationDataGridNode.prototype.__proto__ = WebInspector.DataGridNode.prototype;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/c4fbd3d0/weinre.build/vendor/webkit/WebCore/inspector/front-end/Database.js
----------------------------------------------------------------------
diff --git a/weinre.build/vendor/webkit/WebCore/inspector/front-end/Database.js b/weinre.build/vendor/webkit/WebCore/inspector/front-end/Database.js
new file mode 100644
index 0000000..effb809
--- /dev/null
+++ b/weinre.build/vendor/webkit/WebCore/inspector/front-end/Database.js
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.Database = function(id, domain, name, version)
+{
+ this._id = id;
+ this._domain = domain;
+ this._name = name;
+ this._version = version;
+}
+
+WebInspector.Database.prototype = {
+ get id()
+ {
+ return this._id;
+ },
+
+ get name()
+ {
+ return this._name;
+ },
+
+ set name(x)
+ {
+ this._name = x;
+ },
+
+ get version()
+ {
+ return this._version;
+ },
+
+ set version(x)
+ {
+ this._version = x;
+ },
+
+ get domain()
+ {
+ return this._domain;
+ },
+
+ set domain(x)
+ {
+ this._domain = x;
+ },
+
+ get displayDomain()
+ {
+ return WebInspector.Resource.prototype.__lookupGetter__("displayDomain").call(this);
+ },
+
+ getTableNames: function(callback)
+ {
+ function sortingCallback(names)
+ {
+ callback(names.sort());
+ }
+ InspectorBackend.getDatabaseTableNames(this._id, sortingCallback);
+ },
+
+ executeSql: function(query, onSuccess, onError)
+ {
+ function callback(success, transactionId)
+ {
+ if (!success) {
+ onError(WebInspector.UIString("Database not found."));
+ return;
+ }
+ WebInspector.DatabaseDispatcher._callbacks[transactionId] = {"onSuccess": onSuccess, "onError": onError};
+ }
+ InspectorBackend.executeSQL(this._id, query, callback);
+ }
+}
+
+WebInspector.DatabaseDispatcher = function()
+{
+}
+
+WebInspector.DatabaseDispatcher._callbacks = {};
+
+WebInspector.DatabaseDispatcher.prototype = {
+ addDatabase: function(payload)
+ {
+ var database = new WebInspector.Database(
+ payload.id,
+ payload.domain,
+ payload.name,
+ payload.version);
+ WebInspector.panels.resources.addDatabase(database);
+ },
+
+ selectDatabase: function(o)
+ {
+ WebInspector.showPanel("resources");
+ WebInspector.panels.resources.selectDatabase(o);
+ },
+
+ sqlTransactionSucceeded: function(transactionId, columnNames, values)
+ {
+ if (!WebInspector.DatabaseDispatcher._callbacks[transactionId])
+ return;
+
+ var callback = WebInspector.DatabaseDispatcher._callbacks[transactionId].onSuccess;
+ delete WebInspector.DatabaseDispatcher._callbacks[transactionId];
+ if (callback)
+ callback(columnNames, values);
+ },
+
+ sqlTransactionFailed: function(transactionId, errorObj)
+ {
+ if (!WebInspector.DatabaseDispatcher._callbacks[transactionId])
+ return;
+
+ var callback = WebInspector.DatabaseDispatcher._callbacks[transactionId].onError;
+ delete WebInspector.DatabaseDispatcher._callbacks[transactionId];
+ if (callback)
+ callback(errorObj);
+ }
+}
+
+InspectorBackend.registerDomainDispatcher("Database", new WebInspector.DatabaseDispatcher());