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