From 2886bd5a725742c12c8b3a35d836e1c4f1ddf43b Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Thu, 20 Dec 2012 16:03:09 +0100 Subject: [PATCH] Fixed missed g_object_unref. Also avoided to cast a WebKitDOMNode multiple times to a WebKitDOMElement. --- src/hints.c | 13 ++++++++----- src/main.c | 12 +++++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/hints.c b/src/hints.c index 818d654..a2b6ba3 100644 --- a/src/hints.c +++ b/src/hints.c @@ -247,11 +247,14 @@ static void hints_create_for_window( gulong snapshot_length = webkit_dom_xpath_result_get_snapshot_length(result, NULL); for (gulong i = 0; i < snapshot_length && hintCount < MAX_HINTS; i++) { - Node* node = webkit_dom_xpath_result_snapshot_item(result, i, NULL); - if (!dom_element_is_visible(win, WEBKIT_DOM_ELEMENT(node))) { + /* TODO this cast causes a bug if hinting is started after a link was + * opened into new window via middle mouse click or right click + * context menu */ + Element* elem = WEBKIT_DOM_ELEMENT(webkit_dom_xpath_result_snapshot_item(result, i, NULL)); + if (!dom_element_is_visible(win, elem)) { continue; } - DomBoundingRect rect = dom_elemen_get_bounding_rect(WEBKIT_DOM_ELEMENT(node)); + DomBoundingRect rect = dom_elemen_get_bounding_rect(elem); if (rect.left > maxX || rect.right < minX || rect.top > maxY || rect.bottom < minY) { continue; } @@ -260,11 +263,11 @@ static void hints_create_for_window( /* create the hint element */ Element* hint = webkit_dom_document_create_element(doc, "span", NULL); - CssDeclaration* css_style = webkit_dom_element_get_style(WEBKIT_DOM_ELEMENT(node)); + CssDeclaration* css_style = webkit_dom_element_get_style(elem); Hint* newHint = g_new0(Hint, 1); newHint->num = hintCount; - newHint->elem = WEBKIT_DOM_ELEMENT(node); + newHint->elem = elem; newHint->elemColor = webkit_dom_css_style_declaration_get_property_value(css_style, "color"); newHint->elemBackgroundColor = webkit_dom_css_style_declaration_get_property_value(css_style, "background-color"); newHint->hint = hint; diff --git a/src/main.c b/src/main.c index 19cd7c2..b398efd 100644 --- a/src/main.c +++ b/src/main.c @@ -608,23 +608,29 @@ static void vp_setup_signals(void) static gboolean vp_button_relase_cb(WebKitWebView* webview, GdkEventButton* event, gpointer data) { + gboolean propagate = FALSE; WebKitHitTestResultContext context; Mode mode = GET_CLEAN_MODE(); + WebKitHitTestResult *result = webkit_web_view_get_hit_test_result(webview, event); g_object_get(result, "context", &context, NULL); if (mode == VP_MODE_NORMAL && context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE) { vp_set_mode(VP_MODE_INSERT, FALSE); - return TRUE; + + propagate = TRUE; } /* middle mouse click onto link */ if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK && event->button == 2) { Arg a = {VP_TARGET_NEW}; g_object_get(result, "link-uri", &a.s, NULL); vp_load_uri(&a); - return TRUE; + + propagate = TRUE; } - return FALSE; + g_object_unref(result); + + return propagate; } static gboolean vp_new_window_policy_cb( -- 2.20.1