Browse Source

fresnel: started scroll properties

mattias 5 months ago
parent
commit
26d4151bdf
2 changed files with 130 additions and 28 deletions
  1. 113 23
      src/base/fresnel.dom.pas
  2. 17 5
      src/base/fresnel.layouter.pas

+ 113 - 23
src/base/fresnel.dom.pas

@@ -1088,19 +1088,25 @@ type
 
     // used values
     ZIndex: TFresnelLength; // position=static has 0, non static have z-index+0.5
+    MarginLeft: TFresnelLength;
+    MarginRight: TFresnelLength;
+    MarginTop: TFresnelLength;
+    MarginBottom: TFresnelLength;
     BorderLeft: TFresnelLength;
     BorderRight: TFresnelLength;
     BorderTop: TFresnelLength;
     BorderBottom: TFresnelLength;
+    ScrollGutterLeft: TFresnelLength;
+    ScrollGutterRight: TFresnelLength;
+    ScrollGutterTop: TFresnelLength;
+    ScrollGutterBottom: TFresnelLength;
     PaddingLeft: TFresnelLength;
     PaddingRight: TFresnelLength;
     PaddingTop: TFresnelLength;
     PaddingBottom: TFresnelLength;
-    MarginLeft: TFresnelLength;
-    MarginRight: TFresnelLength;
-    MarginTop: TFresnelLength;
-    MarginBottom: TFresnelLength;
     LineHeight: TFresnelLength;
+    ScrollBarVerticalVisible: boolean;
+    ScrollBarHorizontalVisible: boolean;
 
     // attributes depending on position:
     //  static: left, top, right, bottom are ignored
@@ -1113,13 +1119,15 @@ type
     Right: TFresnelLength;
     Bottom: TFresnelLength;
 
-    // content-boxed:
+    // content-boxed (independent of box-sizing):
     Width: TFresnelLength;
     Height: TFresnelLength;
     MinWidth: TFresnelLength;
     MinHeight: TFresnelLength;
     MaxWidth: TFresnelLength;
     MaxHeight: TFresnelLength;
+    ScrollWidth: TFresnelLength;
+    ScrollHeight: TFresnelLength;
 
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
@@ -1270,6 +1278,8 @@ type
     FRendered: boolean;
     FRenderedBorderBox: TFresnelRect;
     FRenderedContentBox: TFresnelRect;
+    FScrollLeft: TFresnelLength;
+    FScrollTop: TFresnelLength;
     FStates: TStates;
     // Todo: change to dictionary to reduce mem footprint
     FStandardEvents : Array[0..evtLastEvent] of TEventHandlerItem;
@@ -1280,6 +1290,8 @@ type
     function GetNodes(Index: integer): TFresnelElement;
     function GetPeudoNodeCount: integer;
     function GetPseudoNodes(Index: integer): TPseudoElement;
+    function GetScrollHeight: TFresnelLength;
+    function GetScrollWidth: TFresnelLength;
     function GetViewportConnected: boolean;
     function GetEventHandler(AIndex: Integer): TFresnelEventHandler;
     function GetFocusEventHandler(AIndex: Integer): TFresnelFocusEventHandler;
@@ -1287,6 +1299,8 @@ type
     procedure SetEventHandler(AIndex: Integer; const AValue: TFresnelEventHandler);
     procedure SetFocusEventHandler(AIndex: Integer; AValue: TFresnelFocusEventHandler);
     procedure SetMouseEventHandler(AIndex: Integer; const AValue: TFresnelMouseEventHandler);
+    procedure SetScrollLeft(const AValue: TFresnelLength);
+    procedure SetScrollTop(const AValue: TFresnelLength);
   protected
     FChildren: TFPList; // list of TFresnelElement
     FPseudoChildren: TFPList; // list of TPseudoElement
@@ -1473,6 +1487,11 @@ type
     property Resolver: TCSSResolver read FResolver;
     property ViewportConnected: boolean read GetViewportConnected write SetViewportConnected; // true for example if using a Font of Viewport
     property Viewport: TFresnelViewport read FViewPort;
+    // Scroll
+    property ScrollLeft: TFresnelLength read FScrollLeft write SetScrollLeft;
+    property ScrollTop: TFresnelLength read FScrollTop write SetScrollTop;
+    property ScrollWidth: TFresnelLength read GetScrollWidth;
+    property ScrollHeight: TFresnelLength read GetScrollHeight;
   published
     property CSSClasses: TStrings read FCSSClasses write SetCSSClasses;
     property Style: string read FStyle write SetStyle;
@@ -1533,7 +1552,9 @@ type
     vlDPIHorizontal,
     vlDPIVertical,
     vlHorizontalScrollbarWidth,
-    vlVerticalScrollbarWidth
+    vlVerticalScrollbarWidth,
+    vlHorizontalScrollbarThinWidth,
+    vlVerticalScrollbarThinWidth
     );
   TFresnelViewportLengths = set of TFresnelViewportLength;
 
@@ -1566,7 +1587,9 @@ type
     FStylesheetResolverStamp: TCSSNumericalID;
     FStylesheet: TStrings;
     FDPI: array[boolean] of TFresnelLength;
+    FScrollbarThinWidth: array[boolean] of TFresnelLength;
     FScrollbarWidth: array[boolean] of TFresnelLength;
+    FScrollbarStable: boolean;
     FHeight: TFresnelLength;
     FWidth: TFresnelLength;
     FFocusedElement : TFresnelElement;
@@ -1580,21 +1603,22 @@ type
     procedure Bubble(lElement: TFresnelElement; lEvt: TFresnelEvent);
     function GetDPI(IsHorizontal: boolean): TFresnelLength; override;
     function GetHeight: TFresnelLength; virtual;
-    function GetScrollbarWidth(IsHorizontal: boolean): TFresnelLength; virtual;
+    function GetScrollbarsStable: boolean; virtual;
+    function GetScrollbarsThinWidth(IsHorizontal: boolean): TFresnelLength; virtual;
+    function GetScrollbarsWidth(IsHorizontal: boolean): TFresnelLength; virtual;
     function GetVPLength(l: TFresnelViewportLength): TFresnelLength; virtual;
     function GetWidth: TFresnelLength; virtual;
     procedure FPOObservedChanged(ASender: TObject; {%H-}Operation: TFPObservedOperation; {%H-}Data: Pointer); override;
     procedure InitResolver; virtual;
     procedure UpdateResolverStylesheet; virtual;
-    procedure Notification(AComponent: TComponent; Operation: TOperation);
-      override;
+    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
     procedure SetDPI(IsHorizontal: boolean; const AValue: TFresnelLength);
     procedure SetHeight(AValue: TFresnelLength); virtual;
-    procedure SetScrollbarWidth(IsHorizontal: boolean;
-      const AValue: TFresnelLength); virtual;
+    procedure SetScrollbarsStable(const AValue: boolean); virtual;
+    procedure SetScrollbarsThinWidth(IsHorizontal: boolean; const AValue: TFresnelLength); virtual;
+    procedure SetScrollbarsWidth(IsHorizontal: boolean; const AValue: TFresnelLength); virtual;
     procedure SetStylesheet(AValue: TStrings); virtual;
-    procedure SetVPLength(l: TFresnelViewportLength;
-      const AValue: TFresnelLength); virtual;
+    procedure SetVPLength(l: TFresnelViewportLength; const AValue: TFresnelLength); virtual;
     procedure SetWidth(AValue: TFresnelLength); virtual;
     procedure StylesheetChanged; virtual;
     function TrySetFocusControl(aControl : TFresnelElement) : Boolean;
@@ -1675,7 +1699,9 @@ type
     function WSInput(WSData: TFresnelInputEventInit) : boolean; virtual;
     property VPApplication: IFresnelVPApplication read FVPApplication;
     property DPI[IsHorizontal: boolean]: TFresnelLength read GetDPI write SetDPI;
-    property ScrollbarWidth[IsHorizontal: boolean]: TFresnelLength read GetScrollbarWidth write SetScrollbarWidth;
+    property ScrollbarsStable: boolean read GetScrollbarsStable write SetScrollbarsStable;
+    property ScrollbarsWidth[IsHorizontal: boolean]: TFresnelLength read GetScrollbarsWidth write SetScrollbarsWidth;
+    property ScrollbarsThinWidth[IsHorizontal: boolean]: TFresnelLength read GetScrollbarsThinWidth write SetScrollbarsThinWidth;
     property VPLength[l: TFresnelViewportLength]: TFresnelLength read GetVPLength write SetVPLength;
     property Resolver: TCSSResolver read FResolver;
     property Stylesheet: TStrings read FStylesheet write SetStylesheet; // CSS origin author
@@ -1686,7 +1712,7 @@ type
     property FontEngine: TFresnelFontEngine read FFontEngine write FFontEngine;
     property OnDomChanged: TNotifyEvent read FOnDomChanged write FOnDomChanged;
     property DomModified: boolean read FDomModified write FDomModified;
-    Property FocusedElement : TFresnelElement read FFocusedElement Write SetFocusedElement;
+    property FocusedElement : TFresnelElement read FFocusedElement Write SetFocusedElement;
   end;
   TFLViewPort = TFresnelViewport;
 
@@ -6423,19 +6449,25 @@ end;
 
 procedure TFresnelLayoutNode.ResetUsedLengths;
 begin
+  MarginLeft:=0;
+  MarginRight:=0;
+  MarginTop:=0;
+  MarginBottom:=0;
   BorderLeft:=0;
   BorderRight:=0;
   BorderTop:=0;
   BorderBottom:=0;
+  ScrollGutterLeft:=0;
+  ScrollGutterRight:=0;
+  ScrollGutterTop:=0;
+  ScrollGutterBottom:=0;
   PaddingLeft:=0;
   PaddingRight:=0;
   PaddingTop:=0;
   PaddingBottom:=0;
-  MarginLeft:=0;
-  MarginRight:=0;
-  MarginTop:=0;
-  MarginBottom:=0;
   LineHeight:=0;
+  ScrollBarVerticalVisible:=false;
+  ScrollBarHorizontalVisible:=false;
 
   Left:=NaN;
   Top:=NaN;
@@ -6531,17 +6563,27 @@ begin
   Result:=FDPI[IsHorizontal];
 end;
 
-function TFresnelViewport.GetScrollbarWidth(IsHorizontal: boolean
+function TFresnelViewport.GetScrollbarsWidth(IsHorizontal: boolean
   ): TFresnelLength;
 begin
   Result:=FScrollbarWidth[IsHorizontal];
 end;
 
+function TFresnelViewport.GetScrollbarsThinWidth(IsHorizontal: boolean): TFresnelLength;
+begin
+  Result:=FScrollbarThinWidth[IsHorizontal];
+end;
+
 function TFresnelViewport.GetHeight: TFresnelLength;
 begin
   Result:=FHeight;
 end;
 
+function TFresnelViewport.GetScrollbarsStable: boolean;
+begin
+  Result:=FScrollbarStable;
+end;
+
 function TFresnelViewport.GetVPLength(l: TFresnelViewportLength
   ): TFresnelLength;
 begin
@@ -6551,6 +6593,8 @@ begin
     vlDPIVertical: Result:=FDPI[false];
     vlHorizontalScrollbarWidth: Result:=FScrollbarWidth[true];
     vlVerticalScrollbarWidth: Result:=FScrollbarWidth[false];
+    vlHorizontalScrollbarThinWidth: Result:=FScrollbarThinWidth[true];
+    vlVerticalScrollbarThinWidth: Result:=FScrollbarThinWidth[false];
   end;
 end;
 
@@ -6707,11 +6751,27 @@ begin
   DomChanged;
 end;
 
-procedure TFresnelViewport.SetScrollbarWidth(IsHorizontal: boolean;
+procedure TFresnelViewport.SetScrollbarsStable(const AValue: boolean);
+begin
+  if FScrollbarStable=AValue then exit;
+  FScrollbarStable:=AValue;
+  DomChanged;
+end;
+
+procedure TFresnelViewport.SetScrollbarsWidth(IsHorizontal: boolean;
   const AValue: TFresnelLength);
 begin
   if FScrollbarWidth[IsHorizontal]=AValue then exit;
   FScrollbarWidth[IsHorizontal]:=AValue;
+  DomChanged;
+end;
+
+procedure TFresnelViewport.SetScrollbarsThinWidth(IsHorizontal: boolean; const AValue: TFresnelLength
+  );
+begin
+  if FScrollbarThinWidth[IsHorizontal]=AValue then exit;
+  FScrollbarThinWidth[IsHorizontal]:=AValue;
+  DomChanged;
 end;
 
 procedure TFresnelViewport.SetStylesheet(AValue: TStrings);
@@ -6729,8 +6789,10 @@ begin
   case l of
     vlDPIHorizontal: DPI[true]:=AValue;
     vlDPIVertical: DPI[false]:=AValue;
-    vlHorizontalScrollbarWidth: ScrollbarWidth[true]:=AValue;
-    vlVerticalScrollbarWidth: ScrollbarWidth[false]:=AValue;
+    vlHorizontalScrollbarWidth: ScrollbarsWidth[true]:=AValue;
+    vlVerticalScrollbarWidth: ScrollbarsWidth[false]:=AValue;
+    vlHorizontalScrollbarThinWidth: ScrollbarsThinWidth[true]:=AValue;
+    vlVerticalScrollbarThinWidth: ScrollbarsThinWidth[false]:=AValue;
   end;
 end;
 
@@ -7369,6 +7431,18 @@ begin
     SetEventHandler(AIndex,TFresnelEventHandler(AValue));
 end;
 
+procedure TFresnelElement.SetScrollLeft(const AValue: TFresnelLength);
+begin
+  if FScrollLeft=AValue then Exit;
+  FScrollLeft:=AValue;
+end;
+
+procedure TFresnelElement.SetScrollTop(const AValue: TFresnelLength);
+begin
+  if FScrollTop=AValue then Exit;
+  FScrollTop:=AValue;
+end;
+
 procedure TFresnelElement.SetViewportConnected(AValue: boolean);
 var
   i: Integer;
@@ -7422,6 +7496,22 @@ begin
   Result:=TPseudoElement(FPseudoChildren[Index]);
 end;
 
+function TFresnelElement.GetScrollHeight: TFresnelLength;
+begin
+  if LayoutNode=nil then
+    Result:=0
+  else
+    Result:=LayoutNode.ScrollHeight;
+end;
+
+function TFresnelElement.GetScrollWidth: TFresnelLength;
+begin
+  if LayoutNode=nil then
+    Result:=0
+  else
+    Result:=LayoutNode.ScrollWidth;
+end;
+
 procedure TFresnelElement.SetParent(const AValue: TFresnelElement);
 begin
   if FParent=AValue then Exit;

+ 17 - 5
src/base/fresnel.layouter.pas

@@ -466,6 +466,11 @@ procedure TUsedLayoutNode.ComputeUsedLengths(NoChildren: boolean);
   end;
 
 begin
+  MarginLeft:=ComputeLength(fcaMarginLeft);
+  MarginTop:=ComputeLength(fcaMarginTop);
+  MarginRight:=ComputeLength(fcaMarginRight);
+  MarginBottom:=ComputeLength(fcaMarginBottom);
+
   BorderLeft:=ComputeLength(fcaBorderLeftWidth);
   BorderTop:=ComputeLength(fcaBorderTopWidth);
   BorderRight:=ComputeLength(fcaBorderRightWidth);
@@ -476,16 +481,18 @@ begin
   PaddingRight:=ComputeLength(fcaPaddingRight);
   PaddingBottom:=ComputeLength(fcaPaddingBottom);
 
-  MarginLeft:=ComputeLength(fcaMarginLeft);
-  MarginTop:=ComputeLength(fcaMarginTop);
-  MarginRight:=ComputeLength(fcaMarginRight);
-  MarginBottom:=ComputeLength(fcaMarginBottom);
-
   Left:=ComputeDistance(fcaLeft);
   Top:=ComputeDistance(fcaTop);
   Right:=ComputeDistance(fcaRight);
   Bottom:=ComputeDistance(fcaBottom);
 
+  if NoChildren then begin
+    if Element.ComputedOverflowX=CSSRegistry.kwScroll then
+      ScrollBarHorizontalVisible:=true;
+    if Element.ComputedOverflowY=CSSRegistry.kwScroll then
+      ScrollBarVerticalVisible:=true;
+  end;
+
   // compute width and height after border and padding
   MinWidth:=GetContentSize(fcaMinWidth,true);
   if IsNan(MinWidth) then MinWidth:=0;
@@ -498,6 +505,11 @@ begin
 
   DeductUsedLengths(NoChildren);
 
+  if Element.ComputedOverflowX=CSSRegistry.kwAuto then
+  begin
+
+  end;
+
   {$IFDEF VerboseFresnelPlacing}
   writeln('TUsedLayoutNode.ComputeUsedLengths ',Element.GetPath,' NoChildren=',NoChildren,' Width=',FloatToCSSStr(Width),' Height=',FloatToCSSStr(Height),' MinWidth=',FloatToCSSStr(MinWidth),' MaxWidth=',FloatToCSSStr(MaxWidth));
   {$ENDIF}