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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 inline DocumentMarkerDescription* toDocumentMarkerDescription( | 58 inline DocumentMarkerDescription* toDocumentMarkerDescription( |
59 DocumentMarkerDetails* details) { | 59 DocumentMarkerDetails* details) { |
60 if (details && details->isDescription()) | 60 if (details && details->isDescription()) |
61 return static_cast<DocumentMarkerDescription*>(details); | 61 return static_cast<DocumentMarkerDescription*>(details); |
62 return 0; | 62 return 0; |
63 } | 63 } |
64 | 64 |
65 class DocumentMarkerTextMatch final : public DocumentMarkerDetails { | 65 class DocumentMarkerTextMatch final : public DocumentMarkerDetails { |
66 public: | 66 public: |
67 static DocumentMarkerTextMatch* create(bool); | 67 static DocumentMarkerTextMatch* create(DocumentMarker::MatchStatus); |
68 | 68 |
69 bool IsActiveMatch() const { return m_match; } | 69 bool IsActiveMatch() const { |
| 70 return m_matchStatus == DocumentMarker::MatchStatus::kActive; |
| 71 } |
70 | 72 |
71 bool isTextMatch() const override { return true; } | 73 bool isTextMatch() const override { return true; } |
72 | 74 |
73 private: | 75 private: |
74 explicit DocumentMarkerTextMatch(bool match) : m_match(match) {} | 76 explicit DocumentMarkerTextMatch(DocumentMarker::MatchStatus matchStatus) |
| 77 : m_matchStatus(matchStatus) {} |
75 | 78 |
76 bool m_match; | 79 DocumentMarker::MatchStatus m_matchStatus; |
77 }; | 80 }; |
78 | 81 |
79 DocumentMarkerTextMatch* DocumentMarkerTextMatch::create(bool match) { | 82 DocumentMarkerTextMatch* DocumentMarkerTextMatch::create( |
80 DEFINE_STATIC_LOCAL(DocumentMarkerTextMatch, trueInstance, | 83 DocumentMarker::MatchStatus matchStatus) { |
81 (new DocumentMarkerTextMatch(true))); | 84 DEFINE_STATIC_LOCAL( |
82 DEFINE_STATIC_LOCAL(DocumentMarkerTextMatch, falseInstance, | 85 DocumentMarkerTextMatch, activeInstance, |
83 (new DocumentMarkerTextMatch(false))); | 86 (new DocumentMarkerTextMatch(DocumentMarker::MatchStatus::kActive))); |
84 return match ? &trueInstance : &falseInstance; | 87 DEFINE_STATIC_LOCAL( |
| 88 DocumentMarkerTextMatch, inactiveInstance, |
| 89 (new DocumentMarkerTextMatch(DocumentMarker::MatchStatus::kInactive))); |
| 90 return matchStatus == DocumentMarker::MatchStatus::kActive |
| 91 ? &activeInstance |
| 92 : &inactiveInstance; |
85 } | 93 } |
86 | 94 |
87 inline DocumentMarkerTextMatch* toDocumentMarkerTextMatch( | 95 inline DocumentMarkerTextMatch* toDocumentMarkerTextMatch( |
88 DocumentMarkerDetails* details) { | 96 DocumentMarkerDetails* details) { |
89 if (details && details->isTextMatch()) | 97 if (details && details->isTextMatch()) |
90 return static_cast<DocumentMarkerTextMatch*>(details); | 98 return static_cast<DocumentMarkerTextMatch*>(details); |
91 return 0; | 99 return 0; |
92 } | 100 } |
93 | 101 |
94 class TextCompositionMarkerDetails final : public DocumentMarkerDetails { | 102 class TextCompositionMarkerDetails final : public DocumentMarkerDetails { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 const String& description) | 144 const String& description) |
137 : m_type(type), | 145 : m_type(type), |
138 m_startOffset(startOffset), | 146 m_startOffset(startOffset), |
139 m_endOffset(endOffset), | 147 m_endOffset(endOffset), |
140 m_details(description.isEmpty() | 148 m_details(description.isEmpty() |
141 ? nullptr | 149 ? nullptr |
142 : DocumentMarkerDescription::create(description)) {} | 150 : DocumentMarkerDescription::create(description)) {} |
143 | 151 |
144 DocumentMarker::DocumentMarker(unsigned startOffset, | 152 DocumentMarker::DocumentMarker(unsigned startOffset, |
145 unsigned endOffset, | 153 unsigned endOffset, |
146 bool activeMatch) | 154 DocumentMarker::MatchStatus matchStatus) |
147 : m_type(DocumentMarker::TextMatch), | 155 : m_type(DocumentMarker::TextMatch), |
148 m_startOffset(startOffset), | 156 m_startOffset(startOffset), |
149 m_endOffset(endOffset), | 157 m_endOffset(endOffset), |
150 m_details(DocumentMarkerTextMatch::create(activeMatch)) {} | 158 m_details(DocumentMarkerTextMatch::create(matchStatus)) {} |
151 | 159 |
152 DocumentMarker::DocumentMarker(unsigned startOffset, | 160 DocumentMarker::DocumentMarker(unsigned startOffset, |
153 unsigned endOffset, | 161 unsigned endOffset, |
154 Color underlineColor, | 162 Color underlineColor, |
155 bool thick, | 163 bool thick, |
156 Color backgroundColor) | 164 Color backgroundColor) |
157 : m_type(DocumentMarker::Composition), | 165 : m_type(DocumentMarker::Composition), |
158 m_startOffset(startOffset), | 166 m_startOffset(startOffset), |
159 m_endOffset(endOffset), | 167 m_endOffset(endOffset), |
160 m_details(TextCompositionMarkerDetails::create(underlineColor, | 168 m_details(TextCompositionMarkerDetails::create(underlineColor, |
161 thick, | 169 thick, |
162 backgroundColor)) {} | 170 backgroundColor)) {} |
163 | 171 |
164 DocumentMarker::DocumentMarker(const DocumentMarker& marker) | 172 DocumentMarker::DocumentMarker(const DocumentMarker& marker) |
165 : m_type(marker.type()), | 173 : m_type(marker.type()), |
166 m_startOffset(marker.startOffset()), | 174 m_startOffset(marker.startOffset()), |
167 m_endOffset(marker.endOffset()), | 175 m_endOffset(marker.endOffset()), |
168 m_details(marker.details()) {} | 176 m_details(marker.details()) {} |
169 | 177 |
170 void DocumentMarker::shiftOffsets(int delta) { | 178 void DocumentMarker::shiftOffsets(int delta) { |
171 m_startOffset += delta; | 179 m_startOffset += delta; |
172 m_endOffset += delta; | 180 m_endOffset += delta; |
173 } | 181 } |
174 | 182 |
175 void DocumentMarker::setIsActiveMatch(bool active) { | 183 void DocumentMarker::setIsActiveMatch(bool active) { |
176 m_details = DocumentMarkerTextMatch::create(active); | 184 m_details = DocumentMarkerTextMatch::create( |
| 185 active ? DocumentMarker::MatchStatus::kActive |
| 186 : DocumentMarker::MatchStatus::kInactive); |
177 } | 187 } |
178 | 188 |
179 const String& DocumentMarker::description() const { | 189 const String& DocumentMarker::description() const { |
180 if (DocumentMarkerDescription* details = | 190 if (DocumentMarkerDescription* details = |
181 toDocumentMarkerDescription(m_details.get())) | 191 toDocumentMarkerDescription(m_details.get())) |
182 return details->description(); | 192 return details->description(); |
183 return emptyString; | 193 return emptyString; |
184 } | 194 } |
185 | 195 |
186 bool DocumentMarker::IsActiveMatch() const { | 196 bool DocumentMarker::IsActiveMatch() const { |
(...skipping 22 matching lines...) Expand all Loading... |
209 toTextCompositionMarkerDetails(m_details.get())) | 219 toTextCompositionMarkerDetails(m_details.get())) |
210 return details->backgroundColor(); | 220 return details->backgroundColor(); |
211 return Color::transparent; | 221 return Color::transparent; |
212 } | 222 } |
213 | 223 |
214 DEFINE_TRACE(DocumentMarker) { | 224 DEFINE_TRACE(DocumentMarker) { |
215 visitor->trace(m_details); | 225 visitor->trace(m_details); |
216 } | 226 } |
217 | 227 |
218 } // namespace blink | 228 } // namespace blink |
OLD | NEW |