Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. |
| 3 * Copyright (C) 2005 Alexey Proskuryakov. | 3 * Copyright (C) 2005 Alexey Proskuryakov. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 EphemeralRange PlainTextRange::createRangeForSelection(const ContainerNode& scop e) const | 66 EphemeralRange PlainTextRange::createRangeForSelection(const ContainerNode& scop e) const |
| 67 { | 67 { |
| 68 return createRangeFor(scope, ForSelection); | 68 return createRangeFor(scope, ForSelection); |
| 69 } | 69 } |
| 70 | 70 |
| 71 EphemeralRange PlainTextRange::createRangeFor(const ContainerNode& scope, GetRan geFor getRangeFor) const | 71 EphemeralRange PlainTextRange::createRangeFor(const ContainerNode& scope, GetRan geFor getRangeFor) const |
| 72 { | 72 { |
| 73 ASSERT(isNotNull()); | 73 ASSERT(isNotNull()); |
| 74 | 74 |
| 75 size_t docTextPosition = 0; | 75 size_t docTextPosition = 0; |
| 76 bool startRangeFound = false; | 76 bool startOutOfBound = true; |
| 77 | 77 |
| 78 Position textRunStartPosition; | 78 Position textRunStartPosition; |
| 79 Position textRunEndPosition; | 79 Position textRunEndPosition; |
| 80 | 80 |
| 81 TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacement Character; | 81 TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacement Character; |
| 82 if (getRangeFor == ForSelection) | 82 if (getRangeFor == ForSelection) |
| 83 behaviorFlags |= TextIteratorEmitsCharactersBetweenAllVisiblePositions; | 83 behaviorFlags |= TextIteratorEmitsCharactersBetweenAllVisiblePositions; |
| 84 auto range = EphemeralRange::rangeOfContents(scope); | 84 auto range = EphemeralRange::rangeOfContents(scope); |
| 85 TextIterator it(range.startPosition(), range.endPosition(), behaviorFlags); | 85 TextIterator it(range.startPosition(), range.endPosition(), behaviorFlags); |
| 86 | 86 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 112 if (!it.atEnd()) { | 112 if (!it.atEnd()) { |
| 113 textRunEndPosition = it.startPositionInCurrentContainer(); | 113 textRunEndPosition = it.startPositionInCurrentContainer(); |
| 114 } else { | 114 } else { |
| 115 Position runEnd = nextPositionOf(createVisiblePosition(textR unStartPosition)).deepEquivalent(); | 115 Position runEnd = nextPositionOf(createVisiblePosition(textR unStartPosition)).deepEquivalent(); |
| 116 if (runEnd.isNotNull()) | 116 if (runEnd.isNotNull()) |
| 117 textRunEndPosition = runEnd; | 117 textRunEndPosition = runEnd; |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 if (foundStart) { | 122 // resultStart should be assigned the first time foundStart is true. |
|
Changwan Ryu
2016/04/07 11:46:19
I don't feel that this comment is needed here.
| |
| 123 startRangeFound = true; | 123 if (foundStart && startOutOfBound) { |
|
Changwan Ryu
2016/04/07 11:46:19
no need to check startOutOfBound?
yabinh
2016/04/08 01:21:30
In "foundStart = start() >= docTextPosition && sta
yabinh
2016/04/11 05:53:25
I was wrong about it. I thought the selected range
| |
| 124 startOutOfBound = false; | |
| 124 if (textRunStartPosition.computeContainerNode()->isTextNode()) { | 125 if (textRunStartPosition.computeContainerNode()->isTextNode()) { |
| 125 int offset = start() - docTextPosition; | 126 int offset = start() - docTextPosition; |
| 126 resultStart = Position(textRunStartPosition.computeContainerNode (), offset + textRunStartPosition.offsetInContainerNode()); | 127 resultStart = Position(textRunStartPosition.computeContainerNode (), offset + textRunStartPosition.offsetInContainerNode()); |
| 127 } else { | 128 } else { |
| 128 if (start() == docTextPosition) | 129 if (start() == docTextPosition) |
| 129 resultStart = textRunStartPosition; | 130 resultStart = textRunStartPosition; |
| 130 else | 131 else |
| 131 resultStart = textRunEndPosition; | 132 resultStart = textRunEndPosition; |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 | 135 |
| 135 if (foundEnd) { | 136 if (foundEnd) { |
| 136 if (textRunStartPosition.computeContainerNode()->isTextNode()) { | 137 if (textRunStartPosition.computeContainerNode()->isTextNode()) { |
| 137 int offset = end() - docTextPosition; | 138 int offset = end() - docTextPosition; |
| 138 resultEnd = Position(textRunStartPosition.computeContainerNode() , offset + textRunStartPosition.offsetInContainerNode()); | 139 resultEnd = Position(textRunStartPosition.computeContainerNode() , offset + textRunStartPosition.offsetInContainerNode()); |
| 139 } else { | 140 } else { |
| 140 if (end() == docTextPosition) | 141 if (end() == docTextPosition) |
| 141 resultEnd = textRunStartPosition; | 142 resultEnd = textRunStartPosition; |
| 142 else | 143 else |
| 143 resultEnd = textRunEndPosition; | 144 resultEnd = textRunEndPosition; |
| 144 } | 145 } |
| 145 docTextPosition += len; | 146 docTextPosition += len; |
| 146 break; | 147 break; |
| 147 } | 148 } |
| 148 docTextPosition += len; | 149 docTextPosition += len; |
| 149 } | 150 } |
| 150 | 151 |
| 151 if (!startRangeFound) | 152 if (startOutOfBound) { |
| 152 return EphemeralRange(); | 153 resultStart = textRunEndPosition; |
| 154 resultEnd = textRunEndPosition; | |
| 155 } | |
| 153 | 156 |
| 154 if (length() && end() > docTextPosition) { // end() is out of bounds | 157 if (length() && end() > docTextPosition) { // end() is out of bounds |
| 155 resultEnd = textRunEndPosition; | 158 resultEnd = textRunEndPosition; |
| 156 } | 159 } |
| 157 | 160 |
| 158 return EphemeralRange(resultStart.toOffsetInAnchor(), resultEnd.toOffsetInAn chor()); | 161 return EphemeralRange(resultStart.toOffsetInAnchor(), resultEnd.toOffsetInAn chor()); |
| 159 } | 162 } |
| 160 | 163 |
| 161 PlainTextRange PlainTextRange::create(const ContainerNode& scope, const Ephemera lRange& range) | 164 PlainTextRange PlainTextRange::create(const ContainerNode& scope, const Ephemera lRange& range) |
| 162 { | 165 { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 180 | 183 |
| 181 return PlainTextRange(start, end); | 184 return PlainTextRange(start, end); |
| 182 } | 185 } |
| 183 | 186 |
| 184 PlainTextRange PlainTextRange::create(const ContainerNode& scope, const Range& r ange) | 187 PlainTextRange PlainTextRange::create(const ContainerNode& scope, const Range& r ange) |
| 185 { | 188 { |
| 186 return create(scope, EphemeralRange(&range)); | 189 return create(scope, EphemeralRange(&range)); |
| 187 } | 190 } |
| 188 | 191 |
| 189 } // namespace blink | 192 } // namespace blink |
| OLD | NEW |