123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- #pragma once
- #include "CoreMinimal.h"
- #include "Widgets/DeclarativeSyntaxSupport.h"
- #include "Input/PopupMethodReply.h"
- #include "Widgets/SWidget.h"
- #include "Widgets/SCompoundWidget.h"
- #include "Framework/Application/IMenu.h"
- #include "Framework/SlateDelegates.h"
- #include "Widgets/SViewport.h"
- #include "IWebInterfaceBrowserSingleton.h"
- class FWebInterfaceBrowserViewport;
- class IWebInterfaceBrowserAdapter;
- class IWebInterfaceBrowserDialog;
- class IWebInterfaceBrowserPopupFeatures;
- class IWebInterfaceBrowserWindow;
- struct FWebNavigationRequest;
- enum class EWebInterfaceBrowserDialogEventResponse;
- enum class EWebInterfaceBrowserDocumentState;
- enum class EWebInterfaceBrowserConsoleLogSeverity;
- DECLARE_DELEGATE_RetVal_TwoParams(bool, FOnBeforePopupDelegate, FString, FString);
- DECLARE_DELEGATE_RetVal_TwoParams(bool, FOnCreateWindowDelegate, const TWeakPtr<IWebInterfaceBrowserWindow>&, const TWeakPtr<IWebInterfaceBrowserPopupFeatures>&);
- DECLARE_DELEGATE_RetVal_OneParam(bool, FOnCloseWindowDelegate, const TWeakPtr<IWebInterfaceBrowserWindow>&);
- DECLARE_DELEGATE_RetVal_OneParam(TSharedPtr<IToolTip>, FOnCreateToolTip, const FText&);
- DECLARE_DELEGATE_FourParams(FOnConsoleMessageDelegate, const FString& , const FString& , int32 , EWebInterfaceBrowserConsoleLogSeverity );
- #if WITH_CEF3
- typedef SViewport SWebInterfaceBrowserWidget;
- #else
- typedef SWidget SWebInterfaceBrowserWidget;
- #endif
- class WEBBROWSERUI_API SWebInterfaceBrowserView
- : public SCompoundWidget
- {
- public:
- DECLARE_DELEGATE_RetVal_TwoParams(bool, FOnBeforeBrowse, const FString& , const FWebNavigationRequest& )
- DECLARE_DELEGATE_RetVal_ThreeParams(bool, FOnLoadUrl, const FString& , const FString& , FString& )
- DECLARE_DELEGATE_RetVal_OneParam(EWebInterfaceBrowserDialogEventResponse, FOnShowDialog, const TWeakPtr<IWebInterfaceBrowserDialog>&);
- DECLARE_DELEGATE_RetVal(bool, FOnSuppressContextMenu);
- DECLARE_DELEGATE_RetVal_OneParam(bool, FOnDragWindow, const FPointerEvent& );
- DECLARE_DELEGATE_RetVal_OneParam(bool, FOnUnhandledKeyDown, const FKeyEvent& );
- DECLARE_DELEGATE_RetVal_OneParam(bool, FOnUnhandledKeyUp, const FKeyEvent& );
- DECLARE_DELEGATE_RetVal_OneParam(bool, FOnUnhandledKeyChar, const FCharacterEvent& );
- SLATE_BEGIN_ARGS(SWebInterfaceBrowserView)
- : _InitialURL(TEXT("https://www.google.com"))
- , _ShowErrorMessage(true)
- , _SupportsTransparency(false)
- , _InterceptLoadRequests(false)
- , _SupportsThumbMouseButtonNavigation(true)
- , _BackgroundColor(255,255,255,255)
- , _BrowserFrameRate(24)
- , _PopupMenuMethod(TOptional<EPopupMethod>())
- , _ContextSettings()
- , _AltRetryDomains(TArray<FString>())
- , _ViewportSize(FVector2D::ZeroVector)
- { }
-
- SLATE_ARGUMENT(TSharedPtr<SWindow>, ParentWindow)
-
- SLATE_ARGUMENT(FString, InitialURL)
-
- SLATE_ARGUMENT(TOptional<FString>, ContentsToLoad)
-
- SLATE_ARGUMENT(bool, ShowErrorMessage)
-
- SLATE_ARGUMENT(bool, SupportsTransparency)
-
- SLATE_ARGUMENT(bool, InterceptLoadRequests)
-
- SLATE_ARGUMENT(bool, SupportsThumbMouseButtonNavigation)
-
- SLATE_ARGUMENT(FColor, BackgroundColor)
-
- SLATE_ARGUMENT(int, BrowserFrameRate)
-
- SLATE_ARGUMENT(TOptional<EPopupMethod>, PopupMenuMethod)
-
- SLATE_ARGUMENT(TOptional<FInterfaceBrowserContextSettings>, ContextSettings)
-
- SLATE_ARGUMENT(TArray<FString>, AltRetryDomains)
-
- SLATE_ATTRIBUTE(FVector2D, ViewportSize);
-
- SLATE_EVENT(FSimpleDelegate, OnLoadCompleted)
-
- SLATE_EVENT(FSimpleDelegate, OnLoadError)
-
- SLATE_EVENT(FSimpleDelegate, OnLoadStarted)
-
- SLATE_EVENT(FOnTextChanged, OnTitleChanged)
-
- SLATE_EVENT(FOnTextChanged, OnUrlChanged)
-
- SLATE_EVENT(FOnBeforePopupDelegate, OnBeforePopup)
-
- SLATE_EVENT(FOnCreateWindowDelegate, OnCreateWindow)
-
- SLATE_EVENT(FOnCloseWindowDelegate, OnCloseWindow)
-
- SLATE_EVENT(FOnBeforeBrowse, OnBeforeNavigation)
-
- SLATE_EVENT(FOnLoadUrl, OnLoadUrl)
-
- SLATE_EVENT(FOnShowDialog, OnShowDialog)
-
- SLATE_EVENT(FSimpleDelegate, OnDismissAllDialogs)
-
- SLATE_EVENT(FOnSuppressContextMenu, OnSuppressContextMenu);
-
- SLATE_EVENT(FOnCreateToolTip, OnCreateToolTip)
-
- SLATE_EVENT(FOnDragWindow, OnDragWindow)
-
-
- SLATE_EVENT(FOnUnhandledKeyDown, OnUnhandledKeyDown)
-
- SLATE_EVENT(FOnUnhandledKeyUp, OnUnhandledKeyUp)
-
- SLATE_EVENT(FOnUnhandledKeyChar, OnUnhandledKeyChar)
-
-
- SLATE_EVENT(FOnConsoleMessageDelegate, OnConsoleMessage)
- SLATE_END_ARGS()
-
- SWebInterfaceBrowserView();
- ~SWebInterfaceBrowserView();
- virtual bool SupportsKeyboardFocus() const override {return true;}
-
- void Construct(const FArguments& InArgs, const TSharedPtr<IWebInterfaceBrowserWindow>& InWebBrowserWindow = nullptr);
- virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override;
-
- void LoadURL(FString NewURL);
-
- void LoadString(FString Contents, FString DummyURL);
-
- void Reload();
-
- void StopLoad();
-
- FText GetTitleText() const;
-
- FString GetUrl() const;
-
- FText GetAddressBarUrlText() const;
-
- bool IsLoaded() const;
-
- bool IsLoading() const;
-
- bool IsInitialized() const;
-
- void ExecuteJavascript(const FString& ScriptText);
-
- void GetSource(TFunction<void (const FString&)> Callback) const ;
-
- void BindUObject(const FString& Name, UObject* Object, bool bIsPermanent = true);
-
- void UnbindUObject(const FString& Name, UObject* Object, bool bIsPermanent = true);
- void BindAdapter(const TSharedRef<IWebInterfaceBrowserAdapter>& Adapter);
- void UnbindAdapter(const TSharedRef<IWebInterfaceBrowserAdapter>& Adapter);
- void BindInputMethodSystem(ITextInputMethodSystem* TextInputMethodSystem);
- void UnbindInputMethodSystem();
-
- bool CanGoBack() const;
-
- void GoBack();
-
- bool CanGoForward() const;
-
- void GoForward();
-
- void SetParentWindow(TSharedPtr<SWindow> Window);
-
- void SetBrowserKeyboardFocus();
-
- void CloseBrowser();
- private:
- void SetupParentWindowHandlers();
-
- void HandleBrowserWindowDocumentStateChanged(EWebInterfaceBrowserDocumentState NewState);
-
- void HandleBrowserWindowNeedsRedraw();
-
- void HandleTitleChanged(FString NewTitle);
-
- void HandleUrlChanged(FString NewUrl);
-
- void HandleToolTip(FString ToolTipText);
-
- bool HandleBeforeNavigation(const FString& Url, const FWebNavigationRequest& Request);
- bool HandleLoadUrl(const FString& Method, const FString& Url, FString& OutResponse);
-
- bool HandleCreateWindow(const TWeakPtr<IWebInterfaceBrowserWindow>& NewBrowserWindow, const TWeakPtr<IWebInterfaceBrowserPopupFeatures>& PopupFeatures);
-
- bool HandleCloseWindow(const TWeakPtr<IWebInterfaceBrowserWindow>& BrowserWindow);
-
- EWebInterfaceBrowserDialogEventResponse HandleShowDialog(const TWeakPtr<IWebInterfaceBrowserDialog>& DialogParams);
-
- void HandleDismissAllDialogs();
-
- bool HandleBeforePopup(FString URL, FString Target);
-
- void HandleShowPopup(const FIntRect& PopupSize);
-
- void HandleDismissPopup();
-
- void HandleMenuDismissed(TSharedRef<IMenu>);
- virtual FPopupMethodReply OnQueryPopupMethod() const override
- {
- return PopupMenuMethod.IsSet()
- ? FPopupMethodReply::UseMethod(PopupMenuMethod.GetValue())
- : FPopupMethodReply::Unhandled();
- }
- void HandleWindowDeactivated();
- void HandleWindowActivated();
- bool UnhandledKeyDown(const FKeyEvent& KeyEvent);
- bool UnhandledKeyUp(const FKeyEvent& KeyEvent);
- bool UnhandledKeyChar(const FCharacterEvent& CharacterEvent);
- bool HandleDrag(const FPointerEvent& MouseEvent);
- void HandleConsoleMessage(const FString& Message, const FString& Source, int32 Line, EWebInterfaceBrowserConsoleLogSeverity Serverity);
- TOptional<FSlateRenderTransform> GetPopupRenderTransform() const;
- private:
-
- TSharedPtr<IWebInterfaceBrowserWindow> BrowserWindow;
-
- mutable TWeakPtr<SWindow> SlateParentWindowPtr;
-
- TSharedPtr<FWebInterfaceBrowserViewport> BrowserViewport;
-
- TSharedPtr<FWebInterfaceBrowserViewport> MenuViewport;
-
- TSharedPtr<SWebInterfaceBrowserWidget> BrowserWidget;
- TArray<TSharedRef<IWebInterfaceBrowserAdapter>> Adapters;
-
- TWeakPtr<IMenu> PopupMenuPtr;
-
- TOptional<EPopupMethod> PopupMenuMethod;
-
- FText AddressBarUrl;
-
- FSimpleDelegate OnLoadCompleted;
-
- FSimpleDelegate OnLoadError;
-
- FSimpleDelegate OnLoadStarted;
-
- FOnTextChanged OnTitleChanged;
-
- FOnTextChanged OnUrlChanged;
-
- FOnBeforePopupDelegate OnBeforePopup;
-
- FOnCreateWindowDelegate OnCreateWindow;
-
- FOnCloseWindowDelegate OnCloseWindow;
-
- FOnBeforeBrowse OnBeforeNavigation;
-
- FOnLoadUrl OnLoadUrl;
-
- FOnShowDialog OnShowDialog;
-
- FSimpleDelegate OnDismissAllDialogs;
- FOnSuppressContextMenu OnSuppressContextMenu;
-
- FOnCreateToolTip OnCreateToolTip;
-
- FOnDragWindow OnDragWindow;
-
-
- FOnUnhandledKeyDown OnUnhandledKeyDown;
-
- FOnUnhandledKeyUp OnUnhandledKeyUp;
-
- FOnUnhandledKeyChar OnUnhandledKeyChar;
-
-
- FOnConsoleMessageDelegate OnConsoleMessage;
- protected:
- bool HandleSuppressContextMenu();
- };
|