OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 233 } |
234 | 234 |
235 WebLocalFrameImpl* mainFrameImpl = m_ownerFrame.viewImpl()->mainFrameImpl(); | 235 WebLocalFrameImpl* mainFrameImpl = m_ownerFrame.viewImpl()->mainFrameImpl(); |
236 Position searchStart = firstPositionInNode(m_ownerFrame.frame()->document())
; | 236 Position searchStart = firstPositionInNode(m_ownerFrame.frame()->document())
; |
237 Position searchEnd = lastPositionInNode(m_ownerFrame.frame()->document()); | 237 Position searchEnd = lastPositionInNode(m_ownerFrame.frame()->document()); |
238 ASSERT(searchStart.document() == searchEnd.document()); | 238 ASSERT(searchStart.document() == searchEnd.document()); |
239 | 239 |
240 if (m_resumeScopingFromRange) { | 240 if (m_resumeScopingFromRange) { |
241 // This is a continuation of a scoping operation that timed out and didn
't | 241 // This is a continuation of a scoping operation that timed out and didn
't |
242 // complete last time around, so we should start from where we left off. | 242 // complete last time around, so we should start from where we left off. |
243 ASSERT(m_resumeScopingFromRange->collapsed(ASSERT_NO_EXCEPTION)); | 243 ASSERT(m_resumeScopingFromRange->collapsed()); |
244 searchStart = m_resumeScopingFromRange->startPosition().next(); | 244 searchStart = m_resumeScopingFromRange->startPosition().next(); |
245 if (searchStart.document() != searchEnd.document()) | 245 if (searchStart.document() != searchEnd.document()) |
246 return; | 246 return; |
247 } | 247 } |
248 | 248 |
249 // This timeout controls how long we scope before releasing control. This | 249 // This timeout controls how long we scope before releasing control. This |
250 // value does not prevent us from running for longer than this, but it is | 250 // value does not prevent us from running for longer than this, but it is |
251 // periodically checked to see if we have exceeded our allocated time. | 251 // periodically checked to see if we have exceeded our allocated time. |
252 const double maxScopingDuration = 0.1; // seconds | 252 const double maxScopingDuration = 0.1; // seconds |
253 | 253 |
254 int matchCount = 0; | 254 int matchCount = 0; |
255 bool timedOut = false; | 255 bool timedOut = false; |
256 double startTime = currentTime(); | 256 double startTime = currentTime(); |
257 do { | 257 do { |
258 // Find next occurrence of the search string. | 258 // Find next occurrence of the search string. |
259 // FIXME: (http://crbug.com/6818) This WebKit operation may run for long
er | 259 // FIXME: (http://crbug.com/6818) This WebKit operation may run for long
er |
260 // than the timeout value, and is not interruptible as it is currently | 260 // than the timeout value, and is not interruptible as it is currently |
261 // written. We may need to rewrite it with interruptibility in mind, or | 261 // written. We may need to rewrite it with interruptibility in mind, or |
262 // find an alternative. | 262 // find an alternative. |
263 Position resultStart; | 263 Position resultStart; |
264 Position resultEnd; | 264 Position resultEnd; |
265 findPlainText(searchStart, searchEnd, searchText, options.matchCase ? 0
: CaseInsensitive, resultStart, resultEnd); | 265 findPlainText(searchStart, searchEnd, searchText, options.matchCase ? 0
: CaseInsensitive, resultStart, resultEnd); |
266 if (resultStart == resultEnd) { | 266 if (resultStart == resultEnd) { |
267 // Not found. | 267 // Not found. |
268 break; | 268 break; |
269 } | 269 } |
270 | 270 |
271 RefPtrWillBeRawPtr<Range> resultRange = Range::create(*resultStart.docum
ent(), resultStart, resultEnd); | 271 RefPtrWillBeRawPtr<Range> resultRange = Range::create(*resultStart.docum
ent(), resultStart, resultEnd); |
272 if (resultRange->collapsed(ASSERT_NO_EXCEPTION)) { | 272 if (resultRange->collapsed()) { |
273 // resultRange will be collapsed if the matched text spans over mult
iple TreeScopes. | 273 // resultRange will be collapsed if the matched text spans over mult
iple TreeScopes. |
274 // FIXME: Show such matches to users. | 274 // FIXME: Show such matches to users. |
275 searchStart = resultStart.next(); | 275 searchStart = resultStart.next(); |
276 continue; | 276 continue; |
277 } | 277 } |
278 | 278 |
279 ++matchCount; | 279 ++matchCount; |
280 | 280 |
281 // Catch a special case where Find found something but doesn't know what | 281 // Catch a special case where Find found something but doesn't know what |
282 // the bounding box for it is. In this case we set the first match we fi
nd | 282 // the bounding box for it is. In this case we set the first match we fi
nd |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 cancelPendingScopingEffort(); | 622 cancelPendingScopingEffort(); |
623 } | 623 } |
624 | 624 |
625 void TextFinder::addMarker(Range* range, bool activeMatch) | 625 void TextFinder::addMarker(Range* range, bool activeMatch) |
626 { | 626 { |
627 m_ownerFrame.frame()->document()->markers().addTextMatchMarker(range, active
Match); | 627 m_ownerFrame.frame()->document()->markers().addTextMatchMarker(range, active
Match); |
628 } | 628 } |
629 | 629 |
630 void TextFinder::setMarkerActive(Range* range, bool active) | 630 void TextFinder::setMarkerActive(Range* range, bool active) |
631 { | 631 { |
632 if (!range || range->collapsed(IGNORE_EXCEPTION)) | 632 if (!range || range->collapsed()) |
633 return; | 633 return; |
634 m_ownerFrame.frame()->document()->markers().setMarkersActive(range, active); | 634 m_ownerFrame.frame()->document()->markers().setMarkersActive(range, active); |
635 } | 635 } |
636 | 636 |
637 int TextFinder::ordinalOfFirstMatchForFrame(WebLocalFrameImpl* frame) const | 637 int TextFinder::ordinalOfFirstMatchForFrame(WebLocalFrameImpl* frame) const |
638 { | 638 { |
639 int ordinal = 0; | 639 int ordinal = 0; |
640 WebLocalFrameImpl* mainFrameImpl = m_ownerFrame.viewImpl()->mainFrameImpl(); | 640 WebLocalFrameImpl* mainFrameImpl = m_ownerFrame.viewImpl()->mainFrameImpl(); |
641 // Iterate from the main frame up to (but not including) |frame| and | 641 // Iterate from the main frame up to (but not including) |frame| and |
642 // add up the number of matches found so far. | 642 // add up the number of matches found so far. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 if (!m_framesScopingCount) | 729 if (!m_framesScopingCount) |
730 m_ownerFrame.increaseMatchCount(0, identifier); | 730 m_ownerFrame.increaseMatchCount(0, identifier); |
731 } | 731 } |
732 | 732 |
733 int TextFinder::ordinalOfFirstMatch() const | 733 int TextFinder::ordinalOfFirstMatch() const |
734 { | 734 { |
735 return ordinalOfFirstMatchForFrame(&m_ownerFrame); | 735 return ordinalOfFirstMatchForFrame(&m_ownerFrame); |
736 } | 736 } |
737 | 737 |
738 } // namespace blink | 738 } // namespace blink |
OLD | NEW |