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

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: Use assertion for nodes common ancestor 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()) {
yosin_UTC9 2015/11/02 03:44:17 nit: Please get rid of redundant curly braces.
Andrey Kraynov 2015/11/02 14:06:57 Done.
132 return resultRange;
133 }
134
135 // resultRange will be collapsed if the matched text spans over multiple TreeScopes.
136 // FIXME: Show such matches to users.
yosin_UTC9 2015/11/02 03:44:17 nit: Please use "TODO(iceman):" instead of "FIXME:
Andrey Kraynov 2015/11/02 14:06:57 Done.
137 searchRange = EphemeralRangeTemplate<Strategy>(result.endPosition(), sea rchRange.endPosition());
138 } while (!searchRange.isCollapsed());
139
140 return nullptr;
141 }
142
143 PassRefPtrWillBeRawPtr<Range> TextFinder::findStringAndScrollToVisible(const Str ing& searchText, FindOptions findOptions)
144 {
145 if (RuntimeEnabledFeatures::selectionForComposedTreeEnabled())
146 return findStringAndScrollToVisibleAlgorithm(ownerFrame().frame()->edito r(), searchText, EphemeralRangeInComposedTree(m_activeMatch.get()), findOptions) ;
147
148 return findStringAndScrollToVisibleAlgorithm(ownerFrame().frame()->editor(), searchText, EphemeralRange(m_activeMatch.get()), findOptions);
149 }
150
116 bool TextFinder::find(int identifier, const WebString& searchText, const WebFind Options& options, bool wrapWithinFrame, WebRect* selectionRect) 151 bool TextFinder::find(int identifier, const WebString& searchText, const WebFind Options& options, bool wrapWithinFrame, WebRect* selectionRect)
117 { 152 {
118 if (!ownerFrame().frame() || !ownerFrame().frame()->page()) 153 if (!ownerFrame().frame() || !ownerFrame().frame()->page())
119 return false; 154 return false;
120 155
121 WebLocalFrameImpl* mainFrameImpl = ownerFrame().viewImpl()->mainFrameImpl(); 156 WebLocalFrameImpl* mainFrameImpl = ownerFrame().viewImpl()->mainFrameImpl();
122 157
123 if (!options.findNext) 158 if (!options.findNext)
124 unmarkAllTextMatches(); 159 unmarkAllTextMatches();
125 else 160 else
(...skipping 12 matching lines...) Expand all
138 ownerFrame().frame()->selection().clear(); 173 ownerFrame().frame()->selection().clear();
139 } 174 }
140 175
141 ASSERT(ownerFrame().frame() && ownerFrame().frame()->view()); 176 ASSERT(ownerFrame().frame() && ownerFrame().frame()->view());
142 const FindOptions findOptions = (options.forward ? 0 : Backwards) 177 const FindOptions findOptions = (options.forward ? 0 : Backwards)
143 | (options.matchCase ? 0 : CaseInsensitive) 178 | (options.matchCase ? 0 : CaseInsensitive)
144 | (wrapWithinFrame ? WrapAround : 0) 179 | (wrapWithinFrame ? WrapAround : 0)
145 | (options.wordStart ? AtWordStarts : 0) 180 | (options.wordStart ? AtWordStarts : 0)
146 | (options.medialCapitalAsWordStart ? TreatMedialCapitalAsWordStart : 0) 181 | (options.medialCapitalAsWordStart ? TreatMedialCapitalAsWordStart : 0)
147 | (options.findNext ? 0 : StartInSelection); 182 | (options.findNext ? 0 : StartInSelection);
148 m_activeMatch = ownerFrame().frame()->editor().findStringAndScrollToVisible( searchText, m_activeMatch.get(), findOptions); 183 m_activeMatch = findStringAndScrollToVisible(searchText, findOptions);
149 184
150 if (!m_activeMatch) { 185 if (!m_activeMatch) {
151 // If we're finding next the next active match might not be in the curre nt frame. 186 // 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. 187 // In this case we don't want to clear the matches cache.
153 if (!options.findNext) 188 if (!options.findNext)
154 clearFindMatchesCache(); 189 clearFindMatchesCache();
155 190
156 ownerFrame().frameView()->invalidatePaintForTickmarks(); 191 ownerFrame().frameView()->invalidatePaintForTickmarks();
157 return false; 192 return false;
158 } 193 }
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 visitor->trace(m_ownerFrame); 851 visitor->trace(m_ownerFrame);
817 visitor->trace(m_currentActiveMatchFrame); 852 visitor->trace(m_currentActiveMatchFrame);
818 visitor->trace(m_activeMatch); 853 visitor->trace(m_activeMatch);
819 visitor->trace(m_resumeScopingFromRange); 854 visitor->trace(m_resumeScopingFromRange);
820 visitor->trace(m_deferredScopingWork); 855 visitor->trace(m_deferredScopingWork);
821 visitor->trace(m_findMatchesCache); 856 visitor->trace(m_findMatchesCache);
822 #endif 857 #endif
823 } 858 }
824 859
825 } // namespace blink 860 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698