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