Chromium Code Reviews| Index: Source/core/html/HTMLTextFormControlElement.cpp |
| diff --git a/Source/core/html/HTMLTextFormControlElement.cpp b/Source/core/html/HTMLTextFormControlElement.cpp |
| index 1cfab17e841ced2e367b7ad2c8c31777f1636fdc..7709f5ab8b75b3995d6b1bb3100a8e9af561b51d 100644 |
| --- a/Source/core/html/HTMLTextFormControlElement.cpp |
| +++ b/Source/core/html/HTMLTextFormControlElement.cpp |
| @@ -171,12 +171,12 @@ void HTMLTextFormControlElement::updatePlaceholderVisibility(bool placeholderVal |
| void HTMLTextFormControlElement::setSelectionStart(int start) |
| { |
| - setSelectionRange(start, std::max(start, selectionEnd()), selectionDirection()); |
| + setSelectionRange(start, std::max<unsigned>(start, selectionEnd()), selectionDirection()); |
| } |
| void HTMLTextFormControlElement::setSelectionEnd(int end) |
| { |
| - setSelectionRange(std::min(end, selectionStart()), end, selectionDirection()); |
| + setSelectionRange(std::min<unsigned>(end, selectionStart()), end, selectionDirection()); |
| } |
| void HTMLTextFormControlElement::setSelectionDirection(const String& direction) |
| @@ -266,7 +266,7 @@ void HTMLTextFormControlElement::setRangeText(const String& replacement, unsigne |
| setSelectionRange(newSelectionStart, newSelectionEnd, SelectionHasNoDirection); |
| } |
| -void HTMLTextFormControlElement::setSelectionRange(int start, int end, const String& directionString) |
| +void HTMLTextFormControlElement::setSelectionRange(unsigned start, unsigned end, const String& directionString) |
| { |
| TextFieldSelectionDirection direction = SelectionHasNoDirection; |
| if (directionString == "forward") |
| @@ -280,16 +280,15 @@ void HTMLTextFormControlElement::setSelectionRange(int start, int end, const Str |
| return setSelectionRange(start, end, direction); |
| } |
| -static Position positionForIndex(HTMLElement* innerEditor, int index) |
| +static Position positionForIndex(HTMLElement* innerEditor, unsigned index) |
| { |
| - ASSERT(index >= 0); |
| if (index == 0) { |
| Node* node = NodeTraversal::next(*innerEditor, innerEditor); |
| if (node && node->isTextNode()) |
| return Position(node, 0); |
| return Position(innerEditor, 0); |
| } |
| - int remainingCharactersToMoveForward = index; |
| + unsigned remainingCharactersToMoveForward = index; |
| Node* lastBrOrText = innerEditor; |
| for (Node& node : NodeTraversal::descendantsOf(*innerEditor)) { |
| ASSERT(remainingCharactersToMoveForward >= 0); |
| @@ -303,7 +302,7 @@ static Position positionForIndex(HTMLElement* innerEditor, int index) |
| if (node.isTextNode()) { |
| Text& text = toText(node); |
| - if (remainingCharactersToMoveForward < static_cast<int>(text.length())) |
| + if (remainingCharactersToMoveForward < text.length()) |
| return Position(&text, remainingCharactersToMoveForward); |
| remainingCharactersToMoveForward -= text.length(); |
| lastBrOrText = &node; |
| @@ -315,7 +314,7 @@ static Position positionForIndex(HTMLElement* innerEditor, int index) |
| return lastPositionInOrAfterNode(lastBrOrText); |
| } |
| -static int indexForPosition(HTMLElement* innerEditor, const Position& passedPosition) |
| +static unsigned indexForPosition(HTMLElement* innerEditor, const Position& passedPosition) |
| { |
| if (!innerEditor || !innerEditor->contains(passedPosition.anchorNode()) || passedPosition.isNull()) |
| return 0; |
| @@ -323,7 +322,7 @@ static int indexForPosition(HTMLElement* innerEditor, const Position& passedPosi |
| if (positionBeforeNode(innerEditor) == passedPosition) |
| return 0; |
| - int index = 0; |
| + unsigned index = 0; |
| Node* startNode = passedPosition.computeNodeBeforePosition(); |
| if (!startNode) |
| startNode = passedPosition.computeContainerNode(); |
| @@ -332,9 +331,9 @@ static int indexForPosition(HTMLElement* innerEditor, const Position& passedPosi |
| for (Node* node = startNode; node; node = NodeTraversal::previous(*node, innerEditor)) { |
| if (node->isTextNode()) { |
| - int length = toText(*node).length(); |
| + unsigned length = toText(*node).length(); |
| if (node == passedPosition.computeContainerNode()) |
| - index += std::min(length, passedPosition.offsetInContainerNode()); |
| + index += std::min<unsigned>(length, passedPosition.offsetInContainerNode()); |
|
philipj_slow
2015/08/14 07:45:52
offsetInContainerNode() returns int. Maybe assign
|
| else |
| index += length; |
| } else if (node->hasTagName(brTag)) { |
| @@ -342,19 +341,17 @@ static int indexForPosition(HTMLElement* innerEditor, const Position& passedPosi |
| } |
| } |
| - ASSERT(index >= 0); |
| return index; |
| } |
| -void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextFieldSelectionDirection direction, NeedToDispatchSelectEvent eventBehaviour, SelectionOption selectionOption) |
| +void HTMLTextFormControlElement::setSelectionRange(unsigned start, unsigned end, TextFieldSelectionDirection direction, NeedToDispatchSelectEvent eventBehaviour, SelectionOption selectionOption) |
| { |
| if (openShadowRoot() || !isTextFormControl() || !inDocument()) |
| return; |
| - const int editorValueLength = static_cast<int>(innerEditorValue().length()); |
| - ASSERT(editorValueLength >= 0); |
| - end = std::max(std::min(end, editorValueLength), 0); |
| - start = std::min(std::max(start, 0), end); |
| + const unsigned editorValueLength = static_cast<unsigned>(innerEditorValue().length()); |
|
philipj_slow
2015/08/14 07:45:52
String::length() is already unsigned.
tanay.c
2015/08/17 12:06:32
Done.
|
| + end = std::min<unsigned>(end, editorValueLength); |
| + start = std::min<unsigned>(start, end); |
| cacheSelection(start, end, direction); |
| if (selectionOption == NotChangeSelection || (selectionOption == ChangeSelectionIfFocused && document().focusedElement() != this)) { |
| @@ -371,8 +368,8 @@ void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField |
| Position startPosition = positionForIndex(innerEditor, start); |
| Position endPosition = start == end ? startPosition : positionForIndex(innerEditor, end); |
| - ASSERT(start == indexForPosition(innerEditor, startPosition)); |
| - ASSERT(end == indexForPosition(innerEditor, endPosition)); |
| + ASSERT(start == (unsigned)indexForPosition(innerEditor, startPosition)); |
|
philipj_slow
2015/08/14 07:45:52
Don't use C-style casts.
tanay.c
2015/08/17 12:06:32
Done.
|
| + ASSERT(end == (unsigned)indexForPosition(innerEditor, endPosition)); |
| // startPosition and endPosition can be null position for example when |
| // "-webkit-user-select: none" style attribute is specified. |
| @@ -417,7 +414,7 @@ int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& p |
| return TextIterator::rangeLength(range->startPosition(), range->endPosition()); |
| } |
| -int HTMLTextFormControlElement::selectionStart() const |
| +unsigned HTMLTextFormControlElement::selectionStart() const |
| { |
| if (!isTextFormControl()) |
| return 0; |
| @@ -427,7 +424,7 @@ int HTMLTextFormControlElement::selectionStart() const |
| return computeSelectionStart(); |
| } |
| -int HTMLTextFormControlElement::computeSelectionStart() const |
| +unsigned HTMLTextFormControlElement::computeSelectionStart() const |
| { |
| ASSERT(isTextFormControl()); |
| LocalFrame* frame = document().frame(); |
| @@ -437,7 +434,7 @@ int HTMLTextFormControlElement::computeSelectionStart() const |
| return indexForPosition(innerEditorElement(), frame->selection().start()); |
| } |
| -int HTMLTextFormControlElement::selectionEnd() const |
| +unsigned HTMLTextFormControlElement::selectionEnd() const |
| { |
| if (!isTextFormControl()) |
| return 0; |
| @@ -446,7 +443,7 @@ int HTMLTextFormControlElement::selectionEnd() const |
| return computeSelectionEnd(); |
| } |
| -int HTMLTextFormControlElement::computeSelectionEnd() const |
| +unsigned HTMLTextFormControlElement::computeSelectionEnd() const |
| { |
| ASSERT(isTextFormControl()); |
| LocalFrame* frame = document().frame(); |
| @@ -496,7 +493,7 @@ TextFieldSelectionDirection HTMLTextFormControlElement::computeSelectionDirectio |
| return selection.isDirectional() ? (selection.isBaseFirst() ? SelectionHasForwardDirection : SelectionHasBackwardDirection) : SelectionHasNoDirection; |
| } |
| -static inline void setContainerAndOffsetForRange(Node* node, int offset, Node*& containerNode, int& offsetInContainer) |
| +static inline void setContainerAndOffsetForRange(Node* node, unsigned offset, Node*& containerNode, unsigned& offsetInContainer) |
| { |
| if (node->isTextNode()) { |
| containerNode = node; |
| @@ -512,8 +509,8 @@ PassRefPtrWillBeRawPtr<Range> HTMLTextFormControlElement::selection() const |
| if (!layoutObject() || !isTextFormControl()) |
| return nullptr; |
| - int start = m_cachedSelectionStart; |
| - int end = m_cachedSelectionEnd; |
| + unsigned start = m_cachedSelectionStart; |
| + unsigned end = m_cachedSelectionEnd; |
| ASSERT(start <= end); |
| HTMLElement* innerText = innerEditorElement(); |
| @@ -523,7 +520,7 @@ PassRefPtrWillBeRawPtr<Range> HTMLTextFormControlElement::selection() const |
| if (!innerText->hasChildren()) |
| return Range::create(document(), innerText, 0, innerText, 0); |
| - int offset = 0; |
| + unsigned offset = 0; |
| Node* startNode = 0; |
| Node* endNode = 0; |
| for (Node& node : NodeTraversal::descendantsOf(*innerText)) { |