|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 * interface for rendering objects that manually create subtrees of |
|
8 * anonymous content |
|
9 */ |
|
10 |
|
11 #ifndef nsIAnonymousContentCreator_h___ |
|
12 #define nsIAnonymousContentCreator_h___ |
|
13 |
|
14 #include "nsQueryFrame.h" |
|
15 #include "nsIContent.h" |
|
16 #include "nsStyleContext.h" |
|
17 #include "nsTArrayForwardDeclare.h" |
|
18 |
|
19 class nsBaseContentList; |
|
20 class nsIFrame; |
|
21 |
|
22 /** |
|
23 * Any source for anonymous content can implement this interface to provide it. |
|
24 * HTML frames like nsFileControlFrame currently use this. |
|
25 * |
|
26 * @see nsCSSFrameConstructor |
|
27 */ |
|
28 class nsIAnonymousContentCreator |
|
29 { |
|
30 public: |
|
31 NS_DECL_QUERYFRAME_TARGET(nsIAnonymousContentCreator) |
|
32 |
|
33 struct ContentInfo { |
|
34 ContentInfo(nsIContent* aContent) : |
|
35 mContent(aContent) |
|
36 {} |
|
37 |
|
38 ContentInfo(nsIContent* aContent, nsStyleContext* aStyleContext) : |
|
39 mContent(aContent), mStyleContext(aStyleContext) |
|
40 {} |
|
41 |
|
42 nsIContent* mContent; |
|
43 nsRefPtr<nsStyleContext> mStyleContext; |
|
44 nsTArray<ContentInfo> mChildren; |
|
45 }; |
|
46 |
|
47 /** |
|
48 * Creates "native" anonymous content and adds the created content to |
|
49 * the aElements array. None of the returned elements can be nullptr. |
|
50 * |
|
51 * If the anonymous content creator sets the editable flag on some |
|
52 * of the elements that it creates, the flag will be applied to the node |
|
53 * upon being bound to the document. |
|
54 * |
|
55 * @note The returned elements are owned by this object. This object is |
|
56 * responsible for calling UnbindFromTree on the elements it returned |
|
57 * from CreateAnonymousContent when appropriate (i.e. before releasing |
|
58 * them). |
|
59 * |
|
60 * @note Implementations of this method that add items to mChildren must not |
|
61 * hook them up to any parent since frame construction takes care of |
|
62 * that. |
|
63 */ |
|
64 virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements)=0; |
|
65 |
|
66 /** |
|
67 * Appends "native" anonymous children created by CreateAnonymousContent() |
|
68 * to the given content list depending on the filter. |
|
69 * |
|
70 * @see nsIContent::GetChildren for set of values used for filter. |
|
71 */ |
|
72 virtual void AppendAnonymousContentTo(nsBaseContentList& aElements, |
|
73 uint32_t aFilter) = 0; |
|
74 |
|
75 /** |
|
76 * Implementations can override this method to create special frames for the |
|
77 * anonymous content returned from CreateAnonymousContent. |
|
78 * By default this method returns nullptr, which means the default frame |
|
79 * is created. |
|
80 */ |
|
81 virtual nsIFrame* CreateFrameFor(nsIContent* aContent) { return nullptr; } |
|
82 }; |
|
83 |
|
84 #endif |
|
85 |