Bug 1874684 - Part 37: Fix unified compilation. r=allstarschh
[gecko.git] / layout / forms / HTMLSelectEventListener.h
blob452610a2175cd200292dd639c815df94b05218fb
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"
13 class nsIFrame;
14 class nsListControlFrame;
16 namespace mozilla {
18 namespace dom {
19 class HTMLSelectElement;
20 class HTMLOptionElement;
21 class Event;
22 } // namespace dom
24 /**
25 * HTMLSelectEventListener
26 * This class is responsible for propagating events to the select element while
27 * it has a frame.
28 * Frames are not refcounted so they can't be used as event listeners.
31 class HTMLSelectEventListener final : public nsStubMutationObserver,
32 public nsIDOMEventListener {
33 public:
34 enum class SelectType : uint8_t { Listbox, Combobox };
35 HTMLSelectEventListener(dom::HTMLSelectElement& aElement,
36 SelectType aSelectType)
37 : mElement(&aElement), mIsCombobox(aSelectType == SelectType::Combobox) {
38 Attach();
41 NS_DECL_ISUPPORTS
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;
53 void Attach();
54 void Detach();
56 dom::HTMLOptionElement* GetCurrentOption() const;
58 MOZ_CAN_RUN_SCRIPT void FireOnInputAndOnChange();
60 private:
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;
79 MOZ_CAN_RUN_SCRIPT
80 void PostHandleKeyEvent(int32_t aNewIndex, uint32_t aCharCode, bool aIsShift,
81 bool aIsControlOrMeta);
83 /**
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