Jacek Caban : mshtml: Store editor controller in NSContainer.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Jun 11 08:46:39 CDT 2007


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Sun Jun 10 11:49:12 2007 +0200

mshtml: Store editor controller in NSContainer.

---

 dlls/mshtml/mshtml_private.h |    4 ++
 dlls/mshtml/nsembed.c        |   71 +++++++++++++++++++++++++++++++++++++++++-
 dlls/mshtml/nsiface.idl      |   25 +++++++++++++++
 3 files changed, 99 insertions(+), 1 deletions(-)

diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index 468dd6c..44d6645 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -140,6 +140,8 @@ struct NSContainer {
     nsIBaseWindow *window;
     nsIWebBrowserFocus *focus;
 
+    nsIController *editor_controller;
+
     LONG ref;
 
     NSContainer *parent;
@@ -376,6 +378,7 @@ void release_nodes(HTMLDocument*);
 
 BOOL install_wine_gecko(void);
 
+/* commands */
 typedef struct {
     DWORD id;
     HRESULT (*query)(HTMLDocument*,OLECMD*);
@@ -384,6 +387,7 @@ typedef struct {
 
 extern const cmdtable_t editmode_cmds[];
 
+/* timer */
 #define UPDATE_UI       0x0001
 #define UPDATE_TITLE    0x0002
 
diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c
index 832298b..f8944e9 100644
--- a/dlls/mshtml/nsembed.c
+++ b/dlls/mshtml/nsembed.c
@@ -42,6 +42,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
 #define NS_STRINGSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1"
 #define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1"
 #define NS_HTMLSERIALIZER_CONTRACTID "@mozilla.org/layout/contentserializer;1?mimetype=text/html"
+#define NS_EDITORCONTROLLER_CONTRACTID "@mozilla.org/editor/editorcontroller;1"
 
 #define APPSTARTUP_TOPIC "app-startup"
 
@@ -580,6 +581,58 @@ void nsnode_to_nsstring(nsIDOMNode *nsdoc, nsAString *str)
     nsIContentSerializer_Release(serializer);
 }
 
+static nsIController *get_editor_controller(NSContainer *This)
+{
+    nsIController *ret = NULL;
+    nsIEditingSession *editing_session = NULL;
+    nsIInterfaceRequestor *iface_req;
+    nsIControllerContext *ctrlctx;
+    nsIEditor *editor = NULL;
+    nsresult nsres;
+
+    nsres = nsIWebBrowser_QueryInterface(This->webbrowser,
+            &IID_nsIInterfaceRequestor, (void**)&iface_req);
+    if(NS_FAILED(nsres)) {
+        ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres);
+        return NULL;
+    }
+
+    nsres = nsIInterfaceRequestor_GetInterface(iface_req, &IID_nsIEditingSession,
+                                               (void**)&editing_session);
+    nsIInterfaceRequestor_Release(iface_req);
+    if(NS_FAILED(nsres)) {
+        ERR("Could not get nsIEditingSession: %08x\n", nsres);
+        return NULL;
+    }
+
+    nsres = nsIEditingSession_GetEditorForWindow(editing_session,
+            This->doc->window->nswindow, &editor);
+    nsIEditingSession_Release(editing_session);
+    if(NS_FAILED(nsres)) {
+        ERR("Could not get editor: %08x\n", nsres);
+        return NULL;
+    }
+
+    nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
+            NS_EDITORCONTROLLER_CONTRACTID, NULL, &IID_nsIControllerContext, (void**)&ctrlctx);
+    if(NS_SUCCEEDED(nsres)) {
+        nsres = nsIControllerContext_SetCommandContext(ctrlctx, editor);
+        if(NS_FAILED(nsres))
+            ERR("SetCommandContext failed: %08x\n", nsres);
+        nsres = nsIControllerContext_QueryInterface(ctrlctx, &IID_nsIController,
+                (void**)&ret);
+        nsIControllerContext_Release(ctrlctx);
+        if(NS_FAILED(nsres))
+            ERR("Could not get nsIController interface: %08x\n", nsres);
+    }else {
+        ERR("Could not create edit controller: %08x\n", nsres);
+    }
+
+    nsISupports_Release(editor);
+
+    return ret;
+}
+
 void set_ns_editmode(NSContainer *This)
 {
     nsIInterfaceRequestor *iface_req;
@@ -637,6 +690,14 @@ static void handle_load_event(NSContainer *This, nsIDOMEvent *event)
     if(!This->doc)
         return;
 
+    if(This->editor_controller) {
+        nsIController_Release(This->editor_controller);
+        This->editor_controller = NULL;
+    }
+
+    if(This->doc->usermode == EDITMODE)
+        This->editor_controller = get_editor_controller(This);
+
     task = mshtml_alloc(sizeof(task_t));
 
     task->doc = This->doc;
@@ -1318,7 +1379,9 @@ static nsresult NSAPI nsDOMEventListener_HandleEvent(nsIDOMEventListener *iface,
 
     if(!strcmpW(loadW, type)) {
         handle_load_event(This, event);
-    }else if(This->doc && This->doc->usermode == EDITMODE) {
+    }else if(This->doc) {
+        update_doc(This->doc, UPDATE_UI);
+        if(This->doc->usermode == EDITMODE)
             handle_edit_event(This->doc, event);
     }
 
@@ -1485,6 +1548,7 @@ NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
     ret->ref = 1;
     ret->bscallback = NULL;
     ret->content_listener = NULL;
+    ret->editor_controller = NULL;
 
     if(parent)
         nsIWebBrowserChrome_AddRef(NSWBCHROME(parent));
@@ -1605,6 +1669,11 @@ void NSContainer_Release(NSContainer *This)
     nsIWebBrowserFocus_Release(This->focus);
     This->focus = NULL;
 
+    if(This->editor_controller) {
+        nsIController_Release(This->editor_controller);
+        This->editor_controller = NULL;
+    }
+
     if(This->content_listener) {
         nsIURIContentListener_Release(This->content_listener);
         This->content_listener = NULL;
diff --git a/dlls/mshtml/nsiface.idl b/dlls/mshtml/nsiface.idl
index 73fc1e2..9643e61 100644
--- a/dlls/mshtml/nsiface.idl
+++ b/dlls/mshtml/nsiface.idl
@@ -111,6 +111,7 @@ typedef nsISupports nsIWebProgressListener;
 typedef nsISupports nsIDOMCSSValue;
 typedef nsISupports nsIDOMCSSRule;
 typedef nsISupports nsIPrintSession;
+typedef nsISupports nsIControllerCommandTable;
 
 [
     object,
@@ -1611,6 +1612,30 @@ interface nsICommandManager : nsISupports
 
 [
     object,
+    uuid(47b82b60-a36f-4167-8072-6f421151ed50)
+    /* NOT_FROZEN */
+]
+interface nsIControllerContext : nsISupports
+{
+    nsresult Init(nsIControllerCommandTable *aCommandTable);
+    nsresult SetCommandContext(nsISupports *aCommandContext);
+}
+
+[
+    object,
+    uuid(d5b61b82-1da4-11d3-bf87-00105a1b0627)
+    /* NOT_FROZEN */
+]
+interface nsIController : nsISupports
+{
+    nsresult IsCommandEnabled(const char *command, PRBool *_retval);
+    nsresult SupportsCommand(const char *command, PRBool *_retval);
+    nsresult DoCommand(const char *command);
+    nsresult OnEvent(const char *eventName);
+}
+
+[
+    object,
     uuid(d650439a-ca29-410d-a906-b0557fb62fcd)
     /* NOT_FROZEN */
 ]




More information about the wine-cvs mailing list