Changeset 198974 in webkit
- Timestamp:
- Apr 2, 2016 1:01:34 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r198970 r198974 1 2016-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 1 29 2016-04-01 Myles C. Maxfield <mmaxfield@apple.com> 2 30 -
trunk/Source/WebCore/editing/cocoa/DataDetection.mm
r198864 r198974 29 29 #import "Attr.h" 30 30 #import "CSSStyleDeclaration.h" 31 #import "DataDetectorsCoreSoftLink.h"32 31 #import "DataDetectorsSPI.h" 33 32 #import "FrameView.h" 34 33 #import "HTMLAnchorElement.h" 34 #import "HTMLNames.h" 35 35 #import "HTMLTextFormControlElement.h" 36 36 #import "HitTestResult.h" … … 45 45 #import "VisibleUnits.h" 46 46 #import "htmlediting.h" 47 #import <wtf/text/StringBuilder.h> 48 49 #import "DataDetectorsCoreSoftLink.h" 47 50 48 51 #if USE(APPLE_INTERNAL_SDK) … … 50 53 #endif 51 54 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";55 55 const char* dataDetectorsLinkStyle = "-webkit-text-decoration-color:rgb(199, 199, 204); color:initial;"; 56 56 57 57 namespace WebCore { 58 59 using namespace HTMLNames; 58 60 59 61 #if PLATFORM(MAC) … … 161 163 bool DataDetection::requiresExtendedContext(Element& element) 162 164 { 163 return equalIgnoringASCIICase(element.fastGetAttribute( QualifiedName(nullAtom, dataDetectorsAttributeTypeKey, nullAtom)), "calendar-event");165 return equalIgnoringASCIICase(element.fastGetAttribute(x_apple_data_detectors_typeAttr), "calendar-event"); 164 166 } 165 167 166 168 String DataDetection::dataDetectorIdentifier(Element& element) 167 169 { 168 return element.fastGetAttribute( QualifiedName(nullAtom, dataDetectorsAttributeResultKey, nullAtom));170 return element.fastGetAttribute(x_apple_data_detectors_resultAttr); 169 171 } 170 172 … … 177 179 return true; 178 180 179 const AtomicString& resultAttribute = element.fastGetAttribute( QualifiedName(nullAtom, dataDetectorsAttributeResultKey, nullAtom));181 const AtomicString& resultAttribute = element.fastGetAttribute(x_apple_data_detectors_resultAttr); 180 182 if (resultAttribute.isEmpty()) 181 183 return false; … … 239 241 return; 240 242 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"); 242 244 243 245 RefPtr<NodeList> children = node->childNodes(); 244 246 unsigned childCount = children->length(); 245 247 for (size_t i = 0; i < childCount; i++) { 246 Node *child = children->item(i);248 Node* child = children->item(i); 247 249 if (is<Element>(*child)) 248 250 removeResultLinksFromAnchor(child, node); … … 256 258 // Remove the anchor afterwards. 257 259 for (size_t i = 0; i < childCount; i++) { 258 Node *child = children->item(0);260 Node* child = children->item(0); 259 261 nodeParent->insertBefore(child, node, ASSERT_NO_EXCEPTION); 260 262 } … … 263 265 } 264 266 265 static bool searchForLinkRemovingExistingDDLinks(Node * startNode, Node* endNode, bool &didModifyDOM)267 static bool searchForLinkRemovingExistingDDLinks(Node& startNode, Node& endNode, bool& didModifyDOM) 266 268 { 267 269 didModifyDOM = false; 268 Node *node =startNode;270 Node* node = &startNode; 269 271 while (node) { 270 272 if (is<HTMLAnchorElement>(*node)) { 271 if ( downcast<Element>(*node).getAttribute(dataDetectorsURLScheme) != "true")273 if (!equalIgnoringASCIICase(downcast<Element>(*node).fastGetAttribute(x_apple_data_detectorsAttr), "true")) 272 274 return true; 273 275 removeResultLinksFromAnchor(node, node->parentElement()); … … 275 277 } 276 278 277 if (node == endNode) {279 if (node == &endNode) { 278 280 // If we found the end node and no link, return false unless an ancestor node is a link. 279 281 // 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(); 281 283 while (node) { 282 284 if (is<HTMLAnchorElement>(*node)) { 283 if ( downcast<Element>(*node).getAttribute(dataDetectorsURLScheme) != "true")285 if (!equalIgnoringASCIICase(downcast<Element>(*node).fastGetAttribute(x_apple_data_detectorsAttr), "true")) 284 286 return true; 285 287 removeResultLinksFromAnchor(node, node->parentElement()); … … 295 297 node = childNodes->item(0); 296 298 else { 297 Node *newNode = node->nextSibling();298 Node *parentNode = node;299 Node* newNode = node->nextSibling(); 300 Node* parentNode = node; 299 301 while (!newNode) { 300 302 parentNode = parentNode->parentNode(); … … 327 329 } 328 330 329 static String dataDetectorStringForPath(NSIndexPath *path)331 static String dataDetectorStringForPath(NSIndexPath *path) 330 332 { 331 333 NSUInteger length = path.length; … … 333 335 switch (length) { 334 336 case 0: 335 return String(); 336 337 return { }; 337 338 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 } 353 357 } 354 358 } … … 381 385 } 382 386 // Test for white space nodes, we're coalescing them. 383 const UniChar *currentCharPtr = iterator.text().upconvertedCharacters();387 const UniChar* currentCharPtr = iterator.text().upconvertedCharacters(); 384 388 385 389 bool containsOnlyWhiteSpace = true; … … 536 540 String lastNodeContent; 537 541 size_t contentOffset = 0; 538 DDQueryOffset lastModifiedQueryOffset = { -1, 0};542 DDQueryOffset lastModifiedQueryOffset = { -1, 0 }; 539 543 540 544 // For each result add the link. … … 565 569 rangeBoundaries.append(std::make_pair(range->startPosition(), range->endPosition())); 566 570 567 if (!correspondingURL || searchForLinkRemovingExistingDDLinks( &resultRanges.first()->startContainer(), &resultRanges.last()->endContainer(), didModifyDOM))571 if (!correspondingURL || searchForLinkRemovingExistingDDLinks(resultRanges.first()->startContainer(), resultRanges.last()->endContainer(), didModifyDOM)) 568 572 continue; 569 573 … … 618 622 parentNode->insertBefore(anchorElement, ¤tTextNode, ASSERT_NO_EXCEPTION); 619 623 // 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); 623 627 contentOffset = range->endOffset(); 624 628 -
trunk/Source/WebCore/html/HTMLAttributeNames.in
r197790 r198974 382 382 x-webkit-wirelessvideoplaybackdisabled 383 383 x-itunes-inherit-uri-query-component 384 385 x-apple-data-detectors 386 x-apple-data-detectors-type 387 x-apple-data-detectors-result
Note: See TracChangeset
for help on using the changeset viewer.