BaseChromeView.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. unit BaseChromeView;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, cefvcl, BaseWebApp, ceflib, RealICQSkinFrm, InterfaceUI, ViewManager,
  6. superobject;
  7. type
  8. TBaseChromeViewForm = class(TRealICQSkinForm, IUIForm)
  9. Chrome: TChromium;
  10. procedure ChromeKeyEvent(Sender: TObject; const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: PMsg; out Result: Boolean);
  11. procedure ChromeBeforeContextMenu(Sender: TObject;
  12. const browser: ICefBrowser; const frame: ICefFrame;
  13. const params: ICefContextMenuParams; const model: ICefMenuModel);
  14. private
  15. FURL: string;
  16. FAutoFree: Boolean;
  17. { Private declarations }
  18. protected
  19. procedure WMWindowPosChanging(var Message: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
  20. procedure DoShow; override;
  21. procedure DoClose(var Action: TCloseAction); override;
  22. public
  23. function GetIdentify: Cardinal;
  24. procedure SetFormInfo(AJson: WideString);
  25. function GetAutoFree: Boolean;
  26. procedure SetAutoFree(const Value: Boolean);
  27. { Public declarations }
  28. property URL: string read FURL write FURL;
  29. property AutoFree: Boolean read GetAutoFree write SetAutoFree;
  30. end;
  31. var
  32. BaseChromeViewForm: TBaseChromeViewForm;
  33. implementation
  34. uses
  35. DevToolChromeFrm, ConditionConfig;
  36. {$R *.dfm}
  37. { TBaseChromeViewForm }
  38. procedure TBaseChromeViewForm.ChromeBeforeContextMenu(Sender: TObject;
  39. const browser: ICefBrowser; const frame: ICefFrame;
  40. const params: ICefContextMenuParams; const model: ICefMenuModel);
  41. begin
  42. model.Clear;
  43. model.AddItem(Integer(MENU_ID_COPY), '¸´ÖÆ');
  44. end;
  45. procedure TBaseChromeViewForm.ChromeKeyEvent(Sender: TObject; const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: PMsg; out Result: Boolean);
  46. begin
  47. if TConditionConfig.GetConfig.Dev and (event^.windows_key_code = VK_F12) then
  48. ShowDevTool(Self, Chrome);
  49. end;
  50. procedure TBaseChromeViewForm.DoClose(var Action: TCloseAction);
  51. begin
  52. inherited;
  53. if FAutoFree then
  54. Action := caFree;
  55. end;
  56. procedure TBaseChromeViewForm.DoShow;
  57. begin
  58. inherited;
  59. ChangeUIColor($EADEBA);
  60. Chrome.Load(URL);
  61. end;
  62. function TBaseChromeViewForm.GetAutoFree: Boolean;
  63. begin
  64. Result := FAutoFree;
  65. end;
  66. function TBaseChromeViewForm.GetIdentify: Cardinal;
  67. begin
  68. Result := Handle;
  69. end;
  70. procedure TBaseChromeViewForm.SetAutoFree(const Value: Boolean);
  71. begin
  72. FAutoFree := Value;
  73. end;
  74. procedure TBaseChromeViewForm.SetFormInfo(AJson: WideString);
  75. var
  76. AJo: ISuperObject;
  77. begin
  78. AJo := SO(AJson);
  79. if AJo <> nil then
  80. begin
  81. if AJo.S['url'] <> '' then
  82. URL := AJo.S['url'];
  83. if AJo.S['caption'] <> '' then
  84. Caption := AJo.S['caption'];
  85. if AJo.I['width'] > 0 then
  86. Width := AJo.I['width'];
  87. if AJo.I['height'] > 0 then
  88. Height := AJo.I['height'];
  89. if AJo.B['center'] then
  90. begin
  91. // Position := poDesktopCenter;
  92. Top := (Screen.Height - Height) div 2;
  93. Left := (Screen.Width - Width) div 2;
  94. end;
  95. if AJo.B['unsizeable'] then
  96. begin
  97. CanResizeWindow := False;
  98. end;
  99. end;
  100. end;
  101. procedure TBaseChromeViewForm.WMWindowPosChanging(var Message: TWMWindowPosChanging);
  102. begin
  103. if Chrome.Browser <> nil then
  104. Chrome.Browser.Host.NotifyMoveOrResizeStarted;
  105. inherited;
  106. end;
  107. end.