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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 return new DocumentMarkerDescription(description); | 56 return new DocumentMarkerDescription(description); |
57 } | 57 } |
58 | 58 |
59 inline DocumentMarkerDescription* ToDocumentMarkerDescription( | 59 inline DocumentMarkerDescription* ToDocumentMarkerDescription( |
60 DocumentMarkerDetails* details) { | 60 DocumentMarkerDetails* details) { |
61 if (details && details->IsDescription()) | 61 if (details && details->IsDescription()) |
62 return static_cast<DocumentMarkerDescription*>(details); | 62 return static_cast<DocumentMarkerDescription*>(details); |
63 return 0; | 63 return 0; |
64 } | 64 } |
65 | 65 |
66 class TextCompositionMarkerDetails final : public DocumentMarkerDetails { | |
67 public: | |
68 static TextCompositionMarkerDetails* Create(Color underline_color, | |
69 bool thick, | |
70 Color background_color); | |
71 | |
72 bool IsComposition() const override { return true; } | |
73 Color UnderlineColor() const { return underline_color_; } | |
74 bool Thick() const { return thick_; } | |
75 Color BackgroundColor() const { return background_color_; } | |
76 | |
77 private: | |
78 TextCompositionMarkerDetails(Color underline_color, | |
79 bool thick, | |
80 Color background_color) | |
81 : underline_color_(underline_color), | |
82 background_color_(background_color), | |
83 thick_(thick) {} | |
84 | |
85 Color underline_color_; | |
86 Color background_color_; | |
87 bool thick_; | |
88 }; | |
89 | |
90 TextCompositionMarkerDetails* TextCompositionMarkerDetails::Create( | |
91 Color underline_color, | |
92 bool thick, | |
93 Color background_color) { | |
94 return new TextCompositionMarkerDetails(underline_color, thick, | |
95 background_color); | |
96 } | |
97 | |
98 inline TextCompositionMarkerDetails* ToTextCompositionMarkerDetails( | |
99 DocumentMarkerDetails* details) { | |
100 if (details && details->IsComposition()) | |
101 return static_cast<TextCompositionMarkerDetails*>(details); | |
102 return nullptr; | |
103 } | |
104 | |
105 DocumentMarker::DocumentMarker(MarkerType type, | 66 DocumentMarker::DocumentMarker(MarkerType type, |
106 unsigned start_offset, | 67 unsigned start_offset, |
107 unsigned end_offset) | 68 unsigned end_offset) |
108 : type_(type), start_offset_(start_offset), end_offset_(end_offset) { | 69 : type_(type), start_offset_(start_offset), end_offset_(end_offset) { |
109 DCHECK_LT(start_offset, end_offset); | 70 DCHECK_LT(start_offset, end_offset); |
110 } | 71 } |
111 | 72 |
112 DocumentMarker::DocumentMarker(MarkerType type, | 73 DocumentMarker::DocumentMarker(MarkerType type, |
113 unsigned start_offset, | 74 unsigned start_offset, |
114 unsigned end_offset, | 75 unsigned end_offset, |
115 const String& description) | 76 const String& description) |
116 : type_(type), | 77 : type_(type), |
117 start_offset_(start_offset), | 78 start_offset_(start_offset), |
118 end_offset_(end_offset), | 79 end_offset_(end_offset), |
119 details_(description.IsEmpty() | 80 details_(description.IsEmpty() |
120 ? nullptr | 81 ? nullptr |
121 : DocumentMarkerDescription::Create(description)) {} | 82 : DocumentMarkerDescription::Create(description)) {} |
122 | 83 |
123 DocumentMarker::DocumentMarker(unsigned start_offset, | |
124 unsigned end_offset, | |
125 Color underline_color, | |
126 bool thick, | |
127 Color background_color) | |
128 : type_(DocumentMarker::kComposition), | |
129 start_offset_(start_offset), | |
130 end_offset_(end_offset), | |
131 details_(TextCompositionMarkerDetails::Create(underline_color, | |
132 thick, | |
133 background_color)) {} | |
134 | |
135 Optional<DocumentMarker::MarkerOffsets> | 84 Optional<DocumentMarker::MarkerOffsets> |
136 DocumentMarker::ComputeOffsetsAfterShift(unsigned offset, | 85 DocumentMarker::ComputeOffsetsAfterShift(unsigned offset, |
137 unsigned old_length, | 86 unsigned old_length, |
138 unsigned new_length) const { | 87 unsigned new_length) const { |
139 MarkerOffsets result; | 88 MarkerOffsets result; |
140 result.start_offset = StartOffset(); | 89 result.start_offset = StartOffset(); |
141 result.end_offset = EndOffset(); | 90 result.end_offset = EndOffset(); |
142 | 91 |
143 // algorithm inspired by https://dom.spec.whatwg.org/#concept-cd-replace | 92 // algorithm inspired by https://dom.spec.whatwg.org/#concept-cd-replace |
144 // but with some changes | 93 // but with some changes |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 end_offset_ += delta; | 132 end_offset_ += delta; |
184 } | 133 } |
185 | 134 |
186 const String& DocumentMarker::Description() const { | 135 const String& DocumentMarker::Description() const { |
187 if (DocumentMarkerDescription* details = | 136 if (DocumentMarkerDescription* details = |
188 ToDocumentMarkerDescription(details_.Get())) | 137 ToDocumentMarkerDescription(details_.Get())) |
189 return details->Description(); | 138 return details->Description(); |
190 return g_empty_string; | 139 return g_empty_string; |
191 } | 140 } |
192 | 141 |
193 Color DocumentMarker::UnderlineColor() const { | |
194 if (TextCompositionMarkerDetails* details = | |
195 ToTextCompositionMarkerDetails(details_.Get())) | |
196 return details->UnderlineColor(); | |
197 return Color::kTransparent; | |
198 } | |
199 | |
200 bool DocumentMarker::Thick() const { | |
201 if (TextCompositionMarkerDetails* details = | |
202 ToTextCompositionMarkerDetails(details_.Get())) | |
203 return details->Thick(); | |
204 return false; | |
205 } | |
206 | |
207 Color DocumentMarker::BackgroundColor() const { | |
208 if (TextCompositionMarkerDetails* details = | |
209 ToTextCompositionMarkerDetails(details_.Get())) | |
210 return details->BackgroundColor(); | |
211 return Color::kTransparent; | |
212 } | |
213 | |
214 DEFINE_TRACE(DocumentMarker) { | 142 DEFINE_TRACE(DocumentMarker) { |
215 visitor->Trace(details_); | 143 visitor->Trace(details_); |
216 } | 144 } |
217 | 145 |
218 } // namespace blink | 146 } // namespace blink |
OLD | NEW |