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 mozilla_HTMLSelectEventListener_h
8 #define mozilla_HTMLSelectEventListener_h
10 #include "nsIDOMEventListener.h"
11 #include "nsStubMutationObserver.h"
14 class nsListControlFrame
;
19 class HTMLSelectElement
;
20 class HTMLOptionElement
;
25 * HTMLSelectEventListener
26 * This class is responsible for propagating events to the select element while
28 * Frames are not refcounted so they can't be used as event listeners.
31 class HTMLSelectEventListener final
: public nsStubMutationObserver
,
32 public nsIDOMEventListener
{
34 enum class SelectType
: uint8_t { Listbox
, Combobox
};
35 HTMLSelectEventListener(dom::HTMLSelectElement
& aElement
,
36 SelectType aSelectType
)
37 : mElement(&aElement
), mIsCombobox(aSelectType
== SelectType::Combobox
) {
43 // For comboboxes, we need to keep the list up to date when options change.
44 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
45 NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
46 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
47 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
48 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
50 // nsIDOMEventListener
51 MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD
HandleEvent(dom::Event
*) override
;
56 dom::HTMLOptionElement
* GetCurrentOption() const;
58 MOZ_CAN_RUN_SCRIPT
void FireOnInputAndOnChange();
61 // This is always guaranteed to be > 0, but callers want signed integers so we
62 // do the cast for them.
63 int32_t ItemsPerPage() const;
65 nsListControlFrame
* GetListControlFrame() const;
67 MOZ_CAN_RUN_SCRIPT nsresult
KeyDown(dom::Event
*);
68 MOZ_CAN_RUN_SCRIPT nsresult
KeyPress(dom::Event
*);
69 MOZ_CAN_RUN_SCRIPT nsresult
MouseDown(dom::Event
*);
70 MOZ_CAN_RUN_SCRIPT nsresult
MouseUp(dom::Event
*);
71 MOZ_CAN_RUN_SCRIPT nsresult
MouseMove(dom::Event
*);
73 void AdjustIndexForDisabledOpt(int32_t aStartIndex
, int32_t& aNewIndex
,
74 int32_t aNumOptions
, int32_t aDoAdjustInc
,
75 int32_t aDoAdjustIncNext
);
76 bool IsOptionInteractivelySelectable(uint32_t aIndex
) const;
77 int32_t GetEndSelectionIndex() const;
80 void PostHandleKeyEvent(int32_t aNewIndex
, uint32_t aCharCode
, bool aIsShift
,
81 bool aIsControlOrMeta
);
84 * Return the first non-disabled option starting at aFromIndex (inclusive).
85 * @param aFoundIndex if non-null, set to the index of the returned option
87 dom::HTMLOptionElement
* GetNonDisabledOptionFrom(
88 int32_t aFromIndex
, int32_t* aFoundIndex
= nullptr) const;
90 void ComboboxMightHaveChanged();
91 void OptionValueMightHaveChanged(nsIContent
* aMutatingNode
);
93 ~HTMLSelectEventListener();
95 RefPtr
<dom::HTMLSelectElement
> mElement
;
96 const bool mIsCombobox
;
97 bool mButtonDown
= false;
98 bool mControlSelectMode
= false;
101 } // namespace mozilla
103 #endif // mozilla_HTMLSelectEventListener_h