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