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/. */
7 #ifndef nsComboboxControlFrame_h___
8 #define nsComboboxControlFrame_h___
15 // #define DO_REFLOW_DEBUG
16 // #define DO_REFLOW_COUNTER
17 // #define DO_UNCONSTRAINED_CHECK
19 // #define DO_NEW_REFLOW
22 // Mark used to indicate when onchange has been fired for current combobox item
23 #define NS_SKIP_NOTIFY_INDEX -2
25 #include "mozilla/Attributes.h"
26 #include "nsBlockFrame.h"
27 #include "nsIFormControlFrame.h"
28 #include "nsIAnonymousContentCreator.h"
29 #include "nsISelectControlFrame.h"
30 #include "nsIRollupListener.h"
31 #include "nsThreadUtils.h"
33 class nsComboboxDisplayFrame
;
38 class HTMLSelectEventListener
;
40 class HTMLSelectElement
;
46 } // namespace mozilla
48 class nsComboboxControlFrame final
: public nsBlockFrame
,
49 public nsIFormControlFrame
,
50 public nsIAnonymousContentCreator
,
51 public nsISelectControlFrame
{
52 using DrawTarget
= mozilla::gfx::DrawTarget
;
53 using Element
= mozilla::dom::Element
;
56 friend nsComboboxControlFrame
* NS_NewComboboxControlFrame(
57 mozilla::PresShell
* aPresShell
, ComputedStyle
* aStyle
,
59 friend class nsComboboxDisplayFrame
;
61 explicit nsComboboxControlFrame(ComputedStyle
* aStyle
,
62 nsPresContext
* aPresContext
);
63 ~nsComboboxControlFrame();
66 NS_DECL_FRAMEARENA_HELPERS(nsComboboxControlFrame
)
68 // nsIAnonymousContentCreator
69 nsresult
CreateAnonymousContent(nsTArray
<ContentInfo
>& aElements
) final
;
70 void AppendAnonymousContentTo(nsTArray
<nsIContent
*>& aElements
,
71 uint32_t aFilter
) final
;
73 nsIContent
* GetDisplayNode() const;
74 nsIFrame
* CreateFrameForDisplayNode();
77 mozilla::a11y::AccType
AccessibleType() final
;
80 nscoord
GetMinISize(gfxContext
* aRenderingContext
) final
;
82 nscoord
GetPrefISize(gfxContext
* aRenderingContext
) final
;
84 void Reflow(nsPresContext
* aCX
, ReflowOutput
& aDesiredSize
,
85 const ReflowInput
& aReflowInput
, nsReflowStatus
& aStatus
) final
;
87 MOZ_CAN_RUN_SCRIPT_BOUNDARY
88 nsresult
HandleEvent(nsPresContext
* aPresContext
,
89 mozilla::WidgetGUIEvent
* aEvent
,
90 nsEventStatus
* aEventStatus
) final
;
92 void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
93 const nsDisplayListSet
& aLists
) final
;
95 void PaintFocus(DrawTarget
& aDrawTarget
, nsPoint aPt
);
97 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
98 nsIFrame
* aPrevInFlow
) final
;
100 #ifdef DEBUG_FRAME_DUMP
101 nsresult
GetFrameName(nsAString
& aResult
) const final
;
103 void Destroy(DestroyContext
&) final
;
105 void SetInitialChildList(ChildListID aListID
, nsFrameList
&& aChildList
) final
;
106 const nsFrameList
& GetChildList(ChildListID aListID
) const final
;
107 void GetChildLists(nsTArray
<ChildList
>* aLists
) const final
;
109 nsContainerFrame
* GetContentInsertionFrame() final
;
111 // Return the dropdown and display frame.
112 void AppendDirectlyOwnedAnonBoxes(nsTArray
<OwnedAnonBox
>& aResult
) final
;
114 // nsIFormControlFrame
115 nsresult
SetFormProperty(nsAtom
* aName
, const nsAString
& aValue
) final
{
120 * Inform the control that it got (or lost) focus.
121 * If it lost focus, the dropdown menu will be rolled up if needed,
122 * and FireOnChange() will be called.
123 * @param aOn true if got focus, false if lost focus.
124 * @param aRepaint if true then force repaint (NOTE: we always force repaint
126 * @note This method might destroy |this|.
128 MOZ_CAN_RUN_SCRIPT_BOUNDARY
129 void SetFocus(bool aOn
, bool aRepaint
) final
;
132 * Return the available space before and after this frame for
133 * placing the drop-down list, and the current 2D translation.
134 * Note that either or both can be less than or equal to zero,
135 * if both are then the drop-down should be closed.
137 void GetAvailableDropdownSpace(mozilla::WritingMode aWM
, nscoord
* aBefore
,
139 mozilla::LogicalPoint
* aTranslation
);
140 int32_t GetIndexOfDisplayArea();
142 * @note This method might destroy |this|.
144 nsresult
RedisplaySelectedText();
145 int32_t UpdateRecentIndex(int32_t aIndex
);
147 bool IsDroppedDown() const;
149 // nsISelectControlFrame
150 NS_IMETHOD
AddOption(int32_t index
) final
;
151 NS_IMETHOD
RemoveOption(int32_t index
) final
;
152 NS_IMETHOD
DoneAddingChildren(bool aIsDone
) final
;
153 NS_IMETHOD
OnOptionSelected(int32_t aIndex
, bool aSelected
) final
;
155 OnSetSelectedIndex(int32_t aOldIndex
, int32_t aNewIndex
) final
;
157 int32_t CharCountOfLargestOptionForInflation() const;
160 friend class RedisplayTextEvent
;
161 friend class nsAsyncResize
;
162 friend class nsResizeDropdownAtFinalPosition
;
164 // Return true if we should render a dropdown button.
165 bool HasDropDownButton() const;
166 nscoord
DropDownButtonISize();
168 enum DropDownPositionState
{
169 // can't show the dropdown at its current position
170 eDropDownPositionSuppressed
,
171 // a resize reflow is pending, don't show it yet
172 eDropDownPositionPendingResize
,
173 // the dropdown has its final size and position and can be displayed here
174 eDropDownPositionFinal
176 DropDownPositionState
AbsolutelyPositionDropDown();
178 nscoord
GetLongestOptionISize(gfxContext
*) const;
180 // Helper for GetMinISize/GetPrefISize
181 nscoord
GetIntrinsicISize(gfxContext
* aRenderingContext
,
182 mozilla::IntrinsicISizeType aType
);
184 class RedisplayTextEvent
: public mozilla::Runnable
{
187 explicit RedisplayTextEvent(nsComboboxControlFrame
* c
)
188 : mozilla::Runnable("nsComboboxControlFrame::RedisplayTextEvent"),
190 void Revoke() { mControlFrame
= nullptr; }
193 nsComboboxControlFrame
* mControlFrame
;
196 void CheckFireOnChange();
197 void FireValueChangeEvent();
198 nsresult
RedisplayText();
199 void HandleRedisplayTextEvent();
200 void ActuallyDisplayText(bool aNotify
);
202 // If our total transform to the root frame of the root document is only a 2d
203 // translation then return that translation, otherwise returns (0,0).
204 nsPoint
GetCSSTransformTranslation();
206 mozilla::dom::HTMLSelectElement
& Select() const;
207 void GetOptionText(uint32_t aIndex
, nsAString
& aText
) const;
209 RefPtr
<nsTextNode
> mDisplayContent
; // Anonymous content used to display the
211 RefPtr
<Element
> mButtonContent
; // Anonymous content for the button
212 nsContainerFrame
* mDisplayFrame
; // frame to display selection
213 nsIFrame
* mButtonFrame
; // button frame
215 // The inline size of our display area. Used by that frame's reflow
216 // to size to the full inline size except the drop-marker.
217 nscoord mDisplayISize
;
218 // The maximum inline size of our display area, which is the
219 // nsComoboxControlFrame's border-box.
221 // Going over this would be observable via DOM APIs like client / scrollWidth.
222 nscoord mMaxDisplayISize
;
224 nsRevocableEventPtr
<RedisplayTextEvent
> mRedisplayTextEvent
;
226 int32_t mRecentSelectedIndex
;
227 int32_t mDisplayedIndex
;
228 nsString mDisplayedOptionTextOrPreview
;
230 RefPtr
<mozilla::HTMLSelectEventListener
> mEventListener
;
232 // See comment in HandleRedisplayTextEvent().
233 bool mInRedisplayText
;
234 bool mIsOpenInParentProcess
;
236 // static class data member for Bug 32920
237 // only one control can be focused at a time
238 static nsComboboxControlFrame
* sFocused
;
240 #ifdef DO_REFLOW_COUNTER