Browse Source

dom: started parsing justify-items

mattias 11 months ago
parent
commit
7d458bec81
1 changed files with 142 additions and 4 deletions
  1. 142 4
      src/base/fresnel.dom.pas

+ 142 - 4
src/base/fresnel.dom.pas

@@ -151,6 +151,7 @@ type
     fcaFlexFlow,
     fcaFlex,
     fcaJustifyContent,
+    fcaJustifyItems,
     fcaJustifySelf
     );
   TFresnelCSSAttributes = set of TFresnelCSSAttribute;
@@ -255,6 +256,7 @@ const
     'flex-flow',
     'flex',
     'justify-content',
+    'justify-items',
     'justify-self'
     );
 
@@ -412,6 +414,7 @@ type
     function CheckFlexFlow(Resolver: TCSSBaseResolver): boolean; virtual;
     function CheckFlex(Resolver: TCSSBaseResolver): boolean; virtual;
     function CheckJustifyContent(Resolver: TCSSBaseResolver): boolean; virtual;
+    function CheckJustifyItems(Resolver: TCSSBaseResolver): boolean; virtual;
     function CheckJustifySelf(Resolver: TCSSBaseResolver): boolean; virtual;
 
     // utility check/parse functions
@@ -428,6 +431,7 @@ type
     function ReadFlex(Resolver: TCSSBaseResolver; Check: boolean; out Grow, Shrink, Basis: TCSSString): boolean; virtual;
     function ReadFlexFlow(Resolver: TCSSBaseResolver; Check: boolean; out Direction, Wrap: TCSSString): boolean; virtual;
     function ReadJustifySelf(Resolver: TCSSBaseResolver; Check: boolean; out MainKW, SubKW: TCSSNumericalID): boolean; virtual;
+    function ReadJustifyItems(Resolver: TCSSBaseResolver; Check: boolean; out MainKW, SubKW: TCSSNumericalID): boolean; virtual;
     function IsColor(const ResValue: TCSSResCompValue): boolean; virtual;
     procedure SplitLonghandSides(var AttrIDs: TCSSNumericalIDArray; var Values: TCSSStringArray;
       Top, Right, Bottom, Left: TFresnelCSSAttribute; const Found: TCSSStringArray);
@@ -566,7 +570,8 @@ type
       kwLarger = kwLarge+1;
       kwLast = kwLarger+1;
       kwLeft = kwLast+1;
-      kwLighter = kwLeft+1;
+      kwLegacy = kwLeft+1;
+      kwLighter = kwLegacy+1;
       kwLocal = kwLighter+1;
       kwLTR = kwLocal+1;
       kwMaxContent = kwLTR+1; // max-content
@@ -753,6 +758,7 @@ type
     Chk_FlexShrink_Dim: TCSSCheckAttrParams_Dimension;
     Chk_FlexWrap_KeywordIDs: TCSSNumericalIDArray;
     Chk_JustifyContent_KeywordIDs: TCSSNumericalIDArray;
+    Chk_JustifyItems_KeywordIDs: TCSSNumericalIDArray;
     Chk_JustifySelf_KeywordIDs: TCSSNumericalIDArray;
 
     constructor Create;
@@ -2013,6 +2019,13 @@ begin
   Result:=Resolver.CheckAttribute_Keyword(Chk_JustifyContent_KeywordIDs);
 end;
 
+function TFresnelCSSRegistry.CheckJustifyItems(Resolver: TCSSBaseResolver): boolean;
+var
+  MainKW, SubKW: TCSSNumericalID;
+begin
+  Result:=ReadJustifyItems(Resolver,true,MainKW,SubKW);
+end;
+
 function TFresnelCSSRegistry.CheckJustifySelf(Resolver: TCSSBaseResolver): boolean;
 var
   MainKW, SubKW: TCSSNumericalID;
@@ -2462,8 +2475,81 @@ begin
       begin
         KW:=Resolver.CurComp.KeywordID;
         case KW of
-        kwAuto, kwNormal,kwStart,kwEnd,kwFlexStart,kwFlexEnd,kwSelfStart,kwSelfEnd,kwCenter,kwLeft,kwRight,
-        kwAnchorCenter,kwSafe,kwUnsafe:
+        kwAuto, kwNormal:
+          begin
+            if MainKW>0 then
+              exit;
+            if SubKW>0 then
+              exit;
+            MainKW:=KW;
+          end;
+        kwStart,kwEnd,
+        kwFlexStart,kwFlexEnd,
+        kwSelfStart,kwSelfEnd,
+        kwCenter,kwLeft,kwRight,
+        kwStretch,
+        kwAnchorCenter:
+          begin
+            if MainKW>0 then
+              exit;
+            if (SubKW>0) and not (SubKW in [kwSafe,kwUnsafe]) then
+              exit;
+            MainKW:=KW;
+          end;
+        kwSafe,kwUnsafe:
+          begin
+            if (MainKW>0) and not (MainKW in [kwStart, kwEnd, kwFlexStart, kwFlexEnd,
+                kwSelfStart, kwSelfEnd, kwCenter, kwLeft, kwRight]) then
+              exit;
+            if SubKW>0 then
+              exit;
+            SubKW:=KW;
+          end;
+        kwFirst,kwLast:
+          begin
+            if (MainKW>0) and (MainKW<>kwBaseline) then
+              exit;
+            if SubKW>0 then
+              exit;
+            SubKW:=KW;
+          end;
+        kwBaseline:
+          begin
+            if MainKW>0 then
+              exit;
+            if (SubKW>0) and not (SubKW in [kwFirst,kwLast]) then
+              exit;
+            MainKW:=KW;
+          end;
+        else
+          exit;
+        end;
+      end;
+    rvkFunction:
+      if Resolver.CurComp.FunctionID=afVar then
+        exit(Check)
+      else
+        exit;
+    end;
+  until not Resolver.ReadNext;
+  Result:=true;
+end;
+
+function TFresnelCSSRegistry.ReadJustifyItems(Resolver: TCSSBaseResolver; Check: boolean; out
+  MainKW, SubKW: TCSSNumericalID): boolean;
+var
+  KW: TCSSNumericalID;
+begin
+  Result:=false;
+  MainKW:=0;
+  SubKW:=0;
+  repeat
+    case Resolver.CurComp.Kind of
+    rvkKeyword:
+      begin
+        KW:=Resolver.CurComp.KeywordID;
+        case KW of
+        kwNormal,kwStretch:
           begin
             if MainKW>0 then
               exit;
@@ -2471,8 +2557,30 @@ begin
               exit;
             MainKW:=KW;
           end;
+        kwStart,kwEnd,
+        kwFlexStart,kwFlexEnd,
+        kwSelfStart,kwSelfEnd,
+        kwCenter,kwLeft,kwRight,
+        kwAnchorCenter:
+          begin
+            if MainKW>0 then
+              exit;
+            if (SubKW>0) and not (SubKW in [kwSafe,kwUnsafe]) then
+              exit;
+            MainKW:=KW;
+          end;
+        kwSafe,kwUnsafe:
+          begin
+            if (MainKW>0) and not (MainKW in [kwStart, kwEnd, kwFlexStart, kwFlexEnd,
+                kwSelfStart, kwSelfEnd, kwCenter, kwLeft, kwRight]) then
+              exit;
+            if SubKW>0 then
+              exit;
+            SubKW:=KW;
+          end;
         kwFirst,kwLast:
           begin
+            // baseline with optional first or last
             if (MainKW>0) and (MainKW<>kwBaseline) then
               exit;
             if SubKW>0 then
@@ -2483,10 +2591,33 @@ begin
           begin
             if MainKW>0 then
               exit;
-            if (SubKW>0) and (not (SubKW in [kwFirst,kwLast])) then
+            // baseline with optional first or last
+            if (SubKW>0) and not (SubKW in [kwFirst,kwLast]) then
               exit;
             MainKW:=KW;
           end;
+        kwLegacy:
+          begin
+            // legacy followed by left or right
+            MainKW:=KW;
+            if not Resolver.ReadNext then exit;
+            case Resolver.CurComp.Kind of
+            rvkKeyword:
+              begin
+                KW:=Resolver.CurComp.KeywordID;
+                if not (KW in [kwLeft,kwRight]) then
+                  exit;
+                SubKW:=KW;
+              end;
+            rvkFunction:
+              if Resolver.CurComp.FunctionID=afVar then
+                exit(Check)
+              else
+                exit;
+            else
+              exit;
+            end;
+          end
         else
           exit;
         end;
@@ -2496,6 +2627,8 @@ begin
         exit(Check)
       else
         exit;
+    else
+      exit;
     end;
   until not Resolver.ReadNext;
   Result:=true;
@@ -3390,6 +3523,7 @@ begin
   AddKW(kwLarger,'larger'); // e.g. font-size
   AddKW(kwLast,'last'); // e.g. justify-self
   AddKW(kwLeft,'left'); // e.g. clear, float
+  AddKW(kwLegacy,'legacy'); // e.g. justify-items
   AddKW(kwLighter,'lighter'); // e.g. font-weight
   AddKW(kwLocal,'local'); // e.g. background-attachment
   AddKW(kwLTR,'ltr'); // e.g. direction
@@ -3796,6 +3930,10 @@ begin
   AddFresnelLonghand(fcaJustifyContent,false,@CheckJustifyContent,'normal');
   Chk_JustifyContent_KeywordIDs:=[kwStart,kwEnd,kwFlexEnd,kwCenter,kwLeft,kwRight,kwNormal,
     kwSpaceBetween,kwSpaceAround,kwSpaceEvenly,kwStretch,kwSafe,kwUnsafe];
+  AddFresnelLonghand(fcaJustifyItems,false,@CheckJustifyItems,'legacy');
+  Chk_JustifyItems_KeywordIDs:=[kwNormal,kwStart,kwEnd,kwFlexStart,kwFlexEnd,
+    kwSelfStart,kwSelfEnd,kwCenter,kwLeft,kwRight,kwBaseline,kwFirst,kwLast,kwStretch,
+    kwAnchorCenter,kwSafe,kwUnsafe];
   AddFresnelLonghand(fcaJustifySelf,false,@CheckJustifySelf,'auto');
   Chk_JustifySelf_KeywordIDs:=[kwAuto,kwNormal,kwStart,kwEnd,kwFlexStart,kwFlexEnd,
     kwSelfStart,kwSelfEnd,kwCenter,kwLeft,kwRight,kwBaseline,kwFirst,kwLast,kwStretch,