2019-05-19 16:08:15 +02:00
|
|
|
|
// ************************************************************************
|
2018-06-17 14:18:11 +02:00
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
//
|
2019-10-19 10:58:34 +02:00
|
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
|
2018-06-17 14:18:11 +02:00
|
|
|
|
// browser in Delphi applications.
|
|
|
|
|
//
|
|
|
|
|
// The original license of DCEF3 still applies to CEF4Delphi.
|
|
|
|
|
//
|
|
|
|
|
// For more information about CEF4Delphi visit :
|
|
|
|
|
// https://www.briskbard.com/index.php?lang=en&pageid=cef
|
|
|
|
|
//
|
2020-01-01 12:48:10 +01:00
|
|
|
|
// Copyright <20> 2020 Salvador Diaz Fau. All rights reserved.
|
2018-06-17 14:18:11 +02:00
|
|
|
|
//
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ************ vvvv Original license and comments below vvvv *************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
(*
|
|
|
|
|
* Delphi Chromium Embedded 3
|
|
|
|
|
*
|
|
|
|
|
* Usage allowed under the restrictions of the Lesser GNU General Public License
|
|
|
|
|
* or alternatively the restrictions of the Mozilla Public License 1.1
|
|
|
|
|
*
|
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
|
|
|
|
* the specific language governing rights and limitations under the License.
|
|
|
|
|
*
|
|
|
|
|
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
|
|
|
|
|
* Web site : http://www.progdigy.com
|
|
|
|
|
* Repository : http://code.google.com/p/delphichromiumembedded/
|
|
|
|
|
* Group : http://groups.google.com/group/delphichromiumembedded
|
|
|
|
|
*
|
|
|
|
|
* Embarcadero Technologies, Inc is not permitted to use or redistribute
|
|
|
|
|
* this source code without explicit permission.
|
|
|
|
|
*
|
|
|
|
|
*)
|
|
|
|
|
|
|
|
|
|
unit usimplelazosrbrowser;
|
|
|
|
|
|
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
2019-10-14 15:39:27 +02:00
|
|
|
|
Windows, LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes,
|
|
|
|
|
SyncObjs, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Types,
|
|
|
|
|
uCEFChromium, uCEFTypes, uCEFInterfaces, uCEFConstants, uCEFBufferPanel,
|
|
|
|
|
uCEFChromiumEvents, uCEFSentinel;
|
2018-06-17 14:18:11 +02:00
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
|
|
{ TForm1 }
|
|
|
|
|
|
|
|
|
|
TForm1 = class(TForm)
|
|
|
|
|
NavControlPnl: TPanel;
|
|
|
|
|
chrmosr: TChromium;
|
|
|
|
|
ComboBox1: TComboBox;
|
|
|
|
|
Panel2: TPanel;
|
|
|
|
|
GoBtn: TButton;
|
|
|
|
|
SnapshotBtn: TButton;
|
|
|
|
|
SaveDialog1: TSaveDialog;
|
|
|
|
|
Timer1: TTimer;
|
|
|
|
|
Panel1: TBufferPanel;
|
|
|
|
|
|
|
|
|
|
procedure GoBtnClick(Sender: TObject);
|
|
|
|
|
procedure GoBtnEnter(Sender: TObject);
|
|
|
|
|
|
|
|
|
|
procedure Panel1Enter(Sender: TObject);
|
|
|
|
|
procedure Panel1Exit(Sender: TObject);
|
2019-01-08 19:15:25 +01:00
|
|
|
|
procedure Panel1IMECancelComposition(Sender: TObject);
|
|
|
|
|
procedure Panel1IMECommitText(Sender: TObject; const aText: ustring; const replacement_range: PCefRange; relative_cursor_pos: integer);
|
|
|
|
|
procedure Panel1IMESetComposition(Sender: TObject; const aText: ustring; const underlines: TCefCompositionUnderlineDynArray; const replacement_range, selection_range: TCefRange);
|
2018-06-17 14:18:11 +02:00
|
|
|
|
procedure Panel1Resize(Sender: TObject);
|
|
|
|
|
procedure Panel1Click(Sender: TObject);
|
|
|
|
|
procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
|
|
|
|
procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
|
|
|
|
procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
|
|
|
|
procedure Panel1MouseLeave(Sender: TObject);
|
|
|
|
|
procedure Panel1MouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
|
|
|
|
|
procedure Panel1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
|
|
|
|
procedure Panel1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
|
2018-06-18 21:57:18 +02:00
|
|
|
|
procedure Panel1UTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
|
2018-06-17 14:18:11 +02:00
|
|
|
|
|
|
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
|
procedure FormDestroy(Sender: TObject);
|
|
|
|
|
procedure FormShow(Sender: TObject);
|
|
|
|
|
procedure FormHide(Sender: TObject);
|
|
|
|
|
procedure FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
|
|
|
|
|
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
|
|
|
|
|
|
|
|
|
procedure chrmosrPaint(Sender: TObject; const browser: ICefBrowser; kind: TCefPaintElementType; dirtyRectsCount: NativeUInt; const dirtyRects: PCefRectArray; const buffer: Pointer; aWidth, aHeight: Integer);
|
|
|
|
|
procedure chrmosrCursorChange(Sender: TObject; const browser: ICefBrowser; aCursor: HICON; cursorType: TCefCursorType; const customCursorInfo: PCefCursorInfo);
|
2018-12-12 17:13:23 +01:00
|
|
|
|
procedure chrmosrGetViewRect(Sender: TObject; const browser: ICefBrowser; var rect: TCefRect);
|
2018-06-17 14:18:11 +02:00
|
|
|
|
procedure chrmosrGetScreenPoint(Sender: TObject; const browser: ICefBrowser; viewX, viewY: Integer; var screenX, screenY: Integer; out Result: Boolean);
|
|
|
|
|
procedure chrmosrGetScreenInfo(Sender: TObject; const browser: ICefBrowser; var screenInfo: TCefScreenInfo; out Result: Boolean);
|
|
|
|
|
procedure chrmosrPopupShow(Sender: TObject; const browser: ICefBrowser; aShow: Boolean);
|
|
|
|
|
procedure chrmosrPopupSize(Sender: TObject; const browser: ICefBrowser; const rect: PCefRect);
|
|
|
|
|
procedure chrmosrAfterCreated(Sender: TObject; const browser: ICefBrowser);
|
|
|
|
|
procedure chrmosrTooltip(Sender: TObject; const browser: ICefBrowser; var aText: ustring; out Result: Boolean);
|
2019-06-16 10:31:13 +02:00
|
|
|
|
procedure chrmosrBeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var noJavascriptAccess: Boolean; var Result: Boolean);
|
2018-06-17 14:18:11 +02:00
|
|
|
|
procedure chrmosrBeforeClose(Sender: TObject; const browser: ICefBrowser);
|
2019-01-08 19:15:25 +01:00
|
|
|
|
procedure chrmosrIMECompositionRangeChanged(Sender: TObject; const browser: ICefBrowser; const selected_range: PCefRange; character_boundsCount: NativeUInt; const character_bounds: PCefRect);
|
2018-06-17 14:18:11 +02:00
|
|
|
|
|
|
|
|
|
procedure SnapshotBtnClick(Sender: TObject);
|
|
|
|
|
procedure SnapshotBtnEnter(Sender: TObject);
|
2019-05-19 16:08:15 +02:00
|
|
|
|
|
|
|
|
|
procedure Timer1Timer(Sender: TObject);
|
2018-06-17 14:18:11 +02:00
|
|
|
|
procedure ComboBox1Enter(Sender: TObject);
|
|
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
FbFirst : boolean;
|
|
|
|
|
FPopUpBitmap : TBitmap;
|
|
|
|
|
FPopUpRect : TRect;
|
|
|
|
|
FShowPopUp : boolean;
|
|
|
|
|
FResizing : boolean;
|
|
|
|
|
FPendingResize : boolean;
|
|
|
|
|
FCanClose : boolean;
|
|
|
|
|
FClosing : boolean;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
FResizeCS : TCriticalSection;
|
|
|
|
|
FIMECS : TCriticalSection;
|
|
|
|
|
FDeviceBounds : TCefRectDynArray;
|
|
|
|
|
FSelectedRange : TCefRange;
|
2018-06-17 14:18:11 +02:00
|
|
|
|
|
|
|
|
|
FLastClickCount : integer;
|
|
|
|
|
FLastClickTime : integer;
|
|
|
|
|
FLastClickPoint : TPoint;
|
|
|
|
|
FLastClickButton : TMouseButton;
|
|
|
|
|
|
|
|
|
|
function getModifiers(Shift: TShiftState): TCefEventFlags;
|
|
|
|
|
function GetButton(Button: TMouseButton): TCefMouseButtonType;
|
|
|
|
|
procedure DoResize;
|
|
|
|
|
procedure InitializeLastClick;
|
|
|
|
|
function CancelPreviousClick(x, y : integer; var aCurrentTime : integer) : boolean;
|
|
|
|
|
|
|
|
|
|
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
|
|
|
|
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
|
|
|
|
procedure WMCaptureChanged(var aMessage : TMessage); message WM_CAPTURECHANGED;
|
|
|
|
|
procedure WMCancelMode(var aMessage : TMessage); message WM_CANCELMODE;
|
|
|
|
|
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
|
|
|
|
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
|
|
|
|
|
procedure WMSysChar(var aMessage: TMessage); message WM_SYSCHAR;
|
|
|
|
|
procedure WMSysKeyDown(var aMessage: TMessage); message WM_SYSKEYDOWN;
|
|
|
|
|
procedure WMSysKeyUp(var aMessage: TMessage); message WM_SYSKEYUP;
|
|
|
|
|
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
|
|
|
|
procedure PendingResizeMsg(var aMessage : TMessage); message CEF_PENDINGRESIZE;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
procedure PendingInvalidateMsg(var aMessage : TMessage); message CEF_PENDINGINVALIDATE;
|
|
|
|
|
procedure RangeChangedMsg(var aMessage : TMessage); message CEF_IMERANGECHANGED;
|
2018-06-17 14:18:11 +02:00
|
|
|
|
|
|
|
|
|
public
|
|
|
|
|
{ Public declarations }
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
Form1: TForm1;
|
|
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
|
procedure CreateGlobalCEFApp;
|
|
|
|
|
|
2018-06-17 14:18:11 +02:00
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
{$R *.lfm}
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
Math,
|
|
|
|
|
uCEFMiscFunctions, uCEFApplication;
|
|
|
|
|
|
|
|
|
|
// This is the destruction sequence in OSR mode :
|
|
|
|
|
// 1- FormCloseQuery sets CanClose to the initial FCanClose value (False) and calls chrmosr.CloseBrowser(True).
|
|
|
|
|
// 2- chrmosr.CloseBrowser(True) will trigger chrmosr.OnClose and we have to
|
2019-10-19 10:58:34 +02:00
|
|
|
|
// set "Result" to false and CEF will destroy the internal browser immediately.
|
2018-06-17 14:18:11 +02:00
|
|
|
|
// 3- chrmosr.OnBeforeClose is triggered because the internal browser was destroyed.
|
2020-02-26 13:28:29 +01:00
|
|
|
|
// FCanClose is set to True and sends WM_CLOSE to the form.
|
2019-06-19 16:53:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procedure CreateGlobalCEFApp;
|
|
|
|
|
begin
|
|
|
|
|
GlobalCEFApp := TCefApplication.Create;
|
|
|
|
|
GlobalCEFApp.WindowlessRenderingEnabled := True;
|
|
|
|
|
GlobalCEFApp.EnableHighDPISupport := True;
|
|
|
|
|
end;
|
2018-06-17 14:18:11 +02:00
|
|
|
|
|
|
|
|
|
procedure TForm1.GoBtnClick(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
FResizeCS.Acquire;
|
|
|
|
|
FResizing := False;
|
|
|
|
|
FPendingResize := False;
|
|
|
|
|
FResizeCS.Release;
|
|
|
|
|
|
|
|
|
|
chrmosr.LoadURL(ComboBox1.Text);
|
|
|
|
|
end;
|
|
|
|
|
|
2019-01-08 19:15:25 +01:00
|
|
|
|
procedure TForm1.chrmosrIMECompositionRangeChanged( Sender : TObject;
|
|
|
|
|
const browser : ICefBrowser;
|
|
|
|
|
const selected_range : PCefRange;
|
|
|
|
|
character_boundsCount : NativeUInt;
|
|
|
|
|
const character_bounds : PCefRect);
|
|
|
|
|
var
|
|
|
|
|
TempPRect : PCefRect;
|
|
|
|
|
i : NativeUInt;
|
|
|
|
|
begin
|
|
|
|
|
try
|
|
|
|
|
FIMECS.Acquire;
|
|
|
|
|
|
|
|
|
|
// TChromium.OnIMECompositionRangeChanged is triggered in a different thread
|
|
|
|
|
// and all functions using a IMM context need to be executed in the same
|
|
|
|
|
// thread, in this case the main thread. We need to save the parameters and
|
|
|
|
|
// send a message to the form to execute Panel1.ChangeCompositionRange in
|
|
|
|
|
// the main thread.
|
|
|
|
|
|
|
|
|
|
if (FDeviceBounds <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
Finalize(FDeviceBounds);
|
|
|
|
|
FDeviceBounds := nil;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
FSelectedRange := selected_range^;
|
|
|
|
|
|
|
|
|
|
if (character_boundsCount > 0) then
|
|
|
|
|
begin
|
|
|
|
|
SetLength(FDeviceBounds, character_boundsCount);
|
|
|
|
|
|
|
|
|
|
i := 0;
|
|
|
|
|
TempPRect := character_bounds;
|
|
|
|
|
|
|
|
|
|
while (i < character_boundsCount) do
|
|
|
|
|
begin
|
|
|
|
|
FDeviceBounds[i] := TempPRect^;
|
|
|
|
|
LogicalToDevice(FDeviceBounds[i], GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
|
|
|
|
|
inc(TempPRect);
|
|
|
|
|
inc(i);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
PostMessage(Handle, CEF_IMERANGECHANGED, 0, 0);
|
|
|
|
|
finally
|
|
|
|
|
FIMECS.Release;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2018-06-17 14:18:11 +02:00
|
|
|
|
procedure TForm1.GoBtnEnter(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.SendFocusEvent(False);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.chrmosrAfterCreated(Sender: TObject; const browser: ICefBrowser);
|
|
|
|
|
begin
|
|
|
|
|
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.chrmosrBeforeClose(Sender: TObject; const browser: ICefBrowser);
|
|
|
|
|
begin
|
2020-01-01 12:48:10 +01:00
|
|
|
|
FCanClose := True;
|
|
|
|
|
PostMessage(Handle, WM_CLOSE, 0, 0);
|
2018-06-17 14:18:11 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2018-06-18 21:57:18 +02:00
|
|
|
|
procedure TForm1.Panel1UTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
|
|
|
|
|
var
|
|
|
|
|
TempKeyEvent : TCefKeyEvent;
|
|
|
|
|
TempString : UnicodeString;
|
|
|
|
|
begin
|
|
|
|
|
if Panel1.Focused then
|
|
|
|
|
begin
|
|
|
|
|
TempString := UTF8Decode(UTF8Key);
|
|
|
|
|
|
|
|
|
|
if (length(TempString) > 0) then
|
|
|
|
|
begin
|
|
|
|
|
TempKeyEvent.kind := KEYEVENT_CHAR;
|
|
|
|
|
TempKeyEvent.modifiers := GetCefKeyboardModifiers(WParam(TempString[1]), 0);
|
|
|
|
|
TempKeyEvent.windows_key_code := ord(TempString[1]);
|
|
|
|
|
TempKeyEvent.native_key_code := 0;
|
|
|
|
|
TempKeyEvent.is_system_key := ord(False);
|
|
|
|
|
TempKeyEvent.character := #0;
|
|
|
|
|
TempKeyEvent.unmodified_character := #0;
|
|
|
|
|
TempKeyEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempKeyEvent);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2018-06-17 14:18:11 +02:00
|
|
|
|
procedure TForm1.chrmosrBeforePopup(Sender: TObject;
|
|
|
|
|
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
|
|
|
|
|
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
|
|
|
|
|
userGesture: Boolean; const popupFeatures: TCefPopupFeatures;
|
|
|
|
|
var windowInfo: TCefWindowInfo; var client: ICefClient;
|
2019-06-16 10:31:13 +02:00
|
|
|
|
var settings: TCefBrowserSettings;
|
|
|
|
|
var extra_info: ICefDictionaryValue;
|
|
|
|
|
var noJavascriptAccess: Boolean;
|
2018-06-17 14:18:11 +02:00
|
|
|
|
var Result: Boolean);
|
|
|
|
|
begin
|
|
|
|
|
// For simplicity, this demo blocks all popup windows and new tabs
|
|
|
|
|
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.chrmosrCursorChange(Sender : TObject;
|
|
|
|
|
const browser : ICefBrowser;
|
|
|
|
|
aCursor : HICON;
|
|
|
|
|
cursorType : TCefCursorType;
|
|
|
|
|
const customCursorInfo : PCefCursorInfo);
|
|
|
|
|
begin
|
2019-11-08 23:15:53 +01:00
|
|
|
|
Panel1.Cursor := CefCursorToWindowsCursor(cursorType);
|
2018-06-17 14:18:11 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.chrmosrGetScreenInfo(Sender : TObject;
|
|
|
|
|
const browser : ICefBrowser;
|
|
|
|
|
var screenInfo : TCefScreenInfo;
|
|
|
|
|
out Result : Boolean);
|
|
|
|
|
var
|
|
|
|
|
TempRect : TCEFRect;
|
|
|
|
|
begin
|
|
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
TempRect.x := 0;
|
|
|
|
|
TempRect.y := 0;
|
|
|
|
|
TempRect.width := DeviceToLogical(Panel1.Width, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
TempRect.height := DeviceToLogical(Panel1.Height, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
|
|
|
|
|
screenInfo.device_scale_factor := GlobalCEFApp.DeviceScaleFactor;
|
|
|
|
|
screenInfo.depth := 0;
|
|
|
|
|
screenInfo.depth_per_component := 0;
|
|
|
|
|
screenInfo.is_monochrome := Ord(False);
|
|
|
|
|
screenInfo.rect := TempRect;
|
|
|
|
|
screenInfo.available_rect := TempRect;
|
|
|
|
|
|
|
|
|
|
Result := True;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
Result := False;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.chrmosrGetScreenPoint(Sender: TObject;
|
|
|
|
|
const browser: ICefBrowser; viewX, viewY: Integer; var screenX,
|
|
|
|
|
screenY: Integer; out Result: Boolean);
|
|
|
|
|
var
|
|
|
|
|
TempScreenPt, TempViewPt : TPoint;
|
|
|
|
|
begin
|
|
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
TempViewPt.x := LogicalToDevice(viewX, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
TempViewPt.y := LogicalToDevice(viewY, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
TempScreenPt := Panel1.ClientToScreen(TempViewPt);
|
|
|
|
|
screenX := TempScreenPt.x;
|
|
|
|
|
screenY := TempScreenPt.y;
|
|
|
|
|
Result := True;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
Result := False;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.chrmosrGetViewRect(Sender : TObject;
|
|
|
|
|
const browser : ICefBrowser;
|
2018-12-12 17:13:23 +01:00
|
|
|
|
var rect : TCefRect);
|
2018-06-17 14:18:11 +02:00
|
|
|
|
begin
|
|
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
rect.x := 0;
|
|
|
|
|
rect.y := 0;
|
|
|
|
|
rect.width := DeviceToLogical(Panel1.Width, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
rect.height := DeviceToLogical(Panel1.Height, GlobalCEFApp.DeviceScaleFactor);
|
2018-12-12 17:13:23 +01:00
|
|
|
|
end;
|
2018-06-17 14:18:11 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.chrmosrPaint(Sender: TObject; const browser: ICefBrowser;
|
|
|
|
|
kind: TCefPaintElementType; dirtyRectsCount: NativeUInt;
|
|
|
|
|
const dirtyRects: PCefRectArray; const buffer: Pointer; aWidth,
|
|
|
|
|
aHeight: Integer);
|
|
|
|
|
var
|
|
|
|
|
src, dst: PByte;
|
|
|
|
|
i, j, TempLineSize, TempSrcOffset, TempDstOffset, SrcStride : Integer;
|
|
|
|
|
n : NativeUInt;
|
|
|
|
|
TempWidth, TempHeight : integer;
|
|
|
|
|
TempBufferBits : Pointer;
|
|
|
|
|
TempForcedResize : boolean;
|
|
|
|
|
TempBitmap : TBitmap;
|
|
|
|
|
begin
|
|
|
|
|
try
|
|
|
|
|
FResizeCS.Acquire;
|
|
|
|
|
TempForcedResize := False;
|
|
|
|
|
|
|
|
|
|
if Panel1.BeginBufferDraw then
|
|
|
|
|
begin
|
|
|
|
|
if (kind = PET_POPUP) then
|
|
|
|
|
begin
|
|
|
|
|
if (FPopUpBitmap = nil) or
|
|
|
|
|
(aWidth <> FPopUpBitmap.Width) or
|
|
|
|
|
(aHeight <> FPopUpBitmap.Height) then
|
|
|
|
|
begin
|
|
|
|
|
if (FPopUpBitmap <> nil) then FPopUpBitmap.Free;
|
|
|
|
|
|
|
|
|
|
FPopUpBitmap := TBitmap.Create;
|
|
|
|
|
FPopUpBitmap.PixelFormat := pf32bit;
|
|
|
|
|
FPopUpBitmap.HandleType := bmDIB;
|
|
|
|
|
FPopUpBitmap.Width := aWidth;
|
|
|
|
|
FPopUpBitmap.Height := aHeight;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TempBitmap := FPopUpBitmap;
|
|
|
|
|
TempBitmap.BeginUpdate;
|
|
|
|
|
|
|
|
|
|
TempWidth := FPopUpBitmap.Width;
|
|
|
|
|
TempHeight := FPopUpBitmap.Height;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
TempForcedResize := Panel1.UpdateBufferDimensions(aWidth, aHeight) or not(Panel1.BufferIsResized(False));
|
|
|
|
|
|
|
|
|
|
TempBitmap := Panel1.Buffer;
|
|
|
|
|
TempBitmap.BeginUpdate;
|
|
|
|
|
|
|
|
|
|
TempWidth := Panel1.BufferWidth;
|
|
|
|
|
TempHeight := Panel1.BufferHeight;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
if (TempBufferBits <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
SrcStride := aWidth * SizeOf(TRGBQuad);
|
|
|
|
|
n := 0;
|
|
|
|
|
|
|
|
|
|
while (n < dirtyRectsCount) do
|
|
|
|
|
begin
|
|
|
|
|
if (dirtyRects^[n].x >= 0) and (dirtyRects^[n].y >= 0) then
|
|
|
|
|
begin
|
|
|
|
|
TempLineSize := min(dirtyRects^[n].width, TempWidth - dirtyRects^[n].x) * SizeOf(TRGBQuad);
|
|
|
|
|
|
|
|
|
|
if (TempLineSize > 0) then
|
|
|
|
|
begin
|
|
|
|
|
TempSrcOffset := ((dirtyRects^[n].y * aWidth) + dirtyRects^[n].x) * SizeOf(TRGBQuad);
|
|
|
|
|
TempDstOffset := (dirtyRects^[n].x * SizeOf(TRGBQuad));
|
|
|
|
|
|
|
|
|
|
src := @PByte(buffer)[TempSrcOffset];
|
|
|
|
|
|
|
|
|
|
i := 0;
|
|
|
|
|
j := min(dirtyRects^[n].height, TempHeight - dirtyRects^[n].y);
|
|
|
|
|
|
|
|
|
|
while (i < j) do
|
|
|
|
|
begin
|
|
|
|
|
TempBufferBits := TempBitmap.Scanline[dirtyRects^[n].y + i];
|
|
|
|
|
dst := @PByte(TempBufferBits)[TempDstOffset];
|
|
|
|
|
|
|
|
|
|
Move(src^, dst^, TempLineSize);
|
|
|
|
|
|
|
|
|
|
Inc(src, SrcStride);
|
|
|
|
|
inc(i);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
inc(n);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TempBitmap.EndUpdate;
|
|
|
|
|
|
|
|
|
|
if FShowPopup and (FPopUpBitmap <> nil) then
|
|
|
|
|
Panel1.BufferDraw(FPopUpRect.Left, FPopUpRect.Top, FPopUpBitmap);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
Panel1.EndBufferDraw;
|
|
|
|
|
|
|
|
|
|
if HandleAllocated then PostMessage(Handle, CEF_PENDINGINVALIDATE, 0, 0);
|
|
|
|
|
|
|
|
|
|
if (kind = PET_VIEW) then
|
|
|
|
|
begin
|
|
|
|
|
if (TempForcedResize or FPendingResize) and
|
|
|
|
|
HandleAllocated then
|
|
|
|
|
PostMessage(Handle, CEF_PENDINGRESIZE, 0, 0);
|
|
|
|
|
|
|
|
|
|
FResizing := False;
|
|
|
|
|
FPendingResize := False;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
finally
|
|
|
|
|
FResizeCS.Release;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.chrmosrPopupShow(Sender : TObject;
|
|
|
|
|
const browser : ICefBrowser;
|
|
|
|
|
aShow : Boolean);
|
|
|
|
|
begin
|
|
|
|
|
if aShow then
|
|
|
|
|
FShowPopUp := True
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
FShowPopUp := False;
|
|
|
|
|
FPopUpRect := rect(0, 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
if (chrmosr <> nil) then chrmosr.Invalidate(PET_VIEW);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.chrmosrPopupSize(Sender : TObject;
|
|
|
|
|
const browser : ICefBrowser;
|
|
|
|
|
const rect : PCefRect);
|
|
|
|
|
begin
|
|
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
LogicalToDevice(rect^, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
|
|
|
|
|
FPopUpRect.Left := rect^.x;
|
|
|
|
|
FPopUpRect.Top := rect^.y;
|
|
|
|
|
FPopUpRect.Right := rect^.x + rect^.width - 1;
|
|
|
|
|
FPopUpRect.Bottom := rect^.y + rect^.height - 1;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.chrmosrTooltip(Sender: TObject; const browser: ICefBrowser; var aText: ustring; out Result: Boolean);
|
|
|
|
|
begin
|
|
|
|
|
Panel1.hint := aText;
|
|
|
|
|
Panel1.ShowHint := (length(aText) > 0);
|
|
|
|
|
Result := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.ComboBox1Enter(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.SendFocusEvent(False);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TForm1.getModifiers(Shift: TShiftState): TCefEventFlags;
|
|
|
|
|
begin
|
|
|
|
|
Result := EVENTFLAG_NONE;
|
|
|
|
|
|
|
|
|
|
if (ssShift in Shift) then Result := Result or EVENTFLAG_SHIFT_DOWN;
|
|
|
|
|
if (ssAlt in Shift) then Result := Result or EVENTFLAG_ALT_DOWN;
|
|
|
|
|
if (ssCtrl in Shift) then Result := Result or EVENTFLAG_CONTROL_DOWN;
|
|
|
|
|
if (ssLeft in Shift) then Result := Result or EVENTFLAG_LEFT_MOUSE_BUTTON;
|
|
|
|
|
if (ssRight in Shift) then Result := Result or EVENTFLAG_RIGHT_MOUSE_BUTTON;
|
|
|
|
|
if (ssMiddle in Shift) then Result := Result or EVENTFLAG_MIDDLE_MOUSE_BUTTON;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TForm1.GetButton(Button: TMouseButton): TCefMouseButtonType;
|
|
|
|
|
begin
|
|
|
|
|
case Button of
|
|
|
|
|
TMouseButton.mbRight : Result := MBT_RIGHT;
|
|
|
|
|
TMouseButton.mbMiddle : Result := MBT_MIDDLE;
|
|
|
|
|
else Result := MBT_LEFT;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.WMMove(var aMessage : TWMMove);
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
|
|
if (chrmosr <> nil) then chrmosr.NotifyMoveOrResizeStarted;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.WMMoving(var aMessage : TMessage);
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
|
|
if (chrmosr <> nil) then chrmosr.NotifyMoveOrResizeStarted;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.WMCaptureChanged(var aMessage : TMessage);
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
|
|
if (chrmosr <> nil) then chrmosr.SendCaptureLostEvent;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.WMCancelMode(var aMessage : TMessage);
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
|
|
if (chrmosr <> nil) then chrmosr.SendCaptureLostEvent;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.WMEnterMenuLoop(var aMessage: TMessage);
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
|
|
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.WMExitMenuLoop(var aMessage: TMessage);
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
|
|
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.WMSysChar(var aMessage: TMessage);
|
|
|
|
|
var
|
|
|
|
|
TempKeyEvent : TCefKeyEvent;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
|
|
if Panel1.Focused and (aMessage.wParam in [VK_BACK..VK_HELP]) then
|
|
|
|
|
begin
|
|
|
|
|
TempKeyEvent.kind := KEYEVENT_CHAR;
|
|
|
|
|
TempKeyEvent.modifiers := GetCefKeyboardModifiers(aMessage.wParam, aMessage.lParam);
|
|
|
|
|
TempKeyEvent.windows_key_code := aMessage.wParam;
|
|
|
|
|
TempKeyEvent.native_key_code := aMessage.lParam;
|
|
|
|
|
TempKeyEvent.is_system_key := ord(True);
|
|
|
|
|
TempKeyEvent.character := #0;
|
|
|
|
|
TempKeyEvent.unmodified_character := #0;
|
|
|
|
|
TempKeyEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempKeyEvent);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.WMSysKeyDown(var aMessage: TMessage);
|
|
|
|
|
var
|
|
|
|
|
TempKeyEvent : TCefKeyEvent;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
|
|
if Panel1.Focused and (aMessage.wParam in [VK_BACK..VK_HELP]) then
|
|
|
|
|
begin
|
|
|
|
|
TempKeyEvent.kind := KEYEVENT_RAWKEYDOWN;
|
|
|
|
|
TempKeyEvent.modifiers := GetCefKeyboardModifiers(aMessage.wParam, aMessage.lParam);
|
|
|
|
|
TempKeyEvent.windows_key_code := aMessage.wParam;
|
|
|
|
|
TempKeyEvent.native_key_code := aMessage.lParam;
|
|
|
|
|
TempKeyEvent.is_system_key := ord(True);
|
|
|
|
|
TempKeyEvent.character := #0;
|
|
|
|
|
TempKeyEvent.unmodified_character := #0;
|
|
|
|
|
TempKeyEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempKeyEvent);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.WMSysKeyUp(var aMessage: TMessage);
|
|
|
|
|
var
|
|
|
|
|
TempKeyEvent : TCefKeyEvent;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
|
|
if Panel1.Focused and (aMessage.wParam in [VK_BACK..VK_HELP]) then
|
|
|
|
|
begin
|
|
|
|
|
TempKeyEvent.kind := KEYEVENT_KEYUP;
|
|
|
|
|
TempKeyEvent.modifiers := GetCefKeyboardModifiers(aMessage.wParam, aMessage.lParam);
|
|
|
|
|
TempKeyEvent.windows_key_code := aMessage.wParam;
|
|
|
|
|
TempKeyEvent.native_key_code := aMessage.lParam;
|
|
|
|
|
TempKeyEvent.is_system_key := ord(True);
|
|
|
|
|
TempKeyEvent.character := #0;
|
|
|
|
|
TempKeyEvent.unmodified_character := #0;
|
|
|
|
|
TempKeyEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempKeyEvent);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.BrowserCreatedMsg(var aMessage : TMessage);
|
|
|
|
|
begin
|
|
|
|
|
Caption := 'Simple Lazarus OSR Browser';
|
|
|
|
|
NavControlPnl.Enabled := True;
|
|
|
|
|
GoBtn.Click;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
|
|
|
|
|
begin
|
|
|
|
|
if (chrmosr <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.NotifyScreenInfoChanged;
|
|
|
|
|
chrmosr.WasResized;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
|
|
|
|
begin
|
|
|
|
|
CanClose := FCanClose;
|
|
|
|
|
|
|
|
|
|
if not(FClosing) then
|
|
|
|
|
begin
|
|
|
|
|
FClosing := True;
|
|
|
|
|
Visible := False;
|
|
|
|
|
chrmosr.CloseBrowser(True);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.FormCreate(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
FbFirst := False;
|
|
|
|
|
FPopUpBitmap := nil;
|
|
|
|
|
FPopUpRect := rect(0, 0, 0, 0);
|
|
|
|
|
FShowPopUp := False;
|
|
|
|
|
FResizing := False;
|
|
|
|
|
FPendingResize := False;
|
|
|
|
|
FCanClose := False;
|
|
|
|
|
FClosing := False;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
FDeviceBounds := nil;
|
|
|
|
|
|
|
|
|
|
FSelectedRange.from := 0;
|
|
|
|
|
FSelectedRange.to_ := 0;
|
|
|
|
|
|
2018-06-17 14:18:11 +02:00
|
|
|
|
FResizeCS := TCriticalSection.Create;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
FIMECS := TCriticalSection.Create;
|
2018-06-17 14:18:11 +02:00
|
|
|
|
|
|
|
|
|
InitializeLastClick;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.FormDestroy(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.ShutdownDragAndDrop;
|
|
|
|
|
|
2019-01-08 19:15:25 +01:00
|
|
|
|
if (FPopUpBitmap <> nil) then FreeAndNil(FPopUpBitmap);
|
|
|
|
|
if (FResizeCS <> nil) then FreeAndNil(FResizeCS);
|
|
|
|
|
if (FIMECS <> nil) then FreeAndNil(FIMECS);
|
|
|
|
|
|
|
|
|
|
if (FDeviceBounds <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
Finalize(FDeviceBounds);
|
|
|
|
|
FDeviceBounds := nil;
|
|
|
|
|
end;
|
2018-06-17 14:18:11 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.FormHide(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.SendFocusEvent(False);
|
|
|
|
|
chrmosr.WasHidden(True);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.FormShow(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
if chrmosr.Initialized then
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.WasHidden(False);
|
|
|
|
|
chrmosr.SendFocusEvent(True);
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
// opaque white background color
|
|
|
|
|
chrmosr.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF);
|
|
|
|
|
|
2019-01-08 19:15:25 +01:00
|
|
|
|
// The IME handler needs to be created when Panel1 has a valid handle
|
|
|
|
|
// and before the browser creation.
|
|
|
|
|
// You can skip this if the user doesn't need an "Input Method Editor".
|
|
|
|
|
Panel1.CreateIMEHandler;
|
|
|
|
|
|
2018-06-17 14:18:11 +02:00
|
|
|
|
if chrmosr.CreateBrowser(nil, '') then
|
|
|
|
|
chrmosr.InitializeDragAndDrop(Panel1)
|
|
|
|
|
else
|
|
|
|
|
Timer1.Enabled := True;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1Click(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
Panel1.SetFocus;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
|
|
|
|
var
|
|
|
|
|
TempEvent : TCefMouseEvent;
|
|
|
|
|
TempTime : integer;
|
|
|
|
|
begin
|
|
|
|
|
if (GlobalCEFApp <> nil) and (chrmosr <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
Panel1.SetFocus;
|
|
|
|
|
|
|
|
|
|
if not(CancelPreviousClick(x, y, TempTime)) and (Button = FLastClickButton) then
|
|
|
|
|
inc(FLastClickCount)
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
FLastClickPoint.x := x;
|
|
|
|
|
FLastClickPoint.y := y;
|
|
|
|
|
FLastClickCount := 1;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
FLastClickTime := TempTime;
|
|
|
|
|
FLastClickButton := Button;
|
|
|
|
|
|
|
|
|
|
TempEvent.x := X;
|
|
|
|
|
TempEvent.y := Y;
|
|
|
|
|
TempEvent.modifiers := getModifiers(Shift);
|
|
|
|
|
DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), False, FLastClickCount);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1MouseLeave(Sender: TObject);
|
|
|
|
|
var
|
|
|
|
|
TempEvent : TCefMouseEvent;
|
|
|
|
|
TempPoint : TPoint;
|
|
|
|
|
TempTime : integer;
|
|
|
|
|
begin
|
|
|
|
|
if (GlobalCEFApp <> nil) and (chrmosr <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
GetCursorPos(TempPoint);
|
|
|
|
|
TempPoint := Panel1.ScreenToclient(TempPoint);
|
|
|
|
|
|
|
|
|
|
if CancelPreviousClick(TempPoint.x, TempPoint.y, TempTime) then InitializeLastClick;
|
|
|
|
|
|
|
|
|
|
TempEvent.x := TempPoint.x;
|
|
|
|
|
TempEvent.y := TempPoint.y;
|
|
|
|
|
TempEvent.modifiers := GetCefMouseModifiers;
|
|
|
|
|
DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
chrmosr.SendMouseMoveEvent(@TempEvent, True);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
|
|
|
|
var
|
|
|
|
|
TempEvent : TCefMouseEvent;
|
|
|
|
|
TempTime : integer;
|
|
|
|
|
begin
|
|
|
|
|
if (GlobalCEFApp <> nil) and (chrmosr <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
if CancelPreviousClick(x, y, TempTime) then InitializeLastClick;
|
|
|
|
|
|
|
|
|
|
TempEvent.x := x;
|
|
|
|
|
TempEvent.y := y;
|
|
|
|
|
TempEvent.modifiers := getModifiers(Shift);
|
|
|
|
|
DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
chrmosr.SendMouseMoveEvent(@TempEvent, False);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
|
|
|
|
var
|
|
|
|
|
TempEvent : TCefMouseEvent;
|
|
|
|
|
begin
|
|
|
|
|
if (GlobalCEFApp <> nil) and (chrmosr <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
TempEvent.x := X;
|
|
|
|
|
TempEvent.y := Y;
|
|
|
|
|
TempEvent.modifiers := getModifiers(Shift);
|
|
|
|
|
DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), True, FLastClickCount);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1Resize(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
DoResize;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.PendingResizeMsg(var aMessage : TMessage);
|
|
|
|
|
begin
|
|
|
|
|
DoResize;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.PendingInvalidateMsg(var aMessage : TMessage);
|
|
|
|
|
begin
|
|
|
|
|
Panel1.Invalidate;
|
|
|
|
|
end;
|
|
|
|
|
|
2019-01-08 19:15:25 +01:00
|
|
|
|
procedure TForm1.RangeChangedMsg(var aMessage : TMessage);
|
|
|
|
|
begin
|
|
|
|
|
try
|
|
|
|
|
FIMECS.Acquire;
|
|
|
|
|
Panel1.ChangeCompositionRange(FSelectedRange, FDeviceBounds);
|
|
|
|
|
finally
|
|
|
|
|
FIMECS.Release;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2018-06-17 14:18:11 +02:00
|
|
|
|
procedure TForm1.DoResize;
|
|
|
|
|
begin
|
|
|
|
|
try
|
|
|
|
|
FResizeCS.Acquire;
|
|
|
|
|
|
|
|
|
|
if FResizing then
|
|
|
|
|
FPendingResize := True
|
|
|
|
|
else
|
|
|
|
|
if Panel1.BufferIsResized then
|
|
|
|
|
chrmosr.Invalidate(PET_VIEW)
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
FResizing := True;
|
|
|
|
|
chrmosr.WasResized;
|
|
|
|
|
end;
|
|
|
|
|
finally
|
|
|
|
|
FResizeCS.Release;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.InitializeLastClick;
|
|
|
|
|
begin
|
2020-02-26 13:28:29 +01:00
|
|
|
|
FLastClickCount := 1;
|
2018-06-17 14:18:11 +02:00
|
|
|
|
FLastClickTime := 0;
|
|
|
|
|
FLastClickPoint.x := 0;
|
|
|
|
|
FLastClickPoint.y := 0;
|
|
|
|
|
FLastClickButton := mbLeft;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TForm1.CancelPreviousClick(x, y : integer; var aCurrentTime : integer) : boolean;
|
|
|
|
|
begin
|
|
|
|
|
aCurrentTime := GetMessageTime;
|
|
|
|
|
|
|
|
|
|
Result := (abs(FLastClickPoint.x - x) > (GetSystemMetrics(SM_CXDOUBLECLK) div 2)) or
|
|
|
|
|
(abs(FLastClickPoint.y - y) > (GetSystemMetrics(SM_CYDOUBLECLK) div 2)) or
|
|
|
|
|
(cardinal(aCurrentTime - FLastClickTime) > GetDoubleClickTime);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1Enter(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.SendFocusEvent(True);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1Exit(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.SendFocusEvent(False);
|
|
|
|
|
end;
|
|
|
|
|
|
2019-01-08 19:15:25 +01:00
|
|
|
|
procedure TForm1.Panel1IMECancelComposition(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.IMECancelComposition;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1IMECommitText( Sender : TObject;
|
|
|
|
|
const aText : ustring;
|
|
|
|
|
const replacement_range : PCefRange;
|
|
|
|
|
relative_cursor_pos : Integer);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.IMECommitText(aText, replacement_range, relative_cursor_pos);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1IMESetComposition( Sender : TObject;
|
|
|
|
|
const aText : ustring;
|
|
|
|
|
const underlines : TCefCompositionUnderlineDynArray;
|
|
|
|
|
const replacement_range : TCefRange;
|
|
|
|
|
const selection_range : TCefRange);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.IMESetComposition(aText, underlines, @replacement_range, @selection_range);
|
|
|
|
|
end;
|
|
|
|
|
|
2018-06-17 14:18:11 +02:00
|
|
|
|
procedure TForm1.Panel1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
|
|
|
|
var
|
|
|
|
|
TempKeyEvent : TCefKeyEvent;
|
|
|
|
|
begin
|
|
|
|
|
if (Key <> 0) and (chrmosr <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
TempKeyEvent.kind := KEYEVENT_RAWKEYDOWN;
|
|
|
|
|
TempKeyEvent.modifiers := getModifiers(Shift);
|
|
|
|
|
TempKeyEvent.windows_key_code := Key;
|
|
|
|
|
TempKeyEvent.native_key_code := 0;
|
|
|
|
|
TempKeyEvent.is_system_key := ord(False);
|
|
|
|
|
TempKeyEvent.character := #0;
|
|
|
|
|
TempKeyEvent.unmodified_character := #0;
|
|
|
|
|
TempKeyEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempKeyEvent);
|
2019-06-19 16:53:26 +02:00
|
|
|
|
|
|
|
|
|
if (Key in [VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN, VK_TAB]) then Key := 0;
|
2018-06-17 14:18:11 +02:00
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
|
|
|
|
|
var
|
|
|
|
|
TempKeyEvent : TCefKeyEvent;
|
|
|
|
|
begin
|
|
|
|
|
if (Key <> 0) and (chrmosr <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
TempKeyEvent.kind := KEYEVENT_KEYUP;
|
|
|
|
|
TempKeyEvent.modifiers := getModifiers(Shift);
|
|
|
|
|
TempKeyEvent.windows_key_code := Key;
|
|
|
|
|
TempKeyEvent.native_key_code := 0;
|
|
|
|
|
TempKeyEvent.is_system_key := ord(False);
|
|
|
|
|
TempKeyEvent.character := #0;
|
|
|
|
|
TempKeyEvent.unmodified_character := #0;
|
|
|
|
|
TempKeyEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempKeyEvent);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1MouseWheel(Sender: TObject; Shift: TShiftState;
|
|
|
|
|
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
|
|
|
|
|
var
|
|
|
|
|
TempEvent : TCefMouseEvent;
|
|
|
|
|
begin
|
|
|
|
|
if (GlobalCEFApp <> nil) and (chrmosr <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
TempEvent.x := MousePos.x;
|
|
|
|
|
TempEvent.y := MousePos.y;
|
|
|
|
|
TempEvent.modifiers := getModifiers(Shift);
|
|
|
|
|
DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
chrmosr.SendMouseWheelEvent(@TempEvent, 0, WheelDelta);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.SnapshotBtnClick(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
if SaveDialog1.Execute then Panel1.SaveToFile(SaveDialog1.FileName);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.SnapshotBtnEnter(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.SendFocusEvent(False);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Timer1Timer(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
Timer1.Enabled := False;
|
|
|
|
|
|
|
|
|
|
if chrmosr.CreateBrowser(nil, '') then
|
|
|
|
|
chrmosr.InitializeDragAndDrop(Panel1)
|
|
|
|
|
else
|
|
|
|
|
if not(chrmosr.Initialized) then Timer1.Enabled := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
end.
|