2020-05-05 18:10:33 +02:00
|
|
|
unit uCEFScrollViewComponent;
|
|
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2020-05-05 18:10:33 +02:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
{$IFDEF MSWINDOWS}WinApi.Windows,{$ENDIF} System.Classes,
|
|
|
|
{$ELSE}
|
|
|
|
{$IFDEF MSWINDOWS}Windows,{$ENDIF} Classes,
|
|
|
|
{$IFDEF FPC}
|
|
|
|
LCLProc, LCLType, LCLIntf, LResources, InterfaceBase,
|
|
|
|
{$ENDIF}
|
|
|
|
{$ENDIF}
|
2022-10-14 16:35:50 +02:00
|
|
|
uCEFTypes, uCEFInterfaces, uCEFConstants, uCEFViewsFrameworkEvents, uCEFViewComponent;
|
2020-05-05 18:10:33 +02:00
|
|
|
|
|
|
|
type
|
2022-10-14 16:35:50 +02:00
|
|
|
{$IFNDEF FPC}{$IFDEF DELPHI16_UP}[ComponentPlatformsAttribute(pfidWindows or pfidOSX or pfidLinux)]{$ENDIF}{$ENDIF}
|
2020-05-05 18:10:33 +02:00
|
|
|
TCEFScrollViewComponent = class(TCEFViewComponent)
|
|
|
|
protected
|
|
|
|
FScrollView : ICefScrollView;
|
|
|
|
|
|
|
|
procedure DestroyView; override;
|
|
|
|
procedure Initialize; override;
|
|
|
|
|
|
|
|
function GetInitialized : boolean; override;
|
|
|
|
function GetAsView : ICefView; override;
|
|
|
|
function GetAsScrollView : ICefScrollView; override;
|
|
|
|
function GetContentView : ICefView;
|
|
|
|
function GetVisibleContentRect : TCefRect;
|
|
|
|
function GetHasHorizontalScrollbar : boolean;
|
|
|
|
function GetHorizontalScrollbarHeight : Integer;
|
|
|
|
function GetHasVerticalScrollbar : boolean;
|
|
|
|
function GetVerticalScrollbarWidth : Integer;
|
|
|
|
|
|
|
|
procedure SetContentView(const view: ICefView);
|
|
|
|
|
|
|
|
// ICefViewDelegateEvents
|
|
|
|
procedure doCreateCustomView; override;
|
|
|
|
|
|
|
|
public
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Create a new ScrollView.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
procedure CreateScrollView;
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Get and set the content View. The content View must have a specified size (e.g.
|
|
|
|
/// via ICefView.SetBounds or ICefViewDelegate.GetPreferredSize).
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
property ContentView : ICefView read GetContentView write SetContentView;
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the visible region of the content View.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
property VisibleContentRect : TCefRect read GetVisibleContentRect;
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the height of the horizontal scrollbar.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
property HorizontalScrollbarHeight : Integer read GetHorizontalScrollbarHeight;
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the width of the vertical scrollbar.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
property VerticalScrollbarWidth : Integer read GetVerticalScrollbarWidth;
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns true (1) if the horizontal scrollbar is currently showing.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
property HasHorizontalScrollbar : boolean read GetHasHorizontalScrollbar;
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns true (1) if the vertical scrollbar is currently showing.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
property HasVerticalScrollbar : boolean read GetHasVerticalScrollbar;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
procedure Register;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
// *********************************************************
|
|
|
|
// ********************** ATTENTION ! **********************
|
|
|
|
// *********************************************************
|
|
|
|
// ** **
|
|
|
|
// ** MANY OF THE EVENTS IN CEF4DELPHI COMPONENTS LIKE **
|
|
|
|
// ** TCHROMIUM, TFMXCHROMIUM OR TCEFAPPLICATION ARE **
|
|
|
|
// ** EXECUTED IN A CEF THREAD BY DEFAULT. **
|
|
|
|
// ** **
|
|
|
|
// ** WINDOWS CONTROLS MUST BE CREATED AND DESTROYED IN **
|
|
|
|
// ** THE SAME THREAD TO AVOID ERRORS. **
|
|
|
|
// ** SOME OF THEM RECREATE THE HANDLERS IF THEY ARE **
|
|
|
|
// ** MODIFIED AND CAN CAUSE THE SAME ERRORS. **
|
|
|
|
// ** **
|
|
|
|
// ** DON'T CREATE, MODIFY OR DESTROY WINDOWS CONTROLS **
|
|
|
|
// ** INSIDE THE CEF4DELPHI EVENTS AND USE **
|
|
|
|
// ** SYNCHRONIZATION OBJECTS TO PROTECT VARIABLES AND **
|
|
|
|
// ** FIELDS IF THEY ARE ALSO USED IN THE MAIN THREAD. **
|
|
|
|
// ** **
|
|
|
|
// ** READ THIS FOR MORE INFORMATION : **
|
|
|
|
// ** https://www.briskbard.com/index.php?pageid=cef **
|
|
|
|
// ** **
|
|
|
|
// ** USE OUR FORUMS FOR MORE QUESTIONS : **
|
|
|
|
// ** https://www.briskbard.com/forum/ **
|
|
|
|
// ** **
|
|
|
|
// *********************************************************
|
|
|
|
// *********************************************************
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFScrollView, uCEFMiscFunctions, uCEFViewDelegate;
|
|
|
|
|
|
|
|
procedure TCEFScrollViewComponent.CreateScrollView;
|
|
|
|
begin
|
|
|
|
CreateView;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFScrollViewComponent.doCreateCustomView;
|
|
|
|
var
|
|
|
|
TempDelegate : ICefViewDelegate;
|
|
|
|
begin
|
|
|
|
if (FScrollView = nil) then
|
|
|
|
try
|
|
|
|
TempDelegate := TCustomViewDelegate.Create(self);
|
|
|
|
FScrollView := TCefScrollViewRef.CreateScrollView(TempDelegate);
|
|
|
|
finally
|
|
|
|
TempDelegate := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFScrollViewComponent.Initialize;
|
|
|
|
begin
|
|
|
|
inherited Initialize;
|
|
|
|
|
|
|
|
FScrollView := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFScrollViewComponent.DestroyView;
|
|
|
|
begin
|
|
|
|
FScrollView := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFScrollViewComponent.GetInitialized : boolean;
|
|
|
|
begin
|
|
|
|
Result := (FScrollView <> nil);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFScrollViewComponent.GetAsView : ICefView;
|
|
|
|
begin
|
|
|
|
Result := FScrollView as ICefView;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFScrollViewComponent.GetAsScrollView : ICefScrollView;
|
|
|
|
begin
|
|
|
|
Result := FScrollView;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFScrollViewComponent.SetContentView(const view: ICefView);
|
|
|
|
begin
|
|
|
|
if Initialized then FScrollView.SetContentView(view);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFScrollViewComponent.GetContentView : ICefView;
|
|
|
|
begin
|
|
|
|
if Initialized then
|
|
|
|
Result := FScrollView.GetContentView
|
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFScrollViewComponent.GetVisibleContentRect : TCefRect;
|
|
|
|
var
|
|
|
|
TempRect : TCefRect;
|
|
|
|
begin
|
|
|
|
if Initialized then
|
|
|
|
TempRect := FScrollView.GetVisibleContentRect
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
TempRect.x := 0;
|
|
|
|
TempRect.y := 0;
|
|
|
|
TempRect.width := 0;
|
|
|
|
TempRect.height := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
Result := TempRect;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFScrollViewComponent.GetHasHorizontalScrollbar : boolean;
|
|
|
|
begin
|
|
|
|
Result := Initialized and FScrollView.HasHorizontalScrollbar;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFScrollViewComponent.GetHorizontalScrollbarHeight : Integer;
|
|
|
|
begin
|
|
|
|
if Initialized then
|
|
|
|
Result := FScrollView.GetHorizontalScrollbarHeight
|
|
|
|
else
|
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFScrollViewComponent.GetHasVerticalScrollbar : boolean;
|
|
|
|
begin
|
|
|
|
Result := Initialized and FScrollView.HasVerticalScrollbar;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFScrollViewComponent.GetVerticalScrollbarWidth : Integer;
|
|
|
|
begin
|
|
|
|
if Initialized then
|
|
|
|
Result := FScrollView.GetVerticalScrollbarWidth
|
|
|
|
else
|
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
procedure Register;
|
|
|
|
begin
|
|
|
|
{$I res/tcefscrollviewcomponent.lrs}
|
|
|
|
RegisterComponents('Chromium Views Framework', [TCEFScrollViewComponent]);
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
end.
|