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