diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/css/cascade.nim | 2 | ||||
-rw-r--r-- | src/css/mediaquery.nim | 26 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim index 4429dee4..88f0c211 100644 --- a/src/css/cascade.nim +++ b/src/css/cascade.nim @@ -53,6 +53,8 @@ func applies(feature: MediaFeature, window: Window): bool = return feature.appliesLR(window, toLayoutUnit(window.attrs.width_px)) of FEATURE_HEIGHT: return feature.appliesLR(window, toLayoutUnit(window.attrs.height_px)) + of FEATURE_SCRIPTING: + return feature.b == window.settings.scripting func applies(mq: MediaQuery, window: Window): bool = case mq.t diff --git a/src/css/mediaquery.nim b/src/css/mediaquery.nim index 5a73712d..5d092355 100644 --- a/src/css/mediaquery.nim +++ b/src/css/mediaquery.nim @@ -25,13 +25,14 @@ type MediaFeatureType* = enum FEATURE_COLOR, FEATURE_GRID, FEATURE_HOVER, FEATURE_PREFERS_COLOR_SCHEME, - FEATURE_WIDTH, FEATURE_HEIGHT + FEATURE_WIDTH, FEATURE_HEIGHT, FEATURE_SCRIPTING MediaFeature* = object case t*: MediaFeatureType of FEATURE_COLOR: range*: Slice[int] - of FEATURE_GRID, FEATURE_HOVER, FEATURE_PREFERS_COLOR_SCHEME: + of FEATURE_GRID, FEATURE_HOVER, FEATURE_PREFERS_COLOR_SCHEME, + FEATURE_SCRIPTING: b*: bool of FEATURE_WIDTH, FEATURE_HEIGHT: lengthrange*: Slice[CSSLength] @@ -90,6 +91,8 @@ func `$`*(mf: MediaFeature): string = result &= "=" result &= " " result &= $mf.lengthrange.b + of FEATURE_SCRIPTING: + return "scripting: " & (if mf.b: "enabled" else: "none") func `$`*(mq: MediaQuery): string = case mq.t @@ -177,7 +180,7 @@ template expect_mq_int(b: bool, ifalse: int, itrue: int) = elif i == itrue: b = true else: return nil -template expect_bool(b: bool, sfalse: string, strue: string) = +template expect_bool(b: bool, sfalse, strue: string) = let tok = consume_token() if tok.tokenType != CSS_IDENT_TOKEN: return nil let s = tok.value @@ -186,6 +189,15 @@ template expect_bool(b: bool, sfalse: string, strue: string) = of sfalse: b = false else: return nil +template expect_bool(b: bool, sfalse, sfalse2, strue: string) = + let tok = consume_token() + if tok.tokenType != CSS_IDENT_TOKEN: return nil + let s = tok.value + case s + of strue: b = true + of sfalse, sfalse2: b = false + else: return nil + template expect_comparison(comparison: var MediaQueryComparison) = let tok = consume_token() if tok != CSS_DELIM_TOKEN: return nil @@ -331,6 +343,12 @@ proc parseFeature(parser: var MediaQueryParser, t: MediaFeatureType, lengthaeq: lengthaeq, lengthbeq: lengthbeq ) + of FEATURE_SCRIPTING: + if ismin or ismax: + return nil + var b: bool + expect_bool(b, "none", "initial-only", "enabled") + MediaFeature(t: t, b: b) parser.skipBlanks() if parser.has(): return nil @@ -374,6 +392,8 @@ proc parseMediaInParens(parser: var MediaQueryParser): MediaQuery = return fparser.parseFeature(FEATURE_HOVER, ismin, ismax) of "prefers-color-scheme": return fparser.parseFeature(FEATURE_PREFERS_COLOR_SCHEME, ismin, ismax) + of "scripting": + return fparser.parseFeature(FEATURE_SCRIPTING, ismin, ismax) else: discard return nil |