unit uCEFScrollView;
{$IFDEF FPC}
{$MODE OBJFPC}{$H+}
{$ENDIF}
{$I cef.inc}
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
{$MINENUMSIZE 4}
interface
uses
{$IFDEF DELPHI16_UP}
System.Classes, System.SysUtils,
{$ELSE}
Classes, SysUtils,
{$ENDIF}
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes, uCEFView;
type
///
/// A ScrollView will show horizontal and/or vertical scrollbars when necessary
/// based on the size of the attached content view. Methods must be called on
/// the browser process UI thread unless otherwise indicated.
///
///
/// CEF source file: /include/capi/views/cef_scroll_view_capi.h (cef_scroll_view_t)
///
TCefScrollViewRef = class(TCefViewRef, ICefScrollView)
protected
///
/// Set the content View. The content View must have a specified size (e.g.
/// via ICefView.SetBounds or ICefViewDelegate.GetPreferredSize).
///
procedure SetContentView(const view: ICefView);
///
/// Returns the content View.
///
function GetContentView : ICefView;
///
/// Returns the visible region of the content View.
///
function GetVisibleContentRect : TCefRect;
///
/// Returns true (1) if the horizontal scrollbar is currently showing.
///
function HasHorizontalScrollbar : boolean;
///
/// Returns the height of the horizontal scrollbar.
///
function GetHorizontalScrollbarHeight : Integer;
///
/// Returns true (1) if the vertical scrollbar is currently showing.
///
function HasVerticalScrollbar : boolean;
///
/// Returns the width of the vertical scrollbar.
///
function GetVerticalScrollbarWidth : Integer;
public
///
/// Returns a ICefScrollView instance using a PCefScrollView data pointer.
///
class function UnWrap(data: Pointer): ICefScrollView;
///
/// Create a new ScrollView.
///
class function CreateScrollView(const delegate: ICefViewDelegate): ICefScrollView;
end;
implementation
uses
uCEFLibFunctions, uCEFMiscFunctions;
procedure TCefScrollViewRef.SetContentView(const view: ICefView);
begin
PCefScrollView(FData)^.set_content_view(PCefScrollView(FData),
CefGetData(view));
end;
function TCefScrollViewRef.GetContentView : ICefView;
begin
Result := TCefViewRef.UnWrap(PCefScrollView(FData)^.get_content_view(PCefScrollView(FData)));
end;
function TCefScrollViewRef.GetVisibleContentRect : TCefRect;
begin
Result := PCefScrollView(FData)^.get_visible_content_rect(PCefScrollView(FData));
end;
function TCefScrollViewRef.HasHorizontalScrollbar : boolean;
begin
Result := (PCefScrollView(FData)^.has_horizontal_scrollbar(PCefScrollView(FData)) <> 0);
end;
function TCefScrollViewRef.GetHorizontalScrollbarHeight : Integer;
begin
Result := PCefScrollView(FData)^.get_horizontal_scrollbar_height(PCefScrollView(FData));
end;
function TCefScrollViewRef.HasVerticalScrollbar : boolean;
begin
Result := (PCefScrollView(FData)^.has_vertical_scrollbar(PCefScrollView(FData)) <> 0);
end;
function TCefScrollViewRef.GetVerticalScrollbarWidth : Integer;
begin
Result := PCefScrollView(FData)^.get_vertical_scrollbar_width(PCefScrollView(FData));
end;
class function TCefScrollViewRef.UnWrap(data: Pointer): ICefScrollView;
begin
if (data <> nil) then
Result := Create(data) as ICefScrollView
else
Result := nil;
end;
class function TCefScrollViewRef.CreateScrollView(const delegate: ICefViewDelegate): ICefScrollView;
var
TempScrollView : PCefScrollView;
begin
Result := nil;
if (delegate <> nil) then
begin
TempScrollView := cef_scroll_view_create(CefGetData(delegate));
if (TempScrollView <> nil) then
Result := Create(TempScrollView) as ICefScrollView;
end;
end;
end.