Changeset 170495 in webkit


Ignore:
Timestamp:
Jun 26, 2014, 2:23:02 PM (11 years ago)
Author:
mitz@apple.com
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.

Location:
trunk/Source/WebKit2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r170492 r170495  
     12014-06-26  Dan Bernstein  <mitz@apple.com>
     2
     3        [iOS] Add API for opting into character selection granularity
     4        https://bugs.webkit.org/show_bug.cgi?id=134354
     5
     6        Reviewed by Geoff Garen.
     7
     8        * Shared/API/Cocoa/WKFoundation.h: Added a definition of WK_ENUM_AVAILABLE_IOS.
     9        * UIProcess/API/Cocoa/WKWebViewConfiguration.h:
     10        (WKSelectionGranularity): Added this enum with two values, one representing dynamic
     11        granularity( the current, default behavior) and one representing character granularity.
     12        Delcared new selectionGranularity property.
     13        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
     14        (-[WKWebViewConfiguration copyWithZone:]): Copy the _selectionGranularity ivar.
     15
     16        * UIProcess/ios/WKContentViewInteraction.mm:
     17        (toUIWebSelectionMode): Added this helper function for mapping WKSelectionGranularity values
     18        to UIWebSelectionMode values.
     19        (-[WKContentView setupInteraction]): Use a selection assistant with the mode specified in
     20        the configuration.
     21        (-[WKContentView _stopAssistingKeyboard]): Ditto.
     22
     23        * WebProcess/WebPage/ios/WebPageIOS.mm:
     24        (WebKit::WebPage::selectWithGesture): Changed the behavior of the loupe gesture type in
     25        non-editable text to select a word, rather than an empty range, matching the UITextView
     26        behavior.
     27
    1282014-06-26  Ada Chan  <adachan@apple.com>
    229
  • trunk/Source/WebKit2/Shared/API/Cocoa/WKFoundation.h

    r170237 r170495  
    4545#define WK_CLASS_AVAILABLE(_mac, _ios) __attribute__((visibility ("default")))
    4646#define WK_ENUM_AVAILABLE(_mac, _ios)
     47#define WK_ENUM_AVAILABLE_IOS(_ios)
    4748
    4849#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.h

    r169818 r170495  
    3333@class WKProcessPool;
    3434@class WKUserContentController;
     35
     36#if TARGET_OS_IPHONE
     37/*! @enum WKSelectionGranularity
     38 @abstract The granularity with which a selection can be created and modified interactively.
     39 @constant WKSelectionGranularityDynamic    Selection granularity varies automatically based on the selection.
     40 @constant WKSelectionGranularityCharacter  Selection endpoints can be placed at any character boundary.
     41 @discussion An example of how granularity may vary when WKSelectionGranularityDynamic is used is
     42 that when the selection is within a single block, the granularity may be single character, and when
     43 the selection is not confined to a single block, the selection granularity may be single block.
     44 */
     45typedef NS_ENUM(NSInteger, WKSelectionGranularity) {
     46    WKSelectionGranularityDynamic,
     47    WKSelectionGranularityCharacter,
     48} WK_ENUM_AVAILABLE_IOS(8_0);
     49#endif
    3550
    3651/*! A WKWebViewConfiguration object is a collection of properties with
     
    8196@property (nonatomic) BOOL mediaPlaybackAllowsAirPlay;
    8297
     98/*! @abstract The level of granularity with which the user can interactively
     99 select content in the web view.
     100 @discussion Possible values are described in WKSelectionGranularity.
     101 The default value is WKSelectionGranularityDynamic.
     102 */
     103@property (nonatomic) WKSelectionGranularity selectionGranularity;
     104
    83105#endif
    84106
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm

    r170371 r170495  
    117117    configuration->_mediaPlaybackRequiresUserAction = self->_mediaPlaybackRequiresUserAction;
    118118    configuration->_mediaPlaybackAllowsAirPlay = self->_mediaPlaybackAllowsAirPlay;
     119    configuration->_selectionGranularity = self->_selectionGranularity;
    119120#endif
    120121
  • trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

    r170445 r170495  
    3737#import "WKFormSelectControl.h"
    3838#import "WKInspectorNodeSearchGestureRecognizer.h"
     39#import "WKWebViewConfiguration.h"
    3940#import "WKWebViewPrivate.h"
    4041#import "WebEvent.h"
     
    191192@implementation WKContentView (WKInteraction)
    192193
     194static UIWebSelectionMode toUIWebSelectionMode(WKSelectionGranularity granularity)
     195{
     196    switch (granularity) {
     197    case WKSelectionGranularityDynamic:
     198        return UIWebSelectionModeWeb;
     199    case WKSelectionGranularityCharacter:
     200        return UIWebSelectionModeTextOnly;
     201    }
     202
     203    ASSERT_NOT_REACHED();
     204    return UIWebSelectionModeWeb;
     205}
     206
    193207- (void)setupInteraction
    194208{
     
    238252
    239253    // FIXME: This should be called when we get notified that loading has completed.
    240     [self useSelectionAssistantWithMode:UIWebSelectionModeWeb];
     254    [self useSelectionAssistantWithMode:toUIWebSelectionMode([[_webView configuration] selectionGranularity])];
    241255   
    242256    _actionSheetAssistant = adoptNS([[WKActionSheetAssistant alloc] initWithView:self]);
     
    23072321- (void)_stopAssistingKeyboard
    23082322{
    2309     [self useSelectionAssistantWithMode:UIWebSelectionModeWeb];
     2323    [self useSelectionAssistantWithMode:toUIWebSelectionMode([[_webView configuration] selectionGranularity])];
    23102324}
    23112325
  • trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

    r170445 r170495  
    857857
    858858    case GestureType::Loupe:
    859         range = Range::create(*frame.document(), position, position);
     859        if (position.rootEditableElement())
     860            range = Range::create(*frame.document(), position, position);
     861        else
     862            range = wordRangeFromPosition(position);
    860863        break;
    861864
Note: See TracChangeset for help on using the changeset viewer.