Changeset 211770 in webkit


Ignore:
Timestamp:
Feb 6, 2017 8:23:52 PM (7 years ago)
Author:
mitz@apple.com
Message:

[iOS] -[WKWebView becomeFirstResponder] and -[WKWebView resignFirstResponder] don’t get called when non-programmatic first responder changes happen
https://bugs.webkit.org/show_bug.cgi?id=167898

Reviewed by Tim Horton.

Made WKContentView’s -becomeFirstResponder and -resignFirstResponder forward to the
WKWebView, giving subclasses an opportunity to override these methods. Changed the WKWebView
implementations to call back into WKContentView methods that actually do the work.

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView becomeFirstResponder]): If the current content view is a WKContentView, call

-becomeFirstResponderForWebView. Added a check that the content view has a superview to
get the right behavior when this is called during the transition from not having to having
a custom content view.

(-[WKWebView canBecomeFirstResponder]): If the current content view is a WKContentView, call

-canBecomeFirstResponderForWebView.

(-[WKWebView resignFirstResponder]): If the current content view is a WKContentView, call

-resignFirstResponderForWebView.

(-[WKWebView _setHasCustomContentView:loadedMIMEType:]): If the new content view is a

WKContentView, use -canBecomeFirstResponderForWebView.

  • UIProcess/ios/WKContentViewInteraction.h: Added _becomingFirstResponder ivar.
  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView canBecomeFirstResponder]): Return _becomingFirstResponder. Normally this is

NO, so code that hit-tests then walks up the view hierarchy to select a first responder
will continue to the WKWebView. But we need to return YES around the call to super’s
-becomeFirstResponder in -becomeFirstResponderForWebView.

(-[WKContentView canBecomeFirstResponderForWebView]): Moved the old

-becomeFirstResponderForWebView implementation here.

(-[WKContentView becomeFirstResponder]): Forward to the WKWebView.
(-[WKContentView becomeFirstResponderForWebView]): Moved the old -becomeFirstResponder

implementation here, setting _becomingFirstResponder to YES around the call to super.

(-[WKContentView resignFirstResponder]): Forward to the WKWebView.
(-[WKContentView resignFirstResponderForWebView]): Moved the old -resignFirstResponder

implementation here.

Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r211767 r211770  
     12017-02-06  Dan Bernstein  <mitz@apple.com>
     2
     3        [iOS] -[WKWebView becomeFirstResponder] and -[WKWebView resignFirstResponder] don’t get called when non-programmatic first responder changes happen
     4        https://bugs.webkit.org/show_bug.cgi?id=167898
     5
     6        Reviewed by Tim Horton.
     7
     8        Made WKContentView’s -becomeFirstResponder and -resignFirstResponder forward to the
     9        WKWebView, giving subclasses an opportunity to override these methods. Changed the WKWebView
     10        implementations to call back into WKContentView methods that actually do the work.
     11
     12        * UIProcess/API/Cocoa/WKWebView.mm:
     13        (-[WKWebView becomeFirstResponder]): If the current content view is a WKContentView, call
     14          -becomeFirstResponderForWebView. Added a check that the content view has a superview to
     15          get the right behavior when this is called during the transition from not having to having
     16          a custom content view.
     17        (-[WKWebView canBecomeFirstResponder]): If the current content view is a WKContentView, call
     18          -canBecomeFirstResponderForWebView.
     19        (-[WKWebView resignFirstResponder]): If the current content view is a WKContentView, call
     20          -resignFirstResponderForWebView.
     21        (-[WKWebView _setHasCustomContentView:loadedMIMEType:]): If the new content view is a
     22          WKContentView, use -canBecomeFirstResponderForWebView.
     23
     24        * UIProcess/ios/WKContentViewInteraction.h: Added _becomingFirstResponder ivar.
     25        * UIProcess/ios/WKContentViewInteraction.mm:
     26        (-[WKContentView canBecomeFirstResponder]): Return _becomingFirstResponder. Normally this is
     27          NO, so code that hit-tests then walks up the view hierarchy to select a first responder
     28          will continue to the WKWebView. But we need to return YES around the call to super’s
     29          -becomeFirstResponder in -becomeFirstResponderForWebView.
     30        (-[WKContentView canBecomeFirstResponderForWebView]): Moved the old
     31          -becomeFirstResponderForWebView implementation here.
     32        (-[WKContentView becomeFirstResponder]): Forward to the WKWebView.
     33        (-[WKContentView becomeFirstResponderForWebView]): Moved the old -becomeFirstResponder
     34          implementation here, setting _becomingFirstResponder to YES around the call to super.
     35        (-[WKContentView resignFirstResponder]): Forward to the WKWebView.
     36        (-[WKContentView resignFirstResponderForWebView]): Moved the old -resignFirstResponder
     37          implementation here.
     38
    1392017-02-06  Simon Fraser  <simon.fraser@apple.com>
    240
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r211656 r211770  
    11/*
    2  * Copyright (C) 2014-2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    10141014- (BOOL)becomeFirstResponder
    10151015{
    1016     return [self._currentContentView becomeFirstResponder] || [super becomeFirstResponder];
     1016    UIView *currentContentView = self._currentContentView;
     1017    if (currentContentView == _contentView && [_contentView superview])
     1018        return [_contentView becomeFirstResponderForWebView] || [super becomeFirstResponder];
     1019
     1020    return [currentContentView becomeFirstResponder] || [super becomeFirstResponder];
    10171021}
    10181022
    10191023- (BOOL)canBecomeFirstResponder
    10201024{
    1021     if (self._currentContentView == _contentView && [_contentView isResigningFirstResponder])
    1022         return NO;
     1025    if (self._currentContentView == _contentView)
     1026        return [_contentView canBecomeFirstResponderForWebView];
     1027
    10231028    return YES;
     1029}
     1030
     1031- (BOOL)resignFirstResponder
     1032{
     1033    if ([_contentView isFirstResponder])
     1034        return [_contentView resignFirstResponderForWebView];
     1035
     1036    return [super resignFirstResponder];
    10241037}
    10251038
     
    10901103    }
    10911104
    1092     if (self.isFirstResponder && self._currentContentView.canBecomeFirstResponder)
    1093         [self._currentContentView becomeFirstResponder];
     1105    if (self.isFirstResponder) {
     1106        UIView *currentContentView = self._currentContentView;
     1107        if (currentContentView == _contentView ? [_contentView canBecomeFirstResponderForWebView] : currentContentView.canBecomeFirstResponder)
     1108            [currentContentView becomeFirstResponder];
     1109    }
    10941110}
    10951111
  • trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h

    r211679 r211770  
    11/*
    2  * Copyright (C) 2012-2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    185185    BOOL _showDebugTapHighlightsForFastClicking;
    186186
     187    BOOL _becomingFirstResponder;
    187188    BOOL _resigningFirstResponder;
    188189    BOOL _needsDeferredEndScrollingSelectionUpdate;
     
    213214
    214215- (void)scrollViewWillStartPanOrPinchGesture;
     216
     217- (BOOL)canBecomeFirstResponderForWebView;
     218- (BOOL)becomeFirstResponderForWebView;
     219- (BOOL)resignFirstResponderForWebView;
    215220
    216221#if ENABLE(TOUCH_EVENTS)
  • trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

    r211643 r211770  
    11/*
    2  * Copyright (C) 2012-2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    8181#import <WebKit/WebSelectionRect.h> // FIXME: WK2 should not include WebKit headers!
    8282#import <wtf/RetainPtr.h>
     83#import <wtf/SetForScope.h>
    8384
    8485#if ENABLE(DATA_INTERACTION)
     
    831832- (BOOL)canBecomeFirstResponder
    832833{
     834    return _becomingFirstResponder;
     835}
     836
     837- (BOOL)canBecomeFirstResponderForWebView
     838{
    833839    if (_resigningFirstResponder)
    834840        return NO;
     
    840846- (BOOL)becomeFirstResponder
    841847{
     848    return [_webView becomeFirstResponder];
     849}
     850
     851- (BOOL)becomeFirstResponderForWebView
     852{
    842853    if (_resigningFirstResponder)
    843854        return NO;
    844     BOOL didBecomeFirstResponder = [super becomeFirstResponder];
     855
     856    BOOL didBecomeFirstResponder;
     857    {
     858        SetForScope<BOOL> becomingFirstResponder { _becomingFirstResponder, YES };
     859        didBecomeFirstResponder = [super becomeFirstResponder];
     860    }
    845861    if (didBecomeFirstResponder)
    846862        [_textSelectionAssistant activateSelection];
     
    850866
    851867- (BOOL)resignFirstResponder
     868{
     869    return [_webView resignFirstResponder];
     870}
     871
     872- (BOOL)resignFirstResponderForWebView
    852873{
    853874    // FIXME: Maybe we should call resignFirstResponder on the superclass
Note: See TracChangeset for help on using the changeset viewer.