{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Miso.Lynx.Element.View.Method
(
boundingClientRect
, takeScreenshot
, requestAccessibilityFocus
, Rect (..)
, BoundingClientRect (..)
, TakeScreenshot (..)
, defaultBoundingClientRect
, defaultTakeScreenshot
) where
import Language.Javascript.JSaddle
import Miso
import Miso.Lynx.FFI
data Rect
= Rect
{ Rect -> Double
x,Rect -> Double
y :: Double
, Rect -> Double
width, Rect -> Double
height :: Double
, Rect -> Double
top, Rect -> Double
bottom :: Double
, Rect -> Double
right, Rect -> Double
left :: Double
} deriving (Int -> Rect -> ShowS
[Rect] -> ShowS
Rect -> String
(Int -> Rect -> ShowS)
-> (Rect -> String) -> ([Rect] -> ShowS) -> Show Rect
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Rect -> ShowS
showsPrec :: Int -> Rect -> ShowS
$cshow :: Rect -> String
show :: Rect -> String
$cshowList :: [Rect] -> ShowS
showList :: [Rect] -> ShowS
Show, Rect -> Rect -> Bool
(Rect -> Rect -> Bool) -> (Rect -> Rect -> Bool) -> Eq Rect
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Rect -> Rect -> Bool
== :: Rect -> Rect -> Bool
$c/= :: Rect -> Rect -> Bool
/= :: Rect -> Rect -> Bool
Eq)
instance FromJSVal Rect where
fromJSVal :: JSVal -> JSM (Maybe Rect)
fromJSVal = \JSVal
rect -> do
let readProp :: MisoString -> JSM Double
readProp = \MisoString
name ->
JSVal -> JSM Double
forall a. FromJSVal a => JSVal -> JSM a
fromJSValUnchecked (JSVal -> JSM Double) -> JSM JSVal -> JSM Double
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
JSVal
rect JSVal -> MisoString -> JSM JSVal
forall this name.
(MakeObject this, ToJSString name) =>
this -> name -> JSM JSVal
! (MisoString
name :: MisoString)
x <- MisoString -> JSM Double
readProp MisoString
"x"
y <- readProp "y"
height <- readProp "height"
width <- readProp "width"
top <- readProp "top"
right <- readProp "right"
left <- readProp "left"
bottom <- readProp "bottom"
pure $ Just Rect {..}
data BoundingClientRect
= BoundingClientRect
{ BoundingClientRect -> Bool
androidEnableTransformProps :: Bool
, BoundingClientRect -> Maybe JSVal
relativeTo :: Maybe JSVal
}
instance ToJSVal BoundingClientRect where
toJSVal :: BoundingClientRect -> JSM JSVal
toJSVal BoundingClientRect {Bool
Maybe JSVal
androidEnableTransformProps :: BoundingClientRect -> Bool
relativeTo :: BoundingClientRect -> Maybe JSVal
androidEnableTransformProps :: Bool
relativeTo :: Maybe JSVal
..} = do
o <- JSM Object
create
set "androidEnableTransformProps" androidEnableTransformProps o
set "relativeTo" relativeTo o
toJSVal o
defaultBoundingClientRect :: BoundingClientRect
defaultBoundingClientRect :: BoundingClientRect
defaultBoundingClientRect
= BoundingClientRect
{ androidEnableTransformProps :: Bool
androidEnableTransformProps = Bool
True
, relativeTo :: Maybe JSVal
relativeTo = Maybe JSVal
forall a. Maybe a
Nothing
}
boundingClientRect
:: MisoString
-> BoundingClientRect
-> (Rect -> action)
-> (MisoString -> action)
-> Effect parent model action
boundingClientRect :: forall action parent model.
MisoString
-> BoundingClientRect
-> (Rect -> action)
-> (MisoString -> action)
-> Effect parent model action
boundingClientRect = MisoString
-> MisoString
-> BoundingClientRect
-> (Rect -> action)
-> (MisoString -> action)
-> Effect parent model action
forall params argument action parent model.
(ToJSVal params, FromJSVal argument) =>
MisoString
-> MisoString
-> params
-> (argument -> action)
-> (MisoString -> action)
-> Effect parent model action
invokeExec MisoString
"boundingClientRect"
data TakeScreenshot
= TakeScreenshot
{ TakeScreenshot -> MisoString
format :: MisoString
, TakeScreenshot -> Double
scale :: Double
}
instance ToJSVal TakeScreenshot where
toJSVal :: TakeScreenshot -> JSM JSVal
toJSVal TakeScreenshot {Double
MisoString
format :: TakeScreenshot -> MisoString
scale :: TakeScreenshot -> Double
format :: MisoString
scale :: Double
..} = do
o <- JSM Object
create
set "format" format o
set "scale" scale o
toJSVal o
takeScreenshot
:: MisoString
-> TakeScreenshot
-> (JSVal -> action)
-> (MisoString -> action)
-> Effect parent model action
takeScreenshot :: forall action parent model.
MisoString
-> TakeScreenshot
-> (JSVal -> action)
-> (MisoString -> action)
-> Effect parent model action
takeScreenshot = MisoString
-> MisoString
-> TakeScreenshot
-> (JSVal -> action)
-> (MisoString -> action)
-> Effect parent model action
forall params argument action parent model.
(ToJSVal params, FromJSVal argument) =>
MisoString
-> MisoString
-> params
-> (argument -> action)
-> (MisoString -> action)
-> Effect parent model action
invokeExec MisoString
"takeScreenshot"
defaultTakeScreenshot :: TakeScreenshot
defaultTakeScreenshot :: TakeScreenshot
defaultTakeScreenshot
= TakeScreenshot
{ scale :: Double
scale = Double
0.5
, format :: MisoString
format = MisoString
".png"
}
requestAccessibilityFocus
:: MisoString
-> (JSVal -> action)
-> (MisoString -> action)
-> Effect parent model action
requestAccessibilityFocus :: forall action parent model.
MisoString
-> (JSVal -> action)
-> (MisoString -> action)
-> Effect parent model action
requestAccessibilityFocus MisoString
selector =
MisoString
-> MisoString
-> ()
-> (JSVal -> action)
-> (MisoString -> action)
-> Effect parent model action
forall params argument action parent model.
(ToJSVal params, FromJSVal argument) =>
MisoString
-> MisoString
-> params
-> (argument -> action)
-> (MisoString -> action)
-> Effect parent model action
invokeExec MisoString
"requestAccessibilityFocus" MisoString
selector ()