nsContentListDeclarations.h (2468B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 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 nsContentListDeclarations_h 8 #define nsContentListDeclarations_h 9 10 #include <stdint.h> 11 12 #include "nsCOMPtr.h" 13 #include "nsStringFwd.h" 14 15 class nsContentList; 16 class nsAtom; 17 class nsIContent; 18 class nsINode; 19 20 namespace mozilla::dom { 21 class Element; 22 } // namespace mozilla::dom 23 24 // Magic namespace id that means "match all namespaces". This is 25 // negative so it won't collide with actual namespace constants. 26 #define kNameSpaceID_Wildcard INT32_MIN 27 28 // This is a callback function type that can be used to implement an 29 // arbitrary matching algorithm. aContent is the content that may 30 // match the list, while aNamespaceID, aAtom, and aData are whatever 31 // was passed to the list's constructor. 32 using nsContentListMatchFunc = bool (*)(mozilla::dom::Element* aElement, 33 int32_t aNamespaceID, nsAtom* aAtom, 34 void* aData); 35 36 using nsContentListDestroyFunc = void (*)(void* aData); 37 38 /** 39 * A function that allocates the matching data for this 40 * FuncStringContentList. Returning aString is perfectly fine; in 41 * that case the destructor function should be a no-op. 42 */ 43 using nsFuncStringContentListDataAllocator = void* (*)(nsINode* aRootNode, 44 const nsString* aString); 45 46 // If aMatchNameSpaceId is kNameSpaceID_Unknown, this will return a 47 // content list which matches ASCIIToLower(aTagname) against HTML 48 // elements in HTML documents and aTagname against everything else. 49 // For any other value of aMatchNameSpaceId, the list will match 50 // aTagname against all elements. 51 already_AddRefed<nsContentList> NS_GetContentList(nsINode* aRootNode, 52 int32_t aMatchNameSpaceId, 53 const nsAString& aTagname); 54 55 template <class ListType> 56 already_AddRefed<nsContentList> GetFuncStringContentList( 57 nsINode* aRootNode, nsContentListMatchFunc aFunc, 58 nsContentListDestroyFunc aDestroyFunc, 59 nsFuncStringContentListDataAllocator aDataAllocator, 60 const nsAString& aString); 61 62 #endif // nsContentListDeclarations_h