From c49e894e9f650eb197563eec2a3116d7d4bc8275 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 12 Nov 2007 01:23:47 +0100 Subject: [PATCH] mshtml: Reset focus after loading the page in edit mode. --- dlls/mshtml/editor.c | 1 + dlls/mshtml/mshtml_private.h | 1 + dlls/mshtml/nsembed.c | 30 ++++++++++++++++++++++++------ dlls/mshtml/nsevents.c | 4 ++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/dlls/mshtml/editor.c b/dlls/mshtml/editor.c index 51f5f26e2ad..827fa072855 100644 --- a/dlls/mshtml/editor.c +++ b/dlls/mshtml/editor.c @@ -524,6 +524,7 @@ void handle_edit_event(HTMLDocument *This, nsIDOMEvent *event) void handle_edit_load(HTMLDocument *This) { + This->nscontainer->reset_focus = GetFocus(); get_editor_controller(This->nscontainer); } diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 2a8627c1957..a35347e5886 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -209,6 +209,7 @@ struct NSContainer { HWND hwnd; BSCallback *bscallback; /* hack */ + HWND reset_focus; /* hack */ }; typedef struct { diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c index 9b8740da367..00b98b2a09d 100644 --- a/dlls/mshtml/nsembed.c +++ b/dlls/mshtml/nsembed.c @@ -81,6 +81,8 @@ static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e',' static ATOM nscontainer_class; +#define WM_RESETFOCUS_HACK WM_USER+600 + static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { NSContainer *This; @@ -96,13 +98,25 @@ static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP } switch(msg) { - case WM_SIZE: - TRACE("(%p)->(WM_SIZE)\n", This); + case WM_SIZE: + TRACE("(%p)->(WM_SIZE)\n", This); - nsres = nsIBaseWindow_SetSize(This->window, - LOWORD(lParam), HIWORD(lParam), TRUE); - if(NS_FAILED(nsres)) - WARN("SetSize failed: %08x\n", nsres); + nsres = nsIBaseWindow_SetSize(This->window, + LOWORD(lParam), HIWORD(lParam), TRUE); + if(NS_FAILED(nsres)) + WARN("SetSize failed: %08x\n", nsres); + break; + + case WM_RESETFOCUS_HACK: + /* + * FIXME + * Gecko grabs focus in edit mode and some apps don't like it. + * We should somehow prevent grabbing focus. + */ + if(This->reset_focus) { + SetFocus(This->reset_focus); + This->reset_focus = NULL; + } } return DefWindowProcW(hwnd, msg, wParam, lParam); @@ -1293,6 +1307,9 @@ static nsresult NSAPI nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow *ifa TRACE("(%p)\n", This); + if(This->reset_focus) + PostMessageW(This->hwnd, WM_RESETFOCUS_HACK, 0, 0); + return nsIBaseWindow_SetFocus(This->window); } @@ -1558,6 +1575,7 @@ NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent) ret->content_listener = NULL; ret->editor_controller = NULL; ret->editor = NULL; + ret->reset_focus = NULL; if(parent) nsIWebBrowserChrome_AddRef(NSWBCHROME(parent)); diff --git a/dlls/mshtml/nsevents.c b/dlls/mshtml/nsevents.c index b61aec22fd5..3c532f0f9b3 100644 --- a/dlls/mshtml/nsevents.c +++ b/dlls/mshtml/nsevents.c @@ -90,7 +90,7 @@ static nsresult NSAPI handle_blur(nsIDOMEventListener *iface, nsIDOMEvent *event TRACE("(%p)\n", This); - if(This->doc && This->doc->focus && !is_doc_child_focus(This)) { + if(!This->reset_focus && This->doc && This->doc->focus && !is_doc_child_focus(This)) { This->doc->focus = FALSE; notif_focus(This->doc); } @@ -104,7 +104,7 @@ static nsresult NSAPI handle_focus(nsIDOMEventListener *iface, nsIDOMEvent *even TRACE("(%p)\n", This); - if(This->doc && !This->doc->focus) { + if(!This->reset_focus && This->doc && !This->doc->focus) { This->doc->focus = TRUE; notif_focus(This->doc); }