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

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

Issue 1330233003: Revert of Avoid style clobbering in setCompositionFromExistingText. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 inline DocumentMarkerDescription* toDocumentMarkerDescription(DocumentMarkerDeta ils* details) 61 inline DocumentMarkerDescription* toDocumentMarkerDescription(DocumentMarkerDeta ils* details)
62 { 62 {
63 if (details && details->isDescription()) 63 if (details && details->isDescription())
64 return static_cast<DocumentMarkerDescription*>(details); 64 return static_cast<DocumentMarkerDescription*>(details);
65 return 0; 65 return 0;
66 } 66 }
67 67
68 68
69 class DocumentMarkerTextMatch final : public DocumentMarkerDetails { 69 class DocumentMarkerTextMatch final : public DocumentMarkerDetails {
70 public: 70 public:
71 static PassRefPtrWillBeRawPtr<DocumentMarkerTextMatch> create(bool); 71 static PassRefPtrWillBeRawPtr<DocumentMarkerTextMatch> instanceFor(bool);
72 72
73 bool activeMatch() const { return m_match; } 73 bool activeMatch() const { return m_match; }
74 bool isTextMatch() const override { return true; } 74 bool isTextMatch() const override { return true; }
75 75
76 private: 76 private:
77 explicit DocumentMarkerTextMatch(bool match) 77 explicit DocumentMarkerTextMatch(bool match)
78 : m_match(match) 78 : m_match(match)
79 { 79 {
80 } 80 }
81 81
82 bool m_match; 82 bool m_match;
83 }; 83 };
84 84
85 PassRefPtrWillBeRawPtr<DocumentMarkerTextMatch> DocumentMarkerTextMatch::create( bool match) 85 PassRefPtrWillBeRawPtr<DocumentMarkerTextMatch> DocumentMarkerTextMatch::instanc eFor(bool match)
86 { 86 {
87 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(DocumentMarkerTextMatch, trueInstance, (adoptRefWillBeNoop(new DocumentMarkerTextMatch(true)))); 87 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(DocumentMarkerTextMatch, trueInstance, (adoptRefWillBeNoop(new DocumentMarkerTextMatch(true))));
88 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(DocumentMarkerTextMatch, falseInstance, (adoptRefWillBeNoop(new DocumentMarkerTextMatch(false)))); 88 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(DocumentMarkerTextMatch, falseInstance, (adoptRefWillBeNoop(new DocumentMarkerTextMatch(false))));
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> create(Color und erlineColor, bool thick, Color backgroundColor);
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_backgroundColor(backgroundColor)
112 , m_thick(thick)
113 {
114 }
115
116 Color m_underlineColor;
117 Color m_backgroundColor;
118 bool m_thick;
119 };
120
121 PassRefPtrWillBeRawPtr<TextCompositionMarkerDetails> TextCompositionMarkerDetail s::create(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
134 DocumentMarker::DocumentMarker(MarkerType type, unsigned startOffset, unsigned e ndOffset, const String& description, uint32_t hash) 99 DocumentMarker::DocumentMarker(MarkerType type, unsigned startOffset, unsigned e ndOffset, const String& description, uint32_t hash)
135 : m_type(type) 100 : m_type(type)
136 , m_startOffset(startOffset) 101 , m_startOffset(startOffset)
137 , m_endOffset(endOffset) 102 , m_endOffset(endOffset)
138 , m_details(description.isEmpty() ? nullptr : DocumentMarkerDescription::cre ate(description)) 103 , m_details(description.isEmpty() ? nullptr : DocumentMarkerDescription::cre ate(description))
139 , m_hash(hash) 104 , m_hash(hash)
140 { 105 {
141 } 106 }
142 107
143 DocumentMarker::DocumentMarker(unsigned startOffset, unsigned endOffset, bool ac tiveMatch) 108 DocumentMarker::DocumentMarker(unsigned startOffset, unsigned endOffset, bool ac tiveMatch)
144 : m_type(DocumentMarker::TextMatch) 109 : m_type(DocumentMarker::TextMatch)
145 , m_startOffset(startOffset) 110 , m_startOffset(startOffset)
146 , m_endOffset(endOffset) 111 , m_endOffset(endOffset)
147 , m_details(DocumentMarkerTextMatch::create(activeMatch)) 112 , m_details(DocumentMarkerTextMatch::instanceFor(activeMatch))
148 , m_hash(0) 113 , m_hash(0)
149 { 114 {
150 } 115 }
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::create(underlineColor, thick, back groundColor))
157 , m_hash(0)
158 {
159 }
160 116
161 DocumentMarker::DocumentMarker(const DocumentMarker& marker) 117 DocumentMarker::DocumentMarker(const DocumentMarker& marker)
162 : m_type(marker.type()) 118 : m_type(marker.type())
163 , m_startOffset(marker.startOffset()) 119 , m_startOffset(marker.startOffset())
164 , m_endOffset(marker.endOffset()) 120 , m_endOffset(marker.endOffset())
165 , m_details(marker.details()) 121 , m_details(marker.details())
166 , m_hash(marker.hash()) 122 , m_hash(marker.hash())
167 { 123 {
168 } 124 }
169 125
170 void DocumentMarker::shiftOffsets(int delta) 126 void DocumentMarker::shiftOffsets(int delta)
171 { 127 {
172 m_startOffset += delta; 128 m_startOffset += delta;
173 m_endOffset += delta; 129 m_endOffset += delta;
174 } 130 }
175 131
176 void DocumentMarker::setActiveMatch(bool active) 132 void DocumentMarker::setActiveMatch(bool active)
177 { 133 {
178 m_details = DocumentMarkerTextMatch::create(active); 134 m_details = DocumentMarkerTextMatch::instanceFor(active);
179 } 135 }
180 136
181 const String& DocumentMarker::description() const 137 const String& DocumentMarker::description() const
182 { 138 {
183 if (DocumentMarkerDescription* details = toDocumentMarkerDescription(m_detai ls.get())) 139 if (DocumentMarkerDescription* details = toDocumentMarkerDescription(m_detai ls.get()))
184 return details->description(); 140 return details->description();
185 return emptyString(); 141 return emptyString();
186 } 142 }
187 143
188 bool DocumentMarker::activeMatch() const 144 bool DocumentMarker::activeMatch() const
189 { 145 {
190 if (DocumentMarkerTextMatch* details = toDocumentMarkerTextMatch(m_details.g et())) 146 if (DocumentMarkerTextMatch* details = toDocumentMarkerTextMatch(m_details.g et()))
191 return details->activeMatch(); 147 return details->activeMatch();
192 return false; 148 return false;
193 } 149 }
194 150
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
216 DEFINE_TRACE(DocumentMarker) 151 DEFINE_TRACE(DocumentMarker)
217 { 152 {
218 visitor->trace(m_details); 153 visitor->trace(m_details);
219 } 154 }
220 155
221 } // namespace blink 156 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/markers/DocumentMarker.h ('k') | Source/core/editing/markers/DocumentMarkerController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698