leaningtech / cheerp-meta

Cheerp - a C/C++ compiler for Web applications - compiles to WebAssembly and JavaScript
https://labs.leaningtech.com/cheerp
Other
1.03k stars 51 forks source link

MSStyleCSSProperties is not defined #77

Closed sdrecker closed 6 years ago

sdrecker commented 6 years ago

Hi cheerp/developers,

first of all congrats to this project. From my perspective it will change the way of web developing dramatically.

But now to my problem. I have following simplified code:

using namespace client;
HTMLElement *body;

class CButton
{
    private:

        HTMLElement *m_pButton;
        //MSStyleCSSProperties m_buttonStyle;

    public:

    CButton ()
    {
        m_pButton = document.createElement ("div");
        m_pButton ->set_innerHTML ("save");
        // m_buttonStyle.set_color ("blue");
        // m_pButton->set_style (&m_buttonStyle);
        body->appendChild (m_pButton);
    }
};

void webMain ()
{
    CButton *button;

    body = document.get_body ();
    button = new CButton ();
}

When I compile the code above everything works fine. But when I activate the commented lines to style my element, the code can still be compiled but the browser throws the error "MSStyleCSSProperties is not defined".

Have I done something wrong?

Best greetings Sebastian

alexp-sssup commented 6 years ago

Thanks for your support.

I think the fundamental problem is that the style properties of DOM objects is a collection of individual properties that can be set, but it is not itself writeable. You can check this by trying the following JS code.

document.body.style = null;
console.log(document.body.style); // not null

This also implies that the object representing the collection of properties is not truly something you can allocate, but only something you can get from an existing DOM object.

sdrecker commented 6 years ago

Ah okay. So is there a way then, besides editing a corresponding css-File or using javascript in C++, to manipulate the style of an element over your API?

alexp-sssup commented 6 years ago

Yes sure, the API is absolutely equivalent to the normal JS one.

m_pButton->get_style()->set_color ("blue");