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___
10 #include "mozilla/Attributes.h"
11 #include "nsIFormControlFrame.h"
12 #include "nsIAnonymousContentCreator.h"
13 #include "nsISelectControlFrame.h"
14 #include "nsIRollupListener.h"
15 #include "nsThreadUtils.h"
16 #include "nsHTMLButtonControlFrame.h"
20 class HTMLSelectEventListener
;
21 class ComboboxLabelFrame
;
23 class HTMLSelectElement
;
25 } // namespace mozilla
27 class nsComboboxControlFrame final
: public nsHTMLButtonControlFrame
,
28 public nsIAnonymousContentCreator
,
29 public nsISelectControlFrame
{
30 using Element
= mozilla::dom::Element
;
33 friend class mozilla::ComboboxLabelFrame
;
34 explicit nsComboboxControlFrame(ComputedStyle
* aStyle
,
35 nsPresContext
* aPresContext
);
36 ~nsComboboxControlFrame();
39 NS_DECL_FRAMEARENA_HELPERS(nsComboboxControlFrame
)
41 // nsIAnonymousContentCreator
42 nsresult
CreateAnonymousContent(nsTArray
<ContentInfo
>& aElements
) final
;
43 void AppendAnonymousContentTo(nsTArray
<nsIContent
*>& aElements
,
44 uint32_t aFilter
) final
;
47 mozilla::a11y::AccType
AccessibleType() final
;
50 nscoord
GetMinISize(gfxContext
* aRenderingContext
) final
;
51 nscoord
GetPrefISize(gfxContext
* aRenderingContext
) final
;
53 // We're a leaf, so we need to report ourselves as the content insertion
55 nsContainerFrame
* GetContentInsertionFrame() override
{ return this; }
57 void Reflow(nsPresContext
* aCX
, ReflowOutput
& aDesiredSize
,
58 const ReflowInput
& aReflowInput
, nsReflowStatus
& aStatus
) final
;
60 MOZ_CAN_RUN_SCRIPT_BOUNDARY
61 nsresult
HandleEvent(nsPresContext
* aPresContext
,
62 mozilla::WidgetGUIEvent
* aEvent
,
63 nsEventStatus
* aEventStatus
) final
;
65 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
66 nsIFrame
* aPrevInFlow
) final
;
67 void Destroy(DestroyContext
&) final
;
69 #ifdef DEBUG_FRAME_DUMP
70 nsresult
GetFrameName(nsAString
& aResult
) const final
{
71 return MakeFrameName(u
"ComboboxControl"_ns
, aResult
);
75 // nsIFormControlFrame
76 nsresult
SetFormProperty(nsAtom
* aName
, const nsAString
& aValue
) final
{
81 * @note This method might destroy |this|.
83 void FireValueChangeEvent();
84 nsresult
RedisplaySelectedText();
86 bool IsDroppedDown() const;
88 // nsISelectControlFrame
89 NS_IMETHOD
AddOption(int32_t index
) final
;
90 NS_IMETHOD
RemoveOption(int32_t index
) final
;
91 NS_IMETHOD
DoneAddingChildren(bool aIsDone
) final
;
92 NS_IMETHOD
OnOptionSelected(int32_t aIndex
, bool aSelected
) final
;
94 OnSetSelectedIndex(int32_t aOldIndex
, int32_t aNewIndex
) final
;
96 int32_t CharCountOfLargestOptionForInflation() const;
99 friend class RedisplayTextEvent
;
100 friend class nsAsyncResize
;
101 friend class nsResizeDropdownAtFinalPosition
;
103 // Return true if we should render a dropdown button.
104 bool HasDropDownButton() const;
105 nscoord
DropDownButtonISize();
107 enum DropDownPositionState
{
108 // can't show the dropdown at its current position
109 eDropDownPositionSuppressed
,
110 // a resize reflow is pending, don't show it yet
111 eDropDownPositionPendingResize
,
112 // the dropdown has its final size and position and can be displayed here
113 eDropDownPositionFinal
115 DropDownPositionState
AbsolutelyPositionDropDown();
117 nscoord
GetLongestOptionISize(gfxContext
*) const;
119 // Helper for GetMinISize/GetPrefISize
120 nscoord
GetIntrinsicISize(gfxContext
* aRenderingContext
,
121 mozilla::IntrinsicISizeType aType
);
123 class RedisplayTextEvent
: public mozilla::Runnable
{
126 explicit RedisplayTextEvent(nsComboboxControlFrame
* c
)
127 : mozilla::Runnable("nsComboboxControlFrame::RedisplayTextEvent"),
129 void Revoke() { mControlFrame
= nullptr; }
132 nsComboboxControlFrame
* mControlFrame
;
135 nsresult
RedisplayText();
136 void HandleRedisplayTextEvent();
137 void ActuallyDisplayText(bool aNotify
);
139 mozilla::dom::HTMLSelectElement
& Select() const;
140 void GetOptionText(uint32_t aIndex
, nsAString
& aText
) const;
142 RefPtr
<Element
> mDisplayLabel
; // Anonymous content for the label
143 RefPtr
<Element
> mButtonContent
; // Anonymous content for the button
144 nsRevocableEventPtr
<RedisplayTextEvent
> mRedisplayTextEvent
;
146 // The inline size of our display area. Used by that frame's reflow to size to
147 // the full inline size except the drop-marker.
148 nscoord mDisplayISize
= 0;
149 int32_t mDisplayedIndex
= -1;
150 nsString mDisplayedOptionTextOrPreview
;
151 RefPtr
<mozilla::HTMLSelectEventListener
> mEventListener
;