| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 if (!startRangeFound) | 152 if (!startRangeFound) |
| 153 return nullptr; | 153 return nullptr; |
| 154 | 154 |
| 155 if (length() && end() > docTextPosition) { // end() is out of bounds | 155 if (length() && end() > docTextPosition) { // end() is out of bounds |
| 156 resultRange->setEnd(textRunRange->endContainer(), textRunRange->endOffse
t(), IGNORE_EXCEPTION); | 156 resultRange->setEnd(textRunRange->endContainer(), textRunRange->endOffse
t(), IGNORE_EXCEPTION); |
| 157 } | 157 } |
| 158 | 158 |
| 159 return resultRange.release(); | 159 return resultRange.release(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 PlainTextRange PlainTextRange::create(const Node& scope, const Range& range) | 162 PlainTextRange PlainTextRange::create(const ContainerNode& scope, const Range& r
ange) |
| 163 { | 163 { |
| 164 if (!range.startContainer()) | 164 if (!range.startContainer()) |
| 165 return PlainTextRange(); | 165 return PlainTextRange(); |
| 166 | 166 |
| 167 // The critical assumption is that this only gets called with ranges that | 167 // The critical assumption is that this only gets called with ranges that |
| 168 // concentrate on a given area containing the selection root. This is done | 168 // concentrate on a given area containing the selection root. This is done |
| 169 // because of text fields and textareas. The DOM for those is not | 169 // because of text fields and textareas. The DOM for those is not |
| 170 // directly in the document DOM, so ensure that the range does not cross a | 170 // directly in the document DOM, so ensure that the range does not cross a |
| 171 // boundary of one of those. | 171 // boundary of one of those. |
| 172 if (range.startContainer() != &scope && !range.startContainer()->isDescendan
tOf(&scope)) | 172 if (range.startContainer() != &scope && !range.startContainer()->isDescendan
tOf(&scope)) |
| 173 return PlainTextRange(); | 173 return PlainTextRange(); |
| 174 if (range.endContainer() != scope && !range.endContainer()->isDescendantOf(&
scope)) | 174 if (range.endContainer() != scope && !range.endContainer()->isDescendantOf(&
scope)) |
| 175 return PlainTextRange(); | 175 return PlainTextRange(); |
| 176 | 176 |
| 177 RefPtrWillBeRawPtr<Range> testRange = Range::create(scope.document(), const_
cast<Node*>(&scope), 0, range.startContainer(), range.startOffset()); | 177 RefPtrWillBeRawPtr<Range> testRange = Range::create(scope.document(), const_
cast<ContainerNode*>(&scope), 0, range.startContainer(), range.startOffset()); |
| 178 ASSERT(testRange->startContainer() == &scope); | 178 ASSERT(testRange->startContainer() == &scope); |
| 179 size_t start = TextIterator::rangeLength(testRange.get()); | 179 size_t start = TextIterator::rangeLength(testRange.get()); |
| 180 | 180 |
| 181 testRange->setEnd(range.endContainer(), range.endOffset(), IGNORE_EXCEPTION)
; | 181 testRange->setEnd(range.endContainer(), range.endOffset(), IGNORE_EXCEPTION)
; |
| 182 ASSERT(testRange->startContainer() == &scope); | 182 ASSERT(testRange->startContainer() == &scope); |
| 183 size_t end = TextIterator::rangeLength(testRange.get()); | 183 size_t end = TextIterator::rangeLength(testRange.get()); |
| 184 | 184 |
| 185 return PlainTextRange(start, end); | 185 return PlainTextRange(start, end); |
| 186 } | 186 } |
| 187 | 187 |
| 188 } | 188 } |
| OLD | NEW |