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 17 matching lines...) Expand all Loading... |
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/TextMatchMarker.h" | 33 #include "core/editing/markers/TextMatchMarker.h" |
34 #include "platform/wtf/StdLibExtras.h" | 34 #include "platform/wtf/StdLibExtras.h" |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 DocumentMarkerDetails::~DocumentMarkerDetails() {} | 38 DocumentMarker::~DocumentMarker() = default; |
39 | |
40 class DocumentMarkerDescription final : public DocumentMarkerDetails { | |
41 public: | |
42 static DocumentMarkerDescription* Create(const String&); | |
43 | |
44 const String& Description() const { return description_; } | |
45 bool IsDescription() const override { return true; } | |
46 | |
47 private: | |
48 explicit DocumentMarkerDescription(const String& description) | |
49 : description_(description) {} | |
50 | |
51 String description_; | |
52 }; | |
53 | |
54 DocumentMarkerDescription* DocumentMarkerDescription::Create( | |
55 const String& description) { | |
56 return new DocumentMarkerDescription(description); | |
57 } | |
58 | |
59 inline DocumentMarkerDescription* ToDocumentMarkerDescription( | |
60 DocumentMarkerDetails* details) { | |
61 if (details && details->IsDescription()) | |
62 return static_cast<DocumentMarkerDescription*>(details); | |
63 return 0; | |
64 } | |
65 | 39 |
66 DocumentMarker::DocumentMarker(MarkerType type, | 40 DocumentMarker::DocumentMarker(MarkerType type, |
67 unsigned start_offset, | 41 unsigned start_offset, |
68 unsigned end_offset) | 42 unsigned end_offset) |
69 : type_(type), start_offset_(start_offset), end_offset_(end_offset) { | 43 : type_(type), start_offset_(start_offset), end_offset_(end_offset) { |
70 DCHECK_LT(start_offset, end_offset); | 44 DCHECK_LT(start_offset_, end_offset_); |
71 } | 45 } |
72 | 46 |
73 DocumentMarker::DocumentMarker(MarkerType type, | |
74 unsigned start_offset, | |
75 unsigned end_offset, | |
76 const String& description) | |
77 : type_(type), | |
78 start_offset_(start_offset), | |
79 end_offset_(end_offset), | |
80 details_(description.IsEmpty() | |
81 ? nullptr | |
82 : DocumentMarkerDescription::Create(description)) {} | |
83 | |
84 Optional<DocumentMarker::MarkerOffsets> | 47 Optional<DocumentMarker::MarkerOffsets> |
85 DocumentMarker::ComputeOffsetsAfterShift(unsigned offset, | 48 DocumentMarker::ComputeOffsetsAfterShift(unsigned offset, |
86 unsigned old_length, | 49 unsigned old_length, |
87 unsigned new_length) const { | 50 unsigned new_length) const { |
88 MarkerOffsets result; | 51 MarkerOffsets result; |
89 result.start_offset = StartOffset(); | 52 result.start_offset = StartOffset(); |
90 result.end_offset = EndOffset(); | 53 result.end_offset = EndOffset(); |
91 | 54 |
92 // algorithm inspired by https://dom.spec.whatwg.org/#concept-cd-replace | 55 // algorithm inspired by https://dom.spec.whatwg.org/#concept-cd-replace |
93 // but with some changes | 56 // but with some changes |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 return WTF::nullopt; | 88 return WTF::nullopt; |
126 | 89 |
127 return result; | 90 return result; |
128 } | 91 } |
129 | 92 |
130 void DocumentMarker::ShiftOffsets(int delta) { | 93 void DocumentMarker::ShiftOffsets(int delta) { |
131 start_offset_ += delta; | 94 start_offset_ += delta; |
132 end_offset_ += delta; | 95 end_offset_ += delta; |
133 } | 96 } |
134 | 97 |
135 const String& DocumentMarker::Description() const { | |
136 if (DocumentMarkerDescription* details = | |
137 ToDocumentMarkerDescription(details_.Get())) | |
138 return details->Description(); | |
139 return g_empty_string; | |
140 } | |
141 | |
142 DEFINE_TRACE(DocumentMarker) { | |
143 visitor->Trace(details_); | |
144 } | |
145 | |
146 } // namespace blink | 98 } // namespace blink |
OLD | NEW |