WebInterfaceBrowserViewport.cpp
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// 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);
CefWebBrowserWindow->SetZoomLevelByPercentage(DPI);
#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::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);
}