[PATCH v3 2/3] mshtml: Implement inline attributes parsing for createElement.

Gabriel Ivăncescu gabrielopcode at gmail.com
Fri Nov 5 11:31:17 CDT 2021


On 05/11/2021 16:11, Jacek Caban wrote:
> On 11/4/21 3:10 PM, Gabriel Ivăncescu wrote:
>> +    /* Create a temporary html element and parse it there */
>> +    nsAString_InitDepend(&str, L"HTML");
>> +    nsres = nsIDOMHTMLDocument_CreateElement(doc->nsdoc, &str, 
>> (nsIDOMElement**)&nshtml);
>> +    nsAString_Finish(&str);
>> +    if(NS_FAILED(nsres))
>> +        return map_nsresult(nsres);
>> +
>> +    if(name_len == 4 && !wcsnicmp(tag + 1, L"HTML", 4)) {
>> +        FIXME("Returning <html> element with no attributes\n");
>> +*ret = (nsIDOMElement*)nshtml;
>> +        return S_OK;
>> +    }
> 
> 
> Did you try using <template> element instead of <html>? I'd expect it do 
> do the right thing, but I didn't try.
> 

I tried it now, it doesn't seem to work properly for all tags because 
it's context-dependent. It works fine for tags under <body>, but it 
won't work for the tags outside of it, such as <body> <head> <title> etc

It seems they are simply discarded and the outer HTML looks like just a 
<template></template>. The html tag already has this issue but only with 
the <html> element which is probably not important (prints a FIXME 
anyway in such case).

> 
>> +
>> +    nsAString_InitDepend(&str, tag);
>> +    nsres = nsIDOMHTMLElement_SetInnerHTML(nshtml, &str);
>> +    nsAString_Finish(&str);
>> +    if(NS_FAILED(nsres)) {
>> +        hres = map_nsresult(nsres);
>> +        goto fail;
>> +    }
>> +
>> +    /* Get the element and remove it from the temporary */
>> +    if(!(p = heap_alloc((name_len + 1) * sizeof(WCHAR))))
>> +        hres = E_OUTOFMEMORY;
>> +    else {
>> +        memcpy(p, tag + 1, name_len * sizeof(WCHAR));
>> +        p[name_len] = '\0';
>> +        nsAString_InitDepend(&str, p);
>> +        nsres = nsIDOMHTMLElement_GetElementsByTagName(nshtml, &str, 
>> &nscol);
>> +        nsAString_Finish(&str);
>> +        heap_free(p);
>> +        if(NS_FAILED(nsres))
>> +            goto fail;
> 
> 
> That's making things more complicated that they need to be. You could 
> just use firstElementChild or something similar.
> 

Unfortunately, it's not that simple. Continuing the above, when used in 
a <html> element, the inserted element tag can be in different places. 
For example, the innerHTML of such with a <div> would look like this:

<head></head><body><div a="b"></div></body>

This is what gecko does when setInnerHTML to a <div a="b">.

But if the created element is, say, <head a="b">, it would be:

<head a="b"></head><body></body>

If it's <title a="b"> it would be:

<head><title a="b"></title></head><body></body>

That is, gecko places it in appropriate place depending on its context.

As you can see, it's in different places, so how can I retrieve it 
without knowing its name? Do you have any ideas?

Thanks,
Gabriel



More information about the wine-devel mailing list