mshtml: Added IHTMLTable::get_rows implementation.

This commit is contained in:
Jacek Caban 2008-09-30 17:45:48 +02:00 committed by Alexandre Julliard
parent bf9155dbaa
commit ac4117fdb5
5 changed files with 88 additions and 4 deletions

View File

@ -503,6 +503,31 @@ IHTMLElementCollection *create_collection_from_nodelist(HTMLDocument *doc, IUnkn
return HTMLElementCollection_Create(unk, buf.buf, buf.len);
}
IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocument *doc, IUnknown *unk, nsIDOMHTMLCollection *nscol)
{
PRUint32 length = 0, i;
elem_vector_t buf;
nsIDOMHTMLCollection_GetLength(nscol, &length);
buf.len = buf.size = length;
if(buf.len) {
nsIDOMNode *nsnode;
buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
for(i=0; i<length; i++) {
nsIDOMHTMLCollection_Item(nscol, i, &nsnode);
buf.buf[i] = HTMLELEM_NODE_THIS(get_node(doc, nsnode, TRUE));
nsIDOMNode_Release(nsnode);
}
}else {
buf.buf = NULL;
}
return HTMLElementCollection_Create(unk, buf.buf, buf.len);
}
IHTMLElementCollection *HTMLElementCollection_Create(IUnknown *ref_unk,
HTMLElement **elems, DWORD len)
{

View File

@ -274,8 +274,21 @@ static HRESULT WINAPI HTMLTable_refresh(IHTMLTable *iface)
static HRESULT WINAPI HTMLTable_get_rows(IHTMLTable *iface, IHTMLElementCollection **p)
{
HTMLTable *This = HTMLTABLE_THIS(iface);
FIXME("(%p)->(%p)\n", This, p);
return E_NOTIMPL;
nsIDOMHTMLCollection *nscol;
nsresult nsres;
TRACE("(%p)->(%p)\n", This, p);
nsres = nsIDOMHTMLTableElement_GetRows(This->nstable, &nscol);
if(NS_FAILED(nsres)) {
ERR("GetRows failed: %08x\n", nsres);
return E_FAIL;
}
*p = create_collection_from_htmlcol(This->element.node.doc, (IUnknown*)HTMLTABLE(This), nscol);
nsIDOMHTMLCollection_Release(nscol);
return S_OK;
}
static HRESULT WINAPI HTMLTable_put_width(IHTMLTable *iface, VARIANT v)

View File

@ -587,6 +587,7 @@ void set_script_mode(HTMLDocument*,SCRIPTMODE);
IHTMLElementCollection *HTMLElementCollection_Create(IUnknown*,HTMLElement**,DWORD);
IHTMLElementCollection *create_all_collection(HTMLDOMNode*,BOOL);
IHTMLElementCollection *create_collection_from_nodelist(HTMLDocument*,IUnknown*,nsIDOMNodeList*);
IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocument*,IUnknown*,nsIDOMHTMLCollection*);
/* commands */
typedef struct {

View File

@ -115,7 +115,6 @@ typedef nsISupports nsIDOMProcessingInstruction;
typedef nsISupports nsIDOMEntityReference;
typedef nsISupports nsIDOMHTMLFormElement;
typedef nsISupports nsIDOMHTMLOptionsCollection;
typedef nsISupports nsIDOMHTMLCollection;
typedef nsISupports nsIWebProgressListener;
typedef nsISupports nsIDOMCSSValue;
typedef nsISupports nsIPrintSession;
@ -824,6 +823,19 @@ interface nsIDOMNSHTMLElement : nsISupports
nsresult ScrollIntoView(PRBool top);
}
[
object,
uuid(a6cf9083-15b3-11d2-932e-00805f8add32),
local
/* FROZEN */
]
interface nsIDOMHTMLCollection : nsISupports
{
nsresult GetLength(PRUint32 *aLength);
nsresult Item(PRUint32 index, nsIDOMNode **_retval);
nsresult NamedItem(const nsAString *name, nsIDOMNode **_retval);
}
[
object,
uuid(a6cf9072-15b3-11d2-932e-00805f8add32),

View File

@ -45,7 +45,7 @@ static const char elem_test_str[] =
"<input id=\"in\" class=\"testclass\" tabIndex=\"2\" title=\"test title\" />"
"<select id=\"s\"><option id=\"x\" value=\"val1\">opt1</option><option id=\"y\">opt2</option></select>"
"<textarea id=\"X\">text text</textarea>"
"<table><tbody><tr></tr></tbody></table>"
"<table id=\"tbl\"><tbody><tr></tr><tr id=\"row2\"></tr></tbody></table>"
"<script id=\"sc\" type=\"text/javascript\"></script>"
"<test />"
"<img id=\"imgid\"/>"
@ -2243,6 +2243,30 @@ static void test_defaults(IHTMLDocument2 *doc)
test_doc_title(doc, "");
}
static void test_table_elem(IHTMLElement *elem)
{
IHTMLElementCollection *col;
IHTMLTable *table;
HRESULT hres;
static const elem_type_t row_types[] = {ET_TR,ET_TR};
hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
if(FAILED(hres))
return;
col = NULL;
hres = IHTMLTable_get_rows(table, &col);
ok(hres == S_OK, "get_rows failed: %08x\n", hres);
ok(col != NULL, "get_ros returned NULL\n");
test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
IHTMLElementCollection_Release(col);
IHTMLTable_Release(table);
}
static void test_stylesheet(IDispatch *disp)
{
IHTMLStyleSheetRulesCollection *col = NULL;
@ -2359,6 +2383,7 @@ static void test_elems(IHTMLDocument2 *doc)
static const WCHAR sW[] = {'s',0};
static const WCHAR scW[] = {'s','c',0};
static const WCHAR xxxW[] = {'x','x','x',0};
static const WCHAR tblW[] = {'t','b','l',0};
static const elem_type_t all_types[] = {
ET_HTML,
@ -2376,6 +2401,7 @@ static void test_elems(IHTMLDocument2 *doc)
ET_TABLE,
ET_TBODY,
ET_TR,
ET_TR,
ET_SCRIPT,
ET_TEST,
ET_IMG
@ -2537,6 +2563,13 @@ static void test_elems(IHTMLDocument2 *doc)
IHTMLElement_Release(elem);
}
elem = get_doc_elem_by_id(doc, tblW);
ok(elem != NULL, "elem == NULL\n");
if(elem) {
test_table_elem(elem);
IHTMLElement_Release(elem);
}
hres = IHTMLDocument2_get_body(doc, &elem);
ok(hres == S_OK, "get_body failed: %08x\n", hres);