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

Side by Side Diff: Source/web/WebFrameImpl.cpp

Issue 108273003: Completed decoupling of decoupling WebFrameImpl and TextFinder. Base URL: https://chromium.googlesource.com/chromium/blink.git@update-review-5-rebase
Patch Set: Created 7 years 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
« no previous file with comments | « Source/web/WebFrameImpl.h ('k') | Source/web/web.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 #include "config.h" 74 #include "config.h"
75 #include "WebFrameImpl.h" 75 #include "WebFrameImpl.h"
76 76
77 #include <algorithm> 77 #include <algorithm>
78 #include "AssociatedURLLoader.h" 78 #include "AssociatedURLLoader.h"
79 #include "DOMUtilitiesPrivate.h" 79 #include "DOMUtilitiesPrivate.h"
80 #include "EventListenerWrapper.h" 80 #include "EventListenerWrapper.h"
81 #include "FindInPageCoordinates.h" 81 #include "FindInPageCoordinates.h"
82 #include "HTMLNames.h" 82 #include "HTMLNames.h"
83 #include "PageOverlay.h" 83 #include "PageOverlay.h"
84 #include "TextFinder.h"
84 #include "V8DOMFileSystem.h" 85 #include "V8DOMFileSystem.h"
85 #include "V8DirectoryEntry.h" 86 #include "V8DirectoryEntry.h"
86 #include "V8FileEntry.h" 87 #include "V8FileEntry.h"
87 #include "WebConsoleMessage.h" 88 #include "WebConsoleMessage.h"
88 #include "WebDOMEvent.h" 89 #include "WebDOMEvent.h"
89 #include "WebDOMEventListener.h" 90 #include "WebDOMEventListener.h"
90 #include "WebDataSourceImpl.h" 91 #include "WebDataSourceImpl.h"
91 #include "WebDevToolsAgentPrivate.h" 92 #include "WebDevToolsAgentPrivate.h"
92 #include "WebDocument.h" 93 #include "WebDocument.h"
93 #include "WebFindOptions.h" 94 #include "WebFindOptions.h"
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 int m_pageCount; 456 int m_pageCount;
456 WebPrintParams m_printParams; 457 WebPrintParams m_printParams;
457 458
458 }; 459 };
459 460
460 static WebDataSource* DataSourceForDocLoader(DocumentLoader* loader) 461 static WebDataSource* DataSourceForDocLoader(DocumentLoader* loader)
461 { 462 {
462 return loader ? WebDataSourceImpl::fromDocumentLoader(loader) : 0; 463 return loader ? WebDataSourceImpl::fromDocumentLoader(loader) : 0;
463 } 464 }
464 465
465 WebFrameImpl::FindMatch::FindMatch(PassRefPtr<Range> range, int ordinal)
466 : m_range(range)
467 , m_ordinal(ordinal)
468 {
469 }
470
471 class WebFrameImpl::DeferredScopeStringMatches {
472 public:
473 DeferredScopeStringMatches(WebFrameImpl* webFrame, int identifier, const Web String& searchText, const WebFindOptions& options, bool reset)
474 : m_timer(this, &DeferredScopeStringMatches::doTimeout)
475 , m_webFrame(webFrame)
476 , m_identifier(identifier)
477 , m_searchText(searchText)
478 , m_options(options)
479 , m_reset(reset)
480 {
481 m_timer.startOneShot(0.0);
482 }
483
484 private:
485 void doTimeout(Timer<DeferredScopeStringMatches>*)
486 {
487 m_webFrame->callScopeStringMatches(this, m_identifier, m_searchText, m_o ptions, m_reset);
488 }
489
490 Timer<DeferredScopeStringMatches> m_timer;
491 RefPtr<WebFrameImpl> m_webFrame;
492 int m_identifier;
493 WebString m_searchText;
494 WebFindOptions m_options;
495 bool m_reset;
496 };
497
498 // WebFrame ------------------------------------------------------------------- 466 // WebFrame -------------------------------------------------------------------
499 467
500 int WebFrame::instanceCount() 468 int WebFrame::instanceCount()
501 { 469 {
502 return frameCount; 470 return frameCount;
503 } 471 }
504 472
505 WebFrame* WebFrame::frameForCurrentContext() 473 WebFrame* WebFrame::frameForCurrentContext()
506 { 474 {
507 v8::Handle<v8::Context> context = v8::Isolate::GetCurrent()->GetCurrentConte xt(); 475 v8::Handle<v8::Context> context = v8::Isolate::GetCurrent()->GetCurrentConte xt();
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 } 1411 }
1444 1412
1445 WebString WebFrameImpl::pageProperty(const WebString& propertyName, int pageInde x) 1413 WebString WebFrameImpl::pageProperty(const WebString& propertyName, int pageInde x)
1446 { 1414 {
1447 ASSERT(m_printContext); 1415 ASSERT(m_printContext);
1448 return m_printContext->pageProperty(frame(), propertyName.utf8().data(), pag eIndex); 1416 return m_printContext->pageProperty(frame(), propertyName.utf8().data(), pag eIndex);
1449 } 1417 }
1450 1418
1451 bool WebFrameImpl::find(int identifier, const WebString& searchText, const WebFi ndOptions& options, bool wrapWithinFrame, WebRect* selectionRect) 1419 bool WebFrameImpl::find(int identifier, const WebString& searchText, const WebFi ndOptions& options, bool wrapWithinFrame, WebRect* selectionRect)
1452 { 1420 {
1453 if (!frame() || !frame()->page()) 1421 return getOrCreateTextFinder()->find(identifier, searchText, options, wrapWi thinFrame, selectionRect);
1454 return false;
1455
1456 WebFrameImpl* mainFrameImpl = viewImpl()->mainFrameImpl();
1457
1458 if (!options.findNext)
1459 frame()->page()->unmarkAllTextMatches();
1460 else
1461 setMarkerActive(m_activeMatch.get(), false);
1462
1463 if (m_activeMatch && &m_activeMatch->ownerDocument() != frame()->document())
1464 m_activeMatch = 0;
1465
1466 // If the user has selected something since the last Find operation we want
1467 // to start from there. Otherwise, we start searching from where the last Fi nd
1468 // operation left off (either a Find or a FindNext operation).
1469 VisibleSelection selection(frame()->selection().selection());
1470 bool activeSelection = !selection.isNone();
1471 if (activeSelection) {
1472 m_activeMatch = selection.firstRange().get();
1473 frame()->selection().clear();
1474 }
1475
1476 ASSERT(frame() && frame()->view());
1477 const FindOptions findOptions = (options.forward ? 0 : Backwards)
1478 | (options.matchCase ? 0 : CaseInsensitive)
1479 | (wrapWithinFrame ? WrapAround : 0)
1480 | (options.wordStart ? AtWordStarts : 0)
1481 | (options.medialCapitalAsWordStart ? TreatMedialCapitalAsWordStart : 0)
1482 | (options.findNext ? 0 : StartInSelection);
1483 m_activeMatch = frame()->editor().findStringAndScrollToVisible(searchText, m _activeMatch.get(), findOptions);
1484
1485 if (!m_activeMatch) {
1486 // If we're finding next the next active match might not be in the curre nt frame.
1487 // In this case we don't want to clear the matches cache.
1488 if (!options.findNext)
1489 clearFindMatchesCache();
1490 invalidateArea(InvalidateAll);
1491 return false;
1492 }
1493
1494 #if OS(ANDROID)
1495 viewImpl()->zoomToFindInPageRect(frameView()->contentsToWindow(enclosingIntR ect(RenderObject::absoluteBoundingBoxRectForRange(m_activeMatch.get()))));
1496 #endif
1497
1498 setMarkerActive(m_activeMatch.get(), true);
1499 WebFrameImpl* oldActiveFrame = mainFrameImpl->m_currentActiveMatchFrame;
1500 mainFrameImpl->m_currentActiveMatchFrame = this;
1501
1502 // Make sure no node is focused. See http://crbug.com/38700.
1503 frame()->document()->setFocusedElement(0);
1504
1505 if (!options.findNext || activeSelection) {
1506 // This is either a Find operation or a Find-next from a new start point
1507 // due to a selection, so we set the flag to ask the scoping effort
1508 // to find the active rect for us and report it back to the UI.
1509 m_locatingActiveRect = true;
1510 } else {
1511 if (oldActiveFrame != this) {
1512 if (options.forward)
1513 m_activeMatchIndexInCurrentFrame = 0;
1514 else
1515 m_activeMatchIndexInCurrentFrame = m_lastMatchCount - 1;
1516 } else {
1517 if (options.forward)
1518 ++m_activeMatchIndexInCurrentFrame;
1519 else
1520 --m_activeMatchIndexInCurrentFrame;
1521
1522 if (m_activeMatchIndexInCurrentFrame + 1 > m_lastMatchCount)
1523 m_activeMatchIndexInCurrentFrame = 0;
1524 if (m_activeMatchIndexInCurrentFrame == -1)
1525 m_activeMatchIndexInCurrentFrame = m_lastMatchCount - 1;
1526 }
1527 if (selectionRect) {
1528 *selectionRect = frameView()->contentsToWindow(m_activeMatch->boundi ngBox());
1529 reportFindInPageSelection(*selectionRect, m_activeMatchIndexInCurren tFrame + 1, identifier);
1530 }
1531 }
1532
1533 return true;
1534 } 1422 }
1535 1423
1536 void WebFrameImpl::stopFinding(bool clearSelection) 1424 void WebFrameImpl::stopFinding(bool clearSelection)
1537 { 1425 {
1538 if (!clearSelection) 1426 ASSERT(m_textFinder);
1539 setFindEndstateFocusAndSelection(); 1427 m_textFinder->stopFinding(clearSelection);
1540 cancelPendingScopingEffort();
1541
1542 // Remove all markers for matches found and turn off the highlighting.
1543 frame()->document()->markers()->removeMarkers(DocumentMarker::TextMatch);
1544 frame()->editor().setMarkedTextMatchesAreHighlighted(false);
1545 clearFindMatchesCache();
1546
1547 // Let the frame know that we don't want tickmarks or highlighting anymore.
1548 invalidateArea(InvalidateAll);
1549 } 1428 }
1550 1429
1551 void WebFrameImpl::scopeStringMatches(int identifier, const WebString& searchTex t, const WebFindOptions& options, bool reset) 1430 void WebFrameImpl::scopeStringMatches(int identifier, const WebString& searchTex t, const WebFindOptions& options, bool reset)
1552 { 1431 {
1553 if (reset) { 1432 getOrCreateTextFinder()->scopeStringMatches(identifier, searchText, options, reset);
1554 // This is a brand new search, so we need to reset everything.
1555 // Scoping is just about to begin.
1556 m_scopingInProgress = true;
1557
1558 // Need to keep the current identifier locally in order to finish the
1559 // request in case the frame is detached during the process.
1560 m_findRequestIdentifier = identifier;
1561
1562 // Clear highlighting for this frame.
1563 if (frame() && frame()->page() && frame()->editor().markedTextMatchesAre Highlighted())
1564 frame()->page()->unmarkAllTextMatches();
1565
1566 // Clear the tickmarks and results cache.
1567 clearFindMatchesCache();
1568
1569 // Clear the counters from last operation.
1570 m_lastMatchCount = 0;
1571 m_nextInvalidateAfter = 0;
1572
1573 m_resumeScopingFromRange = 0;
1574
1575 // The view might be null on detached frames.
1576 if (frame() && frame()->page())
1577 viewImpl()->mainFrameImpl()->m_framesScopingCount++;
1578
1579 // Now, defer scoping until later to allow find operation to finish quic kly.
1580 scopeStringMatchesSoon(identifier, searchText, options, false); // false means just reset, so don't do it again.
1581 return;
1582 }
1583
1584 if (!shouldScopeMatches(searchText)) {
1585 // Note that we want to defer the final update when resetting even if sh ouldScopeMatches returns false.
1586 // This is done in order to prevent sending a final message based only o n the results of the first frame
1587 // since m_framesScopingCount would be 0 as other frames have yet to res et.
1588 finishCurrentScopingEffort(identifier);
1589 return;
1590 }
1591
1592 WebFrameImpl* mainFrameImpl = viewImpl()->mainFrameImpl();
1593 RefPtr<Range> searchRange(rangeOfContents(frame()->document()));
1594
1595 Node* originalEndContainer = searchRange->endContainer();
1596 int originalEndOffset = searchRange->endOffset();
1597
1598 TrackExceptionState exceptionState, exceptionState2;
1599 if (m_resumeScopingFromRange) {
1600 // This is a continuation of a scoping operation that timed out and didn 't
1601 // complete last time around, so we should start from where we left off.
1602 searchRange->setStart(m_resumeScopingFromRange->startContainer(), m_resu meScopingFromRange->startOffset(exceptionState2) + 1, exceptionState);
1603 if (exceptionState.hadException() || exceptionState2.hadException()) {
1604 if (exceptionState2.hadException()) // A non-zero |exceptionState| h appens when navigating during search.
1605 ASSERT_NOT_REACHED();
1606 return;
1607 }
1608 }
1609
1610 // This timeout controls how long we scope before releasing control. This
1611 // value does not prevent us from running for longer than this, but it is
1612 // periodically checked to see if we have exceeded our allocated time.
1613 const double maxScopingDuration = 0.1; // seconds
1614
1615 int matchCount = 0;
1616 bool timedOut = false;
1617 double startTime = currentTime();
1618 do {
1619 // Find next occurrence of the search string.
1620 // FIXME: (http://b/1088245) This WebKit operation may run for longer
1621 // than the timeout value, and is not interruptible as it is currently
1622 // written. We may need to rewrite it with interruptibility in mind, or
1623 // find an alternative.
1624 RefPtr<Range> resultRange(findPlainText(searchRange.get(),
1625 searchText,
1626 options.matchCase ? 0 : CaseInse nsitive));
1627 if (resultRange->collapsed(exceptionState)) {
1628 if (!resultRange->startContainer()->isInShadowTree())
1629 break;
1630
1631 searchRange->setStartAfter(
1632 resultRange->startContainer()->deprecatedShadowAncestorNode(), e xceptionState);
1633 searchRange->setEnd(originalEndContainer, originalEndOffset, excepti onState);
1634 continue;
1635 }
1636
1637 ++matchCount;
1638
1639 // Catch a special case where Find found something but doesn't know what
1640 // the bounding box for it is. In this case we set the first match we fi nd
1641 // as the active rect.
1642 IntRect resultBounds = resultRange->boundingBox();
1643 IntRect activeSelectionRect;
1644 if (m_locatingActiveRect) {
1645 activeSelectionRect = m_activeMatch.get() ?
1646 m_activeMatch->boundingBox() : resultBounds;
1647 }
1648
1649 // If the Find function found a match it will have stored where the
1650 // match was found in m_activeSelectionRect on the current frame. If we
1651 // find this rect during scoping it means we have found the active
1652 // tickmark.
1653 bool foundActiveMatch = false;
1654 if (m_locatingActiveRect && (activeSelectionRect == resultBounds)) {
1655 // We have found the active tickmark frame.
1656 mainFrameImpl->m_currentActiveMatchFrame = this;
1657 foundActiveMatch = true;
1658 // We also know which tickmark is active now.
1659 m_activeMatchIndexInCurrentFrame = matchCount - 1;
1660 // To stop looking for the active tickmark, we set this flag.
1661 m_locatingActiveRect = false;
1662
1663 // Notify browser of new location for the selected rectangle.
1664 reportFindInPageSelection(
1665 frameView()->contentsToWindow(resultBounds),
1666 m_activeMatchIndexInCurrentFrame + 1,
1667 identifier);
1668 }
1669
1670 addMarker(resultRange.get(), foundActiveMatch);
1671
1672 m_findMatchesCache.append(FindMatch(resultRange.get(), m_lastMatchCount + matchCount));
1673
1674 // Set the new start for the search range to be the end of the previous
1675 // result range. There is no need to use a VisiblePosition here,
1676 // since findPlainText will use a TextIterator to go over the visible
1677 // text nodes.
1678 searchRange->setStart(resultRange->endContainer(exceptionState), resultR ange->endOffset(exceptionState), exceptionState);
1679
1680 Node* shadowTreeRoot = searchRange->shadowRoot();
1681 if (searchRange->collapsed(exceptionState) && shadowTreeRoot)
1682 searchRange->setEnd(shadowTreeRoot, shadowTreeRoot->childNodeCount() , exceptionState);
1683
1684 m_resumeScopingFromRange = resultRange;
1685 timedOut = (currentTime() - startTime) >= maxScopingDuration;
1686 } while (!timedOut);
1687
1688 // Remember what we search for last time, so we can skip searching if more
1689 // letters are added to the search string (and last outcome was 0).
1690 m_lastSearchString = searchText;
1691
1692 if (matchCount > 0) {
1693 frame()->editor().setMarkedTextMatchesAreHighlighted(true);
1694
1695 m_lastMatchCount += matchCount;
1696
1697 // Let the mainframe know how much we found during this pass.
1698 mainFrameImpl->increaseMatchCount(matchCount, identifier);
1699 }
1700
1701 if (timedOut) {
1702 // If we found anything during this pass, we should redraw. However, we
1703 // don't want to spam too much if the page is extremely long, so if we
1704 // reach a certain point we start throttling the redraw requests.
1705 if (matchCount > 0)
1706 invalidateIfNecessary();
1707
1708 // Scoping effort ran out of time, lets ask for another time-slice.
1709 scopeStringMatchesSoon(
1710 identifier,
1711 searchText,
1712 options,
1713 false); // don't reset.
1714 return; // Done for now, resume work later.
1715 }
1716
1717 finishCurrentScopingEffort(identifier);
1718 }
1719
1720 void WebFrameImpl::flushCurrentScopingEffort(int identifier)
1721 {
1722 if (!frame() || !frame()->page())
1723 return;
1724
1725 WebFrameImpl* mainFrameImpl = viewImpl()->mainFrameImpl();
1726
1727 // This frame has no further scoping left, so it is done. Other frames might ,
1728 // of course, continue to scope matches.
1729 mainFrameImpl->m_framesScopingCount--;
1730
1731 // If this is the last frame to finish scoping we need to trigger the final
1732 // update to be sent.
1733 if (!mainFrameImpl->m_framesScopingCount)
1734 mainFrameImpl->increaseMatchCount(0, identifier);
1735 }
1736
1737 void WebFrameImpl::finishCurrentScopingEffort(int identifier)
1738 {
1739 flushCurrentScopingEffort(identifier);
1740
1741 m_scopingInProgress = false;
1742 m_lastFindRequestCompletedWithNoMatches = !m_lastMatchCount;
1743
1744 // This frame is done, so show any scrollbar tickmarks we haven't drawn yet.
1745 invalidateArea(InvalidateScrollbar);
1746 } 1433 }
1747 1434
1748 void WebFrameImpl::cancelPendingScopingEffort() 1435 void WebFrameImpl::cancelPendingScopingEffort()
1749 { 1436 {
1750 deleteAllValues(m_deferredScopingWork); 1437 if (m_textFinder)
1751 m_deferredScopingWork.clear(); 1438 m_textFinder->cancelPendingScopingEffort();
1752
1753 m_activeMatchIndexInCurrentFrame = -1;
1754
1755 // Last request didn't complete.
1756 if (m_scopingInProgress)
1757 m_lastFindRequestCompletedWithNoMatches = false;
1758
1759 m_scopingInProgress = false;
1760 } 1439 }
1761 1440
1762 void WebFrameImpl::increaseMatchCount(int count, int identifier) 1441 void WebFrameImpl::increaseMatchCount(int count, int identifier)
1763 { 1442 {
1764 // This function should only be called on the mainframe. 1443 // This function should only be called on the mainframe.
1765 ASSERT(!parent()); 1444 ASSERT(!parent());
1766 1445 ASSERT(m_textFinder);
1767 if (count) 1446 m_textFinder->increaseMatchCount(identifier, count);
1768 ++m_findMatchMarkersVersion;
1769
1770 m_totalMatchCount += count;
1771
1772 // Update the UI with the latest findings.
1773 if (client())
1774 client()->reportFindInPageMatchCount(identifier, m_totalMatchCount, !m_f ramesScopingCount);
1775 }
1776
1777 void WebFrameImpl::reportFindInPageSelection(const WebRect& selectionRect, int a ctiveMatchOrdinal, int identifier)
1778 {
1779 // Update the UI with the latest selection rect.
1780 if (client())
1781 client()->reportFindInPageSelection(identifier, ordinalOfFirstMatchForFr ame(this) + activeMatchOrdinal, selectionRect);
1782 } 1447 }
1783 1448
1784 void WebFrameImpl::resetMatchCount() 1449 void WebFrameImpl::resetMatchCount()
1785 { 1450 {
1786 if (m_totalMatchCount > 0) 1451 ASSERT(m_textFinder);
1787 ++m_findMatchMarkersVersion; 1452 m_textFinder->resetMatchCount();
1788
1789 m_totalMatchCount = 0;
1790 m_framesScopingCount = 0;
1791 } 1453 }
1792 1454
1793 void WebFrameImpl::sendOrientationChangeEvent(int orientation) 1455 void WebFrameImpl::sendOrientationChangeEvent(int orientation)
1794 { 1456 {
1795 #if ENABLE(ORIENTATION_EVENTS) 1457 #if ENABLE(ORIENTATION_EVENTS)
1796 if (frame()) 1458 if (frame())
1797 frame()->sendOrientationChangeEvent(orientation); 1459 frame()->sendOrientationChangeEvent(orientation);
1798 #endif 1460 #endif
1799 } 1461 }
1800 1462
1801 void WebFrameImpl::dispatchMessageEventWithOriginCheck(const WebSecurityOrigin& intendedTargetOrigin, const WebDOMEvent& event) 1463 void WebFrameImpl::dispatchMessageEventWithOriginCheck(const WebSecurityOrigin& intendedTargetOrigin, const WebDOMEvent& event)
1802 { 1464 {
1803 ASSERT(!event.isNull()); 1465 ASSERT(!event.isNull());
1804 frame()->domWindow()->dispatchMessageEventWithOriginCheck(intendedTargetOrig in.get(), event, 0); 1466 frame()->domWindow()->dispatchMessageEventWithOriginCheck(intendedTargetOrig in.get(), event, 0);
1805 } 1467 }
1806 1468
1807 int WebFrameImpl::findMatchMarkersVersion() const 1469 int WebFrameImpl::findMatchMarkersVersion() const
1808 { 1470 {
1809 ASSERT(!parent()); 1471 ASSERT(!parent());
1810 return m_findMatchMarkersVersion; 1472
1473 return m_textFinder ? m_textFinder->findMatchMarkersVersion() : 0;
1811 } 1474 }
1812 1475
1813 void WebFrameImpl::clearFindMatchesCache() 1476 int WebFrameImpl::selectNearestFindMatch(const WebFloatPoint& point, WebRect* se lectionRect)
1814 { 1477 {
1815 if (!m_findMatchesCache.isEmpty()) 1478 ASSERT(!parent());
1816 viewImpl()->mainFrameImpl()->m_findMatchMarkersVersion++; 1479 ASSERT(m_textFinder);
1817 1480 return m_textFinder->selectNearestFindMatch(point, selectionRect);
1818 m_findMatchesCache.clear();
1819 m_findMatchRectsAreValid = false;
1820 }
1821
1822 bool WebFrameImpl::isActiveMatchFrameValid() const
1823 {
1824 WebFrameImpl* mainFrameImpl = viewImpl()->mainFrameImpl();
1825 WebFrameImpl* activeMatchFrame = mainFrameImpl->activeMatchFrame();
1826 return activeMatchFrame && activeMatchFrame->m_activeMatch && activeMatchFra me->frame()->tree().isDescendantOf(mainFrameImpl->frame());
1827 }
1828
1829 void WebFrameImpl::updateFindMatchRects()
1830 {
1831 IntSize currentContentsSize = contentsSize();
1832 if (m_contentsSizeForCurrentFindMatchRects != currentContentsSize) {
1833 m_contentsSizeForCurrentFindMatchRects = currentContentsSize;
1834 m_findMatchRectsAreValid = false;
1835 }
1836
1837 size_t deadMatches = 0;
1838 for (Vector<FindMatch>::iterator it = m_findMatchesCache.begin(); it != m_fi ndMatchesCache.end(); ++it) {
1839 if (!it->m_range->boundaryPointsValid() || !it->m_range->startContainer( )->inDocument())
1840 it->m_rect = FloatRect();
1841 else if (!m_findMatchRectsAreValid)
1842 it->m_rect = findInPageRectFromRange(it->m_range.get());
1843
1844 if (it->m_rect.isEmpty())
1845 ++deadMatches;
1846 }
1847
1848 // Remove any invalid matches from the cache.
1849 if (deadMatches) {
1850 Vector<FindMatch> filteredMatches;
1851 filteredMatches.reserveCapacity(m_findMatchesCache.size() - deadMatches) ;
1852
1853 for (Vector<FindMatch>::const_iterator it = m_findMatchesCache.begin(); it != m_findMatchesCache.end(); ++it)
1854 if (!it->m_rect.isEmpty())
1855 filteredMatches.append(*it);
1856
1857 m_findMatchesCache.swap(filteredMatches);
1858 }
1859
1860 // Invalidate the rects in child frames. Will be updated later during traver sal.
1861 if (!m_findMatchRectsAreValid)
1862 for (WebFrame* child = firstChild(); child; child = child->nextSibling() )
1863 toWebFrameImpl(child)->m_findMatchRectsAreValid = false;
1864
1865 m_findMatchRectsAreValid = true;
1866 } 1481 }
1867 1482
1868 WebFloatRect WebFrameImpl::activeFindMatchRect() 1483 WebFloatRect WebFrameImpl::activeFindMatchRect()
1869 { 1484 {
1870 ASSERT(!parent()); 1485 ASSERT(!parent());
1486 ASSERT(m_textFinder);
1871 1487
1872 if (!isActiveMatchFrameValid()) 1488 return m_textFinder->activeFindMatchRect();
1873 return WebFloatRect();
1874
1875 return WebFloatRect(findInPageRectFromRange(m_currentActiveMatchFrame->m_act iveMatch.get()));
1876 } 1489 }
1877 1490
1878 void WebFrameImpl::findMatchRects(WebVector<WebFloatRect>& outputRects) 1491 void WebFrameImpl::findMatchRects(WebVector<WebFloatRect>& outputRects)
1879 { 1492 {
1880 ASSERT(!parent()); 1493 ASSERT(!parent());
1881 1494 ASSERT(m_textFinder);
1882 Vector<WebFloatRect> matchRects; 1495 m_textFinder->findMatchRects(outputRects);
1883 for (WebFrameImpl* frame = this; frame; frame = toWebFrameImpl(frame->traver seNext(false)))
1884 frame->appendFindMatchRects(matchRects);
1885
1886 outputRects = matchRects;
1887 }
1888
1889 void WebFrameImpl::appendFindMatchRects(Vector<WebFloatRect>& frameRects)
1890 {
1891 updateFindMatchRects();
1892 frameRects.reserveCapacity(frameRects.size() + m_findMatchesCache.size());
1893 for (Vector<FindMatch>::const_iterator it = m_findMatchesCache.begin(); it ! = m_findMatchesCache.end(); ++it) {
1894 ASSERT(!it->m_rect.isEmpty());
1895 frameRects.append(it->m_rect);
1896 }
1897 }
1898
1899 int WebFrameImpl::selectNearestFindMatch(const WebFloatPoint& point, WebRect* se lectionRect)
1900 {
1901 ASSERT(!parent());
1902
1903 WebFrameImpl* bestFrame = 0;
1904 int indexInBestFrame = -1;
1905 float distanceInBestFrame = FLT_MAX;
1906
1907 for (WebFrameImpl* frame = this; frame; frame = toWebFrameImpl(frame->traver seNext(false))) {
1908 float distanceInFrame;
1909 int indexInFrame = frame->nearestFindMatch(point, distanceInFrame);
1910 if (distanceInFrame < distanceInBestFrame) {
1911 bestFrame = frame;
1912 indexInBestFrame = indexInFrame;
1913 distanceInBestFrame = distanceInFrame;
1914 }
1915 }
1916
1917 if (indexInBestFrame != -1)
1918 return bestFrame->selectFindMatch(static_cast<unsigned>(indexInBestFrame ), selectionRect);
1919
1920 return -1;
1921 }
1922
1923 int WebFrameImpl::nearestFindMatch(const FloatPoint& point, float& distanceSquar ed)
1924 {
1925 updateFindMatchRects();
1926
1927 int nearest = -1;
1928 distanceSquared = FLT_MAX;
1929 for (size_t i = 0; i < m_findMatchesCache.size(); ++i) {
1930 ASSERT(!m_findMatchesCache[i].m_rect.isEmpty());
1931 FloatSize offset = point - m_findMatchesCache[i].m_rect.center();
1932 float width = offset.width();
1933 float height = offset.height();
1934 float currentDistanceSquared = width * width + height * height;
1935 if (currentDistanceSquared < distanceSquared) {
1936 nearest = i;
1937 distanceSquared = currentDistanceSquared;
1938 }
1939 }
1940 return nearest;
1941 }
1942
1943 int WebFrameImpl::selectFindMatch(unsigned index, WebRect* selectionRect)
1944 {
1945 ASSERT_WITH_SECURITY_IMPLICATION(index < m_findMatchesCache.size());
1946
1947 RefPtr<Range> range = m_findMatchesCache[index].m_range;
1948 if (!range->boundaryPointsValid() || !range->startContainer()->inDocument())
1949 return -1;
1950
1951 // Check if the match is already selected.
1952 WebFrameImpl* activeMatchFrame = viewImpl()->mainFrameImpl()->m_currentActiv eMatchFrame;
1953 if (this != activeMatchFrame || !m_activeMatch || !areRangesEqual(m_activeMa tch.get(), range.get())) {
1954 if (isActiveMatchFrameValid())
1955 activeMatchFrame->setMarkerActive(activeMatchFrame->m_activeMatch.ge t(), false);
1956
1957 m_activeMatchIndexInCurrentFrame = m_findMatchesCache[index].m_ordinal - 1;
1958
1959 // Set this frame as the active frame (the one with the active highlight ).
1960 viewImpl()->mainFrameImpl()->m_currentActiveMatchFrame = this;
1961 viewImpl()->setFocusedFrame(this);
1962
1963 m_activeMatch = range.release();
1964 setMarkerActive(m_activeMatch.get(), true);
1965
1966 // Clear any user selection, to make sure Find Next continues on from th e match we just activated.
1967 frame()->selection().clear();
1968
1969 // Make sure no node is focused. See http://crbug.com/38700.
1970 frame()->document()->setFocusedElement(0);
1971 }
1972
1973 IntRect activeMatchRect;
1974 IntRect activeMatchBoundingBox = enclosingIntRect(RenderObject::absoluteBoun dingBoxRectForRange(m_activeMatch.get()));
1975
1976 if (!activeMatchBoundingBox.isEmpty()) {
1977 if (m_activeMatch->firstNode() && m_activeMatch->firstNode()->renderer() )
1978 m_activeMatch->firstNode()->renderer()->scrollRectToVisible(activeMa tchBoundingBox,
1979 ScrollAlignment::alignCenterIfNeeded, ScrollAlignment::align CenterIfNeeded);
1980
1981 // Zoom to the active match.
1982 activeMatchRect = frameView()->contentsToWindow(activeMatchBoundingBox);
1983 viewImpl()->zoomToFindInPageRect(activeMatchRect);
1984 }
1985
1986 if (selectionRect)
1987 *selectionRect = activeMatchRect;
1988
1989 return ordinalOfFirstMatchForFrame(this) + m_activeMatchIndexInCurrentFrame + 1;
1990 } 1496 }
1991 1497
1992 WebString WebFrameImpl::contentAsText(size_t maxChars) const 1498 WebString WebFrameImpl::contentAsText(size_t maxChars) const
1993 { 1499 {
1994 if (!frame()) 1500 if (!frame())
1995 return WebString(); 1501 return WebString();
1996 StringBuilder text; 1502 StringBuilder text;
1997 frameContentAsPlainText(maxChars, frame(), text); 1503 frameContentAsPlainText(maxChars, frame(), text);
1998 return text.toString(); 1504 return text.toString();
1999 } 1505 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2079 1585
2080 WebFrameImpl* WebFrameImpl::create(WebFrameClient* client, long long embedderIde ntifier) 1586 WebFrameImpl* WebFrameImpl::create(WebFrameClient* client, long long embedderIde ntifier)
2081 { 1587 {
2082 return adoptRef(new WebFrameImpl(client, embedderIdentifier)).leakRef(); 1588 return adoptRef(new WebFrameImpl(client, embedderIdentifier)).leakRef();
2083 } 1589 }
2084 1590
2085 WebFrameImpl::WebFrameImpl(WebFrameClient* client, long long embedderIdentifier) 1591 WebFrameImpl::WebFrameImpl(WebFrameClient* client, long long embedderIdentifier)
2086 : FrameDestructionObserver(0) 1592 : FrameDestructionObserver(0)
2087 , m_frameInit(WebFrameInit::create(this, embedderIdentifier)) 1593 , m_frameInit(WebFrameInit::create(this, embedderIdentifier))
2088 , m_client(client) 1594 , m_client(client)
2089 , m_currentActiveMatchFrame(0)
2090 , m_activeMatchIndexInCurrentFrame(-1)
2091 , m_locatingActiveRect(false)
2092 , m_resumeScopingFromRange(0)
2093 , m_lastMatchCount(-1)
2094 , m_totalMatchCount(-1)
2095 , m_framesScopingCount(-1)
2096 , m_findRequestIdentifier(-1)
2097 , m_scopingInProgress(false)
2098 , m_lastFindRequestCompletedWithNoMatches(false)
2099 , m_nextInvalidateAfter(0)
2100 , m_findMatchMarkersVersion(0)
2101 , m_findMatchRectsAreValid(false)
2102 , m_inputEventsScaleFactorForEmulation(1) 1595 , m_inputEventsScaleFactorForEmulation(1)
2103 { 1596 {
2104 blink::Platform::current()->incrementStatsCounter(webFrameActiveCount); 1597 blink::Platform::current()->incrementStatsCounter(webFrameActiveCount);
2105 frameCount++; 1598 frameCount++;
2106 } 1599 }
2107 1600
2108 WebFrameImpl::~WebFrameImpl() 1601 WebFrameImpl::~WebFrameImpl()
2109 { 1602 {
2110 blink::Platform::current()->decrementStatsCounter(webFrameActiveCount); 1603 blink::Platform::current()->decrementStatsCounter(webFrameActiveCount);
2111 frameCount--; 1604 frameCount--;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2200 // NOTE: m_client will be null if this frame has been detached. 1693 // NOTE: m_client will be null if this frame has been detached.
2201 if (!childFrame->tree().parent()) 1694 if (!childFrame->tree().parent())
2202 return 0; 1695 return 0;
2203 1696
2204 return childFrame.release(); 1697 return childFrame.release();
2205 } 1698 }
2206 1699
2207 void WebFrameImpl::didChangeContentsSize(const IntSize& size) 1700 void WebFrameImpl::didChangeContentsSize(const IntSize& size)
2208 { 1701 {
2209 // This is only possible on the main frame. 1702 // This is only possible on the main frame.
2210 if (m_totalMatchCount > 0) { 1703 if (m_textFinder && m_textFinder->totalMatchCount() > 0) {
2211 ASSERT(!parent()); 1704 ASSERT(!parent());
2212 ++m_findMatchMarkersVersion; 1705 m_textFinder->increaseMarkerVersion();
2213 } 1706 }
2214 } 1707 }
2215 1708
2216 void WebFrameImpl::createFrameView() 1709 void WebFrameImpl::createFrameView()
2217 { 1710 {
2218 TRACE_EVENT0("webkit", "WebFrameImpl::createFrameView"); 1711 TRACE_EVENT0("webkit", "WebFrameImpl::createFrameView");
2219 1712
2220 ASSERT(frame()); // If frame() doesn't exist, we probably didn't init proper ly. 1713 ASSERT(frame()); // If frame() doesn't exist, we probably didn't init proper ly.
2221 1714
2222 WebViewImpl* webView = viewImpl(); 1715 WebViewImpl* webView = viewImpl();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 1756
2264 WebDataSourceImpl* WebFrameImpl::provisionalDataSourceImpl() const 1757 WebDataSourceImpl* WebFrameImpl::provisionalDataSourceImpl() const
2265 { 1758 {
2266 return static_cast<WebDataSourceImpl*>(provisionalDataSource()); 1759 return static_cast<WebDataSourceImpl*>(provisionalDataSource());
2267 } 1760 }
2268 1761
2269 void WebFrameImpl::setFindEndstateFocusAndSelection() 1762 void WebFrameImpl::setFindEndstateFocusAndSelection()
2270 { 1763 {
2271 WebFrameImpl* mainFrameImpl = viewImpl()->mainFrameImpl(); 1764 WebFrameImpl* mainFrameImpl = viewImpl()->mainFrameImpl();
2272 1765
2273 if (this == mainFrameImpl->activeMatchFrame() && m_activeMatch.get()) { 1766 if (this == mainFrameImpl->activeMatchFrame() && m_textFinder->activeMatch() ) {
1767 Range* activeMatch = m_textFinder->activeMatch();
2274 // If the user has set the selection since the match was found, we 1768 // If the user has set the selection since the match was found, we
2275 // don't focus anything. 1769 // don't focus anything.
2276 VisibleSelection selection(frame()->selection().selection()); 1770 VisibleSelection selection(frame()->selection().selection());
2277 if (!selection.isNone()) 1771 if (!selection.isNone())
2278 return; 1772 return;
2279 1773
2280 // Try to find the first focusable node up the chain, which will, for 1774 // Try to find the first focusable node up the chain, which will, for
2281 // example, focus links if we have found text within the link. 1775 // example, focus links if we have found text within the link.
2282 Node* node = m_activeMatch->firstNode(); 1776 Node* node = activeMatch->firstNode();
2283 if (node && node->isInShadowTree()) { 1777 if (node && node->isInShadowTree()) {
2284 Node* host = node->deprecatedShadowAncestorNode(); 1778 Node* host = node->deprecatedShadowAncestorNode();
2285 if (host->hasTagName(HTMLNames::inputTag) || isHTMLTextAreaElement(h ost)) 1779 if (host->hasTagName(HTMLNames::inputTag) || isHTMLTextAreaElement(h ost))
2286 node = host; 1780 node = host;
2287 } 1781 }
2288 for (; node; node = node->parentNode()) { 1782 for (; node; node = node->parentNode()) {
2289 if (!node->isElementNode()) 1783 if (!node->isElementNode())
2290 continue; 1784 continue;
2291 Element* element = toElement(node); 1785 Element* element = toElement(node);
2292 if (element->isFocusable()) { 1786 if (element->isFocusable()) {
2293 // Found a focusable parent node. Set the active match as the 1787 // Found a focusable parent node. Set the active match as the
2294 // selection and focus to the focusable node. 1788 // selection and focus to the focusable node.
2295 frame()->selection().setSelection(m_activeMatch.get()); 1789 frame()->selection().setSelection(activeMatch);
2296 frame()->document()->setFocusedElement(element); 1790 frame()->document()->setFocusedElement(element);
2297 return; 1791 return;
2298 } 1792 }
2299 } 1793 }
2300 1794
2301 // Iterate over all the nodes in the range until we find a focusable nod e. 1795 // Iterate over all the nodes in the range until we find a focusable nod e.
2302 // This, for example, sets focus to the first link if you search for 1796 // This, for example, sets focus to the first link if you search for
2303 // text and text that is within one or more links. 1797 // text and text that is within one or more links.
2304 node = m_activeMatch->firstNode(); 1798 node = activeMatch->firstNode();
2305 for (; node && node != m_activeMatch->pastLastNode(); node = NodeTravers al::next(*node)) { 1799 for (; node && node != activeMatch->pastLastNode(); node = NodeTraversal ::next(*node)) {
2306 if (!node->isElementNode()) 1800 if (!node->isElementNode())
2307 continue; 1801 continue;
2308 Element* element = toElement(node); 1802 Element* element = toElement(node);
2309 if (element->isFocusable()) { 1803 if (element->isFocusable()) {
2310 frame()->document()->setFocusedElement(element); 1804 frame()->document()->setFocusedElement(element);
2311 return; 1805 return;
2312 } 1806 }
2313 } 1807 }
2314 1808
2315 // No node related to the active match was focusable, so set the 1809 // No node related to the active match was focusable, so set the
2316 // active match as the selection (so that when you end the Find session, 1810 // active match as the selection (so that when you end the Find session,
2317 // you'll have the last thing you found highlighted) and make sure that 1811 // you'll have the last thing you found highlighted) and make sure that
2318 // we have nothing focused (otherwise you might have text selected but 1812 // we have nothing focused (otherwise you might have text selected but
2319 // a link focused, which is weird). 1813 // a link focused, which is weird).
2320 frame()->selection().setSelection(m_activeMatch.get()); 1814 frame()->selection().setSelection(activeMatch);
2321 frame()->document()->setFocusedElement(0); 1815 frame()->document()->setFocusedElement(0);
2322 1816
2323 // Finally clear the active match, for two reasons: 1817 // Finally clear the active match, for two reasons:
2324 // We just finished the find 'session' and we don't want future (potenti ally 1818 // We just finished the find 'session' and we don't want future (potenti ally
2325 // unrelated) find 'sessions' operations to start at the same place. 1819 // unrelated) find 'sessions' operations to start at the same place.
2326 // The WebFrameImpl could get reused and the m_activeMatch could end up pointing 1820 // The WebFrameImpl could get reused and the activeMatch could end up po inting
2327 // to a document that is no longer valid. Keeping an invalid reference a round 1821 // to a document that is no longer valid. Keeping an invalid reference a round
2328 // is just asking for trouble. 1822 // is just asking for trouble.
2329 m_activeMatch = 0; 1823 m_textFinder->resetActiveMatch();
2330 } 1824 }
2331 } 1825 }
2332 1826
2333 void WebFrameImpl::didFail(const ResourceError& error, bool wasProvisional) 1827 void WebFrameImpl::didFail(const ResourceError& error, bool wasProvisional)
2334 { 1828 {
2335 if (!client()) 1829 if (!client())
2336 return; 1830 return;
2337 WebURLError webError = error; 1831 WebURLError webError = error;
2338 if (wasProvisional) 1832 if (wasProvisional)
2339 client()->didFailProvisionalLoad(this, webError); 1833 client()->didFailProvisionalLoad(this, webError);
2340 else 1834 else
2341 client()->didFailLoad(this, webError); 1835 client()->didFailLoad(this, webError);
2342 } 1836 }
2343 1837
2344 void WebFrameImpl::setCanHaveScrollbars(bool canHaveScrollbars) 1838 void WebFrameImpl::setCanHaveScrollbars(bool canHaveScrollbars)
2345 { 1839 {
2346 frame()->view()->setCanHaveScrollbars(canHaveScrollbars); 1840 frame()->view()->setCanHaveScrollbars(canHaveScrollbars);
2347 } 1841 }
2348 1842
2349 void WebFrameImpl::setInputEventsTransformForEmulation(const IntSize& offset, fl oat contentScaleFactor) 1843 void WebFrameImpl::setInputEventsTransformForEmulation(const IntSize& offset, fl oat contentScaleFactor)
2350 { 1844 {
2351 m_inputEventsOffsetForEmulation = offset; 1845 m_inputEventsOffsetForEmulation = offset;
2352 m_inputEventsScaleFactorForEmulation = contentScaleFactor; 1846 m_inputEventsScaleFactorForEmulation = contentScaleFactor;
2353 if (frame()->view()) 1847 if (frame()->view())
2354 frame()->view()->setInputEventsTransformForEmulation(m_inputEventsOffset ForEmulation, m_inputEventsScaleFactorForEmulation); 1848 frame()->view()->setInputEventsTransformForEmulation(m_inputEventsOffset ForEmulation, m_inputEventsScaleFactorForEmulation);
2355 } 1849 }
2356 1850
2357 void WebFrameImpl::invalidateArea(AreaToInvalidate area)
2358 {
2359 ASSERT(frame() && frame()->view());
2360 FrameView* view = frame()->view();
2361
2362 if ((area & InvalidateAll) == InvalidateAll)
2363 view->invalidateRect(view->frameRect());
2364 else {
2365 if ((area & InvalidateContentArea) == InvalidateContentArea) {
2366 IntRect contentArea(
2367 view->x(), view->y(), view->visibleWidth(), view->visibleHeight( ));
2368 IntRect frameRect = view->frameRect();
2369 contentArea.move(-frameRect.x(), -frameRect.y());
2370 view->invalidateRect(contentArea);
2371 }
2372 }
2373
2374 if ((area & InvalidateScrollbar) == InvalidateScrollbar) {
2375 // Invalidate the vertical scroll bar region for the view.
2376 Scrollbar* scrollbar = view->verticalScrollbar();
2377 if (scrollbar)
2378 scrollbar->invalidate();
2379 }
2380 }
2381
2382 void WebFrameImpl::addMarker(Range* range, bool activeMatch)
2383 {
2384 frame()->document()->markers()->addTextMatchMarker(range, activeMatch);
2385 }
2386
2387 void WebFrameImpl::setMarkerActive(Range* range, bool active)
2388 {
2389 if (!range || range->collapsed(IGNORE_EXCEPTION))
2390 return;
2391 frame()->document()->markers()->setMarkersActive(range, active);
2392 }
2393
2394 int WebFrameImpl::ordinalOfFirstMatchForFrame(WebFrameImpl* frame) const
2395 {
2396 int ordinal = 0;
2397 WebFrameImpl* mainFrameImpl = viewImpl()->mainFrameImpl();
2398 // Iterate from the main frame up to (but not including) |frame| and
2399 // add up the number of matches found so far.
2400 for (WebFrameImpl* it = mainFrameImpl; it != frame; it = toWebFrameImpl(it-> traverseNext(true))) {
2401 if (it->m_lastMatchCount > 0)
2402 ordinal += it->m_lastMatchCount;
2403 }
2404 return ordinal;
2405 }
2406
2407 bool WebFrameImpl::shouldScopeMatches(const String& searchText)
2408 {
2409 // Don't scope if we can't find a frame or a view.
2410 // The user may have closed the tab/application, so abort.
2411 // Also ignore detached frames, as many find operations report to the main f rame.
2412 if (!frame() || !frame()->view() || !frame()->page() || !hasVisibleContent() )
2413 return false;
2414
2415 ASSERT(frame()->document() && frame()->view());
2416
2417 // If the frame completed the scoping operation and found 0 matches the last
2418 // time it was searched, then we don't have to search it again if the user i s
2419 // just adding to the search string or sending the same search string again.
2420 if (m_lastFindRequestCompletedWithNoMatches && !m_lastSearchString.isEmpty() ) {
2421 // Check to see if the search string prefixes match.
2422 String previousSearchPrefix =
2423 searchText.substring(0, m_lastSearchString.length());
2424
2425 if (previousSearchPrefix == m_lastSearchString)
2426 return false; // Don't search this frame, it will be fruitless.
2427 }
2428
2429 return true;
2430 }
2431
2432 void WebFrameImpl::scopeStringMatchesSoon(int identifier, const WebString& searc hText, const WebFindOptions& options, bool reset)
2433 {
2434 m_deferredScopingWork.append(new DeferredScopeStringMatches(this, identifier , searchText, options, reset));
2435 }
2436
2437 void WebFrameImpl::callScopeStringMatches(DeferredScopeStringMatches* caller, in t identifier, const WebString& searchText, const WebFindOptions& options, bool r eset)
2438 {
2439 m_deferredScopingWork.remove(m_deferredScopingWork.find(caller));
2440 scopeStringMatches(identifier, searchText, options, reset);
2441
2442 // This needs to happen last since searchText is passed by reference.
2443 delete caller;
2444 }
2445
2446 void WebFrameImpl::invalidateIfNecessary()
2447 {
2448 if (m_lastMatchCount <= m_nextInvalidateAfter)
2449 return;
2450
2451 // FIXME: (http://b/1088165) Optimize the drawing of the tickmarks and
2452 // remove this. This calculation sets a milestone for when next to
2453 // invalidate the scrollbar and the content area. We do this so that we
2454 // don't spend too much time drawing the scrollbar over and over again.
2455 // Basically, up until the first 500 matches there is no throttle.
2456 // After the first 500 matches, we set set the milestone further and
2457 // further out (750, 1125, 1688, 2K, 3K).
2458 static const int startSlowingDownAfter = 500;
2459 static const int slowdown = 750;
2460
2461 int i = m_lastMatchCount / startSlowingDownAfter;
2462 m_nextInvalidateAfter += i * slowdown;
2463 invalidateArea(InvalidateScrollbar);
2464 }
2465
2466 void WebFrameImpl::loadJavaScriptURL(const KURL& url) 1851 void WebFrameImpl::loadJavaScriptURL(const KURL& url)
2467 { 1852 {
2468 // This is copied from ScriptController::executeScriptIfJavaScriptURL. 1853 // This is copied from ScriptController::executeScriptIfJavaScriptURL.
2469 // Unfortunately, we cannot just use that method since it is private, and 1854 // Unfortunately, we cannot just use that method since it is private, and
2470 // it also doesn't quite behave as we require it to for bookmarklets. The 1855 // it also doesn't quite behave as we require it to for bookmarklets. The
2471 // key difference is that we need to suppress loading the string result 1856 // key difference is that we need to suppress loading the string result
2472 // from evaluating the JS URL if executing the JS URL resulted in a 1857 // from evaluating the JS URL if executing the JS URL resulted in a
2473 // location change. We also allow a JS URL to be loaded even if scripts on 1858 // location change. We also allow a JS URL to be loaded even if scripts on
2474 // the page are otherwise disabled. 1859 // the page are otherwise disabled.
2475 1860
(...skipping 18 matching lines...) Expand all
2494 frame()->document()->loader()->replaceDocument(scriptResult, ownerDocume nt.get()); 1879 frame()->document()->loader()->replaceDocument(scriptResult, ownerDocume nt.get());
2495 } 1880 }
2496 1881
2497 void WebFrameImpl::willDetachPage() 1882 void WebFrameImpl::willDetachPage()
2498 { 1883 {
2499 if (!frame() || !frame()->page()) 1884 if (!frame() || !frame()->page())
2500 return; 1885 return;
2501 1886
2502 // Do not expect string scoping results from any frames that got detached 1887 // Do not expect string scoping results from any frames that got detached
2503 // in the middle of the operation. 1888 // in the middle of the operation.
2504 if (m_scopingInProgress) { 1889 if (m_textFinder && m_textFinder->scopingInProgress()) {
2505 1890
2506 // There is a possibility that the frame being detached was the only 1891 // There is a possibility that the frame being detached was the only
2507 // pending one. We need to make sure final replies can be sent. 1892 // pending one. We need to make sure final replies can be sent.
2508 flushCurrentScopingEffort(m_findRequestIdentifier); 1893 m_textFinder->flushCurrentScoping();
2509 1894
2510 cancelPendingScopingEffort(); 1895 m_textFinder->cancelPendingScopingEffort();
2511 } 1896 }
2512 } 1897 }
2513 1898
1899 WebFrameImpl* WebFrameImpl::activeMatchFrame() const
1900 {
1901 ASSERT(!parent());
1902 ASSERT(m_textFinder);
1903 return m_textFinder->activeMatchFrame();
1904 }
1905
1906 WebCore::Range* WebFrameImpl::activeMatch() const
1907 {
1908 ASSERT(m_textFinder);
1909 return m_textFinder->activeMatch();
1910 }
1911
1912 TextFinder* WebFrameImpl::getOrCreateTextFinder()
1913 {
1914 if (!m_textFinder)
1915 m_textFinder = TextFinder::create(this);
1916
1917 return m_textFinder.get();
1918 }
1919
2514 } // namespace blink 1920 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebFrameImpl.h ('k') | Source/web/web.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698