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

Side by Side Diff: third_party/WebKit/Source/web/WebLocalFrameImpl.cpp

Issue 1959183002: Multi-Process Find-in-Page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased and made WebLocalFrame::isFocused() private. Created 4 years, 7 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) 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 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 m_sharedWorkerRepositoryClient = SharedWorkerRepositoryClientImpl::create(cl ient); 615 m_sharedWorkerRepositoryClient = SharedWorkerRepositoryClientImpl::create(cl ient);
616 } 616 }
617 617
618 ScrollableArea* WebLocalFrameImpl::layoutViewportScrollableArea() const 618 ScrollableArea* WebLocalFrameImpl::layoutViewportScrollableArea() const
619 { 619 {
620 if (FrameView* view = frameView()) 620 if (FrameView* view = frameView())
621 return view->layoutViewportScrollableArea(); 621 return view->layoutViewportScrollableArea();
622 return nullptr; 622 return nullptr;
623 } 623 }
624 624
625 bool WebLocalFrameImpl::isFocused() const
626 {
627 return this == WebFrame::fromFrame(viewImpl()->page()->focusController().foc usedFrame());
628 }
629
625 WebSize WebLocalFrameImpl::scrollOffset() const 630 WebSize WebLocalFrameImpl::scrollOffset() const
626 { 631 {
627 if (ScrollableArea* scrollableArea = layoutViewportScrollableArea()) 632 if (ScrollableArea* scrollableArea = layoutViewportScrollableArea())
628 return toIntSize(scrollableArea->scrollPosition()); 633 return toIntSize(scrollableArea->scrollPosition());
629 return WebSize(); 634 return WebSize();
630 } 635 }
631 636
632 void WebLocalFrameImpl::setScrollOffset(const WebSize& offset) 637 void WebLocalFrameImpl::setScrollOffset(const WebSize& offset)
633 { 638 {
634 if (ScrollableArea* scrollableArea = layoutViewportScrollableArea()) 639 if (ScrollableArea* scrollableArea = layoutViewportScrollableArea())
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 // Note a synchronous navigation (about:blank) would have already processed 1551 // Note a synchronous navigation (about:blank) would have already processed
1547 // onload, so it is possible for the child frame to have already been 1552 // onload, so it is possible for the child frame to have already been
1548 // detached by script in the page. 1553 // detached by script in the page.
1549 if (!webframeChild->parent()) 1554 if (!webframeChild->parent())
1550 return nullptr; 1555 return nullptr;
1551 return webframeChild->frame(); 1556 return webframeChild->frame();
1552 } 1557 }
1553 1558
1554 void WebLocalFrameImpl::didChangeContentsSize(const IntSize& size) 1559 void WebLocalFrameImpl::didChangeContentsSize(const IntSize& size)
1555 { 1560 {
1556 // This is only possible on the main frame. 1561 if (m_textFinder && m_textFinder->totalMatchCount() > 0)
1557 if (m_textFinder && m_textFinder->totalMatchCount() > 0) {
1558 DCHECK(!parent());
1559 m_textFinder->increaseMarkerVersion(); 1562 m_textFinder->increaseMarkerVersion();
1560 }
1561 } 1563 }
1562 1564
1563 void WebLocalFrameImpl::createFrameView() 1565 void WebLocalFrameImpl::createFrameView()
1564 { 1566 {
1565 TRACE_EVENT0("blink", "WebLocalFrameImpl::createFrameView"); 1567 TRACE_EVENT0("blink", "WebLocalFrameImpl::createFrameView");
1566 1568
1567 DCHECK(frame()); // If frame() doesn't exist, we probably didn't init proper ly. 1569 DCHECK(frame()); // If frame() doesn't exist, we probably didn't init proper ly.
1568 1570
1569 WebViewImpl* webView = viewImpl(); 1571 WebViewImpl* webView = viewImpl();
1570 1572
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 return static_cast<WebDataSourceImpl*>(dataSource()); 1620 return static_cast<WebDataSourceImpl*>(dataSource());
1619 } 1621 }
1620 1622
1621 WebDataSourceImpl* WebLocalFrameImpl::provisionalDataSourceImpl() const 1623 WebDataSourceImpl* WebLocalFrameImpl::provisionalDataSourceImpl() const
1622 { 1624 {
1623 return static_cast<WebDataSourceImpl*>(provisionalDataSource()); 1625 return static_cast<WebDataSourceImpl*>(provisionalDataSource());
1624 } 1626 }
1625 1627
1626 void WebLocalFrameImpl::setFindEndstateFocusAndSelection() 1628 void WebLocalFrameImpl::setFindEndstateFocusAndSelection()
1627 { 1629 {
1628 WebLocalFrameImpl* mainFrameImpl = viewImpl()->mainFrameImpl(); 1630 if (!m_textFinder || !m_textFinder->activeMatchFrame())
1629
1630 // Main frame should already have a textFinder at this point of time.
1631 DCHECK(mainFrameImpl->textFinder());
1632
1633 if (this != mainFrameImpl->textFinder()->activeMatchFrame())
1634 return; 1631 return;
1635 1632
1636 if (Range* activeMatch = m_textFinder->activeMatch()) { 1633 if (Range* activeMatch = m_textFinder->activeMatch()) {
1637 // If the user has set the selection since the match was found, we 1634 // If the user has set the selection since the match was found, we
1638 // don't focus anything. 1635 // don't focus anything.
1639 VisibleSelection selection(frame()->selection().selection()); 1636 VisibleSelection selection(frame()->selection().selection());
1640 if (!selection.isNone()) 1637 if (!selection.isNone())
1641 return; 1638 return;
1642 1639
1643 // Need to clean out style and layout state before querying Element::isF ocusable(). 1640 // Need to clean out style and layout state before querying Element::isF ocusable().
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1969 UseCounter::count(frame(), UseCounter::ExternalAddSearchProvider); 1966 UseCounter::count(frame(), UseCounter::ExternalAddSearchProvider);
1970 } 1967 }
1971 1968
1972 void WebLocalFrameImpl::didCallIsSearchProviderInstalled() 1969 void WebLocalFrameImpl::didCallIsSearchProviderInstalled()
1973 { 1970 {
1974 UseCounter::count(frame(), UseCounter::ExternalIsSearchProviderInstalled); 1971 UseCounter::count(frame(), UseCounter::ExternalIsSearchProviderInstalled);
1975 } 1972 }
1976 1973
1977 bool WebLocalFrameImpl::find(int identifier, const WebString& searchText, const WebFindOptions& options, bool wrapWithinFrame, WebRect* selectionRect, bool* act iveNow) 1974 bool WebLocalFrameImpl::find(int identifier, const WebString& searchText, const WebFindOptions& options, bool wrapWithinFrame, WebRect* selectionRect, bool* act iveNow)
1978 { 1975 {
1979 return ensureTextFinder().find(identifier, searchText, options, wrapWithinFr ame, selectionRect, activeNow); 1976 // Search for an active match only if this frame is focused or if this is a
1977 // find next request.
1978 if (isFocused() || options.findNext)
1979 return ensureTextFinder().find(identifier, searchText, options, wrapWith inFrame, selectionRect, activeNow);
1980
1981 return false;
1980 } 1982 }
1981 1983
1982 void WebLocalFrameImpl::stopFinding(bool clearSelection) 1984 void WebLocalFrameImpl::stopFinding(bool clearSelection, bool activateSelection)
1983 { 1985 {
1986 // The selection cannot be both cleared and activated.
1987 DCHECK(!(clearSelection && activateSelection));
1988
1989 if (clearSelection)
1990 executeCommand(WebString::fromUTF8("Unselect"));
1991
1984 if (m_textFinder) { 1992 if (m_textFinder) {
1985 if (!clearSelection) 1993 if (!clearSelection)
1986 setFindEndstateFocusAndSelection(); 1994 setFindEndstateFocusAndSelection();
1987 m_textFinder->stopFindingAndClearSelection(); 1995 m_textFinder->stopFindingAndClearSelection();
1988 } 1996 }
1997
1998 if (activateSelection && isFocused()) {
1999 WebDocument doc = document();
2000 if (!doc.isNull()) {
2001 WebElement element = doc.focusedElement();
2002 if (!element.isNull())
2003 element.simulateClick();
2004 }
2005 }
1989 } 2006 }
1990 2007
1991 void WebLocalFrameImpl::scopeStringMatches(int identifier, const WebString& sear chText, const WebFindOptions& options, bool reset) 2008 void WebLocalFrameImpl::scopeStringMatches(int identifier, const WebString& sear chText, const WebFindOptions& options, bool reset)
1992 { 2009 {
1993 ensureTextFinder().scopeStringMatches(identifier, searchText, options, reset ); 2010 ensureTextFinder().scopeStringMatches(identifier, searchText, options, reset );
1994 } 2011 }
1995 2012
1996 void WebLocalFrameImpl::cancelPendingScopingEffort() 2013 void WebLocalFrameImpl::cancelPendingScopingEffort()
1997 { 2014 {
1998 if (m_textFinder) 2015 if (m_textFinder)
1999 m_textFinder->cancelPendingScopingEffort(); 2016 m_textFinder->cancelPendingScopingEffort();
2000 } 2017 }
2001 2018
2002 void WebLocalFrameImpl::increaseMatchCount(int count, int identifier) 2019 void WebLocalFrameImpl::increaseMatchCount(int count, int identifier)
2003 { 2020 {
2004 // This function should only be called on the mainframe.
2005 DCHECK(!parent());
2006 ensureTextFinder().increaseMatchCount(identifier, count); 2021 ensureTextFinder().increaseMatchCount(identifier, count);
2007 } 2022 }
2008 2023
2009 void WebLocalFrameImpl::resetMatchCount() 2024 void WebLocalFrameImpl::resetMatchCount()
2010 { 2025 {
2011 ensureTextFinder().resetMatchCount(); 2026 ensureTextFinder().resetMatchCount();
2012 } 2027 }
2013 2028
2014 void WebLocalFrameImpl::dispatchMessageEventWithOriginCheck(const WebSecurityOri gin& intendedTargetOrigin, const WebDOMEvent& event) 2029 void WebLocalFrameImpl::dispatchMessageEventWithOriginCheck(const WebSecurityOri gin& intendedTargetOrigin, const WebDOMEvent& event)
2015 { 2030 {
2016 DCHECK(!event.isNull()); 2031 DCHECK(!event.isNull());
2017 frame()->localDOMWindow()->dispatchMessageEventWithOriginCheck(intendedTarge tOrigin.get(), event, nullptr); 2032 frame()->localDOMWindow()->dispatchMessageEventWithOriginCheck(intendedTarge tOrigin.get(), event, nullptr);
2018 } 2033 }
2019 2034
2020 int WebLocalFrameImpl::findMatchMarkersVersion() const 2035 int WebLocalFrameImpl::findMatchMarkersVersion() const
2021 { 2036 {
2022 DCHECK(!parent());
2023
2024 if (m_textFinder) 2037 if (m_textFinder)
2025 return m_textFinder->findMatchMarkersVersion(); 2038 return m_textFinder->findMatchMarkersVersion();
2026 return 0; 2039 return 0;
2027 } 2040 }
2028 2041
2029 int WebLocalFrameImpl::selectNearestFindMatch(const WebFloatPoint& point, WebRec t* selectionRect) 2042 int WebLocalFrameImpl::selectNearestFindMatch(const WebFloatPoint& point, WebRec t* selectionRect)
2030 { 2043 {
2031 DCHECK(!parent());
2032 return ensureTextFinder().selectNearestFindMatch(point, selectionRect); 2044 return ensureTextFinder().selectNearestFindMatch(point, selectionRect);
2033 } 2045 }
2034 2046
2047 float WebLocalFrameImpl::nearestFindMatch(const WebFloatPoint& point)
2048 {
2049 float nearestDistance;
2050 ensureTextFinder().nearestFindMatch(point, &nearestDistance);
2051 return nearestDistance;
2052 }
2053
2035 WebFloatRect WebLocalFrameImpl::activeFindMatchRect() 2054 WebFloatRect WebLocalFrameImpl::activeFindMatchRect()
2036 { 2055 {
2037 DCHECK(!parent());
2038
2039 if (m_textFinder) 2056 if (m_textFinder)
2040 return m_textFinder->activeFindMatchRect(); 2057 return m_textFinder->activeFindMatchRect();
2041 return WebFloatRect(); 2058 return WebFloatRect();
2042 } 2059 }
2043 2060
2044 void WebLocalFrameImpl::findMatchRects(WebVector<WebFloatRect>& outputRects) 2061 void WebLocalFrameImpl::findMatchRects(WebVector<WebFloatRect>& outputRects)
2045 { 2062 {
2046 DCHECK(!parent());
2047 ensureTextFinder().findMatchRects(outputRects); 2063 ensureTextFinder().findMatchRects(outputRects);
2048 } 2064 }
2049 2065
2050 void WebLocalFrameImpl::setTickmarks(const WebVector<WebRect>& tickmarks) 2066 void WebLocalFrameImpl::setTickmarks(const WebVector<WebRect>& tickmarks)
2051 { 2067 {
2052 if (frameView()) { 2068 if (frameView()) {
2053 Vector<IntRect> tickmarksConverted(tickmarks.size()); 2069 Vector<IntRect> tickmarksConverted(tickmarks.size());
2054 for (size_t i = 0; i < tickmarks.size(); ++i) 2070 for (size_t i = 0; i < tickmarks.size(); ++i)
2055 tickmarksConverted[i] = tickmarks[i]; 2071 tickmarksConverted[i] = tickmarks[i];
2056 frameView()->setTickmarks(tickmarksConverted); 2072 frameView()->setTickmarks(tickmarksConverted);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 if (!frame()) 2121 if (!frame())
2106 return WebSandboxFlags::None; 2122 return WebSandboxFlags::None;
2107 return static_cast<WebSandboxFlags>(frame()->loader().effectiveSandboxFlags( )); 2123 return static_cast<WebSandboxFlags>(frame()->loader().effectiveSandboxFlags( ));
2108 } 2124 }
2109 2125
2110 void WebLocalFrameImpl::forceSandboxFlags(WebSandboxFlags flags) 2126 void WebLocalFrameImpl::forceSandboxFlags(WebSandboxFlags flags)
2111 { 2127 {
2112 frame()->loader().forceSandboxFlags(static_cast<SandboxFlags>(flags)); 2128 frame()->loader().forceSandboxFlags(static_cast<SandboxFlags>(flags));
2113 } 2129 }
2114 2130
2131 void WebLocalFrameImpl::clearActiveFindMatch()
2132 {
2133 ensureTextFinder().clearActiveFindMatch();
2134 }
2135
2115 } // namespace blink 2136 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698