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