Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/DOMSelection.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/DOMSelection.cpp b/third_party/WebKit/Source/core/editing/DOMSelection.cpp |
| index d473161afba0f1e496fda0842d1b9f6079b6c2fb..aa15eb366788d22e532b65d8de49279b9a4a7dda 100644 |
| --- a/third_party/WebKit/Source/core/editing/DOMSelection.cpp |
| +++ b/third_party/WebKit/Source/core/editing/DOMSelection.cpp |
| @@ -125,8 +125,25 @@ static Position extentPosition(const VisibleSelection& selection) { |
| return selection.extent().parentAnchoredEquivalent(); |
| } |
| +class ScopedRange { |
|
yosin_UTC9
2017/03/30 08:58:17
Please introduce a function acts like primaryRange
|
| + STACK_ALLOCATED(); |
| + |
| + public: |
| + ScopedRange(Range* range, bool dispose) |
| + : m_range(range), m_dispose(dispose) {} |
| + ~ScopedRange() { |
| + if (m_dispose) |
| + m_range->dispose(); |
| + } |
| + |
| + private: |
| + Member<Range> m_range; |
| + bool m_dispose; |
| +}; |
| + |
| Node* DOMSelection::anchorNode() const { |
| if (Range* range = primaryRangeOrNull()) { |
| + ScopedRange scope(range, !isSelectionOfDocument()); |
| if (!frame() || isBaseFirstInSelection()) |
| return range->startContainer(); |
| return range->endContainer(); |
| @@ -136,6 +153,7 @@ Node* DOMSelection::anchorNode() const { |
| unsigned DOMSelection::anchorOffset() const { |
| if (Range* range = primaryRangeOrNull()) { |
| + ScopedRange scope(range, !isSelectionOfDocument()); |
| if (!frame() || isBaseFirstInSelection()) |
| return range->startOffset(); |
| return range->endOffset(); |
| @@ -145,6 +163,7 @@ unsigned DOMSelection::anchorOffset() const { |
| Node* DOMSelection::focusNode() const { |
| if (Range* range = primaryRangeOrNull()) { |
| + ScopedRange scope(range, !isSelectionOfDocument()); |
| if (!frame() || isBaseFirstInSelection()) |
| return range->endContainer(); |
| return range->startContainer(); |
| @@ -154,6 +173,7 @@ Node* DOMSelection::focusNode() const { |
| unsigned DOMSelection::focusOffset() const { |
| if (Range* range = primaryRangeOrNull()) { |
| + ScopedRange scope(range, !isSelectionOfDocument()); |
| if (!frame() || isBaseFirstInSelection()) |
| return range->endOffset(); |
| return range->startOffset(); |
| @@ -589,7 +609,9 @@ void DOMSelection::removeRange(Range* range) { |
| DCHECK(range); |
| if (!isAvailable()) |
| return; |
| - if (range == primaryRangeOrNull()) |
| + Range* originalRange = primaryRangeOrNull(); |
| + ScopedRange scope(originalRange, !isSelectionOfDocument()); |
| + if (range == originalRange) |
| frame()->selection().clear(); |
| } |
| @@ -631,6 +653,7 @@ void DOMSelection::addRange(Range* newRange) { |
| Range* originalRange = primaryRangeOrNull(); |
| DCHECK(originalRange); |
| + ScopedRange scope(originalRange, !isSelectionOfDocument()); |
| if (originalRange->startContainer()->treeScope() != |
| newRange->startContainer()->treeScope()) { |