- Revision
- 170495
- Author
- [email protected]
- Date
- 2014-06-26 14:23:02 -0700 (Thu, 26 Jun 2014)
Log Message
[iOS] Add API for opting into character selection granularity
https://bugs.webkit.org/show_bug.cgi?id=134354
Reviewed by Geoff Garen.
* Shared/API/Cocoa/WKFoundation.h: Added a definition of WK_ENUM_AVAILABLE_IOS.
* UIProcess/API/Cocoa/WKWebViewConfiguration.h:
(WKSelectionGranularity): Added this enum with two values, one representing dynamic
granularity( the current, default behavior) and one representing character granularity.
Delcared new selectionGranularity property.
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration copyWithZone:]): Copy the _selectionGranularity ivar.
* UIProcess/ios/WKContentViewInteraction.mm:
(toUIWebSelectionMode): Added this helper function for mapping WKSelectionGranularity values
to UIWebSelectionMode values.
(-[WKContentView setupInteraction]): Use a selection assistant with the mode specified in
the configuration.
(-[WKContentView _stopAssistingKeyboard]): Ditto.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::selectWithGesture): Changed the behavior of the loupe gesture type in
non-editable text to select a word, rather than an empty range, matching the UITextView
behavior.
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (170494 => 170495)
--- trunk/Source/WebKit2/ChangeLog 2014-06-26 21:14:39 UTC (rev 170494)
+++ trunk/Source/WebKit2/ChangeLog 2014-06-26 21:23:02 UTC (rev 170495)
@@ -1,3 +1,30 @@
+2014-06-26 Dan Bernstein <[email protected]>
+
+ [iOS] Add API for opting into character selection granularity
+ https://bugs.webkit.org/show_bug.cgi?id=134354
+
+ Reviewed by Geoff Garen.
+
+ * Shared/API/Cocoa/WKFoundation.h: Added a definition of WK_ENUM_AVAILABLE_IOS.
+ * UIProcess/API/Cocoa/WKWebViewConfiguration.h:
+ (WKSelectionGranularity): Added this enum with two values, one representing dynamic
+ granularity( the current, default behavior) and one representing character granularity.
+ Delcared new selectionGranularity property.
+ * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+ (-[WKWebViewConfiguration copyWithZone:]): Copy the _selectionGranularity ivar.
+
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (toUIWebSelectionMode): Added this helper function for mapping WKSelectionGranularity values
+ to UIWebSelectionMode values.
+ (-[WKContentView setupInteraction]): Use a selection assistant with the mode specified in
+ the configuration.
+ (-[WKContentView _stopAssistingKeyboard]): Ditto.
+
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::selectWithGesture): Changed the behavior of the loupe gesture type in
+ non-editable text to select a word, rather than an empty range, matching the UITextView
+ behavior.
+
2014-06-26 Ada Chan <[email protected]>
Change the target membership of WKBackForwardListPrivate.h from WebKit2 to WebKit.
Modified: trunk/Source/WebKit2/Shared/API/Cocoa/WKFoundation.h (170494 => 170495)
--- trunk/Source/WebKit2/Shared/API/Cocoa/WKFoundation.h 2014-06-26 21:14:39 UTC (rev 170494)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/WKFoundation.h 2014-06-26 21:23:02 UTC (rev 170495)
@@ -44,6 +44,7 @@
#define WK_AVAILABLE(_mac, _ios)
#define WK_CLASS_AVAILABLE(_mac, _ios) __attribute__((visibility ("default")))
#define WK_ENUM_AVAILABLE(_mac, _ios)
+#define WK_ENUM_AVAILABLE_IOS(_ios)
#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.h (170494 => 170495)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.h 2014-06-26 21:14:39 UTC (rev 170494)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.h 2014-06-26 21:23:02 UTC (rev 170495)
@@ -33,6 +33,21 @@
@class WKProcessPool;
@class WKUserContentController;
+#if TARGET_OS_IPHONE
+/*! @enum WKSelectionGranularity
+ @abstract The granularity with which a selection can be created and modified interactively.
+ @constant WKSelectionGranularityDynamic Selection granularity varies automatically based on the selection.
+ @constant WKSelectionGranularityCharacter Selection endpoints can be placed at any character boundary.
+ @discussion An example of how granularity may vary when WKSelectionGranularityDynamic is used is
+ that when the selection is within a single block, the granularity may be single character, and when
+ the selection is not confined to a single block, the selection granularity may be single block.
+ */
+typedef NS_ENUM(NSInteger, WKSelectionGranularity) {
+ WKSelectionGranularityDynamic,
+ WKSelectionGranularityCharacter,
+} WK_ENUM_AVAILABLE_IOS(8_0);
+#endif
+
/*! A WKWebViewConfiguration object is a collection of properties with
which to initialize a web view.
@helps Contains properties used to configure a @link WKWebView @/link.
@@ -80,6 +95,13 @@
*/
@property (nonatomic) BOOL mediaPlaybackAllowsAirPlay;
+/*! @abstract The level of granularity with which the user can interactively
+ select content in the web view.
+ @discussion Possible values are described in WKSelectionGranularity.
+ The default value is WKSelectionGranularityDynamic.
+ */
+@property (nonatomic) WKSelectionGranularity selectionGranularity;
+
#endif
@end
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm (170494 => 170495)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm 2014-06-26 21:14:39 UTC (rev 170494)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm 2014-06-26 21:23:02 UTC (rev 170495)
@@ -116,6 +116,7 @@
configuration->_allowsInlineMediaPlayback = self->_allowsInlineMediaPlayback;
configuration->_mediaPlaybackRequiresUserAction = self->_mediaPlaybackRequiresUserAction;
configuration->_mediaPlaybackAllowsAirPlay = self->_mediaPlaybackAllowsAirPlay;
+ configuration->_selectionGranularity = self->_selectionGranularity;
#endif
return configuration;
Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (170494 => 170495)
--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm 2014-06-26 21:14:39 UTC (rev 170494)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm 2014-06-26 21:23:02 UTC (rev 170495)
@@ -36,6 +36,7 @@
#import "WKFormInputControl.h"
#import "WKFormSelectControl.h"
#import "WKInspectorNodeSearchGestureRecognizer.h"
+#import "WKWebViewConfiguration.h"
#import "WKWebViewPrivate.h"
#import "WebEvent.h"
#import "WebIOSEventFactory.h"
@@ -190,6 +191,19 @@
@implementation WKContentView (WKInteraction)
+static UIWebSelectionMode toUIWebSelectionMode(WKSelectionGranularity granularity)
+{
+ switch (granularity) {
+ case WKSelectionGranularityDynamic:
+ return UIWebSelectionModeWeb;
+ case WKSelectionGranularityCharacter:
+ return UIWebSelectionModeTextOnly;
+ }
+
+ ASSERT_NOT_REACHED();
+ return UIWebSelectionModeWeb;
+}
+
- (void)setupInteraction
{
if (!_inverseScaleRootView) {
@@ -237,7 +251,7 @@
_showingTextStyleOptions = NO;
// FIXME: This should be called when we get notified that loading has completed.
- [self useSelectionAssistantWithMode:UIWebSelectionModeWeb];
+ [self useSelectionAssistantWithMode:toUIWebSelectionMode([[_webView configuration] selectionGranularity])];
_actionSheetAssistant = adoptNS([[WKActionSheetAssistant alloc] initWithView:self]);
_smartMagnificationController = std::make_unique<SmartMagnificationController>(self);
@@ -2306,7 +2320,7 @@
- (void)_stopAssistingKeyboard
{
- [self useSelectionAssistantWithMode:UIWebSelectionModeWeb];
+ [self useSelectionAssistantWithMode:toUIWebSelectionMode([[_webView configuration] selectionGranularity])];
}
- (const AssistedNodeInformation&)assistedNodeInformation
Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (170494 => 170495)
--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm 2014-06-26 21:14:39 UTC (rev 170494)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm 2014-06-26 21:23:02 UTC (rev 170495)
@@ -856,7 +856,10 @@
break;
case GestureType::Loupe:
- range = Range::create(*frame.document(), position, position);
+ if (position.rootEditableElement())
+ range = Range::create(*frame.document(), position, position);
+ else
+ range = wordRangeFromPosition(position);
break;
case GestureType::TapAndAHalf: