Title: [239628] trunk/Source/WebKit
Revision
239628
Author
[email protected]
Date
2019-01-04 12:24:26 -0800 (Fri, 04 Jan 2019)

Log Message

Share ink choice and ruler between all editable images
https://bugs.webkit.org/show_bug.cgi?id=193130
<rdar://problem/46826491>

Reviewed by Wenson Hsieh.

* SourcesCocoa.txt:
Add WKDrawingCoordinator, which maintains WKWebView-wide drawing state,
and manages a single shared ink picker.

* UIProcess/PageClient.h:
(WebKit::PageClient::createDrawingView):
* UIProcess/ios/EditableImageController.mm:
(WebKit::EditableImageController::ensureEditableImage):
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::createDrawingView):
Plumb WKDrawingView creation through PageClient, so that it can be instantiated
with knowledge of its owning WKContentView.

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):
(-[WKContentView _elementDidBlur]):
(-[WKContentView _drawingCoordinator]):
(-[WKContentView _installInkPickerForDrawingViewWithID:]): Deleted.
(-[WKContentView _uninstallInkPicker]): Deleted.
Move ink picker management into WKDrawingCoordinator.

* UIProcess/ios/WKDrawingView.h:
* UIProcess/ios/WKDrawingView.mm:
(-[WKDrawingView initWithEmbeddedViewID:contentView:]):
(-[WKDrawingView _canvasViewWillBeginDrawing:]):
(-[WKDrawingView invalidateAttachment]):
(-[WKDrawingView didChangeRulerState:]):
(-[WKDrawingView initWithEmbeddedViewID:webPageProxy:]): Deleted.
(-[WKDrawingView canvasView]): Deleted.
Use a shared ruler, owned by WKDrawingCoordinator.
Update the editable image's ink when drawing begins. This way, we don't have
to push ink changes to all drawings as they happen.

* UIProcess/ios/WKInkPickerView.h:
* UIProcess/ios/WKInkPickerView.mm:
(-[WKInkPickerView initWithContentView:]):
(-[WKInkPickerView inlineInkPickerDidToggleRuler:]):
(-[WKInkPickerView viewControllerForPopoverPresentationFromInlineInkPicker:]):
(-[WKInkPickerView setInk:]):
(-[WKInkPickerView ink]):
(-[WKInkPickerView initWithDrawingView:]): Deleted.
(-[WKInkPickerView didPickInk]): Deleted.
(-[WKInkPickerView inlineInkPicker:didSelectTool:]): Deleted.
(-[WKInkPickerView inlineInkPicker:didSelectColor:]): Deleted.
* WebKit.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (239627 => 239628)


--- trunk/Source/WebKit/ChangeLog	2019-01-04 19:56:51 UTC (rev 239627)
+++ trunk/Source/WebKit/ChangeLog	2019-01-04 20:24:26 UTC (rev 239628)
@@ -1,3 +1,59 @@
+2019-01-04  Tim Horton  <[email protected]>
+
+        Share ink choice and ruler between all editable images
+        https://bugs.webkit.org/show_bug.cgi?id=193130
+        <rdar://problem/46826491>
+
+        Reviewed by Wenson Hsieh.
+
+        * SourcesCocoa.txt:
+        Add WKDrawingCoordinator, which maintains WKWebView-wide drawing state,
+        and manages a single shared ink picker.
+
+        * UIProcess/PageClient.h:
+        (WebKit::PageClient::createDrawingView):
+        * UIProcess/ios/EditableImageController.mm:
+        (WebKit::EditableImageController::ensureEditableImage):
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::createDrawingView):
+        Plumb WKDrawingView creation through PageClient, so that it can be instantiated
+        with knowledge of its owning WKContentView.
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):
+        (-[WKContentView _elementDidBlur]):
+        (-[WKContentView _drawingCoordinator]):
+        (-[WKContentView _installInkPickerForDrawingViewWithID:]): Deleted.
+        (-[WKContentView _uninstallInkPicker]): Deleted.
+        Move ink picker management into WKDrawingCoordinator.
+
+        * UIProcess/ios/WKDrawingView.h:
+        * UIProcess/ios/WKDrawingView.mm:
+        (-[WKDrawingView initWithEmbeddedViewID:contentView:]):
+        (-[WKDrawingView _canvasViewWillBeginDrawing:]):
+        (-[WKDrawingView invalidateAttachment]):
+        (-[WKDrawingView didChangeRulerState:]):
+        (-[WKDrawingView initWithEmbeddedViewID:webPageProxy:]): Deleted.
+        (-[WKDrawingView canvasView]): Deleted.
+        Use a shared ruler, owned by WKDrawingCoordinator.
+        Update the editable image's ink when drawing begins. This way, we don't have
+        to push ink changes to all drawings as they happen.
+
+        * UIProcess/ios/WKInkPickerView.h:
+        * UIProcess/ios/WKInkPickerView.mm:
+        (-[WKInkPickerView initWithContentView:]):
+        (-[WKInkPickerView inlineInkPickerDidToggleRuler:]):
+        (-[WKInkPickerView viewControllerForPopoverPresentationFromInlineInkPicker:]):
+        (-[WKInkPickerView setInk:]):
+        (-[WKInkPickerView ink]):
+        (-[WKInkPickerView initWithDrawingView:]): Deleted.
+        (-[WKInkPickerView didPickInk]): Deleted.
+        (-[WKInkPickerView inlineInkPicker:didSelectTool:]): Deleted.
+        (-[WKInkPickerView inlineInkPicker:didSelectColor:]): Deleted.
+        * WebKit.xcodeproj/project.pbxproj:
+
 2019-01-04  Wenson Hsieh  <[email protected]>
 
         [Cocoa] Merge WebEditCommandProxy::nameForEditAction and undoNameForEditAction into a single function

Modified: trunk/Source/WebKit/SourcesCocoa.txt (239627 => 239628)


--- trunk/Source/WebKit/SourcesCocoa.txt	2019-01-04 19:56:51 UTC (rev 239627)
+++ trunk/Source/WebKit/SourcesCocoa.txt	2019-01-04 20:24:26 UTC (rev 239628)
@@ -389,6 +389,7 @@
 UIProcess/ios/WKApplicationStateTrackingView.mm
 UIProcess/ios/WKContentView.mm @no-unify
 UIProcess/ios/WKContentViewInteraction.mm @no-unify
+UIProcess/ios/WKDrawingCoordinator.mm
 UIProcess/ios/WKDrawingView.mm
 UIProcess/ios/WKGeolocationProviderIOS.mm
 UIProcess/ios/WKGeolocationProviderIOSObjCSecurityOrigin.mm

Modified: trunk/Source/WebKit/UIProcess/PageClient.h (239627 => 239628)


--- trunk/Source/WebKit/UIProcess/PageClient.h	2019-01-04 19:56:51 UTC (rev 239627)
+++ trunk/Source/WebKit/UIProcess/PageClient.h	2019-01-04 20:24:26 UTC (rev 239628)
@@ -49,6 +49,7 @@
 OBJC_CLASS CALayer;
 OBJC_CLASS NSFileWrapper;
 OBJC_CLASS NSSet;
+OBJC_CLASS WKDrawingView;
 OBJC_CLASS _WKRemoteObjectRegistry;
 
 #if USE(APPKIT)
@@ -462,6 +463,10 @@
     virtual NSSet *serializableFileWrapperClasses() const { return nullptr; }
 #endif
 #endif
+
+#if HAVE(PENCILKIT)
+    virtual RetainPtr<WKDrawingView> createDrawingView(WebCore::GraphicsLayer::EmbeddedViewID) { return nullptr; }
+#endif
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/ios/EditableImageController.mm (239627 => 239628)


--- trunk/Source/WebKit/UIProcess/ios/EditableImageController.mm	2019-01-04 19:56:51 UTC (rev 239627)
+++ trunk/Source/WebKit/UIProcess/ios/EditableImageController.mm	2019-01-04 20:24:26 UTC (rev 239628)
@@ -30,6 +30,7 @@
 
 #import "APIAttachment.h"
 #import "EditableImageControllerMessages.h"
+#import "PageClientImplIOS.h"
 #import "PencilKitSPI.h"
 #import "WKDrawingView.h"
 #import "WebPageProxy.h"
@@ -56,7 +57,7 @@
 {
     auto result = m_editableImages.ensure(embeddedViewID, [&] {
         std::unique_ptr<EditableImage> image = std::make_unique<EditableImage>();
-        image->drawingView = adoptNS([[WKDrawingView alloc] initWithEmbeddedViewID:embeddedViewID webPageProxy:*m_webPageProxy]);
+        image->drawingView = m_webPageProxy->pageClient().createDrawingView(embeddedViewID);
         return image;
     });
     return *result.iterator->value;

Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h (239627 => 239628)


--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h	2019-01-04 19:56:51 UTC (rev 239627)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h	2019-01-04 20:24:26 UTC (rev 239628)
@@ -228,6 +228,10 @@
 
     void didFinishProcessingAllPendingMouseEvents() final { }
 
+#if HAVE(PENCILKIT)
+    RetainPtr<WKDrawingView> createDrawingView(WebCore::GraphicsLayer::EmbeddedViewID) override;
+#endif
+
     WKContentView *m_contentView;
     RetainPtr<WKEditorUndoTarget> m_undoTarget;
 };

Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm (239627 => 239628)


--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2019-01-04 19:56:51 UTC (rev 239627)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2019-01-04 20:24:26 UTC (rev 239628)
@@ -41,6 +41,7 @@
 #import "ViewSnapshotStore.h"
 #import "WKContentView.h"
 #import "WKContentViewInteraction.h"
+#import "WKDrawingView.h"
 #import "WKEditCommand.h"
 #import "WKGeolocationProviderIOS.h"
 #import "WKPasswordView.h"
@@ -817,6 +818,13 @@
 }
 #endif
 
+#if HAVE(PENCILKIT)
+RetainPtr<WKDrawingView> PageClientImpl::createDrawingView(WebCore::GraphicsLayer::EmbeddedViewID embeddedViewID)
+{
+    return adoptNS([[WKDrawingView alloc] initWithEmbeddedViewID:embeddedViewID contentView:m_contentView]);
+}
+#endif
+
 } // namespace WebKit
 
 #endif // PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (239627 => 239628)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2019-01-04 19:56:51 UTC (rev 239627)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2019-01-04 20:24:26 UTC (rev 239628)
@@ -93,10 +93,10 @@
 @class UIHoverGestureRecognizer;
 @class WebEvent;
 @class WKActionSheetAssistant;
+@class WKDrawingCoordinator;
 @class WKFocusedFormControlView;
 @class WKFormInputControl;
 @class WKFormInputSession;
-@class WKInkPickerView;
 @class WKInspectorNodeSearchGestureRecognizer;
 
 typedef void (^UIWKAutocorrectionCompletionHandler)(UIWKAutocorrectionRects *rectsForInput);
@@ -278,7 +278,7 @@
 #endif
 
 #if HAVE(PENCILKIT)
-    RetainPtr<WKInkPickerView> _inkPicker;
+    RetainPtr<WKDrawingCoordinator> _drawingCoordinator;
 #endif
 
     BOOL _isEditable;
@@ -440,6 +440,10 @@
 - (void)updateTextSuggestionsForInputDelegate;
 #endif
 
+#if HAVE(PENCILKIT)
+- (WKDrawingCoordinator *)_drawingCoordinator;
+#endif
+
 @end
 
 @interface WKContentView (WKTesting)

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (239627 => 239628)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-01-04 19:56:51 UTC (rev 239627)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-01-04 20:24:26 UTC (rev 239628)
@@ -42,6 +42,7 @@
 #import "UIKitSPI.h"
 #import "WKActionSheetAssistant.h"
 #import "WKDatePickerViewController.h"
+#import "WKDrawingCoordinator.h"
 #import "WKError.h"
 #import "WKFocusedFormControlView.h"
 #import "WKFormInputControl.h"
@@ -848,6 +849,8 @@
     [_keyboardScrollingAnimator invalidate];
     _keyboardScrollingAnimator = nil;
 
+    _drawingCoordinator = nil;
+
 #if ENABLE(DATALIST_ELEMENT)
     _dataListTextSuggestionsInputView = nil;
     _dataListTextSuggestions = nil;
@@ -4497,7 +4500,7 @@
 
 #if HAVE(PENCILKIT)
     if (information.elementType == WebKit::InputType::Drawing)
-        [self _installInkPickerForDrawingViewWithID:information.embeddedViewID];
+        [_drawingCoordinator installInkPickerForDrawing:information.embeddedViewID];
 #endif
 
     if (!shouldShowKeyboard)
@@ -4589,8 +4592,7 @@
     SetForScope<BOOL> isBlurringFocusedNodeForScope { _isBlurringFocusedNode, YES };
 
 #if HAVE(PENCILKIT)
-    if (_inkPicker)
-        [self _uninstallInkPicker];
+    [_drawingCoordinator uninstallInkPicker];
 #endif
 
     [_formInputSession invalidate];
@@ -6293,27 +6295,12 @@
 #endif
 
 #if HAVE(PENCILKIT)
-- (void)_installInkPickerForDrawingViewWithID:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID
+- (WKDrawingCoordinator *)_drawingCoordinator
 {
-    _inkPicker = adoptNS([[WKInkPickerView alloc] initWithDrawingView:_page->editableImageController().editableImage(embeddedViewID)->drawingView.get()]);
-    [_inkPicker sizeToFit];
-    [_inkPicker setTranslatesAutoresizingMaskIntoConstraints:NO];
-    [_webView addSubview:_inkPicker.get()];
-
-    [NSLayoutConstraint activateConstraints:@[
-        [[_inkPicker heightAnchor] constraintEqualToConstant:[_inkPicker frame].size.height],
-        [[_inkPicker bottomAnchor] constraintEqualToAnchor:_webView.safeAreaLayoutGuide.bottomAnchor],
-        [[_inkPicker leftAnchor] constraintEqualToAnchor:_webView.safeAreaLayoutGuide.leftAnchor],
-        [[_inkPicker rightAnchor] constraintEqualToAnchor:_webView.safeAreaLayoutGuide.rightAnchor],
-    ]];
+    if (!_drawingCoordinator)
+        _drawingCoordinator = adoptNS([[WKDrawingCoordinator alloc] initWithContentView:self]);
+    return _drawingCoordinator.get();
 }
-
-- (void)_uninstallInkPicker
-{
-    [_inkPicker removeFromSuperview];
-    _inkPicker = nil;
-}
-
 #endif // HAVE(PENCILKIT)
 
 @end

Copied: trunk/Source/WebKit/UIProcess/ios/WKDrawingCoordinator.h (from rev 239627, trunk/Source/WebKit/UIProcess/ios/WKInkPickerView.h) (0 => 239628)


--- trunk/Source/WebKit/UIProcess/ios/WKDrawingCoordinator.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/ios/WKDrawingCoordinator.h	2019-01-04 20:24:26 UTC (rev 239628)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE(PENCILKIT)
+
+#import <WebCore/GraphicsLayer.h>
+
+OBJC_CLASS PKInk;
+OBJC_CLASS WKContentView;
+OBJC_CLASS WKInkPickerView;
+
+@interface WKDrawingCoordinator : NSObject
+
+- (instancetype)init NS_UNAVAILABLE;
+- (instancetype)initWithContentView:(WKContentView *)contentView;
+
+- (void)installInkPickerForDrawing:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID;
+- (void)uninstallInkPicker;
+
+- (void)didChangeRulerState:(BOOL)rulerEnabled;
+- (void)didChangeInk:(PKInk *)ink;
+
+@property (nonatomic, readonly, retain) WKInkPickerView *inkPicker;
+
+@end
+
+
+#endif // HAVE(PENCILKIT)

Added: trunk/Source/WebKit/UIProcess/ios/WKDrawingCoordinator.mm (0 => 239628)


--- trunk/Source/WebKit/UIProcess/ios/WKDrawingCoordinator.mm	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/ios/WKDrawingCoordinator.mm	2019-01-04 20:24:26 UTC (rev 239628)
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WKDrawingCoordinator.h"
+
+#if HAVE(PENCILKIT)
+
+#import "EditableImageController.h"
+#import "WKContentViewInteraction.h"
+#import "WKInkPickerView.h"
+#import "WKWebView.h"
+#import <wtf/RetainPtr.h>
+
+#import "PencilKitSoftLink.h"
+
+@interface WKDrawingCoordinator () <PKRulerHostingDelegate>
+@end
+
+@implementation WKDrawingCoordinator {
+    __weak WKContentView *_contentView;
+
+    RetainPtr<WKInkPickerView> _inkPicker;
+
+    WebCore::GraphicsLayer::EmbeddedViewID _focusedEmbeddedViewID;
+}
+
+- (instancetype)initWithContentView:(WKContentView *)contentView
+{
+    self = [super init];
+    if (!self)
+        return nil;
+
+    _contentView = contentView;
+    _inkPicker = adoptNS([[WKInkPickerView alloc] initWithContentView:_contentView]);
+
+    return self;
+}
+
+- (WKInkPickerView *)inkPicker
+{
+    return _inkPicker.get();
+}
+
+- (UIView *)rulerHostingView
+{
+    return _contentView;
+}
+
+- (BOOL)rulerHostWantsSharedRuler
+{
+    return YES;
+}
+
+- (WKDrawingView *)_focusedDrawingView
+{
+    WebKit::EditableImage *focusedEditableImage = _contentView.page->editableImageController().editableImage(_focusedEmbeddedViewID);
+    if (!focusedEditableImage)
+        return nil;
+    return focusedEditableImage->drawingView.get();
+}
+
+- (void)didChangeRulerState:(BOOL)rulerEnabled
+{
+    [self._focusedDrawingView didChangeRulerState:rulerEnabled];
+}
+
+- (void)didChangeInk:(PKInk *)ink
+{
+    [self._focusedDrawingView didChangeInk:ink];
+}
+
+- (void)installInkPickerForDrawing:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID
+{
+    _focusedEmbeddedViewID = embeddedViewID;
+
+    WKWebView *webView = _contentView->_webView;
+
+    [_inkPicker sizeToFit];
+    [_inkPicker setTranslatesAutoresizingMaskIntoConstraints:NO];
+    [webView addSubview:_inkPicker.get()];
+
+    [NSLayoutConstraint activateConstraints:@[
+        [[_inkPicker heightAnchor] constraintEqualToConstant:[_inkPicker frame].size.height],
+        [[_inkPicker bottomAnchor] constraintEqualToAnchor:webView.safeAreaLayoutGuide.bottomAnchor],
+        [[_inkPicker leftAnchor] constraintEqualToAnchor:webView.safeAreaLayoutGuide.leftAnchor],
+        [[_inkPicker rightAnchor] constraintEqualToAnchor:webView.safeAreaLayoutGuide.rightAnchor],
+    ]];
+
+    // When focused, push the ruler state down to the canvas so that it doesn't get out of sync
+    // and early-return from later changes.
+    [self._focusedDrawingView didChangeRulerState:[_inkPicker rulerEnabled]];
+}
+
+- (void)uninstallInkPicker
+{
+    [_inkPicker removeFromSuperview];
+    _focusedEmbeddedViewID = 0;
+}
+
+@end
+
+#endif // HAVE(PENCILKIT)

Modified: trunk/Source/WebKit/UIProcess/ios/WKDrawingView.h (239627 => 239628)


--- trunk/Source/WebKit/UIProcess/ios/WKDrawingView.h	2019-01-04 19:56:51 UTC (rev 239627)
+++ trunk/Source/WebKit/UIProcess/ios/WKDrawingView.h	2019-01-04 20:24:26 UTC (rev 239628)
@@ -28,16 +28,18 @@
 #import "RemoteLayerTreeHost.h"
 #import "RemoteLayerTreeViews.h"
 
-OBJC_CLASS PKCanvasView;
+OBJC_CLASS PKInk;
+OBJC_CLASS WKContentView;
 
 @interface WKDrawingView : WKEmbeddedView <WKNativelyInteractible>
 
-- (instancetype)initWithEmbeddedViewID:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID webPageProxy:(WebKit::WebPageProxy&)webPageProxy;
+- (instancetype)initWithEmbeddedViewID:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID contentView:(WKContentView *)contentView;
 
 - (NSData *)PNGRepresentation;
 - (void)loadDrawingFromPNGRepresentation:(NSData *)PNGData;
 
-@property (nonatomic, readonly) PKCanvasView *canvasView;
+- (void)didChangeRulerState:(BOOL)rulerEnabled;
+- (void)didChangeInk:(PKInk *)ink;
 
 @end
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKDrawingView.mm (239627 => 239628)


--- trunk/Source/WebKit/UIProcess/ios/WKDrawingView.mm	2019-01-04 19:56:51 UTC (rev 239627)
+++ trunk/Source/WebKit/UIProcess/ios/WKDrawingView.mm	2019-01-04 20:24:26 UTC (rev 239628)
@@ -29,10 +29,12 @@
 #if HAVE(PENCILKIT)
 
 #import "EditableImageController.h"
-#import "PencilKitSoftLink.h"
+#import "WKInkPickerView.h"
 #import <wtf/OSObjectPtr.h>
 #import <wtf/RetainPtr.h>
 
+#import "PencilKitSoftLink.h"
+
 @interface WKDrawingView () <PKCanvasViewDelegate>
 @end
 
@@ -44,16 +46,16 @@
     RetainPtr<PKImageRenderer> _renderer;
 #endif
 
-    WeakPtr<WebKit::WebPageProxy> _webPageProxy;
+    __weak WKContentView *_contentView;
 }
 
-- (instancetype)initWithEmbeddedViewID:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID webPageProxy:(WebKit::WebPageProxy&)webPageProxy
+- (instancetype)initWithEmbeddedViewID:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID contentView:(WKContentView *)contentView
 {
     self = [super initWithEmbeddedViewID:embeddedViewID];
     if (!self)
         return nil;
 
-    _webPageProxy = makeWeakPtr(webPageProxy);
+    _contentView = contentView;
 
     _pencilView = adoptNS([WebKit::allocPKCanvasViewInstance() initWithFrame:CGRectZero]);
 
@@ -61,6 +63,7 @@
     [_pencilView setUserInteractionEnabled:YES];
     [_pencilView setOpaque:NO];
     [_pencilView setDelegate:self];
+    [_pencilView setRulerHostingDelegate:_contentView._drawingCoordinator];
 
     [self addSubview:_pencilView.get()];
 
@@ -165,20 +168,30 @@
     [self invalidateAttachment];
 }
 
+- (void)_canvasViewWillBeginDrawing:(PKCanvasView *)canvasView
+{
+    [_pencilView setInk:_contentView._drawingCoordinator.inkPicker.ink];
+}
+
 - (void)invalidateAttachment
 {
-    if (!_webPageProxy)
+    if (!_contentView.page)
         return;
-    auto& page = *_webPageProxy;
+    auto& page = *_contentView.page;
 
     page.editableImageController().invalidateAttachmentForEditableImage(self.embeddedViewID);
 }
 
-- (PKCanvasView *)canvasView
+- (void)didChangeRulerState:(BOOL)rulerEnabled
 {
-    return _pencilView.get();
+    [_pencilView setRulerEnabled:rulerEnabled];
 }
 
+- (void)didChangeInk:(PKInk *)ink
+{
+    [_pencilView setInk:ink];
+}
+
 @end
 
 #endif // HAVE(PENCILKIT)

Modified: trunk/Source/WebKit/UIProcess/ios/WKInkPickerView.h (239627 => 239628)


--- trunk/Source/WebKit/UIProcess/ios/WKInkPickerView.h	2019-01-04 19:56:51 UTC (rev 239627)
+++ trunk/Source/WebKit/UIProcess/ios/WKInkPickerView.h	2019-01-04 20:24:26 UTC (rev 239628)
@@ -27,7 +27,8 @@
 
 #import <UIKit/UIKit.h>
 
-OBJC_CLASS WKDrawingView;
+OBJC_CLASS PKInk;
+OBJC_CLASS WKContentView;
 
 @interface WKInkPickerView : UIView
 
@@ -35,8 +36,11 @@
 - (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
 - (instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE;
 
-- (instancetype)initWithDrawingView:(WKDrawingView *)drawingView NS_DESIGNATED_INITIALIZER;
+- (instancetype)initWithContentView:(WKContentView *)contentView NS_DESIGNATED_INITIALIZER;
 
+@property (nonatomic) BOOL rulerEnabled;
+@property (nonatomic, retain) PKInk *ink;
+
 @end
 
 #endif // HAVE(PENCILKIT)

Modified: trunk/Source/WebKit/UIProcess/ios/WKInkPickerView.mm (239627 => 239628)


--- trunk/Source/WebKit/UIProcess/ios/WKInkPickerView.mm	2019-01-04 19:56:51 UTC (rev 239627)
+++ trunk/Source/WebKit/UIProcess/ios/WKInkPickerView.mm	2019-01-04 20:24:26 UTC (rev 239628)
@@ -28,7 +28,7 @@
 
 #if HAVE(PENCILKIT)
 
-#import "WKDrawingView.h"
+#import "WKContentViewInteraction.h"
 
 #import "PencilKitSoftLink.h"
 
@@ -37,10 +37,10 @@
 
 @implementation WKInkPickerView {
     RetainPtr<PKInlineInkPicker> _inlinePicker;
-    RetainPtr<WKDrawingView> _drawingView;
+    __weak WKContentView *_contentView;
 }
 
-- (instancetype)initWithDrawingView:(WKDrawingView *)drawingView
+- (instancetype)initWithContentView:(WKContentView *)contentView
 {
     self = [super initWithFrame:CGRectZero];
     if (!self)
@@ -47,11 +47,9 @@
         return nil;
 
     _inlinePicker = adoptNS([WebKit::allocPKInlineInkPickerInstance() init]);
-    [_inlinePicker setSelectedInk:[drawingView canvasView].ink animated:NO];
-    [_inlinePicker addTarget:self action:@selector(didPickInk) forControlEvents:UIControlEventValueChanged];
     [_inlinePicker setDelegate:self];
 
-    _drawingView = drawingView;
+    _contentView = contentView;
     [self addSubview:_inlinePicker.get()];
 
     return self;
@@ -59,12 +57,13 @@
 
 - (void)didPickInk
 {
-    [_drawingView canvasView].ink = [_inlinePicker selectedInk];
+    [_contentView._drawingCoordinator didChangeInk:[_inlinePicker selectedInk]];
 }
 
 - (void)inlineInkPickerDidToggleRuler:(PKInlineInkPicker *)inlineInkPicker
 {
-    [_drawingView canvasView].rulerEnabled = ![_drawingView canvasView].rulerEnabled;
+    _rulerEnabled = !_rulerEnabled;
+    [_contentView._drawingCoordinator didChangeRulerState:_rulerEnabled];
 }
 
 - (void)inlineInkPicker:(PKInlineInkPicker *)inlineInkPicker didSelectTool:(PKInkIdentifier)identifer
@@ -97,9 +96,19 @@
 
 - (UIViewController *)viewControllerForPopoverPresentationFromInlineInkPicker:(PKInlineInkPicker *)inlineInkPicker
 {
-    return [UIViewController _viewControllerForFullScreenPresentationFromView:_drawingView.get()];
+    return [UIViewController _viewControllerForFullScreenPresentationFromView:_contentView];
 }
 
+- (void)setInk:(PKInk *)ink
+{
+    [_inlinePicker setSelectedInk:ink];
+}
+
+- (PKInk *)ink
+{
+    return [_inlinePicker selectedInk];
+}
+
 @end
 
 #endif // HAVE(PENCILKIT)

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (239627 => 239628)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2019-01-04 19:56:51 UTC (rev 239627)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2019-01-04 20:24:26 UTC (rev 239628)
@@ -2487,6 +2487,8 @@
 		2D1B5D5C185869C8006C6596 /* ViewGestureControllerMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ViewGestureControllerMessages.h; path = DerivedSources/WebKit2/ViewGestureControllerMessages.h; sourceTree = BUILT_PRODUCTS_DIR; };
 		2D1E8221216FFF5000A15265 /* WKWebEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKWebEvent.h; path = ios/WKWebEvent.h; sourceTree = "<group>"; };
 		2D1E8222216FFF5100A15265 /* WKWebEvent.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKWebEvent.mm; path = ios/WKWebEvent.mm; sourceTree = "<group>"; };
+		2D21A45821DED49B002487E7 /* WKDrawingCoordinator.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WKDrawingCoordinator.mm; path = ios/WKDrawingCoordinator.mm; sourceTree = "<group>"; };
+		2D21A45921DED49B002487E7 /* WKDrawingCoordinator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WKDrawingCoordinator.h; path = ios/WKDrawingCoordinator.h; sourceTree = "<group>"; };
 		2D28A4951AF965A100F190C9 /* WKViewLayoutStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKViewLayoutStrategy.h; sourceTree = "<group>"; };
 		2D28A4961AF965A100F190C9 /* WKViewLayoutStrategy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKViewLayoutStrategy.mm; sourceTree = "<group>"; };
 		2D28F3E01885CCC1004B9EAE /* WebChromeClientIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebChromeClientIOS.mm; path = ios/WebChromeClientIOS.mm; sourceTree = "<group>"; };
@@ -5844,6 +5846,8 @@
 				0FCB4E3D18BBE044000FCFC9 /* WKContentView.mm */,
 				0FCB4E6A18BBF26A000FCFC9 /* WKContentViewInteraction.h */,
 				0FCB4E6B18BBF26A000FCFC9 /* WKContentViewInteraction.mm */,
+				2D21A45921DED49B002487E7 /* WKDrawingCoordinator.h */,
+				2D21A45821DED49B002487E7 /* WKDrawingCoordinator.mm */,
 				2DC18FAB218910480025A88D /* WKDrawingView.h */,
 				2DC18FAC218910480025A88D /* WKDrawingView.mm */,
 				0FCB4E3F18BBE044000FCFC9 /* WKGeolocationProviderIOS.h */,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to