Rename webelem.js functions to match WebEngineElem

Fixes #2726
This commit is contained in:
Florian Bruhin 2017-06-16 23:13:07 +02:00
parent 9cc688ea2b
commit 695a2656fe
2 changed files with 23 additions and 23 deletions

View File

@ -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)

View File

@ -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);
};