no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / layout / forms / nsRangeFrame.h
blob4d2073aa50dd0af42f8b883e7a1bc9ec78217ed3
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 /**
91 * Returns true if the slider's thumb moves horizontally, or else false if it
92 * moves vertically.
94 bool IsHorizontal() const;
96 /**
97 * Returns true if the slider is oriented along the inline axis.
99 bool IsInlineOriented() const {
100 return IsHorizontal() != GetWritingMode().IsVertical();
104 * Returns true if the slider's thumb moves right-to-left for increasing
105 * values; only relevant when IsHorizontal() is true.
107 bool IsRightToLeft() const {
108 MOZ_ASSERT(IsHorizontal());
109 return GetWritingMode().IsPhysicalRTL();
113 * Returns true if the range progresses upwards (for vertical ranges in
114 * horizontal writing mode, or for bidi-RTL in vertical mode). Only
115 * relevant when IsHorizontal() is false.
117 bool IsUpwards() const {
118 MOZ_ASSERT(!IsHorizontal());
119 mozilla::WritingMode wm = GetWritingMode();
120 return wm.GetBlockDir() == mozilla::WritingMode::eBlockTB ||
121 wm.GetInlineDir() == mozilla::WritingMode::eInlineBTT;
124 double GetMin() const;
125 double GetMax() const;
126 double GetValue() const;
129 * Returns the input element's value as a fraction of the difference between
130 * the input's minimum and its maximum (i.e. returns 0.0 when the value is
131 * the same as the minimum, and returns 1.0 when the value is the same as the
132 * maximum).
134 double GetValueAsFractionOfRange();
137 * Returns the given value as a fraction of the difference between the input's
138 * minimum and its maximum (i.e. returns 0.0 when the value is the same as the
139 * input's minimum, and returns 1.0 when the value is the same as the input's
140 * maximum).
142 double GetDoubleAsFractionOfRange(const mozilla::Decimal& value);
145 * Returns whether the frame and its child should use the native style.
147 bool ShouldUseNativeStyle() const;
149 mozilla::Decimal GetValueAtEventPoint(mozilla::WidgetGUIEvent* aEvent);
152 * Helper that's used when the value of the range changes to reposition the
153 * thumb, resize the range-progress element, and schedule a repaint. (This
154 * does not reflow, since the position and size of the thumb and
155 * range-progress element do not affect the position or size of any other
156 * frames.)
158 void UpdateForValueChange();
160 nsTArray<mozilla::Decimal> TickMarks();
163 * Returns the given value's offset from the range's nearest list tick mark
164 * or NaN if there are no tick marks.
166 mozilla::Decimal NearestTickMark(const mozilla::Decimal& aValue);
168 protected:
169 mozilla::dom::HTMLInputElement& InputElement() const;
171 private:
172 // Return our preferred size in the cross-axis (the axis perpendicular
173 // to the direction of movement of the thumb).
174 nscoord AutoCrossSize(mozilla::Length aEm);
176 // Helper function which reflows the anonymous div frames.
177 void ReflowAnonymousContent(nsPresContext* aPresContext,
178 ReflowOutput& aDesiredSize,
179 const ReflowInput& aReflowInput);
181 void DoUpdateThumbPosition(nsIFrame* aThumbFrame, const nsSize& aRangeSize);
183 void DoUpdateRangeProgressFrame(nsIFrame* aProgressFrame,
184 const nsSize& aRangeSize);
187 * The div used to show the ::-moz-range-track pseudo-element.
188 * @see nsRangeFrame::CreateAnonymousContent
190 nsCOMPtr<Element> mTrackDiv;
193 * The div used to show the ::-moz-range-progress pseudo-element, which is
194 * used to (optionally) style the specific chunk of track leading up to the
195 * thumb's current position.
196 * @see nsRangeFrame::CreateAnonymousContent
198 nsCOMPtr<Element> mProgressDiv;
201 * The div used to show the ::-moz-range-thumb pseudo-element.
202 * @see nsRangeFrame::CreateAnonymousContent
204 nsCOMPtr<Element> mThumbDiv;
207 * This mutation observer is used to invalidate paint when the @list changes,
208 * when a @list exists.
210 RefPtr<mozilla::ListMutationObserver> mListMutationObserver;
213 #endif