Optimize get_absolute_offset_for_element

This commit is contained in:
Alexander Butenko 2012-01-07 20:15:09 -04:00 committed by Christian Dywan
parent 9445539c48
commit 3d774d2d09

View file

@ -68,31 +68,24 @@ formhistory_suggestion_selected_cb (GtkWidget* treeview,
static void static void
get_absolute_offset_for_element (WebKitDOMElement* element, get_absolute_offset_for_element (WebKitDOMElement* element,
WebKitDOMDocument* element_document,
WebKitDOMNodeList* frames,
glong* x, glong* x,
glong* y, glong* y,
gboolean mainframe) gboolean ismainframe)
{ {
WebKitDOMElement* offset_parent; WebKitDOMElement* offset_parent;
WebKitDOMDocument* element_document; gint i, offset_top = 0, offset_left = 0;
gint offset_top = 0, offset_left = 0;
gboolean ismainframe = FALSE;
WebKitDOMNodeList* frames;
WebKitDOMDocument* fdoc;
int i;
frames = g_object_get_data (G_OBJECT (element), "framelist");
element_document = g_object_get_data (G_OBJECT (element), "doc");
g_object_get (element, "offset-left", &offset_left, g_object_get (element, "offset-left", &offset_left,
"offset-top", &offset_top, "offset-top", &offset_top,
"offset-parent", &offset_parent, "offset-parent", &offset_parent,
NULL); NULL);
*x += offset_left; *x += offset_left;
*y += offset_top; *y += offset_top;
/* To avoid deadlock check only first element of the mainframe parent */ /* To avoid deadlock check only first element of the mainframe parent */
if (mainframe == TRUE) if (ismainframe == TRUE)
return; return;
if (offset_parent) if (offset_parent)
goto finish; goto finish;
@ -101,13 +94,13 @@ get_absolute_offset_for_element (WebKitDOMElement* element,
and get its offsets */ and get its offsets */
for (i = 0; i < webkit_dom_node_list_get_length (frames); i++) for (i = 0; i < webkit_dom_node_list_get_length (frames); i++)
{ {
WebKitDOMDocument *fdoc;
WebKitDOMNode *frame = webkit_dom_node_list_item (frames, i); WebKitDOMNode *frame = webkit_dom_node_list_item (frames, i);
if (WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT (frame)) if (WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT (frame))
fdoc = webkit_dom_html_iframe_element_get_content_document (WEBKIT_DOM_HTML_IFRAME_ELEMENT (frame)); fdoc = webkit_dom_html_iframe_element_get_content_document (WEBKIT_DOM_HTML_IFRAME_ELEMENT (frame));
else else
fdoc = webkit_dom_html_frame_element_get_content_document (WEBKIT_DOM_HTML_FRAME_ELEMENT (frame)); fdoc = webkit_dom_html_frame_element_get_content_document (WEBKIT_DOM_HTML_FRAME_ELEMENT (frame));
if (fdoc == element_document) if (fdoc == element_document)
{ {
offset_parent = WEBKIT_DOM_ELEMENT (frame); offset_parent = WEBKIT_DOM_ELEMENT (frame);
@ -117,20 +110,17 @@ get_absolute_offset_for_element (WebKitDOMElement* element,
break; break;
} }
} }
if (!offset_parent)
return;
finish: finish:
/* Copy set properties to parents as they dont have them set */ if (offset_parent)
/* FIXME: Seems we need to drop them afterwards to save some memory? */ get_absolute_offset_for_element (offset_parent, element_document, frames, x, y, ismainframe);
g_object_set_data (G_OBJECT (offset_parent), "doc", element_document);
g_object_set_data (G_OBJECT (offset_parent), "framelist", frames);
get_absolute_offset_for_element (offset_parent, x, y, ismainframe);
} }
static void static void
formhistory_reposition_popup (FormHistoryPriv* priv, formhistory_reposition_popup (FormHistoryPriv* priv,
GtkWidget* widget) GtkWidget* widget)
{ {
WebKitDOMDocument* element_document;
WebKitDOMNodeList* frames;
GdkWindow* window; GdkWindow* window;
gint rx, ry; gint rx, ry;
gint wx, wy; gint wx, wy;
@ -146,7 +136,9 @@ formhistory_reposition_popup (FormHistoryPriv* priv,
gdk_window_get_position (window, &wx, &wy); gdk_window_get_position (window, &wx, &wy);
/* Position of editbox on the webview */ /* Position of editbox on the webview */
get_absolute_offset_for_element (priv->element, &x, &y, FALSE); frames = g_object_get_data (G_OBJECT (priv->element), "framelist");
element_document = g_object_get_data (G_OBJECT (priv->element), "doc");
get_absolute_offset_for_element (priv->element, element_document, frames, &x, &y, FALSE);
/* Add height as menu should start under editbox, now on top of it */ /* Add height as menu should start under editbox, now on top of it */
g_object_get (priv->element, "client-height", &height, NULL); g_object_get (priv->element, "client-height", &height, NULL);
y += height + 1; y += height + 1;