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 /*
8  * interface for rendering objects that manually create subtrees of
9  * anonymous content
10  */
11 
12 #ifndef nsIAnonymousContentCreator_h___
13 #define nsIAnonymousContentCreator_h___
14 
15 #include "mozilla/AnonymousContentKey.h"
16 
17 #include "nsQueryFrame.h"
18 #include "nsTArrayForwardDeclare.h"
19 #include "X11UndefineNone.h"
20 
21 class nsIContent;
22 
23 /**
24  * Any source for anonymous content can implement this interface to provide it.
25  * HTML frames like nsFileControlFrame currently use this.
26  *
27  * @see nsCSSFrameConstructor
28  */
29 class nsIAnonymousContentCreator {
30  public:
31   NS_DECL_QUERYFRAME_TARGET(nsIAnonymousContentCreator)
32 
33   struct ContentInfo {
34     explicit ContentInfo(
35         nsIContent* aContent,
36         mozilla::AnonymousContentKey aKey = mozilla::AnonymousContentKey::None)
mContentContentInfo37         : mContent(aContent), mKey(aKey) {}
38 
39     nsIContent* mContent;
40     mozilla::AnonymousContentKey mKey;
41   };
42 
43   /**
44    * Creates "native" anonymous content and adds the created content to
45    * the aElements array. None of the returned elements can be nullptr.
46    *
47    * If the anonymous content creator sets the editable flag on some
48    * of the elements that it creates, the flag will be applied to the node
49    * upon being bound to the document.
50    *
51    * @note The returned elements are owned by this object. This object is
52    *       responsible for calling UnbindFromTree on the elements it returned
53    *       from CreateAnonymousContent when appropriate (i.e. before releasing
54    *       them).
55    */
56   virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) = 0;
57 
58   /**
59    * Appends "native" anonymous children created by CreateAnonymousContent()
60    * to the given content list depending on the filter.
61    *
62    * @see nsIContent::GetChildren for set of values used for filter.  Currently,
63    *   eSkipPlaceholderContent is the only flag that any implementation of
64    *   this method heeds.
65    */
66   virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
67                                         uint32_t aFilter) = 0;
68 };
69 
70 #endif
71