瀏覽代碼

viewport: scrollbars

mattias 5 月之前
父節點
當前提交
e770402e9c
共有 3 個文件被更改,包括 62 次插入52 次删除
  1. 7 1
      src/base/fresnel.controls.pas
  2. 6 2
      src/base/fresnel.dom.pas
  3. 49 49
      src/base/fresnel.renderer.pas

+ 7 - 1
src/base/fresnel.controls.pas

@@ -250,7 +250,13 @@ end;
 
 class function TBody.GetCSSTypeStyle: TCSSString;
 begin
-  Result:='body { background-color: white; color: black; display: block; position: static; margin: 8px; }';
+  Result:='body {'
+    +' background-color: white;'
+    +' color: black;'
+    +' display: block;'
+    +' position: static;'
+    +' margin: 8px;'
+    +'}';
 end;
 
 

+ 6 - 2
src/base/fresnel.dom.pas

@@ -7022,6 +7022,7 @@ procedure TFresnelViewport.ApplyCSS;
   var
     i: Integer;
   begin
+    //writeln('TraverseLayoutFinished ',El.Name,' Border=',El.UsedBorderBox.ToString,' Content=',El.UsedContentBox.ToString,' Client=',FloatToCSSStr(El.ClientWidth),'x',FloatToCSSStr(El.ClientHeight));
     El.ComputeCSSLayoutFinished;
     if fesPseudoElement in FStates then
       exit;
@@ -7113,9 +7114,12 @@ end;
 class function TFresnelViewport.GetCSSTypeStyle: TCSSString;
 begin
   Result:=':root {'
-    +' display: block flow-root; position: absolute;'
+    +' display: block flow-root;'
+    +' position: absolute;'
     +' font-family: arial; font-size: 12px;'
-    +' color: #000; background-color: #fff;'
+    +' color: #000;'
+    +' background-color: #fff;'
+    +' overflow: auto;'
     +' }';
 end;
 

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

@@ -59,6 +59,7 @@ type
     FSubPixel: boolean;
     FOrigin: TFresnelPoint;
     FTextShadows : TFresnelTextShadowArray;
+    FIntfRenderer: IFresnelRenderer;
   protected
     type
       { TBorderAndBackground }
@@ -115,7 +116,7 @@ type
     //
     // Put methods not part of IFresnelRenderer here
     //
-
+    constructor Create(AOwner: TComponent); override;
     // draw the given viewport.
     procedure Draw(Viewport: TFresnelViewport); virtual;
     // Round coordinates of given rectangle.
@@ -773,6 +774,12 @@ begin
   Result:=S;
 end;
 
+constructor TFresnelRenderer.Create(AOwner: TComponent);
+begin
+  inherited Create(AOwner);
+  FIntfRenderer:=Self;
+end;
+
 function TFresnelRenderer.GetTextShadow(aIndex : Integer): PFresnelTextShadow;
 begin
   Result:=Nil;
@@ -1036,42 +1043,45 @@ begin
 
   //writeln('TFresnelRenderer.DrawElement ',El.Name,' BorderBox=',El.UsedBorderBox.ToString,' ContentBox=',El.UsedContentBox.ToString,' Origin=',Origin.ToString);
 
-  // background and border
-  BorderParams:=CreateBorderAndBackground;
-  try
-    BorderParams.BoundingBox.Box:=aBorderBox;
-    if not SubPixel then
-      MathRoundRect(BorderParams.BoundingBox.Box);
-
-    // border-width
-    BorderParams.Width[ffsLeft]:=LNode.BorderLeft;
-    BorderParams.Width[ffsTop]:=LNode.BorderTop;
-    BorderParams.Width[ffsRight]:=LNode.BorderRight;
-    BorderParams.Width[ffsBottom]:=LNode.BorderBottom;
-
-    // background-color
-    BorderParams.BackgroundColorFP:=El.GetComputedColor(fcaBackgroundColor,colTransparent);
-
-    // border-color
-    for s in TFresnelCSSSide do
-      BorderParams.Color[s]:=El.GetComputedColor(TFresnelCSSAttribute(ord(fcaBorderTopColor)+ord(s)),colTransparent);
-
-    // border-image
-    BorderParams.BackgroundImage:=El.GetComputedImage(fcaBackgroundImage);
-
-    // border-radius
-    for Corner in TFresnelCSSCorner do
-      BorderParams.BoundingBox.Radii[Corner]:=El.GetComputedBorderRadius(Corner);
-    // Normalize
-    if PrepareBackgroundBorder(El,BorderParams) then
-      begin
-      // Background
-      DrawElBackground(El,BorderParams);
-      // Border
-      DrawElBorder(El,BorderParams);
-      end;
-  finally
-    BorderParams.Free;
+  if El<>El.Viewport then
+  begin
+    // background and border
+    BorderParams:=CreateBorderAndBackground;
+    try
+      BorderParams.BoundingBox.Box:=aBorderBox;
+      if not SubPixel then
+        MathRoundRect(BorderParams.BoundingBox.Box);
+
+      // border-width
+      BorderParams.Width[ffsLeft]:=LNode.BorderLeft;
+      BorderParams.Width[ffsTop]:=LNode.BorderTop;
+      BorderParams.Width[ffsRight]:=LNode.BorderRight;
+      BorderParams.Width[ffsBottom]:=LNode.BorderBottom;
+
+      // background-color
+      BorderParams.BackgroundColorFP:=El.GetComputedColor(fcaBackgroundColor,colTransparent);
+
+      // border-color
+      for s in TFresnelCSSSide do
+        BorderParams.Color[s]:=El.GetComputedColor(TFresnelCSSAttribute(ord(fcaBorderTopColor)+ord(s)),colTransparent);
+
+      // border-image
+      BorderParams.BackgroundImage:=El.GetComputedImage(fcaBackgroundImage);
+
+      // border-radius
+      for Corner in TFresnelCSSCorner do
+        BorderParams.BoundingBox.Radii[Corner]:=El.GetComputedBorderRadius(Corner);
+      // Normalize
+      if PrepareBackgroundBorder(El,BorderParams) then
+        begin
+        // Background
+        DrawElBackground(El,BorderParams);
+        // Border
+        DrawElBorder(El,BorderParams);
+        end;
+    finally
+      BorderParams.Free;
+    end;
   end;
 
   NeedRestore:=false;
@@ -1097,7 +1107,7 @@ begin
   end;
   try
     // Give element a chance to draw itself (on top of background and border)
-    aRenderable.Render(Self as IFresnelRenderer);
+    aRenderable.Render(FIntfRenderer);
 
     DrawChildren(El);
 
@@ -1136,22 +1146,12 @@ end;
 procedure TFresnelRenderer.Draw(Viewport: TFresnelViewport);
 var
   BackgroundColorFP: TFPColor;
-  aRenderable: IFresnelRenderable;
 begin
   //debugln(['TFresnelRenderer.Draw Origin=',dbgs(Origin)]);
-  aRenderable:=Viewport as IFresnelRenderable;
-  aRenderable.BeforeRender;
-  Viewport.Rendered:=true;
-
   BackgroundColorFP:=Viewport.GetComputedColor(fcaBackgroundColor,colWhite);
   FillRect(BackgroundColorFP,RectFre(0,0,Viewport.Width,Viewport.Height));
 
-  // todo: draw scrollbars
-
-  aRenderable.Render(Self as IFresnelRenderer);
-  DrawChildren(Viewport);
-
-  aRenderable.AfterRender;
+  DrawElement(Viewport);
 end;
 
 procedure TFresnelRenderer.ClearTextShadows;