Beispiel #1
0
// document_scroll_cb is called when the document is scrolled, and updates
// the main processes knowledge of the document.
static void
document_scroll_cb(WebKitDOMEventTarget *target,
                   WebKitDOMEvent       *event,
                   gpointer              user_data)
{
    Exten *exten = user_data;
    WebKitDOMDocument *dom = WEBKIT_DOM_DOCUMENT(target);
    WebKitDOMElement *e = NULL;
    if(dom != NULL) {
        e = WEBKIT_DOM_ELEMENT(webkit_dom_document_get_body(dom));
    }

    // Check for current scroll position. If it has changed, signal DBus.
    if(e != NULL) {
        glong top = webkit_dom_element_get_scroll_top(e);
        glong height = webkit_dom_element_get_scroll_height(e);
        if(top != exten->last_top || height != exten->last_height) {
            exten->last_top = top;
            exten->last_height = height;
            vertical_position_changed(exten->page_id, top, height, exten);
        }
    }

    if(dom != NULL) {
        e = webkit_dom_document_get_active_element(dom);
    }
}
Beispiel #2
0
// active_element_change_cb is called when the active element is changed, and
// updates bookkeeping and the main process.
static void
active_element_change_cb(WebKitDOMEventTarget *target,
                         WebKitDOMEvent       *event,
                         gpointer              user_data)
{
    Exten *exten = user_data;
    WebKitDOMDocument *document;
    if(WEBKIT_DOM_IS_DOCUMENT(target)) {
        document = WEBKIT_DOM_DOCUMENT(target);
    } else {
        // target is a window.
        g_object_get(target, "document", &document, NULL);
    }
    WebKitDOMElement *active = webkit_dom_document_get_active_element(document);
    if(active == NULL || active == exten->active) {
        return;
    }
    if(WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT(active)) {
        // The iframe document handles this, unless it isn't registered yet.
        // In this case, register it and call recursively.
        WebKitDOMDocument *doc =
            webkit_dom_html_iframe_element_get_content_document(
                    WEBKIT_DOM_HTML_IFRAME_ELEMENT(active));
        if(!g_hash_table_contains(exten->registered_documents, doc)) {
            frame_document_loaded(doc, exten);
            active_element_change_cb(
                    WEBKIT_DOM_EVENT_TARGET(doc),
                    NULL,
                    exten);
        }
        return;
    }
    exten->active = active;
    exten->scroll_target = get_scroll_target(active);

    // Check whether the currently active element is an input element.
    // If this has changed, signal DBus.
    //
    // Input elements:
    //
    // WebKitDOMHTMLAppletElement
    // WebKitDOMHTMLEmbedElement
    // WebKitDOMHTMLInputElement
    // WebKitDOMHTMLTextAreaElement
    gboolean input_focus = (
            WEBKIT_DOM_IS_HTML_APPLET_ELEMENT(active) ||
            WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(active) ||
            WEBKIT_DOM_IS_HTML_INPUT_ELEMENT(active) ||
            WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT(active));
    if(input_focus != exten->last_input_focus) {
        exten->last_input_focus = input_focus;
        input_focus_changed(
            exten->page_id,
            input_focus,
            exten);
    }
}
Beispiel #3
0
/**
 * Callback called if a editable element changes it focus state.
 * Event target may be a WebKitDOMDocument (in case of iframe) or a
 * WebKitDOMDOMWindow.
 */
static void on_editable_change_focus(WebKitDOMEventTarget *target,
        WebKitDOMEvent *event, WebKitWebPage *page)
{
    WebKitDOMDocument *doc;
    WebKitDOMDOMWindow *dom_window;
    WebKitDOMElement *active;
    GVariant *variant;
    char *message;

    if (WEBKIT_DOM_IS_DOM_WINDOW(target)) {
        g_object_get(target, "document", &doc, NULL);
    } else {
        /* target is a doc document */
        doc = WEBKIT_DOM_DOCUMENT(target);
    }

    dom_window = webkit_dom_document_get_default_view(doc);
    if (!dom_window) {
        return;
    }

    active = webkit_dom_document_get_active_element(doc);
    /* Don't do anything if there is no active element */
    if (!active) {
        return;
    }
    if (WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT(active)) {
        WebKitDOMHTMLIFrameElement *iframe;
        WebKitDOMDocument *subdoc;

        iframe = WEBKIT_DOM_HTML_IFRAME_ELEMENT(active);
        subdoc = webkit_dom_html_iframe_element_get_content_document(iframe);
        add_onload_event_observers(subdoc, page);
        return;
    }

    /* Check if the active element is an editable element. */
    variant = g_variant_new("(tb)", webkit_web_page_get_id(page),
            ext_dom_is_editable(active));
    message = g_variant_print(variant, FALSE);
    g_variant_unref(variant);
    if (!webkit_dom_dom_window_webkit_message_handlers_post_message(dom_window, "focus", message)) {
        g_warning("Error sending focus message");
    }
    g_free(message);
    g_object_unref(dom_window);
}