Permalink
Browse files

Switch from XPath to CSS for finding elements.

  • Loading branch information...
1 parent 47f38b8 commit fa6260c69070e49c6fd40a0428b0bee2f53b77ff @tristandunn committed Oct 24, 2011
Showing with 16 additions and 20 deletions.
  1. +2 −4 src/Find.cpp
  2. +14 −16 src/webkit_server.js
View
6 src/Find.cpp
@@ -10,10 +10,8 @@ void Find::start(QStringList &arguments) {
QVariant result = page()->invokeWebKitServerFunction("find", arguments);
if (result.isValid()) {
- message = result.toString();
- emit finished(new Response(true, message));
+ emit finished(new Response(true, result.toString()));
} else {
- emit finished(new Response(false, "Invalid XPath expression"));
+ emit finished(new Response(false, "Invalid selector."));
}
}
-
View
30 src/webkit_server.js
@@ -1,29 +1,28 @@
window.WebKitServer = {
- nextIndex: 0,
- nodes: {},
- lastAttachedFile: "",
+ nodes : {},
+ nextIndex : 0,
+ lastAttachedFile : "",
invoke: function() {
return this[WebKitServerInvocation.functionName].apply(this, WebKitServerInvocation.arguments);
},
- find: function(xpath) {
- return this.findRelativeTo(document, xpath);
+ find: function(selector) {
+ return this.findRelativeTo(document, selector);
},
- findWithin: function(index, xpath) {
- return this.findRelativeTo(this.nodes[index], xpath);
+ findWithin: function(index, selector) {
+ return this.findRelativeTo(this.nodes[index], selector);
},
- findRelativeTo: function(reference, xpath) {
- var iterator = document.evaluate(xpath, reference, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
- var node;
- var results = [];
- while (node = iterator.iterateNext()) {
- this.nextIndex++;
- this.nodes[this.nextIndex] = node;
- results.push(this.nextIndex);
+ findRelativeTo: function(parent, selector) {
+ var results = [],
+ elements = parent.querySelectorAll(selector);
+
+ for (var index = 0, length = elements.length; index < length; index++) {
+ this.nodes[results.push(this.nextIndex++)] = elements[index];
}
+
return results.join(",");
},
@@ -202,4 +201,3 @@ window.WebKitServer = {
mouseTrigger('mouseup', options);
}
};
-

0 comments on commit fa6260c

Please sign in to comment.