Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) | 3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) |
| 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) | 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) |
| 5 * (C) 2001 Peter Kelly (pmk@post.com) | 5 * (C) 2001 Peter Kelly (pmk@post.com) |
| 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
| 7 * rights reserved. | 7 * rights reserved. |
| 8 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 8 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 #include "wtf/text/CString.h" | 55 #include "wtf/text/CString.h" |
| 56 #include "wtf/text/StringBuilder.h" | 56 #include "wtf/text/StringBuilder.h" |
| 57 #ifndef NDEBUG | 57 #ifndef NDEBUG |
| 58 #include <stdio.h> | 58 #include <stdio.h> |
| 59 #endif | 59 #endif |
| 60 | 60 |
| 61 namespace blink { | 61 namespace blink { |
| 62 | 62 |
| 63 class RangeUpdateScope { | 63 class RangeUpdateScope { |
| 64 STACK_ALLOCATED(); | 64 STACK_ALLOCATED(); |
| 65 RangeUpdateScope(Range* range) { | 65 RangeUpdateScope(Range* range) { |
|
dcheng
2017/03/30 18:46:31
Mind fixing this to add explicit while you're at i
nasko
2017/03/30 22:59:20
Done.
| |
| 66 DCHECK(range); | 66 DCHECK(range); |
| 67 if (++s_scopeCount == 1) { | 67 if (++s_scopeCount == 1) { |
| 68 m_range = range; | 68 m_range = range; |
| 69 m_oldDocument = range->ownerDocument(); | 69 m_oldDocument = range->ownerDocument(); |
| 70 #if DCHECK_IS_ON() | 70 #if DCHECK_IS_ON() |
| 71 s_range = range; | 71 s_rawRange = range; |
| 72 } else { | 72 } else { |
| 73 DCHECK_EQ(s_range, range); | 73 DCHECK_EQ(s_rawRange, range); |
| 74 #endif | 74 #endif |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 ~RangeUpdateScope() { | 78 ~RangeUpdateScope() { |
| 79 DCHECK_GE(s_scopeCount, 1); | 79 DCHECK_GE(s_scopeCount, 1); |
| 80 if (--s_scopeCount > 0) | 80 if (--s_scopeCount > 0) |
| 81 return; | 81 return; |
| 82 m_range->removeFromSelectionIfInDifferentRoot(*m_oldDocument); | 82 m_range->removeFromSelectionIfInDifferentRoot(*m_oldDocument); |
| 83 m_range->updateSelectionIfAddedToSelection(); | 83 m_range->updateSelectionIfAddedToSelection(); |
| 84 #if DCHECK_IS_ON() | 84 #if DCHECK_IS_ON() |
| 85 s_range = nullptr; | 85 s_rawRange = nullptr; |
| 86 #endif | 86 #endif |
| 87 } | 87 } |
| 88 | 88 |
| 89 private: | 89 private: |
| 90 static int s_scopeCount; | 90 static int s_scopeCount; |
| 91 #if DCHECK_IS_ON() | 91 #if DCHECK_IS_ON() |
| 92 // This raw pointer is safe because | 92 // This raw pointer is safe because |
| 93 // - s_range has a valid pointer only if RangeUpdateScope instance is live. | 93 // - s_rawRange has a valid pointer only if RangeUpdateScope instance is |
| 94 // live. | |
| 94 // - RangeUpdateScope is used only in Range member functions. | 95 // - RangeUpdateScope is used only in Range member functions. |
| 95 static Range* s_range; | 96 static Range* s_rawRange; |
|
dcheng
2017/03/30 18:46:31
Hmm... I'd call this s_currentRange.
nasko
2017/03/30 22:59:20
Done.
| |
| 96 #endif | 97 #endif |
| 97 Member<Range> m_range; | 98 Member<Range> m_range; |
| 98 Member<Document> m_oldDocument; | 99 Member<Document> m_oldDocument; |
| 99 | 100 |
| 100 DISALLOW_COPY_AND_ASSIGN(RangeUpdateScope); | 101 DISALLOW_COPY_AND_ASSIGN(RangeUpdateScope); |
| 101 }; | 102 }; |
| 102 | 103 |
| 103 int RangeUpdateScope::s_scopeCount = 0; | 104 int RangeUpdateScope::s_scopeCount = 0; |
| 104 #if DCHECK_IS_ON() | 105 #if DCHECK_IS_ON() |
| 105 Range* RangeUpdateScope::s_range; | 106 Range* RangeUpdateScope::s_rawRange; |
| 106 #endif | 107 #endif |
| 107 | 108 |
| 108 inline Range::Range(Document& ownerDocument) | 109 inline Range::Range(Document& ownerDocument) |
| 109 : m_ownerDocument(&ownerDocument), | 110 : m_ownerDocument(&ownerDocument), |
| 110 m_start(m_ownerDocument), | 111 m_start(m_ownerDocument), |
| 111 m_end(m_ownerDocument) { | 112 m_end(m_ownerDocument) { |
| 112 m_ownerDocument->attachRange(this); | 113 m_ownerDocument->attachRange(this); |
| 113 } | 114 } |
| 114 | 115 |
| 115 Range* Range::create(Document& ownerDocument) { | 116 Range* Range::create(Document& ownerDocument) { |
| (...skipping 1695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1811 .data() | 1812 .data() |
| 1812 << "start offset: " << range->startOffset() | 1813 << "start offset: " << range->startOffset() |
| 1813 << ", end offset: " << range->endOffset(); | 1814 << ", end offset: " << range->endOffset(); |
| 1814 } else { | 1815 } else { |
| 1815 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " | 1816 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " |
| 1816 "invalid."; | 1817 "invalid."; |
| 1817 } | 1818 } |
| 1818 } | 1819 } |
| 1819 | 1820 |
| 1820 #endif | 1821 #endif |
| OLD | NEW |