OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 ASSERT(frame().document()); | 1138 ASSERT(frame().document()); |
1139 ApplyStyleCommand::create(*frame().document(), blockStyle.get(), editing Action)->apply(); | 1139 ApplyStyleCommand::create(*frame().document(), blockStyle.get(), editing Action)->apply(); |
1140 } | 1140 } |
1141 | 1141 |
1142 // Set the remaining style as the typing style. | 1142 // Set the remaining style as the typing style. |
1143 frame().selection().setTypingStyle(typingStyle); | 1143 frame().selection().setTypingStyle(typingStyle); |
1144 } | 1144 } |
1145 | 1145 |
1146 bool Editor::findString(const String& target, FindOptions options) | 1146 bool Editor::findString(const String& target, FindOptions options) |
1147 { | 1147 { |
1148 VisibleSelection selection = frame().selection().selection(); | 1148 const VisibleSelection& selection = frame().selection().selection(); |
1149 const EphemeralRange& resultRange = findRangeOfString( | |
yosin_UTC9
2015/10/22 02:28:27
Remove |&|. Does clang allow this?
Andrey Kraynov
2015/10/22 09:53:20
It's a valid C++ code for all compilers ;)
http:/
| |
1150 target, | |
1151 EphemeralRange(selection.start(), selection.end()), | |
1152 static_cast<FindOptions>(options | FindAPICall)); | |
1149 | 1153 |
1150 // TODO(yosin) We should make |findRangeOfString()| to return | 1154 if (resultRange.isCollapsed()) |
1151 // |EphemeralRange| rather than|Range| object. | |
1152 RefPtrWillBeRawPtr<Range> resultRange = findRangeOfString(target, EphemeralR ange(selection.start(), selection.end()), static_cast<FindOptions>(options | Fin dAPICall)); | |
yosin_UTC9
2015/10/22 02:28:27
Just FYI. We have usage counters
- https://www.ch
| |
1153 | |
1154 if (!resultRange) | |
1155 return false; | 1155 return false; |
1156 | 1156 |
1157 frame().selection().setSelection(VisibleSelection(EphemeralRange(resultRange .get()))); | 1157 frame().selection().setSelection(VisibleSelection(resultRange)); |
1158 frame().selection().revealSelection(); | 1158 frame().selection().revealSelection(); |
1159 return true; | 1159 return true; |
1160 } | 1160 } |
1161 | 1161 |
1162 template <typename Strategy> | 1162 template <typename Strategy> |
1163 static PassRefPtrWillBeRawPtr<Range> findStringAndScrollToVisibleAlgorithm(Edito r& editor, const String& target, const EphemeralRangeTemplate<Strategy>& previou sMatch, FindOptions options) | 1163 static PassRefPtrWillBeRawPtr<Range> findStringAndScrollToVisibleAlgorithm(Edito r& editor, const String& target, const EphemeralRangeTemplate<Strategy>& previou sMatch, FindOptions options) |
1164 { | 1164 { |
1165 RefPtrWillBeRawPtr<Range> nextMatch = editor.findRangeOfString(target, previ ousMatch, options); | 1165 RefPtrWillBeRawPtr<Range> nextMatch = createRange(editor.findRangeOfString(t arget, previousMatch, options)); |
yosin_UTC9
2015/10/22 02:28:28
Let's return EphmeralRange here and ask call to ha
Andrey Kraynov
2015/10/30 18:24:25
Done.
| |
1166 if (!nextMatch) | 1166 if (!nextMatch) |
1167 return nullptr; | 1167 return nullptr; |
1168 | 1168 |
1169 nextMatch->firstNode()->layoutObject()->scrollRectToVisible(LayoutRect(nextM atch->boundingBox()), | 1169 nextMatch->firstNode()->layoutObject()->scrollRectToVisible(LayoutRect(nextM atch->boundingBox()), |
1170 ScrollAlignment::alignCenterIfNeeded, ScrollAlignment::alignCenterIfNeed ed, UserScroll); | 1170 ScrollAlignment::alignCenterIfNeeded, ScrollAlignment::alignCenterIfNeed ed, UserScroll); |
1171 | 1171 |
1172 return nextMatch.release(); | 1172 return nextMatch.release(); |
1173 } | 1173 } |
1174 | 1174 |
1175 PassRefPtrWillBeRawPtr<Range> Editor::findStringAndScrollToVisible(const String& target, Range* range, FindOptions options) | 1175 PassRefPtrWillBeRawPtr<Range> Editor::findStringAndScrollToVisible(const String& target, Range* range, FindOptions options) |
1176 { | 1176 { |
1177 if (RuntimeEnabledFeatures::selectionForComposedTreeEnabled()) | 1177 if (RuntimeEnabledFeatures::selectionForComposedTreeEnabled()) |
1178 return findStringAndScrollToVisibleAlgorithm<EditingInComposedTreeStrate gy>(*this, target, EphemeralRangeInComposedTree(range), options); | 1178 return findStringAndScrollToVisibleAlgorithm<EditingInComposedTreeStrate gy>(*this, target, EphemeralRangeInComposedTree(range), options); |
1179 return findStringAndScrollToVisibleAlgorithm<EditingStrategy>(*this, target, EphemeralRange(range), options); | 1179 return findStringAndScrollToVisibleAlgorithm<EditingStrategy>(*this, target, EphemeralRange(range), options); |
1180 } | 1180 } |
1181 | 1181 |
1182 // TODO(yosin) We should return |EphemeralRange| rather than |Range|. We use | 1182 // This function checks whether start and end position of the |range| |
1183 // |Range| object for checking whether start and end position crossing shadow | 1183 // crossing shadow boundaries. |
1184 // boundaries, however we can do it without |Range| object. | 1184 // It should be equivalent to Range::create(ephemeralRange)->collapsed(). |
1185 template <typename Strategy> | 1185 template <typename Strategy> |
1186 static PassRefPtrWillBeRawPtr<Range> findStringBetweenPositions(const String& ta rget, const EphemeralRangeTemplate<Strategy>& referenceRange, FindOptions option s) | 1186 static bool rangeBoundariesAreValid(const EphemeralRangeTemplate<Strategy>& rang e) |
1187 { | 1187 { |
1188 EphemeralRangeTemplate<Strategy> searchRange(referenceRange); | 1188 const Node* endRootContainer = range.endPosition().computeContainerNode(); |
1189 const Node* startRootContainer = range.startPosition().computeContainerNode( ); | |
1190 if (!startRootContainer || !endRootContainer) | |
1191 return false; | |
1192 | |
1193 while (endRootContainer->parentNode()) | |
yosin_UTC9
2015/10/22 02:28:28
Can we use Node::commonAncestor()?
Why not positi
Andrey Kraynov
2015/10/22 09:53:20
I looked at the checkForDifferentRootContainer() f
yosin_UTC9
2015/10/23 01:52:50
I have no idea when we have a range which start an
Andrey Kraynov
2015/10/30 18:24:25
Done.
| |
1194 endRootContainer = endRootContainer->parentNode(); | |
1195 | |
1196 while (startRootContainer->parentNode()) | |
1197 startRootContainer = startRootContainer->parentNode(); | |
1198 | |
1199 return startRootContainer == endRootContainer | |
1200 && (range.startPosition().compareTo(range.endPosition()) <= 0); | |
1201 } | |
1202 | |
1203 template <typename Strategy> | |
1204 static EphemeralRangeTemplate<Strategy> findStringBetweenPositions(const String& target, const EphemeralRangeTemplate<Strategy>& referenceRange, FindOptions opt ions) | |
1205 { | |
1206 using EphemeralRangeT = EphemeralRangeTemplate<Strategy>; | |
yosin_UTC9
2015/10/22 02:28:27
We don't have rule about "using alias". In our exp
Andrey Kraynov
2015/10/22 09:53:20
OK, I'll revert these changes.
But sometimes it's
yosin_UTC9
2015/10/23 01:52:50
You're not alone. I think so too.
I'm voting to us
Andrey Kraynov
2015/10/30 18:24:25
Done.
| |
1207 | |
1208 EphemeralRangeT searchRange(referenceRange); | |
1189 | 1209 |
1190 bool forward = !(options & Backwards); | 1210 bool forward = !(options & Backwards); |
1191 | 1211 |
1192 while (true) { | 1212 while (true) { |
1193 EphemeralRangeTemplate<Strategy> resultRange = findPlainText(searchRange , target, options); | 1213 const EphemeralRangeT& resultRange = findPlainText(searchRange, target, options); |
yosin_UTC9
2015/10/22 02:28:27
Remove |&|. I think returned object lives on stack
| |
1194 if (resultRange.isCollapsed()) | 1214 if (resultRange.isCollapsed()) |
1195 return nullptr; | 1215 return EphemeralRangeT(); |
1196 | 1216 |
1197 RefPtrWillBeRawPtr<Range> rangeObject = Range::create(resultRange.docume nt(), toPositionInDOMTree(resultRange.startPosition()), toPositionInDOMTree(resu ltRange.endPosition())); | 1217 if (rangeBoundariesAreValid(resultRange)) |
1198 if (!rangeObject->collapsed()) | 1218 return resultRange; |
1199 return rangeObject.release(); | |
1200 | 1219 |
1201 // Found text spans over multiple TreeScopes. Since it's impossible to | 1220 // Found text spans over multiple TreeScopes. Since it's impossible to |
1202 // return such section as a Range, we skip this match and seek for the | 1221 // return such section as a Range, we skip this match and seek for the |
1203 // next occurrence. | 1222 // next occurrence. |
1204 // TODO(yosin) Handle this case. | 1223 // TODO(yosin) Handle this case. |
1205 if (forward) { | 1224 if (forward) { |
1206 // TODO(yosin) We should use |PositionMoveType::Character| | 1225 // TODO(yosin) We should use |PositionMoveType::Character| |
1207 // for |nextPositionOf()|. | 1226 // for |nextPositionOf()|. |
1208 searchRange = EphemeralRangeTemplate<Strategy>(nextPositionOf(result Range.startPosition(), PositionMoveType::CodePoint), searchRange.endPosition()); | 1227 searchRange = EphemeralRangeT(nextPositionOf(resultRange.startPositi on(), PositionMoveType::CodePoint), searchRange.endPosition()); |
1209 } else { | 1228 } else { |
1210 // TODO(yosin) We should use |PositionMoveType::Character| | 1229 // TODO(yosin) We should use |PositionMoveType::Character| |
1211 // for |previousPositionOf()|. | 1230 // for |previousPositionOf()|. |
1212 searchRange = EphemeralRangeTemplate<Strategy>(searchRange.startPosi tion(), previousPositionOf(resultRange.endPosition(), PositionMoveType::CodePoin t)); | 1231 searchRange = EphemeralRangeT(searchRange.startPosition(), previousP ositionOf(resultRange.endPosition(), PositionMoveType::CodePoint)); |
1213 } | 1232 } |
1214 } | 1233 } |
1215 | 1234 |
1216 ASSERT_NOT_REACHED(); | 1235 ASSERT_NOT_REACHED(); |
1217 return nullptr; | 1236 return EphemeralRangeT(); |
1218 } | 1237 } |
1219 | 1238 |
1220 template <typename Strategy> | 1239 template <typename Strategy> |
1221 static PassRefPtrWillBeRawPtr<Range> findRangeOfStringAlgorithm(Document& docume nt, const String& target, const EphemeralRangeTemplate<Strategy>& referenceRange , FindOptions options) | 1240 static EphemeralRangeTemplate<Strategy> findRangeOfStringAlgorithm(const String& target, const EphemeralRangeTemplate<Strategy>& referenceRange, FindOptions opt ions) |
1222 { | 1241 { |
1242 using EphemeralRangeT = EphemeralRangeTemplate<Strategy>; | |
1243 | |
1223 if (target.isEmpty()) | 1244 if (target.isEmpty()) |
1224 return nullptr; | 1245 return EphemeralRangeT(); |
1225 | 1246 |
1226 // Start from an edge of the reference range. Which edge is used depends on | 1247 // Start from an edge of the reference range. Which edge is used depends on |
1227 // whether we're searching forward or backward, and whether startInSelection | 1248 // whether we're searching forward or backward, and whether startInSelection |
1228 // is set. | 1249 // is set. |
1229 EphemeralRangeTemplate<Strategy> documentRange = EphemeralRangeTemplate<Stra tegy>::rangeOfContents(document); | 1250 EphemeralRangeT documentRange = EphemeralRangeT::rangeOfContents(referenceRa nge.document()); |
1230 EphemeralRangeTemplate<Strategy> searchRange(documentRange); | 1251 EphemeralRangeT searchRange(documentRange); |
1231 | 1252 |
1232 bool forward = !(options & Backwards); | 1253 bool forward = !(options & Backwards); |
1233 bool startInReferenceRange = false; | 1254 bool startInReferenceRange = false; |
1234 if (referenceRange.isNotNull()) { | 1255 if (referenceRange.isNotNull()) { |
1235 startInReferenceRange = options & StartInSelection; | 1256 startInReferenceRange = options & StartInSelection; |
1236 if (forward && startInReferenceRange) | 1257 if (forward && startInReferenceRange) |
1237 searchRange = EphemeralRangeTemplate<Strategy>(referenceRange.startP osition(), documentRange.endPosition()); | 1258 searchRange = EphemeralRangeT(referenceRange.startPosition(), docume ntRange.endPosition()); |
1238 else if (forward) | 1259 else if (forward) |
1239 searchRange = EphemeralRangeTemplate<Strategy>(referenceRange.endPos ition(), documentRange.endPosition()); | 1260 searchRange = EphemeralRangeT(referenceRange.endPosition(), document Range.endPosition()); |
1240 else if (startInReferenceRange) | 1261 else if (startInReferenceRange) |
1241 searchRange = EphemeralRangeTemplate<Strategy>(documentRange.startPo sition(), referenceRange.endPosition()); | 1262 searchRange = EphemeralRangeT(documentRange.startPosition(), referen ceRange.endPosition()); |
1242 else | 1263 else |
1243 searchRange = EphemeralRangeTemplate<Strategy>(documentRange.startPo sition(), referenceRange.startPosition()); | 1264 searchRange = EphemeralRangeT(documentRange.startPosition(), referen ceRange.startPosition()); |
1244 } | 1265 } |
1245 | 1266 |
1246 RefPtrWillBeRawPtr<Range> resultRange = findStringBetweenPositions(target, s earchRange, options); | 1267 EphemeralRangeT resultRange = findStringBetweenPositions(target, searchRange , options); |
1247 | 1268 |
1248 // If we started in the reference range and the found range exactly matches | 1269 // If we started in the reference range and the found range exactly matches |
1249 // the reference range, find again. Build a selection with the found range | 1270 // the reference range, find again. Build a selection with the found range |
1250 // to remove collapsed whitespace. Compare ranges instead of selection | 1271 // to remove collapsed whitespace. Compare ranges instead of selection |
1251 // objects to ignore the way that the current selection was made. | 1272 // objects to ignore the way that the current selection was made. |
1252 if (resultRange && startInReferenceRange && normalizeRange(EphemeralRangeTem plate<Strategy>(resultRange.get())) == referenceRange) { | 1273 if (!resultRange.isCollapsed() && startInReferenceRange && normalizeRange(re sultRange) == referenceRange) { |
1253 if (forward) | 1274 if (forward) |
1254 searchRange = EphemeralRangeTemplate<Strategy>(fromPositionInDOMTree <Strategy>(resultRange->endPosition()), searchRange.endPosition()); | 1275 searchRange = EphemeralRangeT(resultRange.endPosition(), searchRange .endPosition()); |
1255 else | 1276 else |
1256 searchRange = EphemeralRangeTemplate<Strategy>(searchRange.startPosi tion(), fromPositionInDOMTree<Strategy>(resultRange->startPosition())); | 1277 searchRange = EphemeralRangeT(searchRange.startPosition(), resultRan ge.startPosition()); |
1257 resultRange = findStringBetweenPositions(target, searchRange, options); | 1278 resultRange = findStringBetweenPositions(target, searchRange, options); |
1258 } | 1279 } |
1259 | 1280 |
1260 if (!resultRange && options & WrapAround) | 1281 if (resultRange.isCollapsed() && options & WrapAround) |
1261 return findStringBetweenPositions(target, documentRange, options); | 1282 return findStringBetweenPositions(target, documentRange, options); |
1262 | 1283 |
1263 return resultRange.release(); | 1284 return resultRange; |
1264 } | 1285 } |
1265 | 1286 |
1266 PassRefPtrWillBeRawPtr<Range> Editor::findRangeOfString(const String& target, co nst EphemeralRange& reference, FindOptions options) | 1287 EphemeralRange Editor::findRangeOfString(const String& target, const EphemeralRa nge& reference, FindOptions options) |
1267 { | 1288 { |
1268 return findRangeOfStringAlgorithm<EditingStrategy>(*frame().document(), targ et, reference, options); | 1289 return findRangeOfStringAlgorithm<EditingStrategy>(target, reference, option s); |
1269 } | 1290 } |
1270 | 1291 |
1271 PassRefPtrWillBeRawPtr<Range> Editor::findRangeOfString(const String& target, co nst EphemeralRangeInComposedTree& reference, FindOptions options) | 1292 EphemeralRangeInComposedTree Editor::findRangeOfString(const String& target, con st EphemeralRangeInComposedTree& reference, FindOptions options) |
1272 { | 1293 { |
1273 return findRangeOfStringAlgorithm<EditingInComposedTreeStrategy>(*frame().do cument(), target, reference, options); | 1294 return findRangeOfStringAlgorithm<EditingInComposedTreeStrategy>(target, ref erence, options); |
1274 } | 1295 } |
1275 | 1296 |
1276 void Editor::setMarkedTextMatchesAreHighlighted(bool flag) | 1297 void Editor::setMarkedTextMatchesAreHighlighted(bool flag) |
1277 { | 1298 { |
1278 if (flag == m_areMarkedTextMatchesHighlighted) | 1299 if (flag == m_areMarkedTextMatchesHighlighted) |
1279 return; | 1300 return; |
1280 | 1301 |
1281 m_areMarkedTextMatchesHighlighted = flag; | 1302 m_areMarkedTextMatchesHighlighted = flag; |
1282 frame().document()->markers().repaintMarkers(DocumentMarker::TextMatch); | 1303 frame().document()->markers().repaintMarkers(DocumentMarker::TextMatch); |
1283 } | 1304 } |
(...skipping 17 matching lines...) Expand all Loading... | |
1301 } | 1322 } |
1302 | 1323 |
1303 DEFINE_TRACE(Editor) | 1324 DEFINE_TRACE(Editor) |
1304 { | 1325 { |
1305 visitor->trace(m_frame); | 1326 visitor->trace(m_frame); |
1306 visitor->trace(m_lastEditCommand); | 1327 visitor->trace(m_lastEditCommand); |
1307 visitor->trace(m_mark); | 1328 visitor->trace(m_mark); |
1308 } | 1329 } |
1309 | 1330 |
1310 } // namespace blink | 1331 } // namespace blink |
OLD | NEW |