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/. */
6 #ifndef nsFileControlFrame_h___
7 #define nsFileControlFrame_h___
9 #include "mozilla/Attributes.h"
10 #include "nsBlockFrame.h"
11 #include "nsIFormControlFrame.h"
12 #include "nsIDOMEventListener.h"
13 #include "nsIAnonymousContentCreator.h"
16 class nsTextControlFrame
;
17 class nsIDOMDataTransfer
;
19 class nsFileControlFrame
: public nsBlockFrame
,
20 public nsIFormControlFrame
,
21 public nsIAnonymousContentCreator
24 explicit nsFileControlFrame(nsStyleContext
* aContext
);
26 virtual void Init(nsIContent
* aContent
,
27 nsContainerFrame
* aParent
,
28 nsIFrame
* aPrevInFlow
) MOZ_OVERRIDE
;
30 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
31 const nsRect
& aDirtyRect
,
32 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
;
35 NS_DECL_FRAMEARENA_HELPERS
37 // nsIFormControlFrame
38 virtual nsresult
SetFormProperty(nsIAtom
* aName
, const nsAString
& aValue
) MOZ_OVERRIDE
;
39 virtual void SetFocus(bool aOn
, bool aRepaint
) MOZ_OVERRIDE
;
41 virtual nscoord
GetMinISize(nsRenderingContext
*aRenderingContext
) MOZ_OVERRIDE
;
43 virtual void DestroyFrom(nsIFrame
* aDestructRoot
) MOZ_OVERRIDE
;
45 #ifdef DEBUG_FRAME_DUMP
46 virtual nsresult
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
;
49 virtual nsresult
AttributeChanged(int32_t aNameSpaceID
,
51 int32_t aModType
) MOZ_OVERRIDE
;
52 virtual void ContentStatesChanged(mozilla::EventStates aStates
) MOZ_OVERRIDE
;
53 virtual bool IsLeaf() const MOZ_OVERRIDE
58 // nsIAnonymousContentCreator
59 virtual nsresult
CreateAnonymousContent(nsTArray
<ContentInfo
>& aElements
) MOZ_OVERRIDE
;
60 virtual void AppendAnonymousContentTo(nsTArray
<nsIContent
*>& aElements
,
61 uint32_t aFilter
) MOZ_OVERRIDE
;
64 virtual mozilla::a11y::AccType
AccessibleType() MOZ_OVERRIDE
;
67 typedef bool (*AcceptAttrCallback
)(const nsAString
&, void*);
72 friend class MouseListener
;
73 class MouseListener
: public nsIDOMEventListener
{
77 explicit MouseListener(nsFileControlFrame
* aFrame
)
86 virtual ~MouseListener() {}
88 nsFileControlFrame
* mFrame
;
91 class SyncDisabledStateEvent
;
92 friend class SyncDisabledStateEvent
;
93 class SyncDisabledStateEvent
: public nsRunnable
96 explicit SyncDisabledStateEvent(nsFileControlFrame
* aFrame
)
100 NS_IMETHOD
Run() MOZ_OVERRIDE
{
101 nsFileControlFrame
* frame
= static_cast<nsFileControlFrame
*>(mFrame
.GetFrame());
102 NS_ENSURE_STATE(frame
);
104 frame
->SyncDisabledState();
112 class DnDListener
: public MouseListener
{
114 explicit DnDListener(nsFileControlFrame
* aFrame
)
115 : MouseListener(aFrame
)
118 NS_DECL_NSIDOMEVENTLISTENER
120 static bool IsValidDropData(nsIDOMDataTransfer
* aDOMDataTransfer
);
121 static bool CanDropTheseFiles(nsIDOMDataTransfer
* aDOMDataTransfer
, bool aSupportsMultiple
);
124 virtual bool IsFrameOfType(uint32_t aFlags
) const MOZ_OVERRIDE
126 return nsBlockFrame::IsFrameOfType(aFlags
&
127 ~(nsIFrame::eReplaced
| nsIFrame::eReplacedContainsBlock
));
131 * The text box input.
132 * @see nsFileControlFrame::CreateAnonymousContent
134 nsCOMPtr
<nsIContent
> mTextContent
;
136 * The browse button input.
137 * @see nsFileControlFrame::CreateAnonymousContent
139 nsCOMPtr
<nsIContent
> mBrowse
;
142 * Drag and drop mouse listener.
143 * This makes sure we don't get used after destruction.
145 nsRefPtr
<DnDListener
> mMouseListener
;
149 * Sync the disabled state of the content with anonymous children.
151 void SyncDisabledState();
154 * Updates the displayed value by using aValue.
156 void UpdateDisplayedValue(const nsAString
& aValue
, bool aNotify
);
159 #endif // nsFileControlFrame_h___