/src/mozilla-central/layout/forms/nsFileControlFrame.h
Line | Count | Source (jump to first uncovered line) |
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 nsFileControlFrame_h___ |
8 | | #define nsFileControlFrame_h___ |
9 | | |
10 | | #include "mozilla/Attributes.h" |
11 | | #include "nsBlockFrame.h" |
12 | | #include "nsIFormControlFrame.h" |
13 | | #include "nsIDOMEventListener.h" |
14 | | #include "nsIAnonymousContentCreator.h" |
15 | | #include "nsCOMPtr.h" |
16 | | |
17 | | namespace mozilla { |
18 | | namespace dom { |
19 | | class FileList; |
20 | | class BlobImpl; |
21 | | class DataTransfer; |
22 | | } // namespace dom |
23 | | } // namespace mozilla |
24 | | |
25 | | class nsFileControlFrame final : public nsBlockFrame, |
26 | | public nsIFormControlFrame, |
27 | | public nsIAnonymousContentCreator |
28 | | { |
29 | | public: |
30 | | explicit nsFileControlFrame(ComputedStyle* aStyle); |
31 | | |
32 | | virtual void Init(nsIContent* aContent, |
33 | | nsContainerFrame* aParent, |
34 | | nsIFrame* aPrevInFlow) override; |
35 | | |
36 | | virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
37 | | const nsDisplayListSet& aLists) override; |
38 | | |
39 | | NS_DECL_QUERYFRAME |
40 | | NS_DECL_FRAMEARENA_HELPERS(nsFileControlFrame) |
41 | | |
42 | | // nsIFormControlFrame |
43 | | virtual nsresult SetFormProperty(nsAtom* aName, const nsAString& aValue) override; |
44 | | virtual void SetFocus(bool aOn, bool aRepaint) override; |
45 | | |
46 | | virtual nscoord GetMinISize(gfxContext *aRenderingContext) override; |
47 | | |
48 | | virtual void DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) override; |
49 | | |
50 | | #ifdef DEBUG_FRAME_DUMP |
51 | | virtual nsresult GetFrameName(nsAString& aResult) const override; |
52 | | #endif |
53 | | |
54 | | virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
55 | | nsAtom* aAttribute, |
56 | | int32_t aModType) override; |
57 | | virtual void ContentStatesChanged(mozilla::EventStates aStates) override; |
58 | | |
59 | | // nsIAnonymousContentCreator |
60 | | virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override; |
61 | | virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements, |
62 | | uint32_t aFilter) override; |
63 | | |
64 | | #ifdef ACCESSIBILITY |
65 | | virtual mozilla::a11y::AccType AccessibleType() override; |
66 | | #endif |
67 | | |
68 | | typedef bool (*AcceptAttrCallback)(const nsAString&, void*); |
69 | | |
70 | | protected: |
71 | | |
72 | | class MouseListener; |
73 | | friend class MouseListener; |
74 | | class MouseListener : public nsIDOMEventListener { |
75 | | public: |
76 | | NS_DECL_ISUPPORTS |
77 | | |
78 | | explicit MouseListener(nsFileControlFrame* aFrame) |
79 | | : mFrame(aFrame) |
80 | 0 | {} |
81 | | |
82 | 0 | void ForgetFrame() { |
83 | 0 | mFrame = nullptr; |
84 | 0 | } |
85 | | |
86 | | protected: |
87 | 0 | virtual ~MouseListener() {} |
88 | | |
89 | | nsFileControlFrame* mFrame; |
90 | | }; |
91 | | |
92 | | class SyncDisabledStateEvent; |
93 | | friend class SyncDisabledStateEvent; |
94 | | class SyncDisabledStateEvent : public mozilla::Runnable |
95 | | { |
96 | | public: |
97 | | explicit SyncDisabledStateEvent(nsFileControlFrame* aFrame) |
98 | | : mozilla::Runnable("nsFileControlFrame::SyncDisabledStateEvent") |
99 | | , mFrame(aFrame) |
100 | 0 | {} |
101 | | |
102 | 0 | NS_IMETHOD Run() override { |
103 | 0 | nsFileControlFrame* frame = static_cast<nsFileControlFrame*>(mFrame.GetFrame()); |
104 | 0 | NS_ENSURE_STATE(frame); |
105 | 0 |
|
106 | 0 | frame->SyncDisabledState(); |
107 | 0 | return NS_OK; |
108 | 0 | } |
109 | | |
110 | | private: |
111 | | WeakFrame mFrame; |
112 | | }; |
113 | | |
114 | | class DnDListener: public MouseListener { |
115 | | public: |
116 | | explicit DnDListener(nsFileControlFrame* aFrame) |
117 | | : MouseListener(aFrame) |
118 | 0 | {} |
119 | | |
120 | | NS_DECL_NSIDOMEVENTLISTENER |
121 | | |
122 | | nsresult GetBlobImplForWebkitDirectory(mozilla::dom::FileList* aFileList, |
123 | | mozilla::dom::BlobImpl** aBlobImpl); |
124 | | |
125 | | bool IsValidDropData(mozilla::dom::DataTransfer* aDataTransfer); |
126 | | bool CanDropTheseFiles(mozilla::dom::DataTransfer* aDataTransfer, |
127 | | bool aSupportsMultiple); |
128 | | }; |
129 | | |
130 | | virtual bool IsFrameOfType(uint32_t aFlags) const override |
131 | 0 | { |
132 | 0 | return nsBlockFrame::IsFrameOfType(aFlags & |
133 | 0 | ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock)); |
134 | 0 | } |
135 | | |
136 | | /** |
137 | | * The text box input. |
138 | | * @see nsFileControlFrame::CreateAnonymousContent |
139 | | */ |
140 | | RefPtr<Element> mTextContent; |
141 | | /** |
142 | | * The button to open a file or directory picker. |
143 | | * @see nsFileControlFrame::CreateAnonymousContent |
144 | | */ |
145 | | RefPtr<Element> mBrowseFilesOrDirs; |
146 | | |
147 | | /** |
148 | | * Drag and drop mouse listener. |
149 | | * This makes sure we don't get used after destruction. |
150 | | */ |
151 | | RefPtr<DnDListener> mMouseListener; |
152 | | |
153 | | protected: |
154 | | /** |
155 | | * Sync the disabled state of the content with anonymous children. |
156 | | */ |
157 | | void SyncDisabledState(); |
158 | | |
159 | | /** |
160 | | * Updates the displayed value by using aValue. |
161 | | */ |
162 | | void UpdateDisplayedValue(const nsAString& aValue, bool aNotify); |
163 | | }; |
164 | | |
165 | | #endif // nsFileControlFrame_h___ |