Module: wine Branch: master Commit: 733dfb64294234970bd956ca9fec563d2183f20b URL: http://source.winehq.org/git/wine.git/?a=commit;h=733dfb64294234970bd956ca9f...
Author: Andrew Eikum aeikum@codeweavers.com Date: Fri Nov 13 14:13:10 2009 -0600
mshtml: Implement IHTMLWindow2::item.
---
dlls/mshtml/htmlwindow.c | 115 +++++++++++++++++++++++++++++++++++++++++++++- dlls/mshtml/tests/dom.c | 20 ++++---- 2 files changed, 123 insertions(+), 12 deletions(-)
diff --git a/dlls/mshtml/htmlwindow.c b/dlls/mshtml/htmlwindow.c index c893a6d..41c5cbe 100644 --- a/dlls/mshtml/htmlwindow.c +++ b/dlls/mshtml/htmlwindow.c @@ -235,11 +235,122 @@ static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMembe pVarResult, pExcepInfo, puArgErr); }
+static HRESULT get_frame_by_index(nsIDOMWindowCollection *nsFrames, PRUint32 index, HTMLWindow **ret) +{ + PRUint32 length; + nsIDOMWindow *nsWindow; + nsresult nsres; + + nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length); + if(NS_FAILED(nsres)) { + FIXME("nsIDOMWindowCollection_GetLength failed: 0x%08x\n", nsres); + return E_FAIL; + } + + if(index >= length) + return DISP_E_MEMBERNOTFOUND; + + nsres = nsIDOMWindowCollection_Item(nsFrames, index, &nsWindow); + if(NS_FAILED(nsres)) { + FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres); + return E_FAIL; + } + + *ret = nswindow_to_window(nsWindow); + + nsIDOMWindow_Release(nsWindow); + + return S_OK; +} + static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult) { HTMLWindow *This = HTMLWINDOW2_THIS(iface); - FIXME("(%p)->(%p %p)\n", This, pvarIndex, pvarResult); - return E_NOTIMPL; + nsIDOMWindowCollection *nsFrames; + HTMLWindow *window; + HRESULT hres; + nsresult nsres; + + TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult); + + nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsFrames); + if(NS_FAILED(nsres)) { + FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres); + return E_FAIL; + } + + if(V_VT(pvarIndex) == VT_I4) { + int index = V_I4(pvarIndex); + TRACE("Getting index %d\n", index); + if(index < 0) { + hres = DISP_E_MEMBERNOTFOUND; + goto cleanup; + } + hres = get_frame_by_index(nsFrames, index, &window); + if(FAILED(hres)) + goto cleanup; + }else if(V_VT(pvarIndex) == VT_UINT) { + unsigned int index = V_UINT(pvarIndex); + TRACE("Getting index %u\n", index); + hres = get_frame_by_index(nsFrames, index, &window); + if(FAILED(hres)) + goto cleanup; + }else if(V_VT(pvarIndex) == VT_BSTR) { + BSTR str = V_BSTR(pvarIndex); + PRUint32 length, i; + + TRACE("Getting name %s\n", wine_dbgstr_w(str)); + + nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length); + + window = NULL; + for(i = 0; i < length && !window; ++i) { + HTMLWindow *cur_window; + nsIDOMWindow *nsWindow; + BSTR id; + + nsres = nsIDOMWindowCollection_Item(nsFrames, i, &nsWindow); + if(NS_FAILED(nsres)) { + FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres); + hres = E_FAIL; + goto cleanup; + } + + cur_window = nswindow_to_window(nsWindow); + + nsIDOMWindow_Release(nsWindow); + + hres = IHTMLElement_get_id(HTMLELEM(&cur_window->frame_element->element), &id); + if(FAILED(hres)) { + FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres); + goto cleanup; + } + + if(!strcmpW(id, str)) + window = cur_window; + + SysFreeString(id); + } + + if(!window) { + hres = DISP_E_MEMBERNOTFOUND; + goto cleanup; + } + }else { + hres = E_INVALIDARG; + goto cleanup; + } + + IHTMLWindow2_AddRef(HTMLWINDOW2(window)); + V_VT(pvarResult) = VT_DISPATCH; + V_DISPATCH(pvarResult) = (IDispatch*)window; + + hres = S_OK; + +cleanup: + nsIDOMWindowCollection_Release(nsFrames); + + return hres; }
static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p) diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index 6cbf2e8..a75f9e1 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -5611,7 +5611,7 @@ static void test_frameset(IHTMLDocument2 *doc) V_VT(&index_var) = VT_I4; V_I4(&index_var) = 0; hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var); - todo_wine ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres); + ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres); if(SUCCEEDED(hres)) { ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x", V_VT(&result_var)); test_frame((IDispatch*)V_DISPATCH(&result_var), "fr1"); @@ -5621,7 +5621,7 @@ static void test_frameset(IHTMLDocument2 *doc) /* test second frame */ V_I4(&index_var) = 1; hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var); - todo_wine ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres); + ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres); if(SUCCEEDED(hres)) { ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x", V_VT(&result_var)); test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2"); @@ -5631,7 +5631,7 @@ static void test_frameset(IHTMLDocument2 *doc) /* fail on third frame */ V_I4(&index_var) = 2; hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var); - todo_wine ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLFramesCollection2_item should have" + ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLFramesCollection2_item should have" "failed with DISP_E_MEMBERNOTFOUND, instead: 0x%08x\n", hres); VariantClear(&result_var);
@@ -5639,7 +5639,7 @@ static void test_frameset(IHTMLDocument2 *doc) V_VT(&index_var) = VT_BSTR; V_BSTR(&index_var) = a2bstr("fr1"); hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var); - todo_wine ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres); + ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres); if(SUCCEEDED(hres)) { ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x", V_VT(&result_var)); test_frame((IDispatch*)V_DISPATCH(&result_var), "fr1"); @@ -5651,7 +5651,7 @@ static void test_frameset(IHTMLDocument2 *doc) V_VT(&index_var) = VT_BOOL; V_BOOL(&index_var) = VARIANT_TRUE; hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var); - todo_wine ok(hres == E_INVALIDARG, "IHTMLFramesCollection2_item should have" + ok(hres == E_INVALIDARG, "IHTMLFramesCollection2_item should have" "failed with E_INVALIDARG, instead: 0x%08x\n", hres); VariantClear(&result_var);
@@ -5668,7 +5668,7 @@ static void test_frameset(IHTMLDocument2 *doc) V_VT(&index_var) = VT_I4; V_I4(&index_var) = 0; hres = IHTMLWindow2_item(window, &index_var, &result_var); - todo_wine ok(hres == S_OK, "IHTMLWindow2_item failed: 0x%08x\n", hres); + ok(hres == S_OK, "IHTMLWindow2_item failed: 0x%08x\n", hres); if(SUCCEEDED(hres)) { ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x", V_VT(&result_var)); test_frame((IDispatch*)V_DISPATCH(&result_var), "fr1"); @@ -5678,7 +5678,7 @@ static void test_frameset(IHTMLDocument2 *doc) /* test second frame */ V_I4(&index_var) = 1; hres = IHTMLWindow2_item(window, &index_var, &result_var); - todo_wine ok(hres == S_OK, "IHTMLWindow2_item failed: 0x%08x\n", hres); + ok(hres == S_OK, "IHTMLWindow2_item failed: 0x%08x\n", hres); if(SUCCEEDED(hres)) { ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x", V_VT(&result_var)); test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2"); @@ -5688,7 +5688,7 @@ static void test_frameset(IHTMLDocument2 *doc) /* fail on third frame */ V_I4(&index_var) = 2; hres = IHTMLWindow2_item(window, &index_var, &result_var); - todo_wine ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLWindow2_item should have" + ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLWindow2_item should have" "failed with DISP_E_MEMBERNOTFOUND, instead: 0x%08x\n", hres); VariantClear(&result_var);
@@ -5696,7 +5696,7 @@ static void test_frameset(IHTMLDocument2 *doc) V_VT(&index_var) = VT_BSTR; V_BSTR(&index_var) = a2bstr("fr2"); hres = IHTMLWindow2_item(window, &index_var, &result_var); - todo_wine ok(hres == S_OK, "IHTMLWindow2_item failed: 0x%08x\n", hres); + ok(hres == S_OK, "IHTMLWindow2_item failed: 0x%08x\n", hres); if(SUCCEEDED(hres)) { ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x", V_VT(&result_var)); test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2"); @@ -5708,7 +5708,7 @@ static void test_frameset(IHTMLDocument2 *doc) V_VT(&index_var) = VT_BOOL; V_BOOL(&index_var) = VARIANT_TRUE; hres = IHTMLWindow2_item(window, &index_var, &result_var); - todo_wine ok(hres == E_INVALIDARG, "IHTMLWindow2_item should have" + ok(hres == E_INVALIDARG, "IHTMLWindow2_item should have" "failed with E_INVALIDARG, instead: 0x%08x\n", hres); VariantClear(&result_var); }