TextDirectiveFinder.h (2333B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef DOM_TEXTDIRECTIVEFINDER_H_ 8 #define DOM_TEXTDIRECTIVEFINDER_H_ 9 #include "mozilla/RefPtr.h" 10 #include "mozilla/TimeStamp.h" 11 #include "nsTArray.h" 12 13 class nsRange; 14 struct TextDirective; 15 namespace mozilla::dom { 16 17 class Document; 18 19 /** 20 * @brief Finds one or more `TextDirective`s in a `Document`. 21 * 22 * This class is designed to consume the `TextDirective`s. 23 * Every `TextDirective` which is found is removed from the list of uninvoked 24 * text directives, and is returned as an `nsRange`. 25 * 26 * Internally, finding a text directive in a document uses Gecko's find-in-page 27 * implementation `nsFind`. 28 */ 29 class TextDirectiveFinder final { 30 public: 31 ~TextDirectiveFinder(); 32 33 void Traverse(nsCycleCollectionTraversalCallback& aCallback); 34 /** 35 * @brief Attempts to convert all uninvoked text directives to ranges. 36 * 37 * This method is the main entry point of this class. 38 */ 39 nsTArray<RefPtr<nsRange>> FindTextDirectivesInDocument(); 40 41 /** 42 * Returns true if there are text directives left which were not yet found in 43 * the document. 44 */ 45 bool HasUninvokedDirectives() const; 46 47 /** 48 * Finds a range for _one_ text directive. 49 */ 50 RefPtr<nsRange> FindRangeForTextDirective( 51 const TextDirective& aTextDirective); 52 53 private: 54 friend class FragmentDirective; 55 TextDirectiveFinder(Document* aDocument, 56 nsTArray<TextDirective>&& aTextDirectives); 57 NotNull<RefPtr<Document>> mDocument; 58 nsTArray<TextDirective> mUninvokedTextDirectives; 59 60 /** 61 * Member variables for telemetry. 62 * Since measured function might called multiple times, we accumulate values 63 * and report them in destructor. 64 */ 65 TimeStamp::DurationType mFindTextDirectivesDuration{0}; 66 int64_t mFoundDirectiveCount{0}; 67 }; 68 } // namespace mozilla::dom 69 70 inline void ImplCycleCollectionTraverse( 71 nsCycleCollectionTraversalCallback& aCallback, 72 mozilla::dom::TextDirectiveFinder& aField, const char* aName, 73 uint32_t aFlags = 0) { 74 aField.Traverse(aCallback); 75 } 76 77 #endif