1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsFileControlFrame_h___
39 #define nsFileControlFrame_h___
41 #include "nsBlockFrame.h"
42 #include "nsIFormControlFrame.h"
43 #include "nsIDOMEventListener.h"
44 #include "nsIAnonymousContentCreator.h"
45 #include "nsICapturePicker.h"
48 class nsTextControlFrame
;
49 class nsIDOMDragEvent
;
51 class nsFileControlFrame
: public nsBlockFrame
,
52 public nsIFormControlFrame
,
53 public nsIAnonymousContentCreator
56 nsFileControlFrame(nsStyleContext
* aContext
);
58 NS_IMETHOD
Init(nsIContent
* aContent
,
60 nsIFrame
* aPrevInFlow
);
62 NS_IMETHOD
BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
63 const nsRect
& aDirtyRect
,
64 const nsDisplayListSet
& aLists
);
67 NS_DECL_FRAMEARENA_HELPERS
69 // nsIFormControlFrame
70 virtual nsresult
SetFormProperty(nsIAtom
* aName
, const nsAString
& aValue
);
71 virtual nsresult
GetFormProperty(nsIAtom
* aName
, nsAString
& aValue
) const;
72 virtual void SetFocus(bool aOn
, bool aRepaint
);
74 virtual nscoord
GetMinWidth(nsRenderingContext
*aRenderingContext
);
76 virtual void DestroyFrom(nsIFrame
* aDestructRoot
);
79 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const;
82 NS_IMETHOD
AttributeChanged(PRInt32 aNameSpaceID
,
85 virtual void ContentStatesChanged(nsEventStates aStates
);
86 virtual bool IsLeaf() const;
90 // nsIAnonymousContentCreator
91 virtual nsresult
CreateAnonymousContent(nsTArray
<ContentInfo
>& aElements
);
92 virtual void AppendAnonymousContentTo(nsBaseContentList
& aElements
,
96 virtual already_AddRefed
<nsAccessible
> CreateAccessible();
99 typedef bool (*AcceptAttrCallback
)(const nsAString
&, void*);
100 void ParseAcceptAttribute(AcceptAttrCallback aCallback
, void* aClosure
) const;
105 friend class MouseListener
;
106 class MouseListener
: public nsIDOMEventListener
{
110 MouseListener(nsFileControlFrame
* aFrame
) :
119 nsFileControlFrame
* mFrame
;
122 class SyncDisabledStateEvent
;
123 friend class SyncDisabledStateEvent
;
124 class SyncDisabledStateEvent
: public nsRunnable
127 SyncDisabledStateEvent(nsFileControlFrame
* aFrame
)
132 nsFileControlFrame
* frame
= static_cast<nsFileControlFrame
*>(mFrame
.GetFrame());
133 NS_ENSURE_STATE(frame
);
135 frame
->SyncDisabledState();
143 class CaptureMouseListener
: public MouseListener
{
145 CaptureMouseListener(nsFileControlFrame
* aFrame
) : MouseListener(aFrame
),
147 NS_DECL_NSIDOMEVENTLISTENER
151 class BrowseMouseListener
: public MouseListener
{
153 BrowseMouseListener(nsFileControlFrame
* aFrame
) : MouseListener(aFrame
) {};
154 NS_DECL_NSIDOMEVENTLISTENER
156 static bool IsValidDropData(nsIDOMDragEvent
* aEvent
);
159 virtual bool IsFrameOfType(PRUint32 aFlags
) const
161 return nsBlockFrame::IsFrameOfType(aFlags
&
162 ~(nsIFrame::eReplaced
| nsIFrame::eReplacedContainsBlock
));
165 virtual PRIntn
GetSkipSides() const;
168 * The text box input.
169 * @see nsFileControlFrame::CreateAnonymousContent
171 nsCOMPtr
<nsIContent
> mTextContent
;
173 * The browse button input.
174 * @see nsFileControlFrame::CreateAnonymousContent
176 nsCOMPtr
<nsIContent
> mBrowse
;
179 * The capture button input.
180 * @see nsFileControlFrame::CreateAnonymousContent
182 nsCOMPtr
<nsIContent
> mCapture
;
185 * Our mouse listener. This makes sure we don't get used after destruction.
187 nsRefPtr
<BrowseMouseListener
> mMouseListener
;
188 nsRefPtr
<CaptureMouseListener
> mCaptureMouseListener
;
192 * @return the text control frame, or null if not found
194 nsTextControlFrame
* GetTextControlFrame();
197 * Copy an attribute from file content to text and button content.
198 * @param aNameSpaceID namespace of attr
199 * @param aAttribute attribute atom
200 * @param aWhichControls which controls to apply to (SYNC_TEXT or SYNC_FILE)
202 void SyncAttr(PRInt32 aNameSpaceID
, nsIAtom
* aAttribute
,
203 PRInt32 aWhichControls
);
206 * Sync the disabled state of the content with anonymous children.
208 void SyncDisabledState();