2017-01-27 18:14:48 +01:00
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
//
|
|
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
|
|
|
|
|
// 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
|
|
|
|
|
//
|
|
|
|
|
// Copyright <20> 2017 Salvador D<>az Fau. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ************ 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-02-11 21:56:08 +01:00
|
|
|
|
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.AppEvnts,
|
|
|
|
|
{$ELSE}
|
|
|
|
|
Windows, Messages, SysUtils, Variants, Classes,
|
|
|
|
|
Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, AppEvnts,
|
|
|
|
|
{$ENDIF}
|
|
|
|
|
GR32_Image, // You need the Graphics32 components for this demo available at http://graphics32.org
|
2017-09-07 10:58:09 +02:00
|
|
|
|
uCEFChromium, uCEFTypes, uCEFInterfaces, uCEFConstants;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
|
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;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
Panel1: TPanel; // This is just a quick and dirty hack to receive some events that the PaintBox can't receive.
|
|
|
|
|
PaintBox: TPaintBox32;
|
|
|
|
|
ComboBox1: 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-07-28 12:47:57 +02:00
|
|
|
|
|
|
|
|
|
procedure AppEventsMessage(var Msg: tagMSG; var Handled: Boolean);
|
|
|
|
|
|
|
|
|
|
procedure GoBtnClick(Sender: TObject);
|
|
|
|
|
|
|
|
|
|
procedure Panel1Enter(Sender: TObject);
|
|
|
|
|
procedure Panel1Exit(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 FormDestroy(Sender: TObject);
|
|
|
|
|
procedure FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
|
|
|
|
|
|
|
|
|
|
procedure PaintBoxClick(Sender: TObject);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
procedure PaintBoxResize(Sender: TObject);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure PaintBoxMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
|
|
|
|
procedure PaintBoxMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
|
|
|
|
procedure PaintBoxMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
2017-07-28 12:47:57 +02:00
|
|
|
|
procedure PaintBoxMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
|
|
|
|
|
procedure PaintBoxMouseLeave(Sender: TObject);
|
|
|
|
|
|
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);
|
|
|
|
|
procedure chrmosrCursorChange(Sender: TObject; const browser: ICefBrowser; cursor: HICON; cursorType: TCefCursorType; const customCursorInfo: PCefCursorInfo);
|
2017-07-28 12:47:57 +02:00
|
|
|
|
procedure chrmosrGetViewRect(Sender: TObject; const browser: ICefBrowser; var rect: TCefRect; out Result: Boolean);
|
|
|
|
|
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);
|
2017-09-07 10:58:09 +02:00
|
|
|
|
procedure SnapshotBtnClick(Sender: TObject);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
|
2017-01-27 18:14:48 +01:00
|
|
|
|
private
|
2017-07-18 17:50:28 +02:00
|
|
|
|
function getModifiers(Shift: TShiftState): TCefEventFlags;
|
|
|
|
|
function GetButton(Button: TMouseButton): TCefMouseButtonType;
|
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-09-07 10:58:09 +02:00
|
|
|
|
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
2017-04-24 12:57:16 +02:00
|
|
|
|
|
2017-01-27 18:14:48 +01:00
|
|
|
|
public
|
|
|
|
|
{ Public declarations }
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
Form1: TForm1;
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
2017-06-06 12:49:27 +02:00
|
|
|
|
uses
|
2017-10-03 14:38:37 +02:00
|
|
|
|
uCEFMiscFunctions, uCEFApplication;
|
2017-06-06 12:49:27 +02:00
|
|
|
|
|
2017-01-27 18:14:48 +01:00
|
|
|
|
procedure TForm1.AppEventsMessage(var Msg: tagMSG; var Handled: Boolean);
|
|
|
|
|
var
|
2017-07-18 17:50:28 +02:00
|
|
|
|
TempEvent : TCefKeyEvent;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
|
|
|
|
case Msg.message of
|
2017-07-18 17:50:28 +02:00
|
|
|
|
WM_SYSCHAR :
|
|
|
|
|
if (Panel1.Focused or chrmosr.FrameIsFocused) and
|
|
|
|
|
(Msg.wParam in [VK_BACK..VK_HELP]) then
|
|
|
|
|
begin
|
|
|
|
|
TempEvent.kind := KEYEVENT_CHAR;
|
|
|
|
|
TempEvent.modifiers := GetCefKeyboardModifiers(Msg.wParam, Msg.lParam);
|
|
|
|
|
TempEvent.windows_key_code := Msg.wParam;
|
|
|
|
|
TempEvent.native_key_code := Msg.lParam;
|
|
|
|
|
TempEvent.is_system_key := ord(True);
|
|
|
|
|
TempEvent.character := #0;
|
|
|
|
|
TempEvent.unmodified_character := #0;
|
|
|
|
|
TempEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempEvent);
|
|
|
|
|
Handled := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
WM_SYSKEYDOWN :
|
|
|
|
|
if (Panel1.Focused or chrmosr.FrameIsFocused) and
|
|
|
|
|
(Msg.wParam in [VK_BACK..VK_HELP]) then
|
|
|
|
|
begin
|
|
|
|
|
TempEvent.kind := KEYEVENT_RAWKEYDOWN;
|
|
|
|
|
TempEvent.modifiers := GetCefKeyboardModifiers(Msg.wParam, Msg.lParam);
|
|
|
|
|
TempEvent.windows_key_code := Msg.wParam;
|
|
|
|
|
TempEvent.native_key_code := Msg.lParam;
|
|
|
|
|
TempEvent.is_system_key := ord(True);
|
|
|
|
|
TempEvent.character := #0;
|
|
|
|
|
TempEvent.unmodified_character := #0;
|
|
|
|
|
TempEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempEvent);
|
|
|
|
|
Handled := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
WM_SYSKEYUP :
|
|
|
|
|
if (Panel1.Focused or chrmosr.FrameIsFocused) and
|
|
|
|
|
(Msg.wParam in [VK_BACK..VK_HELP]) then
|
|
|
|
|
begin
|
|
|
|
|
TempEvent.kind := KEYEVENT_KEYUP;
|
|
|
|
|
TempEvent.modifiers := GetCefKeyboardModifiers(Msg.wParam, Msg.lParam);
|
|
|
|
|
TempEvent.windows_key_code := Msg.wParam;
|
|
|
|
|
TempEvent.native_key_code := Msg.lParam;
|
|
|
|
|
TempEvent.is_system_key := ord(True);
|
|
|
|
|
TempEvent.character := #0;
|
|
|
|
|
TempEvent.unmodified_character := #0;
|
|
|
|
|
TempEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempEvent);
|
|
|
|
|
Handled := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
WM_KEYDOWN :
|
|
|
|
|
if (Panel1.Focused or chrmosr.FrameIsFocused) and
|
|
|
|
|
(Msg.wParam in [VK_BACK..VK_HELP]) then
|
|
|
|
|
begin
|
|
|
|
|
TempEvent.kind := KEYEVENT_RAWKEYDOWN;
|
|
|
|
|
TempEvent.modifiers := GetCefKeyboardModifiers(Msg.wParam, Msg.lParam);
|
|
|
|
|
TempEvent.windows_key_code := Msg.wParam;
|
|
|
|
|
TempEvent.native_key_code := Msg.lParam;
|
|
|
|
|
TempEvent.is_system_key := ord(False);
|
|
|
|
|
TempEvent.character := #0;
|
|
|
|
|
TempEvent.unmodified_character := #0;
|
|
|
|
|
TempEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempEvent);
|
|
|
|
|
Handled := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
WM_KEYUP :
|
|
|
|
|
if (Panel1.Focused or chrmosr.FrameIsFocused) and
|
|
|
|
|
(Msg.wParam in [VK_BACK..VK_HELP]) then
|
|
|
|
|
begin
|
|
|
|
|
TempEvent.kind := KEYEVENT_KEYUP;
|
|
|
|
|
TempEvent.modifiers := GetCefKeyboardModifiers(Msg.wParam, Msg.lParam);
|
|
|
|
|
TempEvent.windows_key_code := Msg.wParam;
|
|
|
|
|
TempEvent.native_key_code := Msg.lParam;
|
|
|
|
|
TempEvent.is_system_key := ord(False);
|
|
|
|
|
TempEvent.character := #0;
|
|
|
|
|
TempEvent.unmodified_character := #0;
|
|
|
|
|
TempEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempEvent);
|
|
|
|
|
Handled := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
WM_CHAR :
|
|
|
|
|
if Panel1.Focused or chrmosr.FrameIsFocused then
|
|
|
|
|
begin
|
|
|
|
|
TempEvent.kind := KEYEVENT_CHAR;
|
|
|
|
|
TempEvent.modifiers := GetCefKeyboardModifiers(Msg.wParam, Msg.lParam);
|
|
|
|
|
TempEvent.windows_key_code := Msg.wParam;
|
|
|
|
|
TempEvent.native_key_code := Msg.lParam;
|
|
|
|
|
TempEvent.is_system_key := ord(False);
|
|
|
|
|
TempEvent.character := #0;
|
|
|
|
|
TempEvent.unmodified_character := #0;
|
|
|
|
|
TempEvent.focus_on_editable_field := ord(False);
|
|
|
|
|
|
|
|
|
|
chrmosr.SendKeyEvent(@TempEvent);
|
|
|
|
|
Handled := True;
|
|
|
|
|
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-07-18 17:50:28 +02:00
|
|
|
|
chrmosr.LoadURL(ComboBox1.Text);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.chrmosrCursorChange(Sender : TObject;
|
|
|
|
|
const browser : ICefBrowser;
|
|
|
|
|
cursor : HICON;
|
|
|
|
|
cursorType : TCefCursorType;
|
|
|
|
|
const customCursorInfo : PCefCursorInfo);
|
|
|
|
|
begin
|
|
|
|
|
PaintBox.Cursor := GefCursorToWindowsCursor(cursorType);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-07-28 12:47:57 +02:00
|
|
|
|
procedure TForm1.chrmosrGetScreenInfo(Sender: TObject;
|
|
|
|
|
const browser: ICefBrowser; var screenInfo: TCefScreenInfo;
|
|
|
|
|
out Result: Boolean);
|
|
|
|
|
var
|
|
|
|
|
TempRect : TCEFRect;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
2017-07-28 12:47:57 +02:00
|
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
TempRect.x := 0;
|
|
|
|
|
TempRect.y := 0;
|
|
|
|
|
TempRect.width := DeviceToLogical(PaintBox.Width, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
TempRect.height := DeviceToLogical(PaintBox.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;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.chrmosrGetScreenPoint(Sender : TObject;
|
|
|
|
|
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;
|
|
|
|
|
begin
|
2017-07-28 12:47:57 +02:00
|
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
TempViewPt.x := LogicalToDevice(viewX, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
TempViewPt.y := LogicalToDevice(viewY, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
TempScreenPt := PaintBox.ClientToScreen(TempViewPt);
|
|
|
|
|
screenX := TempScreenPt.x;
|
|
|
|
|
screenY := TempScreenPt.y;
|
|
|
|
|
Result := True;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
Result := False;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.chrmosrGetViewRect(Sender : TObject;
|
|
|
|
|
const browser : ICefBrowser;
|
2017-07-28 12:47:57 +02:00
|
|
|
|
var rect : TCefRect;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
out Result : Boolean);
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
2017-07-28 12:47:57 +02:00
|
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
rect.x := 0;
|
|
|
|
|
rect.y := 0;
|
|
|
|
|
rect.width := DeviceToLogical(PaintBox.Width, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
rect.height := DeviceToLogical(PaintBox.Height, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
Result := True;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
Result := False;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.chrmosrPaint(Sender : TObject;
|
|
|
|
|
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;
|
|
|
|
|
offset, i, j, w: Integer;
|
|
|
|
|
begin
|
|
|
|
|
if (width <> PaintBox.Width) or (height <> PaintBox.Height) then Exit;
|
|
|
|
|
|
2017-07-28 12:47:57 +02:00
|
|
|
|
// ====================
|
|
|
|
|
// === WARNING !!!! ===
|
|
|
|
|
// ====================
|
|
|
|
|
// This is a simple and basic function that copies the buffer passed from
|
|
|
|
|
// CEF into the PaintBox canvas. If you have a high DPI monitor you may
|
|
|
|
|
// have rounding problems resulting in a black screen.
|
|
|
|
|
// CEF and this demo use a device_scale_factor to calculate screen logical
|
|
|
|
|
// and real sizes. If there's a rounding error CEF and this demo will have
|
|
|
|
|
// slightly different sizes and this function will exit.
|
|
|
|
|
// If you need to support high DPI, you'll have to use a better function
|
|
|
|
|
// to copy the buffer.
|
|
|
|
|
|
2017-01-27 18:14:48 +01:00
|
|
|
|
with PaintBox.Buffer do
|
|
|
|
|
begin
|
|
|
|
|
PaintBox.Canvas.Lock;
|
|
|
|
|
Lock;
|
|
|
|
|
try
|
|
|
|
|
for j := 0 to dirtyRectsCount - 1 do
|
|
|
|
|
begin
|
|
|
|
|
w := Width * 4;
|
|
|
|
|
offset := ((dirtyRects[j].y * Width) + dirtyRects[j].x) * 4;
|
|
|
|
|
src := @PByte(buffer)[offset];
|
|
|
|
|
dst := @PByte(Bits)[offset];
|
|
|
|
|
offset := dirtyRects[j].width * 4;
|
|
|
|
|
for i := 0 to dirtyRects[j].height - 1 do
|
|
|
|
|
begin
|
|
|
|
|
Move(src^, dst^, offset);
|
|
|
|
|
Inc(dst, w);
|
|
|
|
|
Inc(src, w);
|
|
|
|
|
end;
|
|
|
|
|
PaintBox.Flush(Rect(dirtyRects[j].x, dirtyRects[j].y,
|
|
|
|
|
dirtyRects[j].x + dirtyRects[j].width, dirtyRects[j].y + dirtyRects[j].height));
|
|
|
|
|
end;
|
|
|
|
|
finally
|
|
|
|
|
Unlock;
|
|
|
|
|
PaintBox.Canvas.Unlock;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.chrmosrPopupShow(Sender : TObject;
|
|
|
|
|
const browser : ICefBrowser;
|
|
|
|
|
show : Boolean);
|
2017-04-24 12:57:16 +02:00
|
|
|
|
begin
|
|
|
|
|
// TO DO : Needed to draw the "select" items
|
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.chrmosrPopupSize(Sender : TObject;
|
|
|
|
|
const browser : ICefBrowser;
|
|
|
|
|
const rect : PCefRect);
|
2017-04-24 12:57:16 +02:00
|
|
|
|
begin
|
|
|
|
|
// TO DO : Needed to draw the "select" items
|
2017-07-28 12:47:57 +02:00
|
|
|
|
// The rect also needs to be converted.
|
|
|
|
|
// LogicalToDevice(rect, GlobalCEFApp.DeviceScaleFactor);
|
2017-04-24 12:57:16 +02:00
|
|
|
|
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
|
2017-07-18 17:50:28 +02:00
|
|
|
|
TMouseButton.mbRight : Result := MBT_RIGHT;
|
|
|
|
|
TMouseButton.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-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.BrowserCreatedMsg(var aMessage : TMessage);
|
|
|
|
|
begin
|
2017-10-29 17:10:33 +01:00
|
|
|
|
chrmosr.WasHidden(False);
|
|
|
|
|
chrmosr.SendFocusEvent(True);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
NavControlPnl.Enabled := True;
|
|
|
|
|
GoBtn.Click;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
|
2017-04-24 12:57:16 +02:00
|
|
|
|
begin
|
|
|
|
|
if (chrmosr <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.NotifyScreenInfoChanged;
|
|
|
|
|
chrmosr.WasResized;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.FormDestroy(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.ShutdownDragAndDrop;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.FormHide(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
chrmosr.SendFocusEvent(False);
|
|
|
|
|
chrmosr.WasHidden(True);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.FormShow(Sender: TObject);
|
|
|
|
|
begin
|
2017-10-29 17:10:33 +01:00
|
|
|
|
chrmosr.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF); // opaque white background color
|
|
|
|
|
chrmosr.CreateBrowser(nil, '');
|
|
|
|
|
chrmosr.InitializeDragAndDrop(PaintBox);
|
2017-07-18 17:50:28 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.PaintBoxClick(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
Panel1.SetFocus;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.PaintBoxMouseDown(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
|
2017-07-28 12:47:57 +02:00
|
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
TempEvent.x := X;
|
|
|
|
|
TempEvent.y := Y;
|
|
|
|
|
TempEvent.modifiers := getModifiers(Shift);
|
|
|
|
|
DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), False, 1);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.PaintBoxMouseLeave(Sender: TObject);
|
|
|
|
|
var
|
|
|
|
|
TempEvent : TCefMouseEvent;
|
|
|
|
|
TempPoint : TPoint;
|
|
|
|
|
begin
|
|
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
GetCursorPos(TempPoint);
|
|
|
|
|
TempPoint := PaintBox.ScreenToclient(TempPoint);
|
|
|
|
|
TempEvent.x := TempPoint.x;
|
|
|
|
|
TempEvent.y := TempPoint.y;
|
|
|
|
|
TempEvent.modifiers := GetCefMouseModifiers;
|
|
|
|
|
DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
chrmosr.SendMouseMoveEvent(@TempEvent, not PaintBox.MouseInControl);
|
|
|
|
|
end;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.PaintBoxMouseMove(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;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
begin
|
2017-07-28 12:47:57 +02:00
|
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
TempEvent.x := X;
|
|
|
|
|
TempEvent.y := Y;
|
|
|
|
|
TempEvent.modifiers := getModifiers(Shift);
|
|
|
|
|
DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
chrmosr.SendMouseMoveEvent(@TempEvent, not PaintBox.MouseInControl);
|
|
|
|
|
end;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.PaintBoxMouseUp(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
|
2017-07-28 12:47:57 +02:00
|
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
|
begin
|
|
|
|
|
TempEvent.x := X;
|
|
|
|
|
TempEvent.y := Y;
|
|
|
|
|
TempEvent.modifiers := getModifiers(Shift);
|
|
|
|
|
DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor);
|
|
|
|
|
chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), True, 1);
|
|
|
|
|
end;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-07-18 17:50:28 +02:00
|
|
|
|
procedure TForm1.PaintBoxMouseWheel(Sender : TObject;
|
|
|
|
|
Shift : TShiftState;
|
|
|
|
|
WheelDelta : Integer;
|
|
|
|
|
MousePos : TPoint;
|
|
|
|
|
var Handled : Boolean);
|
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
|
2017-07-28 12:47:57 +02:00
|
|
|
|
if (GlobalCEFApp <> 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;
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TForm1.PaintBoxResize(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
PaintBox.Buffer.SetSize(PaintBox.Width, PaintBox.Height);
|
|
|
|
|
chrmosr.WasResized;
|
2017-07-18 17:50:28 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
if SaveDialog1.Execute then PaintBox.Buffer.SaveToFile(SaveDialog1.FileName);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-01-27 18:14:48 +01:00
|
|
|
|
end.
|