| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 return match ? &trueInstance : &falseInstance; | 83 return match ? &trueInstance : &falseInstance; |
| 84 } | 84 } |
| 85 | 85 |
| 86 inline DocumentMarkerTextMatch* toDocumentMarkerTextMatch( | 86 inline DocumentMarkerTextMatch* toDocumentMarkerTextMatch( |
| 87 DocumentMarkerDetails* details) { | 87 DocumentMarkerDetails* details) { |
| 88 if (details && details->isTextMatch()) | 88 if (details && details->isTextMatch()) |
| 89 return static_cast<DocumentMarkerTextMatch*>(details); | 89 return static_cast<DocumentMarkerTextMatch*>(details); |
| 90 return 0; | 90 return 0; |
| 91 } | 91 } |
| 92 | 92 |
| 93 class TextCompositionMarkerDetails final : public DocumentMarkerDetails { | 93 class TextCompositionMarkerDetails : public DocumentMarkerDetails { |
| 94 public: | 94 public: |
| 95 static TextCompositionMarkerDetails* create(Color underlineColor, | 95 static TextCompositionMarkerDetails* create(Color underlineColor, |
| 96 bool thick, | 96 bool thick, |
| 97 Color backgroundColor); | 97 Color backgroundColor); |
| 98 | |
| 99 bool isComposition() const override { return true; } | |
| 100 Color underlineColor() const { return m_underlineColor; } | |
| 101 bool thick() const { return m_thick; } | |
| 102 Color backgroundColor() const { return m_backgroundColor; } | |
| 103 | |
| 104 private: | |
| 105 TextCompositionMarkerDetails(Color underlineColor, | 98 TextCompositionMarkerDetails(Color underlineColor, |
| 106 bool thick, | 99 bool thick, |
| 107 Color backgroundColor) | 100 Color backgroundColor) |
| 108 : m_underlineColor(underlineColor), | 101 : m_underlineColor(underlineColor), |
| 109 m_backgroundColor(backgroundColor), | 102 m_backgroundColor(backgroundColor), |
| 110 m_thick(thick) {} | 103 m_thick(thick) {} |
| 111 | 104 |
| 105 bool isComposition() const override { return true; } |
| 106 Color underlineColor() const { return m_underlineColor; } |
| 107 bool thick() const { return m_thick; } |
| 108 Color backgroundColor() const { return m_backgroundColor; } |
| 109 |
| 110 private: |
| 112 Color m_underlineColor; | 111 Color m_underlineColor; |
| 113 Color m_backgroundColor; | 112 Color m_backgroundColor; |
| 114 bool m_thick; | 113 bool m_thick; |
| 115 }; | 114 }; |
| 116 | 115 |
| 117 TextCompositionMarkerDetails* TextCompositionMarkerDetails::create( | 116 TextCompositionMarkerDetails* TextCompositionMarkerDetails::create( |
| 118 Color underlineColor, | 117 Color underlineColor, |
| 119 bool thick, | 118 bool thick, |
| 120 Color backgroundColor) { | 119 Color backgroundColor) { |
| 121 return new TextCompositionMarkerDetails(underlineColor, thick, | 120 return new TextCompositionMarkerDetails(underlineColor, thick, |
| 122 backgroundColor); | 121 backgroundColor); |
| 123 } | 122 } |
| 124 | 123 |
| 125 inline TextCompositionMarkerDetails* toTextCompositionMarkerDetails( | 124 inline TextCompositionMarkerDetails* toTextCompositionMarkerDetails( |
| 126 DocumentMarkerDetails* details) { | 125 DocumentMarkerDetails* details) { |
| 127 if (details && details->isComposition()) | 126 if (details && details->isComposition()) |
| 128 return static_cast<TextCompositionMarkerDetails*>(details); | 127 return static_cast<TextCompositionMarkerDetails*>(details); |
| 129 return nullptr; | 128 return nullptr; |
| 130 } | 129 } |
| 131 | 130 |
| 131 class TextSuggestionMarkerDetails final : public TextCompositionMarkerDetails { |
| 132 public: |
| 133 static TextSuggestionMarkerDetails* create( |
| 134 Color underlineColor, |
| 135 bool thick, |
| 136 Color backgroundColor, |
| 137 const std::vector<std::string>& suggestions, |
| 138 int id); |
| 139 |
| 140 bool isSuggestion() const override { return true; } |
| 141 std::vector<std::string>& suggestions() { return m_suggestions; } |
| 142 int id() { return m_id; } |
| 143 |
| 144 private: |
| 145 TextSuggestionMarkerDetails(Color underlineColor, |
| 146 bool thick, |
| 147 Color backgroundColor, |
| 148 const std::vector<std::string>& suggestions, |
| 149 int id) |
| 150 : TextCompositionMarkerDetails(underlineColor, thick, backgroundColor), |
| 151 m_suggestions(suggestions), |
| 152 m_id(id) {} |
| 153 |
| 154 std::vector<std::string> m_suggestions; |
| 155 int m_id; |
| 156 }; |
| 157 |
| 158 TextSuggestionMarkerDetails* TextSuggestionMarkerDetails::create( |
| 159 Color underlineColor, |
| 160 bool thick, |
| 161 Color backgroundColor, |
| 162 const std::vector<std::string>& suggestions, |
| 163 int id) { |
| 164 return new TextSuggestionMarkerDetails(underlineColor, thick, backgroundColor, |
| 165 suggestions, id); |
| 166 } |
| 167 |
| 168 inline TextSuggestionMarkerDetails* toTextSuggestionMarkerDetails( |
| 169 DocumentMarkerDetails* details) { |
| 170 if (details && details->isSuggestion()) |
| 171 return static_cast<TextSuggestionMarkerDetails*>(details); |
| 172 return nullptr; |
| 173 } |
| 174 |
| 132 DocumentMarker::DocumentMarker(MarkerType type, | 175 DocumentMarker::DocumentMarker(MarkerType type, |
| 133 unsigned startOffset, | 176 unsigned startOffset, |
| 134 unsigned endOffset, | 177 unsigned endOffset, |
| 135 const String& description, | 178 const String& description, |
| 136 uint32_t hash) | 179 uint32_t hash) |
| 137 : m_type(type), | 180 : m_type(type), |
| 138 m_startOffset(startOffset), | 181 m_startOffset(startOffset), |
| 139 m_endOffset(endOffset), | 182 m_endOffset(endOffset), |
| 140 m_details(description.isEmpty() | 183 m_details(description.isEmpty() |
| 141 ? nullptr | 184 ? nullptr |
| 142 : DocumentMarkerDescription::create(description)), | 185 : DocumentMarkerDescription::create(description)), |
| 143 m_hash(hash) {} | 186 m_hash(hash) {} |
| 144 | 187 |
| 145 DocumentMarker::DocumentMarker(unsigned startOffset, | 188 DocumentMarker::DocumentMarker(unsigned startOffset, |
| 146 unsigned endOffset, | 189 unsigned endOffset, |
| 147 bool activeMatch) | 190 bool activeMatch) |
| 148 : m_type(DocumentMarker::TextMatch), | 191 : m_type(DocumentMarker::TextMatch), |
| 149 m_startOffset(startOffset), | 192 m_startOffset(startOffset), |
| 150 m_endOffset(endOffset), | 193 m_endOffset(endOffset), |
| 151 m_details(DocumentMarkerTextMatch::create(activeMatch)), | 194 m_details(DocumentMarkerTextMatch::create(activeMatch)), |
| 152 m_hash(0) {} | 195 m_hash(0) {} |
| 153 | 196 |
| 154 DocumentMarker::DocumentMarker(unsigned startOffset, | 197 DocumentMarker::DocumentMarker(MarkerType type, |
| 198 unsigned startOffset, |
| 155 unsigned endOffset, | 199 unsigned endOffset, |
| 156 Color underlineColor, | 200 Color underlineColor, |
| 157 bool thick, | 201 bool thick, |
| 158 Color backgroundColor) | 202 Color backgroundColor) |
| 159 : m_type(DocumentMarker::Composition), | 203 : m_type(type), |
| 160 m_startOffset(startOffset), | 204 m_startOffset(startOffset), |
| 161 m_endOffset(endOffset), | 205 m_endOffset(endOffset), |
| 162 m_details(TextCompositionMarkerDetails::create(underlineColor, | 206 m_details(TextCompositionMarkerDetails::create(underlineColor, |
| 163 thick, | 207 thick, |
| 164 backgroundColor)), | 208 backgroundColor)), |
| 165 m_hash(0) {} | 209 m_hash(0) {} |
| 166 | 210 |
| 211 DocumentMarker::DocumentMarker(unsigned startOffset, |
| 212 unsigned endOffset, |
| 213 Color underlineColor, |
| 214 bool thick, |
| 215 Color backgroundColor, |
| 216 const std::vector<std::string>& suggestions, |
| 217 int suggestionMarkerID) |
| 218 : m_startOffset(startOffset), m_endOffset(endOffset), m_hash(0) { |
| 219 if (suggestions.empty()) { |
| 220 m_type = DocumentMarker::Composition; |
| 221 m_details = TextCompositionMarkerDetails::create(underlineColor, thick, |
| 222 backgroundColor); |
| 223 } else { |
| 224 m_type = DocumentMarker::Suggestion; |
| 225 m_details = TextSuggestionMarkerDetails::create( |
| 226 underlineColor, thick, backgroundColor, suggestions, |
| 227 suggestionMarkerID); |
| 228 } |
| 229 } |
| 230 |
| 167 DocumentMarker::DocumentMarker(const DocumentMarker& marker) | 231 DocumentMarker::DocumentMarker(const DocumentMarker& marker) |
| 168 : m_type(marker.type()), | 232 : m_type(marker.type()), |
| 169 m_startOffset(marker.startOffset()), | 233 m_startOffset(marker.startOffset()), |
| 170 m_endOffset(marker.endOffset()), | 234 m_endOffset(marker.endOffset()), |
| 171 m_details(marker.details()), | 235 m_details(marker.details()), |
| 172 m_hash(marker.hash()) {} | 236 m_hash(marker.hash()) {} |
| 173 | 237 |
| 174 void DocumentMarker::shiftOffsets(int delta) { | 238 void DocumentMarker::shiftOffsets(int delta) { |
| 175 m_startOffset += delta; | 239 m_startOffset += delta; |
| 176 m_endOffset += delta; | 240 m_endOffset += delta; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 return false; | 272 return false; |
| 209 } | 273 } |
| 210 | 274 |
| 211 Color DocumentMarker::backgroundColor() const { | 275 Color DocumentMarker::backgroundColor() const { |
| 212 if (TextCompositionMarkerDetails* details = | 276 if (TextCompositionMarkerDetails* details = |
| 213 toTextCompositionMarkerDetails(m_details.get())) | 277 toTextCompositionMarkerDetails(m_details.get())) |
| 214 return details->backgroundColor(); | 278 return details->backgroundColor(); |
| 215 return Color::transparent; | 279 return Color::transparent; |
| 216 } | 280 } |
| 217 | 281 |
| 282 const std::vector<std::string> DocumentMarker::suggestions() const { |
| 283 if (TextSuggestionMarkerDetails* details = |
| 284 toTextSuggestionMarkerDetails(m_details.get())) |
| 285 return details->suggestions(); |
| 286 return std::vector<std::string>(); |
| 287 } |
| 288 |
| 289 int DocumentMarker::suggestionMarkerID() const { |
| 290 if (TextSuggestionMarkerDetails* details = |
| 291 toTextSuggestionMarkerDetails(m_details.get())) |
| 292 return details->id(); |
| 293 return -1; |
| 294 } |
| 295 |
| 296 void DocumentMarker::replaceSuggestion(int index, |
| 297 const std::string& newSuggestion) { |
| 298 if (TextSuggestionMarkerDetails* details = |
| 299 toTextSuggestionMarkerDetails(m_details.get())) |
| 300 details->suggestions()[index] = newSuggestion; |
| 301 } |
| 302 |
| 218 DEFINE_TRACE(DocumentMarker) { | 303 DEFINE_TRACE(DocumentMarker) { |
| 219 visitor->trace(m_details); | 304 visitor->trace(m_details); |
| 220 } | 305 } |
| 221 | 306 |
| 222 } // namespace blink | 307 } // namespace blink |
| OLD | NEW |