| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "core/dom/Node.h" | 29 #include "core/dom/Node.h" |
| 30 #include "core/dom/NodeTraversal.h" | 30 #include "core/dom/NodeTraversal.h" |
| 31 #include "core/editing/Position.h" | 31 #include "core/editing/Position.h" |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 class RangeBoundaryPoint { | 35 class RangeBoundaryPoint { |
| 36 DISALLOW_NEW(); | 36 DISALLOW_NEW(); |
| 37 | 37 |
| 38 public: | 38 public: |
| 39 explicit RangeBoundaryPoint(Node* container); | 39 explicit RangeBoundaryPoint(Node& container); |
| 40 | 40 |
| 41 explicit RangeBoundaryPoint(const RangeBoundaryPoint&); | 41 explicit RangeBoundaryPoint(const RangeBoundaryPoint&); |
| 42 | 42 |
| 43 bool IsConnected() const; | 43 bool IsConnected() const; |
| 44 const Position ToPosition() const; | 44 const Position ToPosition() const; |
| 45 | 45 |
| 46 Node* Container() const; | 46 Node& Container() const; |
| 47 unsigned Offset() const; | 47 unsigned Offset() const; |
| 48 Node* ChildBefore() const; | 48 Node* ChildBefore() const; |
| 49 | 49 |
| 50 void Set(Node* container, unsigned offset, Node* child_before); | 50 void Set(Node& container, unsigned offset, Node* child_before); |
| 51 void SetOffset(unsigned); | 51 void SetOffset(unsigned); |
| 52 | 52 |
| 53 void SetToBeforeChild(Node&); | 53 void SetToBeforeChild(Node&); |
| 54 void SetToStartOfNode(Node&); | 54 void SetToStartOfNode(Node&); |
| 55 void SetToEndOfNode(Node&); | 55 void SetToEndOfNode(Node&); |
| 56 | 56 |
| 57 void ChildBeforeWillBeRemoved(); | 57 void ChildBeforeWillBeRemoved(); |
| 58 void InvalidateOffset(); | 58 void InvalidateOffset(); |
| 59 void MarkValid() const; | 59 void MarkValid() const; |
| 60 | 60 |
| 61 DEFINE_INLINE_TRACE() { | 61 DEFINE_INLINE_TRACE() { |
| 62 visitor->Trace(container_node_); | 62 visitor->Trace(container_node_); |
| 63 visitor->Trace(child_before_boundary_); | 63 visitor->Trace(child_before_boundary_); |
| 64 } | 64 } |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 uint64_t DomTreeVersion() const; | 67 uint64_t DomTreeVersion() const; |
| 68 void EnsureOffsetIsValid() const; | 68 void EnsureOffsetIsValid() const; |
| 69 bool IsOffsetValid() const; | 69 bool IsOffsetValid() const; |
| 70 | 70 |
| 71 static const unsigned kInvalidOffset = static_cast<unsigned>(-1); | 71 static const unsigned kInvalidOffset = static_cast<unsigned>(-1); |
| 72 | 72 |
| 73 Member<Node> container_node_; | 73 Member<Node> container_node_; |
| 74 Member<Node> child_before_boundary_; | 74 Member<Node> child_before_boundary_; |
| 75 mutable uint64_t dom_tree_version_; | 75 mutable uint64_t dom_tree_version_; |
| 76 mutable unsigned offset_in_container_; | 76 mutable unsigned offset_in_container_; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 inline RangeBoundaryPoint::RangeBoundaryPoint(Node* container) | 79 inline RangeBoundaryPoint::RangeBoundaryPoint(Node& container) |
| 80 : container_node_(container), | 80 : container_node_(container), |
| 81 child_before_boundary_(nullptr), | 81 child_before_boundary_(nullptr), |
| 82 dom_tree_version_(DomTreeVersion()), | 82 dom_tree_version_(DomTreeVersion()), |
| 83 offset_in_container_(0) {} | 83 offset_in_container_(0) {} |
| 84 | 84 |
| 85 inline RangeBoundaryPoint::RangeBoundaryPoint(const RangeBoundaryPoint& other) | 85 inline RangeBoundaryPoint::RangeBoundaryPoint(const RangeBoundaryPoint& other) |
| 86 : container_node_(other.Container()), | 86 : container_node_(other.Container()), |
| 87 child_before_boundary_(other.ChildBefore()), | 87 child_before_boundary_(other.ChildBefore()), |
| 88 dom_tree_version_(other.dom_tree_version_), | 88 dom_tree_version_(other.dom_tree_version_), |
| 89 offset_in_container_(other.Offset()) {} | 89 offset_in_container_(other.Offset()) {} |
| 90 | 90 |
| 91 inline Node* RangeBoundaryPoint::Container() const { | 91 inline Node& RangeBoundaryPoint::Container() const { |
| 92 return container_node_.Get(); | 92 return *container_node_; |
| 93 } | 93 } |
| 94 | 94 |
| 95 inline Node* RangeBoundaryPoint::ChildBefore() const { | 95 inline Node* RangeBoundaryPoint::ChildBefore() const { |
| 96 return child_before_boundary_.Get(); | 96 return child_before_boundary_.Get(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 inline uint64_t RangeBoundaryPoint::DomTreeVersion() const { | 99 inline uint64_t RangeBoundaryPoint::DomTreeVersion() const { |
| 100 return container_node_->GetDocument().DomTreeVersion(); | 100 return container_node_->GetDocument().DomTreeVersion(); |
| 101 } | 101 } |
| 102 | 102 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 130 // TODO(yosin): We should return |Position::beforeAnchor| when | 130 // TODO(yosin): We should return |Position::beforeAnchor| when |
| 131 // |m_containerNode| isn't |Text| node. | 131 // |m_containerNode| isn't |Text| node. |
| 132 return Position(container_node_.Get(), offset_in_container_); | 132 return Position(container_node_.Get(), offset_in_container_); |
| 133 } | 133 } |
| 134 | 134 |
| 135 inline unsigned RangeBoundaryPoint::Offset() const { | 135 inline unsigned RangeBoundaryPoint::Offset() const { |
| 136 EnsureOffsetIsValid(); | 136 EnsureOffsetIsValid(); |
| 137 return offset_in_container_; | 137 return offset_in_container_; |
| 138 } | 138 } |
| 139 | 139 |
| 140 inline void RangeBoundaryPoint::Set(Node* container, | 140 inline void RangeBoundaryPoint::Set(Node& container, |
| 141 unsigned offset, | 141 unsigned offset, |
| 142 Node* child_before) { | 142 Node* child_before) { |
| 143 DCHECK(container); | |
| 144 DCHECK_GE(offset, 0u); | 143 DCHECK_GE(offset, 0u); |
| 145 DCHECK_EQ(child_before, | 144 DCHECK_EQ(child_before, |
| 146 offset ? NodeTraversal::ChildAt(*container, offset - 1) : 0); | 145 offset ? NodeTraversal::ChildAt(container, offset - 1) : 0); |
| 147 container_node_ = container; | 146 container_node_ = container; |
| 148 offset_in_container_ = offset; | 147 offset_in_container_ = offset; |
| 149 child_before_boundary_ = child_before; | 148 child_before_boundary_ = child_before; |
| 150 MarkValid(); | 149 MarkValid(); |
| 151 } | 150 } |
| 152 | 151 |
| 153 inline void RangeBoundaryPoint::SetOffset(unsigned offset) { | 152 inline void RangeBoundaryPoint::SetOffset(unsigned offset) { |
| 154 DCHECK(container_node_); | 153 DCHECK(container_node_); |
| 155 DCHECK(container_node_->IsCharacterDataNode()); | 154 DCHECK(container_node_->IsCharacterDataNode()); |
| 156 DCHECK_GE(offset_in_container_, 0u); | 155 DCHECK_GE(offset_in_container_, 0u); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 } else { | 215 } else { |
| 217 if (a.Offset() != b.Offset()) | 216 if (a.Offset() != b.Offset()) |
| 218 return false; | 217 return false; |
| 219 } | 218 } |
| 220 return true; | 219 return true; |
| 221 } | 220 } |
| 222 | 221 |
| 223 } // namespace blink | 222 } // namespace blink |
| 224 | 223 |
| 225 #endif | 224 #endif |
| OLD | NEW |