| Index: third_party/WebKit/Source/core/dom/RangeBoundaryPoint.h
|
| diff --git a/third_party/WebKit/Source/core/dom/RangeBoundaryPoint.h b/third_party/WebKit/Source/core/dom/RangeBoundaryPoint.h
|
| index 7b2dd719d8d1843ef53e23c69eb569d297ceaf31..2e9c80c7c3f9393c5513e9831565d5184304de74 100644
|
| --- a/third_party/WebKit/Source/core/dom/RangeBoundaryPoint.h
|
| +++ b/third_party/WebKit/Source/core/dom/RangeBoundaryPoint.h
|
| @@ -44,20 +44,19 @@ class RangeBoundaryPoint {
|
| const Position toPosition() const;
|
|
|
| Node* container() const;
|
| - int offset() const;
|
| + unsigned offset() const;
|
| Node* childBefore() const;
|
|
|
| void clear();
|
|
|
| - void set(Node* container, int offset, Node* childBefore);
|
| - void setOffset(int);
|
| + void set(Node* container, unsigned offset, Node* childBefore);
|
| + void setOffset(unsigned);
|
|
|
| void setToBeforeChild(Node&);
|
| void setToStartOfNode(Node&);
|
| void setToEndOfNode(Node&);
|
|
|
| void childBeforeWillBeRemoved();
|
| - void invalidateOffset();
|
| void markValid() const;
|
|
|
| DEFINE_INLINE_TRACE() {
|
| @@ -70,23 +69,25 @@ class RangeBoundaryPoint {
|
| void ensureOffsetIsValid() const;
|
| bool isOffsetValid() const;
|
|
|
| - static const int invalidOffset = -1;
|
| -
|
| Member<Node> m_containerNode;
|
| Member<Node> m_childBeforeBoundary;
|
| +
|
| + mutable bool m_isValidOffset;
|
| mutable uint64_t m_domTreeVersion;
|
| - mutable int m_offsetInContainer;
|
| + mutable unsigned m_offsetInContainer;
|
| };
|
|
|
| inline RangeBoundaryPoint::RangeBoundaryPoint(Node* container)
|
| : m_containerNode(container),
|
| m_childBeforeBoundary(nullptr),
|
| + m_isValidOffset(true),
|
| m_domTreeVersion(domTreeVersion()),
|
| m_offsetInContainer(0) {}
|
|
|
| inline RangeBoundaryPoint::RangeBoundaryPoint(const RangeBoundaryPoint& other)
|
| : m_containerNode(other.container()),
|
| m_childBeforeBoundary(other.childBefore()),
|
| + m_isValidOffset(true),
|
| m_domTreeVersion(other.m_domTreeVersion),
|
| m_offsetInContainer(other.offset()) {}
|
|
|
| @@ -107,6 +108,7 @@ inline void RangeBoundaryPoint::ensureOffsetIsValid() const {
|
| return;
|
| DCHECK(!m_containerNode->isCharacterDataNode());
|
| markValid();
|
| + m_isValidOffset = true;
|
| if (!m_childBeforeBoundary) {
|
| m_offsetInContainer = 0;
|
| return;
|
| @@ -119,10 +121,11 @@ inline bool RangeBoundaryPoint::isConnected() const {
|
| }
|
|
|
| inline bool RangeBoundaryPoint::isOffsetValid() const {
|
| - if (m_offsetInContainer == invalidOffset) {
|
| + if (!m_isValidOffset) {
|
| DCHECK(!m_containerNode->isTextNode());
|
| return false;
|
| }
|
| +
|
| return domTreeVersion() == m_domTreeVersion ||
|
| m_containerNode->isCharacterDataNode();
|
| }
|
| @@ -135,36 +138,37 @@ inline const Position RangeBoundaryPoint::toPosition() const {
|
| m_offsetInContainer);
|
| }
|
|
|
| -inline int RangeBoundaryPoint::offset() const {
|
| +inline unsigned RangeBoundaryPoint::offset() const {
|
| ensureOffsetIsValid();
|
| return m_offsetInContainer;
|
| }
|
|
|
| inline void RangeBoundaryPoint::clear() {
|
| m_containerNode.clear();
|
| + m_isValidOffset = true;
|
| m_offsetInContainer = 0;
|
| m_childBeforeBoundary = nullptr;
|
| m_domTreeVersion = 0;
|
| }
|
|
|
| inline void RangeBoundaryPoint::set(Node* container,
|
| - int offset,
|
| + unsigned offset,
|
| Node* childBefore) {
|
| DCHECK(container);
|
| - DCHECK_GE(offset, 0);
|
| DCHECK_EQ(childBefore,
|
| offset ? NodeTraversal::childAt(*container, offset - 1) : 0);
|
| m_containerNode = container;
|
| + m_isValidOffset = true;
|
| m_offsetInContainer = offset;
|
| m_childBeforeBoundary = childBefore;
|
| markValid();
|
| }
|
|
|
| -inline void RangeBoundaryPoint::setOffset(int offset) {
|
| +inline void RangeBoundaryPoint::setOffset(unsigned offset) {
|
| DCHECK(m_containerNode);
|
| DCHECK(m_containerNode->isCharacterDataNode());
|
| - DCHECK_GE(m_offsetInContainer, 0);
|
| DCHECK(!m_childBeforeBoundary);
|
| + m_isValidOffset = true;
|
| m_offsetInContainer = offset;
|
| markValid();
|
| }
|
| @@ -173,12 +177,18 @@ inline void RangeBoundaryPoint::setToBeforeChild(Node& child) {
|
| DCHECK(child.parentNode());
|
| m_childBeforeBoundary = child.previousSibling();
|
| m_containerNode = child.parentNode();
|
| - m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0;
|
| + if (m_childBeforeBoundary) {
|
| + m_isValidOffset = false;
|
| + } else {
|
| + m_isValidOffset = true;
|
| + m_offsetInContainer = 0;
|
| + }
|
| markValid();
|
| }
|
|
|
| inline void RangeBoundaryPoint::setToStartOfNode(Node& container) {
|
| m_containerNode = &container;
|
| + m_isValidOffset = true;
|
| m_offsetInContainer = 0;
|
| m_childBeforeBoundary = nullptr;
|
| markValid();
|
| @@ -187,11 +197,17 @@ inline void RangeBoundaryPoint::setToStartOfNode(Node& container) {
|
| inline void RangeBoundaryPoint::setToEndOfNode(Node& container) {
|
| m_containerNode = &container;
|
| if (m_containerNode->isCharacterDataNode()) {
|
| + m_isValidOffset = true;
|
| m_offsetInContainer = m_containerNode->maxCharacterOffset();
|
| m_childBeforeBoundary = nullptr;
|
| } else {
|
| m_childBeforeBoundary = m_containerNode->lastChild();
|
| - m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0;
|
| + if (m_childBeforeBoundary) {
|
| + m_isValidOffset = false;
|
| + } else {
|
| + m_isValidOffset = true;
|
| + m_offsetInContainer = 0;
|
| + }
|
| }
|
| markValid();
|
| }
|
| @@ -200,7 +216,6 @@ inline void RangeBoundaryPoint::childBeforeWillBeRemoved() {
|
| m_childBeforeBoundary = m_childBeforeBoundary->previousSibling();
|
| if (!isOffsetValid())
|
| return;
|
| - DCHECK_GT(m_offsetInContainer, 0);
|
| if (!m_childBeforeBoundary)
|
| m_offsetInContainer = 0;
|
| else if (m_offsetInContainer > 0)
|
| @@ -208,10 +223,6 @@ inline void RangeBoundaryPoint::childBeforeWillBeRemoved() {
|
| markValid();
|
| }
|
|
|
| -inline void RangeBoundaryPoint::invalidateOffset() {
|
| - m_offsetInContainer = invalidOffset;
|
| -}
|
| -
|
| inline void RangeBoundaryPoint::markValid() const {
|
| m_domTreeVersion = domTreeVersion();
|
| }
|
|
|