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

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

Issue 1605863002: Restart search in page when new text is found. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: small clean up Created 4 years, 10 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 Timer<DeferredScopeStringMatches> m_timer; 107 Timer<DeferredScopeStringMatches> m_timer;
108 RawPtrWillBeMember<TextFinder> m_textFinder; 108 RawPtrWillBeMember<TextFinder> m_textFinder;
109 const int m_identifier; 109 const int m_identifier;
110 const WebString m_searchText; 110 const WebString m_searchText;
111 const WebFindOptions m_options; 111 const WebFindOptions m_options;
112 const bool m_reset; 112 const bool m_reset;
113 }; 113 };
114 114
115 bool TextFinder::find(int identifier, const WebString& searchText, const WebFind Options& options, bool wrapWithinFrame, WebRect* selectionRect) 115 bool TextFinder::find(int identifier, const WebString& searchText, const WebFind Options& options, bool wrapWithinFrame, WebRect* selectionRect, bool* activeNow)
116 { 116 {
117 if (!ownerFrame().frame() || !ownerFrame().frame()->page()) 117 if (!ownerFrame().frame() || !ownerFrame().frame()->page())
118 return false; 118 return false;
119 119
120 WebLocalFrameImpl* mainFrameImpl = ownerFrame().viewImpl()->mainFrameImpl(); 120 WebLocalFrameImpl* mainFrameImpl = ownerFrame().viewImpl()->mainFrameImpl();
121 121
122 if (!options.findNext) 122 if (!options.findNext)
123 unmarkAllTextMatches(); 123 unmarkAllTextMatches();
124 else 124 else
125 setMarkerActive(m_activeMatch.get(), false); 125 setMarkerActive(m_activeMatch.get(), false);
(...skipping 30 matching lines...) Expand all
156 return false; 156 return false;
157 } 157 }
158 158
159 // If the user is browsing a page with autosizing, adjust the zoom to the 159 // If the user is browsing a page with autosizing, adjust the zoom to the
160 // column where the next hit has been found. Doing this when autosizing is 160 // column where the next hit has been found. Doing this when autosizing is
161 // not set will result in a zoom reset on small devices. 161 // not set will result in a zoom reset on small devices.
162 if (ownerFrame().frame()->document()->textAutosizer()->pageNeedsAutosizing() ) { 162 if (ownerFrame().frame()->document()->textAutosizer()->pageNeedsAutosizing() ) {
163 ownerFrame().viewImpl()->zoomToFindInPageRect(ownerFrame().frameView()-> contentsToRootFrame(enclosingIntRect(LayoutObject::absoluteBoundingBoxRectForRan ge(m_activeMatch.get())))); 163 ownerFrame().viewImpl()->zoomToFindInPageRect(ownerFrame().frameView()-> contentsToRootFrame(enclosingIntRect(LayoutObject::absoluteBoundingBoxRectForRan ge(m_activeMatch.get()))));
164 } 164 }
165 165
166 setMarkerActive(m_activeMatch.get(), true); 166 if (activeNow)
167 *activeNow = setMarkerActive(m_activeMatch.get(), true);
168 else
169 setMarkerActive(m_activeMatch.get(), true);
Finnur 2016/01/29 17:47:50 Not as verbose and probably a bit clearer: bool i
dvadym 2016/02/01 12:41:10 Thanks, it makes code clearer.
170
167 WebLocalFrameImpl* oldActiveFrame = mainFrameImpl->ensureTextFinder().m_curr entActiveMatchFrame; 171 WebLocalFrameImpl* oldActiveFrame = mainFrameImpl->ensureTextFinder().m_curr entActiveMatchFrame;
168 mainFrameImpl->ensureTextFinder().m_currentActiveMatchFrame = &ownerFrame(); 172 mainFrameImpl->ensureTextFinder().m_currentActiveMatchFrame = &ownerFrame();
169 173
170 // Make sure no node is focused. See http://crbug.com/38700. 174 // Make sure no node is focused. See http://crbug.com/38700.
171 ownerFrame().frame()->document()->clearFocusedElement(); 175 ownerFrame().frame()->document()->clearFocusedElement();
172 176
173 if (!options.findNext || activeSelection) { 177 if (!options.findNext || activeSelection || (activeNow && !*activeNow)) {
Finnur 2016/01/29 17:47:49 Replace (activeNow && !*activeNow) with !isAct
dvadym 2016/02/01 12:41:10 Done.
174 // This is either a Find operation or a Find-next from a new start point 178 // This is either a Find operation, a Find-next from a new start point
175 // due to a selection, so we set the flag to ask the scoping effort 179 // due to a selection, or Find-next which found newly added text, so we
Finnur 2016/01/29 17:47:50 Suggest: "or new matches were found during Find-ne
dvadym 2016/02/01 12:41:10 Done.
176 // to find the active rect for us and report it back to the UI. 180 // set the flag to ask the scoping effort to find the active rect for
181 // us and report it back to the UI.
177 m_locatingActiveRect = true; 182 m_locatingActiveRect = true;
178 } else { 183 } else {
179 if (oldActiveFrame != &ownerFrame()) { 184 if (oldActiveFrame != &ownerFrame()) {
180 if (options.forward) 185 if (options.forward)
181 m_activeMatchIndexInCurrentFrame = 0; 186 m_activeMatchIndexInCurrentFrame = 0;
182 else 187 else
183 m_activeMatchIndexInCurrentFrame = m_lastMatchCount - 1; 188 m_activeMatchIndexInCurrentFrame = m_lastMatchCount - 1;
184 } else { 189 } else {
185 if (options.forward) 190 if (options.forward)
186 ++m_activeMatchIndexInCurrentFrame; 191 ++m_activeMatchIndexInCurrentFrame;
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 #if !ENABLE(OILPAN) 685 #if !ENABLE(OILPAN)
681 cancelPendingScopingEffort(); 686 cancelPendingScopingEffort();
682 #endif 687 #endif
683 } 688 }
684 689
685 void TextFinder::addMarker(Range* range, bool activeMatch) 690 void TextFinder::addMarker(Range* range, bool activeMatch)
686 { 691 {
687 ownerFrame().frame()->document()->markers().addTextMatchMarker(range, active Match); 692 ownerFrame().frame()->document()->markers().addTextMatchMarker(range, active Match);
688 } 693 }
689 694
690 void TextFinder::setMarkerActive(Range* range, bool active) 695 bool TextFinder::setMarkerActive(Range* range, bool active)
691 { 696 {
692 if (!range || range->collapsed()) 697 if (!range || range->collapsed())
693 return; 698 return false;
694 ownerFrame().frame()->document()->markers().setMarkersActive(range, active); 699 return ownerFrame().frame()->document()->markers().setMarkersActive(range, a ctive);
695 } 700 }
696 701
697 void TextFinder::unmarkAllTextMatches() 702 void TextFinder::unmarkAllTextMatches()
698 { 703 {
699 LocalFrame* frame = ownerFrame().frame(); 704 LocalFrame* frame = ownerFrame().frame();
700 if (frame && frame->page() && frame->editor().markedTextMatchesAreHighlighte d()) { 705 if (frame && frame->page() && frame->editor().markedTextMatchesAreHighlighte d()) {
701 if (ownerFrame().client() && ownerFrame().client()->shouldSearchSingleFr ame()) 706 if (ownerFrame().client() && ownerFrame().client()->shouldSearchSingleFr ame())
702 frame->document()->markers().removeMarkers(DocumentMarker::TextMatch ); 707 frame->document()->markers().removeMarkers(DocumentMarker::TextMatch );
703 else 708 else
704 frame->page()->unmarkAllTextMatches(); 709 frame->page()->unmarkAllTextMatches();
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 visitor->trace(m_ownerFrame); 820 visitor->trace(m_ownerFrame);
816 visitor->trace(m_currentActiveMatchFrame); 821 visitor->trace(m_currentActiveMatchFrame);
817 visitor->trace(m_activeMatch); 822 visitor->trace(m_activeMatch);
818 visitor->trace(m_resumeScopingFromRange); 823 visitor->trace(m_resumeScopingFromRange);
819 visitor->trace(m_deferredScopingWork); 824 visitor->trace(m_deferredScopingWork);
820 visitor->trace(m_findMatchesCache); 825 visitor->trace(m_findMatchesCache);
821 #endif 826 #endif
822 } 827 }
823 828
824 } // namespace blink 829 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698