Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1052)

Unified Diff: Source/core/html/HTMLTextFormControlElement.cpp

Issue 1269263003: The start and end arguments should be unsigned long in setSelectionRange() function Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLTextFormControlElement.h ('k') | Source/core/html/HTMLTextFormControlElementTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLTextFormControlElement.cpp
diff --git a/Source/core/html/HTMLTextFormControlElement.cpp b/Source/core/html/HTMLTextFormControlElement.cpp
index 1cfab17e841ced2e367b7ad2c8c31777f1636fdc..4e2fe6baeef379e3c1880a8fbd753e988e9aa6ec 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,9 @@ static int indexForPosition(HTMLElement* innerEditor, const Position& passedPosi
if (positionBeforeNode(innerEditor) == passedPosition)
return 0;
- int index = 0;
+ unsigned index = 0;
+ int offset = passedPosition.offsetInContainerNode();
+ ASSERT(offset >= 0);
Node* startNode = passedPosition.computeNodeBeforePosition();
if (!startNode)
startNode = passedPosition.computeContainerNode();
@@ -332,9 +333,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, offset);
else
index += length;
} else if (node->hasTagName(brTag)) {
@@ -342,19 +343,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 = innerEditorValue().length();
+ end = std::min<unsigned>(end, editorValueLength);
+ start = std::min<unsigned>(start, end);
cacheSelection(start, end, direction);
if (selectionOption == NotChangeSelection || (selectionOption == ChangeSelectionIfFocused && document().focusedElement() != this)) {
@@ -417,7 +416,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 +426,7 @@ int HTMLTextFormControlElement::selectionStart() const
return computeSelectionStart();
}
-int HTMLTextFormControlElement::computeSelectionStart() const
+unsigned HTMLTextFormControlElement::computeSelectionStart() const
{
ASSERT(isTextFormControl());
LocalFrame* frame = document().frame();
@@ -437,7 +436,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 +445,7 @@ int HTMLTextFormControlElement::selectionEnd() const
return computeSelectionEnd();
}
-int HTMLTextFormControlElement::computeSelectionEnd() const
+unsigned HTMLTextFormControlElement::computeSelectionEnd() const
{
ASSERT(isTextFormControl());
LocalFrame* frame = document().frame();
@@ -496,7 +495,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 +511,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 +522,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)) {
« no previous file with comments | « Source/core/html/HTMLTextFormControlElement.h ('k') | Source/core/html/HTMLTextFormControlElementTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698