Changeset 163825 in webkit
- Timestamp:
- Feb 10, 2014 3:05:19 PM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r163823 r163825 1 2014-02-10 Ryosuke Niwa <rniwa@webkit.org> 2 3 HTMLTextFormControlElement::setSelectionRange shouldn't use VisiblePosition 4 https://bugs.webkit.org/show_bug.cgi?id=128478 5 6 Reviewed by Darin Adler. 7 8 Added positionForIndex to compute Position given a selection index. This function doesn't 9 synchronously trigger like visiblePositionForIndex. 10 11 Also added assertions in visiblePositionForIndex and visiblePositionForIndex to make sure 12 they are inverse of one another. 13 14 * html/HTMLTextFormControlElement.cpp: 15 (WebCore::HTMLTextFormControlElement::setSelectionRange): Use positionForIndex. Also removed 16 the now tautological assertions since we would never create a position outside the inner text 17 element. 18 19 (WebCore::HTMLTextFormControlElement::indexForVisiblePosition): Fixed the bug where this 20 function could return a selection index beyond innerTextElement in some types of input 21 elements such as search fields. fast/forms/search-disabled-readonly.html hits the newly 22 added assertion without this change. Note we can't use visiblePositionForIndex here as that 23 would result in a mutual recursion with the assertion in visiblePositionForIndex. 24 25 (WebCore::HTMLTextFormControlElement::visiblePositionForIndex): Added an assertion. 26 27 (WebCore::positionForIndex): Added. It's here with prototype at the beginning of the file 28 so that it's right next to HTMLTextFormControlElement::innerText() where we do a similar 29 DOM traversal to obtain the inner text value. 30 1 31 2014-02-07 Jeffrey Pfau <jpfau@apple.com> 2 32 -
trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp
r163721 r163825 53 53 using namespace HTMLNames; 54 54 55 static Position positionForIndex(TextControlInnerTextElement*, unsigned); 56 55 57 HTMLTextFormControlElement::HTMLTextFormControlElement(const QualifiedName& tagName, Document& document, HTMLFormElement* form) 56 58 : HTMLFormControlElementWithState(tagName, document, form) … … 297 299 start = std::min(std::max(start, 0), end); 298 300 299 if (!hasVisibleTextArea(*renderer(), innerTextElement())) { 301 TextControlInnerTextElement* innerText = innerTextElement(); 302 if (!hasVisibleTextArea(*renderer(), innerText)) { 300 303 cacheSelection(start, end, direction); 301 304 return; 302 305 } 303 VisiblePosition startPosition = visiblePositionForIndex(start);304 VisiblePosition endPosition;306 Position startPosition = positionForIndex(innerText, start); 307 Position endPosition; 305 308 if (start == end) 306 309 endPosition = startPosition; 307 310 else 308 endPosition = visiblePositionForIndex(end); 309 310 #if !PLATFORM(IOS) 311 // startPosition and endPosition can be null position for example when 312 // "-webkit-user-select: none" style attribute is specified. 313 if (startPosition.isNotNull() && endPosition.isNotNull()) { 314 ASSERT(startPosition.deepEquivalent().deprecatedNode()->shadowHost() == this 315 && endPosition.deepEquivalent().deprecatedNode()->shadowHost() == this); 316 } 317 #endif 311 endPosition = positionForIndex(innerText, end); 312 318 313 VisibleSelection newSelection; 319 314 if (direction == SelectionHasBackwardDirection) … … 329 324 int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& pos) const 330 325 { 331 if (enclosingTextFormControl(pos.deepEquivalent()) != this) 326 TextControlInnerTextElement* innerText = innerTextElement(); 327 if (!innerText || !innerText->contains(pos.deepEquivalent().anchorNode())) 332 328 return 0; 333 329 bool forSelectionPreservation = false; 334 return WebCore::indexForVisiblePosition(innerTextElement(), pos, forSelectionPreservation); 330 unsigned index = WebCore::indexForVisiblePosition(innerTextElement(), pos, forSelectionPreservation); 331 ASSERT(VisiblePosition(positionForIndex(innerTextElement(), index)) == pos); 332 return index; 335 333 } 336 334 337 335 VisiblePosition HTMLTextFormControlElement::visiblePositionForIndex(int index) const 338 336 { 339 return visiblePositionForIndexUsingCharacterIterator(innerTextElement(), index); 337 VisiblePosition position = positionForIndex(innerTextElement(), index); 338 ASSERT(indexForVisiblePosition(position) == index); 339 return position; 340 340 } 341 341 … … 556 556 } 557 557 return finishText(result); 558 } 559 560 static Position positionForIndex(TextControlInnerTextElement* innerText, unsigned index) 561 { 562 unsigned remainingCharactersToMoveForward = index; 563 for (Node* node = innerText; node; node = NodeTraversal::next(node, innerText)) { 564 if (node->hasTagName(brTag)) { 565 if (!remainingCharactersToMoveForward) 566 return positionBeforeNode(node); 567 remainingCharactersToMoveForward--; 568 } else if (node->isTextNode()) { 569 Text* text = toText(node); 570 if (remainingCharactersToMoveForward < text->length()) 571 return Position(text, remainingCharactersToMoveForward); 572 remainingCharactersToMoveForward -= text->length(); 573 } 574 } 575 return lastPositionInNode(innerText); 558 576 } 559 577
Note: See TracChangeset
for help on using the changeset viewer.