Jacek Caban : mshtml: Use stored nsdoc in exec_hyperlink.

Alexandre Julliard julliard at winehq.org
Thu Oct 9 07:42:46 CDT 2008


Module: wine
Branch: master
Commit: 7c7b7f0ae7afe76462d61de7c5daebf4532a588c
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=7c7b7f0ae7afe76462d61de7c5daebf4532a588c

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Oct  8 13:28:19 2008 -0500

mshtml: Use stored nsdoc in exec_hyperlink.

---

 dlls/mshtml/editor.c |  105 +++++++++++++++++++++++--------------------------
 1 files changed, 49 insertions(+), 56 deletions(-)

diff --git a/dlls/mshtml/editor.c b/dlls/mshtml/editor.c
index bba9e40..4e02155 100644
--- a/dlls/mshtml/editor.c
+++ b/dlls/mshtml/editor.c
@@ -1146,13 +1146,18 @@ static INT_PTR CALLBACK hyperlink_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LP
 
 static HRESULT exec_hyperlink(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
 {
+    nsAString a_str, href_str, ns_url;
+    nsIHTMLEditor *html_editor;
+    nsIDOMElement *anchor_elem;
+    PRBool insert_link_at_caret;
+    nsISelection *nsselection;
     BSTR url = NULL;
     INT ret;
-    nsISelection *nsselection;
-    nsIDOMDocument *nsdoc;
-    nsresult nsres;
     HRESULT hres = E_FAIL;
 
+    static const WCHAR wszA[] = {'a',0};
+    static const WCHAR wszHref[] = {'h','r','e','f',0};
+
     TRACE("%p, 0x%x, %p, %p\n", This, cmdexecopt, in, out);
 
     if (cmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER)
@@ -1171,76 +1176,64 @@ static HRESULT exec_hyperlink(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in,
             return OLECMDERR_E_CANCELED;
     }
 
+    if(This->nsdoc) {
+        WARN("NULL nsdoc\n");
+        return E_UNEXPECTED;
+    }
+
     nsselection = get_ns_selection(This);
     if (!nsselection)
         return E_FAIL;
 
-    nsres = nsIWebNavigation_GetDocument(This->nscontainer->navigation, &nsdoc);
-    if(NS_SUCCEEDED(nsres))
-    {
-        static const WCHAR wszA[] = {'a',0};
-        static const WCHAR wszHref[] = {'h','r','e','f',0};
-        nsIHTMLEditor *html_editor;
-        nsIDOMNode *text_node;
-        nsIDOMElement *anchor_elem;
-        nsIDOMNode *unused_node;
-        nsAString a_str;
-        nsAString href_str;
-        nsAString ns_url;
-        PRBool insert_link_at_caret;
-
-        nsAString_Init(&a_str, wszA);
-        nsAString_Init(&href_str, wszHref);
-        nsAString_Init(&ns_url, url);
-
-        /* create an element for the link */
-        nsIDOMDocument_CreateElement(nsdoc, &a_str, &anchor_elem);
-        nsIDOMElement_SetAttribute(anchor_elem, &href_str, &ns_url);
-
-        nsAString_Finish(&href_str);
-        nsAString_Finish(&a_str);
-
-        nsISelection_GetIsCollapsed(nsselection, &insert_link_at_caret);
-
-        /* create an element with text of URL */
-        if (insert_link_at_caret)
-        {
-            nsIDOMDocument_CreateTextNode(nsdoc, &ns_url, (nsIDOMText **)&text_node);
+    nsAString_Init(&a_str, wszA);
+    nsAString_Init(&href_str, wszHref);
+    nsAString_Init(&ns_url, url);
 
-            /* wrap the <a> tags around the text element */
-            nsIDOMElement_AppendChild(anchor_elem, text_node, &unused_node);
-            nsIDOMNode_Release(text_node);
-            nsIDOMNode_Release(unused_node);
-        }
+    /* create an element for the link */
+    nsIDOMDocument_CreateElement(This->nsdoc, &a_str, &anchor_elem);
+    nsIDOMElement_SetAttribute(anchor_elem, &href_str, &ns_url);
 
-        nsAString_Finish(&ns_url);
+    nsAString_Finish(&href_str);
+    nsAString_Finish(&a_str);
 
-        nsIEditor_QueryInterface(This->nscontainer->editor, &IID_nsIHTMLEditor, (void **)&html_editor);
-        if (html_editor)
-        {
-            if (insert_link_at_caret)
-            {
-                /* add them to the document at the caret position */
-                nsres = nsIHTMLEditor_InsertElementAtSelection(html_editor, anchor_elem, FALSE);
-                nsISelection_SelectAllChildren(nsselection, (nsIDOMNode*)anchor_elem);
-            }
-            else /* add them around the selection using the magic provided to us by nsIHTMLEditor */
-                nsres = nsIHTMLEditor_InsertLinkAroundSelection(html_editor, anchor_elem);
-            nsIHTMLEditor_Release(html_editor);
-        }
+    nsISelection_GetIsCollapsed(nsselection, &insert_link_at_caret);
+
+    /* create an element with text of URL */
+    if (insert_link_at_caret) {
+        nsIDOMNode *text_node, *unused_node;
+
+        nsIDOMDocument_CreateTextNode(This->nsdoc, &ns_url, (nsIDOMText **)&text_node);
+
+        /* wrap the <a> tags around the text element */
+        nsIDOMElement_AppendChild(anchor_elem, text_node, &unused_node);
+        nsIDOMNode_Release(text_node);
+        nsIDOMNode_Release(unused_node);
+    }
+
+    nsAString_Finish(&ns_url);
+
+    nsIEditor_QueryInterface(This->nscontainer->editor, &IID_nsIHTMLEditor, (void **)&html_editor);
+    if (html_editor) {
+        nsresult nsres;
 
-        nsIDOMElement_Release(anchor_elem);
-        nsIDOMDocument_Release(nsdoc);
+        if (insert_link_at_caret) {
+            /* add them to the document at the caret position */
+            nsres = nsIHTMLEditor_InsertElementAtSelection(html_editor, anchor_elem, FALSE);
+            nsISelection_SelectAllChildren(nsselection, (nsIDOMNode*)anchor_elem);
+        }else /* add them around the selection using the magic provided to us by nsIHTMLEditor */
+            nsres = nsIHTMLEditor_InsertLinkAroundSelection(html_editor, anchor_elem);
 
+        nsIHTMLEditor_Release(html_editor);
         hres = NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
     }
 
     nsISelection_Release(nsselection);
+    nsIDOMElement_Release(anchor_elem);
 
     if (cmdexecopt != OLECMDEXECOPT_DONTPROMPTUSER)
         SysFreeString(url);
 
-    TRACE("-- 0x%08x\n", nsres);
+    TRACE("-- 0x%08x\n", hres);
     return hres;
 }
 




More information about the wine-cvs mailing list