Browse Source

fcl-css: added GetCSSPath

mattias 2 years ago
parent
commit
de586e55c0
1 changed files with 19 additions and 0 deletions
  1. 19 0
      packages/fcl-css/src/fpcsstree.pp

+ 19 - 0
packages/fcl-css/src/fpcsstree.pp

@@ -364,6 +364,8 @@ Function StringToCSSString(const S : UTF8String) : UTF8String;
 // Escapes non-identifier characters C to \C
 // Escapes non-identifier characters C to \C
 Function StringToIdentifier(const S : UTF8String) : UTF8String;
 Function StringToIdentifier(const S : UTF8String) : UTF8String;
 
 
+Function GetCSSPath(El: TCSSElement): string;
+
 Const
 Const
   CSSUnitNames : Array[TCSSUnits] of string =
   CSSUnitNames : Array[TCSSUnits] of string =
         ('','px','%','rem','em','pt','fr','vw','vh','deg');
         ('','px','%','rem','em','pt','fr','vw','vh','deg');
@@ -480,6 +482,23 @@ begin
   SetLength(Result,iOut);
   SetLength(Result,iOut);
 end;
 end;
 
 
+function GetCSSPath(El: TCSSElement): string;
+begin
+  if El=nil then
+    exit('nil');
+  Result:='';
+  while El<>nil do
+    begin
+    if Result<>'' then
+      Result:='.'+Result;
+    if El is TCSSIdentifierElement then
+      Result:=TCSSIdentifierElement(El).Name+Result
+    else
+      Result:=El.ClassName+Result;
+    El:=El.Parent;
+    end;
+end;
+
 { TCSSListElement }
 { TCSSListElement }
 
 
 function TCSSListElement.GetAsString(aFormat: Boolean; const aIndent: String): UTF8String;
 function TCSSListElement.GetAsString(aFormat: Boolean; const aIndent: String): UTF8String;