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