Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/editing/markers/DocumentMarker.h" | 31 #include "core/editing/markers/DocumentMarker.h" |
| 32 | 32 |
| 33 #include "core/editing/markers/RenderedTextMatchMarker.h" | |
|
Xiaocheng
2017/03/21 03:59:44
This seems redundant.
| |
| 33 #include "wtf/StdLibExtras.h" | 34 #include "wtf/StdLibExtras.h" |
| 34 | 35 |
| 35 namespace blink { | 36 namespace blink { |
| 36 | 37 |
| 37 DocumentMarkerDetails::~DocumentMarkerDetails() {} | 38 DocumentMarkerDetails::~DocumentMarkerDetails() {} |
| 38 | 39 |
| 39 class DocumentMarkerDescription final : public DocumentMarkerDetails { | 40 class DocumentMarkerDescription final : public DocumentMarkerDetails { |
| 40 public: | 41 public: |
| 41 static DocumentMarkerDescription* create(const String&); | 42 static DocumentMarkerDescription* create(const String&); |
| 42 | 43 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 m_details(TextCompositionMarkerDetails::create(underlineColor, | 160 m_details(TextCompositionMarkerDetails::create(underlineColor, |
| 160 thick, | 161 thick, |
| 161 backgroundColor)) {} | 162 backgroundColor)) {} |
| 162 | 163 |
| 163 DocumentMarker::DocumentMarker(const DocumentMarker& marker) | 164 DocumentMarker::DocumentMarker(const DocumentMarker& marker) |
| 164 : m_type(marker.type()), | 165 : m_type(marker.type()), |
| 165 m_startOffset(marker.startOffset()), | 166 m_startOffset(marker.startOffset()), |
| 166 m_endOffset(marker.endOffset()), | 167 m_endOffset(marker.endOffset()), |
| 167 m_details(marker.details()) {} | 168 m_details(marker.details()) {} |
| 168 | 169 |
| 170 DocumentMarker::ShiftMarkerResult DocumentMarker::getShiftedMarkerPosition( | |
| 171 unsigned offset, | |
| 172 unsigned oldLength, | |
| 173 unsigned newLength) { | |
| 174 ShiftMarkerResult result; | |
| 175 result.newStartOffset = startOffset(); | |
| 176 result.newEndOffset = endOffset(); | |
| 177 result.shouldRemoveMarker = false; | |
| 178 | |
| 179 // algorithm inspired by https://dom.spec.whatwg.org/#concept-cd-replace | |
| 180 // but with some changes | |
| 181 if (startOffset() > offset) { | |
| 182 // Deviation from the concept-cd-replace algorithm: < instead of <= in | |
| 183 // the next line | |
| 184 if (startOffset() < offset + oldLength) { | |
| 185 // Marker start was in the replaced text. Move to end of new text | |
| 186 // (Deviation from the concept-cd-replace algorithm: that algorithm | |
| 187 // would move to the beginning of the new text here) | |
| 188 result.newStartOffset = offset + newLength; | |
| 189 } else { | |
| 190 // Marker start was after the replaced text. Shift by length | |
| 191 // difference | |
| 192 result.newStartOffset = startOffset() + newLength - oldLength; | |
| 193 } | |
| 194 } | |
| 195 | |
| 196 if (endOffset() > offset) { | |
| 197 // Deviation from the concept-cd-replace algorithm: < instead of <= in | |
| 198 // the next line | |
| 199 if (endOffset() < offset + oldLength) { | |
| 200 // Marker end was in the replaced text. Move to beginning of new text | |
| 201 result.newEndOffset = offset; | |
| 202 } else { | |
| 203 // Marker end was after the replaced text. Shift by length difference | |
| 204 result.newEndOffset = endOffset() + newLength - oldLength; | |
| 205 } | |
| 206 } | |
| 207 | |
| 208 if (result.newStartOffset >= result.newEndOffset) | |
| 209 result.shouldRemoveMarker = true; | |
| 210 | |
| 211 return result; | |
| 212 } | |
| 213 | |
| 169 void DocumentMarker::shiftOffsets(int delta) { | 214 void DocumentMarker::shiftOffsets(int delta) { |
| 170 m_startOffset += delta; | 215 m_startOffset += delta; |
| 171 m_endOffset += delta; | 216 m_endOffset += delta; |
| 172 } | 217 } |
| 173 | 218 |
| 219 bool DocumentMarker::isRenderedTextMatch() const { | |
| 220 return false; | |
| 221 } | |
| 222 | |
| 174 void DocumentMarker::setActiveMatch(bool active) { | 223 void DocumentMarker::setActiveMatch(bool active) { |
| 175 m_details = DocumentMarkerTextMatch::create(active); | 224 m_details = DocumentMarkerTextMatch::create(active); |
| 176 } | 225 } |
| 177 | 226 |
| 178 const String& DocumentMarker::description() const { | 227 const String& DocumentMarker::description() const { |
| 179 if (DocumentMarkerDescription* details = | 228 if (DocumentMarkerDescription* details = |
| 180 toDocumentMarkerDescription(m_details.get())) | 229 toDocumentMarkerDescription(m_details.get())) |
| 181 return details->description(); | 230 return details->description(); |
| 182 return emptyString; | 231 return emptyString; |
| 183 } | 232 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 208 toTextCompositionMarkerDetails(m_details.get())) | 257 toTextCompositionMarkerDetails(m_details.get())) |
| 209 return details->backgroundColor(); | 258 return details->backgroundColor(); |
| 210 return Color::transparent; | 259 return Color::transparent; |
| 211 } | 260 } |
| 212 | 261 |
| 213 DEFINE_TRACE(DocumentMarker) { | 262 DEFINE_TRACE(DocumentMarker) { |
| 214 visitor->trace(m_details); | 263 visitor->trace(m_details); |
| 215 } | 264 } |
| 216 | 265 |
| 217 } // namespace blink | 266 } // namespace blink |
| OLD | NEW |