ghcjs / ghcjs-dom

Make Document Object Model (DOM) apps that run in any browser and natively using WebKitGtk
74 stars 41 forks source link

No more getStyle function for Element #72

Closed mm1992 closed 7 years ago

mm1992 commented 7 years ago

The GHCJS.DOM.Element module used to have getStyle function It could be used as in the following link: https://github.com/LambdaHack/LambdaHack/blob/master/Game/LambdaHack/Client/UI/Frontend/Dom.hs#L85 (divStyle <- getStyle divBlock).

However, in the latest version of ghcjs-dom getStyle is absent.

[ 57 of 123] Compiling Game.LambdaHack.Client.UI.Frontend.Dom (
Game/LambdaHack/Client/UI/Frontend/Dom.hs,
dist/build/Game/LambdaHack/Client/UI/Frontend/Dom.o )
Game/LambdaHack/Client/UI/Frontend/Dom.hs:22:46: error:
    Module ‘GHCJS.DOM.Element’ does not export ‘getStyle’

Should we instead use getStyle of ElementCSSInlineStyle? Do you know the rationale behind this change?

Thank you in advance for any advice!

hamishmack commented 7 years ago

Should we instead use getStyle of ElementCSSInlineStyle?

Yes, it looks like it has moved to GHCJS.DOM.ElementCSSInlineStyle.

Do you know the rationale behind this change?

It was made in the upstream WebKit IDL files, I am not sure why.

Mikolaj commented 7 years ago

Thank you, Hamish. If this change is intentional, then we'll just stick to the ElementCSSInlineStyle fix. Cheers!

hamishmack commented 7 years ago

From reading this it seems that there could be elements of just type Element that are not HTMLElement or SVGElement (and so would not have a style). By having a separate interface we are forced to cast Element to one of HTMLElement or SVGElement to indicate that it is safe to call getStyle.

You can also do uncheckedCastTo ElementCSSInlineStyle to convert from Element to ElementCSSInlineStyle (if you know it will be one of HTMLELement or SVGElement, but are not sure which). The checked version castTo ElementCSSInlineStyle will not work because there is no way to do x instanceof ElementCSSInlineStyle in JavaScript (because ElementCSSInlineStyle does not exist).

Mikolaj commented 7 years ago

Implicit type conversions seem to do the trick for my code. Just switching to ElementCSSInlineStyle (getStyle) was enough so far. Thanks again.