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), | |
109 start_offset_(start_offset), | |
110 end_offset_(end_offset), | |
111 details_(nullptr) {} | |
112 | |
113 DocumentMarker::DocumentMarker(MarkerType type, | |
114 unsigned start_offset, | |
143 unsigned end_offset, | 115 unsigned end_offset, |
144 const String& description) | 116 const String& description) |
145 : type_(type), | 117 : type_(type), |
146 start_offset_(start_offset), | 118 start_offset_(start_offset), |
147 end_offset_(end_offset), | 119 end_offset_(end_offset), |
148 details_(description.IsEmpty() | 120 details_(description.IsEmpty() |
149 ? nullptr | 121 ? nullptr |
150 : DocumentMarkerDescription::Create(description)) {} | 122 : DocumentMarkerDescription::Create(description)) {} |
151 | 123 |
152 DocumentMarker::DocumentMarker(unsigned start_offset, | 124 DocumentMarker::DocumentMarker(unsigned start_offset, |
153 unsigned end_offset, | 125 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, | 126 Color underline_color, |
163 bool thick, | 127 bool thick, |
164 Color background_color) | 128 Color background_color) |
165 : type_(DocumentMarker::kComposition), | 129 : type_(DocumentMarker::kComposition), |
166 start_offset_(start_offset), | 130 start_offset_(start_offset), |
167 end_offset_(end_offset), | 131 end_offset_(end_offset), |
168 details_(TextCompositionMarkerDetails::Create(underline_color, | 132 details_(TextCompositionMarkerDetails::Create(underline_color, |
169 thick, | 133 thick, |
170 background_color)) {} | 134 background_color)) {} |
171 | 135 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 if (result.start_offset >= result.end_offset) | 182 if (result.start_offset >= result.end_offset) |
219 return WTF::nullopt; | 183 return WTF::nullopt; |
220 | 184 |
221 return result; | 185 return result; |
222 } | 186 } |
223 | 187 |
224 void DocumentMarker::ShiftOffsets(int delta) { | 188 void DocumentMarker::ShiftOffsets(int delta) { |
225 start_offset_ += delta; | 189 start_offset_ += delta; |
226 end_offset_ += delta; | 190 end_offset_ += delta; |
227 } | 191 } |
228 | |
229 void DocumentMarker::SetIsActiveMatch(bool active) { | 192 void DocumentMarker::SetIsActiveMatch(bool active) { |
230 details_ = DocumentMarkerTextMatch::Create( | 193 if (GetType() != DocumentMarker::kTextMatch) |
rlanday
2017/05/25 21:00:48
Note the behavioral change here: calling SetIsActi
Xiaocheng
2017/05/26 00:46:25
We should be fine here, since DM::SetIsActiveMatch
| |
231 active ? DocumentMarker::MatchStatus::kActive | 194 return; |
232 : DocumentMarker::MatchStatus::kInactive); | 195 ToTextMatchMarker(this)->SetIsActiveMatch(active); |
233 } | 196 } |
234 | 197 |
235 const String& DocumentMarker::Description() const { | 198 const String& DocumentMarker::Description() const { |
236 if (DocumentMarkerDescription* details = | 199 if (DocumentMarkerDescription* details = |
237 ToDocumentMarkerDescription(details_.Get())) | 200 ToDocumentMarkerDescription(details_.Get())) |
238 return details->Description(); | 201 return details->Description(); |
239 return g_empty_string; | 202 return g_empty_string; |
240 } | 203 } |
241 | 204 |
242 bool DocumentMarker::IsActiveMatch() const { | 205 bool DocumentMarker::IsActiveMatch() const { |
243 if (DocumentMarkerTextMatch* details = | 206 if (GetType() != DocumentMarker::kTextMatch) |
244 ToDocumentMarkerTextMatch(details_.Get())) | 207 return false; |
245 return details->IsActiveMatch(); | 208 return ToTextMatchMarker(this)->IsActiveMatch(); |
246 return false; | |
247 } | 209 } |
248 | 210 |
249 Color DocumentMarker::UnderlineColor() const { | 211 Color DocumentMarker::UnderlineColor() const { |
250 if (TextCompositionMarkerDetails* details = | 212 if (TextCompositionMarkerDetails* details = |
251 ToTextCompositionMarkerDetails(details_.Get())) | 213 ToTextCompositionMarkerDetails(details_.Get())) |
252 return details->UnderlineColor(); | 214 return details->UnderlineColor(); |
253 return Color::kTransparent; | 215 return Color::kTransparent; |
254 } | 216 } |
255 | 217 |
256 bool DocumentMarker::Thick() const { | 218 bool DocumentMarker::Thick() const { |
257 if (TextCompositionMarkerDetails* details = | 219 if (TextCompositionMarkerDetails* details = |
258 ToTextCompositionMarkerDetails(details_.Get())) | 220 ToTextCompositionMarkerDetails(details_.Get())) |
259 return details->Thick(); | 221 return details->Thick(); |
260 return false; | 222 return false; |
261 } | 223 } |
262 | 224 |
263 Color DocumentMarker::BackgroundColor() const { | 225 Color DocumentMarker::BackgroundColor() const { |
264 if (TextCompositionMarkerDetails* details = | 226 if (TextCompositionMarkerDetails* details = |
265 ToTextCompositionMarkerDetails(details_.Get())) | 227 ToTextCompositionMarkerDetails(details_.Get())) |
266 return details->BackgroundColor(); | 228 return details->BackgroundColor(); |
267 return Color::kTransparent; | 229 return Color::kTransparent; |
268 } | 230 } |
269 | 231 |
270 DEFINE_TRACE(DocumentMarker) { | 232 DEFINE_TRACE(DocumentMarker) { |
271 visitor->Trace(details_); | 233 visitor->Trace(details_); |
272 } | 234 } |
273 | 235 |
274 } // namespace blink | 236 } // namespace blink |
OLD | NEW |