forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebHTMLView.mm
More file actions
7214 lines (6004 loc) · 263 KB
/
WebHTMLView.mm
File metadata and controls
7214 lines (6004 loc) · 263 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
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) 2005-2020 Apple Inc. All rights reserved.
* (C) 2006, 2007 Graham Dennis (graham.dennis@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "WebHTMLView.h"
#import "DOMCSSStyleDeclarationInternal.h"
#import "DOMDocumentFragmentInternal.h"
#import "DOMDocumentInternal.h"
#import "DOMNodeInternal.h"
#import "DOMRangeInternal.h"
#import "WebArchive.h"
#import "WebClipView.h"
#import "WebContextMenuClient.h"
#import "WebDOMOperationsInternal.h"
#import "WebDataSourceInternal.h"
#import "WebDefaultUIDelegate.h"
#import "WebDelegateImplementationCaching.h"
#import "WebDocumentInternal.h"
#import "WebDynamicScrollBarsViewInternal.h"
#import "WebEditingDelegate.h"
#import "WebElementDictionary.h"
#import "WebFrameInternal.h"
#import "WebFramePrivate.h"
#import "WebFrameViewInternal.h"
#import "WebHTMLRepresentationPrivate.h"
#import "WebHTMLViewInternal.h"
#import "WebImmediateActionController.h"
#import "WebKitLogging.h"
#import "WebKitNSStringExtras.h"
#import "WebKitVersionChecks.h"
#import "WebLocalizableStringsInternal.h"
#import "WebNSFileManagerExtras.h"
#import "WebNSImageExtras.h"
#import "WebNSObjectExtras.h"
#import "WebNSPrintOperationExtras.h"
#import "WebNSURLExtras.h"
#import "WebNSViewExtras.h"
#import "WebNetscapePluginView.h"
#import "WebNodeHighlight.h"
#import "WebPluginController.h"
#import "WebPreferences.h"
#import "WebPreferencesPrivate.h"
#import "WebResourcePrivate.h"
#import "WebSharingServicePickerController.h"
#import "WebTextCompletionController.h"
#import "WebUIDelegatePrivate.h"
#import "WebViewInternal.h"
#import <JavaScriptCore/InitializeThreading.h>
#import <QuartzCore/QuartzCore.h>
#import <WebCore/CSSStyleDeclaration.h>
#import <WebCore/CachedImage.h>
#import <WebCore/CachedResourceClient.h>
#import <WebCore/CachedResourceLoader.h>
#import <WebCore/Chrome.h>
#import <WebCore/ColorMac.h>
#import <WebCore/CompositionHighlight.h>
#import <WebCore/ContextMenu.h>
#import <WebCore/ContextMenuController.h>
#import <WebCore/DictationAlternative.h>
#import <WebCore/DictionaryLookup.h>
#import <WebCore/Document.h>
#import <WebCore/DocumentFragment.h>
#import <WebCore/DocumentMarkerController.h>
#import <WebCore/DragController.h>
#import <WebCore/DragImage.h>
#import <WebCore/Editor.h>
#import <WebCore/EditorDeleteAction.h>
#import <WebCore/Element.h>
#import <WebCore/EventHandler.h>
#import <WebCore/FloatRect.h>
#import <WebCore/FocusController.h>
#import <WebCore/Font.h>
#import <WebCore/FontAttributeChanges.h>
#import <WebCore/FontAttributes.h>
#import <WebCore/FontCache.h>
#import <WebCore/Frame.h>
#import <WebCore/FrameLoader.h>
#import <WebCore/FrameSelection.h>
#import <WebCore/FrameView.h>
#import <WebCore/HTMLConverter.h>
#import <WebCore/HTMLNames.h>
#import <WebCore/HitTestResult.h>
#import <WebCore/Image.h>
#import <WebCore/KeyboardEvent.h>
#import <WebCore/LegacyNSPasteboardTypes.h>
#import <WebCore/LegacyWebArchive.h>
#import <WebCore/LocalizedStrings.h>
#import <WebCore/MIMETypeRegistry.h>
#import <WebCore/Page.h>
#import <WebCore/PrintContext.h>
#import <WebCore/Range.h>
#import <WebCore/RenderView.h>
#import <WebCore/RenderWidget.h>
#import <WebCore/RuntimeApplicationChecks.h>
#import <WebCore/RuntimeEnabledFeatures.h>
#import <WebCore/SharedBuffer.h>
#import <WebCore/StyleProperties.h>
#import <WebCore/StyleScope.h>
#import <WebCore/Text.h>
#import <WebCore/TextAlternativeWithRange.h>
#import <WebCore/TextIndicator.h>
#import <WebCore/TextUndoInsertionMarkupMac.h>
#import <WebCore/WebCoreJITOperations.h>
#import <WebCore/WebCoreNSFontManagerExtras.h>
#import <WebCore/WebCoreObjCExtras.h>
#import <WebCore/WebNSAttributedStringExtras.h>
#import <WebCore/markup.h>
#import <WebKitLegacy/DOM.h>
#import <WebKitLegacy/DOMExtensions.h>
#import <WebKitLegacy/DOMPrivate.h>
#import <dlfcn.h>
#import <limits>
#import <pal/spi/cf/CFUtilitiesSPI.h>
#import <pal/spi/cocoa/NSAttributedStringSPI.h>
#import <pal/spi/cocoa/NSURLFileTypeMappingsSPI.h>
#import <pal/spi/mac/NSMenuSPI.h>
#import <pal/spi/mac/NSScrollerImpSPI.h>
#import <pal/spi/mac/NSSpellCheckerSPI.h>
#import <pal/spi/mac/NSViewSPI.h>
#import <pal/spi/mac/NSWindowSPI.h>
#import <wtf/BlockObjCExceptions.h>
#import <wtf/MainThread.h>
#import <wtf/MathExtras.h>
#import <wtf/NakedPtr.h>
#import <wtf/ObjCRuntimeExtras.h>
#import <wtf/RunLoop.h>
#import <wtf/SystemTracing.h>
#import <wtf/WeakObjCPtr.h>
#import <wtf/cocoa/TypeCastsCocoa.h>
#import <wtf/cocoa/VectorCocoa.h>
#if PLATFORM(MAC)
#import "WebNSEventExtras.h"
#import "WebNSPasteboardExtras.h"
#import <AppKit/NSAccessibility.h>
#import <WebCore/PlatformEventFactoryMac.h>
#import <pal/spi/mac/NSMenuSPI.h>
#import <pal/spi/mac/NSTextInputContextSPI.h>
#endif
#if PLATFORM(IOS_FAMILY)
#import "WebUIKitDelegate.h"
#import <WebCore/GraphicsContextCG.h>
#import <WebCore/KeyEventCodesIOS.h>
#import <WebCore/PlatformEventFactoryIOS.h>
#import <WebCore/WAKClipView.h>
#import <WebCore/WAKScrollView.h>
#import <WebCore/WAKWindow.h>
#import <WebCore/WKGraphics.h>
#import <WebCore/WebCoreThreadRun.h>
#import <WebCore/WebEvent.h>
#import <pal/spi/cf/CFNotificationCenterSPI.h>
#import <pal/spi/ios/GraphicsServicesSPI.h>
#endif
#if PLATFORM(IOS_FAMILY)
@interface NSObject (Accessibility)
- (id)accessibilityHitTest:(NSPoint)point;
- (id)accessibilityFocusedUIElement;
@end
#endif
#if PLATFORM(MAC)
@class NSTextInputContext;
@interface NSApplication ()
- (BOOL)isSpeaking;
- (void)speakString:(NSString *)string;
- (void)stopSpeaking:(id)sender;
@end
@interface NSAttributedString ()
- (DOMDocumentFragment *)_documentFromRange:(NSRange)range document:(DOMDocument *)document documentAttributes:(NSDictionary *)dict subresources:(NSArray **)subresources;
@end
@interface NSObject ()
- (BOOL)handleMouseEvent:(NSEvent *)event;
- (BOOL)wantsToHandleMouseEvents;
@end
@interface NSResponder ()
- (NSTextInputContext *)inputContext;
@end
@interface NSView ()
- (BOOL)_drawnByAncestor;
- (void)_invalidateGStatesForTree;
- (void)_windowChangedKeyState;
@end
@interface NSWindow ()
@property (readonly) __kindof NSView *_borderView;
- (id)_newFirstResponderAfterResigning;
@end
#if !HAVE(SUBVIEWS_IVAR_SPI)
@implementation NSView (SubviewsIvar)
- (void)_setSubviewsIvar:(NSMutableArray<__kindof NSView *> *)subviews {
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
_subviews = subviews;
ALLOW_DEPRECATED_DECLARATIONS_END
}
- (NSMutableArray<__kindof NSView *> *)_subviewsIvar {
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
return (NSMutableArray *)_subviews;
ALLOW_DEPRECATED_DECLARATIONS_END
}
@end
#endif
using WebEvent = NSEvent;
const auto WebEventMouseDown = NSEventTypeLeftMouseDown;
@interface WebMenuTarget : NSObject {
NakedPtr<WebCore::ContextMenuController> _menuController;
}
+ (WebMenuTarget*)sharedMenuTarget;
- (NakedPtr<WebCore::ContextMenuController>)menuController;
- (void)setMenuController:(NakedPtr<WebCore::ContextMenuController>)menuController;
- (void)forwardContextMenuAction:(id)sender;
@end
static std::optional<WebCore::ContextMenuAction> toAction(NSInteger tag)
{
using namespace WebCore;
if (tag >= ContextMenuItemBaseCustomTag && tag <= ContextMenuItemLastCustomTag) {
// Just pass these through.
return static_cast<ContextMenuAction>(tag);
}
switch (tag) {
case WebMenuItemTagOpenLinkInNewWindow:
return ContextMenuItemTagOpenLinkInNewWindow;
case WebMenuItemTagDownloadLinkToDisk:
return ContextMenuItemTagDownloadLinkToDisk;
case WebMenuItemTagCopyLinkToClipboard:
return ContextMenuItemTagCopyLinkToClipboard;
case WebMenuItemTagOpenImageInNewWindow:
return ContextMenuItemTagOpenImageInNewWindow;
case WebMenuItemTagDownloadImageToDisk:
return ContextMenuItemTagDownloadImageToDisk;
case WebMenuItemTagCopyImageToClipboard:
return ContextMenuItemTagCopyImageToClipboard;
case WebMenuItemTagOpenFrameInNewWindow:
return ContextMenuItemTagOpenFrameInNewWindow;
case WebMenuItemTagCopy:
return ContextMenuItemTagCopy;
case WebMenuItemTagGoBack:
return ContextMenuItemTagGoBack;
case WebMenuItemTagGoForward:
return ContextMenuItemTagGoForward;
case WebMenuItemTagStop:
return ContextMenuItemTagStop;
case WebMenuItemTagReload:
return ContextMenuItemTagReload;
case WebMenuItemTagCut:
return ContextMenuItemTagCut;
case WebMenuItemTagPaste:
return ContextMenuItemTagPaste;
case WebMenuItemTagSpellingGuess:
return ContextMenuItemTagSpellingGuess;
case WebMenuItemTagNoGuessesFound:
return ContextMenuItemTagNoGuessesFound;
case WebMenuItemTagIgnoreSpelling:
return ContextMenuItemTagIgnoreSpelling;
case WebMenuItemTagLearnSpelling:
return ContextMenuItemTagLearnSpelling;
case WebMenuItemTagOther:
return ContextMenuItemTagOther;
case WebMenuItemTagSearchInSpotlight:
return ContextMenuItemTagSearchInSpotlight;
case WebMenuItemTagSearchWeb:
return ContextMenuItemTagSearchWeb;
case WebMenuItemTagLookUpInDictionary:
return ContextMenuItemTagLookUpInDictionary;
case WebMenuItemTagOpenWithDefaultApplication:
return ContextMenuItemTagOpenWithDefaultApplication;
case WebMenuItemPDFActualSize:
return ContextMenuItemPDFActualSize;
case WebMenuItemPDFZoomIn:
return ContextMenuItemPDFZoomIn;
case WebMenuItemPDFZoomOut:
return ContextMenuItemPDFZoomOut;
case WebMenuItemPDFAutoSize:
return ContextMenuItemPDFAutoSize;
case WebMenuItemPDFSinglePage:
return ContextMenuItemPDFSinglePage;
case WebMenuItemPDFFacingPages:
return ContextMenuItemPDFFacingPages;
case WebMenuItemPDFContinuous:
return ContextMenuItemPDFContinuous;
case WebMenuItemPDFNextPage:
return ContextMenuItemPDFNextPage;
case WebMenuItemPDFPreviousPage:
return ContextMenuItemPDFPreviousPage;
case WebMenuItemTagOpenLink:
return ContextMenuItemTagOpenLink;
case WebMenuItemTagIgnoreGrammar:
return ContextMenuItemTagIgnoreGrammar;
case WebMenuItemTagSpellingMenu:
return ContextMenuItemTagSpellingMenu;
case WebMenuItemTagShowSpellingPanel:
return ContextMenuItemTagShowSpellingPanel;
case WebMenuItemTagCheckSpelling:
return ContextMenuItemTagCheckSpelling;
case WebMenuItemTagCheckSpellingWhileTyping:
return ContextMenuItemTagCheckSpellingWhileTyping;
case WebMenuItemTagCheckGrammarWithSpelling:
return ContextMenuItemTagCheckGrammarWithSpelling;
case WebMenuItemTagFontMenu:
return ContextMenuItemTagFontMenu;
case WebMenuItemTagShowFonts:
return ContextMenuItemTagShowFonts;
case WebMenuItemTagBold:
return ContextMenuItemTagBold;
case WebMenuItemTagItalic:
return ContextMenuItemTagItalic;
case WebMenuItemTagUnderline:
return ContextMenuItemTagUnderline;
case WebMenuItemTagOutline:
return ContextMenuItemTagOutline;
case WebMenuItemTagStyles:
return ContextMenuItemTagStyles;
case WebMenuItemTagShowColors:
return ContextMenuItemTagShowColors;
case WebMenuItemTagSpeechMenu:
return ContextMenuItemTagSpeechMenu;
case WebMenuItemTagStartSpeaking:
return ContextMenuItemTagStartSpeaking;
case WebMenuItemTagStopSpeaking:
return ContextMenuItemTagStopSpeaking;
case WebMenuItemTagWritingDirectionMenu:
return ContextMenuItemTagWritingDirectionMenu;
case WebMenuItemTagDefaultDirection:
return ContextMenuItemTagDefaultDirection;
case WebMenuItemTagLeftToRight:
return ContextMenuItemTagLeftToRight;
case WebMenuItemTagRightToLeft:
return ContextMenuItemTagRightToLeft;
case WebMenuItemPDFSinglePageScrolling:
return ContextMenuItemTagPDFSinglePageScrolling;
case WebMenuItemPDFFacingPagesScrolling:
return ContextMenuItemTagPDFFacingPagesScrolling;
case WebMenuItemTagInspectElement:
return ContextMenuItemTagInspectElement;
case WebMenuItemTagTextDirectionMenu:
return ContextMenuItemTagTextDirectionMenu;
case WebMenuItemTagTextDirectionDefault:
return ContextMenuItemTagTextDirectionDefault;
case WebMenuItemTagTextDirectionLeftToRight:
return ContextMenuItemTagTextDirectionLeftToRight;
case WebMenuItemTagTextDirectionRightToLeft:
return ContextMenuItemTagTextDirectionRightToLeft;
case WebMenuItemTagCorrectSpellingAutomatically:
return ContextMenuItemTagCorrectSpellingAutomatically;
case WebMenuItemTagSubstitutionsMenu:
return ContextMenuItemTagSubstitutionsMenu;
case WebMenuItemTagShowSubstitutions:
return ContextMenuItemTagShowSubstitutions;
case WebMenuItemTagSmartCopyPaste:
return ContextMenuItemTagSmartCopyPaste;
case WebMenuItemTagSmartQuotes:
return ContextMenuItemTagSmartQuotes;
case WebMenuItemTagSmartDashes:
return ContextMenuItemTagSmartDashes;
case WebMenuItemTagSmartLinks:
return ContextMenuItemTagSmartLinks;
case WebMenuItemTagTextReplacement:
return ContextMenuItemTagTextReplacement;
case WebMenuItemTagTransformationsMenu:
return ContextMenuItemTagTransformationsMenu;
case WebMenuItemTagMakeUpperCase:
return ContextMenuItemTagMakeUpperCase;
case WebMenuItemTagMakeLowerCase:
return ContextMenuItemTagMakeLowerCase;
case WebMenuItemTagCapitalize:
return ContextMenuItemTagCapitalize;
case WebMenuItemTagChangeBack:
return ContextMenuItemTagChangeBack;
case WebMenuItemTagOpenMediaInNewWindow:
return ContextMenuItemTagOpenMediaInNewWindow;
case WebMenuItemTagCopyMediaLinkToClipboard:
return ContextMenuItemTagCopyMediaLinkToClipboard;
case WebMenuItemTagToggleMediaControls:
return ContextMenuItemTagToggleMediaControls;
case WebMenuItemTagToggleMediaLoop:
return ContextMenuItemTagToggleMediaLoop;
case WebMenuItemTagEnterVideoFullscreen:
return ContextMenuItemTagEnterVideoFullscreen;
case WebMenuItemTagToggleVideoEnhancedFullscreen:
return ContextMenuItemTagToggleVideoEnhancedFullscreen;
case WebMenuItemTagMediaPlayPause:
return ContextMenuItemTagMediaPlayPause;
case WebMenuItemTagMediaMute:
return ContextMenuItemTagMediaMute;
case WebMenuItemTagDictationAlternative:
return ContextMenuItemTagDictationAlternative;
case WebMenuItemTagTranslate:
return ContextMenuItemTagTranslate;
}
return std::nullopt;
}
static std::optional<NSInteger> toTag(WebCore::ContextMenuAction action)
{
using namespace WebCore;
switch (action) {
case ContextMenuItemTagNoAction:
return std::nullopt;
case ContextMenuItemTagOpenLinkInNewWindow:
return WebMenuItemTagOpenLinkInNewWindow;
case ContextMenuItemTagDownloadLinkToDisk:
return WebMenuItemTagDownloadLinkToDisk;
case ContextMenuItemTagCopyLinkToClipboard:
return WebMenuItemTagCopyLinkToClipboard;
case ContextMenuItemTagOpenImageInNewWindow:
return WebMenuItemTagOpenImageInNewWindow;
case ContextMenuItemTagDownloadImageToDisk:
return WebMenuItemTagDownloadImageToDisk;
case ContextMenuItemTagCopyImageToClipboard:
return WebMenuItemTagCopyImageToClipboard;
case ContextMenuItemTagOpenFrameInNewWindow:
return WebMenuItemTagOpenFrameInNewWindow;
case ContextMenuItemTagCopy:
return WebMenuItemTagCopy;
case ContextMenuItemTagGoBack:
return WebMenuItemTagGoBack;
case ContextMenuItemTagGoForward:
return WebMenuItemTagGoForward;
case ContextMenuItemTagStop:
return WebMenuItemTagStop;
case ContextMenuItemTagReload:
return WebMenuItemTagReload;
case ContextMenuItemTagCut:
return WebMenuItemTagCut;
case ContextMenuItemTagPaste:
return WebMenuItemTagPaste;
case ContextMenuItemTagSpellingGuess:
return WebMenuItemTagSpellingGuess;
case ContextMenuItemTagNoGuessesFound:
return WebMenuItemTagNoGuessesFound;
case ContextMenuItemTagIgnoreSpelling:
return WebMenuItemTagIgnoreSpelling;
case ContextMenuItemTagLearnSpelling:
return WebMenuItemTagLearnSpelling;
case ContextMenuItemTagOther:
return WebMenuItemTagOther;
case ContextMenuItemTagSearchInSpotlight:
return WebMenuItemTagSearchInSpotlight;
case ContextMenuItemTagSearchWeb:
return WebMenuItemTagSearchWeb;
case ContextMenuItemTagLookUpInDictionary:
return WebMenuItemTagLookUpInDictionary;
case ContextMenuItemTagOpenWithDefaultApplication:
return WebMenuItemTagOpenWithDefaultApplication;
case ContextMenuItemPDFActualSize:
return WebMenuItemPDFActualSize;
case ContextMenuItemPDFZoomIn:
return WebMenuItemPDFZoomIn;
case ContextMenuItemPDFZoomOut:
return WebMenuItemPDFZoomOut;
case ContextMenuItemPDFAutoSize:
return WebMenuItemPDFAutoSize;
case ContextMenuItemPDFSinglePage:
return WebMenuItemPDFSinglePage;
case ContextMenuItemPDFFacingPages:
return WebMenuItemPDFFacingPages;
case ContextMenuItemPDFContinuous:
return WebMenuItemPDFContinuous;
case ContextMenuItemPDFNextPage:
return WebMenuItemPDFNextPage;
case ContextMenuItemPDFPreviousPage:
return WebMenuItemPDFPreviousPage;
case ContextMenuItemTagOpenLink:
return WebMenuItemTagOpenLink;
case ContextMenuItemTagIgnoreGrammar:
return WebMenuItemTagIgnoreGrammar;
case ContextMenuItemTagSpellingMenu:
return WebMenuItemTagSpellingMenu;
case ContextMenuItemTagShowSpellingPanel:
return WebMenuItemTagShowSpellingPanel;
case ContextMenuItemTagCheckSpelling:
return WebMenuItemTagCheckSpelling;
case ContextMenuItemTagCheckSpellingWhileTyping:
return WebMenuItemTagCheckSpellingWhileTyping;
case ContextMenuItemTagCheckGrammarWithSpelling:
return WebMenuItemTagCheckGrammarWithSpelling;
case ContextMenuItemTagFontMenu:
return WebMenuItemTagFontMenu;
case ContextMenuItemTagShowFonts:
return WebMenuItemTagShowFonts;
case ContextMenuItemTagBold:
return WebMenuItemTagBold;
case ContextMenuItemTagItalic:
return WebMenuItemTagItalic;
case ContextMenuItemTagUnderline:
return WebMenuItemTagUnderline;
case ContextMenuItemTagOutline:
return WebMenuItemTagOutline;
case ContextMenuItemTagStyles:
return WebMenuItemTagStyles;
case ContextMenuItemTagShowColors:
return WebMenuItemTagShowColors;
case ContextMenuItemTagSpeechMenu:
return WebMenuItemTagSpeechMenu;
case ContextMenuItemTagStartSpeaking:
return WebMenuItemTagStartSpeaking;
case ContextMenuItemTagStopSpeaking:
return WebMenuItemTagStopSpeaking;
case ContextMenuItemTagWritingDirectionMenu:
return WebMenuItemTagWritingDirectionMenu;
case ContextMenuItemTagDefaultDirection:
return WebMenuItemTagDefaultDirection;
case ContextMenuItemTagLeftToRight:
return WebMenuItemTagLeftToRight;
case ContextMenuItemTagRightToLeft:
return WebMenuItemTagRightToLeft;
case ContextMenuItemTagPDFSinglePageScrolling:
return WebMenuItemPDFSinglePageScrolling;
case ContextMenuItemTagPDFFacingPagesScrolling:
return WebMenuItemPDFFacingPagesScrolling;
case ContextMenuItemTagInspectElement:
return WebMenuItemTagInspectElement;
case ContextMenuItemTagTextDirectionMenu:
return WebMenuItemTagTextDirectionMenu;
case ContextMenuItemTagTextDirectionDefault:
return WebMenuItemTagTextDirectionDefault;
case ContextMenuItemTagTextDirectionLeftToRight:
return WebMenuItemTagTextDirectionLeftToRight;
case ContextMenuItemTagTextDirectionRightToLeft:
return WebMenuItemTagTextDirectionRightToLeft;
case ContextMenuItemTagCorrectSpellingAutomatically:
return WebMenuItemTagCorrectSpellingAutomatically;
case ContextMenuItemTagSubstitutionsMenu:
return WebMenuItemTagSubstitutionsMenu;
case ContextMenuItemTagShowSubstitutions:
return WebMenuItemTagShowSubstitutions;
case ContextMenuItemTagSmartCopyPaste:
return WebMenuItemTagSmartCopyPaste;
case ContextMenuItemTagSmartQuotes:
return WebMenuItemTagSmartQuotes;
case ContextMenuItemTagSmartDashes:
return WebMenuItemTagSmartDashes;
case ContextMenuItemTagSmartLinks:
return WebMenuItemTagSmartLinks;
case ContextMenuItemTagTextReplacement:
return WebMenuItemTagTextReplacement;
case ContextMenuItemTagTransformationsMenu:
return WebMenuItemTagTransformationsMenu;
case ContextMenuItemTagMakeUpperCase:
return WebMenuItemTagMakeUpperCase;
case ContextMenuItemTagMakeLowerCase:
return WebMenuItemTagMakeLowerCase;
case ContextMenuItemTagCapitalize:
return WebMenuItemTagCapitalize;
case ContextMenuItemTagChangeBack:
return WebMenuItemTagChangeBack;
case ContextMenuItemTagOpenMediaInNewWindow:
return WebMenuItemTagOpenMediaInNewWindow;
case ContextMenuItemTagDownloadMediaToDisk:
return WebMenuItemTagDownloadMediaToDisk;
case ContextMenuItemTagCopyMediaLinkToClipboard:
return WebMenuItemTagCopyMediaLinkToClipboard;
case ContextMenuItemTagToggleMediaControls:
return WebMenuItemTagToggleMediaControls;
case ContextMenuItemTagToggleMediaLoop:
return WebMenuItemTagToggleMediaLoop;
case ContextMenuItemTagEnterVideoFullscreen:
return WebMenuItemTagEnterVideoFullscreen;
case ContextMenuItemTagMediaPlayPause:
return WebMenuItemTagMediaPlayPause;
case ContextMenuItemTagMediaMute:
return WebMenuItemTagMediaMute;
case ContextMenuItemTagDictationAlternative:
return WebMenuItemTagDictationAlternative;
case ContextMenuItemTagToggleVideoFullscreen:
return WebMenuItemTagToggleVideoFullscreen;
case ContextMenuItemTagAddHighlightToCurrentQuickNote:
case ContextMenuItemTagAddHighlightToNewQuickNote:
return std::nullopt;
case ContextMenuItemTagShareMenu:
return WebMenuItemTagShareMenu;
case ContextMenuItemTagToggleVideoEnhancedFullscreen:
return WebMenuItemTagToggleVideoEnhancedFullscreen;
case ContextMenuItemTagTranslate:
return WebMenuItemTagTranslate;
case ContextMenuItemTagQuickLookImage:
return std::nullopt;
case ContextMenuItemBaseCustomTag ... ContextMenuItemLastCustomTag:
// We just pass these through.
return static_cast<NSInteger>(action);
case ContextMenuItemBaseApplicationTag:
ASSERT_NOT_REACHED();
}
return std::nullopt;
}
@implementation WebMenuTarget
+ (WebMenuTarget *)sharedMenuTarget
{
static WebMenuTarget *target = [[WebMenuTarget alloc] init];
return target;
}
- (NakedPtr<WebCore::ContextMenuController>)menuController
{
return _menuController;
}
- (void)setMenuController:(NakedPtr<WebCore::ContextMenuController>)menuController
{
_menuController = menuController;
}
- (void)forwardContextMenuAction:(id)sender
{
if (auto action = toAction([sender tag]))
_menuController->contextMenuItemSelected(*action, [sender title]);
}
@end
@interface WebResponderChainSink : NSResponder {
NSResponder* _lastResponderInChain;
BOOL _receivedUnhandledCommand;
}
- (id)initWithResponderChain:(NSResponder *)chain;
- (void)detach;
- (BOOL)receivedUnhandledCommand;
@end
@interface WebLayerHostingFlippedView : NSView
@end
@implementation WebLayerHostingFlippedView
- (BOOL)isFlipped
{
return YES;
}
@end
@interface WebRootLayer : CALayer
@end
@implementation WebRootLayer
- (void)renderInContext:(CGContextRef)graphicsContext
{
// AppKit calls -[CALayer renderInContext:] to render layer-backed views
// into bitmap contexts, but renderInContext: doesn't capture mask layers
// (<rdar://problem/9539526>), so we can't rely on it. Since our layer
// contents will have already been rendered by drawRect:, we can safely make
// this a NOOP.
}
@end
// if YES, do the standard NSView hit test (which can't give the right result when HTML overlaps a view)
static BOOL forceNSViewHitTest;
// if YES, do the "top WebHTMLView" hit test (which we'd like to do all the time but can't because of Java requirements [see bug 4349721])
static BOOL forceWebHTMLViewHitTest;
static WebHTMLView *lastHitView;
static bool needsCursorRectsSupportAtPoint(NSWindow* window, NSPoint point)
{
forceNSViewHitTest = YES;
NSView* view = [window._borderView hitTest:point];
forceNSViewHitTest = NO;
// WebHTMLView doesn't use cursor rects.
if ([view isKindOfClass:[WebHTMLView class]])
return false;
#if ENABLE(NETSCAPE_PLUGIN_API)
// Neither do NPAPI plug-ins.
if ([view isKindOfClass:[WebBaseNetscapePluginView class]])
return false;
#endif
// Non-Web content, WebPDFView, and WebKit plug-ins use normal cursor handling.
return true;
}
static IMP oldSetCursorForMouseLocationIMP;
// Overriding an internal method is a hack; <rdar://problem/7662987> tracks finding a better solution.
static void setCursor(NSWindow *self, SEL cmd, NSPoint point)
{
if (needsCursorRectsSupportAtPoint(self, point))
wtfCallIMP<id>(oldSetCursorForMouseLocationIMP, self, cmd, point);
}
#endif // PLATFORM(MAC)
@interface NSView ()
- (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)rect isVisibleRect:(BOOL)isVisibleRect rectIsVisibleRectForView:(NSView *)visibleView topView:(BOOL)topView;
- (void)_recursiveDisplayAllDirtyWithLockFocus:(BOOL)needsLockFocus visRect:(NSRect)visRect;
#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500
- (void)_recursive:(BOOL)recursive displayRectIgnoringOpacity:(NSRect)displayRect inContext:(NSGraphicsContext *)graphicsContext stopAtLayerBackedViews:(BOOL)stopAtLayerBackedViews;
#endif
#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
- (void)_recursive:(BOOL)recursive displayRectIgnoringOpacity:(NSRect)displayRect inContext:(NSGraphicsContext *)graphicsContext shouldChangeFontReferenceColor:(BOOL)shouldChangeFontReferenceColor stopAtLayerBackedViews:(BOOL)stopAtLayerBackedViews;
#endif
- (void)_setDrawsOwnDescendants:(BOOL)drawsOwnDescendants;
#if PLATFORM(IOS_FAMILY)
- (void)centerSelectionInVisibleArea:(id)sender;
#endif
@end
#if PLATFORM(MAC)
@interface NSView (WebSetNeedsDisplayInRect)
- (void)_web_setNeedsDisplayInRect:(NSRect)invalidRect;
@end
@implementation NSView (WebSetNeedsDisplayInRect)
- (void)_web_setNeedsDisplayInRect:(NSRect)invalidRect
{
// Note that we call method_exchangeImplementations below, so any calls
// to _web_setNeedsDisplayInRect: will actually call -[NSView setNeedsDisplayInRect:].
if (![NSThread isMainThread] || ![self _drawnByAncestor]) {
[self _web_setNeedsDisplayInRect:invalidRect];
return;
}
static Class webFrameViewClass = [WebFrameView class];
WebFrameView *enclosingWebFrameView = (WebFrameView *)self;
while (enclosingWebFrameView && ![enclosingWebFrameView isKindOfClass:webFrameViewClass])
enclosingWebFrameView = (WebFrameView *)[enclosingWebFrameView superview];
if (!enclosingWebFrameView) {
[self _web_setNeedsDisplayInRect:invalidRect];
return;
}
auto* coreFrame = core([enclosingWebFrameView webFrame]);
auto* frameView = coreFrame ? coreFrame->view() : 0;
if (!frameView || !frameView->isEnclosedInCompositingLayer()) {
[self _web_setNeedsDisplayInRect:invalidRect];
return;
}
NSRect invalidRectInWebFrameViewCoordinates = [enclosingWebFrameView convertRect:invalidRect fromView:self];
WebCore::IntRect invalidRectInFrameViewCoordinates(invalidRectInWebFrameViewCoordinates);
if (![enclosingWebFrameView isFlipped])
invalidRectInFrameViewCoordinates.setY(frameView->frameRect().size().height() - invalidRectInFrameViewCoordinates.maxY());
frameView->invalidateRect(invalidRectInFrameViewCoordinates);
}
@end
#endif // PLATFORM(MAC)
const float _WebHTMLViewPrintingMinimumShrinkFactor = WebCore::PrintContext::minimumShrinkFactor();
const float _WebHTMLViewPrintingMaximumShrinkFactor = WebCore::PrintContext::maximumShrinkFactor();
// Any non-zero value will do, but using something recognizable might help us debug some day.
#define TRACKING_RECT_TAG 0xBADFACE
// FIXME: From AppKit's _NXSmartPaste constant. Get with an SPI header instead?
#define WebSmartPastePboardType @"NeXT smart paste pasteboard type"
#define STANDARD_WEIGHT 5
#define MIN_BOLD_WEIGHT 7
#define STANDARD_BOLD_WEIGHT 9
#if PLATFORM(MAC)
// <rdar://problem/4985524> References to WebCoreScrollView as a subview of a WebHTMLView may be present
// in some NIB files, so NSUnarchiver must be still able to look up this now-unused class.
@interface WebCoreScrollView : NSScrollView
@end
@implementation WebCoreScrollView
@end
// We need this to be able to safely reference the CachedImage for the promised drag data
static WebCore::CachedImageClient& promisedDataClient()
{
static NeverDestroyed<WebCore::CachedImageClient> staticCachedResourceClient;
return staticCachedResourceClient.get();
}
#endif
#if PLATFORM(IOS_FAMILY)
static NSString * const WebMarkedTextUpdatedNotification = @"WebMarkedTextUpdated";
static void hardwareKeyboardAvailabilityChangedCallback(CFNotificationCenterRef, void* observer, CFStringRef, const void*, CFDictionaryRef)
{
ASSERT(observer);
WeakObjCPtr<WebHTMLView> weakWebView { (__bridge WebHTMLView *)observer };
WebThreadRun(^{
if (auto webView = weakWebView.get()) {
if (auto* coreFrame = core([webView _frame]))
coreFrame->eventHandler().capsLockStateMayHaveChanged();
}
});
}
#endif
@interface WebHTMLView (WebHTMLViewFileInternal)
#if PLATFORM(MAC)
- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard inContext:(DOMRange *)context allowPlainText:(BOOL)allowPlainText;
- (NSString *)_plainTextFromPasteboard:(NSPasteboard *)pasteboard;
- (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText;
- (void)_pasteAsPlainTextWithPasteboard:(NSPasteboard *)pasteboard;
- (void)_postFakeMouseMovedEventForFlagsChangedEvent:(NSEvent *)flagsChangedEvent;
- (void)_removeSuperviewObservers;
- (void)_removeWindowObservers;
#endif
- (BOOL)_shouldInsertFragment:(DOMDocumentFragment *)fragment replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action;
- (BOOL)_shouldInsertText:(NSString *)text replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action;
- (BOOL)_shouldReplaceSelectionWithText:(NSString *)text givenAction:(WebViewInsertAction)action;
- (DOMRange *)_selectedRange;
#if PLATFORM(MAC)
- (void)_writeSelectionWithPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard cachedAttributedString:(NSAttributedString *)attributedString;
#endif
- (DOMRange *)_documentRange;
- (void)_setMouseDownEvent:(WebEvent *)event;
- (WebHTMLView *)_topHTMLView;
- (BOOL)_isTopHTMLView;
#if PLATFORM(MAC)
- (void)_web_setPrintingModeRecursive;
- (void)_web_setPrintingModeRecursiveAndAdjustViewSize;
- (void)_web_clearPrintingModeRecursive;
#endif
#if ENABLE(NETSCAPE_PLUGIN_API)
- (void)_web_makePluginSubviewsPerformSelector:(SEL)selector withObject:(id)object;
#endif
@end
#if PLATFORM(MAC)
@interface WebHTMLView (WebHTMLViewTextCheckingInternal)
- (void)orderFrontSubstitutionsPanel:(id)sender;
- (BOOL)smartInsertDeleteEnabled;
- (void)setSmartInsertDeleteEnabled:(BOOL)flag;
- (void)toggleSmartInsertDelete:(id)sender;
- (BOOL)isAutomaticQuoteSubstitutionEnabled;
- (void)setAutomaticQuoteSubstitutionEnabled:(BOOL)flag;
- (void)toggleAutomaticQuoteSubstitution:(id)sender;
- (BOOL)isAutomaticLinkDetectionEnabled;
- (void)setAutomaticLinkDetectionEnabled:(BOOL)flag;
- (void)toggleAutomaticLinkDetection:(id)sender;
- (BOOL)isAutomaticDashSubstitutionEnabled;
- (void)setAutomaticDashSubstitutionEnabled:(BOOL)flag;
- (void)toggleAutomaticDashSubstitution:(id)sender;
- (BOOL)isAutomaticTextReplacementEnabled;
- (void)setAutomaticTextReplacementEnabled:(BOOL)flag;
- (void)toggleAutomaticTextReplacement:(id)sender;
- (BOOL)isAutomaticSpellingCorrectionEnabled;
- (void)setAutomaticSpellingCorrectionEnabled:(BOOL)flag;
- (void)toggleAutomaticSpellingCorrection:(id)sender;
@end
#endif
@interface WebHTMLView (WebForwardDeclaration) // FIXME: Put this in the WebFileInternal category instead of doing the forward declaration trick.
- (void)_setPrinting:(BOOL)printing minimumPageLogicalWidth:(float)minPageWidth logicalHeight:(float)minPageHeight originalPageWidth:(float)pageLogicalWidth originalPageHeight:(float)pageLogicalHeight maximumShrinkRatio:(float)maximumShrinkRatio adjustViewSize:(BOOL)adjustViewSize paginateScreenContent:(BOOL)paginateScreenContent;
@end
#if PLATFORM(MAC)
@interface WebHTMLView (WebNSTextInputSupport) <NSTextInput>
#else
@interface WebHTMLView (WebNSTextInputSupport)
#endif
#if PLATFORM(MAC)
- (void)_updateSecureInputState;
- (void)_updateSelectionForInputManager;
#endif
#if PLATFORM(IOS_FAMILY)
- (void)setMarkedText:(id)string selectedRange:(NSRange)newSelRange;
- (void)doCommandBySelector:(SEL)selector;
#endif
@end
@interface NSView (WebHTMLViewFileInternal)
- (void)_web_addDescendentWebHTMLViewsToArray:(NSMutableArray *) array;
@end
struct WebHTMLViewInterpretKeyEventsParameters {
WebCore::KeyboardEvent* event;
bool eventInterpretationHadSideEffects;
bool shouldSaveCommands;
bool consumedByIM;
bool executingSavedKeypressCommands;
};
@interface WebHTMLViewPrivate : NSObject {
@public
BOOL closed;
BOOL ignoringMouseDraggedEvents;
BOOL printing;
BOOL paginateScreenContent;
#if PLATFORM(MAC)
BOOL observingSuperviewNotifications;
BOOL observingWindowNotifications;
id savedSubviews;
BOOL subviewsSetAside;
#endif
NSView *layerHostingView;
#if PLATFORM(MAC)
BOOL drawingIntoLayer;
BOOL drawingIntoAcceleratedLayer;
#endif
RetainPtr<WebEvent> mouseDownEvent; // Kept after handling the event.
BOOL handlingMouseDownEvent;
RetainPtr<WebEvent> keyDownEvent; // Kept after handling the event.
// A WebHTMLView has a single input context, but we return nil when in non-editable content to avoid making input methods do their work.
// This state is saved each time selection changes, because computing it causes style recalc, which is not always safe to do.
BOOL exposeInputContext;
#if PLATFORM(MAC)
// Track whether the view has set a secure input state.
BOOL isInSecureInputState;
BOOL _forceUpdateSecureInputState;
#endif
NSPoint lastScrollPosition;
BOOL inScrollPositionChanged;
RetainPtr<WebPluginController> pluginController;
#if PLATFORM(MAC)
RetainPtr<NSString> toolTip;
NSToolTipTag lastToolTipTag;
id trackingRectOwner;
void* trackingRectUserData;
RetainPtr<NSTimer> autoscrollTimer;
RetainPtr<NSEvent> autoscrollTriggerEvent;
#endif
RetainPtr<NSArray> pageRects;
#if PLATFORM(MAC)
RetainPtr<WebTextCompletionController> completionController;
BOOL transparentBackground;
#endif
WebHTMLViewInterpretKeyEventsParameters* interpretKeyEventsParameters;
RetainPtr<WebDataSource> dataSource;
#if PLATFORM(MAC)