Move URL from WebCore to WTF
[WebKit-https.git] / Source / WebKit / UIProcess / mac / PageClientImplMac.h
1 /*
2  * Copyright (C) 2010, 2011, 2016 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 #pragma once
27
28 #if PLATFORM(MAC)
29
30 #include "CorrectionPanel.h"
31 #include "PageClientImplCocoa.h"
32 #include "WebFullScreenManagerProxy.h"
33 #include <wtf/RetainPtr.h>
34
35 @class WKEditorUndoTargetObjC;
36 @class WKView;
37
38 namespace WebCore {
39 class AlternativeTextUIController;
40 struct DragItem;
41 struct PromisedAttachmentInfo;
42 }
43
44 namespace WebKit {
45
46 class WebViewImpl;
47
48 class PageClientImpl final : public PageClientImplCocoa
49 #if ENABLE(FULLSCREEN_API)
50     , public WebFullScreenManagerProxyClient
51 #endif
52     {
53 public:
54     PageClientImpl(NSView *, WKWebView *);
55     virtual ~PageClientImpl();
56
57     // FIXME: Eventually WebViewImpl should become the PageClient.
58     void setImpl(WebViewImpl&);
59
60     void viewWillMoveToAnotherWindow();
61
62 private:
63     // PageClient
64     std::unique_ptr<DrawingAreaProxy> createDrawingAreaProxy() override;
65     void setViewNeedsDisplay(const WebCore::Region&) override;
66     void requestScroll(const WebCore::FloatPoint& scrollPosition, const WebCore::IntPoint& scrollOrigin, bool isProgrammaticScroll) override;
67     WebCore::FloatPoint viewScrollPosition() override;
68
69     WebCore::IntSize viewSize() override;
70     bool isViewWindowActive() override;
71     bool isViewFocused() override;
72     bool isViewVisible() override;
73     bool isViewVisibleOrOccluded() override;
74     bool isViewInWindow() override;
75     bool isVisuallyIdle() override;
76     LayerHostingMode viewLayerHostingMode() override;
77     ColorSpaceData colorSpace() override;
78     void setRemoteLayerTreeRootNode(RemoteLayerTreeNode*) override;
79     CALayer *acceleratedCompositingRootLayer() const override;
80
81     void processDidExit() override;
82     void processWillSwap() override;
83     void pageClosed() override;
84     void didRelaunchProcess() override;
85     void preferencesDidChange() override;
86     void toolTipChanged(const String& oldToolTip, const String& newToolTip) override;
87     void didCommitLoadForMainFrame(const String& mimeType, bool useCustomContentProvider) override;
88     void didFinishLoadingDataForCustomContentProvider(const String& suggestedFilename, const IPC::DataReference&) override;
89     void handleDownloadRequest(DownloadProxy*) override;
90     void didChangeContentSize(const WebCore::IntSize&) override;
91     void setCursor(const WebCore::Cursor&) override;
92     void setCursorHiddenUntilMouseMoves(bool) override;
93     void didChangeViewportProperties(const WebCore::ViewportAttributes&) override;
94
95     void registerEditCommand(Ref<WebEditCommandProxy>&&, UndoOrRedo) override;
96     void clearAllEditCommands() override;
97     bool canUndoRedo(UndoOrRedo) override;
98     void executeUndoRedo(UndoOrRedo) override;
99     bool executeSavedCommandBySelector(const String& selector) override;
100     void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& image) override;
101     void setPromisedDataForImage(const String& pasteboardName, Ref<WebCore::SharedBuffer>&& imageBuffer, const String& filename, const String& extension, const String& title,
102         const String& url, const String& visibleUrl, RefPtr<WebCore::SharedBuffer>&& archiveBuffer) override;
103     void updateSecureInputState() override;
104     void resetSecureInputState() override;
105     void notifyInputContextAboutDiscardedComposition() override;
106     void selectionDidChange() override;
107     void showSafeBrowsingWarning(const SafeBrowsingWarning&, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, URL>&&)>&&) override;
108     void clearSafeBrowsingWarning() override;
109     
110 #if WK_API_ENABLED
111     bool showShareSheet(const WebCore::ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&&) override;
112 #endif
113         
114     WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&) override;
115     WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&) override;
116     WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) override;
117     WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) override;
118 #if PLATFORM(MAC)
119     WebCore::IntRect rootViewToWindow(const WebCore::IntRect&) override;
120 #endif
121 #if PLATFORM(IOS_FAMILY)
122     virtual WebCore::IntPoint accessibilityScreenToRootView(const WebCore::IntPoint&) = 0;
123     virtual WebCore::IntRect rootViewToAccessibilityScreen(const WebCore::IntRect&) = 0;
124 #endif
125
126     void pinnedStateWillChange() final;
127     void pinnedStateDidChange() final;
128
129     CGRect boundsOfLayerInLayerBackedWindowCoordinates(CALayer *) const override;
130
131     void doneWithKeyEvent(const NativeWebKeyboardEvent&, bool wasEventHandled) override;
132
133     RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) override;
134 #if ENABLE(CONTEXT_MENUS)
135     Ref<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, ContextMenuContextData&&, const UserData&) override;
136 #endif
137
138 #if ENABLE(INPUT_TYPE_COLOR)
139     RefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&, Vector<WebCore::Color>&&) override;
140 #endif
141
142 #if ENABLE(DATALIST_ELEMENT)
143     RefPtr<WebDataListSuggestionsDropdown> createDataListSuggestionsDropdown(WebPageProxy&) override;
144 #endif
145
146     Ref<WebCore::ValidationBubble> createValidationBubble(const String& message, const WebCore::ValidationBubble::Settings&) final;
147
148     void setTextIndicator(Ref<WebCore::TextIndicator>, WebCore::TextIndicatorWindowLifetime) override;
149     void clearTextIndicator(WebCore::TextIndicatorWindowDismissalAnimation) override;
150     void setTextIndicatorAnimationProgress(float) override;
151
152     void enterAcceleratedCompositingMode(const LayerTreeContext&) override;
153     void exitAcceleratedCompositingMode() override;
154     void updateAcceleratedCompositingMode(const LayerTreeContext&) override;
155
156     RefPtr<ViewSnapshot> takeViewSnapshot() override;
157     void wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent&) override;
158 #if ENABLE(MAC_GESTURE_EVENTS)
159     void gestureEventWasNotHandledByWebCore(const NativeWebGestureEvent&) override;
160 #endif
161
162     void accessibilityWebProcessTokenReceived(const IPC::DataReference&) override;
163
164     void pluginFocusOrWindowFocusChanged(uint64_t pluginComplexTextInputIdentifier, bool pluginHasFocusAndWindowHasFocus) override;
165     void setPluginComplexTextInputState(uint64_t pluginComplexTextInputIdentifier, PluginComplexTextInputState) override;
166
167     void makeFirstResponder() override;
168     void assistiveTechnologyMakeFirstResponder() override;
169     void setShouldSuppressFirstResponderChanges(bool shouldSuppress) override { m_shouldSuppressFirstResponderChanges = shouldSuppress; }
170
171     void didPerformDictionaryLookup(const WebCore::DictionaryPopupInfo&) override;
172
173     void showCorrectionPanel(WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) override;
174     void dismissCorrectionPanel(WebCore::ReasonForDismissingAlternativeText) override;
175     String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingAlternativeText) override;
176     void recordAutocorrectionResponse(WebCore::AutocorrectionResponse, const String& replacedString, const String& replacementString) override;
177
178     void recommendedScrollbarStyleDidChange(WebCore::ScrollbarStyle) override;
179
180     void intrinsicContentSizeDidChange(const WebCore::IntSize& intrinsicContentSize) override;
181
182 #if USE(DICTATION_ALTERNATIVES)
183     uint64_t addDictationAlternatives(const RetainPtr<NSTextAlternatives>&) override;
184     void removeDictationAlternatives(uint64_t dictationContext) override;
185     void showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, uint64_t dictationContext) override;
186     Vector<String> dictationAlternatives(uint64_t dictationContext) override;
187 #endif
188     void setEditableElementIsFocused(bool) override;
189
190 #if USE(INSERTION_UNDO_GROUPING)
191     void registerInsertionUndoGrouping() override;
192 #endif
193
194     // Auxiliary Client Creation
195 #if ENABLE(FULLSCREEN_API)
196     WebFullScreenManagerProxyClient& fullScreenManagerProxyClient() override;
197 #endif
198
199 #if ENABLE(FULLSCREEN_API)
200     // WebFullScreenManagerProxyClient
201     void closeFullScreenManager() override;
202     bool isFullScreen() override;
203     void enterFullScreen() override;
204     void exitFullScreen() override;
205     void beganEnterFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame) override;
206     void beganExitFullScreen(const WebCore::IntRect& initialFrame, const WebCore::IntRect& finalFrame) override;
207 #endif
208
209     void navigationGestureDidBegin() override;
210     void navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem&) override;
211     void navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem&) override;
212     void navigationGestureDidEnd() override;
213     void willRecordNavigationSnapshot(WebBackForwardListItem&) override;
214     void didRemoveNavigationGestureSnapshot() override;
215
216     NSView *activeView() const;
217     NSWindow *activeWindow() const;
218
219     void didStartProvisionalLoadForMainFrame() override;
220     void didFirstVisuallyNonEmptyLayoutForMainFrame() override;
221     void didFinishLoadForMainFrame() override;
222     void didFailLoadForMainFrame() override;
223     void didSameDocumentNavigationForMainFrame(SameDocumentNavigationType) override;
224     void handleControlledElementIDResponse(const String&) override;
225
226     void didPerformImmediateActionHitTest(const WebHitTestResultData&, bool contentPreventsDefault, API::Object*) override;
227     NSObject *immediateActionAnimationControllerForHitTestResult(RefPtr<API::HitTestResult>, uint64_t, RefPtr<API::Object>) override;
228
229     void didHandleAcceptedCandidate() override;
230
231     void videoControlsManagerDidChange() override;
232
233     void showPlatformContextMenu(NSMenu *, WebCore::IntPoint) override;
234
235     void didChangeBackgroundColor() override;
236
237     void startWindowDrag() override;
238     NSWindow *platformWindow() override;
239
240     WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() override;
241     bool effectiveAppearanceIsDark() const override;
242
243 #if ENABLE(DRAG_SUPPORT)
244     void didPerformDragOperation(bool handled) final;
245 #endif
246
247 #if WK_API_ENABLED
248     NSView *inspectorAttachmentView() override;
249     _WKRemoteObjectRegistry *remoteObjectRegistry() override;
250 #endif
251
252     void didFinishProcessingAllPendingMouseEvents() final;
253
254     NSView *m_view;
255     WeakPtr<WebViewImpl> m_impl;
256 #if USE(AUTOCORRECTION_PANEL)
257     CorrectionPanel m_correctionPanel;
258 #endif
259 #if USE(DICTATION_ALTERNATIVES)
260     std::unique_ptr<WebCore::AlternativeTextUIController> m_alternativeTextUIController;
261 #endif
262
263     bool m_shouldSuppressFirstResponderChanges { false };
264
265 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
266     WebCore::WebMediaSessionManager& mediaSessionManager() override;
267 #endif
268
269     void refView() override;
270     void derefView() override;
271
272     void didRestoreScrollPosition() override;
273     bool windowIsFrontWindowUnderMouse(const NativeWebMouseEvent&) override;
274 };
275
276 } // namespace WebKit
277
278 #endif // PLATFORM(MAC)