[PATCH 1/5] mshtml: OleDocumentView_UIActivate should call IOleInPlaceUIWindow_SetActiveObject and IOleInPlaceFrame_SetBorderSpace.

Robert Shearman rob at codeweavers.com
Tue Jul 24 17:06:42 CDT 2007


Add a test to show this behaviour.

Don't call nsIWebBrowserFocus_Activate when just activating the window. 
Instead call it when UI-activating the window.
---
  dlls/mshtml/mshtml_private.h |    1
  dlls/mshtml/tests/htmldoc.c  |   99 
++++++++++++++++++++++++++++++++++++------
  dlls/mshtml/view.c           |   39 ++++++++++++-----
  3 files changed, 114 insertions(+), 25 deletions(-)
-------------- next part --------------
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index 244a0e4..f45f90a 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -122,6 +122,7 @@ struct HTMLDocument {
     IDocHostUIHandler *hostui;
     IOleInPlaceSite *ipsite;
     IOleInPlaceFrame *frame;
+    IOleInPlaceUIWindow *ip_window;
 
     BSCallback *bscallback;
     IMoniker *mon;
diff --git a/dlls/mshtml/tests/htmldoc.c b/dlls/mshtml/tests/htmldoc.c
index 82bbbed..38d3290 100644
--- a/dlls/mshtml/tests/htmldoc.c
+++ b/dlls/mshtml/tests/htmldoc.c
@@ -125,10 +125,13 @@ DEFINE_EXPECT(UnlockRequest);
 DEFINE_EXPECT(OnFocus_TRUE);
 DEFINE_EXPECT(OnFocus_FALSE);
 DEFINE_EXPECT(RequestUIActivate);
+DEFINE_EXPECT(InPlaceFrame_SetBorderSpace);
+DEFINE_EXPECT(InPlaceUIWindow_SetActiveObject);
 
 static IUnknown *doc_unk;
 static BOOL expect_LockContainer_fLock;
-static BOOL expect_SetActiveObject_active, ipsex;
+static BOOL expect_SetActiveObject_active, expect_InPlaceUIWindow_SetActiveObject_active;
+static BOOL ipsex;
 static BOOL set_clientsite = FALSE, container_locked = FALSE;
 static BOOL readystate_set_loading = FALSE, load_from_stream;
 static BOOL editmode = FALSE;
@@ -1115,15 +1118,28 @@ static HRESULT WINAPI InPlaceFrame_Reque
 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
         LPCBORDERWIDTHS pborderwidths)
 {
-    ok(0, "unexpected call\n");
-    return E_NOTIMPL;
+    CHECK_EXPECT(InPlaceFrame_SetBorderSpace);
+    return S_OK;
 }
 
 static HRESULT WINAPI InPlaceUIWindow_SetActiveObject(IOleInPlaceFrame *iface,
         IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
 {
-    ok(0, "unexpected call\n");
-    return E_NOTIMPL;
+    static const WCHAR wszHTML_Document[] =
+        {'H','T','M','L',' ','D','o','c','u','m','e','n','t',0};
+
+    CHECK_EXPECT2(InPlaceUIWindow_SetActiveObject);
+
+    if(expect_InPlaceUIWindow_SetActiveObject_active) {
+        ok(pActiveObject != NULL, "pActiveObject = NULL\n");
+        if(pActiveObject && PRIMARYLANGID(GetSystemDefaultLangID()) == LANG_ENGLISH)
+            ok(!lstrcmpW(wszHTML_Document, pszObjName), "pszObjName != \"HTML Document\"\n");
+    }
+    else {
+        ok(pActiveObject == NULL, "pActiveObject=%p, expected NULL\n", pActiveObject);
+        ok(pszObjName == NULL, "pszObjName=%p, expected NULL\n", pszObjName);
+    }
+    return S_OK;
 }
 
 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
@@ -1468,7 +1484,14 @@ static ULONG WINAPI DocumentSite_Release
     return 1;
 }
 
-static BOOL call_UIActivate = TRUE;
+typedef enum
+{
+    CallUIActivate_None,
+    CallUIActivate_ActivateMe,
+    CallUIActivate_AfterShow,
+} CallUIActivate;
+
+static BOOL call_UIActivate = CallUIActivate_ActivateMe;
 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
 {
     IOleDocument *document;
@@ -1512,7 +1535,7 @@ static HRESULT WINAPI DocumentSite_Activ
                 ok(hwnd == NULL, "hwnd=%p, expeted NULL\n", hwnd);
             }
             
-            if(call_UIActivate) {
+            if(call_UIActivate == CallUIActivate_ActivateMe) {
                 SET_EXPECT(CanInPlaceActivate);
                 SET_EXPECT(GetWindowContext);
                 SET_EXPECT(GetWindow);
@@ -1572,7 +1595,7 @@ static HRESULT WINAPI DocumentSite_Activ
             hres = IOleDocumentView_SetRect(view, &rect);
             ok(hres == S_OK, "SetRect failed: %08x\n", hres);
 
-            if(call_UIActivate) {
+            if(call_UIActivate == CallUIActivate_ActivateMe) {
                 hres = IOleDocumentView_Show(view, TRUE);
                 ok(hres == S_OK, "Show failed: %08x\n", hres);
             }else {
@@ -1685,7 +1708,7 @@ static HRESULT WINAPI OleControlSite_OnF
     if(fGotFocus)
         CHECK_EXPECT(OnFocus_TRUE);
     else
-        CHECK_EXPECT(OnFocus_FALSE);
+        CHECK_EXPECT2(OnFocus_FALSE);
     return S_OK;
 }
 
@@ -1759,7 +1782,10 @@ static HRESULT WINAPI DocHostUIHandler_S
     ok(pActiveObject != NULL, "pActiveObject = NULL\n");
     ok(pCommandTarget != NULL, "pCommandTarget = NULL\n");
     ok(pFrame == &InPlaceFrame, "pFrame=%p, expected %p\n", pFrame, &InPlaceFrame);
-    ok(pDoc == NULL, "pDoc=%p, expected NULL\n", pDoc);
+    if (expect_InPlaceUIWindow_SetActiveObject_active)
+        ok(pDoc == (IOleInPlaceUIWindow *)&InPlaceUIWindow, "pDoc=%p, expected %p\n", pDoc, &InPlaceUIWindow);
+    else
+        ok(pDoc == NULL, "pDoc=%p, expected NULL\n", pDoc);
 
     return S_OK;
 }
@@ -3236,6 +3262,7 @@ static void test_InPlaceDeactivate(IUnkn
 static HRESULT test_Activate(IUnknown *unk, DWORD flags)
 {
     IOleObject *oleobj = NULL;
+    IOleDocumentView *docview;
     GUID guid;
     HRESULT hres;
 
@@ -3264,6 +3291,31 @@ static HRESULT test_Activate(IUnknown *u
 
     hres = test_DoVerb(oleobj);
 
+    if(call_UIActivate == CallUIActivate_AfterShow) {
+        hres = IOleObject_QueryInterface(oleobj, &IID_IOleDocumentView, (void **)&docview);
+        ok(hres == S_OK, "IOleObject_QueryInterface failed with error 0x%08x\n", hres);
+
+        SET_EXPECT(OnFocus_TRUE);
+        SET_EXPECT(SetActiveObject);
+        SET_EXPECT(ShowUI);
+        SET_EXPECT(InPlaceUIWindow_SetActiveObject);
+        SET_EXPECT(InPlaceFrame_SetBorderSpace);
+        expect_InPlaceUIWindow_SetActiveObject_active = TRUE;
+        expect_SetActiveObject_active = TRUE;
+        expect_status_text = NULL;
+
+        hres = IOleDocumentView_UIActivate(docview, TRUE);
+        ok(hres == S_OK, "IOleDocumentView_UIActivate failed with error 0x%08x\n", hres);
+
+        CHECK_CALLED(OnFocus_TRUE);
+        CHECK_CALLED(SetActiveObject);
+        CHECK_CALLED(ShowUI);
+        CHECK_CALLED(InPlaceUIWindow_SetActiveObject);
+        CHECK_CALLED(InPlaceFrame_SetBorderSpace);
+
+        IOleDocumentView_Release(docview);
+    }
+
     IOleObject_Release(oleobj);
 
     test_OnFrameWindowActivate(unk);
@@ -3321,21 +3373,28 @@ static void test_UIDeactivate(void)
 {
     HRESULT hres;
 
-    if(call_UIActivate) {
+    if(call_UIActivate == CallUIActivate_AfterShow) {
+        SET_EXPECT(InPlaceUIWindow_SetActiveObject);
+    }
+    if(call_UIActivate != CallUIActivate_None) {
         SET_EXPECT(SetActiveObject);
         SET_EXPECT(HideUI);
         SET_EXPECT(OnUIDeactivate);
     }
 
     expect_SetActiveObject_active = FALSE;
+    expect_InPlaceUIWindow_SetActiveObject_active = FALSE;
     hres = IOleDocumentView_UIActivate(view, FALSE);
     ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
 
-    if(call_UIActivate) {
+    if(call_UIActivate != CallUIActivate_None) {
         CHECK_CALLED(SetActiveObject);
         CHECK_CALLED(HideUI);
         CHECK_CALLED(OnUIDeactivate);
     }
+    if(call_UIActivate == CallUIActivate_AfterShow) {
+        CHECK_CALLED(InPlaceUIWindow_SetActiveObject);
+    }
 }
 
 static void test_Hide(void)
@@ -3431,7 +3490,7 @@ static void init_test(enum load_state_t 
     hwnd = last_hwnd = NULL;
     set_clientsite = FALSE;
     load_from_stream = FALSE;
-    call_UIActivate = FALSE;
+    call_UIActivate = CallUIActivate_None;
     load_state = ls;
     editmode = FALSE;
     stream_read = 0;
@@ -3503,7 +3562,7 @@ static void test_HTMLDocument(enum load_
     test_Close(unk, FALSE);
 
     /* Activate HTMLDocument again, this time without UIActivate */
-    call_UIActivate = FALSE;
+    call_UIActivate = CallUIActivate_None;
     test_Activate(unk, CLIENTSITE_SETNULL);
     test_Window(unk, TRUE);
     test_UIDeactivate();
@@ -3514,6 +3573,18 @@ static void test_HTMLDocument(enum load_
     test_OnAmbientPropertyChange2(unk);
     test_GetCurMoniker(unk, load_state == LD_NO ? NULL : &Moniker, NULL);
 
+    if(ls != LD_DOLOAD) {
+        /* Activate HTMLDocument again, calling UIActivate after showing the window */
+        call_UIActivate = CallUIActivate_AfterShow;
+        test_Activate(unk, 0);
+        test_Window(unk, TRUE);
+        test_OleCommandTarget(unk);
+        test_UIDeactivate();
+        test_InPlaceDeactivate(unk, TRUE);
+        test_Close(unk, FALSE);
+        call_UIActivate = CallUIActivate_None;
+    }
+
     if(view)
         IOleDocumentView_Release(view);
     view = NULL;
diff --git a/dlls/mshtml/view.c b/dlls/mshtml/view.c
index c51bcf1..c79da80 100644
--- a/dlls/mshtml/view.c
+++ b/dlls/mshtml/view.c
@@ -93,7 +93,6 @@ static void activate_gecko(NSContainer *
 
     nsIBaseWindow_SetVisibility(This->window, TRUE);
     nsIBaseWindow_SetEnabled(This->window, TRUE);
-    nsIWebBrowserFocus_Activate(This->focus);
 }
 
 void update_doc(HTMLDocument *This, DWORD flags)
@@ -214,6 +213,8 @@ static LRESULT WINAPI serverwnd_proc(HWN
         break;
     case WM_TIMER:
         return on_timer(This);
+    case WM_MOUSEACTIVATE:
+        return MA_ACTIVATE;
     }
         
     return DefWindowProcW(hwnd, msg, wParam, lParam);
@@ -235,7 +236,6 @@ static void register_serverwnd_class(voi
 
 static HRESULT activate_window(HTMLDocument *This)
 {
-    IOleInPlaceUIWindow *pIPWnd;
     IOleInPlaceFrame *pIPFrame;
     IOleCommandTarget *cmdtrg;
     IOleInPlaceSiteEx *ipsiteex;
@@ -253,17 +253,15 @@ static HRESULT activate_window(HTMLDocum
         return FAILED(hres) ? hres : E_FAIL;
     }
 
-    hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &pIPWnd,
+    hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &This->ip_window,
             &posrect, &cliprect, &frameinfo);
     if(FAILED(hres)) {
         WARN("GetWindowContext failed: %08x\n", hres);
         return hres;
     }
 
-    if(pIPWnd)
-        IOleInPlaceUIWindow_Release(pIPWnd);
     TRACE("got window context: %p %p {%d %d %d %d} {%d %d %d %d} {%d %x %p %p %d}\n",
-            pIPFrame, pIPWnd, posrect.left, posrect.top, posrect.right, posrect.bottom,
+            pIPFrame, This->ip_window, posrect.left, posrect.top, posrect.right, posrect.bottom,
             cliprect.left, cliprect.top, cliprect.right, cliprect.bottom,
             frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
 
@@ -292,7 +290,6 @@ static HRESULT activate_window(HTMLDocum
         SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0,
                 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
         RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
-        SetFocus(This->hwnd);
 
         /* NOTE:
          * Windows implementation calls:
@@ -545,6 +542,10 @@ static HRESULT WINAPI OleDocumentView_Sh
         ShowWindow(This->hwnd, SW_SHOW);
     }else {
         ShowWindow(This->hwnd, SW_HIDE);
+        if(This->ip_window) {
+            IOleInPlaceUIWindow_Release(This->ip_window);
+            This->ip_window = NULL;
+        }
     }
 
     return S_OK;
@@ -563,6 +564,9 @@ static HRESULT WINAPI OleDocumentView_UI
     }
 
     if(fUIActivate) {
+        OLECHAR wszHTMLDocument[30];
+        RECT rcBorderWidths;
+
         if(This->ui_active)
             return S_OK;
 
@@ -572,13 +576,17 @@ static HRESULT WINAPI OleDocumentView_UI
                 return hres;
         }
 
+        This->focus = TRUE;
+        nsIWebBrowserFocus_Activate(This->nscontainer->focus);
+        notif_focus(This);
+
         update_doc(This, UPDATE_UI);
 
+        LoadStringW(hInst, IDS_HTMLDOCUMENT, wszHTMLDocument,
+                    sizeof(wszHTMLDocument)/sizeof(WCHAR));
+
         hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
         if(SUCCEEDED(hres)) {
-            OLECHAR wszHTMLDocument[30];
-            LoadStringW(hInst, IDS_HTMLDOCUMENT, wszHTMLDocument,
-                    sizeof(wszHTMLDocument)/sizeof(WCHAR));
             IOleInPlaceFrame_SetActiveObject(This->frame, ACTOBJ(This), wszHTMLDocument);
         }else {
             FIXME("OnUIActivate failed: %08x\n", hres);
@@ -589,15 +597,23 @@ static HRESULT WINAPI OleDocumentView_UI
         }
 
         hres = IDocHostUIHandler_ShowUI(This->hostui, 0, ACTOBJ(This), CMDTARGET(This),
-                This->frame, NULL);
+                This->frame, This->ip_window);
         if(FAILED(hres))
             IDocHostUIHandler_HideUI(This->hostui);
 
+        if(This->ip_window)
+            IOleInPlaceUIWindow_SetActiveObject(This->ip_window, ACTOBJ(This), wszHTMLDocument);
+
+        memset(&rcBorderWidths, 0, sizeof(rcBorderWidths));
+        IOleInPlaceFrame_SetBorderSpace(This->frame, &rcBorderWidths);
+
         This->ui_active = TRUE;
     }else {
         This->window_active = FALSE;
         if(This->ui_active) {
             This->ui_active = FALSE;
+            if(This->ip_window)
+                IOleInPlaceUIWindow_SetActiveObject(This->ip_window, NULL, NULL);
             if(This->frame)
                 IOleInPlaceFrame_SetActiveObject(This->frame, NULL, NULL);
             if(This->hostui)
@@ -778,6 +794,7 @@ void HTMLDocument_View_Init(HTMLDocument
 
     This->ipsite = NULL;
     This->frame = NULL;
+    This->ip_window = NULL;
     This->hwnd = NULL;
     This->tooltips_hwnd = NULL;
 


More information about the wine-patches mailing list