Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Side by Side Diff: third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp

Issue 2904093002: [DMC #18] Eliminate DocumentMarkerTextMatch (subclass of DocumentMarkerDetails) (Closed)
Patch Set: Rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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),
yosin_UTC9 2017/05/29 05:05:33 Just in case, let's add DCHECK_LT(start_offset, e
rlanday 2017/05/30 21:28:11 This causes a test case failure in InputMethodCont
Xiaocheng 2017/05/30 21:31:36 TextIterator shouldn't create zero-length ranges.
Xiaocheng 2017/05/30 22:24:37 DMC should filter results from TextIterator so tha
110 end_offset_(end_offset),
111 details_(nullptr) {}
yosin_UTC9 2017/05/29 05:05:33 nit: s/details_(nullptr)// Since |details_| is |M
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 if (result.start_offset >= result.end_offset) 176 if (result.start_offset >= result.end_offset)
213 return WTF::nullopt; 177 return WTF::nullopt;
214 178
215 return result; 179 return result;
216 } 180 }
217 181
218 void DocumentMarker::ShiftOffsets(int delta) { 182 void DocumentMarker::ShiftOffsets(int delta) {
219 start_offset_ += delta; 183 start_offset_ += delta;
220 end_offset_ += delta; 184 end_offset_ += delta;
221 } 185 }
222
223 void DocumentMarker::SetIsActiveMatch(bool active) { 186 void DocumentMarker::SetIsActiveMatch(bool active) {
224 details_ = DocumentMarkerTextMatch::Create( 187 if (GetType() != DocumentMarker::kTextMatch)
225 active ? DocumentMarker::MatchStatus::kActive 188 return;
226 : DocumentMarker::MatchStatus::kInactive); 189 ToTextMatchMarker(this)->SetIsActiveMatch(active);
227 } 190 }
228 191
229 const String& DocumentMarker::Description() const { 192 const String& DocumentMarker::Description() const {
230 if (DocumentMarkerDescription* details = 193 if (DocumentMarkerDescription* details =
231 ToDocumentMarkerDescription(details_.Get())) 194 ToDocumentMarkerDescription(details_.Get()))
232 return details->Description(); 195 return details->Description();
233 return g_empty_string; 196 return g_empty_string;
234 } 197 }
235 198
236 bool DocumentMarker::IsActiveMatch() const { 199 bool DocumentMarker::IsActiveMatch() const {
237 if (DocumentMarkerTextMatch* details = 200 if (GetType() != DocumentMarker::kTextMatch)
238 ToDocumentMarkerTextMatch(details_.Get())) 201 return false;
239 return details->IsActiveMatch(); 202 return ToTextMatchMarker(this)->IsActiveMatch();
240 return false;
241 } 203 }
242 204
243 Color DocumentMarker::UnderlineColor() const { 205 Color DocumentMarker::UnderlineColor() const {
244 if (TextCompositionMarkerDetails* details = 206 if (TextCompositionMarkerDetails* details =
245 ToTextCompositionMarkerDetails(details_.Get())) 207 ToTextCompositionMarkerDetails(details_.Get()))
246 return details->UnderlineColor(); 208 return details->UnderlineColor();
247 return Color::kTransparent; 209 return Color::kTransparent;
248 } 210 }
249 211
250 bool DocumentMarker::Thick() const { 212 bool DocumentMarker::Thick() const {
251 if (TextCompositionMarkerDetails* details = 213 if (TextCompositionMarkerDetails* details =
252 ToTextCompositionMarkerDetails(details_.Get())) 214 ToTextCompositionMarkerDetails(details_.Get()))
253 return details->Thick(); 215 return details->Thick();
254 return false; 216 return false;
255 } 217 }
256 218
257 Color DocumentMarker::BackgroundColor() const { 219 Color DocumentMarker::BackgroundColor() const {
258 if (TextCompositionMarkerDetails* details = 220 if (TextCompositionMarkerDetails* details =
259 ToTextCompositionMarkerDetails(details_.Get())) 221 ToTextCompositionMarkerDetails(details_.Get()))
260 return details->BackgroundColor(); 222 return details->BackgroundColor();
261 return Color::kTransparent; 223 return Color::kTransparent;
262 } 224 }
263 225
264 DEFINE_TRACE(DocumentMarker) { 226 DEFINE_TRACE(DocumentMarker) {
265 visitor->Trace(details_); 227 visitor->Trace(details_);
266 } 228 }
267 229
268 } // namespace blink 230 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698