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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 return match ? trueInstance : falseInstance; | 89 return match ? trueInstance : falseInstance; |
90 } | 90 } |
91 | 91 |
92 inline DocumentMarkerTextMatch* toDocumentMarkerTextMatch(DocumentMarkerDetails* details) | 92 inline DocumentMarkerTextMatch* toDocumentMarkerTextMatch(DocumentMarkerDetails* details) |
93 { | 93 { |
94 if (details && details->isTextMatch()) | 94 if (details && details->isTextMatch()) |
95 return static_cast<DocumentMarkerTextMatch*>(details); | 95 return static_cast<DocumentMarkerTextMatch*>(details); |
96 return 0; | 96 return 0; |
97 } | 97 } |
98 | 98 |
99 class TextCompositionMarkerDetails final : public DocumentMarkerDetails { | |
100 public: | |
101 static PassRefPtrWillBeRawPtr<TextCompositionMarkerDetails> instanceFor(Colo r underlineColor, bool thick, Color backgroundColor); | |
yosin_UTC9
2015/09/08 06:34:05
nit: Could you use |create()| instead of |instance
| |
102 | |
103 bool isComposition() const override { return true; } | |
104 Color underlineColor() const { return m_underlineColor; } | |
105 bool thick() const { return m_thick; } | |
106 Color backgroundColor() const { return m_backgroundColor; } | |
107 | |
108 private: | |
109 TextCompositionMarkerDetails(Color underlineColor, bool thick, Color backgro undColor) | |
110 : m_underlineColor(underlineColor) | |
111 , m_thick(thick) | |
112 , m_backgroundColor(backgroundColor) | |
113 { | |
114 } | |
115 | |
116 Color m_underlineColor; | |
117 bool m_thick; | |
yosin_UTC9
2015/09/08 06:34:05
nit: Rather than having alignment padding in middl
| |
118 Color m_backgroundColor; | |
119 }; | |
120 | |
121 PassRefPtrWillBeRawPtr<TextCompositionMarkerDetails> TextCompositionMarkerDetail s::instanceFor(Color underlineColor, bool thick, Color backgroundColor) | |
122 { | |
123 return adoptRefWillBeNoop(new TextCompositionMarkerDetails(underlineColor, t hick, backgroundColor)); | |
124 } | |
125 | |
126 inline TextCompositionMarkerDetails* toTextCompositionMarkerDetails(DocumentMark erDetails* details) | |
127 { | |
128 if (details && details->isComposition()) | |
129 return static_cast<TextCompositionMarkerDetails*>(details); | |
130 return nullptr; | |
131 } | |
132 | |
133 | |
99 DocumentMarker::DocumentMarker(MarkerType type, unsigned startOffset, unsigned e ndOffset, const String& description, uint32_t hash) | 134 DocumentMarker::DocumentMarker(MarkerType type, unsigned startOffset, unsigned e ndOffset, const String& description, uint32_t hash) |
100 : m_type(type) | 135 : m_type(type) |
101 , m_startOffset(startOffset) | 136 , m_startOffset(startOffset) |
102 , m_endOffset(endOffset) | 137 , m_endOffset(endOffset) |
103 , m_details(description.isEmpty() ? nullptr : DocumentMarkerDescription::cre ate(description)) | 138 , m_details(description.isEmpty() ? nullptr : DocumentMarkerDescription::cre ate(description)) |
104 , m_hash(hash) | 139 , m_hash(hash) |
105 { | 140 { |
106 } | 141 } |
107 | 142 |
108 DocumentMarker::DocumentMarker(unsigned startOffset, unsigned endOffset, bool ac tiveMatch) | 143 DocumentMarker::DocumentMarker(unsigned startOffset, unsigned endOffset, bool ac tiveMatch) |
109 : m_type(DocumentMarker::TextMatch) | 144 : m_type(DocumentMarker::TextMatch) |
110 , m_startOffset(startOffset) | 145 , m_startOffset(startOffset) |
111 , m_endOffset(endOffset) | 146 , m_endOffset(endOffset) |
112 , m_details(DocumentMarkerTextMatch::instanceFor(activeMatch)) | 147 , m_details(DocumentMarkerTextMatch::instanceFor(activeMatch)) |
113 , m_hash(0) | 148 , m_hash(0) |
114 { | 149 { |
115 } | 150 } |
116 | 151 |
152 DocumentMarker::DocumentMarker(unsigned startOffset, unsigned endOffset, Color u nderlineColor, bool thick, Color backgroundColor) | |
153 : m_type(DocumentMarker::Composition) | |
154 , m_startOffset(startOffset) | |
155 , m_endOffset(endOffset) | |
156 , m_details(TextCompositionMarkerDetails::instanceFor(underlineColor, thick, backgroundColor)) | |
157 , m_hash(0) | |
158 { | |
159 } | |
160 | |
117 DocumentMarker::DocumentMarker(const DocumentMarker& marker) | 161 DocumentMarker::DocumentMarker(const DocumentMarker& marker) |
118 : m_type(marker.type()) | 162 : m_type(marker.type()) |
119 , m_startOffset(marker.startOffset()) | 163 , m_startOffset(marker.startOffset()) |
120 , m_endOffset(marker.endOffset()) | 164 , m_endOffset(marker.endOffset()) |
121 , m_details(marker.details()) | 165 , m_details(marker.details()) |
122 , m_hash(marker.hash()) | 166 , m_hash(marker.hash()) |
123 { | 167 { |
124 } | 168 } |
125 | 169 |
126 void DocumentMarker::shiftOffsets(int delta) | 170 void DocumentMarker::shiftOffsets(int delta) |
(...skipping 14 matching lines...) Expand all Loading... | |
141 return emptyString(); | 185 return emptyString(); |
142 } | 186 } |
143 | 187 |
144 bool DocumentMarker::activeMatch() const | 188 bool DocumentMarker::activeMatch() const |
145 { | 189 { |
146 if (DocumentMarkerTextMatch* details = toDocumentMarkerTextMatch(m_details.g et())) | 190 if (DocumentMarkerTextMatch* details = toDocumentMarkerTextMatch(m_details.g et())) |
147 return details->activeMatch(); | 191 return details->activeMatch(); |
148 return false; | 192 return false; |
149 } | 193 } |
150 | 194 |
195 Color DocumentMarker::underlineColor() const | |
196 { | |
197 if (TextCompositionMarkerDetails* details = toTextCompositionMarkerDetails(m _details.get())) | |
198 return details->underlineColor(); | |
199 return Color::transparent; | |
200 } | |
201 | |
202 bool DocumentMarker::thick() const | |
203 { | |
204 if (TextCompositionMarkerDetails* details = toTextCompositionMarkerDetails(m _details.get())) | |
205 return details->thick(); | |
206 return false; | |
207 } | |
208 | |
209 Color DocumentMarker::backgroundColor() const | |
210 { | |
211 if (TextCompositionMarkerDetails* details = toTextCompositionMarkerDetails(m _details.get())) | |
212 return details->backgroundColor(); | |
213 return Color::transparent; | |
214 } | |
215 | |
151 DEFINE_TRACE(DocumentMarker) | 216 DEFINE_TRACE(DocumentMarker) |
152 { | 217 { |
153 visitor->trace(m_details); | 218 visitor->trace(m_details); |
154 } | 219 } |
155 | 220 |
156 } // namespace blink | 221 } // namespace blink |
OLD | NEW |