You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-06-12 22:07:39 +02:00
Workaround for issue #271
This commit is contained in:
@ -231,6 +231,7 @@ begin
|
||||
GlobalCEFApp.WindowlessRenderingEnabled := True;
|
||||
GlobalCEFApp.EnableHighDPISupport := True;
|
||||
GlobalCEFApp.TouchEvents := STATE_ENABLED;
|
||||
//GlobalCEFApp.EnableGPU := True;
|
||||
|
||||
// If you need transparency leave the GlobalCEFApp.BackgroundColor property
|
||||
// with the default value or set the alpha channel to 0
|
||||
@ -343,12 +344,12 @@ begin
|
||||
end;
|
||||
|
||||
WM_MOUSEWHEEL :
|
||||
if Panel1.Focused and (GlobalCEFApp <> nil) then
|
||||
if Panel1.Focused then
|
||||
begin
|
||||
TempMouseEvent.x := Msg.lParam and $FFFF;
|
||||
TempMouseEvent.y := Msg.lParam shr 16;
|
||||
TempMouseEvent.modifiers := GetCefMouseModifiers(Msg.wParam);
|
||||
DeviceToLogical(TempMouseEvent, GlobalCEFApp.DeviceScaleFactor);
|
||||
DeviceToLogical(TempMouseEvent, Panel1.ScreenScale);
|
||||
chrmosr.SendMouseWheelEvent(@TempMouseEvent, 0, smallint(Msg.wParam shr 16));
|
||||
end;
|
||||
end;
|
||||
@ -413,26 +414,23 @@ procedure TForm1.chrmosrGetScreenInfo( Sender : TObject;
|
||||
var screenInfo : TCefScreenInfo;
|
||||
out Result : Boolean);
|
||||
var
|
||||
TempRect : TCEFRect;
|
||||
TempRect : TCEFRect;
|
||||
TempScale : single;
|
||||
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);
|
||||
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 := GlobalCEFApp.DeviceScaleFactor;
|
||||
screenInfo.depth := 0;
|
||||
screenInfo.depth_per_component := 0;
|
||||
screenInfo.is_monochrome := Ord(False);
|
||||
screenInfo.rect := TempRect;
|
||||
screenInfo.available_rect := TempRect;
|
||||
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;
|
||||
end
|
||||
else
|
||||
Result := False;
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TForm1.chrmosrGetScreenPoint( Sender : TObject;
|
||||
@ -444,30 +442,36 @@ procedure TForm1.chrmosrGetScreenPoint( Sender : TObject;
|
||||
out Result : Boolean);
|
||||
var
|
||||
TempScreenPt, TempViewPt : TPoint;
|
||||
TempScale : single;
|
||||
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;
|
||||
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;
|
||||
end;
|
||||
|
||||
procedure TForm1.chrmosrGetViewRect( Sender : TObject;
|
||||
const browser : ICefBrowser;
|
||||
var rect : TCefRect);
|
||||
var
|
||||
TempScale : single;
|
||||
begin
|
||||
if (GlobalCEFApp <> nil) then
|
||||
TempScale := Panel1.ScreenScale;
|
||||
rect.x := 0;
|
||||
rect.y := 0;
|
||||
rect.width := DeviceToLogical(Panel1.Width, TempScale);
|
||||
rect.height := DeviceToLogical(Panel1.Height, TempScale);
|
||||
|
||||
// Workaround for CEF4Delphi issue #271 (CEF issue #2833)
|
||||
// https://github.com/salvadordf/CEF4Delphi/issues/271
|
||||
// https://bitbucket.org/chromiumembedded/cef/issues/2833/osr-gpu-consume-cpu-and-may-not-draw
|
||||
if (GlobalCEFApp <> nil) and GlobalCEFApp.EnableGPU and (TempScale <> 1) then
|
||||
begin
|
||||
rect.x := 0;
|
||||
rect.y := 0;
|
||||
rect.width := DeviceToLogical(Panel1.Width, GlobalCEFApp.DeviceScaleFactor);
|
||||
rect.height := DeviceToLogical(Panel1.Height, GlobalCEFApp.DeviceScaleFactor);
|
||||
while (Frac(rect.width * TempScale) <> 0) do dec(rect.width);
|
||||
while (Frac(rect.height * TempScale) <> 0) do dec(rect.height);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -607,15 +611,12 @@ procedure TForm1.chrmosrPopupSize( Sender : TObject;
|
||||
const browser : ICefBrowser;
|
||||
const rect : PCefRect);
|
||||
begin
|
||||
if (GlobalCEFApp <> nil) then
|
||||
begin
|
||||
LogicalToDevice(rect^, GlobalCEFApp.DeviceScaleFactor);
|
||||
LogicalToDevice(rect^, Panel1.ScreenScale);
|
||||
|
||||
FPopUpRect.Left := rect.x;
|
||||
FPopUpRect.Top := rect.y;
|
||||
FPopUpRect.Right := rect.x + rect.width - 1;
|
||||
FPopUpRect.Bottom := rect.y + rect.height - 1;
|
||||
end;
|
||||
FPopUpRect.Left := rect.x;
|
||||
FPopUpRect.Top := rect.y;
|
||||
FPopUpRect.Right := rect.x + rect.width - 1;
|
||||
FPopUpRect.Bottom := rect.y + rect.height - 1;
|
||||
end;
|
||||
|
||||
procedure TForm1.chrmosrTooltip(Sender: TObject; const browser: ICefBrowser; var text: ustring; out Result: Boolean);
|
||||
@ -812,6 +813,7 @@ end;
|
||||
procedure TForm1.Panel1CustomTouch(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
|
||||
{$IFDEF DELPHI14_UP}
|
||||
var
|
||||
TempScale : single;
|
||||
TempTouchEvent : TCefTouchEvent;
|
||||
TempHTOUCHINPUT : HTOUCHINPUT;
|
||||
TempNumPoints : integer;
|
||||
@ -832,6 +834,7 @@ begin
|
||||
|
||||
SetLength(TempTouchInputs, TempNumPoints);
|
||||
TempHTOUCHINPUT := HTOUCHINPUT(aMessage.lParam);
|
||||
TempScale := Panel1.ScreenScale;
|
||||
|
||||
if GetTouchInputInfo(TempHTOUCHINPUT, TempNumPoints, @TempTouchInputs[0], SizeOf(TTouchInput)) then
|
||||
begin
|
||||
@ -857,8 +860,8 @@ begin
|
||||
end;
|
||||
|
||||
TempPoint := Panel1.ScreenToClient(TempPoint);
|
||||
TempTouchEvent.x := DeviceToLogical(TempPoint.x, GlobalCEFApp.DeviceScaleFactor);
|
||||
TempTouchEvent.y := DeviceToLogical(TempPoint.y, GlobalCEFApp.DeviceScaleFactor);
|
||||
TempTouchEvent.x := DeviceToLogical(TempPoint.x, TempScale);
|
||||
TempTouchEvent.y := DeviceToLogical(TempPoint.y, TempScale);
|
||||
|
||||
// Touch point identifier stays consistent in a touch contact sequence
|
||||
TempTouchEvent.id := TempTouchInputs[i].dwID;
|
||||
@ -892,28 +895,29 @@ var
|
||||
TempEvent : TCefMouseEvent;
|
||||
TempTime : integer;
|
||||
begin
|
||||
if (GlobalCEFApp <> nil) and (chrmosr <> nil) {$IFDEF DELPHI14_UP}and not(ssTouch in Shift){$ENDIF} then
|
||||
{$IFDEF DELPHI14_UP}
|
||||
if (ssTouch in Shift) then exit;
|
||||
{$ENDIF}
|
||||
|
||||
Panel1.SetFocus;
|
||||
|
||||
if not(CancelPreviousClick(x, y, TempTime)) and (Button = FLastClickButton) then
|
||||
inc(FLastClickCount)
|
||||
else
|
||||
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);
|
||||
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, Panel1.ScreenScale);
|
||||
chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), False, FLastClickCount);
|
||||
end;
|
||||
|
||||
procedure TForm1.Panel1MouseLeave(Sender: TObject);
|
||||
@ -922,19 +926,16 @@ var
|
||||
TempPoint : TPoint;
|
||||
TempTime : integer;
|
||||
begin
|
||||
if (GlobalCEFApp <> nil) and (chrmosr <> nil) then
|
||||
begin
|
||||
GetCursorPos(TempPoint);
|
||||
TempPoint := Panel1.ScreenToclient(TempPoint);
|
||||
GetCursorPos(TempPoint);
|
||||
TempPoint := Panel1.ScreenToclient(TempPoint);
|
||||
|
||||
if CancelPreviousClick(TempPoint.x, TempPoint.y, TempTime) then InitializeLastClick;
|
||||
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;
|
||||
TempEvent.x := TempPoint.x;
|
||||
TempEvent.y := TempPoint.y;
|
||||
TempEvent.modifiers := GetCefMouseModifiers;
|
||||
DeviceToLogical(TempEvent, Panel1.ScreenScale);
|
||||
chrmosr.SendMouseMoveEvent(@TempEvent, True);
|
||||
end;
|
||||
|
||||
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
||||
@ -942,30 +943,32 @@ var
|
||||
TempEvent : TCefMouseEvent;
|
||||
TempTime : integer;
|
||||
begin
|
||||
if (GlobalCEFApp <> nil) and (chrmosr <> nil) {$IFDEF DELPHI14_UP}and not(ssTouch in Shift){$ENDIF} then
|
||||
begin
|
||||
if CancelPreviousClick(x, y, TempTime) then InitializeLastClick;
|
||||
{$IFDEF DELPHI14_UP}
|
||||
if (ssTouch in Shift) then exit;
|
||||
{$ENDIF}
|
||||
|
||||
TempEvent.x := x;
|
||||
TempEvent.y := y;
|
||||
TempEvent.modifiers := getModifiers(Shift);
|
||||
DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor);
|
||||
chrmosr.SendMouseMoveEvent(@TempEvent, False);
|
||||
end;
|
||||
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);
|
||||
end;
|
||||
|
||||
procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||
var
|
||||
TempEvent : TCefMouseEvent;
|
||||
begin
|
||||
if (GlobalCEFApp <> nil) and (chrmosr <> nil) {$IFDEF DELPHI14_UP}and not(ssTouch in Shift){$ENDIF} then
|
||||
begin
|
||||
TempEvent.x := X;
|
||||
TempEvent.y := Y;
|
||||
TempEvent.modifiers := getModifiers(Shift);
|
||||
DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor);
|
||||
chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), True, FLastClickCount);
|
||||
end;
|
||||
{$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);
|
||||
end;
|
||||
|
||||
procedure TForm1.Panel1PaintParentBkg(Sender: TObject);
|
||||
@ -1043,6 +1046,7 @@ var
|
||||
TempPenInfo : POINTER_PEN_INFO;
|
||||
TempTouchEvent : TCefTouchEvent;
|
||||
TempPoint : TPoint;
|
||||
TempScale : single;
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
@ -1090,9 +1094,10 @@ begin
|
||||
if ((TempPenInfo.pointerInfo.pointerFlags and POINTER_FLAG_CANCELED) <> 0) then
|
||||
TempTouchEvent.type_ := CEF_TET_CANCELLED;
|
||||
|
||||
TempScale := Panel1.ScreenScale;
|
||||
TempPoint := Panel1.ScreenToClient(TempPenInfo.pointerInfo.ptPixelLocation);
|
||||
TempTouchEvent.x := DeviceToLogical(TempPoint.x, GlobalCEFApp.DeviceScaleFactor);
|
||||
TempTouchEvent.y := DeviceToLogical(TempPoint.y, GlobalCEFApp.DeviceScaleFactor);
|
||||
TempTouchEvent.x := DeviceToLogical(TempPoint.x, TempScale);
|
||||
TempTouchEvent.y := DeviceToLogical(TempPoint.y, TempScale);
|
||||
|
||||
chrmosr.SendTouchEvent(@TempTouchEvent);
|
||||
end;
|
||||
@ -1102,6 +1107,7 @@ var
|
||||
TempTouchInfo : POINTER_TOUCH_INFO;
|
||||
TempTouchEvent : TCefTouchEvent;
|
||||
TempPoint : TPoint;
|
||||
TempScale : single;
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
@ -1137,9 +1143,10 @@ begin
|
||||
if ((TempTouchInfo.pointerInfo.pointerFlags and POINTER_FLAG_CANCELED) <> 0) then
|
||||
TempTouchEvent.type_ := CEF_TET_CANCELLED;
|
||||
|
||||
TempScale := Panel1.ScreenScale;
|
||||
TempPoint := Panel1.ScreenToClient(TempTouchInfo.pointerInfo.ptPixelLocation);
|
||||
TempTouchEvent.x := DeviceToLogical(TempPoint.x, GlobalCEFApp.DeviceScaleFactor);
|
||||
TempTouchEvent.y := DeviceToLogical(TempPoint.y, GlobalCEFApp.DeviceScaleFactor);
|
||||
TempTouchEvent.x := DeviceToLogical(TempPoint.x, TempScale);
|
||||
TempTouchEvent.y := DeviceToLogical(TempPoint.y, TempScale);
|
||||
|
||||
chrmosr.SendTouchEvent(@TempTouchEvent);
|
||||
end;
|
||||
@ -1253,6 +1260,7 @@ procedure TForm1.chrmosrIMECompositionRangeChanged( Sender :
|
||||
var
|
||||
TempPRect : PCefRect;
|
||||
i : NativeUInt;
|
||||
TempScale : single;
|
||||
begin
|
||||
try
|
||||
FIMECS.Acquire;
|
||||
@ -1277,11 +1285,12 @@ begin
|
||||
|
||||
i := 0;
|
||||
TempPRect := character_bounds;
|
||||
TempScale := Panel1.ScreenScale;
|
||||
|
||||
while (i < character_boundsCount) do
|
||||
begin
|
||||
FDeviceBounds[i] := TempPRect^;
|
||||
LogicalToDevice(FDeviceBounds[i], GlobalCEFApp.DeviceScaleFactor);
|
||||
LogicalToDevice(FDeviceBounds[i], TempScale);
|
||||
|
||||
inc(TempPRect);
|
||||
inc(i);
|
||||
|
Reference in New Issue
Block a user