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

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

Issue 1409073004: Return EphemeralRange from Editor::findRangeOfString. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Extract text bounds collecting to a function Created 5 years, 1 month 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 107
108 Timer<DeferredScopeStringMatches> m_timer; 108 Timer<DeferredScopeStringMatches> m_timer;
109 RawPtrWillBeMember<TextFinder> m_textFinder; 109 RawPtrWillBeMember<TextFinder> m_textFinder;
110 const int m_identifier; 110 const int m_identifier;
111 const WebString m_searchText; 111 const WebString m_searchText;
112 const WebFindOptions m_options; 112 const WebFindOptions m_options;
113 const bool m_reset; 113 const bool m_reset;
114 }; 114 };
115 115
116 template <typename Strategy>
117 static PassRefPtrWillBeRawPtr<Range> findStringAndScrollToVisibleAlgorithm(
118 Editor& editor,
119 const String& searchText,
120 EphemeralRangeTemplate<Strategy> searchRange,
121 FindOptions findOptions)
122 {
123 do {
124 EphemeralRangeTemplate<Strategy> result = editor.findStringAndScrollToVi sible(searchText, searchRange, findOptions);
125 if (result.isCollapsed()) {
126 // Not found.
127 return nullptr;
128 }
129
130 RefPtrWillBeRawPtr<Range> resultRange = Range::create(result.document(), toPositionInDOMTree(result.startPosition()), toPositionInDOMTree(result.endPosi tion()));
131 if (!resultRange->collapsed())
132 return resultRange;
133
134 // |resultRange| will be collapsed if the matched text spans over multip le TreeScopes.
135 // TODO(iceman): Show such matches to users.
136 searchRange = EphemeralRangeTemplate<Strategy>(result.endPosition(), sea rchRange.endPosition());
137 } while (!searchRange.isCollapsed());
138
139 return nullptr;
140 }
141
142 PassRefPtrWillBeRawPtr<Range> TextFinder::findStringAndScrollToVisible(const Str ing& searchText, FindOptions findOptions)
143 {
144 if (RuntimeEnabledFeatures::selectionForComposedTreeEnabled())
145 return findStringAndScrollToVisibleAlgorithm(ownerFrame().frame()->edito r(), searchText, EphemeralRangeInComposedTree(m_activeMatch.get()), findOptions) ;
146
147 return findStringAndScrollToVisibleAlgorithm(ownerFrame().frame()->editor(), searchText, EphemeralRange(m_activeMatch.get()), findOptions);
148 }
149
116 bool TextFinder::find(int identifier, const WebString& searchText, const WebFind Options& options, bool wrapWithinFrame, WebRect* selectionRect) 150 bool TextFinder::find(int identifier, const WebString& searchText, const WebFind Options& options, bool wrapWithinFrame, WebRect* selectionRect)
117 { 151 {
118 if (!ownerFrame().frame() || !ownerFrame().frame()->page()) 152 if (!ownerFrame().frame() || !ownerFrame().frame()->page())
119 return false; 153 return false;
120 154
121 WebLocalFrameImpl* mainFrameImpl = ownerFrame().viewImpl()->mainFrameImpl(); 155 WebLocalFrameImpl* mainFrameImpl = ownerFrame().viewImpl()->mainFrameImpl();
122 156
123 if (!options.findNext) 157 if (!options.findNext)
124 unmarkAllTextMatches(); 158 unmarkAllTextMatches();
125 else 159 else
(...skipping 12 matching lines...) Expand all
138 ownerFrame().frame()->selection().clear(); 172 ownerFrame().frame()->selection().clear();
139 } 173 }
140 174
141 ASSERT(ownerFrame().frame() && ownerFrame().frame()->view()); 175 ASSERT(ownerFrame().frame() && ownerFrame().frame()->view());
142 const FindOptions findOptions = (options.forward ? 0 : Backwards) 176 const FindOptions findOptions = (options.forward ? 0 : Backwards)
143 | (options.matchCase ? 0 : CaseInsensitive) 177 | (options.matchCase ? 0 : CaseInsensitive)
144 | (wrapWithinFrame ? WrapAround : 0) 178 | (wrapWithinFrame ? WrapAround : 0)
145 | (options.wordStart ? AtWordStarts : 0) 179 | (options.wordStart ? AtWordStarts : 0)
146 | (options.medialCapitalAsWordStart ? TreatMedialCapitalAsWordStart : 0) 180 | (options.medialCapitalAsWordStart ? TreatMedialCapitalAsWordStart : 0)
147 | (options.findNext ? 0 : StartInSelection); 181 | (options.findNext ? 0 : StartInSelection);
148 m_activeMatch = ownerFrame().frame()->editor().findStringAndScrollToVisible( searchText, m_activeMatch.get(), findOptions); 182 m_activeMatch = findStringAndScrollToVisible(searchText, findOptions);
149 183
150 if (!m_activeMatch) { 184 if (!m_activeMatch) {
151 // If we're finding next the next active match might not be in the curre nt frame. 185 // If we're finding next the next active match might not be in the curre nt frame.
152 // In this case we don't want to clear the matches cache. 186 // In this case we don't want to clear the matches cache.
153 if (!options.findNext) 187 if (!options.findNext)
154 clearFindMatchesCache(); 188 clearFindMatchesCache();
155 189
156 ownerFrame().frameView()->invalidatePaintForTickmarks(); 190 ownerFrame().frameView()->invalidatePaintForTickmarks();
157 return false; 191 return false;
158 } 192 }
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 visitor->trace(m_ownerFrame); 850 visitor->trace(m_ownerFrame);
817 visitor->trace(m_currentActiveMatchFrame); 851 visitor->trace(m_currentActiveMatchFrame);
818 visitor->trace(m_activeMatch); 852 visitor->trace(m_activeMatch);
819 visitor->trace(m_resumeScopingFromRange); 853 visitor->trace(m_resumeScopingFromRange);
820 visitor->trace(m_deferredScopingWork); 854 visitor->trace(m_deferredScopingWork);
821 visitor->trace(m_findMatchesCache); 855 visitor->trace(m_findMatchesCache);
822 #endif 856 #endif
823 } 857 }
824 858
825 } // namespace blink 859 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698