-
Notifications
You must be signed in to change notification settings - Fork 171
/
webview_window.h
106 lines (70 loc) 路 2.85 KB
/
webview_window.h
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
//
// Created by yangbin on 2021/10/20.
//
#ifndef _WEBVIEW_WINDOW_WEBVIEW_WINDOW_H_
#define _WEBVIEW_WINDOW_WEBVIEW_WINDOW_H_
#include <Windows.h>
#include <flutter/dart_project.h>
#include <flutter/method_channel.h>
#include <flutter/encodable_value.h>
#include <flutter/flutter_view_controller.h>
#include <string>
#include <memory>
#include <functional>
#include <wrl.h>
#include "wil/com.h"
#include "WebView2.h"
#include "flutter_view.h"
#include "web_view.h"
class WebviewWindow {
public:
using MethodChannelPtr = std::shared_ptr<flutter::MethodChannel<flutter::EncodableValue>>;
WebviewWindow(MethodChannelPtr method_channel,
int64_t window_id,
int title_bar_height,
std::function<void()> on_close_callback);
virtual ~WebviewWindow();
using CreateCallback = std::function<void(bool success)>;
void CreateAndShow(const std::wstring &title, int height, int width,
const std::wstring &userDataFolder,
int windowPosX, int windowPosY, bool useWindowPositionAndSize,
bool openMaximized, CreateCallback callback);
// OS callback called by message pump. Handles the WM_NCCREATE message which
// is passed when the non-client area is being created and enables automatic
// non-client DPI scaling so that the non-client area automatically
// responsponds to changes in DPI. All other messages are handled by
// MessageHandler.
static LRESULT CALLBACK WndProc(HWND window,
UINT message,
WPARAM wparam,
LPARAM lparam) noexcept;
void SetBrightness(int brightness);
void setVisibility(bool visible);
void moveWebviewWindow(int left, int top, int width, int height);
void bringToForeground();
[[nodiscard]] const std::unique_ptr<webview_window::WebView> &GetWebView() const {
return web_view_;
}
private:
// Retrieves a class instance pointer for |window|
static WebviewWindow *GetThisFromHandle(HWND window) noexcept;
MethodChannelPtr method_channel_;
wil::unique_hwnd hwnd_;
int64_t window_id_;
std::function<void()> on_close_callback_;
std::unique_ptr<webview_window::FlutterView> flutter_action_bar_;
std::unique_ptr<webview_window::WebView> web_view_;
int last_title_bar_width_ = 0;
bool destroyed_ = false;
int title_bar_height_;
// Processes and route salient window messages for mouse handling,
// size change and DPI. Delegates handling of these to member overloads that
// inheriting classes can handle.
LRESULT MessageHandler(HWND window,
UINT message,
WPARAM wparam,
LPARAM lparam) noexcept;
LRESULT HandleNCHitTest(int x, int y) noexcept;
void SetBorderless() noexcept;
};
#endif //_WEBVIEW_WINDOW_WEBVIEW_WINDOW_H_