forked from MicrosoftEdge/WebView2Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewComponent.h
More file actions
125 lines (102 loc) · 4.18 KB
/
Copy pathViewComponent.h
File metadata and controls
125 lines (102 loc) · 4.18 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
// Copyright (C) Microsoft Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#pragma once
#include "stdafx.h"
#include "AppWindow.h"
#include "ComponentBase.h"
#include <dcomp.h>
#include <unordered_set>
#ifdef USE_WEBVIEW2_WIN10
#include <winrt/Windows.UI.Composition.Desktop.h>
#endif
// This component handles commands from the View menu, as well as the ZoomFactorChanged
// event, and any functionality related to sizing and visibility of the WebView.
// It also manages interaction with the compositor if running in windowless mode.
class DCompTargetImpl;
class DropTarget;
class ViewComponent : public ComponentBase
{
friend class DCompTargetImpl;
public:
ViewComponent(
AppWindow* appWindow,
IDCompositionDevice* dcompDevice,
#ifdef USE_WEBVIEW2_WIN10
winrtComp::Compositor wincompCompositor,
#endif
bool isDCompTargetMode
);
bool HandleWindowMessage(
HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam,
LRESULT* result) override;
void SetBounds(RECT bounds);
// Converts a screen point to a WebView client point while taking into
// account WebView's offset.
void OffsetPointToWebView(LPPOINT point);
void UpdateDpiAndTextScale();
~ViewComponent() override;
private:
enum class TransformType
{
kIdentity = 0,
kScale2X,
kRotate30Deg,
kRotate60DegDiagonally
};
void ResizeWebView();
void ToggleVisibility();
void SetSizeRatio(float ratio);
void SetZoomFactor(float zoom);
void SetScale(float scale);
void SetTransform(TransformType transformType);
void SetRasterizationScale(float additionalScale);
void SetBoundsMode(COREWEBVIEW2_BOUNDS_MODE boundsMode);
void ShowWebViewBounds();
void ShowWebViewZoom();
AppWindow* m_appWindow = nullptr;
wil::com_ptr<ICoreWebView2Controller> m_controller;
wil::com_ptr<ICoreWebView2> m_webView;
wil::com_ptr<ICoreWebView2ExperimentalController> m_controllerExperimental;
bool m_isDcompTargetMode;
bool m_isVisible = true;
float m_webViewRatio = 1.0f;
float m_webViewZoomFactor = 1.0f;
RECT m_webViewBounds = {};
float m_webViewScale = 1.0f;
bool m_useCursorId = false;
wil::com_ptr<DropTarget> m_dropTarget;
float m_webviewAdditionalRasterizationScale = 1.0f;
COREWEBVIEW2_BOUNDS_MODE m_boundsMode = COREWEBVIEW2_USE_RAW_PIXELS;
EventRegistrationToken m_zoomFactorChangedToken = {};
EventRegistrationToken m_rasterizationScaleChangedToken = {};
bool OnMouseMessage(UINT message, WPARAM wParam, LPARAM lParam);
bool OnPointerMessage(UINT message, WPARAM wParam, LPARAM lParam);
void TrackMouseEvents(DWORD mouseTrackingFlags);
wil::com_ptr<ICoreWebView2ExperimentalCompositionController> m_compositionController;
bool m_isTrackingMouse = false;
bool m_isCapturingMouse = false;
std::unordered_set<UINT> m_pointerIdsStartingInWebView;
D2D1_MATRIX_4X4_F m_webViewTransformMatrix = D2D1::Matrix4x4F();
void BuildDCompTreeUsingVisual();
void DestroyDCompVisualTree();
wil::com_ptr<IDCompositionDevice> m_dcompDevice;
wil::com_ptr<IDCompositionTarget> m_dcompHwndTarget;
wil::com_ptr<IDCompositionVisual> m_dcompRootVisual;
wil::com_ptr<IDCompositionVisual> m_dcompWebViewVisual;
#ifdef USE_WEBVIEW2_WIN10
void BuildWinCompVisualTree();
void DestroyWinCompVisualTree();
winrt::Windows::UI::Composition::Compositor m_wincompCompositor{ nullptr };
winrt::Windows::UI::Composition::Desktop::DesktopWindowTarget m_wincompHwndTarget{ nullptr };
winrt::Windows::UI::Composition::ContainerVisual m_wincompRootVisual{ nullptr };
winrt::Windows::UI::Composition::ContainerVisual m_wincompWebViewVisual{ nullptr };
#endif
// This member is used to exercise the put_RootVisualTarget API with an IDCompositionTarget.
// Distinct/unrelated to the dcompHwndTarget
wil::com_ptr<DCompTargetImpl> m_dcompTarget;
EventRegistrationToken m_cursorChangedToken = {};
};