Skip to content

Commit

Permalink
improve focus handling in OSR demo
Browse files Browse the repository at this point in the history
  • Loading branch information
dliw committed Sep 5, 2016
1 parent a6e01bc commit 36679d9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
31 changes: 22 additions & 9 deletions Examples/OSRDemo/main.lfm
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
object Mainform: TMainform
Left = 338
Left = 643
Height = 475
Top = 133
Top = 320
Width = 762
Caption = 'Browser -'
ClientHeight = 475
ClientWidth = 762
OnCreate = FormCreate
LCLVersion = '1.4.2.0'
LCLVersion = '1.6.0.4'
object BGo: TButton
AnchorSideTop.Control = Owner
AnchorSideRight.Control = Owner
Expand Down Expand Up @@ -53,7 +53,7 @@ object Mainform: TMainform
TabOrder = 2
Text = 'http://'
end
object PaintBox: TPaintBox
object OSRPanel: TPanel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = EUrl
AnchorSideTop.Side = asrBottom
Expand All @@ -67,11 +67,24 @@ object Mainform: TMainform
Width = 762
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 10
OnMouseDown = PaintBoxMouseDown
OnMouseMove = PaintBoxMouseMove
OnMouseUp = PaintBoxMouseUp
OnMouseWheel = PaintBoxMouseWheel
OnResize = PaintBoxResize
BevelOuter = bvNone
ClientHeight = 430
ClientWidth = 762
TabOrder = 3
OnEnter = OSRPanelEnter
OnExit = OSRPanelExit
object PaintBox: TPaintBox
Left = 0
Height = 430
Top = 0
Width = 762
Align = alClient
OnMouseDown = PaintBoxMouseDown
OnMouseMove = PaintBoxMouseMove
OnMouseUp = PaintBoxMouseUp
OnMouseWheel = PaintBoxMouseWheel
OnResize = PaintBoxResize
end
end
object Chromium: TChromiumOSR
OnGetRootScreenRect = ChromiumGetRootScreenRect
Expand Down
16 changes: 15 additions & 1 deletion Examples/OSRDemo/main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ TMainform = class(TForm)
EUrl : TEdit;
LUrl : TStaticText;
PaintBox : TPaintBox;
OSRPanel: TPanel;
procedure BGoClick(Sender : TObject);
procedure ChromiumGetRootScreenRect(Sender : TObject;
const Browser : ICefBrowser; rect : PCefRect; out Result : Boolean);
Expand All @@ -30,6 +31,8 @@ TMainform = class(TForm)
procedure EUrlKeyDown(Sender : TObject; var Key : Word;
Shift : TShiftState);
procedure FormCreate(Sender : TObject);
procedure OSRPanelEnter(Sender: TObject);
procedure OSRPanelExit(Sender: TObject);
procedure PaintBoxMouseDown(Sender : TObject; Button : TMouseButton;
Shift : TShiftState; X, Y : Integer);
procedure PaintBoxMouseMove(Sender : TObject; Shift : TShiftState;
Expand Down Expand Up @@ -140,6 +143,8 @@ procedure TMainform.PaintBoxMouseDown(Sender : TObject; Button : TMouseButton;
Var
MouseEvent: TCefMouseEvent;
begin
OSRPanel.SetFocus;

MouseEvent.x := X;
MouseEvent.y := Y;
MouseEvent.modifiers := getModifiers(Shift);
Expand Down Expand Up @@ -184,7 +189,6 @@ procedure TMainform.PaintBoxMouseWheel(Sender : TObject; Shift : TShiftState; Wh
procedure TMainform.PaintBoxResize(Sender : TObject);
begin
Chromium.Browser.Host.WasResized;
Chromium.Browser.Host.SendFocusEvent(1);
Application.ProcessMessages;
end;

Expand All @@ -194,4 +198,14 @@ procedure TMainform.FormCreate(Sender : TObject);
//CefBrowserSubprocessPath := '.' + PathDelim + 'subprocess'{$IFDEF WINDOWS}+'.exe'{$ENDIF};
end;

procedure TMainform.OSRPanelEnter(Sender: TObject);
begin
Chromium.Browser.Host.SendFocusEvent(True);
end;

procedure TMainform.OSRPanelExit(Sender: TObject);
begin
Chromium.Browser.Host.SendFocusEvent(False);
end;

end.
2 changes: 1 addition & 1 deletion Examples/OSRDemo/osrdemo.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<RequiredPackages Count="3">
<Item1>
<PackageName Value="BGRABitmapPack"/>
<MinVersion Major="8" Minor="8" Release="1" Valid="True"/>
<MinVersion Major="9" Minor="1" Valid="True"/>
</Item1>
<Item2>
<PackageName Value="CEF3"/>
Expand Down

0 comments on commit 36679d9

Please sign in to comment.