Use an enum for scrollbar style
[WebKit-https.git] / Source / WebKit2 / UIProcess / mac / PageClientImpl.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 "PageClientImpl.h"
28
29 #if PLATFORM(MAC)
30
31 #import "AttributedString.h"
32 #import "ColorSpaceData.h"
33 #import "DataReference.h"
34 #import "DictionaryPopupInfo.h"
35 #import "DownloadProxy.h"
36 #import "NativeWebKeyboardEvent.h"
37 #import "NativeWebWheelEvent.h"
38 #import "NavigationState.h"
39 #import "StringUtilities.h"
40 #import "ViewSnapshotStore.h"
41 #import "WKAPICast.h"
42 #import "WKFullScreenWindowController.h"
43 #import "WKStringCF.h"
44 #import "WKViewInternal.h"
45 #import "WKWebViewInternal.h"
46 #import "WebColorPickerMac.h"
47 #import "WebContextMenuProxyMac.h"
48 #import "WebEditCommandProxy.h"
49 #import "WebPopupMenuProxyMac.h"
50 #import "WindowServerConnection.h"
51 #import "_WKDownloadInternal.h"
52 #import "_WKThumbnailView.h"
53 #import <WebCore/AlternativeTextUIController.h>
54 #import <WebCore/BitmapImage.h>
55 #import <WebCore/Cursor.h>
56 #import <WebCore/FloatRect.h>
57 #import <WebCore/GraphicsContext.h>
58 #import <WebCore/Image.h>
59 #import <WebCore/KeyboardEvent.h>
60 #import <WebCore/LookupSPI.h>
61 #import <WebCore/NotImplemented.h>
62 #import <WebCore/SharedBuffer.h>
63 #import <WebCore/TextIndicator.h>
64 #import <WebCore/TextUndoInsertionMarkupMac.h>
65 #import <WebKitSystemInterface.h>
66 #import <wtf/text/CString.h>
67 #import <wtf/text/WTFString.h>
68
69 #if USE(DICTATION_ALTERNATIVES)
70 #import <AppKit/NSTextAlternatives.h>
71 #endif
72
73 @interface NSApplication (WebNSApplicationDetails)
74 - (NSCursor *)_cursorRectCursor;
75 @end
76
77 #if HAVE(OUT_OF_PROCESS_LAYER_HOSTING)
78 @interface NSWindow (WebNSWindowDetails)
79 - (BOOL)_hostsLayersInWindowServer;
80 @end
81 #endif
82
83 SOFT_LINK_CONSTANT_MAY_FAIL(Lookup, LUTermOptionDisableSearchTermIndicator, NSString *)
84
85 using namespace WebCore;
86 using namespace WebKit;
87
88 @interface WKEditCommandObjC : NSObject
89 {
90     RefPtr<WebEditCommandProxy> m_command;
91 }
92 - (id)initWithWebEditCommandProxy:(PassRefPtr<WebEditCommandProxy>)command;
93 - (WebEditCommandProxy*)command;
94 @end
95
96 @interface WKEditorUndoTargetObjC : NSObject
97 - (void)undoEditing:(id)sender;
98 - (void)redoEditing:(id)sender;
99 @end
100
101 @implementation WKEditCommandObjC
102
103 - (id)initWithWebEditCommandProxy:(PassRefPtr<WebEditCommandProxy>)command
104 {
105     self = [super init];
106     if (!self)
107         return nil;
108
109     m_command = command;
110     return self;
111 }
112
113 - (WebEditCommandProxy*)command
114 {
115     return m_command.get();
116 }
117
118 @end
119
120 @implementation WKEditorUndoTargetObjC
121
122 - (void)undoEditing:(id)sender
123 {
124     ASSERT([sender isKindOfClass:[WKEditCommandObjC class]]);
125     [sender command]->unapply();
126 }
127
128 - (void)redoEditing:(id)sender
129 {
130     ASSERT([sender isKindOfClass:[WKEditCommandObjC class]]);
131     [sender command]->reapply();
132 }
133
134 @end
135
136 namespace WebKit {
137
138 PageClientImpl::PageClientImpl(WKView* wkView, WKWebView *webView)
139     : m_wkView(wkView)
140     , m_webView(webView)
141     , m_undoTarget(adoptNS([[WKEditorUndoTargetObjC alloc] init]))
142 #if USE(DICTATION_ALTERNATIVES)
143     , m_alternativeTextUIController(std::make_unique<AlternativeTextUIController>())
144 #endif
145 {
146 #if !WK_API_ENABLED
147     ASSERT_UNUSED(m_webView, !m_webView);
148 #endif
149 }
150
151 PageClientImpl::~PageClientImpl()
152 {
153 }
154
155 std::unique_ptr<DrawingAreaProxy> PageClientImpl::createDrawingAreaProxy()
156 {
157     return [m_wkView _createDrawingAreaProxy];
158 }
159
160 void PageClientImpl::setViewNeedsDisplay(const WebCore::IntRect& rect)
161 {
162     ASSERT_NOT_REACHED();
163 }
164
165 void PageClientImpl::displayView()
166 {
167     ASSERT_NOT_REACHED();
168 }
169
170 bool PageClientImpl::canScrollView()
171 {
172     return false;
173 }
174
175 void PageClientImpl::scrollView(const IntRect& scrollRect, const IntSize& scrollOffset)
176 {
177     ASSERT_NOT_REACHED();
178 }
179
180 void PageClientImpl::requestScroll(const FloatPoint& scrollPosition, bool isProgrammaticScroll)
181 {
182     ASSERT_NOT_REACHED();
183 }
184
185 IntSize PageClientImpl::viewSize()
186 {
187     return IntSize([m_wkView bounds].size);
188 }
189
190 NSView *PageClientImpl::activeView() const
191 {
192 #if WK_API_ENABLED
193     return m_wkView._thumbnailView ? (NSView *)m_wkView._thumbnailView : (NSView *)m_wkView;
194 #else
195     return m_wkView;
196 #endif
197 }
198
199 NSWindow *PageClientImpl::activeWindow() const
200 {
201 #if WK_API_ENABLED
202     if (m_wkView._thumbnailView)
203         return m_wkView._thumbnailView.window;
204 #endif
205     if (m_wkView._targetWindowForMovePreparation)
206         return m_wkView._targetWindowForMovePreparation;
207     return m_wkView.window;
208 }
209
210 bool PageClientImpl::isViewWindowActive()
211 {
212     NSWindow *activeViewWindow = activeWindow();
213     return activeViewWindow.isKeyWindow || [NSApp keyWindow] == activeViewWindow;
214 }
215
216 bool PageClientImpl::isViewFocused()
217 {
218     return [m_wkView _isFocused];
219 }
220
221 void PageClientImpl::makeFirstResponder()
222 {
223      [[m_wkView window] makeFirstResponder:m_wkView];
224 }
225     
226 bool PageClientImpl::isViewVisible()
227 {
228     NSView *activeView = this->activeView();
229     NSWindow *activeViewWindow = activeWindow();
230
231     if (!activeViewWindow)
232         return false;
233
234     if (!activeViewWindow.isVisible)
235         return false;
236
237     if (activeView.isHiddenOrHasHiddenAncestor)
238         return false;
239
240     if ([m_wkView windowOcclusionDetectionEnabled] && (activeViewWindow.occlusionState & NSWindowOcclusionStateVisible) != NSWindowOcclusionStateVisible)
241         return false;
242
243     return true;
244 }
245
246 bool PageClientImpl::isViewVisibleOrOccluded()
247 {
248     return activeWindow().isVisible;
249 }
250
251 bool PageClientImpl::isViewInWindow()
252 {
253     return activeWindow();
254 }
255
256 bool PageClientImpl::isVisuallyIdle()
257 {
258     return WindowServerConnection::singleton().applicationWindowModificationsHaveStopped() || !isViewVisible();
259 }
260
261 LayerHostingMode PageClientImpl::viewLayerHostingMode()
262 {
263 #if HAVE(OUT_OF_PROCESS_LAYER_HOSTING)
264     if ([activeWindow() _hostsLayersInWindowServer])
265         return LayerHostingMode::OutOfProcess;
266 #endif
267     return LayerHostingMode::InProcess;
268 }
269
270 void PageClientImpl::viewWillMoveToAnotherWindow()
271 {
272     clearAllEditCommands();
273 }
274
275 ColorSpaceData PageClientImpl::colorSpace()
276 {
277     return [m_wkView _colorSpace];
278 }
279
280 void PageClientImpl::processDidExit()
281 {
282     [m_wkView _processDidExit];
283 }
284
285 void PageClientImpl::pageClosed()
286 {
287     [m_wkView _pageClosed];
288 #if USE(DICTATION_ALTERNATIVES)
289     m_alternativeTextUIController->clear();
290 #endif
291 }
292
293 void PageClientImpl::didRelaunchProcess()
294 {
295     [m_wkView _didRelaunchProcess];
296 }
297
298 void PageClientImpl::preferencesDidChange()
299 {
300     [m_wkView _preferencesDidChange];
301 }
302
303 void PageClientImpl::toolTipChanged(const String& oldToolTip, const String& newToolTip)
304 {
305     [m_wkView _toolTipChangedFrom:nsStringFromWebCoreString(oldToolTip) to:nsStringFromWebCoreString(newToolTip)];
306 }
307
308 void PageClientImpl::didCommitLoadForMainFrame(const String& mimeType, bool useCustomContentProvider)
309 {
310 }
311
312 void PageClientImpl::didFinishLoadingDataForCustomContentProvider(const String& suggestedFilename, const IPC::DataReference& dataReference)
313 {
314 }
315
316 void PageClientImpl::handleDownloadRequest(DownloadProxy* download)
317 {
318     ASSERT_ARG(download, download);
319 #if WK_API_ENABLED
320     ASSERT([download->wrapper() isKindOfClass:[_WKDownload class]]);
321     [static_cast<_WKDownload *>(download->wrapper()) setOriginatingWebView:m_webView];
322 #endif
323 }
324
325 void PageClientImpl::setCursor(const WebCore::Cursor& cursor)
326 {
327     // FIXME: Would be nice to share this code with WebKit1's WebChromeClient.
328
329     if ([NSApp _cursorRectCursor])
330         return;
331
332     if (!m_wkView)
333         return;
334
335     NSWindow *window = [m_wkView window];
336     if (!window)
337         return;
338
339     if ([window windowNumber] != [NSWindow windowNumberAtPoint:[NSEvent mouseLocation] belowWindowWithWindowNumber:0])
340         return;
341
342     NSCursor *platformCursor = cursor.platformCursor();
343     if ([NSCursor currentCursor] == platformCursor)
344         return;
345
346     [platformCursor set];
347 }
348
349 void PageClientImpl::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
350 {
351     [NSCursor setHiddenUntilMouseMoves:hiddenUntilMouseMoves];
352 }
353
354 void PageClientImpl::didChangeViewportProperties(const WebCore::ViewportAttributes&)
355 {
356 }
357
358 void PageClientImpl::registerEditCommand(PassRefPtr<WebEditCommandProxy> prpCommand, WebPageProxy::UndoOrRedo undoOrRedo)
359 {
360     RefPtr<WebEditCommandProxy> command = prpCommand;
361
362     RetainPtr<WKEditCommandObjC> commandObjC = adoptNS([[WKEditCommandObjC alloc] initWithWebEditCommandProxy:command]);
363     String actionName = WebEditCommandProxy::nameForEditAction(command->editAction());
364
365     NSUndoManager *undoManager = [m_wkView undoManager];
366     [undoManager registerUndoWithTarget:m_undoTarget.get() selector:((undoOrRedo == WebPageProxy::Undo) ? @selector(undoEditing:) : @selector(redoEditing:)) object:commandObjC.get()];
367     if (!actionName.isEmpty())
368         [undoManager setActionName:(NSString *)actionName];
369 }
370
371 #if USE(INSERTION_UNDO_GROUPING)
372 void PageClientImpl::registerInsertionUndoGrouping()
373 {
374     registerInsertionUndoGroupingWithUndoManager([m_wkView undoManager]);
375 }
376 #endif
377
378 void PageClientImpl::clearAllEditCommands()
379 {
380     [[m_wkView undoManager] removeAllActionsWithTarget:m_undoTarget.get()];
381 }
382
383 bool PageClientImpl::canUndoRedo(WebPageProxy::UndoOrRedo undoOrRedo)
384 {
385     return (undoOrRedo == WebPageProxy::Undo) ? [[m_wkView undoManager] canUndo] : [[m_wkView undoManager] canRedo];
386 }
387
388 void PageClientImpl::executeUndoRedo(WebPageProxy::UndoOrRedo undoOrRedo)
389 {
390     return (undoOrRedo == WebPageProxy::Undo) ? [[m_wkView undoManager] undo] : [[m_wkView undoManager] redo];
391 }
392
393 void PageClientImpl::setDragImage(const IntPoint& clientPosition, PassRefPtr<ShareableBitmap> dragImage, bool isLinkDrag)
394 {
395     RetainPtr<CGImageRef> dragCGImage = dragImage->makeCGImage();
396     RetainPtr<NSImage> dragNSImage = adoptNS([[NSImage alloc] initWithCGImage:dragCGImage.get() size:dragImage->size()]);
397
398     [m_wkView _setDragImage:dragNSImage.get() at:clientPosition linkDrag:isLinkDrag];
399 }
400
401 void PageClientImpl::setPromisedData(const String& pasteboardName, PassRefPtr<SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title, const String& url, const String& visibleUrl, PassRefPtr<SharedBuffer> archiveBuffer)
402 {
403     RefPtr<Image> image = BitmapImage::create();
404     image->setData(imageBuffer.get(), true);
405     [m_wkView _setPromisedData:image.get() withFileName:filename withExtension:extension withTitle:title withURL:url withVisibleURL:visibleUrl withArchive:archiveBuffer.get() forPasteboard:pasteboardName];
406 }
407
408 void PageClientImpl::updateSecureInputState()
409 {
410     [m_wkView _updateSecureInputState];
411 }
412
413 void PageClientImpl::resetSecureInputState()
414 {
415     [m_wkView _resetSecureInputState];
416 }
417
418 void PageClientImpl::notifyInputContextAboutDiscardedComposition()
419 {
420     [m_wkView _notifyInputContextAboutDiscardedComposition];
421 }
422
423 #if PLATFORM(MAC) && !USE(ASYNC_NSTEXTINPUTCLIENT)
424 void PageClientImpl::notifyApplicationAboutInputContextChange()
425 {
426     [NSApp updateWindows];
427 }
428 #endif
429
430 FloatRect PageClientImpl::convertToDeviceSpace(const FloatRect& rect)
431 {
432     return [m_wkView _convertToDeviceSpace:rect];
433 }
434
435 FloatRect PageClientImpl::convertToUserSpace(const FloatRect& rect)
436 {
437     return [m_wkView _convertToUserSpace:rect];
438 }
439    
440 IntPoint PageClientImpl::screenToRootView(const IntPoint& point)
441 {
442 #pragma clang diagnostic push
443 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
444     NSPoint windowCoord = [[m_wkView window] convertScreenToBase:point];
445 #pragma clang diagnostic pop
446     return IntPoint([m_wkView convertPoint:windowCoord fromView:nil]);
447 }
448     
449 IntRect PageClientImpl::rootViewToScreen(const IntRect& rect)
450 {
451     NSRect tempRect = rect;
452     tempRect = [m_wkView convertRect:tempRect toView:nil];
453 #pragma clang diagnostic push
454 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
455     tempRect.origin = [[m_wkView window] convertBaseToScreen:tempRect.origin];
456 #pragma clang diagnostic pop
457     return enclosingIntRect(tempRect);
458 }
459
460 void PageClientImpl::doneWithKeyEvent(const NativeWebKeyboardEvent& event, bool eventWasHandled)
461 {
462     [m_wkView _doneWithKeyEvent:event.nativeEvent() eventWasHandled:eventWasHandled];
463 }
464
465 PassRefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy* page)
466 {
467     return WebPopupMenuProxyMac::create(m_wkView, page);
468 }
469
470 PassRefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy* page)
471 {
472     return WebContextMenuProxyMac::create(m_wkView, page);
473 }
474
475 #if ENABLE(INPUT_TYPE_COLOR)
476 PassRefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy* page, const WebCore::Color& initialColor,  const WebCore::IntRect& rect)
477 {
478     return WebColorPickerMac::create(page, initialColor, rect, wkView());
479 }
480 #endif
481
482 void PageClientImpl::setTextIndicator(PassRefPtr<TextIndicator> textIndicator, bool fadeOut)
483 {
484     [m_wkView _setTextIndicator:textIndicator fadeOut:fadeOut];
485 }
486
487 void PageClientImpl::setTextIndicatorAnimationProgress(float progress)
488 {
489     [m_wkView _setTextIndicatorAnimationProgress:progress];
490 }
491
492 void PageClientImpl::accessibilityWebProcessTokenReceived(const IPC::DataReference& data)
493 {
494     NSData* remoteToken = [NSData dataWithBytes:data.data() length:data.size()];
495     [m_wkView _setAccessibilityWebProcessToken:remoteToken];
496 }
497     
498 void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
499 {
500     ASSERT(!layerTreeContext.isEmpty());
501
502     CALayer *renderLayer = WKMakeRenderLayer(layerTreeContext.contextID);
503     [m_wkView _setAcceleratedCompositingModeRootLayer:renderLayer];
504 }
505
506 void PageClientImpl::exitAcceleratedCompositingMode()
507 {
508     [m_wkView _setAcceleratedCompositingModeRootLayer:nil];
509 }
510
511 void PageClientImpl::updateAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
512 {
513     ASSERT(!layerTreeContext.isEmpty());
514
515     CALayer *renderLayer = WKMakeRenderLayer(layerTreeContext.contextID);
516     [m_wkView _setAcceleratedCompositingModeRootLayer:renderLayer];
517 }
518
519 void PageClientImpl::setAcceleratedCompositingRootLayer(CALayer *rootLayer)
520 {
521     [m_wkView _setAcceleratedCompositingModeRootLayer:rootLayer];
522 }
523
524 CALayer *PageClientImpl::acceleratedCompositingRootLayer() const
525 {
526     return m_wkView._acceleratedCompositingModeRootLayer;
527 }
528
529 PassRefPtr<ViewSnapshot> PageClientImpl::takeViewSnapshot()
530 {
531     return [m_wkView _takeViewSnapshot];
532 }
533
534 void PageClientImpl::selectionDidChange()
535 {
536     [m_wkView _selectionChanged];
537 }
538
539 void PageClientImpl::wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent& event)
540 {
541     [m_wkView _wheelEventWasNotHandledByWebCore:event.nativeEvent()];
542 }
543
544 void PageClientImpl::pluginFocusOrWindowFocusChanged(uint64_t pluginComplexTextInputIdentifier, bool pluginHasFocusAndWindowHasFocus)
545 {
546     [m_wkView _pluginFocusOrWindowFocusChanged:pluginHasFocusAndWindowHasFocus pluginComplexTextInputIdentifier:pluginComplexTextInputIdentifier];
547 }
548
549 void PageClientImpl::setPluginComplexTextInputState(uint64_t pluginComplexTextInputIdentifier, PluginComplexTextInputState pluginComplexTextInputState)
550 {
551     [m_wkView _setPluginComplexTextInputState:pluginComplexTextInputState pluginComplexTextInputIdentifier:pluginComplexTextInputIdentifier];
552 }
553
554 void PageClientImpl::didPerformDictionaryLookup(const DictionaryPopupInfo& dictionaryPopupInfo)
555 {
556     if (!getLULookupDefinitionModuleClass())
557         return;
558
559     NSPoint textBaselineOrigin = dictionaryPopupInfo.origin;
560
561     // Convert to screen coordinates.
562     textBaselineOrigin = [m_wkView convertPoint:textBaselineOrigin toView:nil];
563     textBaselineOrigin = [m_wkView.window convertRectToScreen:NSMakeRect(textBaselineOrigin.x, textBaselineOrigin.y, 0, 0)].origin;
564
565     RetainPtr<NSMutableDictionary> mutableOptions = adoptNS([(NSDictionary *)dictionaryPopupInfo.options.get() mutableCopy]);
566
567     if (canLoadLUTermOptionDisableSearchTermIndicator() && dictionaryPopupInfo.textIndicator.contentImage) {
568         [m_wkView _setTextIndicator:TextIndicator::create(dictionaryPopupInfo.textIndicator) fadeOut:NO];
569         [mutableOptions setObject:@YES forKey:getLUTermOptionDisableSearchTermIndicator()];
570         [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.string.get() atLocation:textBaselineOrigin options:mutableOptions.get()];
571     } else
572         [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.string.get() atLocation:textBaselineOrigin options:mutableOptions.get()];
573 }
574
575 void PageClientImpl::dismissContentRelativeChildWindows()
576 {
577     [m_wkView _dismissContentRelativeChildWindows];
578 }
579
580 void PageClientImpl::showCorrectionPanel(AlternativeTextType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings)
581 {
582 #if USE(AUTOCORRECTION_PANEL)
583     if (!isViewVisible() || !isViewInWindow())
584         return;
585     m_correctionPanel.show(m_wkView, type, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings);
586 #endif
587 }
588
589 void PageClientImpl::dismissCorrectionPanel(ReasonForDismissingAlternativeText reason)
590 {
591 #if USE(AUTOCORRECTION_PANEL)
592     m_correctionPanel.dismiss(reason);
593 #endif
594 }
595
596 String PageClientImpl::dismissCorrectionPanelSoon(WebCore::ReasonForDismissingAlternativeText reason)
597 {
598 #if USE(AUTOCORRECTION_PANEL)
599     return m_correctionPanel.dismiss(reason);
600 #else
601     return String();
602 #endif
603 }
604
605 void PageClientImpl::recordAutocorrectionResponse(AutocorrectionResponseType responseType, const String& replacedString, const String& replacementString)
606 {
607     NSCorrectionResponse response = responseType == AutocorrectionReverted ? NSCorrectionResponseReverted : NSCorrectionResponseEdited;
608     CorrectionPanel::recordAutocorrectionResponse(m_wkView, response, replacedString, replacementString);
609 }
610
611 void PageClientImpl::recommendedScrollbarStyleDidChange(ScrollbarStyle newStyle)
612 {
613     // Now re-create a tracking area with the appropriate options given the new scrollbar style
614     NSTrackingAreaOptions options = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect;
615     if (newStyle == ScrollbarStyle::AlwaysVisible)
616         options |= NSTrackingActiveAlways;
617     else
618         options |= NSTrackingActiveInKeyWindow;
619
620     RetainPtr<NSTrackingArea> trackingArea = adoptNS([[NSTrackingArea alloc] initWithRect:[m_wkView frame] options:options owner:m_wkView userInfo:nil]);
621     [m_wkView _setPrimaryTrackingArea:trackingArea.get()];
622 }
623
624 void PageClientImpl::intrinsicContentSizeDidChange(const IntSize& intrinsicContentSize)
625 {
626     [m_wkView _setIntrinsicContentSize:intrinsicContentSize];
627 }
628
629 bool PageClientImpl::executeSavedCommandBySelector(const String& selectorString)
630 {
631     return [m_wkView _executeSavedCommandBySelector:NSSelectorFromString(selectorString)];
632 }
633
634 #if USE(DICTATION_ALTERNATIVES)
635 uint64_t PageClientImpl::addDictationAlternatives(const RetainPtr<NSTextAlternatives>& alternatives)
636 {
637     return m_alternativeTextUIController->addAlternatives(alternatives);
638 }
639
640 void PageClientImpl::removeDictationAlternatives(uint64_t dictationContext)
641 {
642     m_alternativeTextUIController->removeAlternatives(dictationContext);
643 }
644
645 void PageClientImpl::showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, uint64_t dictationContext)
646 {
647     if (!isViewVisible() || !isViewInWindow())
648         return;
649     m_alternativeTextUIController->showAlternatives(m_wkView, boundingBoxOfDictatedText, dictationContext, ^(NSString* acceptedAlternative){
650         [m_wkView handleAcceptedAlternativeText:acceptedAlternative];
651     });
652 }
653
654 Vector<String> PageClientImpl::dictationAlternatives(uint64_t dictationContext)
655 {
656     return m_alternativeTextUIController->alternativesForContext(dictationContext);
657 }
658 #endif
659
660 #if ENABLE(FULLSCREEN_API)
661
662 WebFullScreenManagerProxyClient& PageClientImpl::fullScreenManagerProxyClient()
663 {
664     return *this;
665 }
666
667 // WebFullScreenManagerProxyClient
668
669 void PageClientImpl::closeFullScreenManager()
670 {
671     [m_wkView _closeFullScreenWindowController];
672 }
673
674 bool PageClientImpl::isFullScreen()
675 {
676     if (!m_wkView._hasFullScreenWindowController)
677         return false;
678
679     return m_wkView._fullScreenWindowController.isFullScreen;
680 }
681
682 void PageClientImpl::enterFullScreen()
683 {
684     [m_wkView._fullScreenWindowController enterFullScreen:nil];
685 }
686
687 void PageClientImpl::exitFullScreen()
688 {
689     [m_wkView._fullScreenWindowController exitFullScreen];
690 }
691
692 void PageClientImpl::beganEnterFullScreen(const IntRect& initialFrame, const IntRect& finalFrame)
693 {
694     [m_wkView._fullScreenWindowController beganEnterFullScreenWithInitialFrame:initialFrame finalFrame:finalFrame];
695 }
696
697 void PageClientImpl::beganExitFullScreen(const IntRect& initialFrame, const IntRect& finalFrame)
698 {
699     [m_wkView._fullScreenWindowController beganExitFullScreenWithInitialFrame:initialFrame finalFrame:finalFrame];
700 }
701
702 #endif // ENABLE(FULLSCREEN_API)
703
704 void PageClientImpl::navigationGestureDidBegin()
705 {
706     dismissContentRelativeChildWindows();
707
708 #if WK_API_ENABLED
709     if (m_webView)
710         NavigationState::fromWebPage(*m_webView->_page).navigationGestureDidBegin();
711 #endif
712 }
713
714 void PageClientImpl::navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem& item)
715 {
716 #if WK_API_ENABLED
717     if (m_webView)
718         NavigationState::fromWebPage(*m_webView->_page).navigationGestureWillEnd(willNavigate, item);
719 #else
720     UNUSED_PARAM(willNavigate);
721     UNUSED_PARAM(item);
722 #endif
723 }
724
725 void PageClientImpl::navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem& item)
726 {
727 #if WK_API_ENABLED
728     if (m_webView)
729         NavigationState::fromWebPage(*m_webView->_page).navigationGestureDidEnd(willNavigate, item);
730 #else
731     UNUSED_PARAM(willNavigate);
732     UNUSED_PARAM(item);
733 #endif
734 }
735
736 void PageClientImpl::willRecordNavigationSnapshot(WebBackForwardListItem& item)
737 {
738 #if WK_API_ENABLED
739     if (m_webView)
740         NavigationState::fromWebPage(*m_webView->_page).willRecordNavigationSnapshot(item);
741 #else
742     UNUSED_PARAM(item);
743 #endif
744 }
745
746 void PageClientImpl::didFirstVisuallyNonEmptyLayoutForMainFrame()
747 {
748     [m_wkView _didFirstVisuallyNonEmptyLayoutForMainFrame];
749 }
750
751 void PageClientImpl::didFinishLoadForMainFrame()
752 {
753     [m_wkView _didFinishLoadForMainFrame];
754 }
755
756 void PageClientImpl::didSameDocumentNavigationForMainFrame(SameDocumentNavigationType type)
757 {
758     [m_wkView _didSameDocumentNavigationForMainFrame:type];
759 }
760
761 void PageClientImpl::removeNavigationGestureSnapshot()
762 {
763     [m_wkView _removeNavigationGestureSnapshot];
764 }
765
766 CGRect PageClientImpl::boundsOfLayerInLayerBackedWindowCoordinates(CALayer *layer) const
767 {
768     CALayer *windowContentLayer = static_cast<NSView *>(m_wkView.window.contentView).layer;
769     ASSERT(windowContentLayer);
770
771     return [windowContentLayer convertRect:layer.bounds fromLayer:layer];
772 }
773
774 void PageClientImpl::didPerformActionMenuHitTest(const ActionMenuHitTestResult& result, bool forImmediateAction, API::Object* userData)
775 {
776 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
777     [m_wkView _didPerformActionMenuHitTest:result forImmediateAction:forImmediateAction userData:userData];
778 #endif
779 }
780
781 void PageClientImpl::showPlatformContextMenu(NSMenu *menu, IntPoint location)
782 {
783     [menu popUpMenuPositioningItem:nil atLocation:location inView:m_wkView];
784 }
785
786
787 } // namespace WebKit
788
789 #endif // PLATFORM(MAC)