Index: third_party/WebKit/Source/web/WebLocalFrameImpl.cpp |
diff --git a/third_party/WebKit/Source/web/WebLocalFrameImpl.cpp b/third_party/WebKit/Source/web/WebLocalFrameImpl.cpp |
index 5d633b5ab2b9b3bdb66b7ed4b2e09d5a25a8d31c..47e46e8b0016ba5cf69745ca26a32a7016507e81 100644 |
--- a/third_party/WebKit/Source/web/WebLocalFrameImpl.cpp |
+++ b/third_party/WebKit/Source/web/WebLocalFrameImpl.cpp |
@@ -622,6 +622,11 @@ ScrollableArea* WebLocalFrameImpl::layoutViewportScrollableArea() const |
return nullptr; |
} |
+bool WebLocalFrameImpl::isFocused() const |
+{ |
+ return this == WebFrame::fromFrame(viewImpl()->page()->focusController().focusedFrame()); |
+} |
+ |
WebSize WebLocalFrameImpl::scrollOffset() const |
{ |
if (ScrollableArea* scrollableArea = layoutViewportScrollableArea()) |
@@ -1553,11 +1558,8 @@ LocalFrame* WebLocalFrameImpl::createChildFrame(const FrameLoadRequest& request, |
void WebLocalFrameImpl::didChangeContentsSize(const IntSize& size) |
{ |
- // This is only possible on the main frame. |
- if (m_textFinder && m_textFinder->totalMatchCount() > 0) { |
- DCHECK(!parent()); |
+ if (m_textFinder && m_textFinder->totalMatchCount() > 0) |
m_textFinder->increaseMarkerVersion(); |
- } |
} |
void WebLocalFrameImpl::createFrameView() |
@@ -1625,12 +1627,7 @@ WebDataSourceImpl* WebLocalFrameImpl::provisionalDataSourceImpl() const |
void WebLocalFrameImpl::setFindEndstateFocusAndSelection() |
{ |
- WebLocalFrameImpl* mainFrameImpl = viewImpl()->mainFrameImpl(); |
- |
- // Main frame should already have a textFinder at this point of time. |
- DCHECK(mainFrameImpl->textFinder()); |
- |
- if (this != mainFrameImpl->textFinder()->activeMatchFrame()) |
+ if (!m_textFinder || !m_textFinder->activeMatchFrame()) |
return; |
if (Range* activeMatch = m_textFinder->activeMatch()) { |
@@ -1976,16 +1973,34 @@ void WebLocalFrameImpl::didCallIsSearchProviderInstalled() |
bool WebLocalFrameImpl::find(int identifier, const WebString& searchText, const WebFindOptions& options, bool wrapWithinFrame, WebRect* selectionRect, bool* activeNow) |
{ |
- return ensureTextFinder().find(identifier, searchText, options, wrapWithinFrame, selectionRect, activeNow); |
+ // Search for an active match only if this frame is focused or if this is a |
+ // find next request. |
+ if (isFocused() || options.findNext) |
+ return ensureTextFinder().find(identifier, searchText, options, wrapWithinFrame, selectionRect, activeNow); |
+ |
+ return false; |
} |
-void WebLocalFrameImpl::stopFinding(bool clearSelection) |
+void WebLocalFrameImpl::stopFinding(StopFindAction action) |
{ |
+ bool clearSelection = action == StopFindActionClearSelection; |
+ if (clearSelection) |
+ executeCommand(WebString::fromUTF8("Unselect")); |
dglazkov
2016/06/02 01:08:42
Curious -- why is this necessary now? Why wasn't i
paulmeyer
2016/06/02 17:36:37
I saw that you said I could disregard these commen
|
+ |
if (m_textFinder) { |
if (!clearSelection) |
setFindEndstateFocusAndSelection(); |
m_textFinder->stopFindingAndClearSelection(); |
} |
+ |
+ if (action == StopFindActionActivateSelection && isFocused()) { |
+ WebDocument doc = document(); |
+ if (!doc.isNull()) { |
dglazkov
2016/06/02 01:08:42
It's not possible for a frame to be focused and no
paulmeyer
2016/06/02 17:36:36
I'm actually not sure. It was checked before, so I
|
+ WebElement element = doc.focusedElement(); |
+ if (!element.isNull()) |
+ element.simulateClick(); |
dglazkov
2016/06/02 01:08:42
Huh. This is also new code? Why do we need to do t
paulmeyer
2016/06/02 17:36:37
This is the functionality of the "activate" action
|
+ } |
+ } |
} |
void WebLocalFrameImpl::scopeStringMatches(int identifier, const WebString& searchText, const WebFindOptions& options, bool reset) |
@@ -2001,8 +2016,6 @@ void WebLocalFrameImpl::cancelPendingScopingEffort() |
void WebLocalFrameImpl::increaseMatchCount(int count, int identifier) |
{ |
- // This function should only be called on the mainframe. |
- DCHECK(!parent()); |
ensureTextFinder().increaseMatchCount(identifier, count); |
} |
@@ -2019,8 +2032,6 @@ void WebLocalFrameImpl::dispatchMessageEventWithOriginCheck(const WebSecurityOri |
int WebLocalFrameImpl::findMatchMarkersVersion() const |
{ |
- DCHECK(!parent()); |
- |
if (m_textFinder) |
return m_textFinder->findMatchMarkersVersion(); |
return 0; |
@@ -2028,14 +2039,18 @@ int WebLocalFrameImpl::findMatchMarkersVersion() const |
int WebLocalFrameImpl::selectNearestFindMatch(const WebFloatPoint& point, WebRect* selectionRect) |
{ |
- DCHECK(!parent()); |
return ensureTextFinder().selectNearestFindMatch(point, selectionRect); |
} |
-WebFloatRect WebLocalFrameImpl::activeFindMatchRect() |
+float WebLocalFrameImpl::distanceToNearestFindMatch(const WebFloatPoint& point) |
{ |
- DCHECK(!parent()); |
+ float nearestDistance; |
+ ensureTextFinder().nearestFindMatch(point, &nearestDistance); |
+ return nearestDistance; |
+} |
+WebFloatRect WebLocalFrameImpl::activeFindMatchRect() |
+{ |
if (m_textFinder) |
return m_textFinder->activeFindMatchRect(); |
return WebFloatRect(); |
@@ -2043,7 +2058,6 @@ WebFloatRect WebLocalFrameImpl::activeFindMatchRect() |
void WebLocalFrameImpl::findMatchRects(WebVector<WebFloatRect>& outputRects) |
{ |
- DCHECK(!parent()); |
ensureTextFinder().findMatchRects(outputRects); |
} |
@@ -2112,4 +2126,9 @@ void WebLocalFrameImpl::forceSandboxFlags(WebSandboxFlags flags) |
frame()->loader().forceSandboxFlags(static_cast<SandboxFlags>(flags)); |
} |
+void WebLocalFrameImpl::clearActiveFindMatch() |
+{ |
+ ensureTextFinder().clearActiveFindMatch(); |
+} |
+ |
} // namespace blink |