BaseBrowser.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // Copyright aXiuShen. All Rights Reserved.
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "ImitateInput.h"
  5. #include "MatureJsonValue.h"
  6. #include "Widgets/SCompoundWidget.h"
  7. #define BASEBROWSER_PARAMS(CLASSNAME) \
  8. DECLARE_DELEGATE_RetVal_OneParam(bool, FOnKeyUp, const FKeyEvent&); \
  9. DECLARE_DELEGATE_RetVal_OneParam(bool, FOnKeyDown, const FKeyEvent&); \
  10. DECLARE_DELEGATE_RetVal_OneParam(bool, FOnKeyChar, const FCharacterEvent&); \
  11. DECLARE_DELEGATE_OneParam(FOnLoadState, const int); \
  12. DECLARE_DELEGATE_RetVal_TwoParams(bool, FOnBeforePopup, FString, FString); \
  13. DECLARE_DELEGATE_TwoParams(FOnPostResponse, const FString&, const FString&); \
  14. DECLARE_DELEGATE_TwoParams(FOnDownloadComplete, FString, FString); \
  15. /*DECLARE_DELEGATE_TwoParams(FOnTextureChanged, UTexture2D*, UTexture2D*);*/ \
  16. DECLARE_DELEGATE_RetVal_ThreeParams(bool, FOnResourceLoad, FString, int, RequestHeaders&); \
  17. DECLARE_DELEGATE_ThreeParams(FOnJsStr, const FString&, const FString&, const FString&); \
  18. DECLARE_DELEGATE_ThreeParams(FOnJs, const FString&, const FMatureJsonValue&, const FString&); \
  19. DECLARE_DELEGATE_FourParams(FOnWebError, const FString&, const FString&, const FString&, int); \
  20. \
  21. SLATE_BEGIN_ARGS(CLASSNAME) \
  22. : _ViewportSize(FVector2D::ZeroVector) \
  23. , _SwitchInputMethod(false) \
  24. , _EnableMouseTransparency(false) \
  25. , _InitialURL(TEXT("")) \
  26. , _BackgroundColor(255, 255, 255, 255) \
  27. , _ShowControls(true) \
  28. , _ShowAddressBar(false) \
  29. , _Touch(false) \
  30. , _BrowserFrameRate(30) \
  31. { \
  32. _Bridge = false; \
  33. _Visibility = EVisibility::SelfHitTestInvisible; \
  34. } \
  35. \
  36. /* this party for event */ \
  37. /** Called before a popup window happens */ \
  38. SLATE_EVENT(FOnBeforePopup, OnBeforePopup) \
  39. /** Called when post response */ \
  40. SLATE_EVENT(FOnPostResponse, OnPostResponse) \
  41. /** Called when document loading change. */ \
  42. SLATE_EVENT(FOnLoadState, OnLoadState) \
  43. /** Called when the Url changes. */ \
  44. SLATE_EVENT(FOnTextChanged, OnUrlChanged) \
  45. /** Called when the Texture changes. */ \
  46. /*SLATE_EVENT(FOnTextureChanged, OnTextureChanged) */ \
  47. /** Called when file download finish. */ \
  48. SLATE_EVENT(FOnDownloadComplete, OnDownloadComplete) \
  49. /** Called when resource download finish before load. */ \
  50. SLATE_EVENT(FOnResourceLoad, OnResourceLoad) \
  51. /** Called when web has error . */ \
  52. SLATE_EVENT(FOnWebError, OnWebError) \
  53. /** Called when web has error . */ \
  54. SLATE_EVENT(FOnJsStr, OnJsStr) \
  55. /** Called when web has error . */ \
  56. SLATE_EVENT(FOnJs, OnJs) \
  57. \
  58. /* this party for params */ \
  59. /** Control and Editor show text style */ \
  60. SLATE_ARGUMENT(FTextBlockStyle, TextStyle) \
  61. /** Desired size of the web browser viewport. */ \
  62. SLATE_ARGUMENT(FVector2D, ViewportSize) \
  63. /** Desired size of the web browser viewport. */ \
  64. SLATE_ARGUMENT(bool, SwitchInputMethod) \
  65. /** allow mouse transcparency webpage */ \
  66. SLATE_ARGUMENT(bool, EnableMouseTransparency) \
  67. /** URL that the browser will initially navigate to. The URL should include the protocol, eg http:// */ \
  68. SLATE_ARGUMENT(FString, InitialURL) \
  69. /** Opaque background color used before a document is loaded and when no document color is specified. */ \
  70. SLATE_ARGUMENT(FColor, BackgroundColor) \
  71. /** Whether to show standard controls like Back, Forward, Reload etc. */ \
  72. SLATE_ARGUMENT(bool, ShowControls) \
  73. /** Whether to show an address bar. */ \
  74. SLATE_ARGUMENT(bool, RightKeyPopup) \
  75. /** Whether to show an address bar. */ \
  76. SLATE_ARGUMENT(bool, ShowAddressBar) \
  77. SLATE_ARGUMENT(bool, Touch) \
  78. SLATE_ARGUMENT(bool, Bridge) \
  79. /** The frames per second rate that the browser will attempt to use. */ \
  80. SLATE_ARGUMENT(int, BrowserFrameRate) \
  81. /** fixed pixel. */ \
  82. SLATE_ARGUMENT(FIntPoint, Pixel) \
  83. /** zoom level*/ \
  84. SLATE_ARGUMENT(float, zoom) \
  85. /** download show tip */ \
  86. SLATE_ARGUMENT(bool, downloadTip) \
  87. SLATE_ARGUMENT(bool, using_json_object) \
  88. /*SLATE_ARGUMENT(float, zoomlevel)*/ \
  89. SLATE_END_ARGS() \
  90. class BASEBROWSER_API SBaseBrowser
  91. : public SCompoundWidget
  92. {
  93. public:
  94. typedef TMap<FString, FString> RequestHeaders;
  95. SBaseBrowser();
  96. virtual ~SBaseBrowser();
  97. /**
  98. * Load the specified URL.
  99. * @param NewURL New URL to load.
  100. */
  101. virtual void LoadURL(FString NewURL, FString PostData = FString(), bool need_response = false);
  102. virtual void LoadString(FString DummyURL, FString Content);
  103. /**
  104. * reopen a new render to replace old render.
  105. * @param NewURL New URL to load.
  106. * if NewURL is empty,will Assign old URL.
  107. */
  108. virtual void ReopenRender(FString NewURL);
  109. /** Get the current title of the web page. */
  110. virtual FText GetTitleText() const;
  111. /** Stop loading the page. */
  112. virtual void StopLoad();
  113. /** Reload the current page. */
  114. virtual void Reload();
  115. /** Reload the current page. */
  116. virtual bool Isloaded();
  117. /** Whether the document is currently being loaded. */
  118. virtual bool IsLoading() const;
  119. /** Execute javascript on the current window */
  120. virtual void ExecuteJavascript(const FString& ScriptText);
  121. /** Returns true if the browser can navigate backwards. */
  122. virtual bool CanGoBack() const;
  123. /** Returns true if the browser can navigate forwards. */
  124. virtual bool CanGoForward() const;
  125. /** Navigate backwards. */
  126. virtual void GoBack();
  127. virtual bool CallJsonStr(const FString& Function, const FString& Data);
  128. virtual bool CallJson(const FString& Function, const FMatureJsonValue& Data);
  129. virtual 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. virtual FString GetUrl() const;
  135. /** Navigate forwards. */
  136. virtual void GoForward();
  137. /** Set Page Zoom level */
  138. virtual void ZoomLevel(float zoomlevel);
  139. /** Set Page pixel */
  140. virtual void WebPixel(FIntPoint pixel);
  141. /** show or hide address bar */
  142. virtual 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. virtual 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. virtual void UnbindUObject(const FString& Name, UObject* Object, bool bIsPermanent = true);
  159. //
  160. virtual void StopRender(bool hidden);
  161. //
  162. virtual void ShowDevTools();
  163. //
  164. virtual void KeyboardMode(WebView_Keyboard_Mode);
  165. //
  166. virtual void Close();
  167. //
  168. virtual void Silent(bool onoff = true);
  169. //
  170. virtual void SetImitateInput(const FImitateInput& ImitateInput);
  171. //
  172. virtual void PenetrateThreshold(uint8_t value);
  173. };