Bumping manifests a=b2g-bump
[gecko.git] / layout / forms / nsTextControlFrame.h
blobc8d70d34d13e579eb6ee6ea2de44ee03a9f296b5
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 nsTextControlFrame_h___
7 #define nsTextControlFrame_h___
9 #include "mozilla/Attributes.h"
10 #include "nsContainerFrame.h"
11 #include "nsIAnonymousContentCreator.h"
12 #include "nsIContent.h"
13 #include "nsITextControlFrame.h"
14 #include "nsITextControlElement.h"
15 #include "nsIStatefulFrame.h"
17 class nsISelectionController;
18 class EditorInitializerEntryTracker;
19 class nsTextEditorState;
20 class nsIEditor;
21 namespace mozilla {
22 namespace dom {
23 class Element;
27 class nsTextControlFrame MOZ_FINAL : public nsContainerFrame,
28 public nsIAnonymousContentCreator,
29 public nsITextControlFrame,
30 public nsIStatefulFrame
32 public:
33 NS_DECL_FRAMEARENA_HELPERS
35 NS_DECLARE_FRAME_PROPERTY(ContentScrollPos, DestroyPoint)
37 explicit nsTextControlFrame(nsStyleContext* aContext);
38 virtual ~nsTextControlFrame();
40 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
42 virtual nsIScrollableFrame* GetScrollTargetFrame() MOZ_OVERRIDE {
43 return do_QueryFrame(GetFirstPrincipalChild());
46 virtual nscoord GetMinISize(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
47 virtual nscoord GetPrefISize(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
49 virtual mozilla::LogicalSize
50 ComputeAutoSize(nsRenderingContext *aRenderingContext,
51 mozilla::WritingMode aWritingMode,
52 const mozilla::LogicalSize& aCBSize,
53 nscoord aAvailableISize,
54 const mozilla::LogicalSize& aMargin,
55 const mozilla::LogicalSize& aBorder,
56 const mozilla::LogicalSize& aPadding,
57 bool aShrinkWrap) MOZ_OVERRIDE;
59 virtual void Reflow(nsPresContext* aPresContext,
60 nsHTMLReflowMetrics& aDesiredSize,
61 const nsHTMLReflowState& aReflowState,
62 nsReflowStatus& aStatus) MOZ_OVERRIDE;
64 virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
65 virtual bool IsCollapsed() MOZ_OVERRIDE;
67 virtual bool IsLeaf() const MOZ_OVERRIDE;
69 #ifdef ACCESSIBILITY
70 virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
71 #endif
73 #ifdef DEBUG_FRAME_DUMP
74 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
76 aResult.AssignLiteral("nsTextControlFrame");
77 return NS_OK;
79 #endif
81 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
83 // nsStackFrame is already both of these, but that's somewhat bogus,
84 // and we really mean it.
85 return nsContainerFrame::IsFrameOfType(aFlags &
86 ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
89 // nsIAnonymousContentCreator
90 virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
91 virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
92 uint32_t aFilter) MOZ_OVERRIDE;
94 virtual void SetInitialChildList(ChildListID aListID,
95 nsFrameList& aChildList) MOZ_OVERRIDE;
97 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
98 const nsRect& aDirtyRect,
99 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
101 virtual mozilla::dom::Element* GetPseudoElement(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
103 //==== BEGIN NSIFORMCONTROLFRAME
104 virtual void SetFocus(bool aOn , bool aRepaint) MOZ_OVERRIDE;
105 virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue) MOZ_OVERRIDE;
107 //==== END NSIFORMCONTROLFRAME
109 //==== NSITEXTCONTROLFRAME
111 NS_IMETHOD GetEditor(nsIEditor **aEditor) MOZ_OVERRIDE;
112 NS_IMETHOD SetSelectionStart(int32_t aSelectionStart) MOZ_OVERRIDE;
113 NS_IMETHOD SetSelectionEnd(int32_t aSelectionEnd) MOZ_OVERRIDE;
114 NS_IMETHOD SetSelectionRange(int32_t aSelectionStart,
115 int32_t aSelectionEnd,
116 SelectionDirection aDirection = eNone) MOZ_OVERRIDE;
117 NS_IMETHOD GetSelectionRange(int32_t* aSelectionStart,
118 int32_t* aSelectionEnd,
119 SelectionDirection* aDirection = nullptr) MOZ_OVERRIDE;
120 NS_IMETHOD GetOwnedSelectionController(nsISelectionController** aSelCon) MOZ_OVERRIDE;
121 virtual nsFrameSelection* GetOwnedFrameSelection() MOZ_OVERRIDE;
123 nsresult GetPhonetic(nsAString& aPhonetic) MOZ_OVERRIDE;
126 * Ensure mEditor is initialized with the proper flags and the default value.
127 * @throws NS_ERROR_NOT_INITIALIZED if mEditor has not been created
128 * @throws various and sundry other things
130 virtual nsresult EnsureEditorInitialized() MOZ_OVERRIDE;
132 //==== END NSITEXTCONTROLFRAME
134 //==== NSISTATEFULFRAME
136 NS_IMETHOD SaveState(nsPresState** aState) MOZ_OVERRIDE;
137 NS_IMETHOD RestoreState(nsPresState* aState) MOZ_OVERRIDE;
139 //=== END NSISTATEFULFRAME
141 //==== OVERLOAD of nsIFrame
142 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
144 /** handler for attribute changes to mContent */
145 virtual nsresult AttributeChanged(int32_t aNameSpaceID,
146 nsIAtom* aAttribute,
147 int32_t aModType) MOZ_OVERRIDE;
149 nsresult GetText(nsString& aText);
151 virtual nsresult PeekOffset(nsPeekOffsetStruct *aPos) MOZ_OVERRIDE;
153 NS_DECL_QUERYFRAME
155 // Temp reference to scriptrunner
156 // We could make these auto-Revoking via the "delete" entry for safety
157 NS_DECLARE_FRAME_PROPERTY(TextControlInitializer, nullptr)
159 protected:
161 * Launch the reflow on the child frames - see nsTextControlFrame::Reflow()
163 void ReflowTextControlChild(nsIFrame* aFrame,
164 nsPresContext* aPresContext,
165 const nsHTMLReflowState& aReflowState,
166 nsReflowStatus& aStatus,
167 nsHTMLReflowMetrics& aParentDesiredSize);
169 public: //for methods who access nsTextControlFrame directly
170 void SetValueChanged(bool aValueChanged);
172 // called by the focus listener
173 nsresult MaybeBeginSecureKeyboardInput();
174 void MaybeEndSecureKeyboardInput();
176 #define DEFINE_TEXTCTRL_FORWARDER(type, name) \
177 type name() { \
178 nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent()); \
179 NS_ASSERTION(txtCtrl, "Content not a text control element"); \
180 return txtCtrl->name(); \
182 #define DEFINE_TEXTCTRL_CONST_FORWARDER(type, name) \
183 type name() const { \
184 nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent()); \
185 NS_ASSERTION(txtCtrl, "Content not a text control element"); \
186 return txtCtrl->name(); \
189 DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsSingleLineTextControl)
190 DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsTextArea)
191 DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsPlainTextControl)
192 DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsPasswordTextControl)
193 DEFINE_TEXTCTRL_FORWARDER(int32_t, GetCols)
194 DEFINE_TEXTCTRL_FORWARDER(int32_t, GetWrapCols)
195 DEFINE_TEXTCTRL_FORWARDER(int32_t, GetRows)
197 #undef DEFINE_TEXTCTRL_CONST_FORWARDER
198 #undef DEFINE_TEXTCTRL_FORWARDER
200 protected:
201 class EditorInitializer;
202 friend class EditorInitializer;
203 friend class nsTextEditorState; // needs access to UpdateValueDisplay
205 class EditorInitializer : public nsRunnable {
206 public:
207 explicit EditorInitializer(nsTextControlFrame* aFrame) :
208 mFrame(aFrame) {}
210 NS_IMETHOD Run() MOZ_OVERRIDE;
212 // avoids use of nsWeakFrame
213 void Revoke() {
214 mFrame = nullptr;
217 private:
218 nsTextControlFrame* mFrame;
221 class ScrollOnFocusEvent;
222 friend class ScrollOnFocusEvent;
224 class ScrollOnFocusEvent : public nsRunnable {
225 public:
226 explicit ScrollOnFocusEvent(nsTextControlFrame* aFrame) :
227 mFrame(aFrame) {}
229 NS_DECL_NSIRUNNABLE
231 void Revoke() {
232 mFrame = nullptr;
235 private:
236 nsTextControlFrame* mFrame;
239 nsresult OffsetToDOMPoint(int32_t aOffset, nsIDOMNode** aResult, int32_t* aPosition);
242 * Update the textnode under our anonymous div to show the new
243 * value. This should only be called when we have no editor yet.
244 * @throws NS_ERROR_UNEXPECTED if the div has no text content
246 nsresult UpdateValueDisplay(bool aNotify,
247 bool aBeforeEditorInit = false,
248 const nsAString *aValue = nullptr);
251 * Get the maxlength attribute
252 * @param aMaxLength the value of the max length attr
253 * @returns false if attr not defined
255 bool GetMaxLength(int32_t* aMaxLength);
258 * Find out whether an attribute exists on the content or not.
259 * @param aAtt the attribute to determine the existence of
260 * @returns false if it does not exist
262 bool AttributeExists(nsIAtom *aAtt) const
263 { return mContent && mContent->HasAttr(kNameSpaceID_None, aAtt); }
266 * We call this when we are being destroyed or removed from the PFM.
267 * @param aPresContext the current pres context
269 void PreDestroy();
271 // Compute our intrinsic size. This does not include any borders, paddings,
272 // etc. Just the size of our actual area for the text (and the scrollbars,
273 // for <textarea>).
274 nsresult CalcIntrinsicSize(nsRenderingContext* aRenderingContext,
275 mozilla::WritingMode aWM,
276 mozilla::LogicalSize& aIntrinsicSize,
277 float aFontSizeInflation);
279 nsresult ScrollSelectionIntoView() MOZ_OVERRIDE;
281 private:
282 //helper methods
283 nsresult SetSelectionInternal(nsIDOMNode *aStartNode, int32_t aStartOffset,
284 nsIDOMNode *aEndNode, int32_t aEndOffset,
285 SelectionDirection aDirection = eNone);
286 nsresult SelectAllOrCollapseToEndOfText(bool aSelect);
287 nsresult SetSelectionEndPoints(int32_t aSelStart, int32_t aSelEnd,
288 SelectionDirection aDirection = eNone);
291 * Return the root DOM element, and implicitly initialize the editor if needed.
293 mozilla::dom::Element* GetRootNodeAndInitializeEditor();
294 nsresult GetRootNodeAndInitializeEditor(nsIDOMElement **aRootElement);
296 void FinishedInitializer() {
297 Properties().Delete(TextControlInitializer());
300 private:
301 // these packed bools could instead use the high order bits on mState, saving 4 bytes
302 bool mEditorHasBeenInitialized;
303 bool mIsProcessing;
304 // Keep track if we have asked a placeholder node creation.
305 bool mUsePlaceholder;
307 #ifdef DEBUG
308 bool mInEditorInitialization;
309 friend class EditorInitializerEntryTracker;
310 #endif
312 nsRevocableEventPtr<ScrollOnFocusEvent> mScrollEvent;
315 #endif