incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmue...@apache.org
Subject weinre commit: [CB-540] [weinre] easily navigate to spot in DOM
Date Wed, 25 Apr 2012 12:18:56 GMT
Updated Branches:
  refs/heads/master 7ccffd765 -> 135675352


[CB-540] [weinre] easily navigate to spot in DOM

- Web Inspector has a few behaviors here that weinre didn't,
  and so these were added:

  - re-expanding to last selected DOM element on reload
  - expand to DOM element via the inspect() function

- most significant were WiDOMImpl:pushNodeByPathToFrontEnd
  and override in client of DOMNotify:setChildNodes to
  ignore calls made to previously set nodes

- a few drive-by clean ups were done

- added the common/Debug class which adds some nice logging
  methods for weinre developers


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/commit/13567535
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/tree/13567535
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/diff/13567535

Branch: refs/heads/master
Commit: 1356753525115913bb755b6695cfe370e8f223a6
Parents: 7ccffd7
Author: Patrick Mueller <pmuellr@apache.org>
Authored: Wed Apr 25 08:10:16 2012 -0400
Committer: Patrick Mueller <pmuellr@apache.org>
Committed: Wed Apr 25 08:10:16 2012 -0400

----------------------------------------------------------------------
 .wr                                                |    1 -
 weinre.build/vendor.properties                     |    2 +
 weinre.web/modules/weinre/client/Client.coffee     |   23 +++++
 .../weinre/client/InspectorFrontendHostImpl.coffee |    3 +
 weinre.web/modules/weinre/common/Debug.coffee      |   69 +++++++++++++++
 .../modules/weinre/common/MessageDispatcher.coffee |   13 +++-
 .../weinre/target/InjectedScriptHostImpl.coffee    |    3 +
 weinre.web/modules/weinre/target/NodeStore.coffee  |   18 ++--
 weinre.web/modules/weinre/target/WiDOMImpl.coffee  |   26 +++++-
 9 files changed, 147 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/13567535/.wr
----------------------------------------------------------------------
diff --git a/.wr b/.wr
index 7f87a8c..797e61e 100644
--- a/.wr
+++ b/.wr
@@ -28,7 +28,6 @@ weinre.build/scripts
 weinre.doc
 weinre.server/interfaces
 weinre.server/lib
-weinre.server/package.json
 weinre.server/README.md
 weinre.server/weinre
 weinre.server/weinre-hot

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/13567535/weinre.build/vendor.properties
----------------------------------------------------------------------
diff --git a/weinre.build/vendor.properties b/weinre.build/vendor.properties
index 1ba59f7..e773e5d 100644
--- a/weinre.build/vendor.properties
+++ b/weinre.build/vendor.properties
@@ -23,3 +23,5 @@
 
 WEBKIT_VERSION:          r78584
 WEBKIT_URL_PREFIX:       https://svn.webkit.org/repository/webkit/trunk
+
+# svn export -r r78584 https://svn.webkit.org/repository/webkit/trunk/Source/WebCore/inspector

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/13567535/weinre.web/modules/weinre/client/Client.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/client/Client.coffee b/weinre.web/modules/weinre/client/Client.coffee
index 41acfd9..54422a4 100644
--- a/weinre.web/modules/weinre/client/Client.coffee
+++ b/weinre.web/modules/weinre/client/Client.coffee
@@ -42,6 +42,9 @@ module.exports = class Client
 
     #---------------------------------------------------------------------------
     initialize: ->
+    
+        addHack_DOMNotify_setChildNodes()
+        
         window.addEventListener 'load', Binding(this, 'onLoaded'), false
 
         messageDispatcher = new MessageDispatcher('../ws/client', @_getId())
@@ -126,8 +129,28 @@ module.exports = class Client
         Weinre.client.initialize()
 
         window.installWebInspectorAPIsource = installWebInspectorAPIsource
+    
 
 #-------------------------------------------------------------------------------
+old_DOMNotify_setChildNodes = null
+
+#-------------------------------------------------------------------------------
+new_DOMNotify_setChildNodes = (parentId, payloads) ->
+    domNode  = this._domAgent._idToDOMNode[parentId]
+
+    if domNode.children 
+        if domNode.children.length > 0
+            return
+    
+    old_DOMNotify_setChildNodes.call(this, parentId, payloads)
+
+#-------------------------------------------------------------------------------
+addHack_DOMNotify_setChildNodes = ->
+    old_DOMNotify_setChildNodes = WebInspector.DOMDispatcher::setChildNodes
+    
+    WebInspector.DOMDispatcher::setChildNodes = new_DOMNotify_setChildNodes
+    
+#-------------------------------------------------------------------------------
 installWebInspectorAPIsource = () ->
       return if 'webInspector' of window
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/13567535/weinre.web/modules/weinre/client/InspectorFrontendHostImpl.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/client/InspectorFrontendHostImpl.coffee b/weinre.web/modules/weinre/client/InspectorFrontendHostImpl.coffee
index d4e258b..35728e3 100644
--- a/weinre.web/modules/weinre/client/InspectorFrontendHostImpl.coffee
+++ b/weinre.web/modules/weinre/client/InspectorFrontendHostImpl.coffee
@@ -30,6 +30,9 @@ module.exports = class InspectorFrontendHostImpl
         @_getPlatformAndPort()
 
     #---------------------------------------------------------------------------
+    showContextMenu: ->
+
+    #---------------------------------------------------------------------------
     loaded: ->
 
     #---------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/13567535/weinre.web/modules/weinre/common/Debug.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/common/Debug.coffee b/weinre.web/modules/weinre/common/Debug.coffee
new file mode 100644
index 0000000..545de8a
--- /dev/null
+++ b/weinre.web/modules/weinre/common/Debug.coffee
@@ -0,0 +1,69 @@
+
+#-------------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+module.exports = new class Debug
+
+    #---------------------------------------------------------------------------
+    constructor: ->
+        @_printCalledArgs = {}
+
+    #---------------------------------------------------------------------------
+    log: (message) -> 
+        console = window.console.__original || window.console
+        console.log "#{@timeStamp()}: #{message}"
+
+    #---------------------------------------------------------------------------
+    logCall: (context, intf, method, args, message) ->
+        if message
+            message = ": #{message}"
+        else
+            message = ""
+        
+        signature = @signature(intf, method)
+        printArgs = @_printCalledArgs[signature]
+        
+        if printArgs
+            args = JSON.stringify(args,null,4)
+        else
+            args = ""
+        
+        @log "#{context} #{signature}(#{args})#{message}"
+
+    #---------------------------------------------------------------------------
+    logCallArgs: (intf, method) -> 
+        @_printCalledArgs[@signature(intf, method)] = true
+
+    #---------------------------------------------------------------------------
+    signature: (intf, method) ->
+        "#{intf}.#{method}"
+    
+    #---------------------------------------------------------------------------
+    timeStamp: ->
+        date = new Date()
+        
+        mins = "#{date.getMinutes()}"
+        secs = "#{date.getSeconds()}"
+        
+        mins = "0#{mins}" if mins.length == 1
+        secs = "0#{secs}" if secs.length == 1
+        
+        "#{mins}:#{secs}"
+    
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/13567535/weinre.web/modules/weinre/common/MessageDispatcher.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/common/MessageDispatcher.coffee b/weinre.web/modules/weinre/common/MessageDispatcher.coffee
index 37a0cc4..554f0c6 100644
--- a/weinre.web/modules/weinre/common/MessageDispatcher.coffee
+++ b/weinre.web/modules/weinre/common/MessageDispatcher.coffee
@@ -24,11 +24,19 @@ IDLTools     = require('./IDLTools')
 Binding      = require('./Binding')
 Ex           = require('./Ex')
 Callback     = require('./Callback')
+#Debug        = require('./Debug')
 
 Verbose = false
 InspectorBackend = null
 
 #-------------------------------------------------------------------------------
+#Debug.logCallArgs "DOM", "addInspectedNode"
+#Debug.logCallArgs "DOM", "pushNodeByPathToFrontend"
+#Debug.logCallArgs "DOM",  "getChildNodes"
+#Debug.logCallArgs "DOMNotify", "setChildNodes"
+#Debug.logCallArgs "DOMNotify", "setDocument"
+
+#-------------------------------------------------------------------------------
 module.exports = class MessageDispatcher
 
     #---------------------------------------------------------------------------
@@ -112,6 +120,7 @@ module.exports = class MessageDispatcher
             method:    methodName
             args:      args
 
+        #Debug.logCall "send", intfName, methodName, args
         data = JSON.stringify(data)
         @_socket.send data
 
@@ -163,7 +172,7 @@ module.exports = class MessageDispatcher
         intfName = data["interface"]
         methodName = data.method
         args = data.args
-        methodSignature = intfName + ".#{methodName}()"
+        methodSignature = "#{intfName}.#{methodName}()"
         intf = @_interfaces.hasOwnProperty(intfName) and @_interfaces[intfName]
 
         if not intf and InspectorBackend and intfName.match(/.*Notify/)
@@ -179,6 +188,8 @@ module.exports = class MessageDispatcher
         unless typeof method == "function"
             Weinre.notImplemented methodSignature
             return
+            
+        #Debug.logCall "hand", intfName, methodName, args
         try
             method.apply intf, args
         catch e

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/13567535/weinre.web/modules/weinre/target/InjectedScriptHostImpl.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/target/InjectedScriptHostImpl.coffee b/weinre.web/modules/weinre/target/InjectedScriptHostImpl.coffee
index 0358fd9..3469819 100644
--- a/weinre.web/modules/weinre/target/InjectedScriptHostImpl.coffee
+++ b/weinre.web/modules/weinre/target/InjectedScriptHostImpl.coffee
@@ -39,6 +39,9 @@ module.exports = class InjectedScriptHostImpl
         children = Weinre.nodeStore.serializeNode(node, 1)
         Weinre.wi.DOMNotify.setChildNodes nodeId, children
         Weinre.WeinreTargetCommands.sendClientCallback callback if callback
+        
+        if selectInUI
+            Weinre.wi.InspectorNotify.updateFocusedNode nodeId
 
     #---------------------------------------------------------------------------
     inspectedNode: (num, callback) ->

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/13567535/weinre.web/modules/weinre/target/NodeStore.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/target/NodeStore.coffee b/weinre.web/modules/weinre/target/NodeStore.coffee
index c80339c..a78f2ae 100644
--- a/weinre.web/modules/weinre/target/NodeStore.coffee
+++ b/weinre.web/modules/weinre/target/NodeStore.coffee
@@ -21,13 +21,15 @@
 Weinre      = require('../common/Weinre')
 IDGenerator = require('../common/IDGenerator')
 
+Debug       = require('../common/Debug')
+
 #-------------------------------------------------------------------------------
 module.exports = class NodeStore
 
     constructor: ->
-        @__nodeMap      = {}
-        @__nodeDataMap  = {}
-        @inspectedNodes = []
+        @_nodeMap      = {}
+        @_childrenSent = {}
+        @_inspectedNodes = []
 
         document.addEventListener "DOMSubtreeModified",       handleDOMSubtreeModified, false
         document.addEventListener "DOMNodeInserted",          handleDOMNodeInserted, false
@@ -37,16 +39,16 @@ module.exports = class NodeStore
 
     #---------------------------------------------------------------------------
     addInspectedNode: (nodeId) ->
-        @inspectedNodes.unshift nodeId
-        @inspectedNodes = @inspectedNodes.slice(0, 5) if @inspectedNodes.length > 5
+        @_inspectedNodes.unshift nodeId
+        @_inspectedNodes = @_inspectedNodes.slice(0, 5) if @_inspectedNodes.length > 5
 
     #---------------------------------------------------------------------------
     getInspectedNode: (index) ->
-        @inspectedNodes[index]
+        @_inspectedNodes[index]
 
     #---------------------------------------------------------------------------
     getNode: (nodeId) ->
-        @__nodeMap[nodeId]
+        @_nodeMap[nodeId]
 
     #---------------------------------------------------------------------------
     checkNodeId: (node) ->
@@ -56,7 +58,7 @@ module.exports = class NodeStore
     getNodeId: (node) ->
         id = @checkNodeId(node)
         return id if id
-        IDGenerator.getId node, @__nodeMap
+        IDGenerator.getId node, @_nodeMap
 
     #---------------------------------------------------------------------------
     getNodeData: (nodeId, depth) ->

http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/13567535/weinre.web/modules/weinre/target/WiDOMImpl.coffee
----------------------------------------------------------------------
diff --git a/weinre.web/modules/weinre/target/WiDOMImpl.coffee b/weinre.web/modules/weinre/target/WiDOMImpl.coffee
index 7d83ac8..7cc8da3 100644
--- a/weinre.web/modules/weinre/target/WiDOMImpl.coffee
+++ b/weinre.web/modules/weinre/target/WiDOMImpl.coffee
@@ -135,7 +135,31 @@ module.exports = class WiDOMImpl
 
     #---------------------------------------------------------------------------
     pushNodeByPathToFrontend: (path, callback) ->
-        Weinre.notImplemented arguments.callee.signature
+        parts = path.split(",")
+        
+        curr   = document
+        currId = null
+        
+        nodeId = Weinre.nodeStore.getNodeId(curr)
+        @getChildNodes(nodeId)
+        
+        for i in [0...parts.length] by 2
+            index    = parseInt(parts[i])
+            nodeName = parts[i+1]
+            
+            return if isNaN(index) 
+            
+            childNodeIds = Weinre.nodeStore.childNodeIds(curr)
+            currId = childNodeIds[index]
+            return if !currId
+            
+            @getChildNodes(currId)
+            curr = Weinre.nodeStore.getNode(currId)
+            
+            return if curr.nodeName != nodeName
+
+        if callback && currId
+            Weinre.WeinreTargetCommands.sendClientCallback callback, [ currId ]
 
     #---------------------------------------------------------------------------
     resolveNode: (nodeId, callback) ->


Mime
View raw message