Introduce new SPI for context menus on iOS
[WebKit-https.git] / Source / WebKit / UIProcess / Cocoa / WebViewImpl.h
1 /*
2  * Copyright (C) 2015 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 "PluginComplexTextInputState.h"
31 #include "ShareableBitmap.h"
32 #include "WKDragDestinationAction.h"
33 #include "WKLayoutMode.h"
34 #include "_WKOverlayScrollbarStyle.h"
35 #include <WebCore/FocusDirection.h>
36 #include <WebCore/ScrollTypes.h>
37 #include <WebCore/TextIndicatorWindow.h>
38 #include <WebCore/UserInterfaceLayoutDirection.h>
39 #include <pal/spi/cocoa/AVKitSPI.h>
40 #include <wtf/BlockPtr.h>
41 #include <wtf/RetainPtr.h>
42 #include <wtf/WeakObjCPtr.h>
43 #include <wtf/WeakPtr.h>
44 #include <wtf/text/WTFString.h>
45
46 using _WKRectEdge = NSUInteger;
47
48 OBJC_CLASS NSAccessibilityRemoteUIElement;
49 OBJC_CLASS NSImmediateActionGestureRecognizer;
50 OBJC_CLASS NSTextInputContext;
51 OBJC_CLASS NSView;
52 OBJC_CLASS WKAccessibilitySettingsObserver;
53 OBJC_CLASS WKBrowsingContextController;
54 OBJC_CLASS WKEditorUndoTarget;
55 OBJC_CLASS WKFullScreenWindowController;
56 OBJC_CLASS WKImmediateActionController;
57 OBJC_CLASS WKSafeBrowsingWarning;
58 OBJC_CLASS WKShareSheet;
59 OBJC_CLASS WKViewLayoutStrategy;
60 OBJC_CLASS WKWebView;
61 OBJC_CLASS WKWindowVisibilityObserver;
62 OBJC_CLASS _WKRemoteObjectRegistry;
63 OBJC_CLASS _WKThumbnailView;
64
65 #if HAVE(TOUCH_BAR)
66 OBJC_CLASS NSCandidateListTouchBarItem;
67 OBJC_CLASS NSCustomTouchBarItem;
68 OBJC_CLASS NSTouchBar;
69 OBJC_CLASS NSTouchBarItem;
70 OBJC_CLASS NSPopoverTouchBarItem;
71 OBJC_CLASS WKTextTouchBarItemController;
72 OBJC_CLASS WebPlaybackControlsManager;
73 #endif // HAVE(TOUCH_BAR)
74
75 namespace API {
76 class HitTestResult;
77 class Object;
78 class PageConfiguration;
79 }
80
81 namespace WebCore {
82 struct ShareDataWithParsedURL;
83 }
84
85 @protocol WebViewImplDelegate
86
87 - (NSTextInputContext *)_web_superInputContext;
88 - (void)_web_superQuickLookWithEvent:(NSEvent *)event;
89 - (void)_web_superRemoveTrackingRect:(NSTrackingRectTag)tag;
90 - (void)_web_superSwipeWithEvent:(NSEvent *)event;
91 - (void)_web_superMagnifyWithEvent:(NSEvent *)event;
92 - (void)_web_superSmartMagnifyWithEvent:(NSEvent *)event;
93 - (id)_web_superAccessibilityAttributeValue:(NSString *)attribute;
94 - (void)_web_superDoCommandBySelector:(SEL)selector;
95 - (BOOL)_web_superPerformKeyEquivalent:(NSEvent *)event;
96 - (void)_web_superKeyDown:(NSEvent *)event;
97 - (NSView *)_web_superHitTest:(NSPoint)point;
98
99 - (id)_web_immediateActionAnimationControllerForHitTestResultInternal:(API::HitTestResult*)hitTestResult withType:(uint32_t)type userData:(API::Object*)userData;
100 - (void)_web_prepareForImmediateActionAnimation;
101 - (void)_web_cancelImmediateActionAnimation;
102 - (void)_web_completeImmediateActionAnimation;
103
104 - (void)_web_dismissContentRelativeChildWindows;
105 - (void)_web_dismissContentRelativeChildWindowsWithAnimation:(BOOL)animate;
106 - (void)_web_editorStateDidChange;
107
108 - (void)_web_gestureEventWasNotHandledByWebCore:(NSEvent *)event;
109
110 - (void)_web_didChangeContentSize:(NSSize)newSize;
111
112 #if ENABLE(DRAG_SUPPORT)
113 - (WKDragDestinationAction)_web_dragDestinationActionForDraggingInfo:(id <NSDraggingInfo>)draggingInfo;
114 - (void)_web_didPerformDragOperation:(BOOL)handled;
115 #endif
116
117 @optional
118 - (void)_web_didAddMediaControlsManager:(id)controlsManager;
119 - (void)_web_didRemoveMediaControlsManager;
120 - (void)_didHandleAcceptedCandidate;
121 - (void)_didUpdateCandidateListVisibility:(BOOL)visible;
122
123 @end
124
125 namespace WebCore {
126 struct DragItem;
127 struct KeypressCommand;
128 }
129
130 namespace WebKit {
131
132 class PageClient;
133 class PageClientImpl;
134 class DrawingAreaProxy;
135 class SafeBrowsingWarning;
136 class ViewGestureController;
137 class ViewSnapshot;
138 class WebBackForwardListItem;
139 class WebEditCommandProxy;
140 class WebFrameProxy;
141 class WebPageProxy;
142 class WebProcessPool;
143 class WebProcessProxy;
144 struct ColorSpaceData;
145 struct WebHitTestResultData;
146
147 enum class ContinueUnsafeLoad : bool;
148 enum class UndoOrRedo : bool;
149
150 typedef id <NSValidatedUserInterfaceItem> ValidationItem;
151 typedef Vector<RetainPtr<ValidationItem>> ValidationVector;
152 typedef HashMap<String, ValidationVector> ValidationMap;
153
154 class WebViewImpl : public CanMakeWeakPtr<WebViewImpl> {
155     WTF_MAKE_FAST_ALLOCATED;
156     WTF_MAKE_NONCOPYABLE(WebViewImpl);
157 public:
158     WebViewImpl(NSView <WebViewImplDelegate> *, WKWebView *outerWebView, WebProcessPool&, Ref<API::PageConfiguration>&&);
159
160     ~WebViewImpl();
161
162     NSWindow *window();
163
164     WebPageProxy& page() { return m_page.get(); }
165
166     void processWillSwap();
167     void processDidExit();
168     void pageClosed();
169     void didRelaunchProcess();
170
171     void setDrawsBackground(bool);
172     bool drawsBackground() const;
173     void setBackgroundColor(NSColor *);
174     NSColor *backgroundColor() const;
175     bool isOpaque() const;
176
177     void setShouldSuppressFirstResponderChanges(bool);
178     bool acceptsFirstMouse(NSEvent *);
179     bool acceptsFirstResponder();
180     bool becomeFirstResponder();
181     bool resignFirstResponder();
182     bool isFocused() const;
183
184     void viewWillStartLiveResize();
185     void viewDidEndLiveResize();
186
187     void renewGState();
188     void setFrameSize(CGSize);
189     void disableFrameSizeUpdates();
190     void enableFrameSizeUpdates();
191     bool frameSizeUpdatesDisabled() const;
192     void setFrameAndScrollBy(CGRect, CGSize);
193     void updateWindowAndViewFrames();
194
195     void setFixedLayoutSize(CGSize);
196     CGSize fixedLayoutSize() const;
197
198     std::unique_ptr<DrawingAreaProxy> createDrawingAreaProxy(WebProcessProxy&);
199     bool isUsingUISideCompositing() const;
200     void setDrawingAreaSize(CGSize);
201     void updateLayer();
202     static bool wantsUpdateLayer() { return true; }
203
204     void drawRect(CGRect);
205     bool canChangeFrameLayout(WebFrameProxy&);
206     NSPrintOperation *printOperationWithPrintInfo(NSPrintInfo *, WebFrameProxy&);
207
208     void setAutomaticallyAdjustsContentInsets(bool);
209     bool automaticallyAdjustsContentInsets() const { return m_automaticallyAdjustsContentInsets; }
210     void updateContentInsetsIfAutomatic();
211     void setTopContentInset(CGFloat);
212     CGFloat topContentInset() const;
213
214     void prepareContentInRect(CGRect);
215     void updateViewExposedRect();
216     void setClipsToVisibleRect(bool);
217     bool clipsToVisibleRect() const { return m_clipsToVisibleRect; }
218
219     void setMinimumSizeForAutoLayout(CGSize);
220     CGSize minimumSizeForAutoLayout() const;
221     void setShouldExpandToViewHeightForAutoLayout(bool);
222     bool shouldExpandToViewHeightForAutoLayout() const;
223     void setIntrinsicContentSize(CGSize);
224     CGSize intrinsicContentSize() const;
225
226     void setViewScale(CGFloat);
227     CGFloat viewScale() const;
228
229     void showSafeBrowsingWarning(const SafeBrowsingWarning&, CompletionHandler<void(Variant<ContinueUnsafeLoad, URL>&&)>&&);
230     void clearSafeBrowsingWarning();
231     void clearSafeBrowsingWarningIfForMainFrameNavigation();
232
233     WKLayoutMode layoutMode() const;
234     void setLayoutMode(WKLayoutMode);
235     void updateSupportsArbitraryLayoutModes();
236
237     void setOverrideDeviceScaleFactor(CGFloat);
238     CGFloat overrideDeviceScaleFactor() const { return m_overrideDeviceScaleFactor; }
239
240     void windowDidOrderOffScreen();
241     void windowDidOrderOnScreen();
242     void windowDidBecomeKey(NSWindow *);
243     void windowDidResignKey(NSWindow *);
244     void windowDidMiniaturize();
245     void windowDidDeminiaturize();
246     void windowDidMove();
247     void windowDidResize();
248     void windowDidChangeBackingProperties(CGFloat oldBackingScaleFactor);
249     void windowDidChangeScreen();
250     void windowDidChangeLayerHosting();
251     void windowDidChangeOcclusionState();
252     bool shouldDelayWindowOrderingForEvent(NSEvent *);
253     bool windowResizeMouseLocationIsInVisibleScrollerThumb(CGPoint);
254
255     void accessibilitySettingsDidChange();
256
257     // -[NSView mouseDownCanMoveWindow] returns YES when the NSView is transparent,
258     // but we don't want a drag in the NSView to move the window, even if it's transparent.
259     static bool mouseDownCanMoveWindow() { return false; }
260
261     void viewWillMoveToWindow(NSWindow *);
262     void viewDidMoveToWindow();
263     void viewDidChangeBackingProperties();
264     void viewDidHide();
265     void viewDidUnhide();
266     void activeSpaceDidChange();
267
268     NSView *hitTest(CGPoint);
269
270     ColorSpaceData colorSpace();
271
272     void setUnderlayColor(NSColor *);
273     NSColor *underlayColor() const;
274     NSColor *pageExtendedBackgroundColor() const;
275     
276     _WKRectEdge pinnedState();
277     _WKRectEdge rubberBandingEnabled();
278     void setRubberBandingEnabled(_WKRectEdge);
279
280     void setOverlayScrollbarStyle(Optional<WebCore::ScrollbarOverlayStyle> scrollbarStyle);
281     Optional<WebCore::ScrollbarOverlayStyle> overlayScrollbarStyle() const;
282
283     void beginDeferringViewInWindowChanges();
284     // FIXME: Merge these two?
285     void endDeferringViewInWindowChanges();
286     void endDeferringViewInWindowChangesSync();
287     bool isDeferringViewInWindowChanges() const { return m_shouldDeferViewInWindowChanges; }
288
289     void setWindowOcclusionDetectionEnabled(bool enabled) { m_windowOcclusionDetectionEnabled = enabled; }
290     bool windowOcclusionDetectionEnabled() const { return m_windowOcclusionDetectionEnabled; }
291
292     void prepareForMoveToWindow(NSWindow *targetWindow, WTF::Function<void()>&& completionHandler);
293     NSWindow *targetWindowForMovePreparation() const { return m_targetWindowForMovePreparation; }
294
295     void updateSecureInputState();
296     void resetSecureInputState();
297     bool inSecureInputState() const { return m_inSecureInputState; }
298     void notifyInputContextAboutDiscardedComposition();
299     void setPluginComplexTextInputStateAndIdentifier(PluginComplexTextInputState, uint64_t identifier);
300     void disableComplexTextInputIfNecessary();
301     bool handlePluginComplexTextInputKeyDown(NSEvent *);
302     bool tryHandlePluginComplexTextInputKeyDown(NSEvent *);
303     void pluginFocusOrWindowFocusChanged(bool pluginHasFocusAndWindowHasFocus, uint64_t pluginComplexTextInputIdentifier);
304     bool tryPostProcessPluginComplexTextInputKeyDown(NSEvent *);
305     PluginComplexTextInputState pluginComplexTextInputState() const { return m_pluginComplexTextInputState; }
306     uint64_t pluginComplexTextInputIdentifier() const { return m_pluginComplexTextInputIdentifier; }
307     
308     void handleAcceptedAlternativeText(const String&);
309     NSInteger spellCheckerDocumentTag();
310
311     void pressureChangeWithEvent(NSEvent *);
312     NSEvent *lastPressureEvent() { return m_lastPressureEvent.get(); }
313
314 #if ENABLE(FULLSCREEN_API)
315     bool hasFullScreenWindowController() const;
316     WKFullScreenWindowController *fullScreenWindowController();
317     void closeFullScreenWindowController();
318 #endif
319     NSView *fullScreenPlaceholderView();
320     NSWindow *fullScreenWindow();
321
322     bool isEditable() const;
323     bool executeSavedCommandBySelector(SEL);
324     void executeEditCommandForSelector(SEL, const String& argument = String());
325     void registerEditCommand(Ref<WebEditCommandProxy>&&, UndoOrRedo);
326     void clearAllEditCommands();
327     bool writeSelectionToPasteboard(NSPasteboard *, NSArray *types);
328     bool readSelectionFromPasteboard(NSPasteboard *);
329     id validRequestorForSendAndReturnTypes(NSString *sendType, NSString *returnType);
330     void centerSelectionInVisibleArea();
331     void selectionDidChange();
332     
333     void didBecomeEditable();
334     void updateFontManagerIfNeeded();
335     void changeFontFromFontManager();
336     void changeFontAttributesFromSender(id);
337     void changeFontColorFromSender(id);
338     bool validateUserInterfaceItem(id <NSValidatedUserInterfaceItem>);
339     void setEditableElementIsFocused(bool);
340
341     void startSpeaking();
342     void stopSpeaking(id);
343
344     void showGuessPanel(id);
345     void checkSpelling();
346     void changeSpelling(id);
347     void toggleContinuousSpellChecking();
348
349     bool isGrammarCheckingEnabled();
350     void setGrammarCheckingEnabled(bool);
351     void toggleGrammarChecking();
352     void toggleAutomaticSpellingCorrection();
353     void orderFrontSubstitutionsPanel(id);
354     void toggleSmartInsertDelete();
355     bool isAutomaticQuoteSubstitutionEnabled();
356     void setAutomaticQuoteSubstitutionEnabled(bool);
357     void toggleAutomaticQuoteSubstitution();
358     bool isAutomaticDashSubstitutionEnabled();
359     void setAutomaticDashSubstitutionEnabled(bool);
360     void toggleAutomaticDashSubstitution();
361     bool isAutomaticLinkDetectionEnabled();
362     void setAutomaticLinkDetectionEnabled(bool);
363     void toggleAutomaticLinkDetection();
364     bool isAutomaticTextReplacementEnabled();
365     void setAutomaticTextReplacementEnabled(bool);
366     void toggleAutomaticTextReplacement();
367     void uppercaseWord();
368     void lowercaseWord();
369     void capitalizeWord();
370
371     void requestCandidatesForSelectionIfNeeded();
372
373     void preferencesDidChange();
374
375     void setTextIndicator(WebCore::TextIndicator&, WebCore::TextIndicatorWindowLifetime = WebCore::TextIndicatorWindowLifetime::Permanent);
376     void clearTextIndicatorWithAnimation(WebCore::TextIndicatorWindowDismissalAnimation);
377     void setTextIndicatorAnimationProgress(float);
378     void dismissContentRelativeChildWindowsFromViewOnly();
379     void dismissContentRelativeChildWindowsWithAnimation(bool);
380     void dismissContentRelativeChildWindowsWithAnimationFromViewOnly(bool);
381     static void hideWordDefinitionWindow();
382
383     void quickLookWithEvent(NSEvent *);
384     void prepareForDictionaryLookup();
385     void setAllowsLinkPreview(bool);
386     bool allowsLinkPreview() const { return m_allowsLinkPreview; }
387     NSObject *immediateActionAnimationControllerForHitTestResult(API::HitTestResult*, uint32_t type, API::Object* userData);
388     void didPerformImmediateActionHitTest(const WebHitTestResultData&, bool contentPreventsDefault, API::Object* userData);
389     void prepareForImmediateActionAnimation();
390     void cancelImmediateActionAnimation();
391     void completeImmediateActionAnimation();
392     void didChangeContentSize(CGSize);
393     void didHandleAcceptedCandidate();
394     void videoControlsManagerDidChange();
395
396     void setIgnoresNonWheelEvents(bool);
397     bool ignoresNonWheelEvents() const { return m_ignoresNonWheelEvents; }
398     void setIgnoresAllEvents(bool);
399     bool ignoresAllEvents() const { return m_ignoresAllEvents; }
400     void setIgnoresMouseDraggedEvents(bool);
401     bool ignoresMouseDraggedEvents() const { return m_ignoresMouseDraggedEvents; }
402
403     void setAccessibilityWebProcessToken(NSData *);
404     void accessibilityRegisterUIProcessTokens();
405     void updateRemoteAccessibilityRegistration(bool registerProcess);
406     id accessibilityFocusedUIElement();
407     bool accessibilityIsIgnored() const { return false; }
408     id accessibilityHitTest(CGPoint);
409     void enableAccessibilityIfNecessary();
410     id accessibilityAttributeValue(NSString *, id parameter = nil);
411
412     NSTrackingArea *primaryTrackingArea() const { return m_primaryTrackingArea.get(); }
413     void setPrimaryTrackingArea(NSTrackingArea *);
414
415     NSTrackingRectTag addTrackingRect(CGRect, id owner, void* userData, bool assumeInside);
416     NSTrackingRectTag addTrackingRectWithTrackingNum(CGRect, id owner, void* userData, bool assumeInside, int tag);
417     void addTrackingRectsWithTrackingNums(CGRect*, id owner, void** userDataList, bool assumeInside, NSTrackingRectTag *trackingNums, int count);
418     void removeTrackingRect(NSTrackingRectTag);
419     void removeTrackingRects(NSTrackingRectTag *, int count);
420     NSString *stringForToolTip(NSToolTipTag tag);
421     void toolTipChanged(const String& oldToolTip, const String& newToolTip);
422
423     void setAcceleratedCompositingRootLayer(CALayer *);
424     CALayer *acceleratedCompositingRootLayer() const { return m_rootLayer.get(); }
425
426     void setThumbnailView(_WKThumbnailView *);
427     _WKThumbnailView *thumbnailView() const { return m_thumbnailView; }
428
429     void setInspectorAttachmentView(NSView *);
430     NSView *inspectorAttachmentView();
431     
432     void showShareSheet(const WebCore::ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&&, WKWebView *);
433     void shareSheetDidDismiss(WKShareSheet *);
434
435     _WKRemoteObjectRegistry *remoteObjectRegistry();
436
437     ALLOW_DEPRECATED_DECLARATIONS_BEGIN
438     WKBrowsingContextController *browsingContextController();
439     ALLOW_DEPRECATED_DECLARATIONS_END
440
441 #if ENABLE(DRAG_SUPPORT)
442     void draggedImage(NSImage *, CGPoint endPoint, NSDragOperation);
443     NSDragOperation draggingEntered(id <NSDraggingInfo>);
444     NSDragOperation draggingUpdated(id <NSDraggingInfo>);
445     void draggingExited(id <NSDraggingInfo>);
446     bool prepareForDragOperation(id <NSDraggingInfo>);
447     bool performDragOperation(id <NSDraggingInfo>);
448     NSView *hitTestForDragTypes(CGPoint, NSSet *types);
449     void registerDraggedTypes();
450
451     NSDragOperation dragSourceOperationMask(NSDraggingSession *, NSDraggingContext);
452     void draggingSessionEnded(NSDraggingSession *, NSPoint, NSDragOperation);
453
454     NSString *fileNameForFilePromiseProvider(NSFilePromiseProvider *, NSString *fileType);
455     void writeToURLForFilePromiseProvider(NSFilePromiseProvider *, NSURL *, void(^)(NSError *));
456
457     void didPerformDragOperation(bool handled);
458 #endif
459
460     void startWindowDrag();
461
462     void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& image);
463     void setFileAndURLTypes(NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, NSPasteboard *);
464     void setPromisedDataForImage(WebCore::Image*, NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, WebCore::SharedBuffer* archiveBuffer, NSString *pasteboardName);
465     void pasteboardChangedOwner(NSPasteboard *);
466     void provideDataForPasteboard(NSPasteboard *, NSString *type);
467     NSArray *namesOfPromisedFilesDroppedAtDestination(NSURL *dropDestination);
468
469     RefPtr<ViewSnapshot> takeViewSnapshot();
470     void saveBackForwardSnapshotForCurrentItem();
471     void saveBackForwardSnapshotForItem(WebBackForwardListItem&);
472
473     WKSafeBrowsingWarning *safeBrowsingWarning() { return m_safeBrowsingWarning.get(); }
474
475     ViewGestureController* gestureController() { return m_gestureController.get(); }
476     ViewGestureController& ensureGestureController();
477     void setAllowsBackForwardNavigationGestures(bool);
478     bool allowsBackForwardNavigationGestures() const { return m_allowsBackForwardNavigationGestures; }
479     void setAllowsMagnification(bool);
480     bool allowsMagnification() const { return m_allowsMagnification; }
481
482     void setMagnification(double, CGPoint centerPoint);
483     void setMagnification(double);
484     double magnification() const;
485     void setCustomSwipeViews(NSArray *);
486     void setCustomSwipeViewsTopContentInset(float);
487     bool tryToSwipeWithEvent(NSEvent *, bool ignoringPinnedState);
488     void setDidMoveSwipeSnapshotCallback(BlockPtr<void (CGRect)>&&);
489
490     void scrollWheel(NSEvent *);
491     void swipeWithEvent(NSEvent *);
492     void magnifyWithEvent(NSEvent *);
493     void rotateWithEvent(NSEvent *);
494     void smartMagnifyWithEvent(NSEvent *);
495
496     void setLastMouseDownEvent(NSEvent *);
497
498     void gestureEventWasNotHandledByWebCore(NSEvent *);
499     void gestureEventWasNotHandledByWebCoreFromViewOnly(NSEvent *);
500
501     void didRestoreScrollPosition();
502
503     void setTotalHeightOfBanners(CGFloat totalHeightOfBanners) { m_totalHeightOfBanners = totalHeightOfBanners; }
504     CGFloat totalHeightOfBanners() const { return m_totalHeightOfBanners; }
505
506     void doneWithKeyEvent(NSEvent *, bool eventWasHandled);
507     NSArray *validAttributesForMarkedText();
508     void doCommandBySelector(SEL);
509     void insertText(id string);
510     void insertText(id string, NSRange replacementRange);
511     NSTextInputContext *inputContext();
512     void unmarkText();
513     void setMarkedText(id string, NSRange selectedRange, NSRange replacementRange);
514     NSRange selectedRange();
515     bool hasMarkedText();
516     NSRange markedRange();
517     NSAttributedString *attributedSubstringForProposedRange(NSRange, NSRangePointer actualRange);
518     NSUInteger characterIndexForPoint(NSPoint);
519     NSRect firstRectForCharacterRange(NSRange, NSRangePointer actualRange);
520     bool performKeyEquivalent(NSEvent *);
521     void keyUp(NSEvent *);
522     void keyDown(NSEvent *);
523     void flagsChanged(NSEvent *);
524
525     // Override this so that AppKit will send us arrow keys as key down events so we can
526     // support them via the key bindings mechanism.
527     static bool wantsKeyDownForEvent(NSEvent *) { return true; }
528
529     void selectedRangeWithCompletionHandler(void(^)(NSRange));
530     void hasMarkedTextWithCompletionHandler(void(^)(BOOL hasMarkedText));
531     void markedRangeWithCompletionHandler(void(^)(NSRange));
532     void attributedSubstringForProposedRange(NSRange, void(^)(NSAttributedString *attrString, NSRange actualRange));
533     void firstRectForCharacterRange(NSRange, void(^)(NSRect firstRect, NSRange actualRange));
534     void characterIndexForPoint(NSPoint, void(^)(NSUInteger));
535     void typingAttributesWithCompletionHandler(void(^)(NSDictionary<NSString *, id> *));
536
537     void mouseMoved(NSEvent *);
538     void mouseDown(NSEvent *);
539     void mouseUp(NSEvent *);
540     void mouseDragged(NSEvent *);
541     void mouseEntered(NSEvent *);
542     void mouseExited(NSEvent *);
543     void otherMouseDown(NSEvent *);
544     void otherMouseDragged(NSEvent *);
545     void otherMouseUp(NSEvent *);
546     void rightMouseDown(NSEvent *);
547     void rightMouseDragged(NSEvent *);
548     void rightMouseUp(NSEvent *);
549
550     void forceRequestCandidatesForTesting();
551     bool shouldRequestCandidates() const;
552
553     bool windowIsFrontWindowUnderMouse(NSEvent *);
554
555     void setRequiresUserActionForEditingControlsManager(bool requiresUserActionForEditingControlsManager) { m_requiresUserActionForEditingControlsManager = requiresUserActionForEditingControlsManager; }
556     bool requiresUserActionForEditingControlsManager() const { return m_requiresUserActionForEditingControlsManager; }
557
558     WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection();
559     void setUserInterfaceLayoutDirection(NSUserInterfaceLayoutDirection);
560
561     void handleAcceptedCandidate(NSTextCheckingResult *acceptedCandidate);
562
563     void doAfterProcessingAllPendingMouseEvents(dispatch_block_t action);
564     void didFinishProcessingAllPendingMouseEvents();
565
566 #if HAVE(TOUCH_BAR)
567     NSTouchBar *makeTouchBar();
568     void updateTouchBar();
569     NSTouchBar *currentTouchBar() const { return m_currentTouchBar.get(); }
570     NSCandidateListTouchBarItem *candidateListTouchBarItem() const;
571 #if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
572     bool isPictureInPictureActive();
573     void togglePictureInPicture();
574     void updateMediaPlaybackControlsManager();
575
576 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
577     AVTouchBarScrubber *mediaPlaybackControlsView() const;
578 #else
579     AVFunctionBarScrubber *mediaPlaybackControlsView() const;
580 #endif
581 #endif
582     NSTouchBar *textTouchBar() const;
583     void dismissTextTouchBarPopoverItemWithIdentifier(NSString *);
584
585     bool clientWantsMediaPlaybackControlsView() const { return m_clientWantsMediaPlaybackControlsView; }
586     void setClientWantsMediaPlaybackControlsView(bool clientWantsMediaPlaybackControlsView) { m_clientWantsMediaPlaybackControlsView = clientWantsMediaPlaybackControlsView; }
587
588     void updateTouchBarAndRefreshTextBarIdentifiers();
589     void setIsCustomizingTouchBar(bool isCustomizingTouchBar) { m_isCustomizingTouchBar = isCustomizingTouchBar; };
590
591     bool canTogglePictureInPicture();
592 #endif // HAVE(TOUCH_BAR)
593
594     bool beginBackSwipeForTesting();
595     bool completeBackSwipeForTesting();
596     
597     void setUseSystemAppearance(bool);
598     bool useSystemAppearance();
599
600     void effectiveAppearanceDidChange();
601     bool effectiveAppearanceIsDark();
602     bool effectiveAppearanceIsInactive();
603
604     void takeFocus(WebCore::FocusDirection);
605
606 private:
607 #if HAVE(TOUCH_BAR)
608     void setUpTextTouchBar(NSTouchBar *);
609     void updateTextTouchBar();
610     void updateMediaTouchBar();
611
612     bool useMediaPlaybackControlsView() const;
613     bool isRichlyEditableForTouchBar() const;
614
615     bool m_clientWantsMediaPlaybackControlsView { false };
616     bool m_canCreateTouchBars { false };
617     bool m_startedListeningToCustomizationEvents { false };
618     bool m_isUpdatingTextTouchBar { false };
619     bool m_isCustomizingTouchBar { false };
620
621     RetainPtr<NSTouchBar> m_currentTouchBar;
622     RetainPtr<NSTouchBar> m_richTextTouchBar;
623     RetainPtr<NSTouchBar> m_plainTextTouchBar;
624     RetainPtr<NSTouchBar> m_passwordTextTouchBar;
625     RetainPtr<WKTextTouchBarItemController> m_textTouchBarItemController;
626     RetainPtr<NSCandidateListTouchBarItem> m_richTextCandidateListTouchBarItem;
627     RetainPtr<NSCandidateListTouchBarItem> m_plainTextCandidateListTouchBarItem;
628     RetainPtr<NSCandidateListTouchBarItem> m_passwordTextCandidateListTouchBarItem;
629     RetainPtr<WebPlaybackControlsManager> m_playbackControlsManager;
630     RetainPtr<NSCustomTouchBarItem> m_exitFullScreenButton;
631
632 #if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
633 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
634     RetainPtr<AVTouchBarPlaybackControlsProvider> m_mediaTouchBarProvider;
635     RetainPtr<AVTouchBarScrubber> m_mediaPlaybackControlsView;
636 #else
637     RetainPtr<AVFunctionBarPlaybackControlsProvider> m_mediaTouchBarProvider;
638     RetainPtr<AVFunctionBarScrubber> m_mediaPlaybackControlsView;
639 #endif
640 #endif // ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
641 #endif // HAVE(TOUCH_BAR)
642
643     bool supportsArbitraryLayoutModes() const;
644     float intrinsicDeviceScaleFactor() const;
645     void dispatchSetTopContentInset();
646
647     void postFakeMouseMovedEventForFlagsChangedEvent(NSEvent *);
648
649     void setPluginComplexTextInputState(PluginComplexTextInputState);
650
651     void sendToolTipMouseExited();
652     void sendToolTipMouseEntered();
653
654     void reparentLayerTreeInThumbnailView();
655     void updateThumbnailViewLayer();
656
657     void setUserInterfaceItemState(NSString *commandName, bool enabled, int state);
658
659     Vector<WebCore::KeypressCommand> collectKeyboardLayoutCommandsForEvent(NSEvent *);
660     void interpretKeyEvent(NSEvent *, void(^completionHandler)(BOOL handled, const Vector<WebCore::KeypressCommand>&));
661
662     void mouseMovedInternal(NSEvent *);
663     void mouseDownInternal(NSEvent *);
664     void mouseUpInternal(NSEvent *);
665     void mouseDraggedInternal(NSEvent *);
666
667     void handleProcessSwapOrExit();
668
669     bool mightBeginDragWhileInactive();
670     bool mightBeginScrollWhileInactive();
671
672     void handleRequestedCandidates(NSInteger sequenceNumber, NSArray<NSTextCheckingResult *> *candidates);
673     void flushPendingMouseEventCallbacks();
674
675 #if ENABLE(DRAG_SUPPORT)
676     void sendDragEndToPage(CGPoint endPoint, NSDragOperation);
677 #endif
678
679     WeakObjCPtr<NSView<WebViewImplDelegate>> m_view;
680     std::unique_ptr<PageClient> m_pageClient;
681     Ref<WebPageProxy> m_page;
682
683     bool m_willBecomeFirstResponderAgain { false };
684     bool m_inBecomeFirstResponder { false };
685     bool m_inResignFirstResponder { false };
686
687     CGRect m_contentPreparationRect { { 0, 0 }, { 0, 0 } };
688     bool m_useContentPreparationRectForVisibleRect { false };
689     bool m_clipsToVisibleRect { false };
690     bool m_needsViewFrameInWindowCoordinates;
691     bool m_didScheduleWindowAndViewFrameUpdate { false };
692     bool m_windowOcclusionDetectionEnabled { true };
693
694     bool m_automaticallyAdjustsContentInsets { false };
695     CGFloat m_pendingTopContentInset { 0 };
696     bool m_didScheduleSetTopContentInset { false };
697     
698     CGSize m_scrollOffsetAdjustment { 0, 0 };
699
700     CGSize m_intrinsicContentSize { 0, 0 };
701     CGFloat m_overrideDeviceScaleFactor { 0 };
702
703     RetainPtr<WKViewLayoutStrategy> m_layoutStrategy;
704     WKLayoutMode m_lastRequestedLayoutMode { kWKLayoutModeViewSize };
705     CGFloat m_lastRequestedViewScale { 1 };
706     CGSize m_lastRequestedFixedLayoutSize { 0, 0 };
707
708     bool m_inSecureInputState { false };
709     RetainPtr<WKEditorUndoTarget> m_undoTarget;
710
711     ValidationMap m_validationMap;
712
713     // The identifier of the plug-in we want to send complex text input to, or 0 if there is none.
714     uint64_t m_pluginComplexTextInputIdentifier { 0 };
715
716     // The state of complex text input for the plug-in.
717     PluginComplexTextInputState m_pluginComplexTextInputState { PluginComplexTextInputDisabled };
718
719 #if ENABLE(FULLSCREEN_API)
720     RetainPtr<WKFullScreenWindowController> m_fullScreenWindowController;
721 #endif
722     
723     RetainPtr<WKShareSheet> _shareSheet;
724
725     RetainPtr<WKWindowVisibilityObserver> m_windowVisibilityObserver;
726     RetainPtr<WKAccessibilitySettingsObserver> m_accessibilitySettingsObserver;
727
728     bool m_shouldDeferViewInWindowChanges { false };
729     bool m_viewInWindowChangeWasDeferred { false };
730     NSWindow *m_targetWindowForMovePreparation { nullptr };
731
732     id m_flagsChangedEventMonitor { nullptr };
733
734     std::unique_ptr<WebCore::TextIndicatorWindow> m_textIndicatorWindow;
735
736     RetainPtr<NSColorSpace> m_colorSpace;
737
738     RetainPtr<NSColor> m_backgroundColor;
739
740     RetainPtr<NSEvent> m_lastMouseDownEvent;
741     RetainPtr<NSEvent> m_lastPressureEvent;
742
743     bool m_ignoresNonWheelEvents { false };
744     bool m_ignoresAllEvents { false };
745     bool m_ignoresMouseDraggedEvents { false };
746
747     RetainPtr<WKImmediateActionController> m_immediateActionController;
748     RetainPtr<NSImmediateActionGestureRecognizer> m_immediateActionGestureRecognizer;
749
750     bool m_allowsLinkPreview { true };
751
752     RetainPtr<NSTrackingArea> m_primaryTrackingArea;
753
754     NSToolTipTag m_lastToolTipTag { 0 };
755     id m_trackingRectOwner { nil };
756     void* m_trackingRectUserData { nullptr };
757
758     RetainPtr<CALayer> m_rootLayer;
759     RetainPtr<NSView> m_layerHostingView;
760
761     _WKThumbnailView *m_thumbnailView { nullptr };
762
763     RetainPtr<_WKRemoteObjectRegistry> m_remoteObjectRegistry;
764
765     ALLOW_DEPRECATED_DECLARATIONS_BEGIN
766     RetainPtr<WKBrowsingContextController> m_browsingContextController;
767     ALLOW_DEPRECATED_DECLARATIONS_END
768
769     std::unique_ptr<ViewGestureController> m_gestureController;
770     bool m_allowsBackForwardNavigationGestures { false };
771     bool m_allowsMagnification { false };
772
773     RetainPtr<NSAccessibilityRemoteUIElement> m_remoteAccessibilityChild;
774
775     RefPtr<WebCore::Image> m_promisedImage;
776     String m_promisedFilename;
777     String m_promisedURL;
778
779     Optional<NSInteger> m_spellCheckerDocumentTag;
780
781     CGFloat m_totalHeightOfBanners { 0 };
782
783     RetainPtr<NSView> m_inspectorAttachmentView;
784
785     // We keep here the event when resending it to
786     // the application to distinguish the case of a new event from one
787     // that has been already sent to WebCore.
788     RetainPtr<NSEvent> m_keyDownEventBeingResent;
789     Vector<WebCore::KeypressCommand>* m_collectedKeypressCommands { nullptr };
790     Vector<BlockPtr<void()>> m_callbackHandlersAfterProcessingPendingMouseEvents;
791
792     String m_lastStringForCandidateRequest;
793     NSInteger m_lastCandidateRequestSequenceNumber;
794     NSRange m_softSpaceRange { NSNotFound, 0 };
795     bool m_isHandlingAcceptedCandidate { false };
796     bool m_requiresUserActionForEditingControlsManager { false };
797     bool m_editableElementIsFocused { false };
798     bool m_isTextInsertionReplacingSoftSpace { false };
799     RetainPtr<WKSafeBrowsingWarning> m_safeBrowsingWarning;
800     
801 #if ENABLE(DRAG_SUPPORT)
802     NSInteger m_initialNumberOfValidItemsForDrop { 0 };
803 #endif
804
805 };
806     
807 } // namespace WebKit
808
809 #endif // PLATFORM(MAC)