diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 9e27805c7..a6b769e51 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -500,18 +500,18 @@ class WebEngineElements(browsertab.AbstractElements): callback(elem) def find_css(self, selector, callback, *, only_visible=False): - js_code = javascript.assemble('webelem', 'find_all', selector, + js_code = javascript.assemble('webelem', 'find_css', selector, only_visible) js_cb = functools.partial(self._js_cb_multiple, callback) self._tab.run_js_async(js_code, js_cb) def find_id(self, elem_id, callback): - js_code = javascript.assemble('webelem', 'element_by_id', elem_id) + js_code = javascript.assemble('webelem', 'find_id', elem_id) js_cb = functools.partial(self._js_cb_single, callback) self._tab.run_js_async(js_code, js_cb) def find_focused(self, callback): - js_code = javascript.assemble('webelem', 'focus_element') + js_code = javascript.assemble('webelem', 'find_focused') js_cb = functools.partial(self._js_cb_single, callback) self._tab.run_js_async(js_code, js_cb) @@ -519,7 +519,7 @@ class WebEngineElements(browsertab.AbstractElements): assert pos.x() >= 0 assert pos.y() >= 0 pos /= self._tab.zoom.factor() - js_code = javascript.assemble('webelem', 'element_at_pos', + js_code = javascript.assemble('webelem', 'find_at_pos', pos.x(), pos.y()) js_cb = functools.partial(self._js_cb_single, callback) self._tab.run_js_async(js_code, js_cb) diff --git a/qutebrowser/javascript/webelem.js b/qutebrowser/javascript/webelem.js index 6d763b8df..ce348c46b 100644 --- a/qutebrowser/javascript/webelem.js +++ b/qutebrowser/javascript/webelem.js @@ -21,8 +21,8 @@ * The connection for web elements between Python and Javascript works like * this: * - * - Python calls into Javascript and invokes a function to find elements (like - * find_all, focus_element, element_at_pos or element_by_id). + * - Python calls into Javascript and invokes a function to find elements (one + * of the find_* functions). * - Javascript gets the requested element, and calls serialize_elem on it. * - serialize_elem saves the javascript element object in "elements", gets some * attributes from the element, and assigns an ID (index into 'elements') to @@ -144,7 +144,7 @@ window._qutebrowser.webelem = (function() { return true; } - funcs.find_all = function(selector, only_visible) { + funcs.find_css = function(selector, only_visible) { var elems = document.querySelectorAll(selector); var out = []; @@ -157,7 +157,12 @@ window._qutebrowser.webelem = (function() { return out; }; - funcs.focus_element = function() { + funcs.find_id = function(id) { + var elem = document.getElementById(id); + return serialize_elem(elem); + }; + + funcs.find_focused = function() { var elem = document.activeElement; if (!elem || elem === document.body) { @@ -169,6 +174,16 @@ window._qutebrowser.webelem = (function() { return serialize_elem(elem); }; + funcs.find_at_pos = function(x, y) { + // FIXME:qtwebengine + // If the element at the specified point belongs to another document + // (for example, an iframe's subdocument), the subdocument's parent + // element is returned (the iframe itself). + + var elem = document.elementFromPoint(x, y); + return serialize_elem(elem); + }; + // Function for returning a selection to python (so we can click it) funcs.find_selected_link = function() { var elem = window.getSelection().anchorNode; @@ -188,21 +203,6 @@ window._qutebrowser.webelem = (function() { document.execCommand("insertText", false, text); }; - funcs.element_at_pos = function(x, y) { - // FIXME:qtwebengine - // If the element at the specified point belongs to another document - // (for example, an iframe's subdocument), the subdocument's parent - // element is returned (the iframe itself). - - var elem = document.elementFromPoint(x, y); - return serialize_elem(elem); - }; - - funcs.element_by_id = function(id) { - var elem = document.getElementById(id); - return serialize_elem(elem); - }; - funcs.set_attribute = function(id, name, value) { elements[id].setAttribute(name, value); };