Title: [239400] trunk
Revision
239400
Author
timothy_hor...@apple.com
Date
2018-12-19 15:37:02 -0800 (Wed, 19 Dec 2018)

Log Message

UI process crash when focusing an editable image
https://bugs.webkit.org/show_bug.cgi?id=192839
<rdar://problem/46786670>

Reviewed by Wenson Hsieh.

Source/WebKit:

* SourcesCocoa.txt:
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _requiresKeyboardWhenFirstResponder]):
(-[WKContentView inputView]):
(-[WKContentView requiresAccessoryView]):
(-[WKContentView _startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):
(-[WKContentView _stopAssistingNode]):
(-[WKContentView _installInkPickerForDrawingViewWithID:]):
(-[WKContentView _uninstallInkPicker]):
* UIProcess/ios/WKInkPickerView.h: Renamed from Source/WebKit/UIProcess/ios/WKInkPickerControl.h.
* UIProcess/ios/WKInkPickerView.mm: Renamed from Source/WebKit/UIProcess/ios/WKInkPickerControl.mm.
(-[WKInkPickerView initWithDrawingView:]):
(-[WKInkPickerView didPickInk]):
(-[WKInkPickerView inlineInkPickerDidToggleRuler:]):
(-[WKInkPickerView inlineInkPicker:didSelectTool:]):
(-[WKInkPickerView inlineInkPicker:didSelectColor:]):
(-[WKInkPickerView inkPickerSize]):
(-[WKInkPickerView layoutSubviews]):
(-[WKInkPickerView sizeThatFits:]):
(-[WKInkPickerView viewControllerForPopoverPresentationFromInlineInkPicker:]):
* WebKit.xcodeproj/project.pbxproj:
Make WKInkPickerView a WKWebView subview instead of an inputView.
Also, don't force the keyboard to be visible when an editable image is focused.

LayoutTests:

* editing/images/basic-editable-image-with-gesture.html: Added.
* editing/images/basic-editable-image-with-gesture-expected.txt: Added.
* resources/ui-helper.js:
(window.UIHelper.stylusTapAt.return.new.Promise):
(window.UIHelper.stylusTapAt):
Add a test that ensures that adding an editable image from a gesture
doesn't crash, and can be drawn on.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (239399 => 239400)


--- trunk/LayoutTests/ChangeLog	2018-12-19 23:28:58 UTC (rev 239399)
+++ trunk/LayoutTests/ChangeLog	2018-12-19 23:37:02 UTC (rev 239400)
@@ -1,3 +1,19 @@
+2018-12-19  Tim Horton  <timothy_hor...@apple.com>
+
+        UI process crash when focusing an editable image
+        https://bugs.webkit.org/show_bug.cgi?id=192839
+        <rdar://problem/46786670>
+
+        Reviewed by Wenson Hsieh.
+
+        * editing/images/basic-editable-image-with-gesture.html: Added.
+        * editing/images/basic-editable-image-with-gesture-expected.txt: Added.
+        * resources/ui-helper.js:
+        (window.UIHelper.stylusTapAt.return.new.Promise):
+        (window.UIHelper.stylusTapAt):
+        Add a test that ensures that adding an editable image from a gesture
+        doesn't crash, and can be drawn on.
+
 2018-12-19  Youenn Fablet  <you...@apple.com>
 
         [ MacOS iOS ] Layout Test webrtc/no-port-zero-in-upd-candidates.html is flaky timeout

Added: trunk/LayoutTests/editing/images/basic-editable-image-with-gesture-expected.txt (0 => 239400)


--- trunk/LayoutTests/editing/images/basic-editable-image-with-gesture-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/images/basic-editable-image-with-gesture-expected.txt	2018-12-19 23:37:02 UTC (rev 239400)
@@ -0,0 +1,3 @@
+
+Had 0 strokes in editable image before drawing.
+Had 1 stroke in editable image after drawing.

Added: trunk/LayoutTests/editing/images/basic-editable-image-with-gesture.html (0 => 239400)


--- trunk/LayoutTests/editing/images/basic-editable-image-with-gesture.html	                        (rev 0)
+++ trunk/LayoutTests/editing/images/basic-editable-image-with-gesture.html	2018-12-19 23:37:02 UTC (rev 239400)
@@ -0,0 +1,22 @@
+<!DOCTYPE html><!-- webkit-test-runner [ enableEditableImages=true ] -->
+<head>
+<script src=""
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+
+addEventListener("load", async () => {
+    await UIHelper.stylusTapAt(0, 0);
+    const initialNumberOfStrokesInEditableImage = (await UIHelper.numberOfStrokesInEditableImage());
+    await UIHelper.drawSquareInEditableImage();
+    const numberOfStrokesInEditableImageAfterDrawing = (await UIHelper.numberOfStrokesInEditableImage());
+    document.getElementById("log").innerHTML = `Had ${initialNumberOfStrokesInEditableImage} strokes in editable image before drawing.<br/>Had ${numberOfStrokesInEditableImageAfterDrawing} stroke in editable image after drawing.`;
+    testRunner.notifyDone();
+});
+</script>
+</head>
+<body contenteditable>
+<div id="log"></div>
+</body>

Modified: trunk/LayoutTests/resources/ui-helper.js (239399 => 239400)


--- trunk/LayoutTests/resources/ui-helper.js	2018-12-19 23:28:58 UTC (rev 239399)
+++ trunk/LayoutTests/resources/ui-helper.js	2018-12-19 23:37:02 UTC (rev 239400)
@@ -443,6 +443,19 @@
         return new Promise(resolve => testRunner.runUIScript(`uiController.drawSquareInEditableImage()`, resolve));
     }
 
+    static stylusTapAt(x, y)
+    {
+        if (!this.isWebKit2())
+            return Promise.resolve();
+
+        return new Promise((resolve) => {
+            testRunner.runUIScript(`
+                uiController.stylusTapAtPoint(${x}, ${y}, 2, 1, 0.5, function() {
+                    uiController.uiScriptComplete('Done');
+                });`, resolve);
+        });
+    }
+
     static numberOfStrokesInEditableImage()
     {
         if (!this.isWebKit2())

Modified: trunk/Source/WebKit/ChangeLog (239399 => 239400)


--- trunk/Source/WebKit/ChangeLog	2018-12-19 23:28:58 UTC (rev 239399)
+++ trunk/Source/WebKit/ChangeLog	2018-12-19 23:37:02 UTC (rev 239400)
@@ -1,3 +1,36 @@
+2018-12-19  Tim Horton  <timothy_hor...@apple.com>
+
+        UI process crash when focusing an editable image
+        https://bugs.webkit.org/show_bug.cgi?id=192839
+        <rdar://problem/46786670>
+
+        Reviewed by Wenson Hsieh.
+
+        * SourcesCocoa.txt:
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _requiresKeyboardWhenFirstResponder]):
+        (-[WKContentView inputView]):
+        (-[WKContentView requiresAccessoryView]):
+        (-[WKContentView _startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):
+        (-[WKContentView _stopAssistingNode]):
+        (-[WKContentView _installInkPickerForDrawingViewWithID:]):
+        (-[WKContentView _uninstallInkPicker]):
+        * UIProcess/ios/WKInkPickerView.h: Renamed from Source/WebKit/UIProcess/ios/WKInkPickerControl.h.
+        * UIProcess/ios/WKInkPickerView.mm: Renamed from Source/WebKit/UIProcess/ios/WKInkPickerControl.mm.
+        (-[WKInkPickerView initWithDrawingView:]):
+        (-[WKInkPickerView didPickInk]):
+        (-[WKInkPickerView inlineInkPickerDidToggleRuler:]):
+        (-[WKInkPickerView inlineInkPicker:didSelectTool:]):
+        (-[WKInkPickerView inlineInkPicker:didSelectColor:]):
+        (-[WKInkPickerView inkPickerSize]):
+        (-[WKInkPickerView layoutSubviews]):
+        (-[WKInkPickerView sizeThatFits:]):
+        (-[WKInkPickerView viewControllerForPopoverPresentationFromInlineInkPicker:]):
+        * WebKit.xcodeproj/project.pbxproj:
+        Make WKInkPickerView a WKWebView subview instead of an inputView.
+        Also, don't force the keyboard to be visible when an editable image is focused.
+
 2018-12-19  Eric Carlson  <eric.carl...@apple.com>
 
         [MediaStream] Force system camera/microphone TCC prompt if necessary

Modified: trunk/Source/WebKit/SourcesCocoa.txt (239399 => 239400)


--- trunk/Source/WebKit/SourcesCocoa.txt	2018-12-19 23:28:58 UTC (rev 239399)
+++ trunk/Source/WebKit/SourcesCocoa.txt	2018-12-19 23:37:02 UTC (rev 239400)
@@ -390,7 +390,7 @@
 UIProcess/ios/WKDrawingView.mm
 UIProcess/ios/WKGeolocationProviderIOS.mm
 UIProcess/ios/WKGeolocationProviderIOSObjCSecurityOrigin.mm
-UIProcess/ios/WKInkPickerControl.mm
+UIProcess/ios/WKInkPickerView.mm
 UIProcess/ios/WKInspectorNodeSearchGestureRecognizer.mm
 UIProcess/ios/WKKeyboardScrollingAnimator.mm
 UIProcess/ios/WKLegacyPDFView.mm

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (239399 => 239400)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2018-12-19 23:28:58 UTC (rev 239399)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2018-12-19 23:37:02 UTC (rev 239400)
@@ -96,6 +96,7 @@
 @class WKFocusedFormControlView;
 @class WKFormInputControl;
 @class WKFormInputSession;
+@class WKInkPickerView;
 @class WKInspectorNodeSearchGestureRecognizer;
 
 typedef void (^UIWKAutocorrectionCompletionHandler)(UIWKAutocorrectionRects *rectsForInput);
@@ -284,6 +285,10 @@
     RetainPtr<NSArray<UITextSuggestion *>> _dataListTextSuggestions;
 #endif
 
+#if HAVE(PENCILKIT)
+    RetainPtr<WKInkPickerView> _inkPicker;
+#endif
+
     BOOL _isEditable;
     BOOL _showingTextStyleOptions;
     BOOL _hasValidPositionInformation;

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (239399 => 239400)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-12-19 23:28:58 UTC (rev 239399)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-12-19 23:37:02 UTC (rev 239400)
@@ -47,7 +47,7 @@
 #import "WKFormInputControl.h"
 #import "WKFormSelectControl.h"
 #import "WKImagePreviewViewController.h"
-#import "WKInkPickerControl.h"
+#import "WKInkPickerView.h"
 #import "WKInspectorNodeSearchGestureRecognizer.h"
 #import "WKNSURLExtras.h"
 #import "WKPreviewActionItemIdentifiers.h"
@@ -1365,6 +1365,7 @@
     // FIXME: We should add the logic to handle keyboard visibility during focus redirects.
     switch (_assistedNodeInformation.elementType) {
     case WebKit::InputType::None:
+    case WebKit::InputType::Drawing:
         return NO;
     case WebKit::InputType::Select:
 #if ENABLE(INPUT_TYPE_COLOR)
@@ -1375,8 +1376,6 @@
     case WebKit::InputType::DateTimeLocal:
     case WebKit::InputType::Time:
         return !currentUserInterfaceIdiomIsPad();
-    case WebKit::InputType::Drawing:
-        return YES;
     default:
         return !_assistedNodeInformation.isReadOnly;
     }
@@ -1426,14 +1425,6 @@
             _inputPeripheral = adoptNS([[WKFormColorControl alloc] initWithView:self]);
             break;
 #endif
-        case WebKit::InputType::Drawing:
-#if HAVE(PENCILKIT)
-            _inputPeripheral = adoptNS([[WKInkPickerControl alloc] initWithDrawingView:_page->editableImageController().editableImage(_assistedNodeInformation.embeddedViewID)->drawingView.get()]);
-            break;
-#else
-            ASSERT_NOT_REACHED();
-            return [[UIView new] autorelease];
-#endif
         default:
             _inputPeripheral = adoptNS([[WKFormInputControl alloc] initWithView:self]);
             break;
@@ -2194,6 +2185,7 @@
 
     switch (_assistedNodeInformation.elementType) {
     case WebKit::InputType::None:
+    case WebKit::InputType::Drawing:
         return NO;
     case WebKit::InputType::Text:
     case WebKit::InputType::Password:
@@ -2216,8 +2208,6 @@
     case WebKit::InputType::Color:
 #endif
         return !currentUserInterfaceIdiomIsPad();
-    case WebKit::InputType::Drawing:
-        return YES;
     }
 }
 
@@ -4447,6 +4437,11 @@
     if (blurPreviousNode)
         [self _stopAssistingNode];
 
+#if HAVE(PENCILKIT)
+    if (information.elementType == WebKit::InputType::Drawing)
+        [self _installInkPickerForDrawingViewWithID:information.embeddedViewID];
+#endif
+
     if (!shouldShowKeyboard)
         return;
 
@@ -4497,6 +4492,7 @@
     case WebKit::InputType::Time:
     case WebKit::InputType::Month:
     case WebKit::InputType::Date:
+    case WebKit::InputType::Drawing:
 #if ENABLE(INPUT_TYPE_COLOR)
     case WebKit::InputType::Color:
 #endif
@@ -4530,6 +4526,11 @@
 {
     SetForScope<BOOL> isBlurringFocusedNodeForScope { _isBlurringFocusedNode, YES };
 
+#if HAVE(PENCILKIT)
+    if (_inkPicker)
+        [self _uninstallInkPicker];
+#endif
+
     [_formInputSession invalidate];
     _formInputSession = nil;
 
@@ -6210,6 +6211,30 @@
 }
 #endif
 
+#if HAVE(PENCILKIT)
+- (void)_installInkPickerForDrawingViewWithID:(WebCore::GraphicsLayer::EmbeddedViewID)embeddedViewID
+{
+    _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],
+    ]];
+}
+
+- (void)_uninstallInkPicker
+{
+    [_inkPicker removeFromSuperview];
+    _inkPicker = nil;
+}
+
+#endif // HAVE(PENCILKIT)
+
 @end
 
 @implementation WKContentView (WKTesting)

Deleted: trunk/Source/WebKit/UIProcess/ios/WKInkPickerControl.h (239399 => 239400)


--- trunk/Source/WebKit/UIProcess/ios/WKInkPickerControl.h	2018-12-19 23:28:58 UTC (rev 239399)
+++ trunk/Source/WebKit/UIProcess/ios/WKInkPickerControl.h	2018-12-19 23:37:02 UTC (rev 239400)
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2018 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 "WKFormPeripheral.h"
-
-OBJC_CLASS WKDrawingView;
-
-@interface WKInkPickerControl : NSObject <WKFormPeripheral>
-
-- (instancetype)initWithDrawingView:(WKDrawingView *)drawingView;
-
-@end
-
-
-#endif // HAVE(PENCILKIT)

Deleted: trunk/Source/WebKit/UIProcess/ios/WKInkPickerControl.mm (239399 => 239400)


--- trunk/Source/WebKit/UIProcess/ios/WKInkPickerControl.mm	2018-12-19 23:28:58 UTC (rev 239399)
+++ trunk/Source/WebKit/UIProcess/ios/WKInkPickerControl.mm	2018-12-19 23:37:02 UTC (rev 239400)
@@ -1,141 +0,0 @@
-/*
- * Copyright (C) 2018 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 "WKInkPickerControl.h"
-
-#if HAVE(PENCILKIT)
-
-#import "WKDrawingView.h"
-
-#import "PencilKitSoftLink.h"
-
-@interface WKInkPickerView : UIView <PKInlineInkPickerDelegate>
-@end
-
-@implementation WKInkPickerView {
-    RetainPtr<PKInlineInkPicker> _inlinePicker;
-    RetainPtr<WKDrawingView> _drawingView;
-}
-
-- (instancetype)initWithFrame:(CGRect)frame drawingView:(WKDrawingView *)drawingView
-{
-    self = [super initWithFrame:frame];
-    if (!self)
-        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;
-    [self addSubview:_inlinePicker.get()];
-
-    return self;
-}
-
-- (void)didPickInk
-{
-    [_drawingView canvasView].ink = [_inlinePicker selectedInk];
-}
-
-- (void)inlineInkPickerDidToggleRuler:(PKInlineInkPicker *)inlineInkPicker
-{
-    [_drawingView canvasView].rulerEnabled = ![_drawingView canvasView].rulerEnabled;
-}
-
-- (void)inlineInkPicker:(PKInlineInkPicker *)inlineInkPicker didSelectTool:(PKInkIdentifier)identifer
-{
-    [self didPickInk];
-}
-
-- (void)inlineInkPicker:(PKInlineInkPicker *)inlineInkPicker didSelectColor:(UIColor *)color
-{
-    [self didPickInk];
-}
-
-- (CGSize)inkPickerSize
-{
-    CGSize keyboardSize = [UIKeyboard defaultSizeForInterfaceOrientation:[UIApp interfaceOrientation]];
-    return [_inlinePicker sizeThatFits:keyboardSize];
-}
-
-- (void)layoutSubviews
-{
-    CGSize pickerSize = self.inkPickerSize;
-    [_inlinePicker setFrame:CGRectMake(CGRectGetMidX(self.bounds) - (pickerSize.width / 2), 0, pickerSize.width, pickerSize.height)];
-}
-
-- (CGSize)sizeThatFits:(CGSize)size
-{
-    CGSize keyboardSize = [UIKeyboard defaultSizeForInterfaceOrientation:[UIApp interfaceOrientation]];
-    return CGSizeMake(keyboardSize.width, self.inkPickerSize.height);
-}
-
-- (UIViewController *)viewControllerForPopoverPresentationFromInlineInkPicker:(PKInlineInkPicker *)inlineInkPicker
-{
-    return [UIViewController _viewControllerForFullScreenPresentationFromView:_drawingView.get()];
-}
-
-@end
-
-@implementation WKInkPickerControl {
-    RetainPtr<WKInkPickerView> _picker;
-    RetainPtr<WKDrawingView> _drawingView;
-}
-
-- (instancetype)initWithDrawingView:(WKDrawingView *)drawingView
-{
-    self = [super init];
-    if (!self)
-        return nil;
-
-    _drawingView = drawingView;
-
-    return self;
-}
-
-- (void)beginEditing
-{
-
-}
-
-- (void)endEditing
-{
-
-}
-
-- (UIView *)assistantView
-{
-    if (!_picker)
-        _picker = adoptNS([[WKInkPickerView alloc] initWithFrame:CGRectZero drawingView:_drawingView.get()]);
-    [_picker sizeToFit];
-    return _picker.get();
-}
-
-@end
-
-#endif // HAVE(PENCILKIT)

Copied: trunk/Source/WebKit/UIProcess/ios/WKInkPickerView.h (from rev 239399, trunk/Source/WebKit/UIProcess/ios/WKInkPickerControl.h) (0 => 239400)


--- trunk/Source/WebKit/UIProcess/ios/WKInkPickerView.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/ios/WKInkPickerView.h	2018-12-19 23:37:02 UTC (rev 239400)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2018 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 <UIKit/UIKit.h>
+
+OBJC_CLASS WKDrawingView;
+
+@interface WKInkPickerView : UIView
+
+- (instancetype)init NS_UNAVAILABLE;
+- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
+- (instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE;
+
+- (instancetype)initWithDrawingView:(WKDrawingView *)drawingView NS_DESIGNATED_INITIALIZER;
+
+@end
+
+#endif // HAVE(PENCILKIT)

Copied: trunk/Source/WebKit/UIProcess/ios/WKInkPickerView.mm (from rev 239399, trunk/Source/WebKit/UIProcess/ios/WKInkPickerControl.mm) (0 => 239400)


--- trunk/Source/WebKit/UIProcess/ios/WKInkPickerView.mm	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/ios/WKInkPickerView.mm	2018-12-19 23:37:02 UTC (rev 239400)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2018 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 "WKInkPickerView.h"
+
+#if HAVE(PENCILKIT)
+
+#import "WKDrawingView.h"
+
+#import "PencilKitSoftLink.h"
+
+@interface WKInkPickerView () <PKInlineInkPickerDelegate>
+@end
+
+@implementation WKInkPickerView {
+    RetainPtr<PKInlineInkPicker> _inlinePicker;
+    RetainPtr<WKDrawingView> _drawingView;
+}
+
+- (instancetype)initWithDrawingView:(WKDrawingView *)drawingView
+{
+    self = [super initWithFrame:CGRectZero];
+    if (!self)
+        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;
+    [self addSubview:_inlinePicker.get()];
+
+    return self;
+}
+
+- (void)didPickInk
+{
+    [_drawingView canvasView].ink = [_inlinePicker selectedInk];
+}
+
+- (void)inlineInkPickerDidToggleRuler:(PKInlineInkPicker *)inlineInkPicker
+{
+    [_drawingView canvasView].rulerEnabled = ![_drawingView canvasView].rulerEnabled;
+}
+
+- (void)inlineInkPicker:(PKInlineInkPicker *)inlineInkPicker didSelectTool:(PKInkIdentifier)identifer
+{
+    [self didPickInk];
+}
+
+- (void)inlineInkPicker:(PKInlineInkPicker *)inlineInkPicker didSelectColor:(UIColor *)color
+{
+    [self didPickInk];
+}
+
+- (CGSize)inkPickerSize
+{
+    CGSize keyboardSize = [UIKeyboard defaultSizeForInterfaceOrientation:[UIApp interfaceOrientation]];
+    return [_inlinePicker sizeThatFits:keyboardSize];
+}
+
+- (void)layoutSubviews
+{
+    CGSize pickerSize = self.inkPickerSize;
+    [_inlinePicker setFrame:CGRectMake(CGRectGetMidX(self.bounds) - (pickerSize.width / 2), 0, pickerSize.width, pickerSize.height)];
+}
+
+- (CGSize)sizeThatFits:(CGSize)size
+{
+    CGSize keyboardSize = [UIKeyboard defaultSizeForInterfaceOrientation:[UIApp interfaceOrientation]];
+    return CGSizeMake(keyboardSize.width, self.inkPickerSize.height);
+}
+
+- (UIViewController *)viewControllerForPopoverPresentationFromInlineInkPicker:(PKInlineInkPicker *)inlineInkPicker
+{
+    return [UIViewController _viewControllerForFullScreenPresentationFromView:_drawingView.get()];
+}
+
+@end
+
+#endif // HAVE(PENCILKIT)

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (239399 => 239400)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2018-12-19 23:28:58 UTC (rev 239399)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2018-12-19 23:37:02 UTC (rev 239400)
@@ -2546,8 +2546,6 @@
 		2D6AB540192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKPDFPageNumberIndicator.mm; path = ios/WKPDFPageNumberIndicator.mm; sourceTree = "<group>"; };
 		2D6B371918A967AD0042AE80 /* _WKThumbnailView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKThumbnailView.h; sourceTree = "<group>"; };
 		2D6B371A18A967AD0042AE80 /* _WKThumbnailView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKThumbnailView.mm; sourceTree = "<group>"; };
-		2D6BF11E21AE145F001E79C9 /* WKInkPickerControl.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WKInkPickerControl.mm; path = ios/WKInkPickerControl.mm; sourceTree = "<group>"; };
-		2D6BF11F21AE145F001E79C9 /* WKInkPickerControl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WKInkPickerControl.h; path = ios/WKInkPickerControl.h; sourceTree = "<group>"; };
 		2D6BF12121AF56E1001E79C9 /* PencilKitSoftLink.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PencilKitSoftLink.mm; path = ios/PencilKitSoftLink.mm; sourceTree = "<group>"; };
 		2D6BF12221AF56E1001E79C9 /* PencilKitSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PencilKitSoftLink.h; path = ios/PencilKitSoftLink.h; sourceTree = "<group>"; };
 		2D6CD117189058A500E5A4A0 /* ViewSnapshotStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewSnapshotStore.h; sourceTree = "<group>"; };
@@ -2792,6 +2790,8 @@
 		2DE6943B18BD2A68005C15E5 /* SmartMagnificationControllerMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SmartMagnificationControllerMessageReceiver.cpp; path = DerivedSources/WebKit2/SmartMagnificationControllerMessageReceiver.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
 		2DE6943C18BD2A68005C15E5 /* SmartMagnificationControllerMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SmartMagnificationControllerMessages.h; path = DerivedSources/WebKit2/SmartMagnificationControllerMessages.h; sourceTree = BUILT_PRODUCTS_DIR; };
 		2DEAC5CE1AC368BB00A195D8 /* _WKFindOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKFindOptions.h; sourceTree = "<group>"; };
+		2DF3962A21C8DC50008835E3 /* WKInkPickerView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WKInkPickerView.mm; path = ios/WKInkPickerView.mm; sourceTree = "<group>"; };
+		2DF3962B21C8DC50008835E3 /* WKInkPickerView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WKInkPickerView.h; path = ios/WKInkPickerView.h; sourceTree = "<group>"; };
 		2DF9593418A42412009785A1 /* ViewGestureControllerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ViewGestureControllerIOS.mm; path = ios/ViewGestureControllerIOS.mm; sourceTree = "<group>"; };
 		2DF9EEE31A781FB400B6CFBE /* APIFrameInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = APIFrameInfo.cpp; sourceTree = "<group>"; };
 		2DF9EEE41A781FB400B6CFBE /* APIFrameInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIFrameInfo.h; sourceTree = "<group>"; };
@@ -5835,8 +5835,8 @@
 				0FCB4E4118BBE044000FCFC9 /* WKGeolocationProviderIOSObjCSecurityOrigin.mm */,
 				933DF82D1B3BC09000AEA9E3 /* WKImagePreviewViewController.h */,
 				933DF82F1B3BC0B400AEA9E3 /* WKImagePreviewViewController.mm */,
-				2D6BF11F21AE145F001E79C9 /* WKInkPickerControl.h */,
-				2D6BF11E21AE145F001E79C9 /* WKInkPickerControl.mm */,
+				2DF3962B21C8DC50008835E3 /* WKInkPickerView.h */,
+				2DF3962A21C8DC50008835E3 /* WKInkPickerView.mm */,
 				0F3C7259196F5F6800AEDD0C /* WKInspectorHighlightView.h */,
 				0F3C7257196F5F5000AEDD0C /* WKInspectorHighlightView.mm */,
 				A54293A2195A43C6002782C7 /* WKInspectorNodeSearchGestureRecognizer.h */,
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to