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/TextMatchMarker.h" |
33 #include "platform/wtf/StdLibExtras.h" | 34 #include "platform/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 12 matching lines...) Expand all Loading... |
55 return new DocumentMarkerDescription(description); | 56 return new DocumentMarkerDescription(description); |
56 } | 57 } |
57 | 58 |
58 inline DocumentMarkerDescription* ToDocumentMarkerDescription( | 59 inline DocumentMarkerDescription* ToDocumentMarkerDescription( |
59 DocumentMarkerDetails* details) { | 60 DocumentMarkerDetails* details) { |
60 if (details && details->IsDescription()) | 61 if (details && details->IsDescription()) |
61 return static_cast<DocumentMarkerDescription*>(details); | 62 return static_cast<DocumentMarkerDescription*>(details); |
62 return 0; | 63 return 0; |
63 } | 64 } |
64 | 65 |
65 class DocumentMarkerTextMatch final : public DocumentMarkerDetails { | |
66 public: | |
67 static DocumentMarkerTextMatch* Create(DocumentMarker::MatchStatus); | |
68 | |
69 bool IsActiveMatch() const { | |
70 return match_status_ == DocumentMarker::MatchStatus::kActive; | |
71 } | |
72 | |
73 bool IsTextMatch() const override { return true; } | |
74 | |
75 private: | |
76 explicit DocumentMarkerTextMatch(DocumentMarker::MatchStatus match_status) | |
77 : match_status_(match_status) {} | |
78 | |
79 DocumentMarker::MatchStatus match_status_; | |
80 }; | |
81 | |
82 DocumentMarkerTextMatch* DocumentMarkerTextMatch::Create( | |
83 DocumentMarker::MatchStatus match_status) { | |
84 DEFINE_STATIC_LOCAL( | |
85 DocumentMarkerTextMatch, active_instance, | |
86 (new DocumentMarkerTextMatch(DocumentMarker::MatchStatus::kActive))); | |
87 DEFINE_STATIC_LOCAL( | |
88 DocumentMarkerTextMatch, inactive_instance, | |
89 (new DocumentMarkerTextMatch(DocumentMarker::MatchStatus::kInactive))); | |
90 return match_status == DocumentMarker::MatchStatus::kActive | |
91 ? &active_instance | |
92 : &inactive_instance; | |
93 } | |
94 | |
95 inline DocumentMarkerTextMatch* ToDocumentMarkerTextMatch( | |
96 DocumentMarkerDetails* details) { | |
97 if (details && details->IsTextMatch()) | |
98 return static_cast<DocumentMarkerTextMatch*>(details); | |
99 return 0; | |
100 } | |
101 | |
102 class TextCompositionMarkerDetails final : public DocumentMarkerDetails { | 66 class TextCompositionMarkerDetails final : public DocumentMarkerDetails { |
103 public: | 67 public: |
104 static TextCompositionMarkerDetails* Create(Color underline_color, | 68 static TextCompositionMarkerDetails* Create(Color underline_color, |
105 bool thick, | 69 bool thick, |
106 Color background_color); | 70 Color background_color); |
107 | 71 |
108 bool IsComposition() const override { return true; } | 72 bool IsComposition() const override { return true; } |
109 Color UnderlineColor() const { return underline_color_; } | 73 Color UnderlineColor() const { return underline_color_; } |
110 bool Thick() const { return thick_; } | 74 bool Thick() const { return thick_; } |
111 Color BackgroundColor() const { return background_color_; } | 75 Color BackgroundColor() const { return background_color_; } |
(...skipping 21 matching lines...) Expand all Loading... |
133 | 97 |
134 inline TextCompositionMarkerDetails* ToTextCompositionMarkerDetails( | 98 inline TextCompositionMarkerDetails* ToTextCompositionMarkerDetails( |
135 DocumentMarkerDetails* details) { | 99 DocumentMarkerDetails* details) { |
136 if (details && details->IsComposition()) | 100 if (details && details->IsComposition()) |
137 return static_cast<TextCompositionMarkerDetails*>(details); | 101 return static_cast<TextCompositionMarkerDetails*>(details); |
138 return nullptr; | 102 return nullptr; |
139 } | 103 } |
140 | 104 |
141 DocumentMarker::DocumentMarker(MarkerType type, | 105 DocumentMarker::DocumentMarker(MarkerType type, |
142 unsigned start_offset, | 106 unsigned start_offset, |
| 107 unsigned end_offset) |
| 108 : type_(type), start_offset_(start_offset), end_offset_(end_offset) { |
| 109 DCHECK_LT(start_offset, end_offset); |
| 110 } |
| 111 |
| 112 DocumentMarker::DocumentMarker(MarkerType type, |
| 113 unsigned start_offset, |
143 unsigned end_offset, | 114 unsigned end_offset, |
144 const String& description) | 115 const String& description) |
145 : type_(type), | 116 : type_(type), |
146 start_offset_(start_offset), | 117 start_offset_(start_offset), |
147 end_offset_(end_offset), | 118 end_offset_(end_offset), |
148 details_(description.IsEmpty() | 119 details_(description.IsEmpty() |
149 ? nullptr | 120 ? nullptr |
150 : DocumentMarkerDescription::Create(description)) {} | 121 : DocumentMarkerDescription::Create(description)) {} |
151 | 122 |
152 DocumentMarker::DocumentMarker(unsigned start_offset, | 123 DocumentMarker::DocumentMarker(unsigned start_offset, |
153 unsigned end_offset, | 124 unsigned end_offset, |
154 DocumentMarker::MatchStatus match_status) | |
155 : type_(DocumentMarker::kTextMatch), | |
156 start_offset_(start_offset), | |
157 end_offset_(end_offset), | |
158 details_(DocumentMarkerTextMatch::Create(match_status)) {} | |
159 | |
160 DocumentMarker::DocumentMarker(unsigned start_offset, | |
161 unsigned end_offset, | |
162 Color underline_color, | 125 Color underline_color, |
163 bool thick, | 126 bool thick, |
164 Color background_color) | 127 Color background_color) |
165 : type_(DocumentMarker::kComposition), | 128 : type_(DocumentMarker::kComposition), |
166 start_offset_(start_offset), | 129 start_offset_(start_offset), |
167 end_offset_(end_offset), | 130 end_offset_(end_offset), |
168 details_(TextCompositionMarkerDetails::Create(underline_color, | 131 details_(TextCompositionMarkerDetails::Create(underline_color, |
169 thick, | 132 thick, |
170 background_color)) {} | 133 background_color)) {} |
171 | 134 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 if (result.start_offset >= result.end_offset) | 175 if (result.start_offset >= result.end_offset) |
213 return WTF::nullopt; | 176 return WTF::nullopt; |
214 | 177 |
215 return result; | 178 return result; |
216 } | 179 } |
217 | 180 |
218 void DocumentMarker::ShiftOffsets(int delta) { | 181 void DocumentMarker::ShiftOffsets(int delta) { |
219 start_offset_ += delta; | 182 start_offset_ += delta; |
220 end_offset_ += delta; | 183 end_offset_ += delta; |
221 } | 184 } |
222 | |
223 void DocumentMarker::SetIsActiveMatch(bool active) { | 185 void DocumentMarker::SetIsActiveMatch(bool active) { |
224 details_ = DocumentMarkerTextMatch::Create( | 186 if (GetType() != DocumentMarker::kTextMatch) |
225 active ? DocumentMarker::MatchStatus::kActive | 187 return; |
226 : DocumentMarker::MatchStatus::kInactive); | 188 ToTextMatchMarker(this)->SetIsActiveMatch(active); |
227 } | 189 } |
228 | 190 |
229 const String& DocumentMarker::Description() const { | 191 const String& DocumentMarker::Description() const { |
230 if (DocumentMarkerDescription* details = | 192 if (DocumentMarkerDescription* details = |
231 ToDocumentMarkerDescription(details_.Get())) | 193 ToDocumentMarkerDescription(details_.Get())) |
232 return details->Description(); | 194 return details->Description(); |
233 return g_empty_string; | 195 return g_empty_string; |
234 } | 196 } |
235 | 197 |
236 bool DocumentMarker::IsActiveMatch() const { | 198 bool DocumentMarker::IsActiveMatch() const { |
237 if (DocumentMarkerTextMatch* details = | 199 if (GetType() != DocumentMarker::kTextMatch) |
238 ToDocumentMarkerTextMatch(details_.Get())) | 200 return false; |
239 return details->IsActiveMatch(); | 201 return ToTextMatchMarker(this)->IsActiveMatch(); |
240 return false; | |
241 } | 202 } |
242 | 203 |
243 Color DocumentMarker::UnderlineColor() const { | 204 Color DocumentMarker::UnderlineColor() const { |
244 if (TextCompositionMarkerDetails* details = | 205 if (TextCompositionMarkerDetails* details = |
245 ToTextCompositionMarkerDetails(details_.Get())) | 206 ToTextCompositionMarkerDetails(details_.Get())) |
246 return details->UnderlineColor(); | 207 return details->UnderlineColor(); |
247 return Color::kTransparent; | 208 return Color::kTransparent; |
248 } | 209 } |
249 | 210 |
250 bool DocumentMarker::Thick() const { | 211 bool DocumentMarker::Thick() const { |
251 if (TextCompositionMarkerDetails* details = | 212 if (TextCompositionMarkerDetails* details = |
252 ToTextCompositionMarkerDetails(details_.Get())) | 213 ToTextCompositionMarkerDetails(details_.Get())) |
253 return details->Thick(); | 214 return details->Thick(); |
254 return false; | 215 return false; |
255 } | 216 } |
256 | 217 |
257 Color DocumentMarker::BackgroundColor() const { | 218 Color DocumentMarker::BackgroundColor() const { |
258 if (TextCompositionMarkerDetails* details = | 219 if (TextCompositionMarkerDetails* details = |
259 ToTextCompositionMarkerDetails(details_.Get())) | 220 ToTextCompositionMarkerDetails(details_.Get())) |
260 return details->BackgroundColor(); | 221 return details->BackgroundColor(); |
261 return Color::kTransparent; | 222 return Color::kTransparent; |
262 } | 223 } |
263 | 224 |
264 DEFINE_TRACE(DocumentMarker) { | 225 DEFINE_TRACE(DocumentMarker) { |
265 visitor->Trace(details_); | 226 visitor->Trace(details_); |
266 } | 227 } |
267 | 228 |
268 } // namespace blink | 229 } // namespace blink |
OLD | NEW |