~alcinnz/Mondrian

dc6acbc9e4a5eaedd36a83d0116f0847d8042a7d — Adrian Cochrane 1 year, 6 months ago 6236cf8
Parse background-color for image data.
1 files changed, 12 insertions(+), 3 deletions(-)

M lib/Graphics/Rendering/Rect/CSS/Backgrounds.hs
M lib/Graphics/Rendering/Rect/CSS/Backgrounds.hs => lib/Graphics/Rendering/Rect/CSS/Backgrounds.hs +12 -3
@@ 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)]