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

Unified Diff: Source/core/editing/DOMSelection.cpp

Issue 1195833002: Selection attributes changes from long to unsigned long (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixes offset error message Created 5 years, 6 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
Index: Source/core/editing/DOMSelection.cpp
diff --git a/Source/core/editing/DOMSelection.cpp b/Source/core/editing/DOMSelection.cpp
index 9b86b6fa4dccbec1bd0dfd3b5914847dedda6451..7faf447c5dd93f807fd73cf480b161978dbc6ced 100644
--- a/Source/core/editing/DOMSelection.cpp
+++ b/Source/core/editing/DOMSelection.cpp
@@ -107,7 +107,7 @@ Node* DOMSelection::anchorNode() const
return shadowAdjustedNode(anchorPosition(visibleSelection()));
}
-int DOMSelection::anchorOffset() const
+unsigned DOMSelection::anchorOffset() const
{
if (!m_frame)
return 0;
@@ -123,7 +123,7 @@ Node* DOMSelection::focusNode() const
return shadowAdjustedNode(focusPosition(visibleSelection()));
}
-int DOMSelection::focusOffset() const
+unsigned DOMSelection::focusOffset() const
{
if (!m_frame)
return 0;
@@ -139,7 +139,7 @@ Node* DOMSelection::baseNode() const
return shadowAdjustedNode(basePosition(visibleSelection()));
}
-int DOMSelection::baseOffset() const
+unsigned DOMSelection::baseOffset() const
{
if (!m_frame)
return 0;
@@ -155,7 +155,7 @@ Node* DOMSelection::extentNode() const
return shadowAdjustedNode(extentPosition(visibleSelection()));
}
-int DOMSelection::extentOffset() const
+unsigned DOMSelection::extentOffset() const
{
if (!m_frame)
return 0;
@@ -187,14 +187,14 @@ String DOMSelection::type() const
return "Range";
}
-int DOMSelection::rangeCount() const
+unsigned DOMSelection::rangeCount() const
{
if (!m_frame)
return 0;
return m_frame->selection().isNone() ? 0 : 1;
}
-void DOMSelection::collapse(Node* node, int offset, ExceptionState& exceptionState)
+void DOMSelection::collapse(Node* node, unsigned offset, ExceptionState& exceptionState)
{
if (!m_frame)
return;
@@ -204,8 +204,8 @@ void DOMSelection::collapse(Node* node, int offset, ExceptionState& exceptionSta
return;
}
- if (offset < 0) {
- exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset.");
+ if (offset > node->lengthOfContents()) {
+ exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is larger than the given node's length.");
return;
}
@@ -258,18 +258,18 @@ void DOMSelection::empty()
m_frame->selection().clear();
}
-void DOMSelection::setBaseAndExtent(Node* baseNode, int baseOffset, Node* extentNode, int extentOffset, ExceptionState& exceptionState)
+void DOMSelection::setBaseAndExtent(Node* baseNode, unsigned baseOffset, Node* extentNode, unsigned extentOffset, ExceptionState& exceptionState)
{
if (!m_frame)
return;
- if (baseOffset < 0) {
- exceptionState.throwDOMException(IndexSizeError, String::number(baseOffset) + " is not a valid base offset.");
+ if (baseNode && baseOffset > baseNode->lengthOfContents()) {
+ exceptionState.throwDOMException(IndexSizeError, String::number(baseOffset) + " is larger than the base node's length.");
yoichio 2015/07/13 02:29:45 Raising exception when offset is over content leng
philipj_slow 2015/07/13 07:13:49 The spec has different variable names, but it actu
Habib Virji 2015/08/05 09:33:44 @philipj: As far as I can see no error. If it exce
Habib Virji 2015/08/05 09:33:44 Actually spec says to throw an error for both the
return;
}
- if (extentOffset < 0) {
- exceptionState.throwDOMException(IndexSizeError, String::number(extentOffset) + " is not a valid extent offset.");
+ if (extentNode && baseNode && extentOffset > (baseNode->lengthOfContents() + extentNode->lengthOfContents())) {
+ exceptionState.throwDOMException(IndexSizeError, String::number(extentOffset) + " is larger than the extent node's length.");
return;
}
@@ -333,18 +333,14 @@ void DOMSelection::modify(const String& alterString, const String& directionStri
m_frame->selection().modify(alter, direction, granularity);
}
-void DOMSelection::extend(Node* node, int offset, ExceptionState& exceptionState)
+void DOMSelection::extend(Node* node, unsigned offset, ExceptionState& exceptionState)
{
ASSERT(node);
if (!m_frame)
return;
- if (offset < 0) {
- exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset.");
- return;
- }
- if (static_cast<unsigned>(offset) > node->lengthOfContents()) {
+ if (offset > node->lengthOfContents()) {
exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is larger than the given node's length.");
return;
}
@@ -356,12 +352,12 @@ void DOMSelection::extend(Node* node, int offset, ExceptionState& exceptionState
m_frame->selection().setExtent(VisiblePosition(createLegacyEditingPosition(node, offset), DOWNSTREAM));
}
-PassRefPtrWillBeRawPtr<Range> DOMSelection::getRangeAt(int index, ExceptionState& exceptionState)
+PassRefPtrWillBeRawPtr<Range> DOMSelection::getRangeAt(unsigned index, ExceptionState& exceptionState)
{
if (!m_frame)
return nullptr;
- if (index < 0 || index >= rangeCount()) {
+ if (index >= rangeCount()) {
exceptionState.throwDOMException(IndexSizeError, String::number(index) + " is not a valid index.");
return nullptr;
}
@@ -527,7 +523,7 @@ Node* DOMSelection::shadowAdjustedNode(const Position& position) const
return adjustedNode->parentOrShadowHostNode();
}
-int DOMSelection::shadowAdjustedOffset(const Position& position) const
+unsigned DOMSelection::shadowAdjustedOffset(const Position& position) const
{
if (position.isNull())
return 0;

Powered by Google App Engine
This is Rietveld 408576698