⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 192037 in webkit


Ignore:
Timestamp:
Nov 4, 2015, 2:34:01 PM (11 years ago)
Author:
Beth Dakin
Message:

Link preview doesn't work on XHTML pages with Content-Type header as
application/xhtml+xml
https://bugs.webkit.org/show_bug.cgi?id=150740
-and corresponding-
rdar://problem/23063585

Reviewed by Darin Adler.

My original fix for this bug was incorrect in the presence of non-HTML
elements that happen to have the same local name as HTML elements. Since it
seems silly to have all of this logic in the UI process to determine whether
to treat something as a link or an image, this patch fixes the bug by adding
isLink and isImage to InteractionInformationAtPosition in order to simplify
everything. The only remaining uses of clickableElementName just use it to
compare against isNull and isEmpty, so that can be a bool too.

Add isLink and isImage, and turn clickableElementName into isClickableElement

  • Shared/InteractionInformationAtPosition.cpp:

(WebKit::InteractionInformationAtPosition::encode):
(WebKit::InteractionInformationAtPosition::decode):

  • Shared/InteractionInformationAtPosition.h:

Use the new isLink, isImage, and isClickableElement

  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView _actionForLongPress]):
(-[WKContentView gestureRecognizerShouldBegin:]):
(-[WKContentView _highlightLongPressRecognized:]):
(-[WKContentView _interactionShouldBeginFromPreviewItemController:forPosition:]):
(-[WKContentView _dataForPreviewItemController:atPosition:type:]):

Set everything correctly.

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::getPositionInformation):

Location:
trunk/Source/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r192036 r192037  
     12015-11-04  Beth Dakin  <bdakin@apple.com>
     2
     3        Link preview doesn't work on XHTML pages with Content-Type header as
     4        `application/xhtml+xml`
     5        https://bugs.webkit.org/show_bug.cgi?id=150740
     6        -and corresponding-
     7        rdar://problem/23063585
     8
     9        Reviewed by Darin Adler.
     10
     11        My original fix for this bug was incorrect in the presence of non-HTML
     12        elements that happen to have the same local name as HTML elements. Since it
     13        seems silly to have all of this logic in the UI process to determine whether
     14        to treat something as a link or an image, this patch fixes the bug by adding
     15        isLink and isImage to InteractionInformationAtPosition in order to simplify
     16        everything. The only remaining uses of clickableElementName just use it to
     17        compare against isNull and isEmpty, so that can be a bool too.
     18
     19        Add isLink and isImage, and turn clickableElementName into isClickableElement
     20        * Shared/InteractionInformationAtPosition.cpp:
     21        (WebKit::InteractionInformationAtPosition::encode):
     22        (WebKit::InteractionInformationAtPosition::decode):
     23        * Shared/InteractionInformationAtPosition.h:
     24
     25        Use the new isLink, isImage, and isClickableElement
     26        * UIProcess/ios/WKContentViewInteraction.mm:
     27        (-[WKContentView _actionForLongPress]):
     28        (-[WKContentView gestureRecognizerShouldBegin:]):
     29        (-[WKContentView _highlightLongPressRecognized:]):
     30        (-[WKContentView _interactionShouldBeginFromPreviewItemController:forPosition:]):
     31        (-[WKContentView _dataForPreviewItemController:atPosition:type:]):
     32
     33        Set everything correctly.
     34        * WebProcess/WebPage/ios/WebPageIOS.mm:
     35        (WebKit::WebPage::getPositionInformation):
     36
    1372015-11-04  Wenson Hsieh  <wenson_hsieh@apple.com>
    238
  • trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.cpp

    r187173 r192037  
    4040    encoder << isNearMarkedText;
    4141    encoder << touchCalloutEnabled;
     42    encoder << isLink;
     43    encoder << isImage;
    4244    encoder << isAnimatedImage;
    43     encoder << clickableElementName;
     45    encoder << isClickableElement;
    4446    encoder << url;
    4547    encoder << imageURL;
     
    7173        return false;
    7274
     75    if (!decoder.decode(result.isLink))
     76        return false;
     77
     78    if (!decoder.decode(result.isImage))
     79        return false;
     80
    7381    if (!decoder.decode(result.isAnimatedImage))
    7482        return false;
    7583   
    76     if (!decoder.decode(result.clickableElementName))
     84    if (!decoder.decode(result.isClickableElement))
    7785        return false;
    7886
  • trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.h

    r187173 r192037  
    4444    bool isNearMarkedText { false };
    4545    bool touchCalloutEnabled { true };
     46    bool isLink { false };
     47    bool isImage { false };
    4648    bool isAnimatedImage { false };
    47     String clickableElementName;
     49    bool isClickableElement { false };
    4850    String url;
    4951    String imageURL;
  • trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

    r192036 r192037  
    10501050        return nil;
    10511051
    1052     if (equalIgnoringCase(_positionInformation.clickableElementName, "IMG"))
     1052    if (_positionInformation.isImage)
    10531053        return @selector(_showImageSheet);
    10541054
    1055     if (equalIgnoringCase(_positionInformation.clickableElementName, "A")) {
     1055    if (_positionInformation.isLink) {
    10561056        NSURL *targetURL = [NSURL URLWithString:_positionInformation.url];
    10571057        if ([[getDDDetectionControllerClass() tapAndHoldSchemes] containsObject:[targetURL scheme]])
     
    10951095            // Prevent the gesture if there is no node.
    10961096            // Allow the gesture if it is a node that wants highlight or if there is an action for it.
    1097             if (_positionInformation.clickableElementName.isNull())
     1097            if (!_positionInformation.isClickableElement)
    10981098                return NO;
    10991099            return [self _actionForLongPress] != nil;
     
    12091209        break;
    12101210    case UIGestureRecognizerStateEnded:
    1211         if (_highlightLongPressCanClick && !_positionInformation.clickableElementName.isEmpty()) {
     1211        if (_highlightLongPressCanClick && _positionInformation.isClickableElement) {
    12121212            [self _attemptClickAtLocation:[gestureRecognizer startPoint]];
    12131213            [self _finishInteraction];
     
    34353435
    34363436    [self ensurePositionInformationIsUpToDate:position];
    3437     if (equalIgnoringCase(_positionInformation.clickableElementName, "A") && equalIgnoringCase(_positionInformation.clickableElementName, "IMG"))
     3437    if (!_positionInformation.isLink && !_positionInformation.isImage)
    34383438        return NO;
    34393439   
    34403440    String absoluteLinkURL = _positionInformation.url;
    3441     if (equalIgnoringCase(_positionInformation.clickableElementName, "A")) {
     3441    if (_positionInformation.isLink) {
    34423442        if (absoluteLinkURL.isEmpty())
    34433443            return NO;
     
    34583458    id <WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([_webView UIDelegate]);
    34593459    BOOL supportsImagePreview = [uiDelegate respondsToSelector:@selector(_webView:commitPreviewedImageWithURL:)];
    3460     BOOL canShowImagePreview = equalIgnoringCase(_positionInformation.clickableElementName, "IMG") && supportsImagePreview;
    3461     BOOL canShowLinkPreview = equalIgnoringCase(_positionInformation.clickableElementName, "A") || canShowImagePreview;
     3460    BOOL canShowImagePreview = _positionInformation.isImage && supportsImagePreview;
     3461    BOOL canShowLinkPreview = _positionInformation.isLink || canShowImagePreview;
    34623462    BOOL useImageURLForLink = NO;
    34633463
  • trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

    r191904 r192037  
    21762176    bool elementIsLinkOrImage = false;
    21772177    if (hitNode) {
    2178         info.clickableElementName = hitNode->nodeName();
    2179 
    21802178        Element* element = is<Element>(*hitNode) ? downcast<Element>(hitNode) : nullptr;
    21812179        if (element) {
     2180            info.isClickableElement = true;
    21822181            Element* linkElement = nullptr;
    21832182            if (element->renderer() && element->renderer()->isRenderImage()) {
     
    21912190            if (elementIsLinkOrImage) {
    21922191                if (linkElement) {
     2192                    info.isLink = true;
     2193
    21932194                    // Ensure that the image contains at most 600K pixels, so that it is not too big.
    21942195                    if (RefPtr<WebImage> snapshot = snapshotNode(*element, SnapshotOptionsShareable, 600 * 1024))
     
    22062207                    }
    22072208                } else if (element->renderer() && element->renderer()->isRenderImage()) {
     2209                    info.isImage = true;
    22082210                    auto& renderImage = downcast<RenderImage>(*(element->renderer()));
    22092211                    if (renderImage.cachedImage() && !renderImage.cachedImage()->errorOccurred()) {
Note: See TracChangeset for help on using the changeset viewer.