<http://webkit.org/b/91015> Remove BUILDING_ON / TARGETING macros in favor of system...
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / 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 USE(DICTATION_ALTERNATIVES)
30 #import <AppKit/NSTextAlternatives.h>
31 #endif
32 #import "ColorSpaceData.h"
33 #import "DataReference.h"
34 #import "DictionaryPopupInfo.h"
35 #import "FindIndicator.h"
36 #import "NativeWebKeyboardEvent.h"
37 #import "WKAPICast.h"
38 #import "WKStringCF.h"
39 #import "WKViewInternal.h"
40 #import "StringUtilities.h"
41 #import "WebContextMenuProxyMac.h"
42 #import "WebEditCommandProxy.h"
43 #import "WebPopupMenuProxyMac.h"
44 #import <WebCore/AlternativeTextUIController.h>
45 #import <WebCore/BitmapImage.h>
46 #import <WebCore/Cursor.h>
47 #import <WebCore/FloatRect.h>
48 #import <WebCore/FoundationExtras.h>
49 #import <WebCore/GraphicsContext.h>
50 #import <WebCore/Image.h>
51 #import <WebCore/KeyboardEvent.h>
52 #import <WebCore/NotImplemented.h>
53 #import <WebCore/SharedBuffer.h>
54 #import <wtf/PassOwnPtr.h>
55 #import <wtf/text/CString.h>
56 #import <wtf/text/WTFString.h>
57 #import <WebKitSystemInterface.h>
58
59 @interface NSApplication (WebNSApplicationDetails)
60 - (NSCursor *)_cursorRectCursor;
61 @end
62
63 #if HAVE(LAYER_HOSTING_IN_WINDOW_SERVER)
64 @interface NSWindow (WebNSWindowDetails)
65 - (BOOL)_hostsLayersInWindowServer;
66 @end
67 #endif
68
69 using namespace WebCore;
70 using namespace WebKit;
71
72 @interface WKEditCommandObjC : NSObject
73 {
74     RefPtr<WebEditCommandProxy> m_command;
75 }
76 - (id)initWithWebEditCommandProxy:(PassRefPtr<WebEditCommandProxy>)command;
77 - (WebEditCommandProxy*)command;
78 @end
79
80 @interface WKEditorUndoTargetObjC : NSObject
81 - (void)undoEditing:(id)sender;
82 - (void)redoEditing:(id)sender;
83 @end
84
85 @implementation WKEditCommandObjC
86
87 - (id)initWithWebEditCommandProxy:(PassRefPtr<WebEditCommandProxy>)command
88 {
89     self = [super init];
90     if (!self)
91         return nil;
92
93     m_command = command;
94     return self;
95 }
96
97 - (WebEditCommandProxy*)command
98 {
99     return m_command.get();
100 }
101
102 @end
103
104 @implementation WKEditorUndoTargetObjC
105
106 - (void)undoEditing:(id)sender
107 {
108     ASSERT([sender isKindOfClass:[WKEditCommandObjC class]]);
109     [sender command]->unapply();
110 }
111
112 - (void)redoEditing:(id)sender
113 {
114     ASSERT([sender isKindOfClass:[WKEditCommandObjC class]]);
115     [sender command]->reapply();
116 }
117
118 @end
119
120 namespace WebKit {
121
122 PassOwnPtr<PageClientImpl> PageClientImpl::create(WKView* wkView)
123 {
124     return adoptPtr(new PageClientImpl(wkView));
125 }
126
127 PageClientImpl::PageClientImpl(WKView* wkView)
128     : m_wkView(wkView)
129     , m_undoTarget(AdoptNS, [[WKEditorUndoTargetObjC alloc] init])
130 #if USE(DICTATION_ALTERNATIVES)
131     , m_alternativeTextUIController(adoptPtr(new AlternativeTextUIController))
132 #endif
133 {
134 }
135
136 PageClientImpl::~PageClientImpl()
137 {
138 }
139
140 PassOwnPtr<DrawingAreaProxy> PageClientImpl::createDrawingAreaProxy()
141 {
142     return [m_wkView _createDrawingAreaProxy];
143 }
144
145 void PageClientImpl::setViewNeedsDisplay(const WebCore::IntRect& rect)
146 {
147     [m_wkView setNeedsDisplayInRect:rect];
148 }
149
150 void PageClientImpl::displayView()
151 {
152     [m_wkView displayIfNeeded];
153 }
154
155 void PageClientImpl::scrollView(const IntRect& scrollRect, const IntSize& scrollOffset)
156 {
157     NSRect clippedScrollRect = NSIntersectionRect(scrollRect, NSOffsetRect(scrollRect, -scrollOffset.width(), -scrollOffset.height()));
158
159     [m_wkView _cacheWindowBottomCornerRect];
160
161     [m_wkView translateRectsNeedingDisplayInRect:clippedScrollRect by:scrollOffset];
162     [m_wkView scrollRect:clippedScrollRect by:scrollOffset];
163 }
164
165 IntSize PageClientImpl::viewSize()
166 {
167     return IntSize([m_wkView bounds].size);
168 }
169
170 bool PageClientImpl::isViewWindowActive()
171 {
172     return [[m_wkView window] isKeyWindow] || [NSApp keyWindow] == [m_wkView window];
173 }
174
175 bool PageClientImpl::isViewFocused()
176 {
177     return [m_wkView _isFocused];
178 }
179
180 void PageClientImpl::makeFirstResponder()
181 {
182      [[m_wkView window] makeFirstResponder:m_wkView];
183 }
184     
185 bool PageClientImpl::isViewVisible()
186 {
187     if (![m_wkView window])
188         return false;
189
190     if (![[m_wkView window] isVisible])
191         return false;
192
193     if ([m_wkView isHiddenOrHasHiddenAncestor])
194         return false;
195
196     return true;
197 }
198
199 bool PageClientImpl::isViewInWindow()
200 {
201     return [m_wkView window];
202 }
203
204 void PageClientImpl::viewWillMoveToAnotherWindow()
205 {
206     clearAllEditCommands();
207 }
208
209 LayerHostingMode PageClientImpl::viewLayerHostingMode()
210 {
211 #if HAVE(LAYER_HOSTING_IN_WINDOW_SERVER)
212     if (![m_wkView window])
213         return LayerHostingModeDefault;
214
215     return [[m_wkView window] _hostsLayersInWindowServer] ? LayerHostingModeInWindowServer : LayerHostingModeDefault;
216 #else
217     return LayerHostingModeDefault;
218 #endif
219 }
220
221 ColorSpaceData PageClientImpl::colorSpace()
222 {
223     return [m_wkView _colorSpace];
224 }
225
226 void PageClientImpl::processDidCrash()
227 {
228     [m_wkView _processDidCrash];
229 }
230
231 void PageClientImpl::pageClosed()
232 {
233     [m_wkView _pageClosed];
234 #if USE(DICTATION_ALTERNATIVES)
235     m_alternativeTextUIController->clear();
236 #endif
237 }
238
239 void PageClientImpl::didRelaunchProcess()
240 {
241     [m_wkView _didRelaunchProcess];
242 }
243
244 void PageClientImpl::toolTipChanged(const String& oldToolTip, const String& newToolTip)
245 {
246     [m_wkView _toolTipChangedFrom:nsStringFromWebCoreString(oldToolTip) to:nsStringFromWebCoreString(newToolTip)];
247 }
248
249 void PageClientImpl::setCursor(const WebCore::Cursor& cursor)
250 {
251     if (![NSApp _cursorRectCursor])
252         [m_wkView _setCursor:cursor.platformCursor()];
253 }
254
255 void PageClientImpl::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
256 {
257     [NSCursor setHiddenUntilMouseMoves:hiddenUntilMouseMoves];
258 }
259
260 void PageClientImpl::didChangeViewportProperties(const WebCore::ViewportAttributes&)
261 {
262 }
263
264 void PageClientImpl::registerEditCommand(PassRefPtr<WebEditCommandProxy> prpCommand, WebPageProxy::UndoOrRedo undoOrRedo)
265 {
266     RefPtr<WebEditCommandProxy> command = prpCommand;
267
268     RetainPtr<WKEditCommandObjC> commandObjC(AdoptNS, [[WKEditCommandObjC alloc] initWithWebEditCommandProxy:command]);
269     String actionName = WebEditCommandProxy::nameForEditAction(command->editAction());
270
271     NSUndoManager *undoManager = [m_wkView undoManager];
272     [undoManager registerUndoWithTarget:m_undoTarget.get() selector:((undoOrRedo == WebPageProxy::Undo) ? @selector(undoEditing:) : @selector(redoEditing:)) object:commandObjC.get()];
273     if (!actionName.isEmpty())
274         [undoManager setActionName:(NSString *)actionName];
275 }
276
277 void PageClientImpl::clearAllEditCommands()
278 {
279     [[m_wkView undoManager] removeAllActionsWithTarget:m_undoTarget.get()];
280 }
281
282 bool PageClientImpl::canUndoRedo(WebPageProxy::UndoOrRedo undoOrRedo)
283 {
284     return (undoOrRedo == WebPageProxy::Undo) ? [[m_wkView undoManager] canUndo] : [[m_wkView undoManager] canRedo];
285 }
286
287 void PageClientImpl::executeUndoRedo(WebPageProxy::UndoOrRedo undoOrRedo)
288 {
289     return (undoOrRedo == WebPageProxy::Undo) ? [[m_wkView undoManager] undo] : [[m_wkView undoManager] redo];
290 }
291
292 bool PageClientImpl::interpretKeyEvent(const NativeWebKeyboardEvent& event, Vector<WebCore::KeypressCommand>& commands)
293 {
294     return [m_wkView _interpretKeyEvent:event.nativeEvent() savingCommandsTo:commands];
295 }
296
297 void PageClientImpl::setDragImage(const IntPoint& clientPosition, PassRefPtr<ShareableBitmap> dragImage, bool isLinkDrag)
298 {
299     RetainPtr<CGImageRef> dragCGImage = dragImage->makeCGImage();
300     RetainPtr<NSImage> dragNSImage(AdoptNS, [[NSImage alloc] initWithCGImage:dragCGImage.get() size:dragImage->size()]);
301
302     [m_wkView _setDragImage:dragNSImage.get() at:clientPosition linkDrag:isLinkDrag];
303 }
304
305 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)
306 {
307     RefPtr<Image> image = BitmapImage::create();
308     image->setData(imageBuffer.get(), true);
309     [m_wkView _setPromisedData:image.get() withFileName:filename withExtension:extension withTitle:title withURL:url withVisibleURL:visibleUrl withArchive:archiveBuffer.get() forPasteboard:pasteboardName];
310 }
311
312 void PageClientImpl::updateTextInputState(bool updateSecureInputState)
313 {
314     [m_wkView _updateTextInputStateIncludingSecureInputState:updateSecureInputState];
315 }
316
317 void PageClientImpl::resetTextInputState()
318 {
319     [m_wkView _resetTextInputState];
320 }
321
322 FloatRect PageClientImpl::convertToDeviceSpace(const FloatRect& rect)
323 {
324     return [m_wkView _convertToDeviceSpace:rect];
325 }
326
327 FloatRect PageClientImpl::convertToUserSpace(const FloatRect& rect)
328 {
329     return [m_wkView _convertToUserSpace:rect];
330 }
331    
332 IntPoint PageClientImpl::screenToWindow(const IntPoint& point)
333 {
334     NSPoint windowCoord = [[m_wkView window] convertScreenToBase:point];
335     return IntPoint([m_wkView convertPoint:windowCoord fromView:nil]);
336 }
337     
338 IntRect PageClientImpl::windowToScreen(const IntRect& rect)
339 {
340     NSRect tempRect = rect;
341     tempRect = [m_wkView convertRect:tempRect toView:nil];
342     tempRect.origin = [[m_wkView window] convertBaseToScreen:tempRect.origin];
343     return enclosingIntRect(tempRect);
344 }
345
346 #if ENABLE(GESTURE_EVENTS)
347 void PageClientImpl::doneWithGestureEvent(const WebGestureEvent&, bool wasEventHandled)
348 {
349     notImplemented();
350 }
351 #endif
352
353 void PageClientImpl::doneWithKeyEvent(const NativeWebKeyboardEvent& event, bool eventWasHandled)
354 {
355     [m_wkView _doneWithKeyEvent:event.nativeEvent() eventWasHandled:eventWasHandled];
356 }
357
358 PassRefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy* page)
359 {
360     return WebPopupMenuProxyMac::create(m_wkView, page);
361 }
362
363 PassRefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy* page)
364 {
365     return WebContextMenuProxyMac::create(m_wkView, page);
366 }
367
368 #if ENABLE(INPUT_TYPE_COLOR)
369 PassRefPtr<WebColorChooserProxy> PageClientImpl::createColorChooserProxy(WebPageProxy*, const WebCore::Color&)
370 {
371     notImplemented();
372     return 0;
373 }
374 #endif
375
376 void PageClientImpl::setFindIndicator(PassRefPtr<FindIndicator> findIndicator, bool fadeOut, bool animate)
377 {
378     [m_wkView _setFindIndicator:findIndicator fadeOut:fadeOut animate:animate];
379 }
380
381 void PageClientImpl::accessibilityWebProcessTokenReceived(const CoreIPC::DataReference& data)
382 {
383     NSData* remoteToken = [NSData dataWithBytes:data.data() length:data.size()];
384     [m_wkView _setAccessibilityWebProcessToken:remoteToken];
385 }
386     
387 #if USE(ACCELERATED_COMPOSITING)
388 void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
389 {
390     [m_wkView _enterAcceleratedCompositingMode:layerTreeContext];
391 }
392
393 void PageClientImpl::exitAcceleratedCompositingMode()
394 {
395     [m_wkView _exitAcceleratedCompositingMode];
396 }
397
398 void PageClientImpl::updateAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
399 {
400     [m_wkView _updateAcceleratedCompositingMode:layerTreeContext];
401 }
402 #endif // USE(ACCELERATED_COMPOSITING)
403
404 void PageClientImpl::pluginFocusOrWindowFocusChanged(uint64_t pluginComplexTextInputIdentifier, bool pluginHasFocusAndWindowHasFocus)
405 {
406     [m_wkView _pluginFocusOrWindowFocusChanged:pluginHasFocusAndWindowHasFocus pluginComplexTextInputIdentifier:pluginComplexTextInputIdentifier];
407 }
408
409 void PageClientImpl::setPluginComplexTextInputState(uint64_t pluginComplexTextInputIdentifier, PluginComplexTextInputState pluginComplexTextInputState)
410 {
411     [m_wkView _setPluginComplexTextInputState:pluginComplexTextInputState pluginComplexTextInputIdentifier:pluginComplexTextInputIdentifier];
412 }
413
414 CGContextRef PageClientImpl::containingWindowGraphicsContext()
415 {
416     NSWindow *window = [m_wkView window];
417
418     // Don't try to get the graphics context if the NSWindow doesn't have a window device.
419     if ([window windowNumber] <= 0)
420         return 0;
421
422     return static_cast<CGContextRef>([[window graphicsContext] graphicsPort]);
423 }
424
425 void PageClientImpl::didChangeScrollbarsForMainFrame() const
426 {
427     [m_wkView _didChangeScrollbarsForMainFrame];
428 }
429
430 void PageClientImpl::didCommitLoadForMainFrame(bool useCustomRepresentation)
431 {
432     [m_wkView _setPageHasCustomRepresentation:useCustomRepresentation];
433 }
434
435 void PageClientImpl::didFinishLoadingDataForCustomRepresentation(const String& suggestedFilename, const CoreIPC::DataReference& dataReference)
436 {
437     [m_wkView _didFinishLoadingDataForCustomRepresentationWithSuggestedFilename:suggestedFilename dataReference:dataReference];
438 }
439
440 double PageClientImpl::customRepresentationZoomFactor()
441 {
442     return [m_wkView _customRepresentationZoomFactor];
443 }
444
445 void PageClientImpl::setCustomRepresentationZoomFactor(double zoomFactor)
446 {
447     [m_wkView _setCustomRepresentationZoomFactor:zoomFactor];
448 }
449
450 void PageClientImpl::findStringInCustomRepresentation(const String& string, FindOptions options, unsigned maxMatchCount)
451 {
452     [m_wkView _findStringInCustomRepresentation:string withFindOptions:options maxMatchCount:maxMatchCount];
453 }
454
455 void PageClientImpl::countStringMatchesInCustomRepresentation(const String& string, FindOptions options, unsigned maxMatchCount)
456 {
457     [m_wkView _countStringMatchesInCustomRepresentation:string withFindOptions:options maxMatchCount:maxMatchCount];
458 }
459
460 void PageClientImpl::flashBackingStoreUpdates(const Vector<IntRect>&)
461 {
462     notImplemented();
463 }
464
465 void PageClientImpl::didPerformDictionaryLookup(const String& text, double scaleFactor, const DictionaryPopupInfo& dictionaryPopupInfo)
466 {
467     NSFontDescriptor *fontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:(NSDictionary *)dictionaryPopupInfo.fontInfo.fontAttributeDictionary.get()];
468     NSFont *font = [NSFont fontWithDescriptor:fontDescriptor size:((scaleFactor != 1) ? [fontDescriptor pointSize] * scaleFactor : 0)];
469
470     RetainPtr<NSMutableAttributedString> attributedString(AdoptNS, [[NSMutableAttributedString alloc] initWithString:nsStringFromWebCoreString(text)]);
471     [attributedString.get() addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, [attributedString.get() length])];
472
473     NSPoint textBaselineOrigin = dictionaryPopupInfo.origin;
474
475 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
476     // Convert to screen coordinates.
477     textBaselineOrigin = [m_wkView convertPoint:textBaselineOrigin toView:nil];
478     textBaselineOrigin = [m_wkView.window convertRectToScreen:NSMakeRect(textBaselineOrigin.x, textBaselineOrigin.y, 0, 0)].origin;
479
480     WKShowWordDefinitionWindow(attributedString.get(), textBaselineOrigin, (NSDictionary *)dictionaryPopupInfo.options.get());
481 #else
482     // If the dictionary lookup is being triggered by a hot key, force the overlay style.
483     NSDictionary *options = (dictionaryPopupInfo.type == DictionaryPopupInfo::HotKey) ? [NSDictionary dictionaryWithObject:NSDefinitionPresentationTypeOverlay forKey:NSDefinitionPresentationTypeKey] : 0;
484     [m_wkView showDefinitionForAttributedString:attributedString.get() range:NSMakeRange(0, [attributedString.get() length]) options:options baselineOriginProvider:^(NSRange adjustedRange) { return (NSPoint)textBaselineOrigin; }];
485 #endif
486 }
487
488 void PageClientImpl::dismissDictionaryLookupPanel()
489 {
490 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
491     WKHideWordDefinitionWindow();
492 #endif
493 }
494
495 void PageClientImpl::showCorrectionPanel(AlternativeTextType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings)
496 {
497 #if USE(AUTOCORRECTION_PANEL)
498     if (!isViewVisible() || !isViewInWindow())
499         return;
500     m_correctionPanel.show(m_wkView, type, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings);
501 #endif
502 }
503
504 void PageClientImpl::dismissCorrectionPanel(ReasonForDismissingAlternativeText reason)
505 {
506 #if USE(AUTOCORRECTION_PANEL)
507     m_correctionPanel.dismiss(reason);
508 #endif
509 }
510
511 String PageClientImpl::dismissCorrectionPanelSoon(WebCore::ReasonForDismissingAlternativeText reason)
512 {
513 #if USE(AUTOCORRECTION_PANEL)
514     return m_correctionPanel.dismiss(reason);
515 #else
516     return String();
517 #endif
518 }
519
520 void PageClientImpl::recordAutocorrectionResponse(AutocorrectionResponseType responseType, const String& replacedString, const String& replacementString)
521 {
522 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
523     NSCorrectionResponse response = responseType == AutocorrectionReverted ? NSCorrectionResponseReverted : NSCorrectionResponseEdited;
524     CorrectionPanel::recordAutocorrectionResponse(m_wkView, response, replacedString, replacementString);
525 #endif
526 }
527
528 void PageClientImpl::recommendedScrollbarStyleDidChange(int32_t newStyle)
529 {
530 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
531     NSArray *trackingAreas = [m_wkView trackingAreas];
532     NSUInteger count = [trackingAreas count];
533     ASSERT(count == 1);
534     
535     for (NSUInteger i = 0; i < count; ++i)
536         [m_wkView removeTrackingArea:[trackingAreas objectAtIndex:i]];
537
538     // Now re-create a tracking area with the appropriate options given the new scrollbar style
539     NSTrackingAreaOptions options = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect;
540     if (newStyle == NSScrollerStyleLegacy)
541         options |= NSTrackingActiveAlways;
542     else
543         options |= NSTrackingActiveInKeyWindow;
544
545     NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:[m_wkView frame]
546                                                                 options:options
547                                                                   owner:m_wkView
548                                                                userInfo:nil];
549     [m_wkView addTrackingArea:trackingArea];
550     [trackingArea release];
551 #else
552     UNUSED_PARAM(newStyle);
553 #endif
554 }
555
556 bool PageClientImpl::executeSavedCommandBySelector(const String& selectorString)
557 {
558     return [m_wkView _executeSavedCommandBySelector:NSSelectorFromString(selectorString)];
559 }
560
561 #if USE(DICTATION_ALTERNATIVES)
562 uint64_t PageClientImpl::addDictationAlternatives(const RetainPtr<NSTextAlternatives>& alternatives)
563 {
564     return m_alternativeTextUIController->addAlternatives(alternatives);
565 }
566
567 void PageClientImpl::removeDictationAlternatives(uint64_t dictationContext)
568 {
569     m_alternativeTextUIController->removeAlternatives(dictationContext);
570 }
571
572 void PageClientImpl::showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, uint64_t dictationContext)
573 {
574     if (!isViewVisible() || !isViewInWindow())
575         return;
576     m_alternativeTextUIController->showAlternatives(m_wkView, boundingBoxOfDictatedText, dictationContext, ^(NSString* acceptedAlternative){
577         [m_wkView handleAcceptedAlternativeText:acceptedAlternative];
578     });
579 }
580
581 Vector<String> PageClientImpl::dictationAlternatives(uint64_t dictationContext)
582 {
583     return m_alternativeTextUIController->alternativesForContext(dictationContext);
584 }
585
586 void PageClientImpl::dismissDictationAlternativeUI()
587 {
588     m_alternativeTextUIController->dismissAlternatives();
589 }
590 #endif
591
592 } // namespace WebKit