diff --git a/demos/FMXExternalPumpBrowser/uFMXExternalPumpBrowser.pas b/demos/FMXExternalPumpBrowser/uFMXExternalPumpBrowser.pas index 33d9e093..dbb4ba0a 100644 --- a/demos/FMXExternalPumpBrowser/uFMXExternalPumpBrowser.pas +++ b/demos/FMXExternalPumpBrowser/uFMXExternalPumpBrowser.pas @@ -97,20 +97,13 @@ type procedure chrmosrAfterCreated(Sender: TObject; const browser: ICefBrowser); procedure chrmosrClose(Sender: TObject; const browser: ICefBrowser; out Result: Boolean); procedure chrmosrBeforeClose(Sender: TObject; const browser: ICefBrowser); + procedure chrmosrTooltip(Sender: TObject; const browser: ICefBrowser; var text: ustring; out Result: Boolean); + procedure chrmosrBeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean; out Result: Boolean); procedure Timer1Timer(Sender: TObject); procedure AddressEdtEnter(Sender: TObject); procedure SnapshotBtnClick(Sender: TObject); procedure SnapshotBtnEnter(Sender: TObject); - procedure chrmosrTooltip(Sender: TObject; const browser: ICefBrowser; - var text: ustring; out Result: Boolean); - procedure chrmosrBeforePopup(Sender: TObject; - const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, - targetFrameName: ustring; - targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; - var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; - var client: ICefClient; var settings: TCefBrowserSettings; - var noJavascriptAccess: Boolean; out Result: Boolean); protected FPopUpBitmap : TBitmap; @@ -125,10 +118,17 @@ type FMouseWheelService : IFMXMouseService; {$ENDIF} + FLastClickCount : integer; + FLastClickTime : integer; + FLastClickPoint : TPointF; + FLastClickButton : TMouseButton; + procedure LoadURL; function getModifiers(Shift: TShiftState): TCefEventFlags; function GetButton(Button: TMouseButton): TCefMouseButtonType; function SendCompMessage(aMsg : cardinal; wParam : cardinal = 0; lParam : integer = 0) : boolean; + procedure InitializeLastClick; + function CancelPreviousClick(const x, y : single; var aCurrentTime : integer) : boolean; public procedure DoResize; @@ -207,6 +207,8 @@ begin FClosing := False; FResizeCS := TCriticalSection.Create; + InitializeLastClick; + {$IFDEF DELPHI17_UP} if TPlatformServices.Current.SupportsPlatformService(IFMXMouseService) then FMouseWheelService := TPlatformServices.Current.GetPlatformService(IFMXMouseService) as IFMXMouseService; @@ -343,15 +345,28 @@ procedure TFMXExternalPumpBrowserFrm.Panel1MouseDown(Sender : TObject; X, Y : Single); var TempEvent : TCefMouseEvent; + TempTime : integer; begin - if (GlobalCEFApp <> nil) and (chrmosr <> nil) then + if (GlobalCEFApp <> nil) and (chrmosr <> nil) and not(ssShift in Shift) then begin Panel1.SetFocus; + if not(CancelPreviousClick(x, y, TempTime)) and (Button = FLastClickButton) then + inc(FLastClickCount) + else + begin + FLastClickPoint.x := x; + FLastClickPoint.y := y; + FLastClickCount := 1; + end; + + FLastClickTime := TempTime; + FLastClickButton := Button; + TempEvent.x := round(X); TempEvent.y := round(Y); TempEvent.modifiers := getModifiers(Shift); - chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), False, 1); + chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), False, FLastClickCount); end; end; @@ -359,11 +374,15 @@ procedure TFMXExternalPumpBrowserFrm.Panel1MouseLeave(Sender: TObject); var TempEvent : TCefMouseEvent; TempPoint : TPoint; + TempTime : integer; begin if (GlobalCEFApp <> nil) and (chrmosr <> nil) then begin GetCursorPos(TempPoint); - TempPoint := Panel1.ScreenToclient(TempPoint); + TempPoint := Panel1.ScreenToclient(TempPoint); + + if CancelPreviousClick(TempPoint.x, TempPoint.y, TempTime) then InitializeLastClick; + TempEvent.x := TempPoint.x; TempEvent.y := TempPoint.y; TempEvent.modifiers := GetCefMouseModifiers; @@ -376,9 +395,12 @@ procedure TFMXExternalPumpBrowserFrm.Panel1MouseMove(Sender : TObject; X, Y : Single); var TempEvent : TCefMouseEvent; + TempTime : integer; begin if (GlobalCEFApp <> nil) and (chrmosr <> nil) then begin + if CancelPreviousClick(x, y, TempTime) then InitializeLastClick; + TempEvent.x := round(X); TempEvent.y := round(Y); TempEvent.modifiers := getModifiers(Shift); @@ -398,7 +420,7 @@ begin TempEvent.x := round(X); TempEvent.y := round(Y); TempEvent.modifiers := getModifiers(Shift); - chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), True, 1); + chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), True, FLastClickCount); end; end; @@ -860,6 +882,29 @@ begin {$ENDIF} end; +procedure TFMXExternalPumpBrowserFrm.InitializeLastClick; +begin + FLastClickCount := 0; + FLastClickTime := 0; + FLastClickPoint.x := 0; + FLastClickPoint.y := 0; + FLastClickButton := TMouseButton.mbLeft; +end; + +function TFMXExternalPumpBrowserFrm.CancelPreviousClick(const x, y : single; var aCurrentTime : integer) : boolean; +begin + {$IFDEF MSWINDOWS} + 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); + {$ELSE} + aCurrentTime := 0; + Result := False; + {$ENDIF} +end; + procedure TFMXExternalPumpBrowserFrm.SnapshotBtnClick(Sender: TObject); begin if SaveDialog1.Execute then Panel1.SaveToFile(SaveDialog1.FileName); diff --git a/demos/OSRExternalPumpBrowser/uOSRExternalPumpBrowser.dfm b/demos/OSRExternalPumpBrowser/uOSRExternalPumpBrowser.dfm index 318ee2b0..5690c3ad 100644 --- a/demos/OSRExternalPumpBrowser/uOSRExternalPumpBrowser.dfm +++ b/demos/OSRExternalPumpBrowser/uOSRExternalPumpBrowser.dfm @@ -122,6 +122,7 @@ object OSRExternalPumpBrowserFrm: TOSRExternalPumpBrowserFrm OnMouseLeave = Panel1MouseLeave end object chrmosr: TChromium + OnTooltip = chrmosrTooltip OnBeforePopup = chrmosrBeforePopup OnAfterCreated = chrmosrAfterCreated OnBeforeClose = chrmosrBeforeClose diff --git a/demos/OSRExternalPumpBrowser/uOSRExternalPumpBrowser.pas b/demos/OSRExternalPumpBrowser/uOSRExternalPumpBrowser.pas index 24cde94a..7ecdbcd1 100644 --- a/demos/OSRExternalPumpBrowser/uOSRExternalPumpBrowser.pas +++ b/demos/OSRExternalPumpBrowser/uOSRExternalPumpBrowser.pas @@ -96,33 +96,35 @@ type procedure chrmosrAfterCreated(Sender: TObject; const browser: ICefBrowser); procedure chrmosrClose(Sender: TObject; const browser: ICefBrowser; out Result: Boolean); procedure chrmosrBeforeClose(Sender: TObject; const browser: ICefBrowser); + procedure chrmosrTooltip(Sender: TObject; const browser: ICefBrowser; var text: ustring; out Result: Boolean); + procedure chrmosrBeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean; out Result: Boolean); procedure SnapshotBtnClick(Sender: TObject); procedure SnapshotBtnEnter(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure ComboBox1Enter(Sender: TObject); - procedure chrmosrBeforePopup(Sender: TObject; - const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, - targetFrameName: ustring; - targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; - var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; - var client: ICefClient; var settings: TCefBrowserSettings; - var noJavascriptAccess: Boolean; out Result: Boolean); protected - FPopUpBitmap : TBitmap; - FPopUpRect : TRect; - FShowPopUp : boolean; - FResizing : boolean; - FPendingResize : boolean; - FCanClose : boolean; - FClosing : boolean; - FResizeCS : TCriticalSection; + FPopUpBitmap : TBitmap; + FPopUpRect : TRect; + FShowPopUp : boolean; + FResizing : boolean; + FPendingResize : boolean; + FCanClose : boolean; + FClosing : boolean; + FResizeCS : TCriticalSection; + + FLastClickCount : integer; + FLastClickTime : integer; + FLastClickPoint : TPoint; + FLastClickButton : TMouseButton; function getModifiers(Shift: TShiftState): TCefEventFlags; function GetButton(Button: TMouseButton): TCefMouseButtonType; procedure DoResize; + procedure InitializeLastClick; + function CancelPreviousClick(x, y : integer; var aCurrentTime : integer) : boolean; procedure WMMove(var aMessage : TWMMove); message WM_MOVE; procedure WMMoving(var aMessage : TMessage); message WM_MOVING; @@ -542,6 +544,13 @@ begin end; end; +procedure TOSRExternalPumpBrowserFrm.chrmosrTooltip(Sender: TObject; const browser: ICefBrowser; var text: ustring; out Result: Boolean); +begin + Panel1.hint := text; + Panel1.ShowHint := (length(text) > 0); + Result := True; +end; + procedure TOSRExternalPumpBrowserFrm.ComboBox1Enter(Sender: TObject); begin chrmosr.SendFocusEvent(False); @@ -635,6 +644,8 @@ begin FCanClose := False; FClosing := False; FResizeCS := TCriticalSection.Create; + + InitializeLastClick; end; procedure TOSRExternalPumpBrowserFrm.FormDestroy(Sender: TObject); @@ -677,16 +688,29 @@ end; procedure TOSRExternalPumpBrowserFrm.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var TempEvent : TCefMouseEvent; + TempTime : integer; begin - if (GlobalCEFApp <> nil) then + if (GlobalCEFApp <> nil) and (chrmosr <> nil) and not(ssShift in Shift) then begin Panel1.SetFocus; + if not(CancelPreviousClick(x, y, TempTime)) and (Button = FLastClickButton) then + inc(FLastClickCount) + else + begin + FLastClickPoint.x := x; + FLastClickPoint.y := y; + FLastClickCount := 1; + end; + + FLastClickTime := TempTime; + FLastClickButton := Button; + TempEvent.x := X; TempEvent.y := Y; TempEvent.modifiers := getModifiers(Shift); DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor); - chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), False, 1); + chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), False, FLastClickCount); end; end; @@ -694,11 +718,15 @@ procedure TOSRExternalPumpBrowserFrm.Panel1MouseLeave(Sender: TObject); var TempEvent : TCefMouseEvent; TempPoint : TPoint; + TempTime : integer; begin - if (GlobalCEFApp <> nil) then + if (GlobalCEFApp <> nil) and (chrmosr <> nil) then begin GetCursorPos(TempPoint); - TempPoint := Panel1.ScreenToclient(TempPoint); + TempPoint := Panel1.ScreenToclient(TempPoint); + + if CancelPreviousClick(TempPoint.x, TempPoint.y, TempTime) then InitializeLastClick; + TempEvent.x := TempPoint.x; TempEvent.y := TempPoint.y; TempEvent.modifiers := GetCefMouseModifiers; @@ -710,9 +738,12 @@ end; procedure TOSRExternalPumpBrowserFrm.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var TempEvent : TCefMouseEvent; + TempTime : integer; begin - if (GlobalCEFApp <> nil) then + if (GlobalCEFApp <> nil) and (chrmosr <> nil) then begin + if CancelPreviousClick(x, y, TempTime) then InitializeLastClick; + TempEvent.x := X; TempEvent.y := Y; TempEvent.modifiers := getModifiers(Shift); @@ -725,13 +756,13 @@ procedure TOSRExternalPumpBrowserFrm.Panel1MouseUp(Sender: TObject; Button: TMou var TempEvent : TCefMouseEvent; begin - if (GlobalCEFApp <> nil) then + if (GlobalCEFApp <> nil) and (chrmosr <> nil) then begin TempEvent.x := X; TempEvent.y := Y; TempEvent.modifiers := getModifiers(Shift); DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor); - chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), True, 1); + chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), True, FLastClickCount); end; end; @@ -765,6 +796,24 @@ begin end; end; +procedure TOSRExternalPumpBrowserFrm.InitializeLastClick; +begin + FLastClickCount := 0; + FLastClickTime := 0; + FLastClickPoint.x := 0; + FLastClickPoint.y := 0; + FLastClickButton := mbLeft; +end; + +function TOSRExternalPumpBrowserFrm.CancelPreviousClick(x, y : integer; var aCurrentTime : integer) : boolean; +begin + aCurrentTime := GetMessageTime; + + Result := (abs(FLastClickPoint.x - x) > (GetSystemMetrics(SM_CXDOUBLECLK) div 2)) or + (abs(FLastClickPoint.y - y) > (GetSystemMetrics(SM_CYDOUBLECLK) div 2)) or + (cardinal(aCurrentTime - FLastClickTime) > GetDoubleClickTime); +end; + procedure TOSRExternalPumpBrowserFrm.Panel1Enter(Sender: TObject); begin chrmosr.SendFocusEvent(True); diff --git a/demos/SimpleOSRBrowser/uSimpleOSRBrowser.pas b/demos/SimpleOSRBrowser/uSimpleOSRBrowser.pas index 005fb1d7..80b717a8 100644 --- a/demos/SimpleOSRBrowser/uSimpleOSRBrowser.pas +++ b/demos/SimpleOSRBrowser/uSimpleOSRBrowser.pas @@ -105,18 +105,25 @@ type procedure ComboBox1Enter(Sender: TObject); protected - FPopUpBitmap : TBitmap; - FPopUpRect : TRect; - FShowPopUp : boolean; - FResizing : boolean; - FPendingResize : boolean; - FCanClose : boolean; - FClosing : boolean; - FResizeCS : TCriticalSection; + FPopUpBitmap : TBitmap; + FPopUpRect : TRect; + FShowPopUp : boolean; + FResizing : boolean; + FPendingResize : boolean; + FCanClose : boolean; + FClosing : boolean; + FResizeCS : TCriticalSection; + + FLastClickCount : integer; + FLastClickTime : integer; + FLastClickPoint : TPoint; + FLastClickButton : TMouseButton; function getModifiers(Shift: TShiftState): TCefEventFlags; function GetButton(Button: TMouseButton): TCefMouseButtonType; procedure DoResize; + procedure InitializeLastClick; + function CancelPreviousClick(x, y : integer; var aCurrentTime : integer) : boolean; procedure WMMove(var aMessage : TWMMove); message WM_MOVE; procedure WMMoving(var aMessage : TMessage); message WM_MOVING; @@ -645,6 +652,8 @@ begin FCanClose := False; FClosing := False; FResizeCS := TCriticalSection.Create; + + InitializeLastClick; end; procedure TForm1.FormDestroy(Sender: TObject); @@ -687,16 +696,29 @@ end; procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var TempEvent : TCefMouseEvent; + TempTime : integer; begin - if (GlobalCEFApp <> nil) and (chrmosr <> nil) then + if (GlobalCEFApp <> nil) and (chrmosr <> nil) and not(ssShift in Shift) then begin Panel1.SetFocus; + if not(CancelPreviousClick(x, y, TempTime)) and (Button = FLastClickButton) then + inc(FLastClickCount) + else + begin + FLastClickPoint.x := x; + FLastClickPoint.y := y; + FLastClickCount := 1; + end; + + FLastClickTime := TempTime; + FLastClickButton := Button; + TempEvent.x := X; TempEvent.y := Y; TempEvent.modifiers := getModifiers(Shift); DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor); - chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), False, 1); + chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), False, FLastClickCount); end; end; @@ -704,11 +726,15 @@ procedure TForm1.Panel1MouseLeave(Sender: TObject); var TempEvent : TCefMouseEvent; TempPoint : TPoint; + TempTime : integer; begin if (GlobalCEFApp <> nil) and (chrmosr <> nil) then begin GetCursorPos(TempPoint); - TempPoint := Panel1.ScreenToclient(TempPoint); + TempPoint := Panel1.ScreenToclient(TempPoint); + + if CancelPreviousClick(TempPoint.x, TempPoint.y, TempTime) then InitializeLastClick; + TempEvent.x := TempPoint.x; TempEvent.y := TempPoint.y; TempEvent.modifiers := GetCefMouseModifiers; @@ -720,11 +746,14 @@ end; procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var TempEvent : TCefMouseEvent; + TempTime : integer; begin if (GlobalCEFApp <> nil) and (chrmosr <> nil) then begin - TempEvent.x := X; - TempEvent.y := Y; + if CancelPreviousClick(x, y, TempTime) then InitializeLastClick; + + TempEvent.x := x; + TempEvent.y := y; TempEvent.modifiers := getModifiers(Shift); DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor); chrmosr.SendMouseMoveEvent(@TempEvent, False); @@ -741,7 +770,7 @@ begin TempEvent.y := Y; TempEvent.modifiers := getModifiers(Shift); DeviceToLogical(TempEvent, GlobalCEFApp.DeviceScaleFactor); - chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), True, 1); + chrmosr.SendMouseClickEvent(@TempEvent, GetButton(Button), True, FLastClickCount); end; end; @@ -775,6 +804,24 @@ begin end; end; +procedure TForm1.InitializeLastClick; +begin + FLastClickCount := 0; + FLastClickTime := 0; + FLastClickPoint.x := 0; + FLastClickPoint.y := 0; + FLastClickButton := mbLeft; +end; + +function TForm1.CancelPreviousClick(x, y : integer; var aCurrentTime : integer) : boolean; +begin + aCurrentTime := GetMessageTime; + + Result := (abs(FLastClickPoint.x - x) > (GetSystemMetrics(SM_CXDOUBLECLK) div 2)) or + (abs(FLastClickPoint.y - y) > (GetSystemMetrics(SM_CYDOUBLECLK) div 2)) or + (cardinal(aCurrentTime - FLastClickTime) > GetDoubleClickTime); +end; + procedure TForm1.Panel1Enter(Sender: TObject); begin chrmosr.SendFocusEvent(True);