nsNumberControlFrame.h (2902B)
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/. */ 6 7 #ifndef nsNumberControlFrame_h__ 8 #define nsNumberControlFrame_h__ 9 10 #include "nsCOMPtr.h" 11 #include "nsContainerFrame.h" 12 #include "nsIAnonymousContentCreator.h" 13 #include "nsTextControlFrame.h" 14 15 class nsPresContext; 16 17 namespace mozilla { 18 enum class PseudoStyleType : uint8_t; 19 class PresShell; 20 class WidgetEvent; 21 class WidgetGUIEvent; 22 namespace dom { 23 class HTMLInputElement; 24 } // namespace dom 25 } // namespace mozilla 26 27 /** 28 * This frame type is used for <input type=number>. 29 * 30 * TODO(emilio): Maybe merge with nsTextControlFrame? 31 */ 32 class nsNumberControlFrame final : public nsTextControlFrame { 33 friend nsIFrame* NS_NewNumberControlFrame(mozilla::PresShell* aPresShell, 34 ComputedStyle* aStyle); 35 36 typedef mozilla::PseudoStyleType PseudoStyleType; 37 typedef mozilla::dom::Element Element; 38 typedef mozilla::dom::HTMLInputElement HTMLInputElement; 39 typedef mozilla::WidgetEvent WidgetEvent; 40 typedef mozilla::WidgetGUIEvent WidgetGUIEvent; 41 42 explicit nsNumberControlFrame(ComputedStyle* aStyle, 43 nsPresContext* aPresContext); 44 45 public: 46 NS_DECL_QUERYFRAME 47 NS_DECL_FRAMEARENA_HELPERS(nsNumberControlFrame) 48 49 #ifdef ACCESSIBILITY 50 mozilla::a11y::AccType AccessibleType() override; 51 #endif 52 53 // nsIAnonymousContentCreator 54 nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override; 55 56 #ifdef DEBUG_FRAME_DUMP 57 nsresult GetFrameName(nsAString& aResult) const override { 58 return MakeFrameName(u"NumberControl"_ns, aResult); 59 } 60 #endif 61 62 /** 63 * If the frame is the frame for an nsNumberControlFrame's up or down spin 64 * button, returns the nsNumberControlFrame. Else returns nullptr. 65 */ 66 static nsNumberControlFrame* GetNumberControlFrameForSpinButton( 67 nsIFrame* aFrame); 68 69 enum SpinButtonEnum { eSpinButtonNone, eSpinButtonUp, eSpinButtonDown }; 70 71 /** 72 * Returns one of the SpinButtonEnum values to depending on whether the 73 * pointer event is over the spin-up button, the spin-down button, or 74 * neither. 75 */ 76 int32_t GetSpinButtonForPointerEvent(WidgetGUIEvent* aEvent) const; 77 78 void SpinnerStateChanged() const; 79 80 bool SpinnerUpButtonIsDepressed() const; 81 bool SpinnerDownButtonIsDepressed() const; 82 83 /** 84 * Our element had HTMLInputElement::Select() called on it. 85 */ 86 void HandleSelectCall(); 87 88 bool ShouldUseNativeStyleForSpinner() const; 89 90 private: 91 // See nsNumberControlFrame::CreateAnonymousContent for a description of 92 // these. 93 nsCOMPtr<Element> mSpinUp; 94 nsCOMPtr<Element> mSpinDown; 95 }; 96 97 #endif // nsNumberControlFrame_h__