2017-01-27 18:14:48 +01:00
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
//
|
2019-10-19 10:58:34 +02:00
|
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
|
2017-01-27 18:14:48 +01: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
|
|
|
|
|
//
|
2021-01-01 11:11:30 +01:00
|
|
|
|
// Copyright <20> 2021 Salvador Diaz Fau. All rights reserved.
|
2017-01-27 18:14:48 +01: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 uSimpleOSRBrowser;
|
|
|
|
|
|
2017-02-11 21:56:08 +01:00
|
|
|
|
{$I cef.inc}
|
|
|
|
|
|
2017-01-27 18:14:48 +01:00
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
2017-02-11 21:56:08 +01:00
|
|
|
|
{$IFDEF DELPHI16_UP}
|
2017-01-27 18:14:48 +01:00
|
|
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
|
2017-11-16 12:49:15 +01:00
|
|
|
|
System.SyncObjs, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
|
2020-12-13 18:36:10 +01:00
|
|
|
|
Vcl.ExtCtrls, Vcl.AppEvnts, WinApi.imm, Vcl.ComCtrls,
|
2017-02-11 21:56:08 +01:00
|
|
|
|
{$ELSE}
|
2017-11-16 12:49:15 +01:00
|
|
|
|
Windows, Messages, SysUtils, Variants, Classes, SyncObjs,
|
2020-12-13 18:36:10 +01:00
|
|
|
|
Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, AppEvnts, ComCtrls,
|
2017-02-11 21:56:08 +01:00
|
|
|
|
{$ENDIF}
|
2019-10-13 18:50:23 +02:00
|
|
|
|
uCEFChromium, uCEFTypes, uCEFInterfaces, uCEFConstants, uCEFBufferPanel,
|
2020-12-13 18:36:10 +01:00
|
|
|
|
uCEFChromiumCore;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
|
2019-02-20 12:44:07 +01:00
|
|
|
|
const
|
|
|
|
|
// Set this constant to True and load "file://transparency.html" to test a
|
|
|
|
|
// transparent browser.
|
|
|
|
|
TRANSPARENT_BROWSER = False;
|
|
|
|
|
|
2017-01-27 18:14:48 +01:00
|
|
|
|
type
|
|
|
|
|
TForm1 = class(TForm)
|
2017-07-18 17:50:28 +02:00
|
|
|
|
NavControlPnl: TPanel;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
chrmosr: TChromium;
|
|
|
|
|
AppEvents: TApplicationEvents;
|
2020-03-18 10:01:28 +01:00
|
|
|
|
AddressCb: TComboBox;
|
2017-07-28 12:47:57 +02:00
|
|
|
|
Panel2: TPanel;
|
|
|
|
|
GoBtn: TButton;
|
2017-09-07 10:58:09 +02:00
|
|
|
|
SnapshotBtn: TButton;
|
|
|
|
|
SaveDialog1: TSaveDialog;
|
2017-11-04 18:32:29 +01:00
|
|
|
|
Timer1: TTimer;
|
2017-11-16 12:49:15 +01:00
|
|
|
|
Panel1: TBufferPanel;
|
2017-07-28 12:47:57 +02:00
|
|
|
|
|
|
|
|
|
procedure AppEventsMessage(var Msg: tagMSG; var Handled: Boolean);
|
|
|
|
|
|
|
|
|
|
procedure GoBtnClick(Sender: TObject);
|
2017-11-16 12:49:15 +01:00
|
|
|
|
procedure GoBtnEnter(Sender: TObject);
|
2017-07-28 12:47:57 +02:00
|
|
|
|
|
|
|
|
|
procedure Panel1Enter(Sender: TObject);
|
|
|
|
|
procedure Panel1Exit(Sender: TObject);
|
2017-11-16 12:49:15 +01:00
|
|
|
|
procedure Panel1Resize(Sender: TObject);
|
|
|
|
|
procedure Panel1Click(Sender: TObject);
|
2019-06-19 16:53:26 +02:00
|
|
|
|
procedure Panel1PaintParentBkg(Sender: TObject);
|
2017-11-16 12:49:15 +01:00
|
|
|
|
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);
|
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);
|
2020-02-03 12:02:30 +01:00
|
|
|
|
procedure Panel1CustomTouch(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
|
|
|
|
|
procedure Panel1PointerDown(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
|
|
|
|
|
procedure Panel1PointerUp(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
|
|
|
|
|
procedure Panel1PointerUpdate(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
|
2017-11-16 12:49:15 +01:00
|
|
|
|
|
|
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
|
procedure FormDestroy(Sender: TObject);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
procedure FormShow(Sender: TObject);
|
2017-07-28 12:47:57 +02:00
|
|
|
|
procedure FormHide(Sender: TObject);
|
|
|
|
|
procedure FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
|
2018-02-19 13:35:01 +01:00
|
|
|
|
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
2017-07-28 12:47:57 +02:00
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure chrmosrPaint(Sender: TObject; const browser: ICefBrowser; kind: TCefPaintElementType; dirtyRectsCount: NativeUInt; const dirtyRects: PCefRectArray; const buffer: Pointer; width, height: Integer);
|
2021-01-26 18:26:24 +01:00
|
|
|
|
procedure chrmosrCursorChange(Sender: TObject; const browser: ICefBrowser; cursor_: TCefCursorHandle; cursorType: TCefCursorType; const customCursorInfo: PCefCursorInfo; var aResult : boolean);
|
2018-12-12 17:13:23 +01:00
|
|
|
|
procedure chrmosrGetViewRect(Sender: TObject; const browser: ICefBrowser; var rect: TCefRect);
|
2017-07-28 12:47:57 +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);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure chrmosrPopupShow(Sender: TObject; const browser: ICefBrowser; show: Boolean);
|
|
|
|
|
procedure chrmosrPopupSize(Sender: TObject; const browser: ICefBrowser; const rect: PCefRect);
|
|
|
|
|
procedure chrmosrAfterCreated(Sender: TObject; const browser: ICefBrowser);
|
2018-02-01 18:57:54 +01:00
|
|
|
|
procedure chrmosrTooltip(Sender: TObject; const browser: ICefBrowser; var text: 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-02-19 13:35:01 +01: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);
|
2017-11-16 12:49:15 +01:00
|
|
|
|
|
|
|
|
|
procedure SnapshotBtnClick(Sender: TObject);
|
2017-11-13 18:32:48 +01:00
|
|
|
|
procedure SnapshotBtnEnter(Sender: TObject);
|
2019-06-19 16:53:26 +02:00
|
|
|
|
|
|
|
|
|
procedure Timer1Timer(Sender: TObject);
|
2020-03-18 10:01:28 +01:00
|
|
|
|
procedure AddressCbEnter(Sender: TObject);
|
2017-11-16 12:49:15 +01:00
|
|
|
|
|
|
|
|
|
protected
|
2018-02-25 13:10:21 +01:00
|
|
|
|
FPopUpBitmap : TBitmap;
|
|
|
|
|
FPopUpRect : TRect;
|
|
|
|
|
FShowPopUp : boolean;
|
|
|
|
|
FResizing : boolean;
|
|
|
|
|
FPendingResize : boolean;
|
|
|
|
|
FCanClose : boolean;
|
|
|
|
|
FClosing : boolean;
|
|
|
|
|
FResizeCS : TCriticalSection;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
FIMECS : TCriticalSection;
|
|
|
|
|
FDeviceBounds : TCefRectDynArray;
|
|
|
|
|
FSelectedRange : TCefRange;
|
2020-02-08 12:59:59 +01:00
|
|
|
|
FAtLeastWin8 : boolean;
|
2018-02-25 13:10:21 +01:00
|
|
|
|
|
|
|
|
|
FLastClickCount : integer;
|
|
|
|
|
FLastClickTime : integer;
|
|
|
|
|
FLastClickPoint : TPoint;
|
|
|
|
|
FLastClickButton : TMouseButton;
|
2017-11-16 12:49:15 +01:00
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
function getModifiers(Shift: TShiftState): TCefEventFlags;
|
|
|
|
|
function GetButton(Button: TMouseButton): TCefMouseButtonType;
|
2017-11-19 11:30:26 +01:00
|
|
|
|
procedure DoResize;
|
2018-02-25 13:10:21 +01:00
|
|
|
|
procedure InitializeLastClick;
|
|
|
|
|
function CancelPreviousClick(x, y : integer; var aCurrentTime : integer) : boolean;
|
2020-02-03 12:02:30 +01:00
|
|
|
|
function ArePointerEventsSupported : boolean;
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$IFDEF DELPHI14_UP}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
function HandlePenEvent(const aID : uint32; aMsg : cardinal) : boolean;
|
|
|
|
|
function HandleTouchEvent(const aID : uint32; aMsg : cardinal) : boolean;
|
|
|
|
|
function HandlePointerEvent(var aMessage : TMessage) : boolean;
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$ENDIF}
|
2017-04-24 12:57:16 +02:00
|
|
|
|
|
|
|
|
|
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
|
|
|
|
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
2017-07-28 12:47:57 +02:00
|
|
|
|
procedure WMCaptureChanged(var aMessage : TMessage); message WM_CAPTURECHANGED;
|
|
|
|
|
procedure WMCancelMode(var aMessage : TMessage); message WM_CANCELMODE;
|
2017-12-18 19:38:56 +01:00
|
|
|
|
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
|
|
|
|
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
|
2017-09-07 10:58:09 +02:00
|
|
|
|
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
2017-11-19 11:30:26 +01:00
|
|
|
|
procedure PendingResizeMsg(var aMessage : TMessage); message CEF_PENDINGRESIZE;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
procedure RangeChangedMsg(var aMessage : TMessage); message CEF_IMERANGECHANGED;
|
2017-04-24 12:57:16 +02:00
|
|
|
|
|
2017-01-27 18:14:48 +01:00
|
|
|
|
public
|
|
|
|
|
{ Public declarations }
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
Form1: TForm1;
|
|
|
|
|
|
2019-02-20 12:44:07 +01:00
|
|
|
|
procedure CreateGlobalCEFApp;
|
|
|
|
|
|
2017-01-27 18:14:48 +01:00
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
2017-06-06 12:49:27 +02:00
|
|
|
|
uses
|
2017-11-16 12:49:15 +01:00
|
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
|
System.Math,
|
|
|
|
|
{$ELSE}
|
|
|
|
|
Math,
|
|
|
|
|
{$ENDIF}
|
2017-10-03 14:38:37 +02:00
|
|
|
|
uCEFMiscFunctions, uCEFApplication;
|
2017-06-06 12:49:27 +02:00
|
|
|
|
|
2020-03-29 17:31:42 +02:00
|
|
|
|
// Chromium renders the web contents asynchronously. It uses multiple processes
|
|
|
|
|
// and threads which makes it complicated to keep the correct browser size.
|
|
|
|
|
|
|
|
|
|
// In one hand you have the main application thread where the form is resized by
|
|
|
|
|
// the user. On the other hand, Chromium renders the contents asynchronously
|
|
|
|
|
// with the last browser size available, which may have changed by the time
|
|
|
|
|
// Chromium renders the page.
|
|
|
|
|
|
|
|
|
|
// For this reason we need to keep checking the real size and call
|
|
|
|
|
// TChromium.WasResized when we detect that Chromium has an incorrect size.
|
|
|
|
|
|
|
|
|
|
// TChromium.WasResized triggers the TChromium.OnGetViewRect event to let CEF
|
|
|
|
|
// read the current browser size and then it triggers TChromium.OnPaint when the
|
|
|
|
|
// contents are finally rendered.
|
|
|
|
|
|
|
|
|
|
// TChromium.WasResized --> (time passes) --> TChromium.OnGetViewRect --> (time passes) --> TChromium.OnPaint
|
|
|
|
|
|
|
|
|
|
// You have to assume that the real browser size can change between those calls
|
|
|
|
|
// and events.
|
|
|
|
|
|
|
|
|
|
// This demo uses a couple of fields called "FResizing" and "FPendingResize" to
|
|
|
|
|
// reduce the number of TChromium.WasResized calls.
|
|
|
|
|
|
|
|
|
|
// FResizing is set to True before the TChromium.WasResized call and it's set to
|
|
|
|
|
// False at the end of the TChromium.OnPaint event.
|
|
|
|
|
|
|
|
|
|
// FPendingResize is set to True when the browser changed its size while
|
|
|
|
|
// FResizing was True. The FPendingResize value is checked at the end of
|
|
|
|
|
// TChromium.OnPaint to check the browser size again because it changed while
|
|
|
|
|
// Chromium was rendering the page.
|
|
|
|
|
|
|
|
|
|
// The TChromium.OnPaint event in the demo also calls
|
|
|
|
|
// TBufferPanel.UpdateBufferDimensions and TBufferPanel.BufferIsResized to check
|
|
|
|
|
// the width and height of the buffer parameter, and the internal buffer size in
|
|
|
|
|
// the TBufferPanel component.
|
|
|
|
|
|
2020-08-15 12:15:10 +02:00
|
|
|
|
// **********************************************************************************************
|
|
|
|
|
// ************************************** ATTENTION! ********************************************
|
|
|
|
|
// **********************************************************************************************
|
|
|
|
|
// * *
|
|
|
|
|
// * If your Delphi/Lazarus version doesn't have full touch and pen support you will have *
|
|
|
|
|
// * issues building this demo. *
|
|
|
|
|
// * *
|
|
|
|
|
// * Some constants and types like POINTER_INPUT_TYPE, POINTER_PEN_INFO, etc. need to be *
|
|
|
|
|
// * defined in order to test touch screens and pens on Windows. *
|
|
|
|
|
// * *
|
|
|
|
|
// * Try adding this unit made by Andreas Hausladen to the "uses" section if you get *
|
|
|
|
|
// * "Undeclared identifier" errors : *
|
|
|
|
|
// * https://github.com/ahausladen/ObjectPascal-WinAPIs/blob/master/WinApi/WinApi.WMPointer.pas *
|
|
|
|
|
// * *
|
|
|
|
|
// **********************************************************************************************
|
|
|
|
|
|
2018-02-19 13:35:01 +01:00
|
|
|
|
// This is the destruction sequence in OSR mode :
|
2020-03-29 17:31:42 +02:00
|
|
|
|
// 1- FormCloseQuery sets CanClose to the initial FCanClose value (False) and
|
|
|
|
|
// calls chrmosr.CloseBrowser(True).
|
2018-02-19 13:35:01 +01:00
|
|
|
|
// 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-02-19 13:35:01 +01:00
|
|
|
|
// 3- chrmosr.OnBeforeClose is triggered because the internal browser was destroyed.
|
2020-01-01 12:48:10 +01:00
|
|
|
|
// Sets FCanClose := True and sends WM_CLOSE to the form.
|
2017-11-19 11:30:26 +01:00
|
|
|
|
|
2019-02-20 12:44:07 +01:00
|
|
|
|
procedure CreateGlobalCEFApp;
|
|
|
|
|
begin
|
|
|
|
|
GlobalCEFApp := TCefApplication.Create;
|
|
|
|
|
GlobalCEFApp.WindowlessRenderingEnabled := True;
|
|
|
|
|
GlobalCEFApp.EnableHighDPISupport := True;
|
2020-02-03 12:02:30 +01:00
|
|
|
|
GlobalCEFApp.TouchEvents := STATE_ENABLED;
|
2020-03-31 12:44:10 +02:00
|
|
|
|
//GlobalCEFApp.EnableGPU := True;
|
2020-11-22 16:42:52 +01:00
|
|
|
|
GlobalCEFApp.LogFile := 'debug.log';
|
|
|
|
|
GlobalCEFApp.LogSeverity := LOGSEVERITY_VERBOSE;
|
2019-02-20 12:44:07 +01:00
|
|
|
|
|
|
|
|
|
// If you need transparency leave the GlobalCEFApp.BackgroundColor property
|
|
|
|
|
// with the default value or set the alpha channel to 0
|
|
|
|
|
if TRANSPARENT_BROWSER then
|
2020-07-21 13:05:08 +02:00
|
|
|
|
GlobalCEFApp.BackgroundColor := CefColorSetARGB($00, $00, $00, $00)
|
2019-02-20 12:44:07 +01:00
|
|
|
|
else
|
|
|
|
|
GlobalCEFApp.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-01-27 18:14:48 +01:00
|
|
|
|
procedure TForm1.AppEventsMessage(var Msg: tagMSG; var Handled: Boolean);
|
|
|
|
|
var
|
2017-11-13 18:32:48 +01:00
|
|
|
|
TempKeyEvent : TCefKeyEvent;
|
|
|
|
|
TempMouseEvent : TCefMouseEvent;
|
2021-01-29 18:27:10 +01:00
|
|
|
|
TempPoint : TPoint;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
|
|
|
|
case Msg.message of
|
2017-07-18 17:50:28 +02:00
|
|
|
|
WM_SYSCHAR :
|
2018-02-25 16:27:53 +01:00
|
|
|
|
if Panel1.Focused then
|
2017-07-18 17:50:28 +02:00
|
|
|
|
begin
|
2017-11-13 18:32:48 +01:00
|
|
|
|
TempKeyEvent.kind := KEYEVENT_CHAR;
|
|
|
|
|
TempKeyEvent.modifiers := GetCefKeyboardModifiers(Msg.wParam, Msg.lParam);
|
|
|
|
|
TempKeyEvent.windows_key_code := Msg.wParam;
|
|
|
|
|
TempKeyEvent.native_key_code := Msg.lParam;
|
|
|
|
|
TempKeyEvent.is_system_key := ord(True);
|
|
|
|
|
TempKeyEvent.character := #0;
|
|
|
|
|
TempKeyEvent.unmodified_character := #0;
|
|
|
|
|
TempKeyEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
2020-04-10 09:49:34 +02:00
|
|
|
|
CefCheckAltGrPressed(Msg.wParam, TempKeyEvent);
|
2017-11-13 18:32:48 +01:00
|
|
|
|
chrmosr.SendKeyEvent(@TempKeyEvent);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
WM_SYSKEYDOWN :
|
2018-02-25 16:27:53 +01:00
|
|
|
|
if Panel1.Focused then
|
2017-07-18 17:50:28 +02:00
|
|
|
|
begin
|
2017-11-13 18:32:48 +01:00
|
|
|
|
TempKeyEvent.kind := KEYEVENT_RAWKEYDOWN;
|
|
|
|
|
TempKeyEvent.modifiers := GetCefKeyboardModifiers(Msg.wParam, Msg.lParam);
|
|
|
|
|
TempKeyEvent.windows_key_code := Msg.wParam;
|
|
|
|
|
TempKeyEvent.native_key_code := Msg.lParam;
|
|
|
|
|
TempKeyEvent.is_system_key := ord(True);
|
|
|
|
|
TempKeyEvent.character := #0;
|
|
|
|
|
TempKeyEvent.unmodified_character := #0;
|
|
|
|
|
TempKeyEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempKeyEvent);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
WM_SYSKEYUP :
|
2018-02-25 16:27:53 +01:00
|
|
|
|
if Panel1.Focused then
|
2017-07-18 17:50:28 +02:00
|
|
|
|
begin
|
2017-11-13 18:32:48 +01:00
|
|
|
|
TempKeyEvent.kind := KEYEVENT_KEYUP;
|
|
|
|
|
TempKeyEvent.modifiers := GetCefKeyboardModifiers(Msg.wParam, Msg.lParam);
|
|
|
|
|
TempKeyEvent.windows_key_code := Msg.wParam;
|
|
|
|
|
TempKeyEvent.native_key_code := Msg.lParam;
|
|
|
|
|
TempKeyEvent.is_system_key := ord(True);
|
|
|
|
|
TempKeyEvent.character := #0;
|
|
|
|
|
TempKeyEvent.unmodified_character := #0;
|
|
|
|
|
TempKeyEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempKeyEvent);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
WM_KEYDOWN :
|
2018-02-25 16:27:53 +01:00
|
|
|
|
if Panel1.Focused then
|
2017-07-18 17:50:28 +02:00
|
|
|
|
begin
|
2017-11-13 18:32:48 +01:00
|
|
|
|
TempKeyEvent.kind := KEYEVENT_RAWKEYDOWN;
|
|
|
|
|
TempKeyEvent.modifiers := GetCefKeyboardModifiers(Msg.wParam, Msg.lParam);
|
|
|
|
|
TempKeyEvent.windows_key_code := Msg.wParam;
|
|
|
|
|
TempKeyEvent.native_key_code := Msg.lParam;
|
|
|
|
|
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
|
|
|
|
Handled := (Msg.wParam in [VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN, VK_TAB]);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
WM_KEYUP :
|
2018-02-25 16:27:53 +01:00
|
|
|
|
if Panel1.Focused then
|
2017-07-18 17:50:28 +02:00
|
|
|
|
begin
|
2017-11-13 18:32:48 +01:00
|
|
|
|
TempKeyEvent.kind := KEYEVENT_KEYUP;
|
|
|
|
|
TempKeyEvent.modifiers := GetCefKeyboardModifiers(Msg.wParam, Msg.lParam);
|
|
|
|
|
TempKeyEvent.windows_key_code := Msg.wParam;
|
|
|
|
|
TempKeyEvent.native_key_code := Msg.lParam;
|
|
|
|
|
TempKeyEvent.is_system_key := ord(False);
|
|
|
|
|
TempKeyEvent.character := #0;
|
|
|
|
|
TempKeyEvent.unmodified_character := #0;
|
|
|
|
|
TempKeyEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempKeyEvent);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
WM_CHAR :
|
2017-11-13 18:32:48 +01:00
|
|
|
|
if Panel1.Focused then
|
2017-07-18 17:50:28 +02:00
|
|
|
|
begin
|
2017-11-13 18:32:48 +01:00
|
|
|
|
TempKeyEvent.kind := KEYEVENT_CHAR;
|
|
|
|
|
TempKeyEvent.modifiers := GetCefKeyboardModifiers(Msg.wParam, Msg.lParam);
|
|
|
|
|
TempKeyEvent.windows_key_code := Msg.wParam;
|
|
|
|
|
TempKeyEvent.native_key_code := Msg.lParam;
|
|
|
|
|
TempKeyEvent.is_system_key := ord(False);
|
|
|
|
|
TempKeyEvent.character := #0;
|
|
|
|
|
TempKeyEvent.unmodified_character := #0;
|
|
|
|
|
TempKeyEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
2020-04-10 09:49:34 +02:00
|
|
|
|
CefCheckAltGrPressed(Msg.wParam, TempKeyEvent);
|
2017-11-13 18:32:48 +01:00
|
|
|
|
chrmosr.SendKeyEvent(@TempKeyEvent);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
end;
|
2017-11-13 18:32:48 +01:00
|
|
|
|
|
|
|
|
|
WM_MOUSEWHEEL :
|
2020-03-31 12:44:10 +02:00
|
|
|
|
if Panel1.Focused then
|
2017-11-13 18:32:48 +01:00
|
|
|
|
begin
|
2021-01-29 18:27:10 +01:00
|
|
|
|
GetCursorPos(TempPoint);
|
|
|
|
|
TempPoint := Panel1.ScreenToclient(TempPoint);
|
|
|
|
|
TempMouseEvent.x := TempPoint.x;
|
|
|
|
|
TempMouseEvent.y := TempPoint.y;
|
2017-11-13 18:32:48 +01:00
|
|
|
|
TempMouseEvent.modifiers := GetCefMouseModifiers(Msg.wParam);
|
2021-01-29 18:27:10 +01:00
|
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
|
DeviceToLogical(TempMouseEvent, Panel1.ScreenScale);
|
2021-01-29 18:27:10 +01:00
|
|
|
|
|
|
|
|
|
if CefIsKeyDown(VK_SHIFT) then
|
|
|
|
|
chrmosr.SendMouseWheelEvent(@TempMouseEvent, smallint(Msg.wParam shr 16), 0)
|
|
|
|
|
else
|
|
|
|
|
chrmosr.SendMouseWheelEvent(@TempMouseEvent, 0, smallint(Msg.wParam shr 16));
|
2017-11-13 18:32:48 +01:00
|
|
|
|
end;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.GoBtnClick(Sender: TObject);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
2017-11-19 11:30:26 +01:00
|
|
|
|
FResizeCS.Acquire;
|
|
|
|
|
FResizing := False;
|
|
|
|
|
FPendingResize := False;
|
|
|
|
|
FResizeCS.Release;
|
|
|
|
|
|
2020-03-18 10:01:28 +01:00
|
|
|
|
chrmosr.LoadURL(AddressCb.Text);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-11-13 18:32:48 +01:00
|
|
|
|
procedure TForm1.GoBtnEnter(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.SendFocusEvent(False);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.chrmosrAfterCreated(Sender: TObject; const browser: ICefBrowser);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
2017-09-07 10:58:09 +02:00
|
|
|
|
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2018-02-19 13:35:01 +01:00
|
|
|
|
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-02-19 13:35:01 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-01-30 12:08:50 +01:00
|
|
|
|
procedure TForm1.chrmosrBeforePopup( Sender : TObject;
|
2018-02-16 18:41:13 +01:00
|
|
|
|
const browser : ICefBrowser;
|
|
|
|
|
const frame : ICefFrame;
|
|
|
|
|
const targetUrl : ustring;
|
|
|
|
|
const targetFrameName : ustring;
|
|
|
|
|
targetDisposition : TCefWindowOpenDisposition;
|
|
|
|
|
userGesture : Boolean;
|
2018-03-29 20:02:04 +02:00
|
|
|
|
const popupFeatures : TCefPopupFeatures;
|
2018-02-16 18:41:13 +01:00
|
|
|
|
var windowInfo : TCefWindowInfo;
|
|
|
|
|
var client : ICefClient;
|
|
|
|
|
var settings : TCefBrowserSettings;
|
2019-06-16 10:31:13 +02:00
|
|
|
|
var extra_info : ICefDictionaryValue;
|
2018-02-16 18:41:13 +01:00
|
|
|
|
var noJavascriptAccess : Boolean;
|
2018-03-29 20:02:04 +02:00
|
|
|
|
var Result : Boolean);
|
2018-02-16 18:41:13 +01:00
|
|
|
|
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;
|
|
|
|
|
|
2020-01-30 12:08:50 +01:00
|
|
|
|
procedure TForm1.chrmosrCursorChange( Sender : TObject;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
const browser : ICefBrowser;
|
2021-01-26 18:26:24 +01:00
|
|
|
|
cursor_ : TCefCursorHandle;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
cursorType : TCefCursorType;
|
2020-11-22 16:42:52 +01:00
|
|
|
|
const customCursorInfo : PCefCursorInfo;
|
|
|
|
|
var aResult : boolean);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
begin
|
2019-11-08 23:15:53 +01:00
|
|
|
|
Panel1.Cursor := CefCursorToWindowsCursor(cursorType);
|
2020-11-22 16:42:52 +01:00
|
|
|
|
aResult := True;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-01-30 12:08:50 +01:00
|
|
|
|
procedure TForm1.chrmosrGetScreenInfo( Sender : TObject;
|
2017-11-16 12:49:15 +01:00
|
|
|
|
const browser : ICefBrowser;
|
|
|
|
|
var screenInfo : TCefScreenInfo;
|
|
|
|
|
out Result : Boolean);
|
2017-07-28 12:47:57 +02:00
|
|
|
|
var
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempRect : TCEFRect;
|
|
|
|
|
TempScale : single;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempScale := Panel1.ScreenScale;
|
|
|
|
|
TempRect.x := 0;
|
|
|
|
|
TempRect.y := 0;
|
|
|
|
|
TempRect.width := DeviceToLogical(Panel1.Width, TempScale);
|
|
|
|
|
TempRect.height := DeviceToLogical(Panel1.Height, TempScale);
|
|
|
|
|
|
|
|
|
|
screenInfo.device_scale_factor := TempScale;
|
|
|
|
|
screenInfo.depth := 0;
|
|
|
|
|
screenInfo.depth_per_component := 0;
|
|
|
|
|
screenInfo.is_monochrome := Ord(False);
|
|
|
|
|
screenInfo.rect := TempRect;
|
|
|
|
|
screenInfo.available_rect := TempRect;
|
|
|
|
|
|
|
|
|
|
Result := True;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-01-30 12:08:50 +01:00
|
|
|
|
procedure TForm1.chrmosrGetScreenPoint( Sender : TObject;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
const browser : ICefBrowser;
|
|
|
|
|
viewX : Integer;
|
|
|
|
|
viewY : Integer;
|
2017-07-28 12:47:57 +02:00
|
|
|
|
var screenX : Integer;
|
|
|
|
|
var screenY : Integer;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
out Result : Boolean);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
var
|
|
|
|
|
TempScreenPt, TempViewPt : TPoint;
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempScale : single;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempScale := Panel1.ScreenScale;
|
|
|
|
|
TempViewPt.x := LogicalToDevice(viewX, TempScale);
|
|
|
|
|
TempViewPt.y := LogicalToDevice(viewY, TempScale);
|
|
|
|
|
TempScreenPt := Panel1.ClientToScreen(TempViewPt);
|
|
|
|
|
screenX := TempScreenPt.x;
|
|
|
|
|
screenY := TempScreenPt.y;
|
|
|
|
|
Result := True;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-01-30 12:08:50 +01:00
|
|
|
|
procedure TForm1.chrmosrGetViewRect( Sender : TObject;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
const browser : ICefBrowser;
|
2018-12-12 17:13:23 +01:00
|
|
|
|
var rect : TCefRect);
|
2020-03-31 12:44:10 +02:00
|
|
|
|
var
|
|
|
|
|
TempScale : single;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempScale := Panel1.ScreenScale;
|
|
|
|
|
rect.x := 0;
|
|
|
|
|
rect.y := 0;
|
|
|
|
|
rect.width := DeviceToLogical(Panel1.Width, TempScale);
|
|
|
|
|
rect.height := DeviceToLogical(Panel1.Height, TempScale);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2019-08-27 09:52:33 +02:00
|
|
|
|
procedure TForm1.chrmosrPaint( Sender : TObject;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
const browser : ICefBrowser;
|
|
|
|
|
kind : TCefPaintElementType;
|
|
|
|
|
dirtyRectsCount : NativeUInt;
|
|
|
|
|
const dirtyRects : PCefRectArray;
|
|
|
|
|
const buffer : Pointer;
|
|
|
|
|
width : Integer;
|
|
|
|
|
height : Integer);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
var
|
|
|
|
|
src, dst: PByte;
|
2017-11-16 12:49:15 +01:00
|
|
|
|
i, j, TempLineSize, TempSrcOffset, TempDstOffset, SrcStride, DstStride : Integer;
|
|
|
|
|
n : NativeUInt;
|
|
|
|
|
TempWidth, TempHeight, TempScanlineSize : integer;
|
|
|
|
|
TempBufferBits : Pointer;
|
2017-11-19 11:30:26 +01:00
|
|
|
|
TempForcedResize : boolean;
|
2020-03-18 18:37:55 +01:00
|
|
|
|
TempSrcRect : TRect;
|
2017-11-19 11:30:26 +01:00
|
|
|
|
begin
|
|
|
|
|
try
|
|
|
|
|
FResizeCS.Acquire;
|
|
|
|
|
TempForcedResize := False;
|
|
|
|
|
|
|
|
|
|
if Panel1.BeginBufferDraw then
|
|
|
|
|
begin
|
|
|
|
|
if (kind = PET_POPUP) then
|
|
|
|
|
begin
|
|
|
|
|
if (FPopUpBitmap = nil) or
|
|
|
|
|
(width <> FPopUpBitmap.Width) or
|
|
|
|
|
(height <> FPopUpBitmap.Height) then
|
|
|
|
|
begin
|
|
|
|
|
if (FPopUpBitmap <> nil) then FPopUpBitmap.Free;
|
|
|
|
|
|
|
|
|
|
FPopUpBitmap := TBitmap.Create;
|
|
|
|
|
FPopUpBitmap.PixelFormat := pf32bit;
|
|
|
|
|
FPopUpBitmap.HandleType := bmDIB;
|
|
|
|
|
FPopUpBitmap.Width := width;
|
|
|
|
|
FPopUpBitmap.Height := height;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TempWidth := FPopUpBitmap.Width;
|
|
|
|
|
TempHeight := FPopUpBitmap.Height;
|
|
|
|
|
TempScanlineSize := FPopUpBitmap.Width * SizeOf(TRGBQuad);
|
|
|
|
|
TempBufferBits := FPopUpBitmap.Scanline[pred(FPopUpBitmap.Height)];
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
TempForcedResize := Panel1.UpdateBufferDimensions(Width, Height) or not(Panel1.BufferIsResized(False));
|
|
|
|
|
TempWidth := Panel1.BufferWidth;
|
|
|
|
|
TempHeight := Panel1.BufferHeight;
|
|
|
|
|
TempScanlineSize := Panel1.ScanlineSize;
|
|
|
|
|
TempBufferBits := Panel1.BufferBits;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
if (TempBufferBits <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
SrcStride := Width * SizeOf(TRGBQuad);
|
|
|
|
|
DstStride := - TempScanlineSize;
|
|
|
|
|
|
|
|
|
|
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 * Width) + dirtyRects[n].x) * SizeOf(TRGBQuad);
|
|
|
|
|
TempDstOffset := ((TempScanlineSize * pred(TempHeight)) - (dirtyRects[n].y * TempScanlineSize)) +
|
|
|
|
|
(dirtyRects[n].x * SizeOf(TRGBQuad));
|
|
|
|
|
|
|
|
|
|
src := @PByte(buffer)[TempSrcOffset];
|
|
|
|
|
dst := @PByte(TempBufferBits)[TempDstOffset];
|
|
|
|
|
|
|
|
|
|
i := 0;
|
|
|
|
|
j := min(dirtyRects[n].height, TempHeight - dirtyRects[n].y);
|
|
|
|
|
|
|
|
|
|
while (i < j) do
|
|
|
|
|
begin
|
|
|
|
|
Move(src^, dst^, TempLineSize);
|
|
|
|
|
|
|
|
|
|
Inc(dst, DstStride);
|
|
|
|
|
Inc(src, SrcStride);
|
|
|
|
|
inc(i);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
inc(n);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
if FShowPopup and (FPopUpBitmap <> nil) then
|
2020-03-18 18:37:55 +01:00
|
|
|
|
begin
|
|
|
|
|
TempSrcRect := Rect(0, 0,
|
|
|
|
|
min(FPopUpRect.Right - FPopUpRect.Left, FPopUpBitmap.Width),
|
|
|
|
|
min(FPopUpRect.Bottom - FPopUpRect.Top, FPopUpBitmap.Height));
|
|
|
|
|
|
|
|
|
|
Panel1.BufferDraw(FPopUpBitmap, TempSrcRect, FPopUpRect);
|
|
|
|
|
end;
|
2017-11-19 11:30:26 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
Panel1.EndBufferDraw;
|
|
|
|
|
Panel1.InvalidatePanel;
|
|
|
|
|
|
|
|
|
|
if (kind = PET_VIEW) then
|
|
|
|
|
begin
|
|
|
|
|
if TempForcedResize or FPendingResize then PostMessage(Handle, CEF_PENDINGRESIZE, 0, 0);
|
|
|
|
|
|
|
|
|
|
FResizing := False;
|
|
|
|
|
FPendingResize := False;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
finally
|
|
|
|
|
FResizeCS.Release;
|
|
|
|
|
end;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-03-18 10:01:28 +01:00
|
|
|
|
procedure TForm1.chrmosrPopupShow( Sender : TObject;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
const browser : ICefBrowser;
|
2017-11-16 12:49:15 +01:00
|
|
|
|
show : Boolean);
|
2017-04-24 12:57:16 +02:00
|
|
|
|
begin
|
2017-11-16 12:49:15 +01:00
|
|
|
|
if show then
|
|
|
|
|
FShowPopUp := True
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
FShowPopUp := False;
|
|
|
|
|
FPopUpRect := rect(0, 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
if (chrmosr <> nil) then chrmosr.Invalidate(PET_VIEW);
|
|
|
|
|
end;
|
2017-04-24 12:57:16 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2020-03-18 10:01:28 +01:00
|
|
|
|
procedure TForm1.chrmosrPopupSize( Sender : TObject;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
const browser : ICefBrowser;
|
|
|
|
|
const rect : PCefRect);
|
2017-04-24 12:57:16 +02:00
|
|
|
|
begin
|
2020-03-31 12:44:10 +02:00
|
|
|
|
LogicalToDevice(rect^, Panel1.ScreenScale);
|
2017-11-16 12:49:15 +01:00
|
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
|
FPopUpRect.Left := rect.x;
|
|
|
|
|
FPopUpRect.Top := rect.y;
|
|
|
|
|
FPopUpRect.Right := rect.x + rect.width - 1;
|
|
|
|
|
FPopUpRect.Bottom := rect.y + rect.height - 1;
|
2017-04-24 12:57:16 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2018-02-01 18:57:54 +01:00
|
|
|
|
procedure TForm1.chrmosrTooltip(Sender: TObject; const browser: ICefBrowser; var text: ustring; out Result: Boolean);
|
|
|
|
|
begin
|
|
|
|
|
Panel1.hint := text;
|
|
|
|
|
Panel1.ShowHint := (length(text) > 0);
|
|
|
|
|
Result := True;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-03-18 10:01:28 +01:00
|
|
|
|
procedure TForm1.AddressCbEnter(Sender: TObject);
|
2017-11-13 18:32:48 +01:00
|
|
|
|
begin
|
|
|
|
|
chrmosr.SendFocusEvent(False);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-01-27 18:14:48 +01:00
|
|
|
|
function TForm1.getModifiers(Shift: TShiftState): TCefEventFlags;
|
|
|
|
|
begin
|
2017-07-18 17:50:28 +02:00
|
|
|
|
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;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TForm1.GetButton(Button: TMouseButton): TCefMouseButtonType;
|
|
|
|
|
begin
|
|
|
|
|
case Button of
|
2020-03-18 10:01:28 +01:00
|
|
|
|
mbRight : Result := MBT_RIGHT;
|
|
|
|
|
mbMiddle : Result := MBT_MIDDLE;
|
|
|
|
|
else Result := MBT_LEFT;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-04-24 12:57:16 +02:00
|
|
|
|
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;
|
|
|
|
|
|
2017-07-28 12:47:57 +02:00
|
|
|
|
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;
|
|
|
|
|
|
2017-12-18 19:38:56 +01:00
|
|
|
|
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;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.BrowserCreatedMsg(var aMessage : TMessage);
|
|
|
|
|
begin
|
2017-11-13 18:32:48 +01:00
|
|
|
|
Caption := 'Simple OSR Browser';
|
2017-07-18 17:50:28 +02:00
|
|
|
|
NavControlPnl.Enabled := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
|
2017-04-24 12:57:16 +02:00
|
|
|
|
begin
|
2020-10-31 14:23:06 +01:00
|
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
|
GlobalCEFApp.UpdateDeviceScaleFactor;
|
|
|
|
|
|
2017-04-24 12:57:16 +02:00
|
|
|
|
if (chrmosr <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.NotifyScreenInfoChanged;
|
|
|
|
|
chrmosr.WasResized;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2018-02-19 13:35:01 +01:00
|
|
|
|
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;
|
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
|
procedure TForm1.FormCreate(Sender: TObject);
|
2020-02-08 12:59:59 +01:00
|
|
|
|
var
|
|
|
|
|
TempMajorVer, TempMinorVer : DWORD;
|
2017-11-16 12:49:15 +01:00
|
|
|
|
begin
|
2017-11-19 11:30:26 +01:00
|
|
|
|
FPopUpBitmap := nil;
|
|
|
|
|
FPopUpRect := rect(0, 0, 0, 0);
|
|
|
|
|
FShowPopUp := False;
|
|
|
|
|
FResizing := False;
|
|
|
|
|
FPendingResize := False;
|
2018-02-19 13:35:01 +01:00
|
|
|
|
FCanClose := False;
|
|
|
|
|
FClosing := False;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
FDeviceBounds := nil;
|
|
|
|
|
|
2020-02-08 12:59:59 +01:00
|
|
|
|
FAtLeastWin8 := GetWindowsMajorMinorVersion(TempMajorVer, TempMinorVer) and
|
|
|
|
|
((TempMajorVer > 6) or
|
|
|
|
|
((TempMajorVer = 6) and (TempMinorVer >= 2)));
|
|
|
|
|
|
2019-01-08 19:15:25 +01:00
|
|
|
|
FSelectedRange.from := 0;
|
|
|
|
|
FSelectedRange.to_ := 0;
|
|
|
|
|
|
2017-11-19 11:30:26 +01:00
|
|
|
|
FResizeCS := TCriticalSection.Create;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
FIMECS := TCriticalSection.Create;
|
2018-02-25 13:10:21 +01:00
|
|
|
|
|
2019-02-20 12:44:07 +01:00
|
|
|
|
Panel1.Transparent := TRANSPARENT_BROWSER;
|
|
|
|
|
|
2018-02-25 13:10:21 +01:00
|
|
|
|
InitializeLastClick;
|
2020-03-18 10:01:28 +01:00
|
|
|
|
|
|
|
|
|
chrmosr.DefaultURL := trim(AddressCb.Text);
|
2017-11-16 12:49:15 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.FormDestroy(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.ShutdownDragAndDrop;
|
2017-11-16 12:49:15 +01:00
|
|
|
|
|
|
|
|
|
if (FPopUpBitmap <> nil) then FreeAndNil(FPopUpBitmap);
|
2019-01-08 19:15:25 +01:00
|
|
|
|
if (FResizeCS <> nil) then FreeAndNil(FResizeCS);
|
|
|
|
|
if (FIMECS <> nil) then FreeAndNil(FIMECS);
|
|
|
|
|
|
|
|
|
|
if (FDeviceBounds <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
Finalize(FDeviceBounds);
|
|
|
|
|
FDeviceBounds := nil;
|
|
|
|
|
end;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.FormHide(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.SendFocusEvent(False);
|
|
|
|
|
chrmosr.WasHidden(True);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.FormShow(Sender: TObject);
|
|
|
|
|
begin
|
2017-10-29 17:18:27 +01:00
|
|
|
|
if chrmosr.Initialized then
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.WasHidden(False);
|
|
|
|
|
chrmosr.SendFocusEvent(True);
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
begin
|
2019-02-20 12:44:07 +01:00
|
|
|
|
// If you need transparency leave the chrmosr.Options.BackgroundColor property
|
|
|
|
|
// with the default value or set the alpha channel to 0
|
|
|
|
|
if TRANSPARENT_BROWSER then
|
2020-07-21 13:05:08 +02:00
|
|
|
|
chrmosr.Options.BackgroundColor := CefColorSetARGB($00, $00, $00, $00)
|
2019-02-20 12:44:07 +01:00
|
|
|
|
else
|
|
|
|
|
chrmosr.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF);
|
2017-11-04 18:32:29 +01:00
|
|
|
|
|
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;
|
|
|
|
|
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$IFDEF DELPHI14_UP}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
if not(ArePointerEventsSupported) then
|
|
|
|
|
RegisterTouchWindow(Panel1.Handle, 0);
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$ENDIF}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
|
2017-11-04 18:32:29 +01:00
|
|
|
|
if chrmosr.CreateBrowser(nil, '') then
|
2017-11-16 12:49:15 +01:00
|
|
|
|
chrmosr.InitializeDragAndDrop(Panel1)
|
2017-11-04 18:32:29 +01:00
|
|
|
|
else
|
|
|
|
|
Timer1.Enabled := True;
|
2017-10-29 17:18:27 +01:00
|
|
|
|
end;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
|
procedure TForm1.Panel1Click(Sender: TObject);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
begin
|
|
|
|
|
Panel1.SetFocus;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-02-03 12:02:30 +01:00
|
|
|
|
procedure TForm1.Panel1CustomTouch(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$IFDEF DELPHI14_UP}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
var
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempScale : single;
|
2020-02-03 12:02:30 +01:00
|
|
|
|
TempTouchEvent : TCefTouchEvent;
|
|
|
|
|
TempHTOUCHINPUT : HTOUCHINPUT;
|
|
|
|
|
TempNumPoints : integer;
|
|
|
|
|
i : integer;
|
|
|
|
|
TempTouchInputs : array of TTouchInput;
|
|
|
|
|
TempPoint : TPoint;
|
|
|
|
|
TempLParam : LPARAM;
|
|
|
|
|
TempResult : LRESULT;
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$ENDIF}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
begin
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$IFDEF DELPHI14_UP}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
if not(Panel1.Focused) or (GlobalCEFApp = nil) then exit;
|
|
|
|
|
|
|
|
|
|
TempNumPoints := LOWORD(aMessage.wParam);
|
|
|
|
|
|
|
|
|
|
// Chromium only supports upto 16 touch points.
|
|
|
|
|
if (TempNumPoints < 1) or (TempNumPoints > 16) then exit;
|
|
|
|
|
|
|
|
|
|
SetLength(TempTouchInputs, TempNumPoints);
|
|
|
|
|
TempHTOUCHINPUT := HTOUCHINPUT(aMessage.lParam);
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempScale := Panel1.ScreenScale;
|
2020-02-03 12:02:30 +01:00
|
|
|
|
|
|
|
|
|
if GetTouchInputInfo(TempHTOUCHINPUT, TempNumPoints, @TempTouchInputs[0], SizeOf(TTouchInput)) then
|
|
|
|
|
begin
|
|
|
|
|
i := 0;
|
|
|
|
|
while (i < TempNumPoints) do
|
|
|
|
|
begin
|
|
|
|
|
TempPoint := TouchPointToPoint(Panel1.Handle, TempTouchInputs[i]);
|
|
|
|
|
|
2020-02-08 12:59:59 +01:00
|
|
|
|
if not(FAtLeastWin8) then
|
2020-02-03 12:02:30 +01:00
|
|
|
|
begin
|
|
|
|
|
// Windows 7 sends touch events for touches in the non-client area,
|
|
|
|
|
// whereas Windows 8 does not. In order to unify the behaviour, always
|
|
|
|
|
// ignore touch events in the non-client area.
|
|
|
|
|
|
|
|
|
|
TempLParam := MakeLParam(TempPoint.x, TempPoint.y);
|
|
|
|
|
TempResult := SendMessage(Panel1.Handle, WM_NCHITTEST, 0, TempLParam);
|
|
|
|
|
|
|
|
|
|
if (TempResult <> HTCLIENT) then
|
|
|
|
|
begin
|
|
|
|
|
SetLength(TempTouchInputs, 0);
|
|
|
|
|
exit;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TempPoint := Panel1.ScreenToClient(TempPoint);
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempTouchEvent.x := DeviceToLogical(TempPoint.x, TempScale);
|
|
|
|
|
TempTouchEvent.y := DeviceToLogical(TempPoint.y, TempScale);
|
2020-02-03 12:02:30 +01:00
|
|
|
|
|
|
|
|
|
// Touch point identifier stays consistent in a touch contact sequence
|
|
|
|
|
TempTouchEvent.id := TempTouchInputs[i].dwID;
|
|
|
|
|
|
|
|
|
|
if ((TempTouchInputs[i].dwFlags and TOUCHEVENTF_DOWN) <> 0) then TempTouchEvent.type_ := CEF_TET_PRESSED
|
|
|
|
|
else if ((TempTouchInputs[i].dwFlags and TOUCHEVENTF_MOVE) <> 0) then TempTouchEvent.type_ := CEF_TET_MOVED
|
|
|
|
|
else if ((TempTouchInputs[i].dwFlags and TOUCHEVENTF_UP) <> 0) then TempTouchEvent.type_ := CEF_TET_RELEASED;
|
|
|
|
|
|
|
|
|
|
TempTouchEvent.radius_x := 0;
|
|
|
|
|
TempTouchEvent.radius_y := 0;
|
|
|
|
|
TempTouchEvent.rotation_angle := 0;
|
|
|
|
|
TempTouchEvent.pressure := 0;
|
|
|
|
|
TempTouchEvent.modifiers := EVENTFLAG_NONE;
|
|
|
|
|
TempTouchEvent.pointer_type := CEF_POINTER_TYPE_TOUCH;
|
|
|
|
|
|
|
|
|
|
chrmosr.SendTouchEvent(@TempTouchEvent);
|
|
|
|
|
|
|
|
|
|
inc(i);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
CloseTouchInputHandle(TempHTOUCHINPUT);
|
|
|
|
|
aHandled := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
SetLength(TempTouchInputs, 0);
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$ENDIF}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
|
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
var
|
2017-07-18 17:50:28 +02:00
|
|
|
|
TempEvent : TCefMouseEvent;
|
2018-02-25 13:10:21 +01:00
|
|
|
|
TempTime : integer;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
2020-03-31 12:44:10 +02:00
|
|
|
|
{$IFDEF DELPHI14_UP}
|
|
|
|
|
if (ssTouch in Shift) then exit;
|
|
|
|
|
{$ENDIF}
|
2018-02-25 13:10:21 +01:00
|
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
|
Panel1.SetFocus;
|
2018-02-25 13:10:21 +01:00
|
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
|
if not(CancelPreviousClick(x, y, TempTime)) and (Button = FLastClickButton) then
|
|
|
|
|
inc(FLastClickCount)
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
FLastClickPoint.x := x;
|
|
|
|
|
FLastClickPoint.y := y;
|
|
|
|
|
FLastClickCount := 1;
|
2017-07-28 12:47:57 +02:00
|
|
|
|
end;
|
2020-03-31 12:44:10 +02:00
|
|
|
|
|
|
|
|
|
FLastClickTime := TempTime;
|
|
|
|
|
FLastClickButton := Button;
|
|
|
|
|
|
|
|
|
|
TempEvent.x := X;
|
|
|
|
|
TempEvent.y := Y;
|
|
|
|
|
TempEvent.modifiers := getModifiers(Shift);
|
|
|
|
|
DeviceToLogical(TempEvent, Panel1.ScreenScale);
|
|
|
|
|
chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), False, FLastClickCount);
|
2017-07-28 12:47:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
|
procedure TForm1.Panel1MouseLeave(Sender: TObject);
|
2017-07-28 12:47:57 +02:00
|
|
|
|
var
|
|
|
|
|
TempEvent : TCefMouseEvent;
|
|
|
|
|
TempPoint : TPoint;
|
2018-02-25 13:10:21 +01:00
|
|
|
|
TempTime : integer;
|
2017-07-28 12:47:57 +02:00
|
|
|
|
begin
|
2020-03-31 12:44:10 +02:00
|
|
|
|
GetCursorPos(TempPoint);
|
|
|
|
|
TempPoint := Panel1.ScreenToclient(TempPoint);
|
2018-02-25 13:10:21 +01:00
|
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
|
if CancelPreviousClick(TempPoint.x, TempPoint.y, TempTime) then InitializeLastClick;
|
2018-02-25 13:10:21 +01:00
|
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempEvent.x := TempPoint.x;
|
|
|
|
|
TempEvent.y := TempPoint.y;
|
|
|
|
|
TempEvent.modifiers := GetCefMouseModifiers;
|
|
|
|
|
DeviceToLogical(TempEvent, Panel1.ScreenScale);
|
|
|
|
|
chrmosr.SendMouseMoveEvent(@TempEvent, True);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
|
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
var
|
2017-07-18 17:50:28 +02:00
|
|
|
|
TempEvent : TCefMouseEvent;
|
2018-02-25 13:10:21 +01:00
|
|
|
|
TempTime : integer;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
2020-03-31 12:44:10 +02:00
|
|
|
|
{$IFDEF DELPHI14_UP}
|
|
|
|
|
if (ssTouch in Shift) then exit;
|
|
|
|
|
{$ENDIF}
|
2018-02-25 13:10:21 +01:00
|
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
|
if CancelPreviousClick(x, y, TempTime) then InitializeLastClick;
|
|
|
|
|
|
|
|
|
|
TempEvent.x := x;
|
|
|
|
|
TempEvent.y := y;
|
|
|
|
|
TempEvent.modifiers := getModifiers(Shift);
|
|
|
|
|
DeviceToLogical(TempEvent, Panel1.ScreenScale);
|
|
|
|
|
chrmosr.SendMouseMoveEvent(@TempEvent, False);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
|
procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
var
|
2017-07-18 17:50:28 +02:00
|
|
|
|
TempEvent : TCefMouseEvent;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
2020-03-31 12:44:10 +02:00
|
|
|
|
{$IFDEF DELPHI14_UP}
|
|
|
|
|
if (ssTouch in Shift) then exit;
|
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
|
|
TempEvent.x := X;
|
|
|
|
|
TempEvent.y := Y;
|
|
|
|
|
TempEvent.modifiers := getModifiers(Shift);
|
|
|
|
|
DeviceToLogical(TempEvent, Panel1.ScreenScale);
|
|
|
|
|
chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), True, FLastClickCount);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2019-02-20 12:44:07 +01:00
|
|
|
|
procedure TForm1.Panel1PaintParentBkg(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
// This event should only be used if you enabled transparency in the browser
|
|
|
|
|
if TRANSPARENT_BROWSER then
|
|
|
|
|
begin
|
|
|
|
|
// This event should copy the background image into Panel1.Canvas
|
|
|
|
|
// The TBufferPanel uses "AlphaBlend" to draw the browser contents over
|
|
|
|
|
// this background image.
|
|
|
|
|
// For simplicity, we just paint it green.
|
|
|
|
|
Panel1.Canvas.Brush.Color := clGreen;
|
|
|
|
|
Panel1.Canvas.Brush.Style := bsSolid;
|
|
|
|
|
Panel1.Canvas.FillRect(Rect(0, 0, Panel1.Width, Panel1.Height));
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-02-03 12:02:30 +01:00
|
|
|
|
procedure TForm1.Panel1PointerDown(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
|
|
|
|
|
begin
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$IFDEF DELPHI14_UP}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
aHandled := Panel1.Focused and
|
|
|
|
|
(GlobalCEFApp <> nil) and
|
|
|
|
|
ArePointerEventsSupported and
|
|
|
|
|
HandlePointerEvent(aMessage);
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$ELSE}
|
|
|
|
|
aHandled := False;
|
|
|
|
|
{$ENDIF}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1PointerUp(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
|
|
|
|
|
begin
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$IFDEF DELPHI14_UP}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
aHandled := Panel1.Focused and
|
|
|
|
|
(GlobalCEFApp <> nil) and
|
|
|
|
|
ArePointerEventsSupported and
|
|
|
|
|
HandlePointerEvent(aMessage);
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$ELSE}
|
|
|
|
|
aHandled := False;
|
|
|
|
|
{$ENDIF}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.Panel1PointerUpdate(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
|
|
|
|
|
begin
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$IFDEF DELPHI14_UP}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
aHandled := Panel1.Focused and
|
|
|
|
|
(GlobalCEFApp <> nil) and
|
|
|
|
|
ArePointerEventsSupported and
|
|
|
|
|
HandlePointerEvent(aMessage);
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$ELSE}
|
|
|
|
|
aHandled := False;
|
|
|
|
|
{$ENDIF}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$IFDEF DELPHI14_UP}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
function TForm1.HandlePointerEvent(var aMessage : TMessage) : boolean;
|
|
|
|
|
const
|
|
|
|
|
PT_TOUCH = 2;
|
|
|
|
|
PT_PEN = 3;
|
|
|
|
|
var
|
|
|
|
|
TempID : uint32;
|
|
|
|
|
TempType : POINTER_INPUT_TYPE;
|
|
|
|
|
begin
|
|
|
|
|
Result := False;
|
|
|
|
|
TempID := LoWord(aMessage.wParam);
|
|
|
|
|
|
|
|
|
|
if GetPointerType(TempID, @TempType) then
|
|
|
|
|
case TempType of
|
|
|
|
|
PT_PEN : Result := HandlePenEvent(TempID, aMessage.Msg);
|
|
|
|
|
PT_TOUCH : Result := HandleTouchEvent(TempID, aMessage.Msg);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TForm1.HandlePenEvent(const aID : uint32; aMsg : cardinal) : boolean;
|
|
|
|
|
var
|
|
|
|
|
TempPenInfo : POINTER_PEN_INFO;
|
|
|
|
|
TempTouchEvent : TCefTouchEvent;
|
|
|
|
|
TempPoint : TPoint;
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempScale : single;
|
2020-02-03 12:02:30 +01:00
|
|
|
|
begin
|
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
|
|
if not(GetPointerPenInfo(aID, @TempPenInfo)) then exit;
|
|
|
|
|
|
|
|
|
|
TempTouchEvent.id := aID;
|
|
|
|
|
TempTouchEvent.x := 0;
|
|
|
|
|
TempTouchEvent.y := 0;
|
|
|
|
|
TempTouchEvent.radius_x := 0;
|
|
|
|
|
TempTouchEvent.radius_y := 0;
|
|
|
|
|
TempTouchEvent.type_ := CEF_TET_RELEASED;
|
|
|
|
|
TempTouchEvent.modifiers := EVENTFLAG_NONE;
|
|
|
|
|
|
|
|
|
|
if ((TempPenInfo.penFlags and PEN_FLAG_ERASER) <> 0) then
|
|
|
|
|
TempTouchEvent.pointer_type := CEF_POINTER_TYPE_ERASER
|
|
|
|
|
else
|
|
|
|
|
TempTouchEvent.pointer_type := CEF_POINTER_TYPE_PEN;
|
|
|
|
|
|
|
|
|
|
if ((TempPenInfo.penMask and PEN_MASK_PRESSURE) <> 0) then
|
|
|
|
|
TempTouchEvent.pressure := TempPenInfo.pressure / 1024
|
|
|
|
|
else
|
|
|
|
|
TempTouchEvent.pressure := 0;
|
|
|
|
|
|
|
|
|
|
if ((TempPenInfo.penMask and PEN_MASK_ROTATION) <> 0) then
|
2020-02-08 12:59:59 +01:00
|
|
|
|
TempTouchEvent.rotation_angle := TempPenInfo.rotation / 180 * Pi
|
2020-02-03 12:02:30 +01:00
|
|
|
|
else
|
|
|
|
|
TempTouchEvent.rotation_angle := 0;
|
|
|
|
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
|
|
|
|
case aMsg of
|
|
|
|
|
WM_POINTERDOWN :
|
|
|
|
|
TempTouchEvent.type_ := CEF_TET_PRESSED;
|
|
|
|
|
|
|
|
|
|
WM_POINTERUPDATE :
|
|
|
|
|
if ((TempPenInfo.pointerInfo.pointerFlags and POINTER_FLAG_INCONTACT) <> 0) then
|
|
|
|
|
TempTouchEvent.type_ := CEF_TET_MOVED
|
|
|
|
|
else
|
|
|
|
|
exit; // Ignore hover events.
|
|
|
|
|
|
|
|
|
|
WM_POINTERUP :
|
|
|
|
|
TempTouchEvent.type_ := CEF_TET_RELEASED;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
if ((TempPenInfo.pointerInfo.pointerFlags and POINTER_FLAG_CANCELED) <> 0) then
|
|
|
|
|
TempTouchEvent.type_ := CEF_TET_CANCELLED;
|
|
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempScale := Panel1.ScreenScale;
|
2020-02-03 12:02:30 +01:00
|
|
|
|
TempPoint := Panel1.ScreenToClient(TempPenInfo.pointerInfo.ptPixelLocation);
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempTouchEvent.x := DeviceToLogical(TempPoint.x, TempScale);
|
|
|
|
|
TempTouchEvent.y := DeviceToLogical(TempPoint.y, TempScale);
|
2020-02-03 12:02:30 +01:00
|
|
|
|
|
|
|
|
|
chrmosr.SendTouchEvent(@TempTouchEvent);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TForm1.HandleTouchEvent(const aID : uint32; aMsg : cardinal) : boolean;
|
|
|
|
|
var
|
|
|
|
|
TempTouchInfo : POINTER_TOUCH_INFO;
|
|
|
|
|
TempTouchEvent : TCefTouchEvent;
|
|
|
|
|
TempPoint : TPoint;
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempScale : single;
|
2020-02-03 12:02:30 +01:00
|
|
|
|
begin
|
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
|
|
if not(GetPointerTouchInfo(aID, @TempTouchInfo)) then exit;
|
|
|
|
|
|
|
|
|
|
TempTouchEvent.id := aID;
|
|
|
|
|
TempTouchEvent.x := 0;
|
|
|
|
|
TempTouchEvent.y := 0;
|
|
|
|
|
TempTouchEvent.radius_x := 0;
|
|
|
|
|
TempTouchEvent.radius_y := 0;
|
|
|
|
|
TempTouchEvent.rotation_angle := 0;
|
|
|
|
|
TempTouchEvent.pressure := 0;
|
|
|
|
|
TempTouchEvent.type_ := CEF_TET_RELEASED;
|
|
|
|
|
TempTouchEvent.modifiers := EVENTFLAG_NONE;
|
|
|
|
|
TempTouchEvent.pointer_type := CEF_POINTER_TYPE_TOUCH;
|
|
|
|
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
|
|
|
|
case aMsg of
|
|
|
|
|
WM_POINTERDOWN :
|
|
|
|
|
TempTouchEvent.type_ := CEF_TET_PRESSED;
|
|
|
|
|
|
|
|
|
|
WM_POINTERUPDATE :
|
|
|
|
|
if ((TempTouchInfo.pointerInfo.pointerFlags and POINTER_FLAG_INCONTACT) <> 0) then
|
|
|
|
|
TempTouchEvent.type_ := CEF_TET_MOVED
|
|
|
|
|
else
|
|
|
|
|
exit; // Ignore hover events.
|
|
|
|
|
|
|
|
|
|
WM_POINTERUP :
|
|
|
|
|
TempTouchEvent.type_ := CEF_TET_RELEASED;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
if ((TempTouchInfo.pointerInfo.pointerFlags and POINTER_FLAG_CANCELED) <> 0) then
|
|
|
|
|
TempTouchEvent.type_ := CEF_TET_CANCELLED;
|
|
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempScale := Panel1.ScreenScale;
|
2020-02-03 12:02:30 +01:00
|
|
|
|
TempPoint := Panel1.ScreenToClient(TempTouchInfo.pointerInfo.ptPixelLocation);
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempTouchEvent.x := DeviceToLogical(TempPoint.x, TempScale);
|
|
|
|
|
TempTouchEvent.y := DeviceToLogical(TempPoint.y, TempScale);
|
2020-02-03 12:02:30 +01:00
|
|
|
|
|
|
|
|
|
chrmosr.SendTouchEvent(@TempTouchEvent);
|
|
|
|
|
end;
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$ENDIF}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
|
procedure TForm1.Panel1Resize(Sender: TObject);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
2017-11-19 11:30:26 +01:00
|
|
|
|
DoResize;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.PendingResizeMsg(var aMessage : TMessage);
|
|
|
|
|
begin
|
|
|
|
|
DoResize;
|
|
|
|
|
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;
|
|
|
|
|
|
2017-11-19 11:30:26 +01: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;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2018-02-25 13:10:21 +01:00
|
|
|
|
procedure TForm1.InitializeLastClick;
|
|
|
|
|
begin
|
2020-02-26 13:28:29 +01:00
|
|
|
|
FLastClickCount := 1;
|
2018-02-25 13:10:21 +01: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;
|
|
|
|
|
|
2020-02-03 12:02:30 +01:00
|
|
|
|
function TForm1.ArePointerEventsSupported : boolean;
|
|
|
|
|
begin
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$IFDEF DELPHI14_UP}
|
2020-02-08 12:59:59 +01:00
|
|
|
|
Result := FAtLeastWin8 and
|
|
|
|
|
(@GetPointerType <> nil) and
|
2020-02-03 12:02:30 +01:00
|
|
|
|
(@GetPointerTouchInfo <> nil) and
|
|
|
|
|
(@GetPointerPenInfo <> nil);
|
2020-03-18 10:01:28 +01:00
|
|
|
|
{$ELSE}
|
|
|
|
|
Result := False;
|
|
|
|
|
{$ENDIF}
|
2020-02-03 12:02:30 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.Panel1Enter(Sender: TObject);
|
|
|
|
|
begin
|
2017-01-27 18:14:48 +01:00
|
|
|
|
chrmosr.SendFocusEvent(True);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.Panel1Exit(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.SendFocusEvent(False);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-09-07 10:58:09 +02:00
|
|
|
|
procedure TForm1.SnapshotBtnClick(Sender: TObject);
|
|
|
|
|
begin
|
2017-11-16 12:49:15 +01:00
|
|
|
|
if SaveDialog1.Execute then Panel1.SaveToFile(SaveDialog1.FileName);
|
2017-09-07 10:58:09 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2017-11-13 18:32:48 +01:00
|
|
|
|
procedure TForm1.SnapshotBtnEnter(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.SendFocusEvent(False);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-11-04 18:32:29 +01:00
|
|
|
|
procedure TForm1.Timer1Timer(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
Timer1.Enabled := False;
|
|
|
|
|
|
|
|
|
|
if chrmosr.CreateBrowser(nil, '') then
|
2017-11-16 12:49:15 +01:00
|
|
|
|
chrmosr.InitializeDragAndDrop(Panel1)
|
2017-11-04 18:32:29 +01:00
|
|
|
|
else
|
2017-11-16 12:49:15 +01:00
|
|
|
|
if not(chrmosr.Initialized) then Timer1.Enabled := True;
|
2017-11-04 18:32:29 +01:00
|
|
|
|
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;
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempScale : single;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
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;
|
2020-03-31 12:44:10 +02:00
|
|
|
|
TempScale := Panel1.ScreenScale;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
|
|
|
|
|
while (i < character_boundsCount) do
|
|
|
|
|
begin
|
|
|
|
|
FDeviceBounds[i] := TempPRect^;
|
2020-03-31 12:44:10 +02:00
|
|
|
|
LogicalToDevice(FDeviceBounds[i], TempScale);
|
2019-01-08 19:15:25 +01:00
|
|
|
|
|
|
|
|
|
inc(TempPRect);
|
|
|
|
|
inc(i);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
PostMessage(Handle, CEF_IMERANGECHANGED, 0, 0);
|
|
|
|
|
finally
|
|
|
|
|
FIMECS.Release;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end.
|