Переглянути джерело

fixed switch horz scrollbar off

mattias 3 тижнів тому
батько
коміт
b00ea951ab

+ 3 - 3
src/base/fresnel.dom.pas

@@ -1058,9 +1058,9 @@ type
   end;
 
   TFresnelLayoutMode = (
-    flmMinWidth,
-    flmMinHeight,
-    flmMax
+    flmMinWidth, // compute for minimal width, the height is irrelevant
+    flmMinHeight, // compute for minimal height, the width is irrelevant
+    flmMax // normal layout using MaxWidth, MaxHeight
     );
   TFresnelLayoutModes = set of TFresnelLayoutMode;
 

+ 4 - 4
src/base/fresnel.renderer.pas

@@ -927,7 +927,7 @@ begin
       r.Bottom:=Max(r.Top,r.Bottom-BarHeight);
 
     if r.IsEmpty then
-      VertScrollbar.Free
+      FreeAndNil(VertScrollbar)
     else begin
       if VertScrollbar=nil then
         VertScrollbar:=CreateScrollBar(El,false);
@@ -942,7 +942,7 @@ begin
       {$ENDIF}
     end;
   end else if VertScrollbar<>nil then
-    VertScrollbar.Free;
+    FreeAndNil(VertScrollbar);
 
   HorzScrollbar:=TRendererScrollBar(El.ScrollBarHorizontal);
   if HasHorzBar then
@@ -958,7 +958,7 @@ begin
     end;
 
     if r.IsEmpty then
-      HorzScrollbar.Free
+      FreeAndNil(HorzScrollbar)
     else begin
       if HorzScrollbar=nil then
         HorzScrollbar:=CreateScrollBar(El,true);
@@ -975,7 +975,7 @@ begin
       {$ENDIF}
     end;
   end else if HorzScrollbar<>nil then
-    HorzScrollbar.Free;
+    FreeAndNil(HorzScrollbar);
 
   if HasVertBar or HasHorzBar then
   begin

+ 68 - 0
tests/base/TCFlowLayout.pas

@@ -25,6 +25,7 @@ type
 
     // scroll
     procedure TestFL_PositionAbsolute_Left_ScrollWidth;
+    procedure TestFL_Viewport_PositionAbsolute;
     procedure TestFL_OverflowSizeNested;
     // todo procedure TestPositionAbsolute_DivTop100Percent;
 
@@ -586,6 +587,73 @@ begin
   AssertEquals('Body.ScrollHeight',34,Body.ScrollHeight);
 end;
 
+procedure TTestFlowLayout.TestFL_Viewport_PositionAbsolute;
+var
+  Div1: TDiv;
+  VPWidth, VPHeight: TFresnelLength;
+begin
+  Div1:=TDiv.Create(Viewport);
+  Div1.Name:='Div1';
+  Div1.Parent:=Viewport;
+
+  Viewport.Stylesheet.Text:=LinesToStr([
+    'div {',
+    '  margin: 2px;',
+    '  border: 1px;',
+    '  padding: 7px;',
+    '}',
+    '#Div1 {',
+    '  width: 50px;',
+    '  height: 50px;',
+    '  position: absolute;',
+    '}']);
+
+  VPWidth:=Viewport.Width;
+  VPHeight:=Viewport.Height;
+
+  // check default: div1 fits into viewport
+  Viewport.Draw;
+  AssertEquals('Viewport.GetComputedString(fcaOverflowX)','auto',Viewport.GetComputedString(fcaOverflowX));
+  AssertEquals('Viewport.GetComputedString(fcaOverflowY)','auto',Viewport.GetComputedString(fcaOverflowY));
+  AssertEquals('Viewport.GetComputedString(fcaOverflow)','auto',Viewport.GetComputedString(fcaOverflow));
+  AssertEquals('Default Viewport.Width',VPWidth,Viewport.Width);
+  AssertEquals('Default Viewport.Height',VPHeight,Viewport.Height);
+  AssertEquals('Default Viewport.ScrollWidth',VPWidth,Viewport.ScrollWidth);
+  AssertEquals('Default Viewport.ScrollHeight',VPHeight,Viewport.ScrollHeight);
+
+  // check Div1 outside right
+  Div1.Style:='left: '+FloatToCSSPx(VPWidth);
+  Viewport.Draw;
+  AssertEquals('Right Viewport.Width',VPWidth,Viewport.Width);
+  AssertEquals('Right Viewport.Height',VPHeight,Viewport.Height);
+  AssertEquals('Right Viewport.ScrollWidth',VPWidth+70,Viewport.ScrollWidth);
+  AssertEquals('Right Viewport.ScrollHeight',VPHeight,Viewport.ScrollHeight);
+
+  // check Div1 outside bottom
+  Div1.Style:='top: '+FloatToCSSPx(VPHeight);
+  Viewport.Draw;
+  AssertEquals('Bottom Viewport.Width',VPWidth,Viewport.Width);
+  AssertEquals('Bottom Viewport.Height',VPHeight,Viewport.Height);
+  AssertEquals('Bottom Viewport.ScrollWidth',VPWidth,Viewport.ScrollWidth);
+  AssertEquals('Bottom Viewport.ScrollHeight',VPHeight+70,Viewport.ScrollHeight);
+
+  // check Div1 outside left
+  Div1.Style:='left: -50px;';
+  Viewport.Draw;
+  AssertEquals('Left Viewport.Width',VPWidth,Viewport.Width);
+  AssertEquals('Leftt Viewport.Height',VPHeight,Viewport.Height);
+  AssertEquals('Left Viewport.ScrollWidth',VPWidth,Viewport.ScrollWidth);
+  AssertEquals('Left Viewport.ScrollHeight',VPHeight,Viewport.ScrollHeight);
+
+  // check Div1 outside top
+  Div1.Style:='top: -50px;';
+  Viewport.Draw;
+  AssertEquals('Left Viewport.Width',VPWidth,Viewport.Width);
+  AssertEquals('Leftt Viewport.Height',VPHeight,Viewport.Height);
+  AssertEquals('Left Viewport.ScrollWidth',VPWidth,Viewport.ScrollWidth);
+  AssertEquals('Left Viewport.ScrollHeight',VPHeight,Viewport.ScrollHeight);
+end;
+
 procedure TTestFlowLayout.TestFL_OverflowSizeNested;
 var
   Div1, Div2, Div3, Div4: TDiv;