-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqcefwebview.cpp
66 lines (46 loc) · 1.42 KB
/
qcefwebview.cpp
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
#include "qcefwebview.h"
#include "clienthandler.h"
#include "clientapp.h"
#include <include/cef_client.h>
#include <include/cef_app.h>
static CefRefPtr<ClientApp> app = nullptr;
QCefWebView::QCefWebView()
{
_state = NoneBrowserState;
setAttribute(Qt::WA_NativeWindow);
setAttribute(Qt::WA_DontCreateNativeAncestors);
if (!app) {
app = new ClientApp();
}
}
void QCefWebView::showEvent(QShowEvent *event)
{
createBrowser(rect());
}
void QCefWebView::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
}
void QCefWebView::createBrowser(const QRect &rect)
{
CefRect r;
r.x = 0;
r.y = 0;
r.width = rect.width();
r.height = rect.height();
printf("Context initialized\n");
CefWindowInfo window_info;
window_info.SetAsChild(this->winId(), r);
printf("setting mWidget as child\n");
CefRefPtr<ClientHandler> handler(new ClientHandler());
// Specify CEF browser settings here.
CefBrowserSettings browser_settings;
std::string url;
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
url = command_line->GetSwitchValue("url");
if (url.empty())
url = "http://www.google.com";
CefBrowserHost::CreateBrowser(window_info, handler.get(), url,
browser_settings, NULL);
}