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