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