-
Notifications
You must be signed in to change notification settings - Fork 11
/
qultralightpage.cpp
1323 lines (1198 loc) · 42.5 KB
/
qultralightpage.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
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
Copyright (C) 2008 Holger Hans Peter Freyther
Copyright (C) 2009 Girish Ramakrishnan <[email protected]>
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 "qultralightpage.h"
#include "qultralightview.h"
#include <QAction>
#include <QApplication>
#include <QBitArray>
#include <QClipboard>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QInputDialog>
#include <QKeyEvent>
#include <QLabel>
#include <QMessageBox>
#include <QStyle>
#include <QUndoCommand>
using namespace WebCore;
static QUltralightPage::WebAction webActionForAdapterMenuAction(QUltralightPage::MenuAction action)
{
switch (action) {
case QUltralightPage::MenuAction::OpenLink: return QUltralightPage::OpenLink;
case QUltralightPage::MenuAction::OpenLinkInNewWindow: return QUltralightPage::OpenLinkInNewWindow;
case QUltralightPage::MenuAction::OpenFrameInNewWindow: return QUltralightPage::OpenFrameInNewWindow;
case QUltralightPage::MenuAction::DownloadLinkToDisk: return QUltralightPage::DownloadLinkToDisk;
case QUltralightPage::MenuAction::CopyLinkToClipboard: return QUltralightPage::CopyLinkToClipboard;
case QUltralightPage::MenuAction::OpenImageInNewWindow: return QUltralightPage::OpenImageInNewWindow;
case QUltralightPage::MenuAction::DownloadImageToDisk: return QUltralightPage::DownloadImageToDisk;
case QUltralightPage::MenuAction::CopyImageToClipboard: return QUltralightPage::CopyImageToClipboard;
case QUltralightPage::MenuAction::Back: return QUltralightPage::Back;
case QUltralightPage::MenuAction::Forward: return QUltralightPage::Forward;
case QUltralightPage::MenuAction::Stop: return QUltralightPage::Stop;
case QUltralightPage::MenuAction::Reload: return QUltralightPage::Reload;
case QUltralightPage::MenuAction::Cut: return QUltralightPage::Cut;
case QUltralightPage::MenuAction::Copy: return QUltralightPage::Copy;
case QUltralightPage::MenuAction::Paste: return QUltralightPage::Paste;
case QUltralightPage::MenuAction::Undo: return QUltralightPage::Undo;
case QUltralightPage::MenuAction::Redo: return QUltralightPage::Redo;
case QUltralightPage::MenuAction::SetTextDirectionDefault: return QUltralightPage::SetTextDirectionDefault;
case QUltralightPage::MenuAction::SetTextDirectionLeftToRight: return QUltralightPage::SetTextDirectionLeftToRight;
case QUltralightPage::MenuAction::SetTextDirectionRightToLeft: return QUltralightPage::SetTextDirectionRightToLeft;
case QUltralightPage::MenuAction::ToggleBold: return QUltralightPage::ToggleBold;
case QUltralightPage::MenuAction::ToggleItalic: return QUltralightPage::ToggleItalic;
case QUltralightPage::MenuAction::ToggleUnderline: return QUltralightPage::ToggleUnderline;
case QUltralightPage::MenuAction::InspectElement: return QUltralightPage::InspectElement;
case QUltralightPage::MenuAction::SelectAll: return QUltralightPage::SelectAll;
case QUltralightPage::MenuAction::CopyImageUrlToClipboard: return QUltralightPage::CopyImageUrlToClipboard;
case QUltralightPage::MenuAction::OpenLinkInThisWindow: return QUltralightPage::OpenLinkInThisWindow;
case QUltralightPage::MenuAction::DownloadMediaToDisk: return QUltralightPage::DownloadMediaToDisk;
case QUltralightPage::MenuAction::CopyMediaUrlToClipboard: return QUltralightPage::CopyMediaUrlToClipboard;
case QUltralightPage::MenuAction::ToggleMediaControls: return QUltralightPage::ToggleMediaControls;
case QUltralightPage::MenuAction::ToggleMediaLoop: return QUltralightPage::ToggleMediaLoop;
case QUltralightPage::MenuAction::ToggleMediaPlayPause: return QUltralightPage::ToggleMediaPlayPause;
case QUltralightPage::MenuAction::ToggleMediaMute: return QUltralightPage::ToggleMediaMute;
case QUltralightPage::MenuAction::ToggleVideoFullscreen: return QUltralightPage::ToggleVideoFullscreen;
case QUltralightPage::MenuAction::ActionCount: return QUltralightPage::WebActionCount;
default:
Q_UNREACHABLE();
break;
}
return QUltralightPage::NoWebAction;
}
QUltralightPage::QUltralightPage(QObject *parent) : QObject(parent)
{
setView(qobject_cast<QWidget*>(parent));
_history = new QUltralightHistory(this);
createMainFrame();
connect(mainFrame(), SIGNAL(loadStarted()), this, SIGNAL(loadStarted()));
connect(mainFrame(), SIGNAL(loadFinished(bool)), this, SIGNAL(loadFinished(bool)));
}
QUltralightPage::~QUltralightPage()
{
}
void QUltralightPage::createMainFrame()
{
_mainFrame = new QUltralightFrame(this);
emit frameCreated(_mainFrame);
}
QUltralightFrame *QUltralightPage::mainFrame() const
{
if (!_mainFrame) {
QUltralightPage *that = const_cast<QUltralightPage *>(this);
that->createMainFrame();
}
return _mainFrame;
}
QUltralightFrame *QUltralightPage::currentFrame() const
{
if (!_mainFrame) {
QUltralightPage *that = const_cast<QUltralightPage *>(this);
that->createMainFrame();
}
return qobject_cast<QUltralightFrame*>(_mainFrame);
}
QUltralightFrame* QUltralightPage::frameAt(const QPoint& pos) const
{
QUltralightFrame* webFrame = mainFrame();
if (!webFrame->geometry().contains(pos))
return 0;
QUltralightHitTestResult hitTestResult = webFrame->hitTestContent(pos);
return hitTestResult.frame();
}
QUltralightHistory *QUltralightPage::history() const
{
if (!_mainFrame) {
QUltralightPage *that = const_cast<QUltralightPage *>(this);
that->createMainFrame();
}
return _history;
}
void QUltralightPage::setView(QWidget* view)
{
if (this->view() == view)
return;
_view = view;
setViewportSize(view ? view->size() : QSize(0, 0));
// If we have no client, we install a special client delegating
// the responsibility to the QWidget. This is the code path
// handling a.o. the "legacy" QUltralightView.
//
// If such a special delegate already exist, we substitute the view.
// if (d->client) {
// if (d->client->isQWidgetClient())
// static_cast<PageClientQWidget*>(d->client.data())->view = view;
// return;
// }
// if (view)
// d->client.reset(new PageClientQWidget(view, this));
}
QWidget *QUltralightPage::view() const
{
return _view;
}
void QUltralightPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID)
{
Q_UNUSED(sourceID);
// Catch plugin logDestroy message for LayoutTests/plugins/open-and-close-window-with-plugin.html
// At this point DRT's WebPage has already been destroyed
// if (QUltralightPageAdapter::drtRun) {
// if (message == QLatin1String("PLUGIN: NPP_Destroy")) {
// fprintf(stdout, "CONSOLE MESSAGE: ");
// if (lineNumber)
// fprintf(stdout, "line %d: ", lineNumber);
// fprintf(stdout, "%s\n", message.toUtf8().constData());
// }
// }
}
void QUltralightPage::javaScriptAlert(QUltralightFrame *frame, const QString& msg)
{
Q_UNUSED(frame);
#ifndef QT_NO_MESSAGEBOX
QMessageBox box(view());
box.setWindowTitle(tr("JavaScript Alert - %1").arg(mainFrame()->url().host()));
box.setTextFormat(Qt::PlainText);
box.setText(msg);
box.setStandardButtons(QMessageBox::Ok);
box.exec();
#endif
}
bool QUltralightPage::javaScriptConfirm(QUltralightFrame *frame, const QString& msg)
{
Q_UNUSED(frame);
#ifdef QT_NO_MESSAGEBOX
return true;
#else
QMessageBox box(view());
box.setWindowTitle(tr("JavaScript Confirm - %1").arg(mainFrame()->url().host()));
box.setTextFormat(Qt::PlainText);
box.setText(msg);
box.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
return QMessageBox::Ok == box.exec();
#endif
}
bool QUltralightPage::javaScriptPrompt(QUltralightFrame *frame, const QString& msg, const QString& defaultValue, QString* result)
{
Q_UNUSED(frame);
bool ok = false;
#ifndef QT_NO_INPUTDIALOG
QInputDialog dlg(view());
dlg.setWindowTitle(tr("JavaScript Prompt - %1").arg(mainFrame()->url().host()));
// Hack to force the dialog's QLabel into plain text mode
// prevents https://bugs.webkit.org/show_bug.cgi?id=34429
QLabel* label = dlg.findChild<QLabel*>();
if (label)
label->setTextFormat(Qt::PlainText);
// double the &'s because single & will underline the following character
// (Accelerator mnemonics)
QString escMsg(msg);
escMsg.replace(QChar::fromLatin1('&'), QLatin1String("&&"));
dlg.setLabelText(escMsg);
dlg.setTextEchoMode(QLineEdit::Normal);
dlg.setTextValue(defaultValue);
ok = !!dlg.exec();
if (ok && result)
*result = dlg.textValue();
#endif
return ok;
}
bool QUltralightPage::shouldInterruptJavaScript()
{
#ifdef QT_NO_MESSAGEBOX
return false;
#else
return QMessageBox::Yes == QMessageBox::information(view(), tr("JavaScript Problem - %1").arg(mainFrame()->url().host()), tr("The script on this page appears to have a problem. Do you want to stop the script?"), QMessageBox::Yes, QMessageBox::No);
#endif
}
void QUltralightPage::setFeaturePermission(QUltralightFrame* frame, Feature feature, PermissionPolicy policy)
{
//#if !ENABLE(NOTIFICATIONS) && !ENABLE(GEOLOCATION)
// Q_UNUSED(frame);
// Q_UNUSED(policy);
//#endif
// switch (feature) {
// case Notifications:
//#if ENABLE(NOTIFICATIONS)
// if (policy != PermissionUnknown)
// d->setNotificationsAllowedForFrame(frame->d, (policy == PermissionGrantedByUser));
//#endif
// break;
// case Geolocation:
//#if ENABLE(GEOLOCATION) && HAVE(QTPOSITIONING)
// if (policy != PermissionUnknown)
// d->setGeolocationEnabledForFrame(frame->d, (policy == PermissionGrantedByUser));
//#endif
// break;
// default:
// break;
// }
}
QUltralightPage *QUltralightPage::createWindow(WebWindowType type)
{
QUltralightView *webView = qobject_cast<QUltralightView*>(view());
if (webView) {
QUltralightView *newView = webView->createWindow(type);
if (newView)
return newView->page();
}
return 0;
}
QObject *QUltralightPage::createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues)
{
Q_UNUSED(classid);
Q_UNUSED(url);
Q_UNUSED(paramNames);
Q_UNUSED(paramValues);
return 0;
}
QStringList QUltralightPage::supportedContentTypes() const
{
// return d->supportedContentTypes();
return QStringList();
}
bool QUltralightPage::supportsContentType(const QString& mimeType) const
{
// return d->supportsContentType(mimeType);
return true;
}
static void collectChildFrames(QUltralightFrame* frame, QList<QUltralightFrame*>& list)
{
list << frame->childFrames();
QListIterator<QUltralightFrame*> it(frame->childFrames());
while (it.hasNext())
collectChildFrames(it.next(), list);
}
void QUltralightPage::triggerAction(WebAction action, bool)
{
ultralight::Ref<ultralight::View> ulView = qobject_cast<QUltralightView*>(view())->_overlay->view();
switch (action) {
case OpenLink:
case OpenLinkInNewWindow:
case OpenLinkInThisWindow:
case OpenFrameInNewWindow:
case CopyLinkToClipboard:
case OpenImageInNewWindow:
case DownloadImageToDisk:
case DownloadLinkToDisk:
case Back:
history()->back();
break;
case Forward:
history()->forward();
break;
case Stop:
case StopScheduledPageRefresh:
ulView->Stop();
break;
case Reload:
case ReloadAndBypassCache:
ulView->Reload();
break;
case SetTextDirectionDefault:
case SetTextDirectionLeftToRight:
case SetTextDirectionRightToLeft:
case DownloadMediaToDisk:
case ToggleMediaControls:
case ToggleMediaLoop:
case ToggleMediaPlayPause:
case ToggleMediaMute:
case ToggleVideoFullscreen:
break;
#ifndef QT_NO_CLIPBOARD
case CopyImageToClipboard:
QApplication::clipboard()->setPixmap(_hitTestResult->pixmap());
break;
case CopyImageUrlToClipboard:
QApplication::clipboard()->setText(_hitTestResult->imageUrl().toString());
break;
case CopyMediaUrlToClipboard:
QApplication::clipboard()->setText(_hitTestResult->mediaUrl().toString());
break;
#endif
case InspectElement:
if (!_hitTestResult->isNull()) {
//Ultralight
qobject_cast<QUltralightView*>(view())->_overlay->view()->inspector()->Resize(qobject_cast<QUltralightView*>(view())->_overlay->width(), 400);
}
break;
case RequestClose:
// bool success = d->tryClosePage();
// if (success)
emit windowCloseRequested();
break;
default:
// command = QUltralightPage::editorCommandForWebActions(action);
break;
}
// if (command || mappedAction != MenuAction::NoAction)
// d->triggerAction(mappedAction, hitTestResult, command, /*endToEndReload*/ action == ReloadAndBypassCache);
}
QSize QUltralightPage::viewportSize() const
{
return QSize(qobject_cast<QUltralightView*>(view())->_overlay->width(), qobject_cast<QUltralightView*>(view())->_overlay->height());
}
void QUltralightPage::setViewportSize(const QSize &size) const
{
//qobject_cast<QUltralightView*>(view())->_overlay->Resize(size.width(), size.height());
}
void QUltralightPage::setDevicePixelRatio(qreal ratio)
{
// d->setDevicePixelRatio(ratio);
// d->m_customDevicePixelRatioIsSet = true;
}
qreal QUltralightPage::devicePixelRatio() const
{
// return d->devicePixelRatio();
return 1;
}
void QUltralightPage::resetDevicePixelRatio()
{
// d->m_customDevicePixelRatioIsSet = false;
// d->updateWindow();
}
static int getintenv(const char* variable)
{
bool ok;
int value = qgetenv(variable).toInt(&ok);
return (ok) ? value : -1;
}
static QSize queryDeviceSizeForScreenContainingWidget(const QWidget* widget)
{
QDesktopWidget* desktop = QApplication::desktop();
if (!desktop)
return QSize();
QSize size;
if (widget) {
// Returns the available geometry of the screen which contains widget.
// NOTE: this must be the the full screen size including any fixed status areas etc.
size = desktop->availableGeometry(widget).size();
} else
size = desktop->availableGeometry().size();
// This must be in portrait mode, adjust if not.
if (size.width() > size.height()) {
int width = size.width();
size.setWidth(size.height());
size.setHeight(width);
}
return size;
}
//QUltralightPage::ViewportAttributes QUltralightPage::viewportAttributesForSize(const QSize& availableSize) const
//{
// ViewportAttributes result;
// if (availableSize.isEmpty())
// return result; // Returns an invalid instance.
// QSize deviceSize(getintenv("QTWEBKIT_DEVICE_WIDTH"), getintenv("QTWEBKIT_DEVICE_HEIGHT"));
// // Both environment variables need to be set - or they will be ignored.
// if (deviceSize.isNull())
// deviceSize = queryDeviceSizeForScreenContainingWidget(view());
// ViewportAttributes attr = d->viewportAttributesForSize(availableSize, deviceSize);
// result.m_isValid = true;
// result.m_size = attr.size;
// result.m_initialScaleFactor = attr.initialScaleFactor;
// result.m_minimumScaleFactor = attr.minimumScaleFactor;
// result.m_maximumScaleFactor = attr.maximumScaleFactor;
// result.m_devicePixelRatio = attr.devicePixelRatio;
// result.m_isUserScalable = attr.isUserScalable;
// return result;
//}
QSize QUltralightPage::preferredContentsSize() const
{
// QUltralightFrameAdapter* mainFrame = d->mainFrame ? d->mainFrame->d : 0;
// QSize customSize;
// if (mainFrame && mainFrame->hasView())
// customSize = mainFrame->customLayoutSize();
// return customSize.isNull() ? d->fixedLayoutSize : customSize;
return mainFrame()->contentsSize();
}
void QUltralightPage::setPreferredContentsSize(const QSize& size) const
{
// FIXME: Rename this method to setCustomLayoutSize
// d->fixedLayoutSize = size;
// QUltralightFrameAdapter& mainFrame = d->mainFrameAdapter();
// if (!mainFrame.hasView())
// return;
// mainFrame.setCustomLayoutSize(size);
}
void QUltralightPage::setActualVisibleContentRect(const QRect& rect) const
{
// QUltralightFrameAdapter& mainFrame = d->mainFrameAdapter();
// if (!mainFrame.hasView())
// return;
// mainFrame.setFixedVisibleContentRect(rect);
}
bool QUltralightPage::acceptNavigationRequest(QUltralightFrame *frame, const QNetworkRequest &request, QUltralightPage::NavigationType type)
{
// Q_UNUSED(frame);
// if (type == NavigationTypeLinkClicked) {
// switch (d->linkPolicy) {
// case DontDelegateLinks:
// return true;
// case DelegateExternalLinks:
// if (request.url().scheme().isEmpty() && QUltralightPageAdapter::treatSchemeAsLocal(frame->baseUrl().scheme()))
// return true;
// if (QUltralightPageAdapter::treatSchemeAsLocal(request.url().scheme()))
// return true;
// emit linkClicked(request.url());
// return false;
// case DelegateAllLinks:
// emit linkClicked(request.url());
// return false;
// }
// }
return true;
}
bool QUltralightPage::hasSelection() const
{
// d->createMainFrame();
// return d->hasSelection();
return false;
}
QString QUltralightPage::selectedText() const
{
// d->createMainFrame();
// return d->selectedText();
return QString();
}
QString QUltralightPage::selectedHtml() const
{
// d->createMainFrame();
// return d->selectedHtml();
return QString();
}
#ifndef QT_NO_ACTION
QAction *QUltralightPage::action(WebAction action) const
{
if (action == NoWebAction)
return 0;
// if (d->actions[action])
// return d->actions[action];
QString text;
QIcon icon;
QStyle *style = qApp->style();
bool checkable = false;
MenuAction mappedAction = MenuAction::NoAction;
switch (action) {
// to be fetched from LocalizedStringsQt via the page adapter
case OpenLink:
text = tr("Open link");
mappedAction = MenuAction::OpenLink;
break;
case OpenLinkInNewWindow:
text = tr("Open link in new window");
mappedAction = MenuAction::OpenLinkInNewWindow;
break;
case OpenFrameInNewWindow:
text = tr("Open frame in new window");
mappedAction = MenuAction::OpenFrameInNewWindow;
break;
case OpenLinkInThisWindow:
text = tr("Open link in this window");
mappedAction = MenuAction::OpenLinkInThisWindow;
break;
case DownloadLinkToDisk:
text = tr("Download link to disk");
mappedAction = MenuAction::DownloadLinkToDisk;
break;
case CopyLinkToClipboard:
text = tr("Copy link to clipboard");
mappedAction = MenuAction::CopyLinkToClipboard;
break;
case OpenImageInNewWindow:
text = tr("Open image in new window");
mappedAction = MenuAction::OpenImageInNewWindow;
break;
case DownloadImageToDisk:
text = tr("Download image to disk");
mappedAction = MenuAction::DownloadImageToDisk;
break;
case CopyImageToClipboard:
text = tr("Copy image to clipboard");
mappedAction = MenuAction::CopyImageToClipboard;
break;
case CopyImageUrlToClipboard:
text = tr("Copy image URL to clipboard");
mappedAction = MenuAction::CopyImageUrlToClipboard;
break;
case Cut:
text = tr("Cut");
mappedAction = MenuAction::Cut;
break;
case Copy:
text = tr("Copy");
mappedAction = MenuAction::Copy;
break;
case Paste:
text = tr("Paste");
mappedAction = MenuAction::Paste;
break;
#ifdef QT_NO_UNDOSTACK
case Undo:
text = tr("Undo");
mappedAction = MenuAction::Undo;
break;
case Redo:
text = tr("Redo");
mappedAction = MenuAction::Redo;
break;
#endif // QT_NO_UNDOSTACK
case SelectAll:
text = tr("Select all");
mappedAction = MenuAction::SelectAll;
break;
case SetTextDirectionDefault:
text = tr("Set text direction Default");
mappedAction = MenuAction::SetTextDirectionDefault;
break;
case SetTextDirectionLeftToRight:
text = tr("Set text direction Left To Right");
mappedAction = MenuAction::SetTextDirectionLeftToRight;
break;
case SetTextDirectionRightToLeft:
text = tr("Set text direction Right To Left");
mappedAction = MenuAction::SetTextDirectionRightToLeft;
break;
case ToggleBold:
text = tr("Toggle bold");
mappedAction = MenuAction::ToggleBold;
break;
case ToggleItalic:
text = tr("Toggle italic");
mappedAction = MenuAction::ToggleItalic;
break;
case ToggleUnderline:
text = tr("Toggle underline");
mappedAction = MenuAction::ToggleUnderline;
break;
case DownloadMediaToDisk:
text = tr("Download media to disk");
mappedAction = MenuAction::DownloadMediaToDisk;
break;
case CopyMediaUrlToClipboard:
text = tr("Copy media URL to clipboard");
mappedAction = MenuAction::CopyMediaUrlToClipboard;
break;
case ToggleMediaControls:
text = tr("Toggle media controls");
mappedAction = MenuAction::ToggleMediaControls;
break;
case ToggleMediaLoop:
text = tr("Toggle media loop");
mappedAction = MenuAction::ToggleMediaLoop;
break;
case ToggleMediaPlayPause:
text = tr("Toggle media play/pause");
mappedAction = MenuAction::ToggleMediaPlayPause;
break;
case ToggleMediaMute:
text = tr("Toggle media mute");
mappedAction = MenuAction::ToggleMediaMute;
break;
case ToggleVideoFullscreen:
text = tr("Toggle video fullscreen");
mappedAction = MenuAction::ToggleVideoFullscreen;
break;
case InspectElement:
text = tr("Inspect element");
mappedAction = MenuAction::InspectElement;
break;
case Back:
text = tr("Back");
mappedAction = MenuAction::Back;
icon = style->standardIcon(QStyle::SP_ArrowBack);
break;
case Forward:
text = tr("Forward");
mappedAction = MenuAction::Forward;
icon = style->standardIcon(QStyle::SP_ArrowForward);
break;
case Stop:
text = tr("Stop");
mappedAction = MenuAction::Stop;
icon = style->standardIcon(QStyle::SP_BrowserStop);
break;
case Reload:
text = tr("Reload");
mappedAction = MenuAction::Reload;
icon = style->standardIcon(QStyle::SP_BrowserReload);
break;
#ifndef QT_NO_UNDOSTACK
case Undo: {
QAction *a = undoStack()->createUndoAction(const_cast<QUltralightPage *>(this));
// d->actions[action] = a;
return a;
}
case Redo: {
QAction *a = undoStack()->createRedoAction(const_cast<QUltralightPage *>(this));
// d->actions[action] = a;
return a;
}
#endif // QT_NO_UNDOSTACK
// in place l10n
case MoveToNextChar:
text = tr("Move the cursor to the next character");
break;
case MoveToPreviousChar:
text = tr("Move the cursor to the previous character");
break;
case MoveToNextWord:
text = tr("Move the cursor to the next word");
break;
case MoveToPreviousWord:
text = tr("Move the cursor to the previous word");
break;
case MoveToNextLine:
text = tr("Move the cursor to the next line");
break;
case MoveToPreviousLine:
text = tr("Move the cursor to the previous line");
break;
case MoveToStartOfLine:
text = tr("Move the cursor to the start of the line");
break;
case MoveToEndOfLine:
text = tr("Move the cursor to the end of the line");
break;
case MoveToStartOfBlock:
text = tr("Move the cursor to the start of the block");
break;
case MoveToEndOfBlock:
text = tr("Move the cursor to the end of the block");
break;
case MoveToStartOfDocument:
text = tr("Move the cursor to the start of the document");
break;
case MoveToEndOfDocument:
text = tr("Move the cursor to the end of the document");
break;
case SelectNextChar:
text = tr("Select to the next character");
break;
case SelectPreviousChar:
text = tr("Select to the previous character");
break;
case SelectNextWord:
text = tr("Select to the next word");
break;
case SelectPreviousWord:
text = tr("Select to the previous word");
break;
case SelectNextLine:
text = tr("Select to the next line");
break;
case SelectPreviousLine:
text = tr("Select to the previous line");
break;
case SelectStartOfLine:
text = tr("Select to the start of the line");
break;
case SelectEndOfLine:
text = tr("Select to the end of the line");
break;
case SelectStartOfBlock:
text = tr("Select to the start of the block");
break;
case SelectEndOfBlock:
text = tr("Select to the end of the block");
break;
case SelectStartOfDocument:
text = tr("Select to the start of the document");
break;
case SelectEndOfDocument:
text = tr("Select to the end of the document");
break;
case DeleteStartOfWord:
text = tr("Delete to the start of the word");
break;
case DeleteEndOfWord:
text = tr("Delete to the end of the word");
break;
case InsertParagraphSeparator:
text = tr("Insert a new paragraph");
break;
case InsertLineSeparator:
text = tr("Insert a new line");
break;
case PasteAndMatchStyle:
text = tr("Paste and Match Style");
break;
case RemoveFormat:
text = tr("Remove formatting");
break;
case ToggleStrikethrough:
text = tr("Strikethrough");
checkable = true;
break;
case ToggleSubscript:
text = tr("Subscript");
checkable = true;
break;
case ToggleSuperscript:
text = tr("Superscript");
checkable = true;
break;
case InsertUnorderedList:
text = tr("Insert Bulleted List");
checkable = true;
break;
case InsertOrderedList:
text = tr("Insert Numbered List");
checkable = true;
break;
case Indent:
text = tr("Indent");
break;
case Outdent:
text = tr("Outdent");
break;
case AlignCenter:
text = tr("Center");
break;
case AlignJustified:
text = tr("Justify");
break;
case AlignLeft:
text = tr("Align Left");
break;
case AlignRight:
text = tr("Align Right");
break;
case NoWebAction:
return 0;
default:
break;
}
if (text.isEmpty())
return 0;
QAction *a = new QAction();
a->setText(text);
a->setData(action);
a->setCheckable(checkable);
a->setIcon(icon);
connect(a, SIGNAL(triggered(bool)),
this, SLOT(webActionTriggered(bool)));
// d->actions[action] = a;
// d->updateAction(action);
return a;
}
void QUltralightPage::webActionTriggered(bool checked)
{
QAction *a = qobject_cast<QAction *>(sender());
if (!a)
return;
WebAction action = static_cast<WebAction>(a->data().toInt());
triggerAction(action, checked);
}
#endif // QT_NO_ACTION
bool QUltralightPage::isModified() const
{
#ifdef QT_NO_UNDOSTACK
return false;
#else
if (!_undoStack)
return false;
return _undoStack->canUndo();
#endif // QT_NO_UNDOSTACK
return false;
}
#ifndef QT_NO_UNDOSTACK
QUndoStack *QUltralightPage::undoStack() const
{
if (!_undoStack) {
QUltralightPage *that = const_cast<QUltralightPage *>(this);
that->_undoStack = new QUndoStack(that);
}
return _undoStack;
}
#endif // QT_NO_UNDOSTACK
bool QUltralightPage::event(QEvent *ev)
{
// switch (ev->type()) {
// case QEvent::Timer:
// d->timerEvent(static_cast<QTimerEvent*>(ev));
// break;
// case QEvent::MouseMove:
// d->mouseMoveEvent(static_cast<QMouseEvent*>(ev));
// break;
// case QEvent::MouseButtonPress:
// d->mousePressEvent(static_cast<QMouseEvent*>(ev));
// break;
// case QEvent::MouseButtonDblClick:
// d->mouseDoubleClickEvent(static_cast<QMouseEvent*>(ev));
// break;
// case QEvent::MouseButtonRelease:
// d->mouseReleaseEvent(static_cast<QMouseEvent*>(ev));
// break;
//#if !defined(QT_NO_GRAPHICSVIEW)
// case QEvent::GraphicsSceneMouseMove: {
// QGraphicsSceneMouseEvent *gsEv = static_cast<QGraphicsSceneMouseEvent*>(ev);
// QMouseEvent dummyEvent(QEvent::MouseMove, gsEv->pos(), gsEv->screenPos(), gsEv->button(), gsEv->buttons(), gsEv->modifiers());
// d->mouseMoveEvent(&dummyEvent);
// ev->setAccepted(dummyEvent.isAccepted());
// break;
// }
// case QEvent::GraphicsSceneMouseRelease: {
// QGraphicsSceneMouseEvent *gsEv = static_cast<QGraphicsSceneMouseEvent*>(ev);
// QMouseEvent dummyEvent(QEvent::MouseButtonRelease, gsEv->pos(), gsEv->screenPos(), gsEv->button(), gsEv->buttons(), gsEv->modifiers());
// d->adjustPointForClicking(&dummyEvent);
// d->mouseReleaseEvent(&dummyEvent);
// ev->setAccepted(dummyEvent.isAccepted());
// break;
// }
// case QEvent::GraphicsSceneMousePress: {
// QGraphicsSceneMouseEvent *gsEv = static_cast<QGraphicsSceneMouseEvent*>(ev);
// QMouseEvent dummyEvent(QEvent::MouseButtonPress, gsEv->pos(), gsEv->screenPos(), gsEv->button(), gsEv->buttons(), gsEv->modifiers());
// d->adjustPointForClicking(&dummyEvent);
// d->mousePressEvent(&dummyEvent);
// ev->setAccepted(dummyEvent.isAccepted());
// break;
// }
// case QEvent::GraphicsSceneMouseDoubleClick: {
// QGraphicsSceneMouseEvent *gsEv = static_cast<QGraphicsSceneMouseEvent*>(ev);
// QMouseEvent dummyEvent(QEvent::MouseButtonDblClick, gsEv->pos(), gsEv->screenPos(), gsEv->button(), gsEv->buttons(), gsEv->modifiers());
// d->adjustPointForClicking(&dummyEvent);
// d->mouseDoubleClickEvent(&dummyEvent);
// ev->setAccepted(dummyEvent.isAccepted());
// break;
// }
//#endif
//#ifndef QT_NO_CONTEXTMENU
// case QEvent::ContextMenu:
// d->contextMenuEvent(static_cast<QContextMenuEvent*>(ev)->globalPos());
// break;
//#if !defined(QT_NO_GRAPHICSVIEW)
// case QEvent::GraphicsSceneContextMenu:
// d->contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent*>(ev)->screenPos());
// break;
//#endif
//#endif
//#ifndef QT_NO_WHEELEVENT
// case QEvent::Wheel:
// d->wheelEvent(static_cast<QWheelEvent*>(ev), QApplication::wheelScrollLines());
// break;
//#if !defined(QT_NO_GRAPHICSVIEW)
// case QEvent::GraphicsSceneWheel: {
// QGraphicsSceneWheelEvent *gsEv = static_cast<QGraphicsSceneWheelEvent*>(ev);
// QWheelEvent dummyEvent(gsEv->pos(), gsEv->screenPos(), gsEv->delta(), gsEv->buttons(), gsEv->modifiers(), gsEv->orientation());
// d->wheelEvent(&dummyEvent, QApplication::wheelScrollLines());
// ev->setAccepted(dummyEvent.isAccepted());
// break;
// }
//#endif
//#endif
// case QEvent::KeyPress:
// qobject_cast<QUltralightView*>(view())->sendKey(static_cast<QKeyEvent*>(ev));
// break;
// case QEvent::KeyRelease:
// d->keyReleaseEvent(static_cast<QKeyEvent*>(ev));
// break;
// case QEvent::FocusIn:
// d->focusInEvent(static_cast<QFocusEvent*>(ev));
// break;
// case QEvent::FocusOut:
// d->focusOutEvent(static_cast<QFocusEvent*>(ev));
// break;
//#if ENABLE(DRAG_SUPPORT)
// case QEvent::DragEnter:
// d->dragEnterEvent(static_cast<QDragEnterEvent*>(ev));
// break;
// case QEvent::DragLeave:
// d->dragLeaveEvent();
// ev->accept();
// break;