1/* 2 * Copyright (C) 2012-2014 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#if PLATFORM(IOS) 27 28#import "WKContentView.h" 29 30#import "AssistedNodeInformation.h" 31#import "GestureTypes.h" 32#import "InteractionInformationAtPosition.h" 33#import "WKSyntheticClickTapGestureRecognizer.h" 34#import "WKAirPlayRoutePicker.h" 35#import "WKFileUploadPanel.h" 36#import "WKFormPeripheral.h" 37#import <UIKit/UITextInput_Private.h> 38#import <UIKit/UIView.h> 39#import <UIKit/UIWKSelectionAssistant.h> 40#import <UIKit/UIWKTextInteractionAssistant.h> 41#import <UIKit/UIWebFormAccessory.h> 42#import <UIKit/UIWebTouchEventsGestureRecognizer.h> 43#import <WebCore/Color.h> 44#import <WebCore/FloatQuad.h> 45#import <wtf/Forward.h> 46#import <wtf/Vector.h> 47#import <wtf/text/WTFString.h> 48 49namespace WebCore { 50class Color; 51class FloatQuad; 52class IntSize; 53} 54 55namespace WebKit { 56class NativeWebTouchEvent; 57class SmartMagnificationController; 58class WebOpenPanelParameters; 59class WebOpenPanelResultListenerProxy; 60class WebPageProxy; 61} 62 63@class WKActionSheetAssistant; 64@class WKFormInputSession; 65@class WKInspectorNodeSearchGestureRecognizer; 66@class WebIOSEvent; 67@class _UIHighlightView; 68@class _UIWebHighlightLongPressGestureRecognizer; 69 70typedef void (^UIWKAutocorrectionCompletionHandler)(UIWKAutocorrectionRects *rectsForInput); 71typedef void (^UIWKAutocorrectionContextHandler)(UIWKAutocorrectionContext *autocorrectionContext); 72typedef void (^UIWKDictationContextHandler)(NSString *selectedText, NSString *beforeText, NSString *afterText); 73 74namespace WebKit { 75struct WKAutoCorrectionData { 76 String fontName; 77 CGFloat fontSize; 78 uint64_t fontTraits; 79 CGRect textFirstRect; 80 CGRect textLastRect; 81 UIWKAutocorrectionCompletionHandler autocorrectionHandler; 82 UIWKAutocorrectionContextHandler autocorrectionContextHandler; 83}; 84} 85 86@interface WKContentView () { 87 RetainPtr<UIWebTouchEventsGestureRecognizer> _touchEventGestureRecognizer; 88 89 BOOL _canSendTouchEventsAsynchronously; 90 91 RetainPtr<WKSyntheticClickTapGestureRecognizer> _singleTapGestureRecognizer; 92 RetainPtr<_UIWebHighlightLongPressGestureRecognizer> _highlightLongPressGestureRecognizer; 93 RetainPtr<UILongPressGestureRecognizer> _longPressGestureRecognizer; 94 RetainPtr<UITapGestureRecognizer> _doubleTapGestureRecognizer; 95 RetainPtr<UITapGestureRecognizer> _twoFingerDoubleTapGestureRecognizer; 96 RetainPtr<WKInspectorNodeSearchGestureRecognizer> _inspectorNodeSearchGestureRecognizer; 97 98 RetainPtr<UIWKTextInteractionAssistant> _textSelectionAssistant; 99 RetainPtr<UIWKSelectionAssistant> _webSelectionAssistant; 100 101 RetainPtr<UITextInputTraits> _traits; 102 RetainPtr<UIWebFormAccessory> _formAccessoryView; 103 RetainPtr<_UIHighlightView> _highlightView; 104 RetainPtr<UIView> _interactionViewsContainerView; 105 RetainPtr<NSString> _markedText; 106 RetainPtr<WKActionSheetAssistant> _actionSheetAssistant; 107 RetainPtr<WKAirPlayRoutePicker> _airPlayRoutePicker; 108 RetainPtr<WKFormInputSession> _formInputSession; 109 RetainPtr<WKFileUploadPanel> _fileUploadPanel; 110 111 std::unique_ptr<WebKit::SmartMagnificationController> _smartMagnificationController; 112 113 id <UITextInputDelegate> _inputDelegate; 114 115 uint64_t _latestTapHighlightID; 116 struct TapHighlightInformation { 117 WebCore::Color color; 118 Vector<WebCore::FloatQuad> quads; 119 WebCore::IntSize topLeftRadius; 120 WebCore::IntSize topRightRadius; 121 WebCore::IntSize bottomLeftRadius; 122 WebCore::IntSize bottomRightRadius; 123 }; 124 TapHighlightInformation _tapHighlightInformation; 125 126 WebKit::WKAutoCorrectionData _autocorrectionData; 127 WebKit::InteractionInformationAtPosition _positionInformation; 128 WebKit::AssistedNodeInformation _assistedNodeInformation; 129 RetainPtr<NSObject<WKFormPeripheral>> _inputPeripheral; 130 131 CGPoint _lastInteractionLocation; 132 133 BOOL _isEditable; 134 BOOL _showingTextStyleOptions; 135 BOOL _hasValidPositionInformation; 136 BOOL _isTapHighlightIDValid; 137 BOOL _potentialTapInProgress; 138 BOOL _hasTapHighlightForPotentialTap; 139 BOOL _selectionNeedsUpdate; 140 BOOL _shouldRestoreSelection; 141 BOOL _usingGestureForSelection; 142 BOOL _inspectorNodeSearchEnabled; 143 BOOL _didAccessoryTabInitiateFocus; 144} 145 146@end 147 148@interface WKContentView (WKInteraction) <UIGestureRecognizerDelegate, UIWebTouchEventsGestureRecognizerDelegate, UITextInputPrivate, UIWebFormAccessoryDelegate, UIWKInteractionViewProtocol, WKFileUploadPanelDelegate> 149 150@property (nonatomic, readonly) CGPoint lastInteractionLocation; 151@property (nonatomic, readonly) BOOL isEditable; 152@property (nonatomic, readonly) const WebKit::InteractionInformationAtPosition& positionInformation; 153@property (nonatomic, readonly) const WebKit::WKAutoCorrectionData& autocorrectionData; 154@property (nonatomic, readonly) const WebKit::AssistedNodeInformation& assistedNodeInformation; 155@property (nonatomic, readonly) UIWebFormAccessory *formAccessoryView; 156 157- (void)setupInteraction; 158- (void)cleanupInteraction; 159 160- (void)scrollViewWillStartPanOrPinchGesture; 161 162- (void)_webTouchEvent:(const WebKit::NativeWebTouchEvent&)touchEvent preventsNativeGestures:(BOOL)preventsDefault; 163- (void)_commitPotentialTapFailed; 164- (void)_didGetTapHighlightForRequest:(uint64_t)requestID color:(const WebCore::Color&)color quads:(const Vector<WebCore::FloatQuad>&)highlightedQuads topLeftRadius:(const WebCore::IntSize&)topLeftRadius topRightRadius:(const WebCore::IntSize&)topRightRadius bottomLeftRadius:(const WebCore::IntSize&)bottomLeftRadius bottomRightRadius:(const WebCore::IntSize&)bottomRightRadius; 165 166- (void)_startAssistingNode:(const WebKit::AssistedNodeInformation&)information userIsInteracting:(BOOL)userIsInteracting blurPreviousNode:(BOOL)blurPreviousNode userObject:(NSObject <NSSecureCoding> *)userObject; 167- (void)_stopAssistingNode; 168- (void)_selectionChanged; 169- (void)_updateChangedSelection; 170- (BOOL)_interpretKeyEvent:(WebIOSEvent *)theEvent isCharEvent:(BOOL)isCharEvent; 171- (void)_positionInformationDidChange:(const WebKit::InteractionInformationAtPosition&)info; 172- (void)_attemptClickAtLocation:(CGPoint)location; 173- (void)_updatePositionInformation; 174- (void)_performAction:(WebKit::SheetAction)action; 175- (void)_willStartScrollingOrZooming; 176- (void)_didScroll; 177- (void)_didEndScrollingOrZooming; 178- (void)_overflowScrollingWillBegin; 179- (void)_overflowScrollingDidEnd; 180- (void)_didUpdateBlockSelectionWithTouch:(WebKit::SelectionTouch)touch withFlags:(WebKit::SelectionFlags)flags growThreshold:(CGFloat)growThreshold shrinkThreshold:(CGFloat)shrinkThreshold; 181- (void)_showPlaybackTargetPicker:(BOOL)hasVideo fromRect:(const WebCore::IntRect&)elementRect; 182- (void)_showRunOpenPanel:(WebKit::WebOpenPanelParameters*)parameters resultListener:(WebKit::WebOpenPanelResultListenerProxy*)listener; 183- (void)accessoryDone; 184- (void)_didHandleKeyEvent:(WebIOSEvent *)event; 185- (Vector<WebKit::OptionItem>&) assistedNodeSelectOptions; 186- (void)_enableInspectorNodeSearch; 187- (void)_disableInspectorNodeSearch; 188@end 189 190#endif // PLATFORM(IOS) 191