-
Notifications
You must be signed in to change notification settings - Fork 11
/
qultralightview.cpp
715 lines (626 loc) · 21.2 KB
/
qultralightview.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
/*
Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
Copyright (C) 2008 Holger Hans Peter Freyther
Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in>
Copyright (C) 2021 Jerzy Głowacki
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "qultralightview.h"
#include "browserapplication.h"
#include "browsermainwindow.h"
#include "tabwidget.h"
#include "webview.h"
#include <QWindow>
QUltralightView::QUltralightView(QWidget *parent) : QWidget(parent)
{
setAttribute(Qt::WA_AcceptTouchEvents);
setAcceptDrops(true);
setMouseTracking(true);
setFocusPolicy(Qt::WheelFocus);
//Ultralight
_window = ultralight::Window::Create(BrowserApplication::instance()->app->main_monitor(), 0, 0, false, ultralight::kWindowFlags_Hidden);
_overlay = ultralight::Overlay::Create(*_window.get(), _window->width(), _window->height(), 0, 0);
_overlay->view()->set_load_listener(this);
_overlay->view()->set_view_listener(this);
_window->set_listener(this);
QWidget *webview = createWindowContainer(QWindow::fromWinId((unsigned long) _window->native_handle()), this);
QGridLayout *layout = new QGridLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(webview);
setLayout(layout);
}
QUltralightView::~QUltralightView()
{
_overlay->view()->set_load_listener(nullptr);
_overlay->view()->set_view_listener(nullptr);
_window->set_listener(nullptr);
_window->Close();
}
QUltralightPage *QUltralightView::page() const
{
if (!_page) {
QUltralightView *that = const_cast<QUltralightView *>(this);
that->setPage(new QUltralightPage(that));
}
return _page;
}
void QUltralightView::setPage(QUltralightPage* page)
{
if (_page == page)
return;
_page = page;
if (_page) {
_page->setView(this);
_page->setPalette(palette());
// #### connect signals
QUltralightFrame *mainFrame = _page->mainFrame();
connect(mainFrame, SIGNAL(titleChanged(QString)),
this, SIGNAL(titleChanged(QString)));
connect(mainFrame, SIGNAL(iconChanged()),
this, SIGNAL(iconChanged()));
connect(mainFrame, SIGNAL(urlChanged(QUrl)),
this, SIGNAL(urlChanged(QUrl)));
connect(_page, SIGNAL(loadStarted()),
this, SIGNAL(loadStarted()));
connect(_page, SIGNAL(loadProgress(int)),
this, SIGNAL(loadProgress(int)));
connect(_page, SIGNAL(loadFinished(bool)),
this, SIGNAL(loadFinished(bool)));
connect(_page, SIGNAL(statusBarMessage(QString)),
this, SIGNAL(statusBarMessage(QString)));
connect(_page, SIGNAL(linkClicked(QUrl)),
this, SIGNAL(linkClicked(QUrl)));
connect(_page, SIGNAL(selectionChanged()),
this, SIGNAL(selectionChanged()));
connect(_page, SIGNAL(microFocusChanged()),
this, SLOT(updateMicroFocus()));
// connect(_page, SIGNAL(destroyed()),
// this, SLOT(_q_pageDestroyed()));
}
setAttribute(Qt::WA_OpaquePaintEvent, _page);
update();
}
void QUltralightView::load(const QUrl &url)
{
page()->mainFrame()->load(url);
}
void QUltralightView::load(const QNetworkRequest &request, QNetworkAccessManager::Operation operation, const QByteArray &body)
{
page()->mainFrame()->load(request, operation, body);
}
void QUltralightView::setHtml(const QString &html, const QUrl &baseUrl)
{
page()->mainFrame()->setHtml(html, baseUrl);
}
void QUltralightView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl)
{
page()->mainFrame()->setContent(data, mimeType, baseUrl);
}
QUltralightHistory *QUltralightView::history() const
{
return page()->history();
}
QUltralightSettings *QUltralightView::settings() const
{
return page()->settings();
}
QString QUltralightView::title() const
{
return page()->mainFrame()->title();
}
void QUltralightView::setUrl(const QUrl &url)
{
page()->mainFrame()->setUrl(url);
}
QUrl QUltralightView::url() const
{
return page()->mainFrame()->url();
}
QIcon QUltralightView::icon() const
{
return page()->mainFrame()->icon();
}
bool QUltralightView::hasSelection() const
{
return page()->hasSelection();
}
QString QUltralightView::selectedText() const
{
return page()->selectedText();
}
QString QUltralightView::selectedHtml() const
{
return page()->selectedHtml();
}
#ifndef QT_NO_ACTION
QAction *QUltralightView::pageAction(QUltralightPage::WebAction action) const
{
return page()->action(action);
}
#endif
void QUltralightView::triggerPageAction(QUltralightPage::WebAction action, bool checked)
{
page()->triggerAction(action, checked);
}
bool QUltralightView::isModified() const
{
return page()->isModified();
}
QSize QUltralightView::sizeHint() const
{
return QSize(800, 600);
}
void QUltralightView::setZoomFactor(qreal factor)
{
page()->mainFrame()->setZoomFactor(factor);
}
qreal QUltralightView::zoomFactor() const
{
return page()->mainFrame()->zoomFactor();
}
void QUltralightView::setTextSizeMultiplier(qreal factor)
{
page()->mainFrame()->setTextSizeMultiplier(factor);
}
qreal QUltralightView::textSizeMultiplier() const
{
return page()->mainFrame()->textSizeMultiplier();
}
QPainter::RenderHints QUltralightView::renderHints() const
{
return QPainter::RenderHints();
}
void QUltralightView::setRenderHints(QPainter::RenderHints hints)
{
// if (hints == d->renderHints)
// return;
// d->renderHints = hints;
// update();
}
void QUltralightView::setRenderHint(QPainter::RenderHint hint, bool enabled)
{
// QPainter::RenderHints oldHints = d->renderHints;
// if (enabled)
// d->renderHints |= hint;
// else
// d->renderHints &= ~hint;
// if (oldHints != d->renderHints)
// update();
}
bool QUltralightView::findText(const QString &subString, QUltralightPage::FindFlags options)
{
return page()->findText(subString, options);
}
bool QUltralightView::event(QEvent *e)
{
#ifndef QT_NO_CONTEXTMENU
if (e->type() == QEvent::ContextMenu) {
if (!isEnabled())
return false;
QContextMenuEvent *event = static_cast<QContextMenuEvent *>(e);
if (page()->swallowContextMenuEvent(event)) {
e->accept();
return true;
}
page()->updatePositionDependentActions(event->pos());
} else
#endif // QT_NO_CONTEXTMENU
if (e->type() == QEvent::ShortcutOverride
|| e->type() == QEvent::Show
|| e->type() == QEvent::Hide) {
page()->event(e);
#ifndef QT_NO_CURSOR
} else if (e->type() == QEvent::CursorChange) {
// An unsetCursor will set the cursor to Qt::ArrowCursor.
// Thus this cursor change might be a QWidget::unsetCursor()
// If this is not the case and it came from WebCore, the
// QUltralightPageClient already has set its cursor internally
// to Qt::ArrowCursor, so updating the cursor is always
// right, as it falls back to the last cursor set by
// WebCore.
// FIXME: Add a QEvent::CursorUnset or similar to Qt.
//if (cursor().shape() == Qt::ArrowCursor)
// page()->resetCursor();
#endif
} else if (e->type() == QEvent::TouchBegin
|| e->type() == QEvent::TouchEnd
|| e->type() == QEvent::TouchUpdate
|| e->type() == QEvent::TouchCancel) {
if (page()->event(e))
return true;
} else if (e->type() == QEvent::Leave)
page()->event(e);
return QWidget::event(e);
}
void QUltralightView::print(QPrinter *printer) const
{
#if !defined(QT_NO_PRINTER)
page()->mainFrame()->print(printer);
#endif
}
void QUltralightView::stop()
{
_progressTimer->stop();
page()->triggerAction(QUltralightPage::Stop);
}
void QUltralightView::back()
{
_progressTimer->stop();
page()->triggerAction(QUltralightPage::Back);
}
void QUltralightView::forward()
{
_progressTimer->stop();
page()->triggerAction(QUltralightPage::Forward);
}
void QUltralightView::reload()
{
_progressTimer->stop();
page()->triggerAction(QUltralightPage::Reload);
}
void QUltralightView::resizeEvent(QResizeEvent *e)
{
page()->setViewportSize(e->size());
}
void QUltralightView::paintEvent(QPaintEvent *ev)
{
#ifdef QWEBKIT_TIME_RENDERING
QTime time;
time.start();
#endif
QUltralightFrame *frame = page()->mainFrame();
QPainter p(this);
// p.setRenderHints(d->renderHints);
frame->render(&p, ev->region());
#ifdef QWEBKIT_TIME_RENDERING
int elapsed = time.elapsed();
qDebug() << "paint event on " << ev->region() << ", took to render = " << elapsed;
#endif
}
QUltralightView *QUltralightView::createWindow(QUltralightPage::WebWindowType type)
{
Q_UNUSED(type)
return 0;
}
void QUltralightView::mouseMoveEvent(QMouseEvent* ev)
{
const bool accepted = ev->isAccepted();
page()->event(ev);
ev->setAccepted(accepted);
}
void QUltralightView::mousePressEvent(QMouseEvent* ev)
{
const bool accepted = ev->isAccepted();
page()->event(ev);
ev->setAccepted(accepted);
}
void QUltralightView::mouseDoubleClickEvent(QMouseEvent* ev)
{
const bool accepted = ev->isAccepted();
page()->event(ev);
ev->setAccepted(accepted);
}
void QUltralightView::mouseReleaseEvent(QMouseEvent* ev)
{
const bool accepted = ev->isAccepted();
page()->event(ev);
ev->setAccepted(accepted);
}
#ifndef QT_NO_CONTEXTMENU
void QUltralightView::contextMenuEvent(QContextMenuEvent* ev)
{
const bool accepted = ev->isAccepted();
page()->event(ev);
ev->setAccepted(accepted);
}
#endif // QT_NO_CONTEXTMENU
#ifndef QT_NO_WHEELEVENT
void QUltralightView::wheelEvent(QWheelEvent* ev)
{
const bool accepted = ev->isAccepted();
page()->event(ev);
ev->setAccepted(accepted);
}
#endif // QT_NO_WHEELEVENT
void QUltralightView::keyPressEvent(QKeyEvent* ev)
{
// page()->event(ev);
sendKey(ev);
if (!ev->isAccepted())
QWidget::keyPressEvent(ev);
}
void QUltralightView::keyReleaseEvent(QKeyEvent* ev)
{
page()->event(ev);
if (!ev->isAccepted())
QWidget::keyReleaseEvent(ev);
}
void QUltralightView::focusInEvent(QFocusEvent* ev)
{
page()->event(ev);
}
void QUltralightView::focusOutEvent(QFocusEvent* ev)
{
page()->event(ev);
}
void QUltralightView::dragEnterEvent(QDragEnterEvent* ev)
{
//#if ENABLE(DRAG_SUPPORT)
page()->event(ev);
//#endif
}
void QUltralightView::dragLeaveEvent(QDragLeaveEvent* ev)
{
//#if ENABLE(DRAG_SUPPORT)
page()->event(ev);
//#endif
}
void QUltralightView::dragMoveEvent(QDragMoveEvent* ev)
{
//#if ENABLE(DRAG_SUPPORT)
page()->event(ev);
//#endif
}
void QUltralightView::dropEvent(QDropEvent* ev)
{
//#if ENABLE(DRAG_SUPPORT)
page()->event(ev);
//#endif
}
bool QUltralightView::focusNextPrevChild(bool next)
{
if (page()->focusNextPrevChild(next))
return true;
return QWidget::focusNextPrevChild(next);
}
QVariant QUltralightView::inputMethodQuery(Qt::InputMethodQuery property) const
{
return page()->inputMethodQuery(property);
}
void QUltralightView::inputMethodEvent(QInputMethodEvent *e)
{
page()->event(e);
}
void QUltralightView::changeEvent(QEvent *e)
{
if (e->type() == QEvent::PaletteChange)
page()->setPalette(palette());
QWidget::changeEvent(e);
}
int QUltralightView::QtModsToUlMods(int mods)
{
int result = 0;
if (mods & Qt::AltModifier)
result |= ultralight::KeyEvent::kMod_AltKey;
if (mods & Qt::ControlModifier)
result |= ultralight::KeyEvent::kMod_CtrlKey;
if (mods & Qt::MetaModifier)
result |= ultralight::KeyEvent::kMod_MetaKey;
if (mods & Qt::ShiftModifier)
result |= ultralight::KeyEvent::kMod_ShiftKey;
return result;
}
int QUltralightView::QtKeyCodeToUlKeyCode(int key)
{
using namespace ultralight::KeyCodes;
switch (key) {
case Qt::Key_Space: return GK_SPACE;
case Qt::Key_Apostrophe: return GK_OEM_7;
case Qt::Key_Comma: return GK_OEM_COMMA;
case Qt::Key_Minus: return GK_OEM_MINUS;
case Qt::Key_Period: return GK_OEM_PERIOD;
case Qt::Key_Slash: return GK_OEM_2;
case Qt::Key_0: return GK_0;
case Qt::Key_1: return GK_1;
case Qt::Key_2: return GK_2;
case Qt::Key_3: return GK_3;
case Qt::Key_4: return GK_4;
case Qt::Key_5: return GK_5;
case Qt::Key_6: return GK_6;
case Qt::Key_7: return GK_7;
case Qt::Key_8: return GK_8;
case Qt::Key_9: return GK_9;
case Qt::Key_Semicolon: return GK_OEM_1;
case Qt::Key_Equal: return GK_OEM_PLUS;
case Qt::Key_A: return GK_A;
case Qt::Key_B: return GK_B;
case Qt::Key_C: return GK_C;
case Qt::Key_D: return GK_D;
case Qt::Key_E: return GK_E;
case Qt::Key_F: return GK_F;
case Qt::Key_G: return GK_G;
case Qt::Key_H: return GK_H;
case Qt::Key_I: return GK_I;
case Qt::Key_J: return GK_J;
case Qt::Key_K: return GK_K;
case Qt::Key_L: return GK_L;
case Qt::Key_M: return GK_M;
case Qt::Key_N: return GK_N;
case Qt::Key_O: return GK_O;
case Qt::Key_P: return GK_P;
case Qt::Key_Q: return GK_Q;
case Qt::Key_R: return GK_R;
case Qt::Key_S: return GK_S;
case Qt::Key_T: return GK_T;
case Qt::Key_U: return GK_U;
case Qt::Key_V: return GK_V;
case Qt::Key_W: return GK_W;
case Qt::Key_X: return GK_X;
case Qt::Key_Y: return GK_Y;
case Qt::Key_Z: return GK_Z;
case Qt::Key_BracketLeft: return GK_OEM_4;
case Qt::Key_Backslash: return GK_OEM_5;
case Qt::Key_BracketRight: return GK_OEM_6;
case Qt::Key_QuoteLeft: return GK_OEM_3;
case Qt::Key_Escape: return GK_ESCAPE;
case Qt::Key_Enter: return GK_RETURN;
case Qt::Key_Tab: return GK_TAB;
case Qt::Key_Backspace: return GK_BACK;
case Qt::Key_Insert: return GK_INSERT;
case Qt::Key_Delete: return GK_DELETE;
case Qt::Key_Right: return GK_RIGHT;
case Qt::Key_Left: return GK_LEFT;
case Qt::Key_Down: return GK_DOWN;
case Qt::Key_Up: return GK_UP;
case Qt::Key_PageUp: return GK_PRIOR;
case Qt::Key_PageDown: return GK_NEXT;
case Qt::Key_Home: return GK_HOME;
case Qt::Key_End: return GK_END;
case Qt::Key_CapsLock: return GK_CAPITAL;
case Qt::Key_ScrollLock: return GK_SCROLL;
case Qt::Key_NumLock: return GK_NUMLOCK;
case Qt::Key_SysReq: return GK_SNAPSHOT;
case Qt::Key_Pause: return GK_PAUSE;
case Qt::Key_F1: return GK_F1;
case Qt::Key_F2: return GK_F2;
case Qt::Key_F3: return GK_F3;
case Qt::Key_F4: return GK_F4;
case Qt::Key_F5: return GK_F5;
case Qt::Key_F6: return GK_F6;
case Qt::Key_F7: return GK_F7;
case Qt::Key_F8: return GK_F8;
case Qt::Key_F9: return GK_F9;
case Qt::Key_F10: return GK_F10;
case Qt::Key_F11: return GK_F11;
case Qt::Key_F12: return GK_F12;
case Qt::Key_F13: return GK_F13;
case Qt::Key_F14: return GK_F14;
case Qt::Key_F15: return GK_F15;
case Qt::Key_F16: return GK_F16;
case Qt::Key_F17: return GK_F17;
case Qt::Key_F18: return GK_F18;
case Qt::Key_F19: return GK_F19;
case Qt::Key_F20: return GK_F20;
case Qt::Key_F21: return GK_F21;
case Qt::Key_F22: return GK_F22;
case Qt::Key_F23: return GK_F23;
case Qt::Key_F24: return GK_F24;
case Qt::Key_Shift: return GK_SHIFT;
case Qt::Key_Control: return GK_CONTROL;
case Qt::Key_Alt: return GK_MENU;
case Qt::Key_Super_L: return GK_LWIN;
case Qt::Key_AltGr: return GK_MENU;
case Qt::Key_Super_R: return GK_RWIN;
default: return GK_UNKNOWN;
}
}
QString QUltralightView::ulStringToQString(const ultralight::String string)
{
return QString::fromUtf8(string.utf8().data());
}
QUrl QUltralightView::ulStringToQUrl(const ultralight::String string)
{
return QUrl(ulStringToQString(string));
}
ultralight::String QUltralightView::QStringToUlString(const QString string)
{
return (ultralight::String8) string.toUtf8().constData();
}
ultralight::String QUltralightView::QUrlToUlString(const QUrl url)
{
return QStringToUlString(url.toString());
}
void QUltralightView::OnResize(ultralight::Window *window, uint32_t width_px, uint32_t height_px)
{
_overlay->Resize(width_px, height_px);
}
void QUltralightView::OnClose(ultralight::Window *window)
{
BrowserApplication::instance()->app->Quit();
}
void QUltralightView::OnChangeCursor(ultralight::View* caller, ultralight::Cursor cursor) {
_window->SetCursor(cursor);
}
void QUltralightView::OnChangeTitle(ultralight::View *caller, const ultralight::String &title)
{
emit page()->mainFrame()->titleChanged(ulStringToQString(title));
}
void QUltralightView::OnChangeURL(ultralight::View *caller, const ultralight::String &url)
{
emit page()->mainFrame()->urlChanged(ulStringToQUrl(url));
}
void QUltralightView::OnChangeTooltip(ultralight::View *caller, const ultralight::String &tooltip)
{
emit page()->statusBarMessage(ulStringToQString(tooltip));
}
void QUltralightView::OnAddConsoleMessage(ultralight::View *caller, ultralight::MessageSource source, ultralight::MessageLevel level, const ultralight::String &message, uint32_t line_number, uint32_t column_number, const ultralight::String &source_id)
{
if (level == ultralight::MessageLevel::kMessageLevel_Log || level == ultralight::MessageLevel::kMessageLevel_Info)
qInfo() << ulStringToQString(message);
else if (level == ultralight::MessageLevel::kMessageLevel_Debug)
qDebug() << ulStringToQString(message);
else if (level == ultralight::MessageLevel::kMessageLevel_Warning)
qWarning() << ulStringToQString(message);
else if (level == ultralight::MessageLevel::kMessageLevel_Error)
qCritical() << ulStringToQString(message);
}
ultralight::RefPtr<ultralight::View> QUltralightView::OnCreateChildView(ultralight::View *caller, const ultralight::String &opener_url, const ultralight::String &target_url, bool is_popup, const ultralight::IntRect &popup_rect)
{
WebView *webView = BrowserApplication::instance()->mainWindow()->tabWidget()->newTab(true);
webView->load(ulStringToQUrl(target_url));
return webView->_overlay->view();
}
void QUltralightView::OnBeginLoading(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const ultralight::String &url)
{
if (is_main_frame) {
_progress = 0;
_progressTimer = new QTimer(this);
connect(_progressTimer, &QTimer::timeout, this, [=]() {
if (_progress < 100) emit page()->loadProgress(log10(++_progress) * 50);
});
_progressTimer->start(100);
emit page()->mainFrame()->loadStarted();
}
}
void QUltralightView::OnFinishLoading(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const ultralight::String &url)
{
if (is_main_frame) {
_progressTimer->stop();
emit page()->loadProgress(100);
emit page()->mainFrame()->loadFinished(true);
}
}
void QUltralightView::OnFailLoading(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const ultralight::String &url, const ultralight::String &description, const ultralight::String &error_domain, int error_code)
{
qCritical() << "ERROR" << error_code << "(" << ulStringToQString(error_domain) << ")" << ulStringToQString(description) << "while loading" << ulStringToQUrl(url).toString();
if (is_main_frame) {
_progressTimer->stop();
emit page()->loadProgress(100);
emit page()->mainFrame()->loadFinished(false);
}
}
void QUltralightView::OnWindowObjectReady(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const ultralight::String &url)
{
}
void QUltralightView::OnDOMReady(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const ultralight::String &url)
{
}
void QUltralightView::OnUpdateHistory(ultralight::View *caller)
{
}
void QUltralightView::sendKey(QKeyEvent *event)
{
ultralight::KeyEvent evt;
evt.type = ultralight::KeyEvent::kType_RawKeyDown;
evt.virtual_key_code = QtKeyCodeToUlKeyCode(event->key());
evt.native_key_code = event->nativeScanCode();
GetKeyIdentifierFromVirtualKeyCode(event->nativeVirtualKey(), evt.key_identifier);
evt.modifiers = QtModsToUlMods(event->modifiers());
_overlay->view()->FireKeyEvent(evt);
// Support typing chars
evt.type = ultralight::KeyEvent::kType_Char;
evt.text = (ultralight::String8) event->text().toUtf8().constData();
evt.unmodified_text = evt.text;
_overlay->view()->FireKeyEvent(evt);
}