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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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> instanceFor(bool); | 71 static PassRefPtrWillBeRawPtr<DocumentMarkerTextMatch> create(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::instanc
eFor(bool match) | 85 PassRefPtrWillBeRawPtr<DocumentMarkerTextMatch> DocumentMarkerTextMatch::create(
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 |
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::create(activeMatch)) |
113 , m_hash(0) | 148 , m_hash(0) |
114 { | 149 { |
115 } | 150 } |
| 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 } |
116 | 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) |
127 { | 171 { |
128 m_startOffset += delta; | 172 m_startOffset += delta; |
129 m_endOffset += delta; | 173 m_endOffset += delta; |
130 } | 174 } |
131 | 175 |
132 void DocumentMarker::setActiveMatch(bool active) | 176 void DocumentMarker::setActiveMatch(bool active) |
133 { | 177 { |
134 m_details = DocumentMarkerTextMatch::instanceFor(active); | 178 m_details = DocumentMarkerTextMatch::create(active); |
135 } | 179 } |
136 | 180 |
137 const String& DocumentMarker::description() const | 181 const String& DocumentMarker::description() const |
138 { | 182 { |
139 if (DocumentMarkerDescription* details = toDocumentMarkerDescription(m_detai
ls.get())) | 183 if (DocumentMarkerDescription* details = toDocumentMarkerDescription(m_detai
ls.get())) |
140 return details->description(); | 184 return details->description(); |
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 |