-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathufrmModel.pas
142 lines (119 loc) · 3.62 KB
/
ufrmModel.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
unit ufrmModel;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DynamicSkinForm, ExtCtrls, uCEFChromium, uCEFWindowParent,uCEFInterfaces;
type
TfrmModal = class(TForm)
spDynamicSkinForm1: TspDynamicSkinForm;
CEFWindowParent1: TCEFWindowParent;
Chromium1: TChromium;
DevTools: TCEFWindowParent;
Splitter1: TSplitter;
Timer1: TTimer;
procedure Chromium1BeforeContextMenu(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; const model: ICefMenuModel);
procedure Chromium1ContextMenuCommand(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;
eventFlags: Cardinal; out Result: Boolean);
procedure FormShow(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
protected
procedure ShowDevTools(aPoint: TPoint); overload;
procedure ShowDevTools; overload;
procedure HideDevTools;
public
{ Public declarations }
constructor Create(caption: string; width: Integer; height: Integer); overload;
end;
var
frmModal: TfrmModal;
implementation
uses
ufrmMain, unConfig;
{$R *.dfm}
{ TfrmModel }
procedure TfrmModal.Chromium1BeforeContextMenu(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; const model: ICefMenuModel);
begin
// 非调试模式下,无右键菜单
if StrToIntDef(unConfig.getValue('debug'), 0) = 0 then
begin
model.Clear;
Exit;
end;
model.AddSeparator;
if DevTools.Visible then
model.AddItem(MINIBROWSER_CONTEXTMENU_HIDEDEVTOOLS, '关闭开发工具')
else
model.AddItem(MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS, '显示开发工具');
model.AddItem(CUSTOMMENUCOMMAND_REFRESH, '刷新(&R)');
end;
procedure TfrmModal.Chromium1ContextMenuCommand(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer; eventFlags: Cardinal;
out Result: Boolean);
var
TempParam: WParam;
begin
Result := false;
case commandId of
MINIBROWSER_CONTEXTMENU_HIDEDEVTOOLS:
PostMessage(Handle, MINIBROWSER_HIDEDEVTOOLS, 0, 0);
MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS:
begin
TempParam := ((params.XCoord and $FFFF) shl 16) or
(params.YCoord and $FFFF);
PostMessage(Handle, MINIBROWSER_SHOWDEVTOOLS, TempParam, 0);
end;
CUSTOMMENUCOMMAND_REFRESH:
PostMessage(Handle, MINIBROWSER_REFRESH, 0, 0);
end;
end;
constructor TfrmModal.Create(caption: string; width, height: Integer);
begin
inherited create(nil);
Self.Caption := caption;
Self.Width := width;
Self.Height := height;
end;
procedure TfrmModal.FormShow(Sender: TObject);
begin
if not (Chromium1.CreateBrowser(CEFWindowParent1, '')) then
Timer1.Enabled := True;
end;
procedure TfrmModal.HideDevTools;
begin
Chromium1.CloseDevTools(DevTools);
Splitter1.Visible := false;
DevTools.Visible := false;
DevTools.Width := 0;
end;
procedure TfrmModal.ShowDevTools(aPoint: TPoint);
begin
Splitter1.Visible := True;
DevTools.Visible := True;
DevTools.Width := Width div 4;
Chromium1.ShowDevTools(aPoint, DevTools);
end;
procedure TfrmModal.ShowDevTools;
var
TempPoint: TPoint;
begin
TempPoint.x := low(Integer);
TempPoint.y := low(Integer);
ShowDevTools(TempPoint);
end;
procedure TfrmModal.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := false;
if not (Chromium1.CreateBrowser(CEFWindowParent1, '')) and not
(Chromium1.Initialized) then
Timer1.Enabled := True;
end;
end.