mshtml: Store editor controller in NSContainer.

This commit is contained in:
Jacek Caban 2007-06-10 11:49:12 +02:00 committed by Alexandre Julliard
parent c135e0d882
commit b2f995a8d2
3 changed files with 99 additions and 1 deletions

View File

@ -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

View File

@ -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;

View File

@ -111,6 +111,7 @@ typedef nsISupports nsIWebProgressListener;
typedef nsISupports nsIDOMCSSValue;
typedef nsISupports nsIDOMCSSRule;
typedef nsISupports nsIPrintSession;
typedef nsISupports nsIControllerCommandTable;
[
object,
@ -1609,6 +1610,30 @@ interface nsICommandManager : nsISupports
nsIDOMWindow *aTargetWindow);
}
[
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)