@@ 4,6 4,7 @@ module Graphics.Rendering.Rect.CSS.Backgrounds (Backgrounds(..)) where
import Stylist (PropertyParser(..), parseUnorderedShorthand)
import Data.CSS.Syntax.Tokens (Token(..))
import Data.Maybe (isJust, catMaybes)
+import Data.Text (Text)
import Graphics.Rendering.Rect.CSS.Colour (ColourPallet, parseColour)
import Data.Colour (AlphaColour, transparent)
@@ 12,12 13,13 @@ import Graphics.Rendering.Rect.Types (Rects(..), Rect(..))
data Backgrounds = Backgrounds {
pallet :: ColourPallet,
background :: AlphaColour Float,
- clip :: [Rects -> Rect]
+ clip :: [Rects -> Rect],
+ image :: [Text]
}
instance PropertyParser Backgrounds where
temp = Backgrounds {
- pallet = temp, background = transparent, clip = [borderBox]
+ pallet = temp, background = transparent, clip = [borderBox], image = [""]
}
inherit _ = temp
priority _ = []
@@ 32,6 34,13 @@ instance PropertyParser Backgrounds where
inner [Ident "border-box"] = Just borderBox
inner [Ident "initial"] = Just borderBox -- To aid shorthand implementation.
inner _ = Nothing
+ longhand _ self "background-image" t | val@(_:_) <- parseCSSList inner t =
+ Just self { image = val }
+ where
+ inner [Ident "none"] = Just ""
+ inner [Ident "initial"] = Just ""
+ inner [Url ret] = Just ret
+ inner _ = Nothing
longhand _ _ _ _ = Nothing
-- The multi-layered shorthand is one source of parsing complexity.
@@ 48,7 57,7 @@ instance PropertyParser Backgrounds where
-- Shouldn't happen, `inner` expands all props at least to "initial"!
| otherwise = (key, val)
inner toks | ret@(_:_) <- parseUnorderedShorthand self [
- "background-color", "background-clip"
+ "background-color", "background-clip", "background-color"
] toks = Just ret
| otherwise = Nothing
shorthand self key val | Just _ <- longhand self self key val = [(key, val)]