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