SCefBrowser.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. // Copyright aXiuShen. All Rights Reserved.
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "Layout/Visibility.h"
  5. #include "Input/Reply.h"
  6. #include "Widgets/DeclarativeSyntaxSupport.h"
  7. #include "Widgets/SCompoundWidget.h"
  8. #include "Framework/SlateDelegates.h"
  9. #include "CefImitateInput.h"
  10. #include "Styling/SlateTypes.h"
  11. #include "warp_macro.h"
  12. class UWebCoreData;
  13. class CEFBROWSER_DLL SCefBrowser
  14. : public SCompoundWidget
  15. {
  16. public:
  17. typedef TMap<FString, FString> RequestHeaders;
  18. DECLARE_DELEGATE_RetVal_OneParam(bool, FOnKeyUp, const FKeyEvent& );
  19. DECLARE_DELEGATE_RetVal_OneParam(bool, FOnKeyDown, const FKeyEvent& );
  20. DECLARE_DELEGATE_RetVal_OneParam(bool, FOnKeyChar, const FCharacterEvent& );
  21. DECLARE_DELEGATE_OneParam(FOnLoadState, const int);
  22. DECLARE_DELEGATE_RetVal_TwoParams(bool, FOnBeforePopup, FString, FString);
  23. DECLARE_DELEGATE_TwoParams(FOnPostResponse,const FString&, const FString&);
  24. DECLARE_DELEGATE_TwoParams(FOnDownloadComplete, FString, FString);
  25. //DECLARE_DELEGATE_TwoParams(FOnTextureChanged, UTexture2D*, UTexture2D*);
  26. DECLARE_DELEGATE_RetVal_ThreeParams(bool, FOnResourceLoad, FString, int, RequestHeaders&);
  27. DECLARE_DELEGATE_ThreeParams(FOnJsStr, const FString&, const FString&, const FString&);
  28. DECLARE_DELEGATE_FourParams(FOnWebError,const FString&, const FString&, const FString&,int);
  29. SLATE_BEGIN_ARGS(SCefBrowser)
  30. : _ViewportSize(FVector2D::ZeroVector)
  31. , _SwitchInputMethod(false)
  32. , _EnableMouseTransparency(false)
  33. , _InitialURL(TEXT(""))
  34. , _BackgroundColor(255, 255, 255, 255)
  35. , _ShowControls(true)
  36. , _ShowAddressBar(false)
  37. , _Touch(false)
  38. //, _webCursor(false)
  39. , _BrowserFrameRate(30)
  40. {
  41. _Bridge = false;
  42. _Visibility = EVisibility::SelfHitTestInvisible;
  43. }
  44. /* this party for event */
  45. /** Called before a popup window happens */
  46. SLATE_EVENT(FOnBeforePopup, OnBeforePopup)
  47. /** Called when post response */
  48. SLATE_EVENT(FOnPostResponse, OnPostResponse)
  49. /** Called when document loading change. */
  50. SLATE_EVENT(FOnLoadState, OnLoadState)
  51. /** Called when the Url changes. */
  52. SLATE_EVENT(FOnTextChanged, OnUrlChanged)
  53. /** Called when the Texture changes. */
  54. //SLATE_EVENT(FOnTextureChanged, OnTextureChanged)
  55. /** Called when file download finish. */
  56. SLATE_EVENT(FOnDownloadComplete, OnDownloadComplete)
  57. /** Called when resource download finish before load. */
  58. SLATE_EVENT(FOnResourceLoad, OnResourceLoad)
  59. /** Called when web has error . */
  60. SLATE_EVENT(FOnWebError, OnWebError)
  61. /** Called when web has error . */
  62. SLATE_EVENT(FOnJsStr, OnJsStr)
  63. /* this party for params */
  64. /** Control and Editor show text style */
  65. SLATE_ARGUMENT(FTextBlockStyle, TextStyle)
  66. /** Desired size of the web browser viewport. */
  67. SLATE_ARGUMENT(FVector2D, ViewportSize)
  68. /** Desired size of the web browser viewport. */
  69. //SLATE_ARGUMENT(FImitateInput, ImitateInput)
  70. /** Desired size of the web browser viewport. */
  71. SLATE_ARGUMENT(bool, SwitchInputMethod)
  72. /** allow mouse transcparency webpage */
  73. SLATE_ARGUMENT(bool, EnableMouseTransparency)
  74. /** URL that the browser will initially navigate to. The URL should include the protocol, eg http:// */
  75. SLATE_ARGUMENT(FString, InitialURL)
  76. /** Opaque background color used before a document is loaded and when no document color is specified. */
  77. SLATE_ARGUMENT(FColor, BackgroundColor)
  78. /** Whether to show standard controls like Back, Forward, Reload etc. */
  79. SLATE_ARGUMENT(bool, ShowControls)
  80. /** Whether to show an address bar. */
  81. SLATE_ARGUMENT(bool, RightKeyPopup)
  82. /** Whether to show an address bar. */
  83. SLATE_ARGUMENT(bool, ShowAddressBar)
  84. SLATE_ARGUMENT(bool, Touch)
  85. SLATE_ARGUMENT(bool, Bridge)
  86. /** Whether to show an Web Cursor . */
  87. //SLATE_ARGUMENT(bool, webCursor)
  88. /** The frames per second rate that the browser will attempt to use. */
  89. SLATE_ARGUMENT(int, BrowserFrameRate)
  90. /** fixed pixel. */
  91. SLATE_ARGUMENT(FIntPoint, Pixel)
  92. /** zoom level*/
  93. SLATE_ARGUMENT(float, zoom)
  94. /** download show tip */
  95. SLATE_ARGUMENT(bool, downloadTip)
  96. //SLATE_ARGUMENT(float, zoomlevel)
  97. SLATE_END_ARGS()
  98. /**
  99. * Load the specified URL.
  100. * @param NewURL New URL to load.
  101. */
  102. void LoadURL(FString NewURL, FString PostData = FString(), bool need_response=false);
  103. void LoadString(FString DummyURL, FString Content);
  104. /**
  105. * reopen a new render to replace old render.
  106. * @param NewURL New URL to load.
  107. * if NewURL is empty,will Assign old URL.
  108. */
  109. void ReopenRender(FString NewURL);
  110. /** Get the current title of the web page. */
  111. FText GetTitleText() const;
  112. /** Stop loading the page. */
  113. void StopLoad();
  114. /** Reload the current page. */
  115. void Reload();
  116. /** Reload the current page. */
  117. bool Isloaded();
  118. /** Whether the document is currently being loaded. */
  119. bool IsLoading() const;
  120. /** Execute javascript on the current window */
  121. void ExecuteJavascript(const FString& ScriptText);
  122. /** Returns true if the browser can navigate backwards. */
  123. bool CanGoBack() const;
  124. /** Returns true if the browser can navigate forwards. */
  125. bool CanGoForward() const;
  126. /** Navigate backwards. */
  127. void GoBack();
  128. bool CallJsonStr(const FString& Function, const FString& Data);
  129. void PopupURL(const FString& URL);
  130. /**
  131. * Gets the currently loaded URL.
  132. * @return The URL, or empty string if no document is loaded.
  133. */
  134. FString GetUrl() const;
  135. /** Navigate forwards. */
  136. void GoForward();
  137. /** Set Page Zoom level */
  138. void ZoomLevel(float zoomlevel);
  139. /** Set Page pixel */
  140. void WebPixel(FIntPoint pixel);
  141. /** show or hide address bar */
  142. void ShowAddress(bool isShow);
  143. /**
  144. * Expose a UObject instance to the browser runtime.
  145. * Properties and Functions will be accessible from JavaScript side.
  146. * As all communication with the rendering procesis asynchronous, return values (both for properties and function results) are wrapped into JS Future objects.
  147. * @param Name The name of the object. The object will show up as window.ue4.{Name} on the javascript side. If there is an existing object of the same name, this object will replace it. If bIsPermanent is false and there is an existing permanent binding, the permanent binding will be restored when the temporary one is removed.
  148. * @param Object The object instance.
  149. * @param bIsPermanent If true, the object will be visible to all pages loaded through this browser widget, otherwise, it will be deleted when navigating away from the current page. Non-permanent bindings should be registered from inside an OnLoadStarted event handler in order to be available before JS code starts loading.
  150. */
  151. void BindUObject(const FString& Name, UObject* Object, bool bIsPermanent = true);
  152. /**
  153. * Remove an existing script binding registered by BindUObject.
  154. * @param Name The name of the object to remove.
  155. * @param Object The object will only be removed if it is the same object as the one passed in.
  156. * @param bIsPermanent Must match the bIsPermanent argument passed to BindUObject.
  157. */
  158. void UnbindUObject(const FString& Name, UObject* Object, bool bIsPermanent = true);
  159. //
  160. void StopRender(bool hidden);
  161. //
  162. void ShowDevTools();
  163. //
  164. void KeyboardMode(cef::WebView_Keyboard_Mode);
  165. //
  166. void Close();
  167. //
  168. void Silent(bool onoff=true);
  169. //
  170. void SetImitateInput(const cef::FImitateInput& ImitateInput);
  171. public:
  172. /** Default constructor. */
  173. SCefBrowser();
  174. ~SCefBrowser();
  175. /**
  176. * Construct the widget.
  177. * @param InArgs Declaration from which to construct the widget.
  178. */
  179. void Construct(const FArguments& InArgs,const bool isFirst=true);
  180. private:
  181. //
  182. virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime);
  183. virtual void OnDragEnter(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent) override;
  184. virtual void OnDragLeave(const FDragDropEvent& DragDropEvent) override;
  185. virtual FReply OnDragOver(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent) override;
  186. virtual FReply OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent)override;
  187. private:
  188. TSharedPtr<UWebCoreData> _WebCoreData;
  189. };