123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- // Engine/Source/Runtime/WebBrowser/Private/WebBrowserViewport.cpp
- #include "WebInterfaceBrowserViewport.h"
- #include "Textures/SlateShaderResource.h"
- #include "Widgets/SWidget.h"
- #include "IWebInterfaceBrowserWindow.h"
- #include "Layout/WidgetPath.h"
- #if WITH_CEF3
- #include "CEF/CEFWebInterfaceBrowserWindow.h"
- #endif
- FIntPoint FWebInterfaceBrowserViewport::GetSize() const
- {
- return (WebBrowserWindow->GetTexture(bIsPopup) != nullptr)
- ? FIntPoint(WebBrowserWindow->GetTexture(bIsPopup)->GetWidth(), WebBrowserWindow->GetTexture(bIsPopup)->GetHeight())
- : FIntPoint();
- }
- FSlateShaderResource* FWebInterfaceBrowserViewport::GetViewportRenderTargetTexture() const
- {
- return WebBrowserWindow->GetTexture(bIsPopup);
- }
- void FWebInterfaceBrowserViewport::Tick( const FGeometry& AllottedGeometry, double InCurrentTime, float DeltaTime )
- {
- if (!bIsPopup)
- {
- const float DPI = (WebBrowserWindow->GetParentWindow().IsValid() ? WebBrowserWindow->GetParentWindow()->GetNativeWindow()->GetDPIScaleFactor() : 1.0f);
- const float DPIScale = AllottedGeometry.Scale / DPI;
- FVector2D AbsoluteSize = AllottedGeometry.GetLocalSize() * DPIScale;
- WebBrowserWindow->SetViewportSize(AbsoluteSize.IntPoint(), AllottedGeometry.GetAbsolutePosition().IntPoint());
- #if WITH_CEF3
- // Forward the AllottedGeometry to the WebBrowserWindow so the IME implementation can use it
- TSharedPtr<FCEFWebInterfaceBrowserWindow> CefWebBrowserWindow = StaticCastSharedPtr<FCEFWebInterfaceBrowserWindow>(WebBrowserWindow);
- CefWebBrowserWindow->UpdateCachedGeometry(AllottedGeometry);
- #endif
- }
- }
- bool FWebInterfaceBrowserViewport::RequiresVsync() const
- {
- return false;
- }
- FCursorReply FWebInterfaceBrowserViewport::OnCursorQuery( const FGeometry& MyGeometry, const FPointerEvent& CursorEvent )
- {
- return WebBrowserWindow->OnCursorQuery(MyGeometry, CursorEvent);
- }
- FReply FWebInterfaceBrowserViewport::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
- {
- // Capture mouse on left button down so that you can drag out of the viewport
- FReply Reply = WebBrowserWindow->OnMouseButtonDown(MyGeometry, MouseEvent, bIsPopup);
- if (MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton)
- {
- const FWidgetPath* Path = MouseEvent.GetEventPath();
- if (Path->IsValid())
- {
- TSharedRef<SWidget> TopWidget = Path->Widgets.Last().Widget;
- return Reply.CaptureMouse(TopWidget);
- }
- }
- return Reply;
- }
- FReply FWebInterfaceBrowserViewport::OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
- {
- // Release mouse capture when left button released
- FReply Reply = WebBrowserWindow->OnMouseButtonUp(MyGeometry, MouseEvent, bIsPopup);
- if (MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton)
- {
- return Reply.ReleaseMouseCapture();
- }
- return Reply;
- }
- void FWebInterfaceBrowserViewport::OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
- {
- }
- void FWebInterfaceBrowserViewport::OnMouseLeave(const FPointerEvent& MouseEvent)
- {
- WebBrowserWindow->OnMouseLeave(MouseEvent);
- }
- FReply FWebInterfaceBrowserViewport::OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
- {
- return WebBrowserWindow->OnMouseMove(MyGeometry, MouseEvent, bIsPopup);
- }
- FReply FWebInterfaceBrowserViewport::OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
- {
- return WebBrowserWindow->OnMouseWheel(MyGeometry, MouseEvent, bIsPopup);
- }
- FReply FWebInterfaceBrowserViewport::OnTouchGesture(const FGeometry& MyGeometry, const FPointerEvent& GestureEvent)
- {
- return WebBrowserWindow->OnTouchGesture(MyGeometry, GestureEvent, bIsPopup);
- }
- FReply FWebInterfaceBrowserViewport::OnMouseButtonDoubleClick(const FGeometry& InMyGeometry, const FPointerEvent& InMouseEvent)
- {
- FReply Reply = WebBrowserWindow->OnMouseButtonDoubleClick(InMyGeometry, InMouseEvent, bIsPopup);
- return Reply;
- }
- FReply FWebInterfaceBrowserViewport::OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent)
- {
- return WebBrowserWindow->OnKeyDown(InKeyEvent) ? FReply::Handled() : FReply::Unhandled();
- }
- FReply FWebInterfaceBrowserViewport::OnKeyUp(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent)
- {
- return WebBrowserWindow->OnKeyUp(InKeyEvent) ? FReply::Handled() : FReply::Unhandled();
- }
- FReply FWebInterfaceBrowserViewport::OnKeyChar( const FGeometry& MyGeometry, const FCharacterEvent& InCharacterEvent )
- {
- return WebBrowserWindow->OnKeyChar(InCharacterEvent) ? FReply::Handled() : FReply::Unhandled();
- }
- FReply FWebInterfaceBrowserViewport::OnFocusReceived(const FFocusEvent& InFocusEvent)
- {
- WebBrowserWindow->OnFocus(true, bIsPopup);
- return FReply::Handled();
- }
- void FWebInterfaceBrowserViewport::OnFocusLost(const FFocusEvent& InFocusEvent)
- {
- WebBrowserWindow->OnFocus(false, bIsPopup);
- }
|