Fix the iOS build
[WebKit-https.git] / Source / WebKit / mac / WebView / WebView.mm
index 2547bdb..6c66875 100644 (file)
@@ -97,6 +97,7 @@
 #import "WebProgressTrackerClient.h"
 #import "WebScriptDebugDelegate.h"
 #import "WebScriptWorldInternal.h"
+#import "WebSelectionServiceController.h"
 #import "WebStorageManagerInternal.h"
 #import "WebSystemInterface.h"
 #import "WebTextCompletionController.h"
 #import <wtf/StdLibExtras.h>
 
 #if !PLATFORM(IOS)
+#import "WebActionMenuController.h"
 #import "WebContextMenuClient.h"
 #import "WebFullScreenController.h"
 #import "WebNSEventExtras.h"
 #import "WebNSPasteboardExtras.h"
 #import "WebNSPrintOperationExtras.h"
 #import "WebPDFView.h"
+#import <WebCore/NSViewSPI.h>
 #import <WebCore/WebVideoFullscreenController.h>
 #else
 #import "MemoryMeasure.h"
 #import <WebKitLegacy/WebDashboardRegion.h>
 #endif
 
-#if ENABLE(DISK_IMAGE_CACHE) && PLATFORM(IOS)
-#import "WebDiskImageCacheClientIOS.h"
-#import <WebCore/DiskImageCacheIOS.h>
-#endif
-
 #if ENABLE(REMOTE_INSPECTOR)
 #import <JavaScriptCore/RemoteInspector.h>
 #if PLATFORM(IOS)
 #import <WebCore/WebEventRegion.h>
 #endif
 
-#if ENABLE(DISK_IMAGE_CACHE)
-#import "WebDiskImageCacheClientIOS.h"
-#import <WebCore/DiskImageCacheIOS.h>
-#endif
-
 #if ENABLE(GAMEPAD)
 #import <WebCore/HIDGamepadProvider.h>
 #endif
@@ -903,9 +896,6 @@ static void WebKitInitializeGamepadProviderIfNecessary()
 #endif
         WebKitInitializeStorageIfNecessary();
         WebKitInitializeApplicationCachePathIfNecessary();
-#if ENABLE(DISK_IMAGE_CACHE) && PLATFORM(IOS)
-        WebKitInitializeWebDiskImageCache();
-#endif
 #if ENABLE(GAMEPAD)
         WebKitInitializeGamepadProviderIfNecessary();
 #endif
@@ -1073,6 +1063,12 @@ static void WebKitInitializeGamepadProviderIfNecessary()
     [self setMaintainsBackForwardList: YES];
 #if !PLATFORM(IOS)
     _private->page->setDeviceScaleFactor([self _deviceScaleFactor]);
+
+    if ([self respondsToSelector:@selector(setActionMenu:)]) {
+        RetainPtr<NSMenu> actionMenu = adoptNS([[NSMenu alloc] init]);
+        self.actionMenu = actionMenu.get();
+        _private->actionMenuController = [[WebActionMenuController alloc] initWithWebView:self];
+    }
 #endif
     return self;
 }
@@ -1230,13 +1226,6 @@ static void WebKitInitializeGamepadProviderIfNecessary()
 
     tileControllerMemoryHandler().trimUnparentedTilesToTarget(0);
 
-#if ENABLE(DISK_IMAGE_CACHE)
-    {
-        WebKit::MemoryMeasure measurer("Memory warning: flushing images to disk.");
-        WebCore::memoryCache()->flushCachedImagesToDisk();
-    }
-#endif
-
     [WebStorageManager closeIdleLocalStorageDatabases];
 
     [WebView _releaseMemoryNow];
@@ -1721,6 +1710,7 @@ static bool fastDocumentTeardownEnabled()
     [self setUIDelegate:nil];
 
     [_private->inspector webViewClosed];
+    [_private->actionMenuController webViewClosed];
 #endif
 
 #if !PLATFORM(IOS)
@@ -2298,13 +2288,13 @@ static bool needsSelfRetainWhileLoadingQuirk()
     settings.setPlugInSnapshottingEnabled([preferences plugInSnapshottingEnabled]);
 
     settings.setFixedPositionCreatesStackingContext(true);
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
     settings.setAcceleratedCompositingForFixedPositionEnabled(true);
 #endif
 
 #if ENABLE(RUBBER_BANDING)
     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=136131
-    settings.setRubberBandingForOverflowScrollEnabled(false);
+    settings.setRubberBandingForSubScrollableRegionsEnabled(false);
 #endif
 
 #if PLATFORM(IOS)
@@ -2353,9 +2343,6 @@ static bool needsSelfRetainWhileLoadingQuirk()
     settings.setShowsURLsInToolTips([preferences showsURLsInToolTips]);
     settings.setShowsToolTipOverTruncatedText([preferences showsToolTipOverTruncatedText]);
     settings.setQTKitEnabled([preferences isQTKitEnabled]);
-
-    // FIXME: Should we enable this following <rdar://problem/15290404>?
-    settings.setMultithreadedWebGLEnabled([preferences multithreadedWebGLEnabled]);
 #endif // PLATFORM(MAC)
 
 #if ENABLE(SQL_DATABASE)
@@ -2368,6 +2355,7 @@ static bool needsSelfRetainWhileLoadingQuirk()
 
 #if ENABLE(SERVICE_CONTROLS)
     settings.setImageControlsEnabled([preferences imageControlsEnabled]);
+    settings.setServiceControlsEnabled([preferences serviceControlsEnabled]);
 #endif
 
 #if ENABLE(VIDEO_TRACK)
@@ -2409,13 +2397,6 @@ static bool needsSelfRetainWhileLoadingQuirk()
     if (_private->zoomsTextOnly != zoomsTextOnly)
         [self _setZoomMultiplier:_private->zoomMultiplier isTextOnly:zoomsTextOnly];
 
-#if ENABLE(DISK_IMAGE_CACHE) && PLATFORM(IOS)
-    DiskImageCache& diskImageCache = WebCore::diskImageCache();
-    diskImageCache.setEnabled([preferences diskImageCacheEnabled]);
-    diskImageCache.setMinimumImageSize([preferences diskImageCacheMinimumImageSize]);
-    diskImageCache.setMaximumCacheSize([preferences diskImageCacheMaximumCacheSize]);
-#endif
-
 #if PLATFORM(IOS)
     [[self window] setTileBordersVisible:[preferences showDebugBorders]];
     [[self window] setTilePaintCountsVisible:[preferences showRepaintCounter]];
@@ -2988,8 +2969,8 @@ static inline IMP getMethod(id o, SEL s)
     NSView *documentView = [[kit(&frameView->frame()) frameView] documentView];
 
     for (const auto& widget: frameView->children()) {
-        if (widget->isFrameView()) {
-            [self _addScrollerDashboardRegionsForFrameView:toFrameView(widget.get()) dashboardRegions:regions];
+        if (is<FrameView>(*widget)) {
+            [self _addScrollerDashboardRegionsForFrameView:downcast<FrameView>(widget.get()) dashboardRegions:regions];
             continue;
         }
 
@@ -3687,6 +3668,11 @@ static inline IMP getMethod(id o, SEL s)
         if (rect.isEmpty())
             continue;
 
+        // Note that these rectangles are in the coordinate system of the document (inside the WebHTMLView), which is not
+        // the same as the coordinate system of the WebView. If you want to do comparisons with locations in the WebView,
+        // you must convert between the two using WAKView's convertRect:toView: selector. This will take care of scaling
+        // and translations (which are relevant for right-to-left column layout).
+
         // The event region wants this points in this order:
         //  p2------p3
         //  |       |
@@ -8520,6 +8506,15 @@ static void glibContextIterationCallback(CFRunLoopObserverRef, CFRunLoopActivity
 }
 #endif
 
+#if ENABLE(SERVICE_CONTROLS)
+- (WebSelectionServiceController&)_selectionServiceController
+{
+    if (!_private->_selectionServiceController)
+        _private->_selectionServiceController = std::make_unique<WebSelectionServiceController>(self);
+    return *_private->_selectionServiceController;
+}
+#endif
+
 - (NSPoint)_convertPointFromRootView:(NSPoint)point
 {
     return NSMakePoint(point.x, [self bounds].size.height - point.y);
@@ -8530,6 +8525,16 @@ static void glibContextIterationCallback(CFRunLoopObserverRef, CFRunLoopActivity
     return NSMakeRect(rect.origin.x, [self bounds].size.height - rect.origin.y - rect.size.height, rect.size.width, rect.size.height);
 }
 
+#if !PLATFORM(IOS)
+- (void)prepareForMenu:(NSMenu *)menu withEvent:(NSEvent *)event
+{
+    if (menu != self.actionMenu)
+        return;
+
+    [_private->actionMenuController prepareForMenu:menu withEvent:event];
+}
+#endif
+
 @end
 
 @implementation WebView (WebViewDeviceOrientation)
@@ -8648,7 +8653,7 @@ static void glibContextIterationCallback(CFRunLoopObserverRef, CFRunLoopActivity
 {
 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
     JSContextRef context = [[self mainFrame] globalContext];
-    WebCore::Notification* notification = toNotification(toJS(toJS(context), jsNotification));
+    WebCore::Notification* notification = JSNotification::toWrapped(toJS(toJS(context), jsNotification));
     return static_cast<WebNotificationClient*>(NotificationController::clientFrom(_private->page))->notificationIDForTesting(notification);
 #else
     return 0;