Changeset 198974 in webkit


Ignore:
Timestamp:
Apr 2, 2016 1:01:34 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

Cleanup DataDetection.mm a little bit
https://bugs.webkit.org/show_bug.cgi?id=156128

Patch by Sam Weinig <sam@webkit.org> on 2016-04-02
Reviewed by Dan Bernstein.

  • html/HTMLAttributeNames.in:

Add x-apple-data-detectors, x-apple-data-detectors-type, x-apple-data-detectors-result

  • editing/cocoa/DataDetection.mm:

(WebCore::DataDetection::requiresExtendedContext):
(WebCore::DataDetection::dataDetectorIdentifier):
(WebCore::DataDetection::shouldCancelDefaultAction):
(WebCore::removeResultLinksFromAnchor):
(WebCore::searchForLinkRemovingExistingDDLinks):
Use new generated qualified name attributes, switch to using fastGetAttribute and
equalIgnoringASCIICase, and fix the position of some *s.

(WebCore::dataDetectorStringForPath):
Fix some *s and switch to using StringBuilder.

(WebCore::buildQuery):
Fix some *s.

(WebCore::DataDetection::detectContentInRange):
Use new generated qualified name attributes.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r198970 r198974  
     12016-04-02  Sam Weinig  <sam@webkit.org>
     2
     3        Cleanup DataDetection.mm a little bit
     4        https://bugs.webkit.org/show_bug.cgi?id=156128
     5
     6        Reviewed by Dan Bernstein.
     7
     8        * html/HTMLAttributeNames.in:
     9        Add x-apple-data-detectors, x-apple-data-detectors-type, x-apple-data-detectors-result
     10
     11        * editing/cocoa/DataDetection.mm:
     12        (WebCore::DataDetection::requiresExtendedContext):
     13        (WebCore::DataDetection::dataDetectorIdentifier):
     14        (WebCore::DataDetection::shouldCancelDefaultAction):
     15        (WebCore::removeResultLinksFromAnchor):
     16        (WebCore::searchForLinkRemovingExistingDDLinks):
     17        Use new generated qualified name attributes, switch to using fastGetAttribute and
     18        equalIgnoringASCIICase, and fix the position of some *s.
     19
     20        (WebCore::dataDetectorStringForPath):
     21        Fix some *s and switch to using StringBuilder.
     22
     23        (WebCore::buildQuery):
     24        Fix some *s.
     25
     26        (WebCore::DataDetection::detectContentInRange):
     27        Use new generated qualified name attributes.
     28
    1292016-04-01  Myles C. Maxfield  <mmaxfield@apple.com>
    230
  • trunk/Source/WebCore/editing/cocoa/DataDetection.mm

    r198864 r198974  
    2929#import "Attr.h"
    3030#import "CSSStyleDeclaration.h"
    31 #import "DataDetectorsCoreSoftLink.h"
    3231#import "DataDetectorsSPI.h"
    3332#import "FrameView.h"
    3433#import "HTMLAnchorElement.h"
     34#import "HTMLNames.h"
    3535#import "HTMLTextFormControlElement.h"
    3636#import "HitTestResult.h"
     
    4545#import "VisibleUnits.h"
    4646#import "htmlediting.h"
     47#import <wtf/text/StringBuilder.h>
     48
     49#import "DataDetectorsCoreSoftLink.h"
    4750
    4851#if USE(APPLE_INTERNAL_SDK)
     
    5053#endif
    5154
    52 const char* dataDetectorsURLScheme = "x-apple-data-detectors";
    53 const char* dataDetectorsAttributeTypeKey = "x-apple-data-detectors-type";
    54 const char* dataDetectorsAttributeResultKey = "x-apple-data-detectors-result";
    5555const char* dataDetectorsLinkStyle = "-webkit-text-decoration-color:rgb(199, 199, 204); color:initial;";
    5656
    5757namespace WebCore {
     58
     59using namespace HTMLNames;
    5860
    5961#if PLATFORM(MAC)
     
    161163bool DataDetection::requiresExtendedContext(Element& element)
    162164{
    163     return equalIgnoringASCIICase(element.fastGetAttribute(QualifiedName(nullAtom, dataDetectorsAttributeTypeKey, nullAtom)), "calendar-event");
     165    return equalIgnoringASCIICase(element.fastGetAttribute(x_apple_data_detectors_typeAttr), "calendar-event");
    164166}
    165167
    166168String DataDetection::dataDetectorIdentifier(Element& element)
    167169{
    168     return element.fastGetAttribute(QualifiedName(nullAtom, dataDetectorsAttributeResultKey, nullAtom));
     170    return element.fastGetAttribute(x_apple_data_detectors_resultAttr);
    169171}
    170172
     
    177179        return true;
    178180   
    179     const AtomicString& resultAttribute = element.fastGetAttribute(QualifiedName(nullAtom, dataDetectorsAttributeResultKey, nullAtom));
     181    const AtomicString& resultAttribute = element.fastGetAttribute(x_apple_data_detectors_resultAttr);
    180182    if (resultAttribute.isEmpty())
    181183        return false;
     
    239241        return;
    240242   
    241     BOOL nodeIsDDAnchor = is<HTMLAnchorElement>(*node) && downcast<Element>(*node).getAttribute(dataDetectorsURLScheme) == "true";
     243    BOOL nodeIsDDAnchor = is<HTMLAnchorElement>(*node) && equalIgnoringASCIICase(downcast<Element>(*node).fastGetAttribute(x_apple_data_detectorsAttr), "true");
    242244   
    243245    RefPtr<NodeList> children = node->childNodes();
    244246    unsigned childCount = children->length();
    245247    for (size_t i = 0; i < childCount; i++) {
    246         Node *child = children->item(i);
     248        Node* child = children->item(i);
    247249        if (is<Element>(*child))
    248250            removeResultLinksFromAnchor(child, node);
     
    256258        // Remove the anchor afterwards.
    257259        for (size_t i = 0; i < childCount; i++) {
    258             Node *child = children->item(0);
     260            Node* child = children->item(0);
    259261            nodeParent->insertBefore(child, node, ASSERT_NO_EXCEPTION);
    260262        }
     
    263265}
    264266
    265 static bool searchForLinkRemovingExistingDDLinks(Node* startNode, Node* endNode, bool &didModifyDOM)
     267static bool searchForLinkRemovingExistingDDLinks(Node& startNode, Node& endNode, bool& didModifyDOM)
    266268{
    267269    didModifyDOM = false;
    268     Node *node = startNode;
     270    Node* node = &startNode;
    269271    while (node) {
    270272        if (is<HTMLAnchorElement>(*node)) {
    271             if (downcast<Element>(*node).getAttribute(dataDetectorsURLScheme) != "true")
     273            if (!equalIgnoringASCIICase(downcast<Element>(*node).fastGetAttribute(x_apple_data_detectorsAttr), "true"))
    272274                return true;
    273275            removeResultLinksFromAnchor(node, node->parentElement());
     
    275277        }
    276278       
    277         if (node == endNode) {
     279        if (node == &endNode) {
    278280            // If we found the end node and no link, return false unless an ancestor node is a link.
    279281            // The only ancestors not tested at this point are in the direct line from self's parent to the top.
    280             node = startNode->parentNode();
     282            node = startNode.parentNode();
    281283            while (node) {
    282284                if (is<HTMLAnchorElement>(*node)) {
    283                     if (downcast<Element>(*node).getAttribute(dataDetectorsURLScheme) != "true")
     285                    if (!equalIgnoringASCIICase(downcast<Element>(*node).fastGetAttribute(x_apple_data_detectorsAttr), "true"))
    284286                        return true;
    285287                    removeResultLinksFromAnchor(node, node->parentElement());
     
    295297            node = childNodes->item(0);
    296298        else {
    297             Node *newNode = node->nextSibling();
    298             Node *parentNode = node;
     299            Node* newNode = node->nextSibling();
     300            Node* parentNode = node;
    299301            while (!newNode) {
    300302                parentNode = parentNode->parentNode();
     
    327329}
    328330
    329 static String dataDetectorStringForPath(NSIndexPath* path)
     331static String dataDetectorStringForPath(NSIndexPath *path)
    330332{
    331333    NSUInteger length = path.length;
     
    333335    switch (length) {
    334336    case 0:
    335         return String();
    336        
     337        return { };
    337338    case 1:
    338         return String::format("%lu", (unsigned long)[path indexAtPosition:0]);
    339        
    340     case 2:
    341         return String::format("%lu/%lu", (unsigned long)[path indexAtPosition:0], (unsigned long)[path indexAtPosition:1]);
    342        
    343     default:
    344         {
    345             String componentsString = String::format("%lu", (unsigned long)[path indexAtPosition:0]);
    346             for (NSUInteger i = 1 ; i < length ; i++) {
    347                 componentsString.append("/");
    348                 componentsString.append(String::format("%lu", (unsigned long)[path indexAtPosition:i]));
    349             }
    350 
    351             return componentsString;
    352         }
     339        return String::number((unsigned long)[path indexAtPosition:0]);
     340    case 2: {
     341        StringBuilder stringBuilder;
     342        stringBuilder.appendNumber((unsigned long)[path indexAtPosition:0]);
     343        stringBuilder.append('/');
     344        stringBuilder.appendNumber((unsigned long)[path indexAtPosition:1]);
     345        return stringBuilder.toString();
     346    }
     347    default: {
     348        StringBuilder stringBuilder;
     349        stringBuilder.appendNumber((unsigned long)[path indexAtPosition:0]);
     350        for (NSUInteger i = 1 ; i < length ; i++) {
     351            stringBuilder.append('/');
     352            stringBuilder.appendNumber((unsigned long)[path indexAtPosition:i]);
     353        }
     354
     355        return stringBuilder.toString();
     356    }
    353357    }
    354358}
     
    381385        }
    382386        // Test for white space nodes, we're coalescing them.
    383         const UniChar *currentCharPtr = iterator.text().upconvertedCharacters();
     387        const UniChar* currentCharPtr = iterator.text().upconvertedCharacters();
    384388       
    385389        bool containsOnlyWhiteSpace = true;
     
    536540    String lastNodeContent;
    537541    size_t contentOffset = 0;
    538     DDQueryOffset lastModifiedQueryOffset = {-1, 0};
     542    DDQueryOffset lastModifiedQueryOffset = { -1, 0 };
    539543   
    540544    // For each result add the link.
     
    565569            rangeBoundaries.append(std::make_pair(range->startPosition(), range->endPosition()));
    566570
    567         if (!correspondingURL || searchForLinkRemovingExistingDDLinks(&resultRanges.first()->startContainer(), &resultRanges.last()->endContainer(), didModifyDOM))
     571        if (!correspondingURL || searchForLinkRemovingExistingDDLinks(resultRanges.first()->startContainer(), resultRanges.last()->endContainer(), didModifyDOM))
    568572            continue;
    569573       
     
    618622            parentNode->insertBefore(anchorElement, &currentTextNode, ASSERT_NO_EXCEPTION);
    619623            // Add a special attribute to mark this URLification as the result of data detectors.
    620             anchorElement->setAttribute(QualifiedName(nullAtom, dataDetectorsURLScheme, nullAtom), "true");
    621             anchorElement->setAttribute(QualifiedName(nullAtom, dataDetectorsAttributeTypeKey, nullAtom), dataDetectorTypeForCategory(softLink_DataDetectorsCore_DDResultGetCategory(coreResult)));
    622             anchorElement->setAttribute(QualifiedName(nullAtom, dataDetectorsAttributeResultKey, nullAtom), identifier);
     624            anchorElement->setAttribute(x_apple_data_detectorsAttr, "true");
     625            anchorElement->setAttribute(x_apple_data_detectors_typeAttr, dataDetectorTypeForCategory(softLink_DataDetectorsCore_DDResultGetCategory(coreResult)));
     626            anchorElement->setAttribute(x_apple_data_detectors_resultAttr, identifier);
    623627            contentOffset = range->endOffset();
    624628           
  • trunk/Source/WebCore/html/HTMLAttributeNames.in

    r197790 r198974  
    382382x-webkit-wirelessvideoplaybackdisabled
    383383x-itunes-inherit-uri-query-component
     384
     385x-apple-data-detectors
     386x-apple-data-detectors-type
     387x-apple-data-detectors-result
Note: See TracChangeset for help on using the changeset viewer.