Diff
Modified: trunk/LayoutTests/ChangeLog (203732 => 203733)
--- trunk/LayoutTests/ChangeLog 2016-07-26 20:18:03 UTC (rev 203732)
+++ trunk/LayoutTests/ChangeLog 2016-07-26 20:54:25 UTC (rev 203733)
@@ -1,3 +1,15 @@
+2016-07-26 Chris Dumez <cdu...@apple.com>
+
+ Second parameter to Range.isPointInRange() / comparePoint() should be mandatory
+ https://bugs.webkit.org/show_bug.cgi?id=160202
+
+ Reviewed by Ryosuke Niwa.
+
+ Update existing test to reflect behavior change.
+
+ * fast/dom/non-numeric-values-numeric-parameters-expected.txt:
+ * fast/dom/script-tests/non-numeric-values-numeric-parameters.js:
+
2016-07-26 Youenn Fablet <you...@apple.com>
[Fetch API] Add support for fetch mode, in particular cors
Modified: trunk/LayoutTests/fast/dom/non-numeric-values-numeric-parameters-expected.txt (203732 => 203733)
--- trunk/LayoutTests/fast/dom/non-numeric-values-numeric-parameters-expected.txt 2016-07-26 20:18:03 UTC (rev 203732)
+++ trunk/LayoutTests/fast/dom/non-numeric-values-numeric-parameters-expected.txt 2016-07-26 20:54:25 UTC (rev 203733)
@@ -53,8 +53,8 @@
PASS nonNumericPolicy('document.getElementsByTagName("div").item(x)') is 'any type allowed (but not omitted)'
PASS nonNumericPolicy('document.createRange().setStart(document, x)') is 'any type allowed (but not omitted)'
PASS nonNumericPolicy('document.createRange().setEnd(document, x)') is 'any type allowed (but not omitted)'
-PASS nonNumericPolicy('document.createRange().comparePoint(document, x)') is 'any type allowed'
-PASS nonNumericPolicy('document.createRange().isPointInRange(document, x)') is 'any type allowed'
+PASS nonNumericPolicy('document.createRange().comparePoint(document, x)') is 'any type allowed (but not omitted)'
+PASS nonNumericPolicy('document.createRange().isPointInRange(document, x)') is 'any type allowed (but not omitted)'
PASS nonNumericPolicy('getSelection().collapse(document, x)') is 'any type allowed'
PASS nonNumericPolicy('getSelection().setBaseAndExtent(document, x, document, 0)') is 'any type allowed'
PASS nonNumericPolicy('getSelection().setBaseAndExtent(document, 0, document, x)') is 'any type allowed'
Modified: trunk/LayoutTests/fast/dom/script-tests/non-numeric-values-numeric-parameters.js (203732 => 203733)
--- trunk/LayoutTests/fast/dom/script-tests/non-numeric-values-numeric-parameters.js 2016-07-26 20:18:03 UTC (rev 203732)
+++ trunk/LayoutTests/fast/dom/script-tests/non-numeric-values-numeric-parameters.js 2016-07-26 20:54:25 UTC (rev 203733)
@@ -305,8 +305,8 @@
shouldBe("nonNumericPolicy('document.createRange().setStart(document, x)')", "'any type allowed (but not omitted)'");
shouldBe("nonNumericPolicy('document.createRange().setEnd(document, x)')", "'any type allowed (but not omitted)'");
-shouldBe("nonNumericPolicy('document.createRange().comparePoint(document, x)')", "'any type allowed'");
-shouldBe("nonNumericPolicy('document.createRange().isPointInRange(document, x)')", "'any type allowed'");
+shouldBe("nonNumericPolicy('document.createRange().comparePoint(document, x)')", "'any type allowed (but not omitted)'");
+shouldBe("nonNumericPolicy('document.createRange().isPointInRange(document, x)')", "'any type allowed (but not omitted)'");
// Selection
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (203732 => 203733)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2016-07-26 20:18:03 UTC (rev 203732)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2016-07-26 20:54:25 UTC (rev 203733)
@@ -1,3 +1,14 @@
+2016-07-26 Chris Dumez <cdu...@apple.com>
+
+ Second parameter to Range.isPointInRange() / comparePoint() should be mandatory
+ https://bugs.webkit.org/show_bug.cgi?id=160202
+
+ Reviewed by Ryosuke Niwa.
+
+ Rebaseline W3C test now that more checks are passing.
+
+ * web-platform-tests/dom/interfaces-expected.txt:
+
2016-07-26 Youenn Fablet <you...@apple.com>
[Fetch API] Add support for fetch mode, in particular cors
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt (203732 => 203733)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt 2016-07-26 20:18:03 UTC (rev 203732)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt 2016-07-26 20:54:25 UTC (rev 203733)
@@ -1316,8 +1316,8 @@
PASS Range interface: operation surroundContents(Node)
PASS Range interface: operation cloneRange()
PASS Range interface: operation detach()
-FAIL Range interface: operation isPointInRange(Node,unsigned long) assert_equals: property has wrong .length expected 2 but got 1
-FAIL Range interface: operation comparePoint(Node,unsigned long) assert_equals: property has wrong .length expected 2 but got 1
+PASS Range interface: operation isPointInRange(Node,unsigned long)
+PASS Range interface: operation comparePoint(Node,unsigned long)
PASS Range interface: operation intersectsNode(Node)
PASS Range interface: stringifier
PASS Range must be primary interface of document.createRange()
@@ -1362,13 +1362,9 @@
PASS Range interface: document.createRange() must inherit property "cloneRange" with the proper type (25)
PASS Range interface: document.createRange() must inherit property "detach" with the proper type (26)
PASS Range interface: document.createRange() must inherit property "isPointInRange" with the proper type (27)
-FAIL Range interface: calling isPointInRange(Node,unsigned long) on document.createRange() with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
- fn.apply(obj, args);
- }" did not throw
+PASS Range interface: calling isPointInRange(Node,unsigned long) on document.createRange() with too few arguments must throw TypeError
PASS Range interface: document.createRange() must inherit property "comparePoint" with the proper type (28)
-FAIL Range interface: calling comparePoint(Node,unsigned long) on document.createRange() with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
- fn.apply(obj, args);
- }" threw object "WrongDocumentError (DOM Exception 4): The object is in th..." ("WrongDocumentError") expected object "TypeError" ("TypeError")
+PASS Range interface: calling comparePoint(Node,unsigned long) on document.createRange() with too few arguments must throw TypeError
PASS Range interface: document.createRange() must inherit property "intersectsNode" with the proper type (29)
PASS Range interface: calling intersectsNode(Node) on document.createRange() with too few arguments must throw TypeError
PASS Range must be primary interface of detachedRange
@@ -1413,13 +1409,9 @@
PASS Range interface: detachedRange must inherit property "cloneRange" with the proper type (25)
PASS Range interface: detachedRange must inherit property "detach" with the proper type (26)
PASS Range interface: detachedRange must inherit property "isPointInRange" with the proper type (27)
-FAIL Range interface: calling isPointInRange(Node,unsigned long) on detachedRange with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
- fn.apply(obj, args);
- }" did not throw
+PASS Range interface: calling isPointInRange(Node,unsigned long) on detachedRange with too few arguments must throw TypeError
PASS Range interface: detachedRange must inherit property "comparePoint" with the proper type (28)
-FAIL Range interface: calling comparePoint(Node,unsigned long) on detachedRange with too few arguments must throw TypeError assert_throws: Called with 1 arguments function "function () {
- fn.apply(obj, args);
- }" threw object "WrongDocumentError (DOM Exception 4): The object is in th..." ("WrongDocumentError") expected object "TypeError" ("TypeError")
+PASS Range interface: calling comparePoint(Node,unsigned long) on detachedRange with too few arguments must throw TypeError
PASS Range interface: detachedRange must inherit property "intersectsNode" with the proper type (29)
PASS Range interface: calling intersectsNode(Node) on detachedRange with too few arguments must throw TypeError
PASS NodeIterator interface: existence and properties of interface object
Modified: trunk/Source/WebCore/ChangeLog (203732 => 203733)
--- trunk/Source/WebCore/ChangeLog 2016-07-26 20:18:03 UTC (rev 203732)
+++ trunk/Source/WebCore/ChangeLog 2016-07-26 20:54:25 UTC (rev 203733)
@@ -1,3 +1,48 @@
+2016-07-26 Chris Dumez <cdu...@apple.com>
+
+ Second parameter to Range.isPointInRange() / comparePoint() should be mandatory
+ https://bugs.webkit.org/show_bug.cgi?id=160202
+
+ Reviewed by Ryosuke Niwa.
+
+ Second parameter to Range.isPointInRange() / comparePoint() should be mandatory
+ and be of type "unsigned long":
+ - https://dom.spec.whatwg.org/#interface-range
+
+ Firefox and Chrome agree with the specification.
+
+ No new tests, rebaselined existing tests.
+
+ * accessibility/AXObjectCache.cpp:
+ (WebCore::AXObjectCache::traverseToOffsetInRange):
+ * dom/DocumentMarkerController.cpp:
+ (WebCore::DocumentMarkerController::removeMarkers):
+ (WebCore::DocumentMarkerController::markersInRange):
+ (DocumentMarkerController::setMarkersActive):
+ * dom/Range.cpp:
+ (WebCore::Range::isPointInRange):
+ (WebCore::Range::comparePoint):
+ (WebCore::Range::compareBoundaryPoints):
+ (WebCore::Range::toString):
+ (WebCore::Range::absoluteTextRects):
+ (WebCore::Range::absoluteTextQuads):
+ (WebCore::boundaryTextNodesMerged):
+ (WebCore::Range::getBorderAndTextQuads):
+ * dom/Range.h:
+ (WebCore::Range::startOffset):
+ (WebCore::Range::endOffset):
+ * dom/Range.idl:
+ * dom/RangeBoundaryPoint.h:
+ (WebCore::RangeBoundaryPoint::ensureOffsetIsValid):
+ (WebCore::RangeBoundaryPoint::toPosition):
+ (WebCore::RangeBoundaryPoint::offset):
+ (WebCore::RangeBoundaryPoint::setOffset):
+ (WebCore::RangeBoundaryPoint::setToBeforeChild):
+ (WebCore::RangeBoundaryPoint::setToAfterChild):
+ (WebCore::RangeBoundaryPoint::setToEndOfNode):
+ (WebCore::RangeBoundaryPoint::childBeforeWillBeRemoved):
+ (WebCore::RangeBoundaryPoint::invalidateOffset):
+
2016-07-26 Youenn Fablet <you...@apple.com>
[Fetch API] Add support for fetch mode, in particular cors
Modified: trunk/Source/WebCore/accessibility/AXObjectCache.cpp (203732 => 203733)
--- trunk/Source/WebCore/accessibility/AXObjectCache.cpp 2016-07-26 20:18:03 UTC (rev 203732)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.cpp 2016-07-26 20:54:25 UTC (rev 203733)
@@ -1604,7 +1604,7 @@
// Sometimes when we are getting the end CharacterOffset of a line range, the TextIterator will emit an extra space at the end
// and make the character count greater than the Range's end offset.
- if (toNodeEnd && currentNode->isTextNode() && currentNode == &range->endContainer() && range->endOffset() < lastStartOffset + offsetInCharacter)
+ if (toNodeEnd && currentNode->isTextNode() && currentNode == &range->endContainer() && static_cast<int>(range->endOffset()) < lastStartOffset + offsetInCharacter)
offsetInCharacter = range->endOffset() - lastStartOffset;
return CharacterOffset(currentNode, lastStartOffset, offsetInCharacter, remaining);
Modified: trunk/Source/WebCore/accessibility/atk/WebKitAccessibleUtil.cpp (203732 => 203733)
--- trunk/Source/WebCore/accessibility/atk/WebKitAccessibleUtil.cpp 2016-07-26 20:18:03 UTC (rev 203732)
+++ trunk/Source/WebCore/accessibility/atk/WebKitAccessibleUtil.cpp 2016-07-26 20:54:25 UTC (rev 203733)
@@ -163,7 +163,7 @@
Node* lastDescendant = node->lastDescendant();
return (range->intersectsNode(*node, IGNORE_EXCEPTION)
&& (&range->endContainer() != node || range->endOffset())
- && (&range->startContainer() != lastDescendant || range->startOffset() != lastOffsetInNode(lastDescendant)));
+ && (&range->startContainer() != lastDescendant || static_cast<int>(range->startOffset()) != lastOffsetInNode(lastDescendant)));
}
#endif
Modified: trunk/Source/WebCore/dom/DocumentMarkerController.cpp (203732 => 203733)
--- trunk/Source/WebCore/dom/DocumentMarkerController.cpp 2016-07-26 20:18:03 UTC (rev 203732)
+++ trunk/Source/WebCore/dom/DocumentMarkerController.cpp 2016-07-26 20:54:25 UTC (rev 203733)
@@ -142,8 +142,8 @@
ASSERT(!m_markers.isEmpty());
RefPtr<Range> textPiece = markedText.range();
- int startOffset = textPiece->startOffset();
- int endOffset = textPiece->endOffset();
+ unsigned startOffset = textPiece->startOffset();
+ unsigned endOffset = textPiece->endOffset();
removeMarkers(&textPiece->startContainer(), startOffset, endOffset - startOffset, markerTypes, shouldRemovePartiallyOverlappingMarker);
}
}
@@ -531,9 +531,9 @@
for (auto* marker : markersFor(node)) {
if (!markerTypes.contains(marker->type()))
continue;
- if (node == &startContainer && marker->endOffset() <= static_cast<unsigned>(range->startOffset()))
+ if (node == &startContainer && marker->endOffset() <= range->startOffset())
continue;
- if (node == &endContainer && marker->startOffset() >= static_cast<unsigned>(range->endOffset()))
+ if (node == &endContainer && marker->startOffset() >= range->endOffset())
continue;
foundMarkers.append(marker);
}
@@ -701,8 +701,8 @@
Node* pastLastNode = range->pastLastNode();
for (Node* node = range->firstNode(); node != pastLastNode; node = NodeTraversal::next(*node)) {
- int startOffset = node == &startContainer ? range->startOffset() : 0;
- int endOffset = node == &endContainer ? range->endOffset() : INT_MAX;
+ unsigned startOffset = node == &startContainer ? range->startOffset() : 0;
+ unsigned endOffset = node == &endContainer ? range->endOffset() : std::numeric_limits<unsigned>::max();
setMarkersActive(node, startOffset, endOffset, active);
}
}
Modified: trunk/Source/WebCore/dom/Range.cpp (203732 => 203733)
--- trunk/Source/WebCore/dom/Range.cpp 2016-07-26 20:18:03 UTC (rev 203732)
+++ trunk/Source/WebCore/dom/Range.cpp 2016-07-26 20:54:25 UTC (rev 203733)
@@ -226,7 +226,7 @@
m_start = m_end;
}
-bool Range::isPointInRange(Node& refNode, int offset, ExceptionCode& ec)
+bool Range::isPointInRange(Node& refNode, unsigned offset, ExceptionCode& ec)
{
if (&refNode.document() != &ownerDocument()) {
return false;
@@ -249,7 +249,7 @@
return result;
}
-short Range::comparePoint(Node& refNode, int offset, ExceptionCode& ec) const
+short Range::comparePoint(Node& refNode, unsigned offset, ExceptionCode& ec) const
{
// http://developer.mozilla.org/en/docs/DOM:range.comparePoint
// This method returns -1, 0 or 1 depending on if the point described by the
@@ -367,7 +367,7 @@
return compareBoundaryPoints(static_cast<CompareHow>(compareHow), sourceRange, ec);
}
-short Range::compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB, ExceptionCode& ec)
+short Range::compareBoundaryPoints(Node* containerA, unsigned offsetA, Node* containerB, unsigned offsetB, ExceptionCode& ec)
{
ASSERT(containerA);
ASSERT(containerB);
@@ -394,7 +394,7 @@
while (c && c->parentNode() != containerA)
c = c->parentNode();
if (c) {
- int offsetC = 0;
+ unsigned offsetC = 0;
Node* n = containerA->firstChild();
while (n != c && offsetC < offsetA) {
offsetC++;
@@ -412,7 +412,7 @@
while (c && c->parentNode() != containerB)
c = c->parentNode();
if (c) {
- int offsetC = 0;
+ unsigned offsetC = 0;
Node* n = containerB->firstChild();
while (n != c && offsetC < offsetB) {
offsetC++;
@@ -869,9 +869,9 @@
for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(*n)) {
if (n->nodeType() == Node::TEXT_NODE || n->nodeType() == Node::CDATA_SECTION_NODE) {
const String& data = ""
- int length = data.length();
- int start = n == &startContainer() ? std::min(std::max(0, m_start.offset()), length) : 0;
- int end = n == &endContainer() ? std::min(std::max(start, m_end.offset()), length) : length;
+ unsigned length = data.length();
+ unsigned start = n == &startContainer() ? std::min(std::max(0U, m_start.offset()), length) : 0U;
+ unsigned end = n == &endContainer() ? std::min(std::max(start, m_end.offset()), length) : length;
builder.append(data, start, end - start);
}
}
@@ -1149,8 +1149,8 @@
if (renderer->isBR())
renderer->absoluteRects(rects, flooredLayoutPoint(renderer->localToAbsolute()));
else if (is<RenderText>(*renderer)) {
- int startOffset = node == &startContainer() ? m_start.offset() : 0;
- int endOffset = node == &endContainer() ? m_end.offset() : std::numeric_limits<int>::max();
+ unsigned startOffset = node == &startContainer() ? m_start.offset() : 0;
+ unsigned endOffset = node == &endContainer() ? m_end.offset() : std::numeric_limits<unsigned>::max();
rects.appendVector(downcast<RenderText>(*renderer).absoluteRectsForRange(startOffset, endOffset, useSelectionHeight, &isFixed));
} else
continue;
@@ -1176,8 +1176,8 @@
if (renderer->isBR())
renderer->absoluteQuads(quads, &isFixed);
else if (is<RenderText>(*renderer)) {
- int startOffset = node == &startContainer() ? m_start.offset() : 0;
- int endOffset = node == &endContainer() ? m_end.offset() : std::numeric_limits<int>::max();
+ unsigned startOffset = node == &startContainer() ? m_start.offset() : 0;
+ unsigned endOffset = node == &endContainer() ? m_end.offset() : std::numeric_limits<unsigned>::max();
quads.appendVector(downcast<RenderText>(*renderer).absoluteQuadsForRange(startOffset, endOffset, useSelectionHeight, &isFixed));
} else
continue;
@@ -1644,7 +1644,7 @@
{
if (boundary.container() == oldNode.node())
boundary.set(*oldNode.node()->previousSibling(), boundary.offset() + offset, 0);
- else if (boundary.container() == oldNode.node()->parentNode() && boundary.offset() == oldNode.index())
+ else if (boundary.container() == oldNode.node()->parentNode() && static_cast<int>(boundary.offset()) == oldNode.index())
boundary.set(*oldNode.node()->previousSibling(), offset, 0);
}
@@ -1763,8 +1763,8 @@
}
} else if (is<Text>(*node)) {
if (RenderText* renderText = downcast<Text>(*node).renderer()) {
- int startOffset = node == &startContainer() ? m_start.offset() : 0;
- int endOffset = node == &endContainer() ? m_end.offset() : INT_MAX;
+ unsigned startOffset = node == &startContainer() ? m_start.offset() : 0;
+ unsigned endOffset = node == &endContainer() ? m_end.offset() : std::numeric_limits<unsigned>::max();
auto textQuads = renderText->absoluteQuadsForRange(startOffset, endOffset);
Modified: trunk/Source/WebCore/dom/Range.h (203732 => 203733)
--- trunk/Source/WebCore/dom/Range.h 2016-07-26 20:18:03 UTC (rev 203732)
+++ trunk/Source/WebCore/dom/Range.h 2016-07-26 20:54:25 UTC (rev 203733)
@@ -59,9 +59,9 @@
Document& ownerDocument() const { return const_cast<Document&>(m_ownerDocument.get()); }
Node& startContainer() const { ASSERT(m_start.container()); return *m_start.container(); }
- int startOffset() const { return m_start.offset(); }
+ unsigned startOffset() const { return m_start.offset(); }
Node& endContainer() const { ASSERT(m_end.container()); return *m_end.container(); }
- int endOffset() const { return m_end.offset(); }
+ unsigned endOffset() const { return m_end.offset(); }
bool collapsed() const { return m_start == m_end; }
Node* commonAncestorContainer() const { return commonAncestorContainer(&startContainer(), &endContainer()); }
@@ -69,14 +69,14 @@
WEBCORE_EXPORT void setStart(Ref<Node>&& container, unsigned offset, ExceptionCode& = ASSERT_NO_EXCEPTION);
WEBCORE_EXPORT void setEnd(Ref<Node>&& container, unsigned offset, ExceptionCode& = ASSERT_NO_EXCEPTION);
WEBCORE_EXPORT void collapse(bool toStart);
- WEBCORE_EXPORT bool isPointInRange(Node& refNode, int offset, ExceptionCode&);
- short comparePoint(Node& refNode, int offset, ExceptionCode&) const;
+ WEBCORE_EXPORT bool isPointInRange(Node& refNode, unsigned offset, ExceptionCode&);
+ short comparePoint(Node& refNode, unsigned offset, ExceptionCode&) const;
enum CompareResults { NODE_BEFORE, NODE_AFTER, NODE_BEFORE_AND_AFTER, NODE_INSIDE };
CompareResults compareNode(Node& refNode, ExceptionCode&) const;
enum CompareHow { START_TO_START, START_TO_END, END_TO_END, END_TO_START };
WEBCORE_EXPORT short compareBoundaryPoints(CompareHow, const Range& sourceRange, ExceptionCode&) const;
short compareBoundaryPointsForBindings(unsigned short compareHow, const Range& sourceRange, ExceptionCode&) const;
- static short compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB, ExceptionCode&);
+ static short compareBoundaryPoints(Node* containerA, unsigned offsetA, Node* containerB, unsigned offsetB, ExceptionCode&);
static short compareBoundaryPoints(const RangeBoundaryPoint& boundaryA, const RangeBoundaryPoint& boundaryB, ExceptionCode&);
WEBCORE_EXPORT bool boundaryPointsValid() const;
bool intersectsNode(Node& refNode, ExceptionCode&) const;
Modified: trunk/Source/WebCore/dom/Range.idl (203732 => 203733)
--- trunk/Source/WebCore/dom/Range.idl 2016-07-26 20:18:03 UTC (rev 203732)
+++ trunk/Source/WebCore/dom/Range.idl 2016-07-26 20:54:25 UTC (rev 203733)
@@ -89,10 +89,16 @@
const unsigned short NODE_BEFORE_AND_AFTER = 2;
const unsigned short NODE_INSIDE = 3;
- [RaisesException] short comparePoint(Node refNode, optional long offset = 0);
[RaisesException] boolean intersectsNode(Node refNode);
- [RaisesException] boolean isPointInRange(Node refNode, optional long offset = 0);
+#if defined(LANGUAGE_JAVASCRIPT) || LANGUAGE_JAVASCRIPT
+ [RaisesException] short comparePoint(Node refNode, unsigned long offset);
+ [RaisesException] boolean isPointInRange(Node refNode, unsigned long offset);
+#else
+ [RaisesException] short comparePoint(Node refNode, long offset);
+ [RaisesException] boolean isPointInRange(Node refNode, long offset);
+#endif
+
// FIXME: Using "undefined" as default parameter value is wrong.
[RaisesException] void expand(optional DOMString unit = "undefined");
Modified: trunk/Source/WebCore/dom/RangeBoundaryPoint.h (203732 => 203733)
--- trunk/Source/WebCore/dom/RangeBoundaryPoint.h 2016-07-26 20:18:03 UTC (rev 203732)
+++ trunk/Source/WebCore/dom/RangeBoundaryPoint.h 2016-07-26 20:54:25 UTC (rev 203733)
@@ -40,13 +40,13 @@
const Position toPosition() const;
Node* container() const;
- int offset() const;
+ unsigned offset() const;
Node* childBefore() const;
void clear();
void set(Ref<Node>&& container, unsigned offset, Node* childBefore);
- void setOffset(int offset);
+ void setOffset(unsigned);
void setToBeforeChild(Node&);
void setToAfterChild(Node&);
@@ -58,10 +58,8 @@
void ensureOffsetIsValid() const;
private:
- static const int invalidOffset = -1;
-
RefPtr<Node> m_containerNode;
- mutable int m_offsetInContainer { 0 };
+ mutable Optional<unsigned> m_offsetInContainer { 0 };
RefPtr<Node> m_childBeforeBoundary;
};
@@ -90,7 +88,7 @@
inline void RangeBoundaryPoint::ensureOffsetIsValid() const
{
- if (m_offsetInContainer >= 0)
+ if (m_offsetInContainer)
return;
ASSERT(m_childBeforeBoundary);
@@ -100,13 +98,13 @@
inline const Position RangeBoundaryPoint::toPosition() const
{
ensureOffsetIsValid();
- return createLegacyEditingPosition(m_containerNode.get(), m_offsetInContainer);
+ return createLegacyEditingPosition(m_containerNode.get(), m_offsetInContainer.value());
}
-inline int RangeBoundaryPoint::offset() const
+inline unsigned RangeBoundaryPoint::offset() const
{
ensureOffsetIsValid();
- return m_offsetInContainer;
+ return m_offsetInContainer.value();
}
inline void RangeBoundaryPoint::clear()
@@ -124,11 +122,11 @@
m_childBeforeBoundary = childBefore;
}
-inline void RangeBoundaryPoint::setOffset(int offset)
+inline void RangeBoundaryPoint::setOffset(unsigned offset)
{
ASSERT(m_containerNode);
ASSERT(m_containerNode->offsetInCharacters());
- ASSERT(m_offsetInContainer >= 0);
+ ASSERT(m_offsetInContainer);
ASSERT(!m_childBeforeBoundary);
m_offsetInContainer = offset;
}
@@ -138,7 +136,7 @@
ASSERT(child.parentNode());
m_childBeforeBoundary = child.previousSibling();
m_containerNode = child.parentNode();
- m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0;
+ m_offsetInContainer = m_childBeforeBoundary ? Nullopt : Optional<unsigned>(0);
}
inline void RangeBoundaryPoint::setToAfterChild(Node& child)
@@ -146,7 +144,7 @@
ASSERT(child.parentNode());
m_childBeforeBoundary = &child;
m_containerNode = child.parentNode();
- m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0;
+ m_offsetInContainer = m_childBeforeBoundary ? Nullopt : Optional<unsigned>(0);
}
inline void RangeBoundaryPoint::setToStartOfNode(Ref<Node>&& container)
@@ -164,23 +162,23 @@
m_childBeforeBoundary = nullptr;
} else {
m_childBeforeBoundary = m_containerNode->lastChild();
- m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0;
+ m_offsetInContainer = m_childBeforeBoundary ? Nullopt : Optional<unsigned>(0);
}
}
inline void RangeBoundaryPoint::childBeforeWillBeRemoved()
{
- ASSERT(m_offsetInContainer);
+ ASSERT(!m_offsetInContainer || m_offsetInContainer.value());
m_childBeforeBoundary = m_childBeforeBoundary->previousSibling();
if (!m_childBeforeBoundary)
m_offsetInContainer = 0;
- else if (m_offsetInContainer > 0)
- --m_offsetInContainer;
+ else if (m_offsetInContainer && m_offsetInContainer.value() > 0)
+ --(m_offsetInContainer.value());
}
inline void RangeBoundaryPoint::invalidateOffset() const
{
- m_offsetInContainer = invalidOffset;
+ m_offsetInContainer = Nullopt;
}
inline bool operator==(const RangeBoundaryPoint& a, const RangeBoundaryPoint& b)