Commit 733dfb64 authored by Andrew Eikum's avatar Andrew Eikum Committed by Alexandre Julliard

mshtml: Implement IHTMLWindow2::item.

parent ac226b20
......@@ -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)
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment