Bug 1853801 [wpt PR 42001] - Fix extra rel=match in test reference., a=testonly
[gecko.git] / layout / forms / nsRangeFrame.h
blob7e41f1a3f0057ce20d4d15d69d5053aae7335a14
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 nsRangeFrame_h___
8 #define nsRangeFrame_h___
10 #include "mozilla/Attributes.h"
11 #include "mozilla/Decimal.h"
12 #include "mozilla/EventForwards.h"
13 #include "nsContainerFrame.h"
14 #include "nsIAnonymousContentCreator.h"
15 #include "nsIDOMEventListener.h"
16 #include "nsCOMPtr.h"
17 #include "nsTArray.h"
19 class nsDisplayRangeFocusRing;
21 namespace mozilla {
22 class ListMutationObserver;
23 class PresShell;
24 namespace dom {
25 class Event;
26 class HTMLInputElement;
27 } // namespace dom
28 } // namespace mozilla
30 class nsRangeFrame final : public nsContainerFrame,
31 public nsIAnonymousContentCreator {
32 friend nsIFrame* NS_NewRangeFrame(mozilla::PresShell* aPresShell,
33 ComputedStyle* aStyle);
35 void Init(nsIContent* aContent, nsContainerFrame* aParent,
36 nsIFrame* aPrevInFlow) override;
38 friend class nsDisplayRangeFocusRing;
40 explicit nsRangeFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
41 virtual ~nsRangeFrame();
43 typedef mozilla::PseudoStyleType PseudoStyleType;
44 typedef mozilla::dom::Element Element;
46 public:
47 NS_DECL_QUERYFRAME
48 NS_DECL_FRAMEARENA_HELPERS(nsRangeFrame)
50 // nsIFrame overrides
51 void Destroy(DestroyContext&) override;
53 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
54 const nsDisplayListSet& aLists) override;
56 virtual void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
57 const ReflowInput& aReflowInput,
58 nsReflowStatus& aStatus) override;
60 #ifdef DEBUG_FRAME_DUMP
61 virtual nsresult GetFrameName(nsAString& aResult) const override {
62 return MakeFrameName(u"Range"_ns, aResult);
64 #endif
66 #ifdef ACCESSIBILITY
67 virtual mozilla::a11y::AccType AccessibleType() override;
68 #endif
70 // nsIAnonymousContentCreator
71 virtual nsresult CreateAnonymousContent(
72 nsTArray<ContentInfo>& aElements) override;
73 virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
74 uint32_t aFilter) override;
76 virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
77 int32_t aModType) override;
79 mozilla::LogicalSize ComputeAutoSize(
80 gfxContext* aRenderingContext, mozilla::WritingMode aWM,
81 const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
82 const mozilla::LogicalSize& aMargin,
83 const mozilla::LogicalSize& aBorderPadding,
84 const mozilla::StyleSizeOverrides& aSizeOverrides,
85 mozilla::ComputeSizeFlags aFlags) override;
87 virtual nscoord GetMinISize(gfxContext* aRenderingContext) override;
88 virtual nscoord GetPrefISize(gfxContext* aRenderingContext) override;
90 virtual bool IsFrameOfType(uint32_t aFlags) const override {
91 return nsContainerFrame::IsFrameOfType(
92 aFlags & ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
95 /**
96 * Returns true if the slider's thumb moves horizontally, or else false if it
97 * moves vertically.
99 bool IsHorizontal() const;
102 * Returns true if the slider is oriented along the inline axis.
104 bool IsInlineOriented() const {
105 return IsHorizontal() != GetWritingMode().IsVertical();
109 * Returns true if the slider's thumb moves right-to-left for increasing
110 * values; only relevant when IsHorizontal() is true.
112 bool IsRightToLeft() const {
113 MOZ_ASSERT(IsHorizontal());
114 return GetWritingMode().IsPhysicalRTL();
118 * Returns true if the range progresses upwards (for vertical ranges in
119 * horizontal writing mode, or for bidi-RTL in vertical mode). Only
120 * relevant when IsHorizontal() is false.
122 bool IsUpwards() const {
123 MOZ_ASSERT(!IsHorizontal());
124 mozilla::WritingMode wm = GetWritingMode();
125 return wm.GetBlockDir() == mozilla::WritingMode::eBlockTB ||
126 wm.GetInlineDir() == mozilla::WritingMode::eInlineBTT;
129 double GetMin() const;
130 double GetMax() const;
131 double GetValue() const;
134 * Returns the input element's value as a fraction of the difference between
135 * the input's minimum and its maximum (i.e. returns 0.0 when the value is
136 * the same as the minimum, and returns 1.0 when the value is the same as the
137 * maximum).
139 double GetValueAsFractionOfRange();
142 * Returns the given value as a fraction of the difference between the input's
143 * minimum and its maximum (i.e. returns 0.0 when the value is the same as the
144 * input's minimum, and returns 1.0 when the value is the same as the input's
145 * maximum).
147 double GetDoubleAsFractionOfRange(const mozilla::Decimal& value);
150 * Returns whether the frame and its child should use the native style.
152 bool ShouldUseNativeStyle() const;
154 mozilla::Decimal GetValueAtEventPoint(mozilla::WidgetGUIEvent* aEvent);
157 * Helper that's used when the value of the range changes to reposition the
158 * thumb, resize the range-progress element, and schedule a repaint. (This
159 * does not reflow, since the position and size of the thumb and
160 * range-progress element do not affect the position or size of any other
161 * frames.)
163 void UpdateForValueChange();
165 nsTArray<mozilla::Decimal> TickMarks();
168 * Returns the given value's offset from the range's nearest list tick mark
169 * or NaN if there are no tick marks.
171 mozilla::Decimal NearestTickMark(const mozilla::Decimal& aValue);
173 protected:
174 mozilla::dom::HTMLInputElement& InputElement() const;
176 private:
177 // Return our preferred size in the cross-axis (the axis perpendicular
178 // to the direction of movement of the thumb).
179 nscoord AutoCrossSize(mozilla::Length aEm);
181 nsresult MakeAnonymousDiv(Element** aResult, PseudoStyleType aPseudoType,
182 nsTArray<ContentInfo>& aElements);
184 // Helper function which reflows the anonymous div frames.
185 void ReflowAnonymousContent(nsPresContext* aPresContext,
186 ReflowOutput& aDesiredSize,
187 const ReflowInput& aReflowInput);
189 void DoUpdateThumbPosition(nsIFrame* aThumbFrame, const nsSize& aRangeSize);
191 void DoUpdateRangeProgressFrame(nsIFrame* aProgressFrame,
192 const nsSize& aRangeSize);
195 * The div used to show the ::-moz-range-track pseudo-element.
196 * @see nsRangeFrame::CreateAnonymousContent
198 nsCOMPtr<Element> mTrackDiv;
201 * The div used to show the ::-moz-range-progress pseudo-element, which is
202 * used to (optionally) style the specific chunk of track leading up to the
203 * thumb's current position.
204 * @see nsRangeFrame::CreateAnonymousContent
206 nsCOMPtr<Element> mProgressDiv;
209 * The div used to show the ::-moz-range-thumb pseudo-element.
210 * @see nsRangeFrame::CreateAnonymousContent
212 nsCOMPtr<Element> mThumbDiv;
215 * This mutation observer is used to invalidate paint when the @list changes,
216 * when a @list exists.
218 RefPtr<mozilla::ListMutationObserver> mListMutationObserver;
221 #endif