Browse Source

layouter: when border-style is none, use border-width 0

mattias 1 year ago
parent
commit
3b494c5d4d
2 changed files with 43 additions and 22 deletions
  1. 30 9
      src/base/fresnel.dom.pas
  2. 13 13
      src/base/fresnel.layouter.pas

+ 30 - 9
src/base/fresnel.dom.pas

@@ -44,6 +44,9 @@ const
 
 type
   // CSS attributes of the TFresnelElement class
+  // Important:
+  //  for Left,Top,Right,Border attributes use the order defined in TFresnelCSSSide
+  //  for TopLeft,TopRight,BottomLeft,BottomRight attributes use the order defined in TFresnelCSSCorner
   TFresnelCSSAttribute = (
     fcaDisplay,
     fcaDisplayBox,
@@ -533,10 +536,12 @@ type
     // CSS classes and inline style
     property StyleElements: TCSSElement read FStyleElements write SetStyleElements;
     // CSS attributes
+    property CSSAttribute[Attr: TFresnelCSSAttribute]: string read GetCSSElAttribute write SetCSSElAttribute;
+    // CSS computed attributes (values used by layouter to compute the rendered attributes)
     function GetComputedCSSLength(Attr: TFresnelCSSAttribute; UseInherited: boolean; UseNaNOnFail: boolean = false): TFresnelLength; virtual; // on fail returns NaN
-    function GetComputedCSString(Attr: TFresnelCSSAttribute; UseInherited: boolean): string; virtual;
+    function GetComputedCSSString(Attr: TFresnelCSSAttribute; UseInherited: boolean): string; virtual;
+    function GetComputedCSSBorderWidth(Attr: TFresnelCSSAttribute): TFresnelLength; virtual;
     procedure WriteComputedAttributes(Title: string);
-    property CSSAttribute[Attr: TFresnelCSSAttribute]: string read GetCSSElAttribute write SetCSSElAttribute;
     property CSSComputedAttribute[Attr: TFresnelCSSAttribute]: string read GetCSSElComputedAttribute write SetCSSElComputedAttribute;
     class property FresnelElementBaseAttrID: TCSSNumericalID read FFresnelElementBaseAttrID;
     // CSS pseudo classes
@@ -1269,7 +1274,10 @@ var
       El.ComputeCSSInit;
     end;
     Layouter.ComputeCSS(El);
+    if El.GetComputedCSSString(fcaDisplayBox,false)='none' then
+      exit;
     El.ComputeCSSAfterLayoutNode(Layouter);
+    El.WriteComputedAttributes('TFresnelViewport.ApplyCSS');
     for i:=0 to El.NodeCount-1 do
       Traverse(El.Nodes[i]);
     Layouter.ComputedChildrenCSS(El);
@@ -3052,7 +3060,7 @@ begin
     Result:=0;
 end;
 
-function TFresnelElement.GetComputedCSString(Attr: TFresnelCSSAttribute;
+function TFresnelElement.GetComputedCSSString(Attr: TFresnelCSSAttribute;
   UseInherited: boolean): string;
 var
   El: TFresnelElement;
@@ -3073,6 +3081,19 @@ begin
   Result:=GetCSSInitialAttribute(ElementAttrToAttrId(Attr));
 end;
 
+function TFresnelElement.GetComputedCSSBorderWidth(Attr: TFresnelCSSAttribute
+  ): TFresnelLength;
+var
+  StyleAttr: TFresnelCSSAttribute;
+  aStyle: String;
+begin
+  StyleAttr:=TFresnelCSSAttribute(ord(fcaBorderLeftStyle)+ord(Attr)-ord(fcaBorderLeftWidth));
+  aStyle:=GetComputedCSSString(StyleAttr,false);
+  if (aStyle='') or (aStyle='none') then
+    exit(0.0);
+  Result:=GetComputedCSSLength(Attr,false);
+end;
+
 procedure TFresnelElement.WriteComputedAttributes(Title: string);
 var
   Attr: TFresnelCSSAttribute;
@@ -3351,11 +3372,11 @@ begin
   if FFontDescValid then
     exit(FFont);
   FFontDescValid:=true;
-  FFontDesc.Family:=GetComputedCSString(fcaFontFamily,true);
-  FFontDesc.Style:=GetComputedCSString(fcaFontStyle,true);
-  FFontDesc.Variant_:=GetComputedCSString(fcaFontVariant,true);
-  FFontDesc.Weight:=GetComputedCSString(fcaFontWeight,true);
-  s:=GetComputedCSString(fcaFontSize,true);
+  FFontDesc.Family:=GetComputedCSSString(fcaFontFamily,true);
+  FFontDesc.Style:=GetComputedCSSString(fcaFontStyle,true);
+  FFontDesc.Variant_:=GetComputedCSSString(fcaFontVariant,true);
+  FFontDesc.Weight:=GetComputedCSSString(fcaFontWeight,true);
+  s:=GetComputedCSSString(fcaFontSize,true);
   case s of
   'xx-small': FFontDesc.Size:=6;
   'x-small': FFontDesc.Size:=7;
@@ -3370,7 +3391,7 @@ begin
     if not CSSStrToFloat(s,FFontDesc.Size) then
       FFontDesc.Size:=10;
   end;
-  FFontDesc.Kerning:=GetComputedCSString(fcaFontKerning,true);
+  FFontDesc.Kerning:=GetComputedCSSString(fcaFontKerning,true);
   if FFont<>nil then
   begin
     if (FFont.GetFamily=FFontDesc.Family)

+ 13 - 13
src/base/fresnel.layouter.pas

@@ -400,10 +400,10 @@ begin
   ChildMarginTop:=ChildEl.GetComputedCSSLength(fcaMarginTop,false);
   ChildMarginBottom:=ChildEl.GetComputedCSSLength(fcaMarginBottom,false);
 
-  ChildBorderLeft:=ChildEl.GetComputedCSSLength(fcaBorderLeftWidth,false);
-  ChildBorderRight:=ChildEl.GetComputedCSSLength(fcaBorderRightWidth,false);
-  ChildBorderTop:=ChildEl.GetComputedCSSLength(fcaBorderTopWidth,false);
-  ChildBorderBottom:=ChildEl.GetComputedCSSLength(fcaBorderBottomWidth,false);
+  ChildBorderLeft:=ChildEl.GetComputedCSSBorderWidth(fcaBorderLeftWidth);
+  ChildBorderRight:=ChildEl.GetComputedCSSBorderWidth(fcaBorderRightWidth);
+  ChildBorderTop:=ChildEl.GetComputedCSSBorderWidth(fcaBorderTopWidth);
+  ChildBorderBottom:=ChildEl.GetComputedCSSBorderWidth(fcaBorderBottomWidth);
 
   ChildPaddingLeft:=ChildEl.GetComputedCSSLength(fcaPaddingLeft,false);
   ChildPaddingRight:=ChildEl.GetComputedCSSLength(fcaPaddingRight,false);
@@ -551,7 +551,7 @@ procedure TFLBlockFormattingContext.Apply;
 var
   MaxContentWidth: TFresnelLength;
 begin
-  Node.Element.WriteComputedAttributes('TFLBlockFormattingContext.Apply');
+  //Node.Element.WriteComputedAttributes('TFLBlockFormattingContext.Apply');
 
   MaxContentWidth:=Node.Element.GetComputedCSSLength(fcaWidth,false);
   ComputeLayoutBorderBox(MaxContentWidth,true);
@@ -564,10 +564,10 @@ begin
   inherited ComputedChildrenCSS;
   El:=Node.Element;
 
-  FBorderLeft:=El.GetComputedCSSLength(fcaBorderLeftWidth,false);
-  FBorderTop:=El.GetComputedCSSLength(fcaBorderTopWidth,false);
-  FBorderRight:=El.GetComputedCSSLength(fcaBorderRightWidth,false);
-  FBorderBottom:=El.GetComputedCSSLength(fcaBorderBottomWidth,false);
+  FBorderLeft:=El.GetComputedCSSBorderWidth(fcaBorderLeftWidth);
+  FBorderTop:=El.GetComputedCSSBorderWidth(fcaBorderTopWidth);
+  FBorderRight:=El.GetComputedCSSBorderWidth(fcaBorderRightWidth);
+  FBorderBottom:=El.GetComputedCSSBorderWidth(fcaBorderBottomWidth);
   FPaddingLeft:=El.GetComputedCSSLength(fcaPaddingLeft,false);
   FPaddingTop:=El.GetComputedCSSLength(fcaPaddingTop,false);
   FPaddingRight:=El.GetComputedCSSLength(fcaPaddingRight,false);
@@ -673,10 +673,10 @@ begin
     ChildMarginTop:=ChildEl.GetComputedCSSLength(fcaMarginTop,false);
     ChildMarginBottom:=ChildEl.GetComputedCSSLength(fcaMarginBottom,false);
 
-    ChildBorderLeft:=ChildEl.GetComputedCSSLength(fcaBorderLeftWidth,false);
-    ChildBorderRight:=ChildEl.GetComputedCSSLength(fcaBorderRightWidth,false);
-    ChildBorderTop:=ChildEl.GetComputedCSSLength(fcaBorderTopWidth,false);
-    ChildBorderBottom:=ChildEl.GetComputedCSSLength(fcaBorderBottomWidth,false);
+    ChildBorderLeft:=ChildEl.GetComputedCSSBorderWidth(fcaBorderLeftWidth);
+    ChildBorderRight:=ChildEl.GetComputedCSSBorderWidth(fcaBorderRightWidth);
+    ChildBorderTop:=ChildEl.GetComputedCSSBorderWidth(fcaBorderTopWidth);
+    ChildBorderBottom:=ChildEl.GetComputedCSSBorderWidth(fcaBorderBottomWidth);
 
     ChildPaddingLeft:=ChildEl.GetComputedCSSLength(fcaPaddingLeft,false);
     ChildPaddingRight:=ChildEl.GetComputedCSSLength(fcaPaddingRight,false);