fe97010375507b7d71119a4dafb0d528a72e4976
[WebKit-https.git] / Source / WebKit / UIProcess / API / mac / WKView.mm
1 /*
2  * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #import "config.h"
27 #import "WKViewInternal.h"
28
29 #if PLATFORM(MAC)
30
31 #import "APIHitTestResult.h"
32 #import "APIIconLoadingClient.h"
33 #import "APIPageConfiguration.h"
34 #import "WKBrowsingContextGroupPrivate.h"
35 #import "WKDragDestinationAction.h"
36 #import "WKNSData.h"
37 #import "WKProcessGroupPrivate.h"
38 #import "WebBackForwardListItem.h"
39 #import "WebKit2Initialize.h"
40 #import "WebPageGroup.h"
41 #import "WebPreferencesKeys.h"
42 #import "WebProcessPool.h"
43 #import "WebViewImpl.h"
44 #import "_WKLinkIconParametersInternal.h"
45 #import <pal/spi/cocoa/AVKitSPI.h>
46 #import <wtf/BlockPtr.h>
47
48 using namespace WebKit;
49 using namespace WebCore;
50
51 @interface WKViewData : NSObject {
52 @public
53     std::unique_ptr<WebViewImpl> _impl;
54 }
55
56 @end
57
58 @implementation WKViewData
59 @end
60
61 @interface WKView () <WebViewImplDelegate>
62 @end
63
64 #if HAVE(TOUCH_BAR)
65 @interface WKView () <NSTouchBarProvider>
66 @end
67 #endif
68
69 #if ENABLE(DRAG_SUPPORT)
70
71 @interface WKView () <NSFilePromiseProviderDelegate, NSDraggingSource>
72 @end
73
74 #endif
75
76 @implementation WKView
77
78 #if WK_API_ENABLED
79
80 - (id)initWithFrame:(NSRect)frame processGroup:(WKProcessGroup *)processGroup browsingContextGroup:(WKBrowsingContextGroup *)browsingContextGroup
81 {
82     return [self initWithFrame:frame contextRef:processGroup._contextRef pageGroupRef:browsingContextGroup._pageGroupRef relatedToPage:nil];
83 }
84
85 - (id)initWithFrame:(NSRect)frame processGroup:(WKProcessGroup *)processGroup browsingContextGroup:(WKBrowsingContextGroup *)browsingContextGroup relatedToView:(WKView *)relatedView
86 {
87     return [self initWithFrame:frame contextRef:processGroup._contextRef pageGroupRef:browsingContextGroup._pageGroupRef relatedToPage:relatedView ? relatedView.pageRef : nil];
88 }
89
90 #endif // WK_API_ENABLED
91
92 - (void)dealloc
93 {
94     _data->_impl->page().setIconLoadingClient(nullptr);
95     _data->_impl = nullptr;
96
97     [_data release];
98     _data = nil;
99
100     [super dealloc];
101 }
102
103 #if WK_API_ENABLED
104 - (WKBrowsingContextController *)browsingContextController
105 {
106     return _data->_impl->browsingContextController();
107 }
108 #endif // WK_API_ENABLED
109
110 - (void)setDrawsBackground:(BOOL)drawsBackground
111 {
112     _data->_impl->setDrawsBackground(drawsBackground);
113 }
114
115 - (BOOL)drawsBackground
116 {
117     return _data->_impl->drawsBackground();
118 }
119
120 - (NSColor *)_backgroundColor
121 {
122     return _data->_impl->backgroundColor();
123 }
124
125 - (void)_setBackgroundColor:(NSColor *)backgroundColor
126 {
127     _data->_impl->setBackgroundColor(backgroundColor);
128 }
129
130 - (void)setDrawsTransparentBackground:(BOOL)drawsTransparentBackground
131 {
132     _data->_impl->setDrawsBackground(!drawsTransparentBackground);
133 }
134
135 - (BOOL)drawsTransparentBackground
136 {
137     return !_data->_impl->drawsBackground();
138 }
139
140 - (BOOL)acceptsFirstResponder
141 {
142     return _data->_impl->acceptsFirstResponder();
143 }
144
145 - (BOOL)becomeFirstResponder
146 {
147     return _data->_impl->becomeFirstResponder();
148 }
149
150 - (BOOL)resignFirstResponder
151 {
152     return _data->_impl->resignFirstResponder();
153 }
154
155 - (void)viewWillStartLiveResize
156 {
157     _data->_impl->viewWillStartLiveResize();
158 }
159
160 - (void)viewDidEndLiveResize
161 {
162     _data->_impl->viewDidEndLiveResize();
163 }
164
165 - (BOOL)isFlipped
166 {
167     return YES;
168 }
169
170 - (NSSize)intrinsicContentSize
171 {
172     return NSSizeFromCGSize(_data->_impl->intrinsicContentSize());
173 }
174
175 - (void)prepareContentInRect:(NSRect)rect
176 {
177     _data->_impl->prepareContentInRect(NSRectToCGRect(rect));
178 }
179
180 - (void)setFrameSize:(NSSize)size
181 {
182     [super setFrameSize:size];
183     _data->_impl->setFrameSize(NSSizeToCGSize(size));
184 }
185
186 - (void)renewGState
187 {
188     _data->_impl->renewGState();
189     [super renewGState];
190 }
191
192 #define WEBCORE_COMMAND(command) - (void)command:(id)sender { _data->_impl->executeEditCommandForSelector(_cmd); }
193
194 WEBCORE_COMMAND(alignCenter)
195 WEBCORE_COMMAND(alignJustified)
196 WEBCORE_COMMAND(alignLeft)
197 WEBCORE_COMMAND(alignRight)
198 WEBCORE_COMMAND(copy)
199 WEBCORE_COMMAND(cut)
200 WEBCORE_COMMAND(delete)
201 WEBCORE_COMMAND(deleteBackward)
202 WEBCORE_COMMAND(deleteBackwardByDecomposingPreviousCharacter)
203 WEBCORE_COMMAND(deleteForward)
204 WEBCORE_COMMAND(deleteToBeginningOfLine)
205 WEBCORE_COMMAND(deleteToBeginningOfParagraph)
206 WEBCORE_COMMAND(deleteToEndOfLine)
207 WEBCORE_COMMAND(deleteToEndOfParagraph)
208 WEBCORE_COMMAND(deleteToMark)
209 WEBCORE_COMMAND(deleteWordBackward)
210 WEBCORE_COMMAND(deleteWordForward)
211 WEBCORE_COMMAND(ignoreSpelling)
212 WEBCORE_COMMAND(indent)
213 WEBCORE_COMMAND(insertBacktab)
214 WEBCORE_COMMAND(insertLineBreak)
215 WEBCORE_COMMAND(insertNewline)
216 WEBCORE_COMMAND(insertNewlineIgnoringFieldEditor)
217 WEBCORE_COMMAND(insertParagraphSeparator)
218 WEBCORE_COMMAND(insertTab)
219 WEBCORE_COMMAND(insertTabIgnoringFieldEditor)
220 WEBCORE_COMMAND(makeTextWritingDirectionLeftToRight)
221 WEBCORE_COMMAND(makeTextWritingDirectionNatural)
222 WEBCORE_COMMAND(makeTextWritingDirectionRightToLeft)
223 WEBCORE_COMMAND(moveBackward)
224 WEBCORE_COMMAND(moveBackwardAndModifySelection)
225 WEBCORE_COMMAND(moveDown)
226 WEBCORE_COMMAND(moveDownAndModifySelection)
227 WEBCORE_COMMAND(moveForward)
228 WEBCORE_COMMAND(moveForwardAndModifySelection)
229 WEBCORE_COMMAND(moveLeft)
230 WEBCORE_COMMAND(moveLeftAndModifySelection)
231 WEBCORE_COMMAND(moveParagraphBackwardAndModifySelection)
232 WEBCORE_COMMAND(moveParagraphForwardAndModifySelection)
233 WEBCORE_COMMAND(moveRight)
234 WEBCORE_COMMAND(moveRightAndModifySelection)
235 WEBCORE_COMMAND(moveToBeginningOfDocument)
236 WEBCORE_COMMAND(moveToBeginningOfDocumentAndModifySelection)
237 WEBCORE_COMMAND(moveToBeginningOfLine)
238 WEBCORE_COMMAND(moveToBeginningOfLineAndModifySelection)
239 WEBCORE_COMMAND(moveToBeginningOfParagraph)
240 WEBCORE_COMMAND(moveToBeginningOfParagraphAndModifySelection)
241 WEBCORE_COMMAND(moveToBeginningOfSentence)
242 WEBCORE_COMMAND(moveToBeginningOfSentenceAndModifySelection)
243 WEBCORE_COMMAND(moveToEndOfDocument)
244 WEBCORE_COMMAND(moveToEndOfDocumentAndModifySelection)
245 WEBCORE_COMMAND(moveToEndOfLine)
246 WEBCORE_COMMAND(moveToEndOfLineAndModifySelection)
247 WEBCORE_COMMAND(moveToEndOfParagraph)
248 WEBCORE_COMMAND(moveToEndOfParagraphAndModifySelection)
249 WEBCORE_COMMAND(moveToEndOfSentence)
250 WEBCORE_COMMAND(moveToEndOfSentenceAndModifySelection)
251 WEBCORE_COMMAND(moveToLeftEndOfLine)
252 WEBCORE_COMMAND(moveToLeftEndOfLineAndModifySelection)
253 WEBCORE_COMMAND(moveToRightEndOfLine)
254 WEBCORE_COMMAND(moveToRightEndOfLineAndModifySelection)
255 WEBCORE_COMMAND(moveUp)
256 WEBCORE_COMMAND(moveUpAndModifySelection)
257 WEBCORE_COMMAND(moveWordBackward)
258 WEBCORE_COMMAND(moveWordBackwardAndModifySelection)
259 WEBCORE_COMMAND(moveWordForward)
260 WEBCORE_COMMAND(moveWordForwardAndModifySelection)
261 WEBCORE_COMMAND(moveWordLeft)
262 WEBCORE_COMMAND(moveWordLeftAndModifySelection)
263 WEBCORE_COMMAND(moveWordRight)
264 WEBCORE_COMMAND(moveWordRightAndModifySelection)
265 WEBCORE_COMMAND(outdent)
266 WEBCORE_COMMAND(pageDown)
267 WEBCORE_COMMAND(pageDownAndModifySelection)
268 WEBCORE_COMMAND(pageUp)
269 WEBCORE_COMMAND(pageUpAndModifySelection)
270 WEBCORE_COMMAND(paste)
271 WEBCORE_COMMAND(pasteAsPlainText)
272 WEBCORE_COMMAND(scrollPageDown)
273 WEBCORE_COMMAND(scrollPageUp)
274 WEBCORE_COMMAND(scrollLineDown)
275 WEBCORE_COMMAND(scrollLineUp)
276 WEBCORE_COMMAND(scrollToBeginningOfDocument)
277 WEBCORE_COMMAND(scrollToEndOfDocument)
278 WEBCORE_COMMAND(selectAll)
279 WEBCORE_COMMAND(selectLine)
280 WEBCORE_COMMAND(selectParagraph)
281 WEBCORE_COMMAND(selectSentence)
282 WEBCORE_COMMAND(selectToMark)
283 WEBCORE_COMMAND(selectWord)
284 WEBCORE_COMMAND(setMark)
285 WEBCORE_COMMAND(subscript)
286 WEBCORE_COMMAND(superscript)
287 WEBCORE_COMMAND(swapWithMark)
288 WEBCORE_COMMAND(takeFindStringFromSelection)
289 WEBCORE_COMMAND(transpose)
290 WEBCORE_COMMAND(underline)
291 WEBCORE_COMMAND(unscript)
292 WEBCORE_COMMAND(yank)
293 WEBCORE_COMMAND(yankAndSelect)
294
295 #undef WEBCORE_COMMAND
296
297 - (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pasteboard types:(NSArray *)types
298 {
299     return _data->_impl->writeSelectionToPasteboard(pasteboard, types);
300 }
301
302 - (void)centerSelectionInVisibleArea:(id)sender 
303
304     _data->_impl->centerSelectionInVisibleArea();
305 }
306
307 - (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType
308 {
309     return _data->_impl->validRequestorForSendAndReturnTypes(sendType, returnType);
310 }
311
312 - (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pasteboard 
313 {
314     return _data->_impl->readSelectionFromPasteboard(pasteboard);
315 }
316
317 - (void)changeFont:(id)sender
318 {
319     _data->_impl->changeFontFromFontManager();
320 }
321
322 /*
323
324 When possible, editing-related methods should be implemented in WebCore with the
325 EditorCommand mechanism and invoked via WEBCORE_COMMAND, rather than implementing
326 individual methods here with Mac-specific code.
327
328 Editing-related methods still unimplemented that are implemented in WebKit1:
329
330 - (void)complete:(id)sender;
331 - (void)copyFont:(id)sender;
332 - (void)makeBaseWritingDirectionLeftToRight:(id)sender;
333 - (void)makeBaseWritingDirectionNatural:(id)sender;
334 - (void)makeBaseWritingDirectionRightToLeft:(id)sender;
335 - (void)pasteFont:(id)sender;
336 - (void)scrollLineDown:(id)sender;
337 - (void)scrollLineUp:(id)sender;
338 - (void)showGuessPanel:(id)sender;
339
340 Some other editing-related methods still unimplemented:
341
342 - (void)changeCaseOfLetter:(id)sender;
343 - (void)copyRuler:(id)sender;
344 - (void)insertContainerBreak:(id)sender;
345 - (void)insertDoubleQuoteIgnoringSubstitution:(id)sender;
346 - (void)insertSingleQuoteIgnoringSubstitution:(id)sender;
347 - (void)pasteRuler:(id)sender;
348 - (void)toggleRuler:(id)sender;
349 - (void)transposeWords:(id)sender;
350
351 */
352
353 - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item
354 {
355     return _data->_impl->validateUserInterfaceItem(item);
356 }
357
358 - (IBAction)startSpeaking:(id)sender
359 {
360     _data->_impl->startSpeaking();
361 }
362
363 - (IBAction)stopSpeaking:(id)sender
364 {
365     _data->_impl->stopSpeaking(sender);
366 }
367
368 - (IBAction)showGuessPanel:(id)sender
369 {
370     _data->_impl->showGuessPanel(sender);
371 }
372
373 - (IBAction)checkSpelling:(id)sender
374 {
375     _data->_impl->checkSpelling();
376 }
377
378 - (void)changeSpelling:(id)sender
379 {
380     _data->_impl->changeSpelling(sender);
381 }
382
383 - (IBAction)toggleContinuousSpellChecking:(id)sender
384 {
385     _data->_impl->toggleContinuousSpellChecking();
386 }
387
388 - (BOOL)isGrammarCheckingEnabled
389 {
390     return _data->_impl->isGrammarCheckingEnabled();
391 }
392
393 - (void)setGrammarCheckingEnabled:(BOOL)flag
394 {
395     _data->_impl->setGrammarCheckingEnabled(flag);
396 }
397
398 - (IBAction)toggleGrammarChecking:(id)sender
399 {
400     _data->_impl->toggleGrammarChecking();
401 }
402
403 - (IBAction)toggleAutomaticSpellingCorrection:(id)sender
404 {
405     _data->_impl->toggleAutomaticSpellingCorrection();
406 }
407
408 - (void)orderFrontSubstitutionsPanel:(id)sender
409 {
410     _data->_impl->orderFrontSubstitutionsPanel(sender);
411 }
412
413 - (IBAction)toggleSmartInsertDelete:(id)sender
414 {
415     _data->_impl->toggleSmartInsertDelete();
416 }
417
418 - (BOOL)isAutomaticQuoteSubstitutionEnabled
419 {
420     return _data->_impl->isAutomaticQuoteSubstitutionEnabled();
421 }
422
423 - (void)setAutomaticQuoteSubstitutionEnabled:(BOOL)flag
424 {
425     _data->_impl->setAutomaticQuoteSubstitutionEnabled(flag);
426 }
427
428 - (void)toggleAutomaticQuoteSubstitution:(id)sender
429 {
430     _data->_impl->toggleAutomaticQuoteSubstitution();
431 }
432
433 - (BOOL)isAutomaticDashSubstitutionEnabled
434 {
435     return _data->_impl->isAutomaticDashSubstitutionEnabled();
436 }
437
438 - (void)setAutomaticDashSubstitutionEnabled:(BOOL)flag
439 {
440     _data->_impl->setAutomaticDashSubstitutionEnabled(flag);
441 }
442
443 - (void)toggleAutomaticDashSubstitution:(id)sender
444 {
445     _data->_impl->toggleAutomaticDashSubstitution();
446 }
447
448 - (BOOL)isAutomaticLinkDetectionEnabled
449 {
450     return _data->_impl->isAutomaticLinkDetectionEnabled();
451 }
452
453 - (void)setAutomaticLinkDetectionEnabled:(BOOL)flag
454 {
455     _data->_impl->setAutomaticLinkDetectionEnabled(flag);
456 }
457
458 - (void)toggleAutomaticLinkDetection:(id)sender
459 {
460     _data->_impl->toggleAutomaticLinkDetection();
461 }
462
463 - (BOOL)isAutomaticTextReplacementEnabled
464 {
465     return _data->_impl->isAutomaticTextReplacementEnabled();
466 }
467
468 - (void)setAutomaticTextReplacementEnabled:(BOOL)flag
469 {
470     _data->_impl->setAutomaticTextReplacementEnabled(flag);
471 }
472
473 - (void)toggleAutomaticTextReplacement:(id)sender
474 {
475     _data->_impl->toggleAutomaticTextReplacement();
476 }
477
478 - (void)uppercaseWord:(id)sender
479 {
480     _data->_impl->uppercaseWord();
481 }
482
483 - (void)lowercaseWord:(id)sender
484 {
485     _data->_impl->lowercaseWord();
486 }
487
488 - (void)capitalizeWord:(id)sender
489 {
490     _data->_impl->capitalizeWord();
491 }
492
493 - (BOOL)_wantsKeyDownForEvent:(NSEvent *)event
494 {
495     return _data->_impl->wantsKeyDownForEvent(event);
496 }
497
498 - (void)scrollWheel:(NSEvent *)event
499 {
500     _data->_impl->scrollWheel(event);
501 }
502
503 - (void)swipeWithEvent:(NSEvent *)event
504 {
505     _data->_impl->swipeWithEvent(event);
506 }
507
508 - (void)mouseMoved:(NSEvent *)event
509 {
510     _data->_impl->mouseMoved(event);
511 }
512
513 - (void)mouseDown:(NSEvent *)event
514 {
515     _data->_impl->mouseDown(event);
516 }
517
518 - (void)mouseUp:(NSEvent *)event
519 {
520     _data->_impl->mouseUp(event);
521 }
522
523 - (void)mouseDragged:(NSEvent *)event
524 {
525     _data->_impl->mouseDragged(event);
526 }
527
528 - (void)mouseEntered:(NSEvent *)event
529 {
530     _data->_impl->mouseEntered(event);
531 }
532
533 - (void)mouseExited:(NSEvent *)event
534 {
535     _data->_impl->mouseExited(event);
536 }
537
538 - (void)otherMouseDown:(NSEvent *)event
539 {
540     _data->_impl->otherMouseDown(event);
541 }
542
543 - (void)otherMouseDragged:(NSEvent *)event
544 {
545     _data->_impl->otherMouseDragged(event);
546 }
547
548 - (void)otherMouseUp:(NSEvent *)event
549 {
550     _data->_impl->otherMouseUp(event);
551 }
552
553 - (void)rightMouseDown:(NSEvent *)event
554 {
555     _data->_impl->rightMouseDown(event);
556 }
557
558 - (void)rightMouseDragged:(NSEvent *)event
559 {
560     _data->_impl->rightMouseDragged(event);
561 }
562
563 - (void)rightMouseUp:(NSEvent *)event
564 {
565     _data->_impl->rightMouseUp(event);
566 }
567
568 - (void)pressureChangeWithEvent:(NSEvent *)event
569 {
570     _data->_impl->pressureChangeWithEvent(event);
571 }
572
573 - (BOOL)acceptsFirstMouse:(NSEvent *)event
574 {
575     return _data->_impl->acceptsFirstMouse(event);
576 }
577
578 - (BOOL)shouldDelayWindowOrderingForEvent:(NSEvent *)event
579 {
580     return _data->_impl->shouldDelayWindowOrderingForEvent(event);
581 }
582
583 - (void)doCommandBySelector:(SEL)selector
584 {
585     _data->_impl->doCommandBySelector(selector);
586 }
587
588 - (void)insertText:(id)string
589 {
590     _data->_impl->insertText(string);
591 }
592
593 - (void)insertText:(id)string replacementRange:(NSRange)replacementRange
594 {
595     _data->_impl->insertText(string, replacementRange);
596 }
597
598 - (NSTextInputContext *)inputContext
599 {
600     return _data->_impl->inputContext();
601 }
602
603 - (BOOL)performKeyEquivalent:(NSEvent *)event
604 {
605     return _data->_impl->performKeyEquivalent(event);
606 }
607
608 - (void)keyUp:(NSEvent *)theEvent
609 {
610     _data->_impl->keyUp(theEvent);
611 }
612
613 - (void)keyDown:(NSEvent *)theEvent
614 {
615     _data->_impl->keyDown(theEvent);
616 }
617
618 - (void)flagsChanged:(NSEvent *)theEvent
619 {
620     _data->_impl->flagsChanged(theEvent);
621 }
622
623 - (void)setMarkedText:(id)string selectedRange:(NSRange)newSelectedRange replacementRange:(NSRange)replacementRange
624 {
625     _data->_impl->setMarkedText(string, newSelectedRange, replacementRange);
626 }
627
628 - (void)unmarkText
629 {
630     _data->_impl->unmarkText();
631 }
632
633 - (NSRange)selectedRange
634 {
635     return _data->_impl->selectedRange();
636 }
637
638 - (BOOL)hasMarkedText
639 {
640     return _data->_impl->hasMarkedText();
641 }
642
643 - (NSRange)markedRange
644 {
645     return _data->_impl->markedRange();
646 }
647
648 - (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)nsRange actualRange:(NSRangePointer)actualRange
649 {
650     return _data->_impl->attributedSubstringForProposedRange(nsRange, actualRange);
651 }
652
653 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint
654 {
655     return _data->_impl->characterIndexForPoint(thePoint);
656 }
657
658 - (NSRect)firstRectForCharacterRange:(NSRange)theRange actualRange:(NSRangePointer)actualRange
659 {
660     return _data->_impl->firstRectForCharacterRange(theRange, actualRange);
661 }
662
663 - (void)selectedRangeWithCompletionHandler:(void(^)(NSRange selectedRange))completionHandlerPtr
664 {
665     _data->_impl->selectedRangeWithCompletionHandler(completionHandlerPtr);
666 }
667
668 - (void)markedRangeWithCompletionHandler:(void(^)(NSRange markedRange))completionHandlerPtr
669 {
670     _data->_impl->markedRangeWithCompletionHandler(completionHandlerPtr);
671 }
672
673 - (void)hasMarkedTextWithCompletionHandler:(void(^)(BOOL hasMarkedText))completionHandlerPtr
674 {
675     _data->_impl->hasMarkedTextWithCompletionHandler(completionHandlerPtr);
676 }
677
678 - (void)attributedSubstringForProposedRange:(NSRange)nsRange completionHandler:(void(^)(NSAttributedString *attrString, NSRange actualRange))completionHandlerPtr
679 {
680     _data->_impl->attributedSubstringForProposedRange(nsRange, completionHandlerPtr);
681 }
682
683 - (void)firstRectForCharacterRange:(NSRange)theRange completionHandler:(void(^)(NSRect firstRect, NSRange actualRange))completionHandlerPtr
684 {
685     _data->_impl->firstRectForCharacterRange(theRange, completionHandlerPtr);
686 }
687
688 - (void)characterIndexForPoint:(NSPoint)thePoint completionHandler:(void(^)(NSUInteger))completionHandlerPtr
689 {
690     _data->_impl->characterIndexForPoint(thePoint, completionHandlerPtr);
691 }
692
693 - (NSArray *)validAttributesForMarkedText
694 {
695     return _data->_impl->validAttributesForMarkedText();
696 }
697
698 #if ENABLE(DRAG_SUPPORT)
699 - (void)draggedImage:(NSImage *)image endedAt:(NSPoint)endPoint operation:(NSDragOperation)operation
700 {
701     _data->_impl->draggedImage(image, NSPointToCGPoint(endPoint), operation);
702 }
703
704 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)draggingInfo
705 {
706     return _data->_impl->draggingEntered(draggingInfo);
707 }
708
709 - (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)draggingInfo
710 {
711     return _data->_impl->draggingUpdated(draggingInfo);
712 }
713
714 - (void)draggingExited:(id <NSDraggingInfo>)draggingInfo
715 {
716     _data->_impl->draggingExited(draggingInfo);
717 }
718
719 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)draggingInfo
720 {
721     return _data->_impl->prepareForDragOperation(draggingInfo);
722 }
723
724 - (BOOL)performDragOperation:(id <NSDraggingInfo>)draggingInfo
725 {
726     return _data->_impl->performDragOperation(draggingInfo);
727 }
728
729 - (NSView *)_hitTest:(NSPoint *)point dragTypes:(NSSet *)types
730 {
731     return _data->_impl->hitTestForDragTypes(NSPointToCGPoint(*point), types);
732 }
733 #endif // ENABLE(DRAG_SUPPORT)
734
735 - (BOOL)_windowResizeMouseLocationIsInVisibleScrollerThumb:(NSPoint)point
736 {
737     return _data->_impl->windowResizeMouseLocationIsInVisibleScrollerThumb(NSPointToCGPoint(point));
738 }
739
740 - (void)viewWillMoveToWindow:(NSWindow *)window
741 {
742     _data->_impl->viewWillMoveToWindow(window);
743 }
744
745 - (void)viewDidMoveToWindow
746 {
747     _data->_impl->viewDidMoveToWindow();
748 }
749
750 - (void)drawRect:(NSRect)rect
751 {
752     _data->_impl->drawRect(NSRectToCGRect(rect));
753 }
754
755 - (BOOL)isOpaque
756 {
757     return _data->_impl->isOpaque();
758 }
759
760 - (BOOL)mouseDownCanMoveWindow
761 {
762     return WebViewImpl::mouseDownCanMoveWindow();
763 }
764
765 - (void)viewDidHide
766 {
767     _data->_impl->viewDidHide();
768 }
769
770 - (void)viewDidUnhide
771 {
772     _data->_impl->viewDidUnhide();
773 }
774
775 - (void)viewDidChangeBackingProperties
776 {
777     _data->_impl->viewDidChangeBackingProperties();
778 }
779
780 - (void)_activeSpaceDidChange:(NSNotification *)notification
781 {
782     _data->_impl->activeSpaceDidChange();
783 }
784
785 - (id)accessibilityFocusedUIElement
786 {
787     return _data->_impl->accessibilityFocusedUIElement();
788 }
789
790 - (BOOL)accessibilityIsIgnored
791 {
792     return _data->_impl->accessibilityIsIgnored();
793 }
794
795 - (id)accessibilityHitTest:(NSPoint)point
796 {
797     return _data->_impl->accessibilityHitTest(NSPointToCGPoint(point));
798 }
799
800 - (id)accessibilityAttributeValue:(NSString *)attribute
801 {
802     return _data->_impl->accessibilityAttributeValue(attribute);
803 }
804
805 - (NSView *)hitTest:(NSPoint)point
806 {
807     if (!_data)
808         return [super hitTest:point];
809     return _data->_impl->hitTest(NSPointToCGPoint(point));
810 }
811
812 - (NSInteger)conversationIdentifier
813 {
814     return (NSInteger)self;
815 }
816
817 - (void)quickLookWithEvent:(NSEvent *)event
818 {
819     _data->_impl->quickLookWithEvent(event);
820 }
821
822 - (NSTrackingRectTag)addTrackingRect:(NSRect)rect owner:(id)owner userData:(void *)data assumeInside:(BOOL)assumeInside
823 {
824     return _data->_impl->addTrackingRect(NSRectToCGRect(rect), owner, data, assumeInside);
825 }
826
827 - (NSTrackingRectTag)_addTrackingRect:(NSRect)rect owner:(id)owner userData:(void *)data assumeInside:(BOOL)assumeInside useTrackingNum:(int)tag
828 {
829     return _data->_impl->addTrackingRectWithTrackingNum(NSRectToCGRect(rect), owner, data, assumeInside, tag);
830 }
831
832 - (void)_addTrackingRects:(NSRect *)rects owner:(id)owner userDataList:(void **)userDataList assumeInsideList:(BOOL *)assumeInsideList trackingNums:(NSTrackingRectTag *)trackingNums count:(int)count
833 {
834     CGRect *cgRects = (CGRect *)calloc(1, sizeof(CGRect));
835     for (int i = 0; i < count; i++)
836         cgRects[i] = NSRectToCGRect(rects[i]);
837     _data->_impl->addTrackingRectsWithTrackingNums(cgRects, owner, userDataList, assumeInsideList, trackingNums, count);
838     free(cgRects);
839 }
840
841 - (void)removeTrackingRect:(NSTrackingRectTag)tag
842 {
843     if (!_data)
844         return;
845     _data->_impl->removeTrackingRect(tag);
846 }
847
848 - (void)_removeTrackingRects:(NSTrackingRectTag *)tags count:(int)count
849 {
850     if (!_data)
851         return;
852     _data->_impl->removeTrackingRects(tags, count);
853 }
854
855 - (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag point:(NSPoint)point userData:(void *)data
856 {
857     return _data->_impl->stringForToolTip(tag);
858 }
859
860 - (void)pasteboardChangedOwner:(NSPasteboard *)pasteboard
861 {
862     _data->_impl->pasteboardChangedOwner(pasteboard);
863 }
864
865 - (void)pasteboard:(NSPasteboard *)pasteboard provideDataForType:(NSString *)type
866 {
867     _data->_impl->provideDataForPasteboard(pasteboard, type);
868 }
869
870 - (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
871 {
872     return _data->_impl->namesOfPromisedFilesDroppedAtDestination(dropDestination);
873 }
874
875 - (void)maybeInstallIconLoadingClient
876 {
877 #if WK_API_ENABLED
878     class IconLoadingClient : public API::IconLoadingClient {
879     public:
880         explicit IconLoadingClient(WKView *wkView)
881             : m_wkView(wkView)
882         {
883         }
884
885         static SEL delegateSelector()
886         {
887             return @selector(_shouldLoadIconWithParameters:completionHandler:);
888         }
889
890     private:
891         typedef void (^IconLoadCompletionHandler)(NSData*);
892
893         void getLoadDecisionForIcon(const WebCore::LinkIcon& linkIcon, WTF::CompletionHandler<void(WTF::Function<void(API::Data*, WebKit::CallbackBase::Error)>&&)>&& completionHandler) override
894         {
895             RetainPtr<_WKLinkIconParameters> parameters = adoptNS([[_WKLinkIconParameters alloc] _initWithLinkIcon:linkIcon]);
896
897             [m_wkView _shouldLoadIconWithParameters:parameters.get() completionHandler:BlockPtr<void(IconLoadCompletionHandler)>::fromCallable([completionHandler = WTFMove(completionHandler)](IconLoadCompletionHandler loadCompletionHandler) mutable {
898                 ASSERT(RunLoop::isMain());
899                 if (loadCompletionHandler) {
900                     completionHandler([loadCompletionHandler = BlockPtr<void (NSData *)>(loadCompletionHandler)](API::Data* data, WebKit::CallbackBase::Error error) {
901                         if (error != CallbackBase::Error::None || !data)
902                             loadCompletionHandler(nil);
903                         else
904                             loadCompletionHandler(wrapper(*data));
905                     });
906                 } else
907                     completionHandler(nullptr);
908             }).get()];
909         }
910
911         WKView *m_wkView;
912     };
913
914     if ([self respondsToSelector:IconLoadingClient::delegateSelector()])
915         _data->_impl->page().setIconLoadingClient(std::make_unique<IconLoadingClient>(self));
916 #endif // WK_API_ENABLED
917 }
918
919 - (instancetype)initWithFrame:(NSRect)frame processPool:(WebProcessPool&)processPool configuration:(Ref<API::PageConfiguration>&&)configuration
920 {
921     self = [super initWithFrame:frame];
922     if (!self)
923         return nil;
924
925     InitializeWebKit2();
926
927     _data = [[WKViewData alloc] init];
928     _data->_impl = std::make_unique<WebViewImpl>(self, nullptr, processPool, WTFMove(configuration));
929
930     [self maybeInstallIconLoadingClient];
931
932     return self;
933 }
934
935 #if WK_API_ENABLED
936 - (void)_setThumbnailView:(_WKThumbnailView *)thumbnailView
937 {
938     _data->_impl->setThumbnailView(thumbnailView);
939 }
940
941 - (_WKThumbnailView *)_thumbnailView
942 {
943     if (!_data->_impl)
944         return nil;
945     return _data->_impl->thumbnailView();
946 }
947 #endif // WK_API_ENABLED
948
949 - (NSTextInputContext *)_web_superInputContext
950 {
951     return [super inputContext];
952 }
953
954 - (void)_web_superQuickLookWithEvent:(NSEvent *)event
955 {
956     [super quickLookWithEvent:event];
957 }
958
959 - (void)_web_superSwipeWithEvent:(NSEvent *)event
960 {
961     [super swipeWithEvent:event];
962 }
963
964 - (void)_web_superMagnifyWithEvent:(NSEvent *)event
965 {
966     [super magnifyWithEvent:event];
967 }
968
969 - (void)_web_superSmartMagnifyWithEvent:(NSEvent *)event
970 {
971     [super smartMagnifyWithEvent:event];
972 }
973
974 - (void)_web_superRemoveTrackingRect:(NSTrackingRectTag)tag
975 {
976     [super removeTrackingRect:tag];
977 }
978
979 - (id)_web_superAccessibilityAttributeValue:(NSString *)attribute
980 {
981 #pragma clang diagnostic push
982 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
983     return [super accessibilityAttributeValue:attribute];
984 #pragma clang diagnostic pop
985 }
986
987 - (void)_web_superDoCommandBySelector:(SEL)selector
988 {
989     [super doCommandBySelector:selector];
990 }
991
992 - (BOOL)_web_superPerformKeyEquivalent:(NSEvent *)event
993 {
994     return [super performKeyEquivalent:event];
995 }
996
997 - (void)_web_superKeyDown:(NSEvent *)event
998 {
999     [super keyDown:event];
1000 }
1001
1002 - (NSView *)_web_superHitTest:(NSPoint)point
1003 {
1004     return [super hitTest:point];
1005 }
1006
1007 - (id)_web_immediateActionAnimationControllerForHitTestResultInternal:(API::HitTestResult*)hitTestResult withType:(uint32_t)type userData:(API::Object*)userData
1008 {
1009     return [self _immediateActionAnimationControllerForHitTestResult:toAPI(hitTestResult) withType:type userData:toAPI(userData)];
1010 }
1011
1012 - (void)_web_prepareForImmediateActionAnimation
1013 {
1014     [self _prepareForImmediateActionAnimation];
1015 }
1016
1017 - (void)_web_cancelImmediateActionAnimation
1018 {
1019     [self _cancelImmediateActionAnimation];
1020 }
1021
1022 - (void)_web_completeImmediateActionAnimation
1023 {
1024     [self _completeImmediateActionAnimation];
1025 }
1026
1027 - (void)_web_didChangeContentSize:(NSSize)newSize
1028 {
1029     [self _didChangeContentSize:newSize];
1030 }
1031
1032 #if ENABLE(DRAG_SUPPORT) && WK_API_ENABLED
1033
1034 - (void)_web_didPerformDragOperation:(BOOL)handled
1035 {
1036     UNUSED_PARAM(handled);
1037 }
1038
1039 - (WKDragDestinationAction)_web_dragDestinationActionForDraggingInfo:(id <NSDraggingInfo>)draggingInfo
1040 {
1041     return WKDragDestinationActionAny;
1042 }
1043
1044 #endif
1045
1046 - (void)_web_dismissContentRelativeChildWindows
1047 {
1048     [self _dismissContentRelativeChildWindows];
1049 }
1050
1051 - (void)_web_dismissContentRelativeChildWindowsWithAnimation:(BOOL)withAnimation
1052 {
1053     [self _dismissContentRelativeChildWindowsWithAnimation:withAnimation];
1054 }
1055
1056 - (void)_web_editorStateDidChange
1057 {
1058 }
1059
1060 - (void)_web_gestureEventWasNotHandledByWebCore:(NSEvent *)event
1061 {
1062     [self _gestureEventWasNotHandledByWebCore:event];
1063 }
1064
1065 - (void)_didHandleAcceptedCandidate
1066 {
1067 }
1068
1069 - (void)_didUpdateCandidateListVisibility:(BOOL)visible
1070 {
1071 }
1072
1073 #if HAVE(TOUCH_BAR)
1074
1075 @dynamic touchBar;
1076
1077 - (NSTouchBar *)makeTouchBar
1078 {
1079     return _data->_impl->makeTouchBar();
1080 }
1081
1082 - (NSCandidateListTouchBarItem *)candidateListTouchBarItem
1083 {
1084     return _data->_impl->candidateListTouchBarItem();
1085 }
1086
1087 - (void)_web_didAddMediaControlsManager:(id)controlsManager
1088 {
1089     [self _addMediaPlaybackControlsView:controlsManager];
1090 }
1091
1092 - (void)_web_didRemoveMediaControlsManager
1093 {
1094     [self _removeMediaPlaybackControlsView];
1095 }
1096
1097 #endif // HAVE(TOUCH_BAR)
1098
1099 #if ENABLE(DRAG_SUPPORT)
1100
1101 - (NSString *)filePromiseProvider:(NSFilePromiseProvider *)filePromiseProvider fileNameForType:(NSString *)fileType
1102 {
1103     return _data->_impl->fileNameForFilePromiseProvider(filePromiseProvider, fileType);
1104 }
1105
1106 - (void)filePromiseProvider:(NSFilePromiseProvider *)filePromiseProvider writePromiseToURL:(NSURL *)url completionHandler:(void (^)(NSError *error))completionHandler
1107 {
1108     _data->_impl->writeToURLForFilePromiseProvider(filePromiseProvider, url, completionHandler);
1109 }
1110
1111 - (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context
1112 {
1113     return _data->_impl->dragSourceOperationMask(session, context);
1114 }
1115
1116 - (void)draggingSession:(NSDraggingSession *)session endedAtPoint:(NSPoint)screenPoint operation:(NSDragOperation)operation
1117 {
1118     _data->_impl->draggingSessionEnded(session, screenPoint, operation);
1119 }
1120
1121 #endif // ENABLE(DRAG_SUPPORT)
1122
1123 @end
1124
1125 @implementation WKView (Private)
1126
1127 - (void)saveBackForwardSnapshotForCurrentItem
1128 {
1129     _data->_impl->saveBackForwardSnapshotForCurrentItem();
1130 }
1131
1132 - (void)saveBackForwardSnapshotForItem:(WKBackForwardListItemRef)item
1133 {
1134     _data->_impl->saveBackForwardSnapshotForItem(*toImpl(item));
1135 }
1136
1137 - (id)initWithFrame:(NSRect)frame contextRef:(WKContextRef)contextRef pageGroupRef:(WKPageGroupRef)pageGroupRef
1138 {
1139     return [self initWithFrame:frame contextRef:contextRef pageGroupRef:pageGroupRef relatedToPage:nil];
1140 }
1141
1142 #if PLATFORM(MAC)
1143 static WebCore::UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(NSUserInterfaceLayoutDirection direction)
1144 {
1145     switch (direction) {
1146     case NSUserInterfaceLayoutDirectionLeftToRight:
1147         return WebCore::UserInterfaceLayoutDirection::LTR;
1148     case NSUserInterfaceLayoutDirectionRightToLeft:
1149         return WebCore::UserInterfaceLayoutDirection::RTL;
1150     }
1151     return WebCore::UserInterfaceLayoutDirection::LTR;
1152 }
1153 #endif
1154
1155 - (id)initWithFrame:(NSRect)frame contextRef:(WKContextRef)contextRef pageGroupRef:(WKPageGroupRef)pageGroupRef relatedToPage:(WKPageRef)relatedPage
1156 {
1157     auto configuration = API::PageConfiguration::create();
1158     configuration->setProcessPool(toImpl(contextRef));
1159     configuration->setPageGroup(toImpl(pageGroupRef));
1160     configuration->setRelatedPage(toImpl(relatedPage));
1161 #if PLATFORM(MAC)
1162     configuration->preferenceValues().set(WebKit::WebPreferencesKey::systemLayoutDirectionKey(), WebKit::WebPreferencesStore::Value(static_cast<uint32_t>(toUserInterfaceLayoutDirection(self.userInterfaceLayoutDirection))));
1163 #endif
1164
1165     return [self initWithFrame:frame processPool:*toImpl(contextRef) configuration:WTFMove(configuration)];
1166 }
1167
1168 - (id)initWithFrame:(NSRect)frame configurationRef:(WKPageConfigurationRef)configurationRef
1169 {
1170     Ref<API::PageConfiguration> configuration = toImpl(configurationRef)->copy();
1171     auto& processPool = *configuration->processPool();
1172
1173     return [self initWithFrame:frame processPool:processPool configuration:WTFMove(configuration)];
1174 }
1175
1176 - (BOOL)wantsUpdateLayer
1177 {
1178     return WebViewImpl::wantsUpdateLayer();
1179 }
1180
1181 - (void)updateLayer
1182 {
1183     _data->_impl->updateLayer();
1184 }
1185
1186 - (WKPageRef)pageRef
1187 {
1188     return toAPI(&_data->_impl->page());
1189 }
1190
1191 - (BOOL)canChangeFrameLayout:(WKFrameRef)frameRef
1192 {
1193     return _data->_impl->canChangeFrameLayout(*toImpl(frameRef));
1194 }
1195
1196 - (NSPrintOperation *)printOperationWithPrintInfo:(NSPrintInfo *)printInfo forFrame:(WKFrameRef)frameRef
1197 {
1198     return _data->_impl->printOperationWithPrintInfo(printInfo, *toImpl(frameRef));
1199 }
1200
1201 - (void)setFrame:(NSRect)rect andScrollBy:(NSSize)offset
1202 {
1203     _data->_impl->setFrameAndScrollBy(NSRectToCGRect(rect), NSSizeToCGSize(offset));
1204 }
1205
1206 - (void)disableFrameSizeUpdates
1207 {
1208     _data->_impl->disableFrameSizeUpdates();
1209 }
1210
1211 - (void)enableFrameSizeUpdates
1212 {
1213     _data->_impl->enableFrameSizeUpdates();
1214 }
1215
1216 - (BOOL)frameSizeUpdatesDisabled
1217 {
1218     return _data->_impl->frameSizeUpdatesDisabled();
1219 }
1220
1221 + (void)hideWordDefinitionWindow
1222 {
1223     WebViewImpl::hideWordDefinitionWindow();
1224 }
1225
1226 - (NSSize)minimumSizeForAutoLayout
1227 {
1228     return NSSizeFromCGSize(_data->_impl->minimumSizeForAutoLayout());
1229 }
1230
1231 - (void)setMinimumSizeForAutoLayout:(NSSize)minimumSizeForAutoLayout
1232 {
1233     _data->_impl->setMinimumSizeForAutoLayout(NSSizeToCGSize(minimumSizeForAutoLayout));
1234 }
1235
1236 - (BOOL)shouldExpandToViewHeightForAutoLayout
1237 {
1238     return _data->_impl->shouldExpandToViewHeightForAutoLayout();
1239 }
1240
1241 - (void)setShouldExpandToViewHeightForAutoLayout:(BOOL)shouldExpand
1242 {
1243     return _data->_impl->setShouldExpandToViewHeightForAutoLayout(shouldExpand);
1244 }
1245
1246 - (BOOL)shouldClipToVisibleRect
1247 {
1248     return _data->_impl->clipsToVisibleRect();
1249 }
1250
1251 - (void)setShouldClipToVisibleRect:(BOOL)clipsToVisibleRect
1252 {
1253     _data->_impl->setClipsToVisibleRect(clipsToVisibleRect);
1254 }
1255
1256 - (NSColor *)underlayColor
1257 {
1258     return _data->_impl->underlayColor();
1259 }
1260
1261 - (void)setUnderlayColor:(NSColor *)underlayColor
1262 {
1263     _data->_impl->setUnderlayColor(underlayColor);
1264 }
1265
1266 #if WK_API_ENABLED
1267 - (NSView *)_inspectorAttachmentView
1268 {
1269     return _data->_impl->inspectorAttachmentView();
1270 }
1271
1272 - (void)_setInspectorAttachmentView:(NSView *)newView
1273 {
1274     _data->_impl->setInspectorAttachmentView(newView);
1275 }
1276 #endif
1277
1278 - (BOOL)_requiresUserActionForEditingControlsManager
1279 {
1280     return _data->_impl->requiresUserActionForEditingControlsManager();
1281 }
1282
1283 - (void)_setRequiresUserActionForEditingControlsManager:(BOOL)requiresUserAction
1284 {
1285     _data->_impl->setRequiresUserActionForEditingControlsManager(requiresUserAction);
1286 }
1287
1288 - (NSView *)fullScreenPlaceholderView
1289 {
1290     return _data->_impl->fullScreenPlaceholderView();
1291 }
1292
1293 // FIXME: This returns an autoreleased object. Should it really be prefixed 'create'?
1294 - (NSWindow *)createFullScreenWindow
1295 {
1296     return _data->_impl->fullScreenWindow();
1297 }
1298
1299 - (void)beginDeferringViewInWindowChanges
1300 {
1301     _data->_impl->beginDeferringViewInWindowChanges();
1302 }
1303
1304 - (void)endDeferringViewInWindowChanges
1305 {
1306     _data->_impl->endDeferringViewInWindowChanges();
1307 }
1308
1309 - (void)endDeferringViewInWindowChangesSync
1310 {
1311     _data->_impl->endDeferringViewInWindowChangesSync();
1312 }
1313
1314 - (void)_prepareForMoveToWindow:(NSWindow *)targetWindow withCompletionHandler:(void(^)(void))completionHandler
1315 {
1316     auto completionHandlerCopy = makeBlockPtr(completionHandler);
1317     _data->_impl->prepareForMoveToWindow(targetWindow, [completionHandlerCopy] {
1318         completionHandlerCopy();
1319     });
1320 }
1321
1322 - (BOOL)isDeferringViewInWindowChanges
1323 {
1324     return _data->_impl->isDeferringViewInWindowChanges();
1325 }
1326
1327 - (BOOL)windowOcclusionDetectionEnabled
1328 {
1329     return _data->_impl->windowOcclusionDetectionEnabled();
1330 }
1331
1332 - (void)setWindowOcclusionDetectionEnabled:(BOOL)enabled
1333 {
1334     _data->_impl->setWindowOcclusionDetectionEnabled(enabled);
1335 }
1336
1337 - (void)setAllowsBackForwardNavigationGestures:(BOOL)allowsBackForwardNavigationGestures
1338 {
1339     _data->_impl->setAllowsBackForwardNavigationGestures(allowsBackForwardNavigationGestures);
1340 }
1341
1342 - (BOOL)allowsBackForwardNavigationGestures
1343 {
1344     return _data->_impl->allowsBackForwardNavigationGestures();
1345 }
1346
1347 - (BOOL)allowsLinkPreview
1348 {
1349     return _data->_impl->allowsLinkPreview();
1350 }
1351
1352 - (void)setAllowsLinkPreview:(BOOL)allowsLinkPreview
1353 {
1354     _data->_impl->setAllowsLinkPreview(allowsLinkPreview);
1355 }
1356
1357 - (void)_setIgnoresAllEvents:(BOOL)ignoresAllEvents
1358 {
1359     _data->_impl->setIgnoresAllEvents(ignoresAllEvents);
1360 }
1361
1362 // Forward _setIgnoresNonWheelMouseEvents to _setIgnoresNonWheelEvents to avoid breaking existing clients.
1363 - (void)_setIgnoresNonWheelMouseEvents:(BOOL)ignoresNonWheelMouseEvents
1364 {
1365     _data->_impl->setIgnoresNonWheelEvents(ignoresNonWheelMouseEvents);
1366 }
1367
1368 - (void)_setIgnoresNonWheelEvents:(BOOL)ignoresNonWheelEvents
1369 {
1370     _data->_impl->setIgnoresNonWheelEvents(ignoresNonWheelEvents);
1371 }
1372
1373 - (BOOL)_ignoresNonWheelEvents
1374 {
1375     return _data->_impl->ignoresNonWheelEvents();
1376 }
1377
1378 - (BOOL)_ignoresAllEvents
1379 {
1380     return _data->_impl->ignoresAllEvents();
1381 }
1382
1383 - (void)_setOverrideDeviceScaleFactor:(CGFloat)deviceScaleFactor
1384 {
1385     _data->_impl->setOverrideDeviceScaleFactor(deviceScaleFactor);
1386 }
1387
1388 - (CGFloat)_overrideDeviceScaleFactor
1389 {
1390     return _data->_impl->overrideDeviceScaleFactor();
1391 }
1392
1393 - (WKLayoutMode)_layoutMode
1394 {
1395     return _data->_impl->layoutMode();
1396 }
1397
1398 - (void)_setLayoutMode:(WKLayoutMode)layoutMode
1399 {
1400     _data->_impl->setLayoutMode(layoutMode);
1401 }
1402
1403 - (CGSize)_fixedLayoutSize
1404 {
1405     return _data->_impl->fixedLayoutSize();
1406 }
1407
1408 - (void)_setFixedLayoutSize:(CGSize)fixedLayoutSize
1409 {
1410     _data->_impl->setFixedLayoutSize(fixedLayoutSize);
1411 }
1412
1413 - (CGFloat)_viewScale
1414 {
1415     return _data->_impl->viewScale();
1416 }
1417
1418 - (void)_setViewScale:(CGFloat)viewScale
1419 {
1420     _data->_impl->setViewScale(viewScale);
1421 }
1422
1423 - (void)_setTopContentInset:(CGFloat)contentInset
1424 {
1425     return _data->_impl->setTopContentInset(contentInset);
1426 }
1427
1428 - (CGFloat)_topContentInset
1429 {
1430     return _data->_impl->topContentInset();
1431 }
1432
1433 - (void)_setTotalHeightOfBanners:(CGFloat)totalHeightOfBanners
1434 {
1435     _data->_impl->setTotalHeightOfBanners(totalHeightOfBanners);
1436 }
1437
1438 - (CGFloat)_totalHeightOfBanners
1439 {
1440     return _data->_impl->totalHeightOfBanners();
1441 }
1442
1443 static std::optional<WebCore::ScrollbarOverlayStyle> toCoreScrollbarStyle(_WKOverlayScrollbarStyle scrollbarStyle)
1444 {
1445     switch (scrollbarStyle) {
1446     case _WKOverlayScrollbarStyleDark:
1447         return WebCore::ScrollbarOverlayStyleDark;
1448     case _WKOverlayScrollbarStyleLight:
1449         return WebCore::ScrollbarOverlayStyleLight;
1450     case _WKOverlayScrollbarStyleDefault:
1451         return WebCore::ScrollbarOverlayStyleDefault;
1452     case _WKOverlayScrollbarStyleAutomatic:
1453     default:
1454         break;
1455     }
1456
1457     return std::nullopt;
1458 }
1459
1460 static _WKOverlayScrollbarStyle toAPIScrollbarStyle(std::optional<WebCore::ScrollbarOverlayStyle> coreScrollbarStyle)
1461 {
1462     if (!coreScrollbarStyle)
1463         return _WKOverlayScrollbarStyleAutomatic;
1464
1465     switch (coreScrollbarStyle.value()) {
1466     case WebCore::ScrollbarOverlayStyleDark:
1467         return _WKOverlayScrollbarStyleDark;
1468     case WebCore::ScrollbarOverlayStyleLight:
1469         return _WKOverlayScrollbarStyleLight;
1470     case WebCore::ScrollbarOverlayStyleDefault:
1471         return _WKOverlayScrollbarStyleDefault;
1472     default:
1473         return _WKOverlayScrollbarStyleAutomatic;
1474     }
1475 }
1476
1477 - (void)_setOverlayScrollbarStyle:(_WKOverlayScrollbarStyle)scrollbarStyle
1478 {
1479     _data->_impl->setOverlayScrollbarStyle(toCoreScrollbarStyle(scrollbarStyle));
1480 }
1481
1482 - (_WKOverlayScrollbarStyle)_overlayScrollbarStyle
1483 {
1484     return toAPIScrollbarStyle(_data->_impl->overlayScrollbarStyle());
1485 }
1486
1487 - (NSColor *)_pageExtendedBackgroundColor
1488 {
1489     return _data->_impl->pageExtendedBackgroundColor();
1490 }
1491
1492 - (BOOL)isUsingUISideCompositing
1493 {
1494     return _data->_impl->isUsingUISideCompositing();
1495 }
1496
1497 - (void)setAllowsMagnification:(BOOL)allowsMagnification
1498 {
1499     _data->_impl->setAllowsMagnification(allowsMagnification);
1500 }
1501
1502 - (BOOL)allowsMagnification
1503 {
1504     return _data->_impl->allowsMagnification();
1505 }
1506
1507 - (void)magnifyWithEvent:(NSEvent *)event
1508 {
1509     _data->_impl->magnifyWithEvent(event);
1510 }
1511
1512 #if ENABLE(MAC_GESTURE_EVENTS)
1513 - (void)rotateWithEvent:(NSEvent *)event
1514 {
1515     _data->_impl->rotateWithEvent(event);
1516 }
1517 #endif
1518
1519 - (void)_gestureEventWasNotHandledByWebCore:(NSEvent *)event
1520 {
1521     _data->_impl->gestureEventWasNotHandledByWebCoreFromViewOnly(event);
1522 }
1523
1524 - (void)smartMagnifyWithEvent:(NSEvent *)event
1525 {
1526     _data->_impl->smartMagnifyWithEvent(event);
1527 }
1528
1529 - (void)setMagnification:(double)magnification centeredAtPoint:(NSPoint)point
1530 {
1531     _data->_impl->setMagnification(magnification, NSPointToCGPoint(point));
1532 }
1533
1534 - (void)setMagnification:(double)magnification
1535 {
1536     _data->_impl->setMagnification(magnification);
1537 }
1538
1539 - (double)magnification
1540 {
1541     return _data->_impl->magnification();
1542 }
1543
1544 - (void)_setCustomSwipeViews:(NSArray *)customSwipeViews
1545 {
1546     _data->_impl->setCustomSwipeViews(customSwipeViews);
1547 }
1548
1549 - (void)_setCustomSwipeViewsTopContentInset:(float)topContentInset
1550 {
1551     _data->_impl->setCustomSwipeViewsTopContentInset(topContentInset);
1552 }
1553
1554 - (BOOL)_tryToSwipeWithEvent:(NSEvent *)event ignoringPinnedState:(BOOL)ignoringPinnedState
1555 {
1556     return _data->_impl->tryToSwipeWithEvent(event, ignoringPinnedState);
1557 }
1558
1559 - (void)_setDidMoveSwipeSnapshotCallback:(void(^)(CGRect))callback
1560 {
1561     _data->_impl->setDidMoveSwipeSnapshotCallback(callback);
1562 }
1563
1564 - (id)_immediateActionAnimationControllerForHitTestResult:(WKHitTestResultRef)hitTestResult withType:(uint32_t)type userData:(WKTypeRef)userData
1565 {
1566     return nil;
1567 }
1568
1569 - (void)_prepareForImmediateActionAnimation
1570 {
1571 }
1572
1573 - (void)_cancelImmediateActionAnimation
1574 {
1575 }
1576
1577 - (void)_completeImmediateActionAnimation
1578 {
1579 }
1580
1581 - (void)_didChangeContentSize:(NSSize)newSize
1582 {
1583 }
1584
1585 - (void)_dismissContentRelativeChildWindows
1586 {
1587     _data->_impl->dismissContentRelativeChildWindowsFromViewOnly();
1588 }
1589
1590 - (void)_dismissContentRelativeChildWindowsWithAnimation:(BOOL)withAnimation
1591 {
1592     _data->_impl->dismissContentRelativeChildWindowsWithAnimationFromViewOnly(withAnimation);
1593 }
1594
1595 - (void)_setAutomaticallyAdjustsContentInsets:(BOOL)automaticallyAdjustsContentInsets
1596 {
1597     _data->_impl->setAutomaticallyAdjustsContentInsets(automaticallyAdjustsContentInsets);
1598 }
1599
1600 - (BOOL)_automaticallyAdjustsContentInsets
1601 {
1602     return _data->_impl->automaticallyAdjustsContentInsets();
1603 }
1604
1605 - (void)setUserInterfaceLayoutDirection:(NSUserInterfaceLayoutDirection)userInterfaceLayoutDirection
1606 {
1607     [super setUserInterfaceLayoutDirection:userInterfaceLayoutDirection];
1608
1609     _data->_impl->setUserInterfaceLayoutDirection(userInterfaceLayoutDirection);
1610 }
1611
1612 - (BOOL)_wantsMediaPlaybackControlsView
1613 {
1614 #if HAVE(TOUCH_BAR)
1615     return _data->_impl->clientWantsMediaPlaybackControlsView();
1616 #else
1617     return NO;
1618 #endif
1619 }
1620
1621 - (void)_setWantsMediaPlaybackControlsView:(BOOL)wantsMediaPlaybackControlsView
1622 {
1623 #if HAVE(TOUCH_BAR)
1624     _data->_impl->setClientWantsMediaPlaybackControlsView(wantsMediaPlaybackControlsView);
1625 #endif
1626 }
1627
1628 - (id)_mediaPlaybackControlsView
1629 {
1630 #if HAVE(TOUCH_BAR) && ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
1631     return _data->_impl->clientWantsMediaPlaybackControlsView() ? _data->_impl->mediaPlaybackControlsView() : nil;
1632 #else
1633     return nil;
1634 #endif
1635 }
1636
1637 // This method is for subclasses to override.
1638 - (void)_addMediaPlaybackControlsView:(id)mediaPlaybackControlsView
1639 {
1640 }
1641
1642 // This method is for subclasses to override.
1643 - (void)_removeMediaPlaybackControlsView
1644 {
1645 }
1646
1647 - (void)_doAfterNextPresentationUpdate:(void (^)(void))updateBlock
1648 {
1649     auto updateBlockCopy = makeBlockPtr(updateBlock);
1650     _data->_impl->page().callAfterNextPresentationUpdate([updateBlockCopy](WebKit::CallbackBase::Error error) {
1651         if (updateBlockCopy)
1652             updateBlockCopy();
1653     });
1654 }
1655
1656 - (void)_setShouldSuppressFirstResponderChanges:(BOOL)shouldSuppress
1657 {
1658     _data->_impl->setShouldSuppressFirstResponderChanges(shouldSuppress);
1659 }
1660
1661 - (void)viewDidChangeEffectiveAppearance
1662 {
1663     // This can be called during [super initWithCoder:] and [super initWithFrame:].
1664     // That is before _data or _impl is ready to be used, so check. <rdar://problem/39611236>
1665     if (!_data || !_data->_impl)
1666         return;
1667
1668     _data->_impl->effectiveAppearanceDidChange();
1669 }
1670
1671 - (void)_setUseSystemAppearance:(BOOL)useSystemAppearance
1672 {
1673     _data->_impl->setUseSystemAppearance(useSystemAppearance);
1674 }
1675
1676 - (BOOL)_useSystemAppearance
1677 {
1678     return _data->_impl->useSystemAppearance();
1679 }
1680
1681 @end
1682
1683 #endif // PLATFORM(MAC)